drbd: implement csums-after-crash-only
[deliverable/linux.git] / drivers / block / drbd / drbd_worker.c
CommitLineData
b411b363
PR
1/*
2 drbd_worker.c
3
4 This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
5
6 Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
7 Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
8 Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
9
10 drbd is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 drbd is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with drbd; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
84b8c06b 24*/
b411b363 25
b411b363 26#include <linux/module.h>
b411b363
PR
27#include <linux/drbd.h>
28#include <linux/sched.h>
b411b363
PR
29#include <linux/wait.h>
30#include <linux/mm.h>
31#include <linux/memcontrol.h>
32#include <linux/mm_inline.h>
33#include <linux/slab.h>
34#include <linux/random.h>
b411b363
PR
35#include <linux/string.h>
36#include <linux/scatterlist.h>
37
38#include "drbd_int.h"
a3603a6e 39#include "drbd_protocol.h"
b411b363 40#include "drbd_req.h"
b411b363 41
d448a2e1
AG
42static int make_ov_request(struct drbd_device *, int);
43static int make_resync_request(struct drbd_device *, int);
b411b363 44
c5a91619
AG
45/* endio handlers:
46 * drbd_md_io_complete (defined here)
fcefa62e
AG
47 * drbd_request_endio (defined here)
48 * drbd_peer_request_endio (defined here)
c5a91619
AG
49 * bm_async_io_complete (defined in drbd_bitmap.c)
50 *
b411b363
PR
51 * For all these callbacks, note the following:
52 * The callbacks will be called in irq context by the IDE drivers,
53 * and in Softirqs/Tasklets/BH context by the SCSI drivers.
54 * Try to get the locking right :)
55 *
56 */
57
58
59/* About the global_state_lock
60 Each state transition on an device holds a read lock. In case we have
95f8efd0 61 to evaluate the resync after dependencies, we grab a write lock, because
b411b363
PR
62 we need stable states on all devices for that. */
63rwlock_t global_state_lock;
64
65/* used for synchronous meta data and bitmap IO
66 * submitted by drbd_md_sync_page_io()
67 */
68void drbd_md_io_complete(struct bio *bio, int error)
69{
70 struct drbd_md_io *md_io;
b30ab791 71 struct drbd_device *device;
b411b363
PR
72
73 md_io = (struct drbd_md_io *)bio->bi_private;
b30ab791 74 device = container_of(md_io, struct drbd_device, md_io);
cdfda633 75
b411b363
PR
76 md_io->error = error;
77
0cfac5dd
PR
78 /* We grabbed an extra reference in _drbd_md_sync_page_io() to be able
79 * to timeout on the lower level device, and eventually detach from it.
80 * If this io completion runs after that timeout expired, this
81 * drbd_md_put_buffer() may allow us to finally try and re-attach.
82 * During normal operation, this only puts that extra reference
83 * down to 1 again.
84 * Make sure we first drop the reference, and only then signal
85 * completion, or we may (in drbd_al_read_log()) cycle so fast into the
86 * next drbd_md_sync_page_io(), that we trigger the
b30ab791 87 * ASSERT(atomic_read(&device->md_io_in_use) == 1) there.
0cfac5dd 88 */
b30ab791 89 drbd_md_put_buffer(device);
cdfda633 90 md_io->done = 1;
b30ab791 91 wake_up(&device->misc_wait);
cdfda633 92 bio_put(bio);
b30ab791
AG
93 if (device->ldev) /* special case: drbd_md_read() during drbd_adm_attach() */
94 put_ldev(device);
b411b363
PR
95}
96
97/* reads on behalf of the partner,
98 * "submitted" by the receiver
99 */
a186e478 100static void drbd_endio_read_sec_final(struct drbd_peer_request *peer_req) __releases(local)
b411b363
PR
101{
102 unsigned long flags = 0;
6780139c
AG
103 struct drbd_peer_device *peer_device = peer_req->peer_device;
104 struct drbd_device *device = peer_device->device;
b411b363 105
0500813f 106 spin_lock_irqsave(&device->resource->req_lock, flags);
b30ab791 107 device->read_cnt += peer_req->i.size >> 9;
a8cd15ba 108 list_del(&peer_req->w.list);
b30ab791
AG
109 if (list_empty(&device->read_ee))
110 wake_up(&device->ee_wait);
db830c46 111 if (test_bit(__EE_WAS_ERROR, &peer_req->flags))
b30ab791 112 __drbd_chk_io_error(device, DRBD_READ_ERROR);
0500813f 113 spin_unlock_irqrestore(&device->resource->req_lock, flags);
b411b363 114
6780139c 115 drbd_queue_work(&peer_device->connection->sender_work, &peer_req->w);
b30ab791 116 put_ldev(device);
b411b363
PR
117}
118
119/* writes on behalf of the partner, or resync writes,
45bb912b 120 * "submitted" by the receiver, final stage. */
a0fb3c47 121void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req) __releases(local)
b411b363
PR
122{
123 unsigned long flags = 0;
6780139c
AG
124 struct drbd_peer_device *peer_device = peer_req->peer_device;
125 struct drbd_device *device = peer_device->device;
181286ad 126 struct drbd_interval i;
b411b363 127 int do_wake;
579b57ed 128 u64 block_id;
b411b363 129 int do_al_complete_io;
b411b363 130
db830c46 131 /* after we moved peer_req to done_ee,
b411b363
PR
132 * we may no longer access it,
133 * it may be freed/reused already!
134 * (as soon as we release the req_lock) */
181286ad 135 i = peer_req->i;
db830c46
AG
136 do_al_complete_io = peer_req->flags & EE_CALL_AL_COMPLETE_IO;
137 block_id = peer_req->block_id;
b411b363 138
0500813f 139 spin_lock_irqsave(&device->resource->req_lock, flags);
b30ab791 140 device->writ_cnt += peer_req->i.size >> 9;
a8cd15ba 141 list_move_tail(&peer_req->w.list, &device->done_ee);
b411b363 142
bb3bfe96 143 /*
5e472264 144 * Do not remove from the write_requests tree here: we did not send the
bb3bfe96
AG
145 * Ack yet and did not wake possibly waiting conflicting requests.
146 * Removed from the tree from "drbd_process_done_ee" within the
84b8c06b 147 * appropriate dw.cb (e_end_block/e_end_resync_block) or from
bb3bfe96
AG
148 * _drbd_clear_done_ee.
149 */
b411b363 150
b30ab791 151 do_wake = list_empty(block_id == ID_SYNCER ? &device->sync_ee : &device->active_ee);
b411b363 152
a0fb3c47
LE
153 /* FIXME do we want to detach for failed REQ_DISCARD?
154 * ((peer_req->flags & (EE_WAS_ERROR|EE_IS_TRIM)) == EE_WAS_ERROR) */
155 if (peer_req->flags & EE_WAS_ERROR)
b30ab791 156 __drbd_chk_io_error(device, DRBD_WRITE_ERROR);
0500813f 157 spin_unlock_irqrestore(&device->resource->req_lock, flags);
b411b363 158
579b57ed 159 if (block_id == ID_SYNCER)
b30ab791 160 drbd_rs_complete_io(device, i.sector);
b411b363
PR
161
162 if (do_wake)
b30ab791 163 wake_up(&device->ee_wait);
b411b363
PR
164
165 if (do_al_complete_io)
b30ab791 166 drbd_al_complete_io(device, &i);
b411b363 167
6780139c 168 wake_asender(peer_device->connection);
b30ab791 169 put_ldev(device);
45bb912b 170}
b411b363 171
45bb912b
LE
172/* writes on behalf of the partner, or resync writes,
173 * "submitted" by the receiver.
174 */
fcefa62e 175void drbd_peer_request_endio(struct bio *bio, int error)
45bb912b 176{
db830c46 177 struct drbd_peer_request *peer_req = bio->bi_private;
a8cd15ba 178 struct drbd_device *device = peer_req->peer_device->device;
45bb912b
LE
179 int uptodate = bio_flagged(bio, BIO_UPTODATE);
180 int is_write = bio_data_dir(bio) == WRITE;
a0fb3c47 181 int is_discard = !!(bio->bi_rw & REQ_DISCARD);
45bb912b 182
07194272 183 if (error && __ratelimit(&drbd_ratelimit_state))
d0180171 184 drbd_warn(device, "%s: error=%d s=%llus\n",
a0fb3c47
LE
185 is_write ? (is_discard ? "discard" : "write")
186 : "read", error,
db830c46 187 (unsigned long long)peer_req->i.sector);
45bb912b 188 if (!error && !uptodate) {
07194272 189 if (__ratelimit(&drbd_ratelimit_state))
d0180171 190 drbd_warn(device, "%s: setting error to -EIO s=%llus\n",
07194272 191 is_write ? "write" : "read",
db830c46 192 (unsigned long long)peer_req->i.sector);
45bb912b
LE
193 /* strange behavior of some lower level drivers...
194 * fail the request by clearing the uptodate flag,
195 * but do not return any error?! */
196 error = -EIO;
197 }
198
199 if (error)
db830c46 200 set_bit(__EE_WAS_ERROR, &peer_req->flags);
45bb912b
LE
201
202 bio_put(bio); /* no need for the bio anymore */
db830c46 203 if (atomic_dec_and_test(&peer_req->pending_bios)) {
45bb912b 204 if (is_write)
db830c46 205 drbd_endio_write_sec_final(peer_req);
45bb912b 206 else
db830c46 207 drbd_endio_read_sec_final(peer_req);
45bb912b 208 }
b411b363
PR
209}
210
211/* read, readA or write requests on R_PRIMARY coming from drbd_make_request
212 */
fcefa62e 213void drbd_request_endio(struct bio *bio, int error)
b411b363 214{
a115413d 215 unsigned long flags;
b411b363 216 struct drbd_request *req = bio->bi_private;
84b8c06b 217 struct drbd_device *device = req->device;
a115413d 218 struct bio_and_error m;
b411b363
PR
219 enum drbd_req_event what;
220 int uptodate = bio_flagged(bio, BIO_UPTODATE);
221
b411b363 222 if (!error && !uptodate) {
d0180171 223 drbd_warn(device, "p %s: setting error to -EIO\n",
b411b363
PR
224 bio_data_dir(bio) == WRITE ? "write" : "read");
225 /* strange behavior of some lower level drivers...
226 * fail the request by clearing the uptodate flag,
227 * but do not return any error?! */
228 error = -EIO;
229 }
230
1b6dd252
PR
231
232 /* If this request was aborted locally before,
233 * but now was completed "successfully",
234 * chances are that this caused arbitrary data corruption.
235 *
236 * "aborting" requests, or force-detaching the disk, is intended for
237 * completely blocked/hung local backing devices which do no longer
238 * complete requests at all, not even do error completions. In this
239 * situation, usually a hard-reset and failover is the only way out.
240 *
241 * By "aborting", basically faking a local error-completion,
242 * we allow for a more graceful swichover by cleanly migrating services.
243 * Still the affected node has to be rebooted "soon".
244 *
245 * By completing these requests, we allow the upper layers to re-use
246 * the associated data pages.
247 *
248 * If later the local backing device "recovers", and now DMAs some data
249 * from disk into the original request pages, in the best case it will
250 * just put random data into unused pages; but typically it will corrupt
251 * meanwhile completely unrelated data, causing all sorts of damage.
252 *
253 * Which means delayed successful completion,
254 * especially for READ requests,
255 * is a reason to panic().
256 *
257 * We assume that a delayed *error* completion is OK,
258 * though we still will complain noisily about it.
259 */
260 if (unlikely(req->rq_state & RQ_LOCAL_ABORTED)) {
261 if (__ratelimit(&drbd_ratelimit_state))
d0180171 262 drbd_emerg(device, "delayed completion of aborted local request; disk-timeout may be too aggressive\n");
1b6dd252
PR
263
264 if (!error)
265 panic("possible random memory corruption caused by delayed completion of aborted local request\n");
266 }
267
b411b363
PR
268 /* to avoid recursion in __req_mod */
269 if (unlikely(error)) {
2f632aeb
LE
270 if (bio->bi_rw & REQ_DISCARD)
271 what = (error == -EOPNOTSUPP)
272 ? DISCARD_COMPLETED_NOTSUPP
273 : DISCARD_COMPLETED_WITH_ERROR;
274 else
275 what = (bio_data_dir(bio) == WRITE)
8554df1c 276 ? WRITE_COMPLETED_WITH_ERROR
5c3c7e64 277 : (bio_rw(bio) == READ)
8554df1c
AG
278 ? READ_COMPLETED_WITH_ERROR
279 : READ_AHEAD_COMPLETED_WITH_ERROR;
b411b363 280 } else
8554df1c 281 what = COMPLETED_OK;
b411b363
PR
282
283 bio_put(req->private_bio);
284 req->private_bio = ERR_PTR(error);
285
a115413d 286 /* not req_mod(), we need irqsave here! */
0500813f 287 spin_lock_irqsave(&device->resource->req_lock, flags);
a115413d 288 __req_mod(req, what, &m);
0500813f 289 spin_unlock_irqrestore(&device->resource->req_lock, flags);
b30ab791 290 put_ldev(device);
a115413d
LE
291
292 if (m.bio)
b30ab791 293 complete_master_bio(device, &m);
b411b363
PR
294}
295
79a3c8d3 296void drbd_csum_ee(struct crypto_hash *tfm, struct drbd_peer_request *peer_req, void *digest)
45bb912b
LE
297{
298 struct hash_desc desc;
299 struct scatterlist sg;
db830c46 300 struct page *page = peer_req->pages;
45bb912b
LE
301 struct page *tmp;
302 unsigned len;
303
304 desc.tfm = tfm;
305 desc.flags = 0;
306
307 sg_init_table(&sg, 1);
308 crypto_hash_init(&desc);
309
310 while ((tmp = page_chain_next(page))) {
311 /* all but the last page will be fully used */
312 sg_set_page(&sg, page, PAGE_SIZE, 0);
313 crypto_hash_update(&desc, &sg, sg.length);
314 page = tmp;
315 }
316 /* and now the last, possibly only partially used page */
db830c46 317 len = peer_req->i.size & (PAGE_SIZE - 1);
45bb912b
LE
318 sg_set_page(&sg, page, len ?: PAGE_SIZE, 0);
319 crypto_hash_update(&desc, &sg, sg.length);
320 crypto_hash_final(&desc, digest);
321}
322
79a3c8d3 323void drbd_csum_bio(struct crypto_hash *tfm, struct bio *bio, void *digest)
b411b363
PR
324{
325 struct hash_desc desc;
326 struct scatterlist sg;
7988613b
KO
327 struct bio_vec bvec;
328 struct bvec_iter iter;
b411b363
PR
329
330 desc.tfm = tfm;
331 desc.flags = 0;
332
333 sg_init_table(&sg, 1);
334 crypto_hash_init(&desc);
335
7988613b
KO
336 bio_for_each_segment(bvec, bio, iter) {
337 sg_set_page(&sg, bvec.bv_page, bvec.bv_len, bvec.bv_offset);
b411b363
PR
338 crypto_hash_update(&desc, &sg, sg.length);
339 }
340 crypto_hash_final(&desc, digest);
341}
342
9676c760 343/* MAYBE merge common code with w_e_end_ov_req */
99920dc5 344static int w_e_send_csum(struct drbd_work *w, int cancel)
b411b363 345{
a8cd15ba 346 struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w);
6780139c
AG
347 struct drbd_peer_device *peer_device = peer_req->peer_device;
348 struct drbd_device *device = peer_device->device;
b411b363
PR
349 int digest_size;
350 void *digest;
99920dc5 351 int err = 0;
b411b363 352
53ea4331
LE
353 if (unlikely(cancel))
354 goto out;
b411b363 355
9676c760 356 if (unlikely((peer_req->flags & EE_WAS_ERROR) != 0))
53ea4331 357 goto out;
b411b363 358
6780139c 359 digest_size = crypto_hash_digestsize(peer_device->connection->csums_tfm);
53ea4331
LE
360 digest = kmalloc(digest_size, GFP_NOIO);
361 if (digest) {
db830c46
AG
362 sector_t sector = peer_req->i.sector;
363 unsigned int size = peer_req->i.size;
6780139c 364 drbd_csum_ee(peer_device->connection->csums_tfm, peer_req, digest);
9676c760 365 /* Free peer_req and pages before send.
53ea4331
LE
366 * In case we block on congestion, we could otherwise run into
367 * some distributed deadlock, if the other side blocks on
368 * congestion as well, because our receiver blocks in
c37c8ecf 369 * drbd_alloc_pages due to pp_in_use > max_buffers. */
b30ab791 370 drbd_free_peer_req(device, peer_req);
db830c46 371 peer_req = NULL;
b30ab791 372 inc_rs_pending(device);
6780139c 373 err = drbd_send_drequest_csum(peer_device, sector, size,
db1b0b72
AG
374 digest, digest_size,
375 P_CSUM_RS_REQUEST);
53ea4331
LE
376 kfree(digest);
377 } else {
d0180171 378 drbd_err(device, "kmalloc() of digest failed.\n");
99920dc5 379 err = -ENOMEM;
53ea4331 380 }
b411b363 381
53ea4331 382out:
db830c46 383 if (peer_req)
b30ab791 384 drbd_free_peer_req(device, peer_req);
b411b363 385
99920dc5 386 if (unlikely(err))
d0180171 387 drbd_err(device, "drbd_send_drequest(..., csum) failed\n");
99920dc5 388 return err;
b411b363
PR
389}
390
391#define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN)
392
69a22773 393static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector, int size)
b411b363 394{
69a22773 395 struct drbd_device *device = peer_device->device;
db830c46 396 struct drbd_peer_request *peer_req;
b411b363 397
b30ab791 398 if (!get_ldev(device))
80a40e43 399 return -EIO;
b411b363 400
b30ab791 401 if (drbd_rs_should_slow_down(device, sector))
0f0601f4
LE
402 goto defer;
403
b411b363
PR
404 /* GFP_TRY, because if there is no memory available right now, this may
405 * be rescheduled for later. It is "only" background resync, after all. */
69a22773 406 peer_req = drbd_alloc_peer_req(peer_device, ID_SYNCER /* unused */, sector,
a0fb3c47 407 size, true /* has real payload */, GFP_TRY);
db830c46 408 if (!peer_req)
80a40e43 409 goto defer;
b411b363 410
a8cd15ba 411 peer_req->w.cb = w_e_send_csum;
0500813f 412 spin_lock_irq(&device->resource->req_lock);
a8cd15ba 413 list_add(&peer_req->w.list, &device->read_ee);
0500813f 414 spin_unlock_irq(&device->resource->req_lock);
b411b363 415
b30ab791
AG
416 atomic_add(size >> 9, &device->rs_sect_ev);
417 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
80a40e43 418 return 0;
b411b363 419
10f6d992
LE
420 /* If it failed because of ENOMEM, retry should help. If it failed
421 * because bio_add_page failed (probably broken lower level driver),
422 * retry may or may not help.
423 * If it does not, you may need to force disconnect. */
0500813f 424 spin_lock_irq(&device->resource->req_lock);
a8cd15ba 425 list_del(&peer_req->w.list);
0500813f 426 spin_unlock_irq(&device->resource->req_lock);
22cc37a9 427
b30ab791 428 drbd_free_peer_req(device, peer_req);
80a40e43 429defer:
b30ab791 430 put_ldev(device);
80a40e43 431 return -EAGAIN;
b411b363
PR
432}
433
99920dc5 434int w_resync_timer(struct drbd_work *w, int cancel)
b411b363 435{
84b8c06b
AG
436 struct drbd_device *device =
437 container_of(w, struct drbd_device, resync_work);
438
b30ab791 439 switch (device->state.conn) {
63106d3c 440 case C_VERIFY_S:
d448a2e1 441 make_ov_request(device, cancel);
63106d3c
PR
442 break;
443 case C_SYNC_TARGET:
d448a2e1 444 make_resync_request(device, cancel);
63106d3c 445 break;
b411b363
PR
446 }
447
99920dc5 448 return 0;
794abb75
PR
449}
450
451void resync_timer_fn(unsigned long data)
452{
b30ab791 453 struct drbd_device *device = (struct drbd_device *) data;
794abb75 454
b30ab791 455 if (list_empty(&device->resync_work.list))
84b8c06b
AG
456 drbd_queue_work(&first_peer_device(device)->connection->sender_work,
457 &device->resync_work);
b411b363
PR
458}
459
778f271d
PR
460static void fifo_set(struct fifo_buffer *fb, int value)
461{
462 int i;
463
464 for (i = 0; i < fb->size; i++)
f10f2623 465 fb->values[i] = value;
778f271d
PR
466}
467
468static int fifo_push(struct fifo_buffer *fb, int value)
469{
470 int ov;
471
472 ov = fb->values[fb->head_index];
473 fb->values[fb->head_index++] = value;
474
475 if (fb->head_index >= fb->size)
476 fb->head_index = 0;
477
478 return ov;
479}
480
481static void fifo_add_val(struct fifo_buffer *fb, int value)
482{
483 int i;
484
485 for (i = 0; i < fb->size; i++)
486 fb->values[i] += value;
487}
488
9958c857
PR
489struct fifo_buffer *fifo_alloc(int fifo_size)
490{
491 struct fifo_buffer *fb;
492
8747d30a 493 fb = kzalloc(sizeof(struct fifo_buffer) + sizeof(int) * fifo_size, GFP_NOIO);
9958c857
PR
494 if (!fb)
495 return NULL;
496
497 fb->head_index = 0;
498 fb->size = fifo_size;
499 fb->total = 0;
500
501 return fb;
502}
503
0e49d7b0 504static int drbd_rs_controller(struct drbd_device *device, unsigned int sect_in)
778f271d 505{
daeda1cc 506 struct disk_conf *dc;
778f271d
PR
507 unsigned int want; /* The number of sectors we want in the proxy */
508 int req_sect; /* Number of sectors to request in this turn */
509 int correction; /* Number of sectors more we need in the proxy*/
510 int cps; /* correction per invocation of drbd_rs_controller() */
511 int steps; /* Number of time steps to plan ahead */
512 int curr_corr;
513 int max_sect;
813472ce 514 struct fifo_buffer *plan;
778f271d 515
b30ab791
AG
516 dc = rcu_dereference(device->ldev->disk_conf);
517 plan = rcu_dereference(device->rs_plan_s);
778f271d 518
813472ce 519 steps = plan->size; /* (dc->c_plan_ahead * 10 * SLEEP_TIME) / HZ; */
778f271d 520
b30ab791 521 if (device->rs_in_flight + sect_in == 0) { /* At start of resync */
daeda1cc 522 want = ((dc->resync_rate * 2 * SLEEP_TIME) / HZ) * steps;
778f271d 523 } else { /* normal path */
daeda1cc
PR
524 want = dc->c_fill_target ? dc->c_fill_target :
525 sect_in * dc->c_delay_target * HZ / (SLEEP_TIME * 10);
778f271d
PR
526 }
527
b30ab791 528 correction = want - device->rs_in_flight - plan->total;
778f271d
PR
529
530 /* Plan ahead */
531 cps = correction / steps;
813472ce
PR
532 fifo_add_val(plan, cps);
533 plan->total += cps * steps;
778f271d
PR
534
535 /* What we do in this step */
813472ce
PR
536 curr_corr = fifo_push(plan, 0);
537 plan->total -= curr_corr;
778f271d
PR
538
539 req_sect = sect_in + curr_corr;
540 if (req_sect < 0)
541 req_sect = 0;
542
daeda1cc 543 max_sect = (dc->c_max_rate * 2 * SLEEP_TIME) / HZ;
778f271d
PR
544 if (req_sect > max_sect)
545 req_sect = max_sect;
546
547 /*
d0180171 548 drbd_warn(device, "si=%u if=%d wa=%u co=%d st=%d cps=%d pl=%d cc=%d rs=%d\n",
b30ab791
AG
549 sect_in, device->rs_in_flight, want, correction,
550 steps, cps, device->rs_planed, curr_corr, req_sect);
778f271d
PR
551 */
552
553 return req_sect;
554}
555
b30ab791 556static int drbd_rs_number_requests(struct drbd_device *device)
e65f440d 557{
0e49d7b0
LE
558 unsigned int sect_in; /* Number of sectors that came in since the last turn */
559 int number, mxb;
560
561 sect_in = atomic_xchg(&device->rs_sect_in, 0);
562 device->rs_in_flight -= sect_in;
813472ce
PR
563
564 rcu_read_lock();
0e49d7b0 565 mxb = drbd_get_max_buffers(device) / 2;
b30ab791 566 if (rcu_dereference(device->rs_plan_s)->size) {
0e49d7b0 567 number = drbd_rs_controller(device, sect_in) >> (BM_BLOCK_SHIFT - 9);
b30ab791 568 device->c_sync_rate = number * HZ * (BM_BLOCK_SIZE / 1024) / SLEEP_TIME;
e65f440d 569 } else {
b30ab791
AG
570 device->c_sync_rate = rcu_dereference(device->ldev->disk_conf)->resync_rate;
571 number = SLEEP_TIME * device->c_sync_rate / ((BM_BLOCK_SIZE / 1024) * HZ);
e65f440d 572 }
813472ce 573 rcu_read_unlock();
e65f440d 574
0e49d7b0
LE
575 /* Don't have more than "max-buffers"/2 in-flight.
576 * Otherwise we may cause the remote site to stall on drbd_alloc_pages(),
577 * potentially causing a distributed deadlock on congestion during
578 * online-verify or (checksum-based) resync, if max-buffers,
579 * socket buffer sizes and resync rate settings are mis-configured. */
580 if (mxb - device->rs_in_flight < number)
581 number = mxb - device->rs_in_flight;
582
e65f440d
LE
583 return number;
584}
585
44a4d551 586static int make_resync_request(struct drbd_device *const device, int cancel)
b411b363 587{
44a4d551
LE
588 struct drbd_peer_device *const peer_device = first_peer_device(device);
589 struct drbd_connection *const connection = peer_device ? peer_device->connection : NULL;
b411b363
PR
590 unsigned long bit;
591 sector_t sector;
b30ab791 592 const sector_t capacity = drbd_get_capacity(device->this_bdev);
1816a2b4 593 int max_bio_size;
e65f440d 594 int number, rollback_i, size;
b411b363 595 int align, queued, sndbuf;
0f0601f4 596 int i = 0;
b411b363
PR
597
598 if (unlikely(cancel))
99920dc5 599 return 0;
b411b363 600
b30ab791 601 if (device->rs_total == 0) {
af85e8e8 602 /* empty resync? */
b30ab791 603 drbd_resync_finished(device);
99920dc5 604 return 0;
af85e8e8
LE
605 }
606
b30ab791
AG
607 if (!get_ldev(device)) {
608 /* Since we only need to access device->rsync a
609 get_ldev_if_state(device,D_FAILED) would be sufficient, but
b411b363
PR
610 to continue resync with a broken disk makes no sense at
611 all */
d0180171 612 drbd_err(device, "Disk broke down during resync!\n");
99920dc5 613 return 0;
b411b363
PR
614 }
615
b30ab791
AG
616 max_bio_size = queue_max_hw_sectors(device->rq_queue) << 9;
617 number = drbd_rs_number_requests(device);
0e49d7b0 618 if (number <= 0)
0f0601f4 619 goto requeue;
b411b363 620
b411b363
PR
621 for (i = 0; i < number; i++) {
622 /* Stop generating RS requests, when half of the send buffer is filled */
44a4d551
LE
623 mutex_lock(&connection->data.mutex);
624 if (connection->data.socket) {
625 queued = connection->data.socket->sk->sk_wmem_queued;
626 sndbuf = connection->data.socket->sk->sk_sndbuf;
b411b363
PR
627 } else {
628 queued = 1;
629 sndbuf = 0;
630 }
44a4d551 631 mutex_unlock(&connection->data.mutex);
b411b363
PR
632 if (queued > sndbuf / 2)
633 goto requeue;
634
635next_sector:
636 size = BM_BLOCK_SIZE;
b30ab791 637 bit = drbd_bm_find_next(device, device->bm_resync_fo);
b411b363 638
4b0715f0 639 if (bit == DRBD_END_OF_BITMAP) {
b30ab791
AG
640 device->bm_resync_fo = drbd_bm_bits(device);
641 put_ldev(device);
99920dc5 642 return 0;
b411b363
PR
643 }
644
645 sector = BM_BIT_TO_SECT(bit);
646
b30ab791
AG
647 if (drbd_rs_should_slow_down(device, sector) ||
648 drbd_try_rs_begin_io(device, sector)) {
649 device->bm_resync_fo = bit;
b411b363
PR
650 goto requeue;
651 }
b30ab791 652 device->bm_resync_fo = bit + 1;
b411b363 653
b30ab791
AG
654 if (unlikely(drbd_bm_test_bit(device, bit) == 0)) {
655 drbd_rs_complete_io(device, sector);
b411b363
PR
656 goto next_sector;
657 }
658
1816a2b4 659#if DRBD_MAX_BIO_SIZE > BM_BLOCK_SIZE
b411b363
PR
660 /* try to find some adjacent bits.
661 * we stop if we have already the maximum req size.
662 *
663 * Additionally always align bigger requests, in order to
664 * be prepared for all stripe sizes of software RAIDs.
b411b363
PR
665 */
666 align = 1;
d207450c 667 rollback_i = i;
6377b923 668 while (i < number) {
1816a2b4 669 if (size + BM_BLOCK_SIZE > max_bio_size)
b411b363
PR
670 break;
671
672 /* Be always aligned */
673 if (sector & ((1<<(align+3))-1))
674 break;
675
676 /* do not cross extent boundaries */
677 if (((bit+1) & BM_BLOCKS_PER_BM_EXT_MASK) == 0)
678 break;
679 /* now, is it actually dirty, after all?
680 * caution, drbd_bm_test_bit is tri-state for some
681 * obscure reason; ( b == 0 ) would get the out-of-band
682 * only accidentally right because of the "oddly sized"
683 * adjustment below */
b30ab791 684 if (drbd_bm_test_bit(device, bit+1) != 1)
b411b363
PR
685 break;
686 bit++;
687 size += BM_BLOCK_SIZE;
688 if ((BM_BLOCK_SIZE << align) <= size)
689 align++;
690 i++;
691 }
692 /* if we merged some,
693 * reset the offset to start the next drbd_bm_find_next from */
694 if (size > BM_BLOCK_SIZE)
b30ab791 695 device->bm_resync_fo = bit + 1;
b411b363
PR
696#endif
697
698 /* adjust very last sectors, in case we are oddly sized */
699 if (sector + (size>>9) > capacity)
700 size = (capacity-sector)<<9;
aaaba345
LE
701
702 if (device->use_csums) {
44a4d551 703 switch (read_for_csum(peer_device, sector, size)) {
80a40e43 704 case -EIO: /* Disk failure */
b30ab791 705 put_ldev(device);
99920dc5 706 return -EIO;
80a40e43 707 case -EAGAIN: /* allocation failed, or ldev busy */
b30ab791
AG
708 drbd_rs_complete_io(device, sector);
709 device->bm_resync_fo = BM_SECT_TO_BIT(sector);
d207450c 710 i = rollback_i;
b411b363 711 goto requeue;
80a40e43
LE
712 case 0:
713 /* everything ok */
714 break;
715 default:
716 BUG();
b411b363
PR
717 }
718 } else {
99920dc5
AG
719 int err;
720
b30ab791 721 inc_rs_pending(device);
44a4d551 722 err = drbd_send_drequest(peer_device, P_RS_DATA_REQUEST,
99920dc5
AG
723 sector, size, ID_SYNCER);
724 if (err) {
d0180171 725 drbd_err(device, "drbd_send_drequest() failed, aborting...\n");
b30ab791
AG
726 dec_rs_pending(device);
727 put_ldev(device);
99920dc5 728 return err;
b411b363
PR
729 }
730 }
731 }
732
b30ab791 733 if (device->bm_resync_fo >= drbd_bm_bits(device)) {
b411b363
PR
734 /* last syncer _request_ was sent,
735 * but the P_RS_DATA_REPLY not yet received. sync will end (and
736 * next sync group will resume), as soon as we receive the last
737 * resync data block, and the last bit is cleared.
738 * until then resync "work" is "inactive" ...
739 */
b30ab791 740 put_ldev(device);
99920dc5 741 return 0;
b411b363
PR
742 }
743
744 requeue:
b30ab791
AG
745 device->rs_in_flight += (i << (BM_BLOCK_SHIFT - 9));
746 mod_timer(&device->resync_timer, jiffies + SLEEP_TIME);
747 put_ldev(device);
99920dc5 748 return 0;
b411b363
PR
749}
750
d448a2e1 751static int make_ov_request(struct drbd_device *device, int cancel)
b411b363
PR
752{
753 int number, i, size;
754 sector_t sector;
b30ab791 755 const sector_t capacity = drbd_get_capacity(device->this_bdev);
58ffa580 756 bool stop_sector_reached = false;
b411b363
PR
757
758 if (unlikely(cancel))
759 return 1;
760
b30ab791 761 number = drbd_rs_number_requests(device);
b411b363 762
b30ab791 763 sector = device->ov_position;
b411b363 764 for (i = 0; i < number; i++) {
58ffa580 765 if (sector >= capacity)
b411b363 766 return 1;
58ffa580
LE
767
768 /* We check for "finished" only in the reply path:
769 * w_e_end_ov_reply().
770 * We need to send at least one request out. */
771 stop_sector_reached = i > 0
b30ab791
AG
772 && verify_can_do_stop_sector(device)
773 && sector >= device->ov_stop_sector;
58ffa580
LE
774 if (stop_sector_reached)
775 break;
b411b363
PR
776
777 size = BM_BLOCK_SIZE;
778
b30ab791
AG
779 if (drbd_rs_should_slow_down(device, sector) ||
780 drbd_try_rs_begin_io(device, sector)) {
781 device->ov_position = sector;
b411b363
PR
782 goto requeue;
783 }
784
785 if (sector + (size>>9) > capacity)
786 size = (capacity-sector)<<9;
787
b30ab791 788 inc_rs_pending(device);
69a22773 789 if (drbd_send_ov_request(first_peer_device(device), sector, size)) {
b30ab791 790 dec_rs_pending(device);
b411b363
PR
791 return 0;
792 }
793 sector += BM_SECT_PER_BIT;
794 }
b30ab791 795 device->ov_position = sector;
b411b363
PR
796
797 requeue:
b30ab791 798 device->rs_in_flight += (i << (BM_BLOCK_SHIFT - 9));
58ffa580 799 if (i == 0 || !stop_sector_reached)
b30ab791 800 mod_timer(&device->resync_timer, jiffies + SLEEP_TIME);
b411b363
PR
801 return 1;
802}
803
99920dc5 804int w_ov_finished(struct drbd_work *w, int cancel)
b411b363 805{
84b8c06b
AG
806 struct drbd_device_work *dw =
807 container_of(w, struct drbd_device_work, w);
808 struct drbd_device *device = dw->device;
809 kfree(dw);
b30ab791
AG
810 ov_out_of_sync_print(device);
811 drbd_resync_finished(device);
b411b363 812
99920dc5 813 return 0;
b411b363
PR
814}
815
99920dc5 816static int w_resync_finished(struct drbd_work *w, int cancel)
b411b363 817{
84b8c06b
AG
818 struct drbd_device_work *dw =
819 container_of(w, struct drbd_device_work, w);
820 struct drbd_device *device = dw->device;
821 kfree(dw);
b411b363 822
b30ab791 823 drbd_resync_finished(device);
b411b363 824
99920dc5 825 return 0;
b411b363
PR
826}
827
b30ab791 828static void ping_peer(struct drbd_device *device)
af85e8e8 829{
a6b32bc3 830 struct drbd_connection *connection = first_peer_device(device)->connection;
2a67d8b9 831
bde89a9e
AG
832 clear_bit(GOT_PING_ACK, &connection->flags);
833 request_ping(connection);
834 wait_event(connection->ping_wait,
835 test_bit(GOT_PING_ACK, &connection->flags) || device->state.conn < C_CONNECTED);
af85e8e8
LE
836}
837
b30ab791 838int drbd_resync_finished(struct drbd_device *device)
b411b363
PR
839{
840 unsigned long db, dt, dbdt;
841 unsigned long n_oos;
842 union drbd_state os, ns;
84b8c06b 843 struct drbd_device_work *dw;
b411b363 844 char *khelper_cmd = NULL;
26525618 845 int verify_done = 0;
b411b363
PR
846
847 /* Remove all elements from the resync LRU. Since future actions
848 * might set bits in the (main) bitmap, then the entries in the
849 * resync LRU would be wrong. */
b30ab791 850 if (drbd_rs_del_all(device)) {
b411b363
PR
851 /* In case this is not possible now, most probably because
852 * there are P_RS_DATA_REPLY Packets lingering on the worker's
853 * queue (or even the read operations for those packets
854 * is not finished by now). Retry in 100ms. */
855
20ee6390 856 schedule_timeout_interruptible(HZ / 10);
84b8c06b
AG
857 dw = kmalloc(sizeof(struct drbd_device_work), GFP_ATOMIC);
858 if (dw) {
859 dw->w.cb = w_resync_finished;
860 dw->device = device;
861 drbd_queue_work(&first_peer_device(device)->connection->sender_work,
862 &dw->w);
b411b363
PR
863 return 1;
864 }
84b8c06b 865 drbd_err(device, "Warn failed to drbd_rs_del_all() and to kmalloc(dw).\n");
b411b363
PR
866 }
867
b30ab791 868 dt = (jiffies - device->rs_start - device->rs_paused) / HZ;
b411b363
PR
869 if (dt <= 0)
870 dt = 1;
84b8c06b 871
b30ab791 872 db = device->rs_total;
58ffa580 873 /* adjust for verify start and stop sectors, respective reached position */
b30ab791
AG
874 if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T)
875 db -= device->ov_left;
58ffa580 876
b411b363 877 dbdt = Bit2KB(db/dt);
b30ab791 878 device->rs_paused /= HZ;
b411b363 879
b30ab791 880 if (!get_ldev(device))
b411b363
PR
881 goto out;
882
b30ab791 883 ping_peer(device);
af85e8e8 884
0500813f 885 spin_lock_irq(&device->resource->req_lock);
b30ab791 886 os = drbd_read_state(device);
b411b363 887
26525618
LE
888 verify_done = (os.conn == C_VERIFY_S || os.conn == C_VERIFY_T);
889
b411b363
PR
890 /* This protects us against multiple calls (that can happen in the presence
891 of application IO), and against connectivity loss just before we arrive here. */
892 if (os.conn <= C_CONNECTED)
893 goto out_unlock;
894
895 ns = os;
896 ns.conn = C_CONNECTED;
897
d0180171 898 drbd_info(device, "%s done (total %lu sec; paused %lu sec; %lu K/sec)\n",
58ffa580 899 verify_done ? "Online verify" : "Resync",
b30ab791 900 dt + device->rs_paused, device->rs_paused, dbdt);
b411b363 901
b30ab791 902 n_oos = drbd_bm_total_weight(device);
b411b363
PR
903
904 if (os.conn == C_VERIFY_S || os.conn == C_VERIFY_T) {
905 if (n_oos) {
d0180171 906 drbd_alert(device, "Online verify found %lu %dk block out of sync!\n",
b411b363
PR
907 n_oos, Bit2KB(1));
908 khelper_cmd = "out-of-sync";
909 }
910 } else {
0b0ba1ef 911 D_ASSERT(device, (n_oos - device->rs_failed) == 0);
b411b363
PR
912
913 if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T)
914 khelper_cmd = "after-resync-target";
915
aaaba345 916 if (device->use_csums && device->rs_total) {
b30ab791
AG
917 const unsigned long s = device->rs_same_csum;
918 const unsigned long t = device->rs_total;
b411b363
PR
919 const int ratio =
920 (t == 0) ? 0 :
921 (t < 100000) ? ((s*100)/t) : (s/(t/100));
d0180171 922 drbd_info(device, "%u %% had equal checksums, eliminated: %luK; "
b411b363
PR
923 "transferred %luK total %luK\n",
924 ratio,
b30ab791
AG
925 Bit2KB(device->rs_same_csum),
926 Bit2KB(device->rs_total - device->rs_same_csum),
927 Bit2KB(device->rs_total));
b411b363
PR
928 }
929 }
930
b30ab791 931 if (device->rs_failed) {
d0180171 932 drbd_info(device, " %lu failed blocks\n", device->rs_failed);
b411b363
PR
933
934 if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T) {
935 ns.disk = D_INCONSISTENT;
936 ns.pdsk = D_UP_TO_DATE;
937 } else {
938 ns.disk = D_UP_TO_DATE;
939 ns.pdsk = D_INCONSISTENT;
940 }
941 } else {
942 ns.disk = D_UP_TO_DATE;
943 ns.pdsk = D_UP_TO_DATE;
944
945 if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T) {
b30ab791 946 if (device->p_uuid) {
b411b363
PR
947 int i;
948 for (i = UI_BITMAP ; i <= UI_HISTORY_END ; i++)
b30ab791
AG
949 _drbd_uuid_set(device, i, device->p_uuid[i]);
950 drbd_uuid_set(device, UI_BITMAP, device->ldev->md.uuid[UI_CURRENT]);
951 _drbd_uuid_set(device, UI_CURRENT, device->p_uuid[UI_CURRENT]);
b411b363 952 } else {
d0180171 953 drbd_err(device, "device->p_uuid is NULL! BUG\n");
b411b363
PR
954 }
955 }
956
62b0da3a
LE
957 if (!(os.conn == C_VERIFY_S || os.conn == C_VERIFY_T)) {
958 /* for verify runs, we don't update uuids here,
959 * so there would be nothing to report. */
b30ab791
AG
960 drbd_uuid_set_bm(device, 0UL);
961 drbd_print_uuids(device, "updated UUIDs");
962 if (device->p_uuid) {
62b0da3a
LE
963 /* Now the two UUID sets are equal, update what we
964 * know of the peer. */
965 int i;
966 for (i = UI_CURRENT ; i <= UI_HISTORY_END ; i++)
b30ab791 967 device->p_uuid[i] = device->ldev->md.uuid[i];
62b0da3a 968 }
b411b363
PR
969 }
970 }
971
b30ab791 972 _drbd_set_state(device, ns, CS_VERBOSE, NULL);
b411b363 973out_unlock:
0500813f 974 spin_unlock_irq(&device->resource->req_lock);
b30ab791 975 put_ldev(device);
b411b363 976out:
b30ab791
AG
977 device->rs_total = 0;
978 device->rs_failed = 0;
979 device->rs_paused = 0;
58ffa580
LE
980
981 /* reset start sector, if we reached end of device */
b30ab791
AG
982 if (verify_done && device->ov_left == 0)
983 device->ov_start_sector = 0;
b411b363 984
b30ab791 985 drbd_md_sync(device);
13d42685 986
b411b363 987 if (khelper_cmd)
b30ab791 988 drbd_khelper(device, khelper_cmd);
b411b363
PR
989
990 return 1;
991}
992
993/* helper */
b30ab791 994static void move_to_net_ee_or_free(struct drbd_device *device, struct drbd_peer_request *peer_req)
b411b363 995{
045417f7 996 if (drbd_peer_req_has_active_page(peer_req)) {
b411b363 997 /* This might happen if sendpage() has not finished */
db830c46 998 int i = (peer_req->i.size + PAGE_SIZE -1) >> PAGE_SHIFT;
b30ab791
AG
999 atomic_add(i, &device->pp_in_use_by_net);
1000 atomic_sub(i, &device->pp_in_use);
0500813f 1001 spin_lock_irq(&device->resource->req_lock);
a8cd15ba 1002 list_add_tail(&peer_req->w.list, &device->net_ee);
0500813f 1003 spin_unlock_irq(&device->resource->req_lock);
435f0740 1004 wake_up(&drbd_pp_wait);
b411b363 1005 } else
b30ab791 1006 drbd_free_peer_req(device, peer_req);
b411b363
PR
1007}
1008
1009/**
1010 * w_e_end_data_req() - Worker callback, to send a P_DATA_REPLY packet in response to a P_DATA_REQUEST
b30ab791 1011 * @device: DRBD device.
b411b363
PR
1012 * @w: work object.
1013 * @cancel: The connection will be closed anyways
1014 */
99920dc5 1015int w_e_end_data_req(struct drbd_work *w, int cancel)
b411b363 1016{
a8cd15ba 1017 struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w);
6780139c
AG
1018 struct drbd_peer_device *peer_device = peer_req->peer_device;
1019 struct drbd_device *device = peer_device->device;
99920dc5 1020 int err;
b411b363
PR
1021
1022 if (unlikely(cancel)) {
b30ab791
AG
1023 drbd_free_peer_req(device, peer_req);
1024 dec_unacked(device);
99920dc5 1025 return 0;
b411b363
PR
1026 }
1027
db830c46 1028 if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) {
6780139c 1029 err = drbd_send_block(peer_device, P_DATA_REPLY, peer_req);
b411b363
PR
1030 } else {
1031 if (__ratelimit(&drbd_ratelimit_state))
d0180171 1032 drbd_err(device, "Sending NegDReply. sector=%llus.\n",
db830c46 1033 (unsigned long long)peer_req->i.sector);
b411b363 1034
6780139c 1035 err = drbd_send_ack(peer_device, P_NEG_DREPLY, peer_req);
b411b363
PR
1036 }
1037
b30ab791 1038 dec_unacked(device);
b411b363 1039
b30ab791 1040 move_to_net_ee_or_free(device, peer_req);
b411b363 1041
99920dc5 1042 if (unlikely(err))
d0180171 1043 drbd_err(device, "drbd_send_block() failed\n");
99920dc5 1044 return err;
b411b363
PR
1045}
1046
1047/**
a209b4ae 1048 * w_e_end_rsdata_req() - Worker callback to send a P_RS_DATA_REPLY packet in response to a P_RS_DATA_REQUEST
b411b363
PR
1049 * @w: work object.
1050 * @cancel: The connection will be closed anyways
1051 */
99920dc5 1052int w_e_end_rsdata_req(struct drbd_work *w, int cancel)
b411b363 1053{
a8cd15ba 1054 struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w);
6780139c
AG
1055 struct drbd_peer_device *peer_device = peer_req->peer_device;
1056 struct drbd_device *device = peer_device->device;
99920dc5 1057 int err;
b411b363
PR
1058
1059 if (unlikely(cancel)) {
b30ab791
AG
1060 drbd_free_peer_req(device, peer_req);
1061 dec_unacked(device);
99920dc5 1062 return 0;
b411b363
PR
1063 }
1064
b30ab791
AG
1065 if (get_ldev_if_state(device, D_FAILED)) {
1066 drbd_rs_complete_io(device, peer_req->i.sector);
1067 put_ldev(device);
b411b363
PR
1068 }
1069
b30ab791 1070 if (device->state.conn == C_AHEAD) {
6780139c 1071 err = drbd_send_ack(peer_device, P_RS_CANCEL, peer_req);
db830c46 1072 } else if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) {
b30ab791
AG
1073 if (likely(device->state.pdsk >= D_INCONSISTENT)) {
1074 inc_rs_pending(device);
6780139c 1075 err = drbd_send_block(peer_device, P_RS_DATA_REPLY, peer_req);
b411b363
PR
1076 } else {
1077 if (__ratelimit(&drbd_ratelimit_state))
d0180171 1078 drbd_err(device, "Not sending RSDataReply, "
b411b363 1079 "partner DISKLESS!\n");
99920dc5 1080 err = 0;
b411b363
PR
1081 }
1082 } else {
1083 if (__ratelimit(&drbd_ratelimit_state))
d0180171 1084 drbd_err(device, "Sending NegRSDReply. sector %llus.\n",
db830c46 1085 (unsigned long long)peer_req->i.sector);
b411b363 1086
6780139c 1087 err = drbd_send_ack(peer_device, P_NEG_RS_DREPLY, peer_req);
b411b363
PR
1088
1089 /* update resync data with failure */
b30ab791 1090 drbd_rs_failed_io(device, peer_req->i.sector, peer_req->i.size);
b411b363
PR
1091 }
1092
b30ab791 1093 dec_unacked(device);
b411b363 1094
b30ab791 1095 move_to_net_ee_or_free(device, peer_req);
b411b363 1096
99920dc5 1097 if (unlikely(err))
d0180171 1098 drbd_err(device, "drbd_send_block() failed\n");
99920dc5 1099 return err;
b411b363
PR
1100}
1101
99920dc5 1102int w_e_end_csum_rs_req(struct drbd_work *w, int cancel)
b411b363 1103{
a8cd15ba 1104 struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w);
6780139c
AG
1105 struct drbd_peer_device *peer_device = peer_req->peer_device;
1106 struct drbd_device *device = peer_device->device;
b411b363
PR
1107 struct digest_info *di;
1108 int digest_size;
1109 void *digest = NULL;
99920dc5 1110 int err, eq = 0;
b411b363
PR
1111
1112 if (unlikely(cancel)) {
b30ab791
AG
1113 drbd_free_peer_req(device, peer_req);
1114 dec_unacked(device);
99920dc5 1115 return 0;
b411b363
PR
1116 }
1117
b30ab791
AG
1118 if (get_ldev(device)) {
1119 drbd_rs_complete_io(device, peer_req->i.sector);
1120 put_ldev(device);
1d53f09e 1121 }
b411b363 1122
db830c46 1123 di = peer_req->digest;
b411b363 1124
db830c46 1125 if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) {
b411b363
PR
1126 /* quick hack to try to avoid a race against reconfiguration.
1127 * a real fix would be much more involved,
1128 * introducing more locking mechanisms */
6780139c
AG
1129 if (peer_device->connection->csums_tfm) {
1130 digest_size = crypto_hash_digestsize(peer_device->connection->csums_tfm);
0b0ba1ef 1131 D_ASSERT(device, digest_size == di->digest_size);
b411b363
PR
1132 digest = kmalloc(digest_size, GFP_NOIO);
1133 }
1134 if (digest) {
6780139c 1135 drbd_csum_ee(peer_device->connection->csums_tfm, peer_req, digest);
b411b363
PR
1136 eq = !memcmp(digest, di->digest, digest_size);
1137 kfree(digest);
1138 }
1139
1140 if (eq) {
b30ab791 1141 drbd_set_in_sync(device, peer_req->i.sector, peer_req->i.size);
676396d5 1142 /* rs_same_csums unit is BM_BLOCK_SIZE */
b30ab791 1143 device->rs_same_csum += peer_req->i.size >> BM_BLOCK_SHIFT;
6780139c 1144 err = drbd_send_ack(peer_device, P_RS_IS_IN_SYNC, peer_req);
b411b363 1145 } else {
b30ab791 1146 inc_rs_pending(device);
db830c46
AG
1147 peer_req->block_id = ID_SYNCER; /* By setting block_id, digest pointer becomes invalid! */
1148 peer_req->flags &= ~EE_HAS_DIGEST; /* This peer request no longer has a digest pointer */
204bba99 1149 kfree(di);
6780139c 1150 err = drbd_send_block(peer_device, P_RS_DATA_REPLY, peer_req);
b411b363
PR
1151 }
1152 } else {
6780139c 1153 err = drbd_send_ack(peer_device, P_NEG_RS_DREPLY, peer_req);
b411b363 1154 if (__ratelimit(&drbd_ratelimit_state))
d0180171 1155 drbd_err(device, "Sending NegDReply. I guess it gets messy.\n");
b411b363
PR
1156 }
1157
b30ab791
AG
1158 dec_unacked(device);
1159 move_to_net_ee_or_free(device, peer_req);
b411b363 1160
99920dc5 1161 if (unlikely(err))
d0180171 1162 drbd_err(device, "drbd_send_block/ack() failed\n");
99920dc5 1163 return err;
b411b363
PR
1164}
1165
99920dc5 1166int w_e_end_ov_req(struct drbd_work *w, int cancel)
b411b363 1167{
a8cd15ba 1168 struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w);
6780139c
AG
1169 struct drbd_peer_device *peer_device = peer_req->peer_device;
1170 struct drbd_device *device = peer_device->device;
db830c46
AG
1171 sector_t sector = peer_req->i.sector;
1172 unsigned int size = peer_req->i.size;
b411b363
PR
1173 int digest_size;
1174 void *digest;
99920dc5 1175 int err = 0;
b411b363
PR
1176
1177 if (unlikely(cancel))
1178 goto out;
1179
6780139c 1180 digest_size = crypto_hash_digestsize(peer_device->connection->verify_tfm);
b411b363 1181 digest = kmalloc(digest_size, GFP_NOIO);
8f21420e 1182 if (!digest) {
99920dc5 1183 err = 1; /* terminate the connection in case the allocation failed */
8f21420e 1184 goto out;
b411b363
PR
1185 }
1186
db830c46 1187 if (likely(!(peer_req->flags & EE_WAS_ERROR)))
6780139c 1188 drbd_csum_ee(peer_device->connection->verify_tfm, peer_req, digest);
8f21420e
PR
1189 else
1190 memset(digest, 0, digest_size);
1191
53ea4331
LE
1192 /* Free e and pages before send.
1193 * In case we block on congestion, we could otherwise run into
1194 * some distributed deadlock, if the other side blocks on
1195 * congestion as well, because our receiver blocks in
c37c8ecf 1196 * drbd_alloc_pages due to pp_in_use > max_buffers. */
b30ab791 1197 drbd_free_peer_req(device, peer_req);
db830c46 1198 peer_req = NULL;
b30ab791 1199 inc_rs_pending(device);
6780139c 1200 err = drbd_send_drequest_csum(peer_device, sector, size, digest, digest_size, P_OV_REPLY);
99920dc5 1201 if (err)
b30ab791 1202 dec_rs_pending(device);
8f21420e
PR
1203 kfree(digest);
1204
b411b363 1205out:
db830c46 1206 if (peer_req)
b30ab791
AG
1207 drbd_free_peer_req(device, peer_req);
1208 dec_unacked(device);
99920dc5 1209 return err;
b411b363
PR
1210}
1211
b30ab791 1212void drbd_ov_out_of_sync_found(struct drbd_device *device, sector_t sector, int size)
b411b363 1213{
b30ab791
AG
1214 if (device->ov_last_oos_start + device->ov_last_oos_size == sector) {
1215 device->ov_last_oos_size += size>>9;
b411b363 1216 } else {
b30ab791
AG
1217 device->ov_last_oos_start = sector;
1218 device->ov_last_oos_size = size>>9;
b411b363 1219 }
b30ab791 1220 drbd_set_out_of_sync(device, sector, size);
b411b363
PR
1221}
1222
99920dc5 1223int w_e_end_ov_reply(struct drbd_work *w, int cancel)
b411b363 1224{
a8cd15ba 1225 struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w);
6780139c
AG
1226 struct drbd_peer_device *peer_device = peer_req->peer_device;
1227 struct drbd_device *device = peer_device->device;
b411b363 1228 struct digest_info *di;
b411b363 1229 void *digest;
db830c46
AG
1230 sector_t sector = peer_req->i.sector;
1231 unsigned int size = peer_req->i.size;
53ea4331 1232 int digest_size;
99920dc5 1233 int err, eq = 0;
58ffa580 1234 bool stop_sector_reached = false;
b411b363
PR
1235
1236 if (unlikely(cancel)) {
b30ab791
AG
1237 drbd_free_peer_req(device, peer_req);
1238 dec_unacked(device);
99920dc5 1239 return 0;
b411b363
PR
1240 }
1241
1242 /* after "cancel", because after drbd_disconnect/drbd_rs_cancel_all
1243 * the resync lru has been cleaned up already */
b30ab791
AG
1244 if (get_ldev(device)) {
1245 drbd_rs_complete_io(device, peer_req->i.sector);
1246 put_ldev(device);
1d53f09e 1247 }
b411b363 1248
db830c46 1249 di = peer_req->digest;
b411b363 1250
db830c46 1251 if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) {
6780139c 1252 digest_size = crypto_hash_digestsize(peer_device->connection->verify_tfm);
b411b363
PR
1253 digest = kmalloc(digest_size, GFP_NOIO);
1254 if (digest) {
6780139c 1255 drbd_csum_ee(peer_device->connection->verify_tfm, peer_req, digest);
b411b363 1256
0b0ba1ef 1257 D_ASSERT(device, digest_size == di->digest_size);
b411b363
PR
1258 eq = !memcmp(digest, di->digest, digest_size);
1259 kfree(digest);
1260 }
b411b363
PR
1261 }
1262
9676c760
LE
1263 /* Free peer_req and pages before send.
1264 * In case we block on congestion, we could otherwise run into
1265 * some distributed deadlock, if the other side blocks on
1266 * congestion as well, because our receiver blocks in
c37c8ecf 1267 * drbd_alloc_pages due to pp_in_use > max_buffers. */
b30ab791 1268 drbd_free_peer_req(device, peer_req);
b411b363 1269 if (!eq)
b30ab791 1270 drbd_ov_out_of_sync_found(device, sector, size);
b411b363 1271 else
b30ab791 1272 ov_out_of_sync_print(device);
b411b363 1273
6780139c 1274 err = drbd_send_ack_ex(peer_device, P_OV_RESULT, sector, size,
fa79abd8 1275 eq ? ID_IN_SYNC : ID_OUT_OF_SYNC);
b411b363 1276
b30ab791 1277 dec_unacked(device);
b411b363 1278
b30ab791 1279 --device->ov_left;
ea5442af
LE
1280
1281 /* let's advance progress step marks only for every other megabyte */
b30ab791
AG
1282 if ((device->ov_left & 0x200) == 0x200)
1283 drbd_advance_rs_marks(device, device->ov_left);
ea5442af 1284
b30ab791
AG
1285 stop_sector_reached = verify_can_do_stop_sector(device) &&
1286 (sector + (size>>9)) >= device->ov_stop_sector;
58ffa580 1287
b30ab791
AG
1288 if (device->ov_left == 0 || stop_sector_reached) {
1289 ov_out_of_sync_print(device);
1290 drbd_resync_finished(device);
b411b363
PR
1291 }
1292
99920dc5 1293 return err;
b411b363
PR
1294}
1295
b6dd1a89
LE
1296/* FIXME
1297 * We need to track the number of pending barrier acks,
1298 * and to be able to wait for them.
1299 * See also comment in drbd_adm_attach before drbd_suspend_io.
1300 */
bde89a9e 1301static int drbd_send_barrier(struct drbd_connection *connection)
b411b363 1302{
9f5bdc33 1303 struct p_barrier *p;
b6dd1a89 1304 struct drbd_socket *sock;
b411b363 1305
bde89a9e
AG
1306 sock = &connection->data;
1307 p = conn_prepare_command(connection, sock);
9f5bdc33
AG
1308 if (!p)
1309 return -EIO;
bde89a9e 1310 p->barrier = connection->send.current_epoch_nr;
b6dd1a89 1311 p->pad = 0;
bde89a9e 1312 connection->send.current_epoch_writes = 0;
b6dd1a89 1313
bde89a9e 1314 return conn_send_command(connection, sock, P_BARRIER, sizeof(*p), NULL, 0);
b411b363
PR
1315}
1316
99920dc5 1317int w_send_write_hint(struct drbd_work *w, int cancel)
b411b363 1318{
84b8c06b
AG
1319 struct drbd_device *device =
1320 container_of(w, struct drbd_device, unplug_work);
9f5bdc33
AG
1321 struct drbd_socket *sock;
1322
b411b363 1323 if (cancel)
99920dc5 1324 return 0;
a6b32bc3 1325 sock = &first_peer_device(device)->connection->data;
69a22773 1326 if (!drbd_prepare_command(first_peer_device(device), sock))
9f5bdc33 1327 return -EIO;
69a22773 1328 return drbd_send_command(first_peer_device(device), sock, P_UNPLUG_REMOTE, 0, NULL, 0);
b411b363
PR
1329}
1330
bde89a9e 1331static void re_init_if_first_write(struct drbd_connection *connection, unsigned int epoch)
4eb9b3cb 1332{
bde89a9e
AG
1333 if (!connection->send.seen_any_write_yet) {
1334 connection->send.seen_any_write_yet = true;
1335 connection->send.current_epoch_nr = epoch;
1336 connection->send.current_epoch_writes = 0;
4eb9b3cb
LE
1337 }
1338}
1339
bde89a9e 1340static void maybe_send_barrier(struct drbd_connection *connection, unsigned int epoch)
4eb9b3cb
LE
1341{
1342 /* re-init if first write on this connection */
bde89a9e 1343 if (!connection->send.seen_any_write_yet)
4eb9b3cb 1344 return;
bde89a9e
AG
1345 if (connection->send.current_epoch_nr != epoch) {
1346 if (connection->send.current_epoch_writes)
1347 drbd_send_barrier(connection);
1348 connection->send.current_epoch_nr = epoch;
4eb9b3cb
LE
1349 }
1350}
1351
8f7bed77 1352int w_send_out_of_sync(struct drbd_work *w, int cancel)
73a01a18
PR
1353{
1354 struct drbd_request *req = container_of(w, struct drbd_request, w);
84b8c06b 1355 struct drbd_device *device = req->device;
44a4d551
LE
1356 struct drbd_peer_device *const peer_device = first_peer_device(device);
1357 struct drbd_connection *const connection = peer_device->connection;
99920dc5 1358 int err;
73a01a18
PR
1359
1360 if (unlikely(cancel)) {
8554df1c 1361 req_mod(req, SEND_CANCELED);
99920dc5 1362 return 0;
73a01a18
PR
1363 }
1364
bde89a9e 1365 /* this time, no connection->send.current_epoch_writes++;
b6dd1a89
LE
1366 * If it was sent, it was the closing barrier for the last
1367 * replicated epoch, before we went into AHEAD mode.
1368 * No more barriers will be sent, until we leave AHEAD mode again. */
bde89a9e 1369 maybe_send_barrier(connection, req->epoch);
b6dd1a89 1370
44a4d551 1371 err = drbd_send_out_of_sync(peer_device, req);
8554df1c 1372 req_mod(req, OOS_HANDED_TO_NETWORK);
73a01a18 1373
99920dc5 1374 return err;
73a01a18
PR
1375}
1376
b411b363
PR
1377/**
1378 * w_send_dblock() - Worker callback to send a P_DATA packet in order to mirror a write request
b411b363
PR
1379 * @w: work object.
1380 * @cancel: The connection will be closed anyways
1381 */
99920dc5 1382int w_send_dblock(struct drbd_work *w, int cancel)
b411b363
PR
1383{
1384 struct drbd_request *req = container_of(w, struct drbd_request, w);
84b8c06b 1385 struct drbd_device *device = req->device;
44a4d551
LE
1386 struct drbd_peer_device *const peer_device = first_peer_device(device);
1387 struct drbd_connection *connection = peer_device->connection;
99920dc5 1388 int err;
b411b363
PR
1389
1390 if (unlikely(cancel)) {
8554df1c 1391 req_mod(req, SEND_CANCELED);
99920dc5 1392 return 0;
b411b363
PR
1393 }
1394
bde89a9e
AG
1395 re_init_if_first_write(connection, req->epoch);
1396 maybe_send_barrier(connection, req->epoch);
1397 connection->send.current_epoch_writes++;
b6dd1a89 1398
44a4d551 1399 err = drbd_send_dblock(peer_device, req);
99920dc5 1400 req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK);
b411b363 1401
99920dc5 1402 return err;
b411b363
PR
1403}
1404
1405/**
1406 * w_send_read_req() - Worker callback to send a read request (P_DATA_REQUEST) packet
b411b363
PR
1407 * @w: work object.
1408 * @cancel: The connection will be closed anyways
1409 */
99920dc5 1410int w_send_read_req(struct drbd_work *w, int cancel)
b411b363
PR
1411{
1412 struct drbd_request *req = container_of(w, struct drbd_request, w);
84b8c06b 1413 struct drbd_device *device = req->device;
44a4d551
LE
1414 struct drbd_peer_device *const peer_device = first_peer_device(device);
1415 struct drbd_connection *connection = peer_device->connection;
99920dc5 1416 int err;
b411b363
PR
1417
1418 if (unlikely(cancel)) {
8554df1c 1419 req_mod(req, SEND_CANCELED);
99920dc5 1420 return 0;
b411b363
PR
1421 }
1422
b6dd1a89
LE
1423 /* Even read requests may close a write epoch,
1424 * if there was any yet. */
bde89a9e 1425 maybe_send_barrier(connection, req->epoch);
b6dd1a89 1426
44a4d551 1427 err = drbd_send_drequest(peer_device, P_DATA_REQUEST, req->i.sector, req->i.size,
6c1005e7 1428 (unsigned long)req);
b411b363 1429
99920dc5 1430 req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK);
b411b363 1431
99920dc5 1432 return err;
b411b363
PR
1433}
1434
99920dc5 1435int w_restart_disk_io(struct drbd_work *w, int cancel)
265be2d0
PR
1436{
1437 struct drbd_request *req = container_of(w, struct drbd_request, w);
84b8c06b 1438 struct drbd_device *device = req->device;
265be2d0 1439
0778286a 1440 if (bio_data_dir(req->master_bio) == WRITE && req->rq_state & RQ_IN_ACT_LOG)
4dd726f0 1441 drbd_al_begin_io(device, &req->i);
265be2d0
PR
1442
1443 drbd_req_make_private_bio(req, req->master_bio);
b30ab791 1444 req->private_bio->bi_bdev = device->ldev->backing_bdev;
265be2d0
PR
1445 generic_make_request(req->private_bio);
1446
99920dc5 1447 return 0;
265be2d0
PR
1448}
1449
b30ab791 1450static int _drbd_may_sync_now(struct drbd_device *device)
b411b363 1451{
b30ab791 1452 struct drbd_device *odev = device;
95f8efd0 1453 int resync_after;
b411b363
PR
1454
1455 while (1) {
a3f8f7dc 1456 if (!odev->ldev || odev->state.disk == D_DISKLESS)
438c8374 1457 return 1;
daeda1cc 1458 rcu_read_lock();
95f8efd0 1459 resync_after = rcu_dereference(odev->ldev->disk_conf)->resync_after;
daeda1cc 1460 rcu_read_unlock();
95f8efd0 1461 if (resync_after == -1)
b411b363 1462 return 1;
b30ab791 1463 odev = minor_to_device(resync_after);
a3f8f7dc 1464 if (!odev)
841ce241 1465 return 1;
b411b363
PR
1466 if ((odev->state.conn >= C_SYNC_SOURCE &&
1467 odev->state.conn <= C_PAUSED_SYNC_T) ||
1468 odev->state.aftr_isp || odev->state.peer_isp ||
1469 odev->state.user_isp)
1470 return 0;
1471 }
1472}
1473
1474/**
1475 * _drbd_pause_after() - Pause resync on all devices that may not resync now
b30ab791 1476 * @device: DRBD device.
b411b363
PR
1477 *
1478 * Called from process context only (admin command and after_state_ch).
1479 */
b30ab791 1480static int _drbd_pause_after(struct drbd_device *device)
b411b363 1481{
54761697 1482 struct drbd_device *odev;
b411b363
PR
1483 int i, rv = 0;
1484
695d08fa 1485 rcu_read_lock();
05a10ec7 1486 idr_for_each_entry(&drbd_devices, odev, i) {
b411b363
PR
1487 if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS)
1488 continue;
1489 if (!_drbd_may_sync_now(odev))
1490 rv |= (__drbd_set_state(_NS(odev, aftr_isp, 1), CS_HARD, NULL)
1491 != SS_NOTHING_TO_DO);
1492 }
695d08fa 1493 rcu_read_unlock();
b411b363
PR
1494
1495 return rv;
1496}
1497
1498/**
1499 * _drbd_resume_next() - Resume resync on all devices that may resync now
b30ab791 1500 * @device: DRBD device.
b411b363
PR
1501 *
1502 * Called from process context only (admin command and worker).
1503 */
b30ab791 1504static int _drbd_resume_next(struct drbd_device *device)
b411b363 1505{
54761697 1506 struct drbd_device *odev;
b411b363
PR
1507 int i, rv = 0;
1508
695d08fa 1509 rcu_read_lock();
05a10ec7 1510 idr_for_each_entry(&drbd_devices, odev, i) {
b411b363
PR
1511 if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS)
1512 continue;
1513 if (odev->state.aftr_isp) {
1514 if (_drbd_may_sync_now(odev))
1515 rv |= (__drbd_set_state(_NS(odev, aftr_isp, 0),
1516 CS_HARD, NULL)
1517 != SS_NOTHING_TO_DO) ;
1518 }
1519 }
695d08fa 1520 rcu_read_unlock();
b411b363
PR
1521 return rv;
1522}
1523
b30ab791 1524void resume_next_sg(struct drbd_device *device)
b411b363
PR
1525{
1526 write_lock_irq(&global_state_lock);
b30ab791 1527 _drbd_resume_next(device);
b411b363
PR
1528 write_unlock_irq(&global_state_lock);
1529}
1530
b30ab791 1531void suspend_other_sg(struct drbd_device *device)
b411b363
PR
1532{
1533 write_lock_irq(&global_state_lock);
b30ab791 1534 _drbd_pause_after(device);
b411b363
PR
1535 write_unlock_irq(&global_state_lock);
1536}
1537
dc97b708 1538/* caller must hold global_state_lock */
b30ab791 1539enum drbd_ret_code drbd_resync_after_valid(struct drbd_device *device, int o_minor)
b411b363 1540{
54761697 1541 struct drbd_device *odev;
95f8efd0 1542 int resync_after;
b411b363
PR
1543
1544 if (o_minor == -1)
1545 return NO_ERROR;
a3f8f7dc 1546 if (o_minor < -1 || o_minor > MINORMASK)
95f8efd0 1547 return ERR_RESYNC_AFTER;
b411b363
PR
1548
1549 /* check for loops */
b30ab791 1550 odev = minor_to_device(o_minor);
b411b363 1551 while (1) {
b30ab791 1552 if (odev == device)
95f8efd0 1553 return ERR_RESYNC_AFTER_CYCLE;
b411b363 1554
a3f8f7dc
LE
1555 /* You are free to depend on diskless, non-existing,
1556 * or not yet/no longer existing minors.
1557 * We only reject dependency loops.
1558 * We cannot follow the dependency chain beyond a detached or
1559 * missing minor.
1560 */
1561 if (!odev || !odev->ldev || odev->state.disk == D_DISKLESS)
1562 return NO_ERROR;
1563
daeda1cc 1564 rcu_read_lock();
95f8efd0 1565 resync_after = rcu_dereference(odev->ldev->disk_conf)->resync_after;
daeda1cc 1566 rcu_read_unlock();
b411b363 1567 /* dependency chain ends here, no cycles. */
95f8efd0 1568 if (resync_after == -1)
b411b363
PR
1569 return NO_ERROR;
1570
1571 /* follow the dependency chain */
b30ab791 1572 odev = minor_to_device(resync_after);
b411b363
PR
1573 }
1574}
1575
dc97b708 1576/* caller must hold global_state_lock */
b30ab791 1577void drbd_resync_after_changed(struct drbd_device *device)
b411b363
PR
1578{
1579 int changes;
b411b363 1580
dc97b708 1581 do {
b30ab791
AG
1582 changes = _drbd_pause_after(device);
1583 changes |= _drbd_resume_next(device);
dc97b708 1584 } while (changes);
b411b363
PR
1585}
1586
b30ab791 1587void drbd_rs_controller_reset(struct drbd_device *device)
9bd28d3c 1588{
813472ce
PR
1589 struct fifo_buffer *plan;
1590
b30ab791
AG
1591 atomic_set(&device->rs_sect_in, 0);
1592 atomic_set(&device->rs_sect_ev, 0);
1593 device->rs_in_flight = 0;
813472ce
PR
1594
1595 /* Updating the RCU protected object in place is necessary since
1596 this function gets called from atomic context.
1597 It is valid since all other updates also lead to an completely
1598 empty fifo */
1599 rcu_read_lock();
b30ab791 1600 plan = rcu_dereference(device->rs_plan_s);
813472ce
PR
1601 plan->total = 0;
1602 fifo_set(plan, 0);
1603 rcu_read_unlock();
9bd28d3c
LE
1604}
1605
1f04af33
PR
1606void start_resync_timer_fn(unsigned long data)
1607{
b30ab791 1608 struct drbd_device *device = (struct drbd_device *) data;
ac0acb9e 1609 drbd_device_post_work(device, RS_START);
1f04af33
PR
1610}
1611
ac0acb9e 1612static void do_start_resync(struct drbd_device *device)
1f04af33 1613{
b30ab791 1614 if (atomic_read(&device->unacked_cnt) || atomic_read(&device->rs_pending_cnt)) {
ac0acb9e 1615 drbd_warn(device, "postponing start_resync ...\n");
b30ab791
AG
1616 device->start_resync_timer.expires = jiffies + HZ/10;
1617 add_timer(&device->start_resync_timer);
ac0acb9e 1618 return;
1f04af33
PR
1619 }
1620
b30ab791
AG
1621 drbd_start_resync(device, C_SYNC_SOURCE);
1622 clear_bit(AHEAD_TO_SYNC_SOURCE, &device->flags);
1f04af33
PR
1623}
1624
aaaba345
LE
1625static bool use_checksum_based_resync(struct drbd_connection *connection, struct drbd_device *device)
1626{
1627 bool csums_after_crash_only;
1628 rcu_read_lock();
1629 csums_after_crash_only = rcu_dereference(connection->net_conf)->csums_after_crash_only;
1630 rcu_read_unlock();
1631 return connection->agreed_pro_version >= 89 && /* supported? */
1632 connection->csums_tfm && /* configured? */
1633 (csums_after_crash_only == 0 /* use for each resync? */
1634 || test_bit(CRASHED_PRIMARY, &device->flags)); /* or only after Primary crash? */
1635}
1636
b411b363
PR
1637/**
1638 * drbd_start_resync() - Start the resync process
b30ab791 1639 * @device: DRBD device.
b411b363
PR
1640 * @side: Either C_SYNC_SOURCE or C_SYNC_TARGET
1641 *
1642 * This function might bring you directly into one of the
1643 * C_PAUSED_SYNC_* states.
1644 */
b30ab791 1645void drbd_start_resync(struct drbd_device *device, enum drbd_conns side)
b411b363 1646{
44a4d551
LE
1647 struct drbd_peer_device *peer_device = first_peer_device(device);
1648 struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
b411b363
PR
1649 union drbd_state ns;
1650 int r;
1651
b30ab791 1652 if (device->state.conn >= C_SYNC_SOURCE && device->state.conn < C_AHEAD) {
d0180171 1653 drbd_err(device, "Resync already running!\n");
b411b363
PR
1654 return;
1655 }
1656
b30ab791 1657 if (!test_bit(B_RS_H_DONE, &device->flags)) {
e64a3294
PR
1658 if (side == C_SYNC_TARGET) {
1659 /* Since application IO was locked out during C_WF_BITMAP_T and
1660 C_WF_SYNC_UUID we are still unmodified. Before going to C_SYNC_TARGET
1661 we check that we might make the data inconsistent. */
b30ab791 1662 r = drbd_khelper(device, "before-resync-target");
e64a3294
PR
1663 r = (r >> 8) & 0xff;
1664 if (r > 0) {
d0180171 1665 drbd_info(device, "before-resync-target handler returned %d, "
09b9e797 1666 "dropping connection.\n", r);
44a4d551 1667 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
09b9e797
PR
1668 return;
1669 }
e64a3294 1670 } else /* C_SYNC_SOURCE */ {
b30ab791 1671 r = drbd_khelper(device, "before-resync-source");
e64a3294
PR
1672 r = (r >> 8) & 0xff;
1673 if (r > 0) {
1674 if (r == 3) {
d0180171 1675 drbd_info(device, "before-resync-source handler returned %d, "
e64a3294
PR
1676 "ignoring. Old userland tools?", r);
1677 } else {
d0180171 1678 drbd_info(device, "before-resync-source handler returned %d, "
e64a3294 1679 "dropping connection.\n", r);
44a4d551 1680 conn_request_state(connection,
a6b32bc3 1681 NS(conn, C_DISCONNECTING), CS_HARD);
e64a3294
PR
1682 return;
1683 }
1684 }
09b9e797 1685 }
b411b363
PR
1686 }
1687
44a4d551 1688 if (current == connection->worker.task) {
dad20554 1689 /* The worker should not sleep waiting for state_mutex,
e64a3294 1690 that can take long */
b30ab791
AG
1691 if (!mutex_trylock(device->state_mutex)) {
1692 set_bit(B_RS_H_DONE, &device->flags);
1693 device->start_resync_timer.expires = jiffies + HZ/5;
1694 add_timer(&device->start_resync_timer);
e64a3294
PR
1695 return;
1696 }
1697 } else {
b30ab791 1698 mutex_lock(device->state_mutex);
e64a3294 1699 }
b30ab791 1700 clear_bit(B_RS_H_DONE, &device->flags);
b411b363 1701
074f4afe
LE
1702 /* req_lock: serialize with drbd_send_and_submit() and others
1703 * global_state_lock: for stable sync-after dependencies */
1704 spin_lock_irq(&device->resource->req_lock);
1705 write_lock(&global_state_lock);
a700471b 1706 /* Did some connection breakage or IO error race with us? */
b30ab791
AG
1707 if (device->state.conn < C_CONNECTED
1708 || !get_ldev_if_state(device, D_NEGOTIATING)) {
074f4afe
LE
1709 write_unlock(&global_state_lock);
1710 spin_unlock_irq(&device->resource->req_lock);
b30ab791 1711 mutex_unlock(device->state_mutex);
b411b363
PR
1712 return;
1713 }
1714
b30ab791 1715 ns = drbd_read_state(device);
b411b363 1716
b30ab791 1717 ns.aftr_isp = !_drbd_may_sync_now(device);
b411b363
PR
1718
1719 ns.conn = side;
1720
1721 if (side == C_SYNC_TARGET)
1722 ns.disk = D_INCONSISTENT;
1723 else /* side == C_SYNC_SOURCE */
1724 ns.pdsk = D_INCONSISTENT;
1725
b30ab791
AG
1726 r = __drbd_set_state(device, ns, CS_VERBOSE, NULL);
1727 ns = drbd_read_state(device);
b411b363
PR
1728
1729 if (ns.conn < C_CONNECTED)
1730 r = SS_UNKNOWN_ERROR;
1731
1732 if (r == SS_SUCCESS) {
b30ab791 1733 unsigned long tw = drbd_bm_total_weight(device);
1d7734a0
LE
1734 unsigned long now = jiffies;
1735 int i;
1736
b30ab791
AG
1737 device->rs_failed = 0;
1738 device->rs_paused = 0;
1739 device->rs_same_csum = 0;
1740 device->rs_last_events = 0;
1741 device->rs_last_sect_ev = 0;
1742 device->rs_total = tw;
1743 device->rs_start = now;
1d7734a0 1744 for (i = 0; i < DRBD_SYNC_MARKS; i++) {
b30ab791
AG
1745 device->rs_mark_left[i] = tw;
1746 device->rs_mark_time[i] = now;
1d7734a0 1747 }
b30ab791 1748 _drbd_pause_after(device);
5ab7d2c0
LE
1749 /* Forget potentially stale cached per resync extent bit-counts.
1750 * Open coded drbd_rs_cancel_all(device), we already have IRQs
1751 * disabled, and know the disk state is ok. */
1752 spin_lock(&device->al_lock);
1753 lc_reset(device->resync);
1754 device->resync_locked = 0;
1755 device->resync_wenr = LC_FREE;
1756 spin_unlock(&device->al_lock);
b411b363 1757 }
074f4afe
LE
1758 write_unlock(&global_state_lock);
1759 spin_unlock_irq(&device->resource->req_lock);
5a22db89 1760
b411b363 1761 if (r == SS_SUCCESS) {
5ab7d2c0 1762 wake_up(&device->al_wait); /* for lc_reset() above */
328e0f12
PR
1763 /* reset rs_last_bcast when a resync or verify is started,
1764 * to deal with potential jiffies wrap. */
b30ab791 1765 device->rs_last_bcast = jiffies - HZ;
328e0f12 1766
d0180171 1767 drbd_info(device, "Began resync as %s (will sync %lu KB [%lu bits set]).\n",
b411b363 1768 drbd_conn_str(ns.conn),
b30ab791
AG
1769 (unsigned long) device->rs_total << (BM_BLOCK_SHIFT-10),
1770 (unsigned long) device->rs_total);
aaaba345 1771 if (side == C_SYNC_TARGET) {
b30ab791 1772 device->bm_resync_fo = 0;
aaaba345
LE
1773 device->use_csums = use_checksum_based_resync(connection, device);
1774 } else {
1775 device->use_csums = 0;
1776 }
6c922ed5
LE
1777
1778 /* Since protocol 96, we must serialize drbd_gen_and_send_sync_uuid
1779 * with w_send_oos, or the sync target will get confused as to
1780 * how much bits to resync. We cannot do that always, because for an
1781 * empty resync and protocol < 95, we need to do it here, as we call
1782 * drbd_resync_finished from here in that case.
1783 * We drbd_gen_and_send_sync_uuid here for protocol < 96,
1784 * and from after_state_ch otherwise. */
44a4d551
LE
1785 if (side == C_SYNC_SOURCE && connection->agreed_pro_version < 96)
1786 drbd_gen_and_send_sync_uuid(peer_device);
b411b363 1787
44a4d551 1788 if (connection->agreed_pro_version < 95 && device->rs_total == 0) {
af85e8e8
LE
1789 /* This still has a race (about when exactly the peers
1790 * detect connection loss) that can lead to a full sync
1791 * on next handshake. In 8.3.9 we fixed this with explicit
1792 * resync-finished notifications, but the fix
1793 * introduces a protocol change. Sleeping for some
1794 * time longer than the ping interval + timeout on the
1795 * SyncSource, to give the SyncTarget the chance to
1796 * detect connection loss, then waiting for a ping
1797 * response (implicit in drbd_resync_finished) reduces
1798 * the race considerably, but does not solve it. */
44ed167d
PR
1799 if (side == C_SYNC_SOURCE) {
1800 struct net_conf *nc;
1801 int timeo;
1802
1803 rcu_read_lock();
44a4d551 1804 nc = rcu_dereference(connection->net_conf);
44ed167d
PR
1805 timeo = nc->ping_int * HZ + nc->ping_timeo * HZ / 9;
1806 rcu_read_unlock();
1807 schedule_timeout_interruptible(timeo);
1808 }
b30ab791 1809 drbd_resync_finished(device);
b411b363
PR
1810 }
1811
b30ab791
AG
1812 drbd_rs_controller_reset(device);
1813 /* ns.conn may already be != device->state.conn,
b411b363
PR
1814 * we may have been paused in between, or become paused until
1815 * the timer triggers.
1816 * No matter, that is handled in resync_timer_fn() */
1817 if (ns.conn == C_SYNC_TARGET)
b30ab791 1818 mod_timer(&device->resync_timer, jiffies);
b411b363 1819
b30ab791 1820 drbd_md_sync(device);
b411b363 1821 }
b30ab791
AG
1822 put_ldev(device);
1823 mutex_unlock(device->state_mutex);
b411b363
PR
1824}
1825
e334f550 1826static void update_on_disk_bitmap(struct drbd_device *device, bool resync_done)
c7a58db4
LE
1827{
1828 struct sib_info sib = { .sib_reason = SIB_SYNC_PROGRESS, };
1829 device->rs_last_bcast = jiffies;
1830
1831 if (!get_ldev(device))
1832 return;
1833
1834 drbd_bm_write_lazy(device, 0);
5ab7d2c0 1835 if (resync_done && is_sync_state(device->state.conn))
c7a58db4 1836 drbd_resync_finished(device);
5ab7d2c0 1837
c7a58db4
LE
1838 drbd_bcast_event(device, &sib);
1839 /* update timestamp, in case it took a while to write out stuff */
1840 device->rs_last_bcast = jiffies;
1841 put_ldev(device);
1842}
1843
e334f550
LE
1844static void drbd_ldev_destroy(struct drbd_device *device)
1845{
1846 lc_destroy(device->resync);
1847 device->resync = NULL;
1848 lc_destroy(device->act_log);
1849 device->act_log = NULL;
1850 __no_warn(local,
1851 drbd_free_ldev(device->ldev);
1852 device->ldev = NULL;);
1853 clear_bit(GOING_DISKLESS, &device->flags);
1854 wake_up(&device->misc_wait);
1855}
1856
1857static void go_diskless(struct drbd_device *device)
1858{
1859 D_ASSERT(device, device->state.disk == D_FAILED);
1860 /* we cannot assert local_cnt == 0 here, as get_ldev_if_state will
1861 * inc/dec it frequently. Once we are D_DISKLESS, no one will touch
1862 * the protected members anymore, though, so once put_ldev reaches zero
1863 * again, it will be safe to free them. */
1864
1865 /* Try to write changed bitmap pages, read errors may have just
1866 * set some bits outside the area covered by the activity log.
1867 *
1868 * If we have an IO error during the bitmap writeout,
1869 * we will want a full sync next time, just in case.
1870 * (Do we want a specific meta data flag for this?)
1871 *
1872 * If that does not make it to stable storage either,
1873 * we cannot do anything about that anymore.
1874 *
1875 * We still need to check if both bitmap and ldev are present, we may
1876 * end up here after a failed attach, before ldev was even assigned.
1877 */
1878 if (device->bitmap && device->ldev) {
1879 /* An interrupted resync or similar is allowed to recounts bits
1880 * while we detach.
1881 * Any modifications would not be expected anymore, though.
1882 */
1883 if (drbd_bitmap_io_from_worker(device, drbd_bm_write,
1884 "detach", BM_LOCKED_TEST_ALLOWED)) {
1885 if (test_bit(WAS_READ_ERROR, &device->flags)) {
1886 drbd_md_set_flag(device, MDF_FULL_SYNC);
1887 drbd_md_sync(device);
1888 }
1889 }
1890 }
1891
1892 drbd_force_state(device, NS(disk, D_DISKLESS));
1893}
1894
ac0acb9e
LE
1895static int do_md_sync(struct drbd_device *device)
1896{
1897 drbd_warn(device, "md_sync_timer expired! Worker calls drbd_md_sync().\n");
1898 drbd_md_sync(device);
1899 return 0;
1900}
1901
e334f550
LE
1902#define WORK_PENDING(work_bit, todo) (todo & (1UL << work_bit))
1903static void do_device_work(struct drbd_device *device, const unsigned long todo)
1904{
ac0acb9e
LE
1905 if (WORK_PENDING(MD_SYNC, todo))
1906 do_md_sync(device);
e334f550
LE
1907 if (WORK_PENDING(RS_DONE, todo) ||
1908 WORK_PENDING(RS_PROGRESS, todo))
1909 update_on_disk_bitmap(device, WORK_PENDING(RS_DONE, todo));
1910 if (WORK_PENDING(GO_DISKLESS, todo))
1911 go_diskless(device);
1912 if (WORK_PENDING(DESTROY_DISK, todo))
1913 drbd_ldev_destroy(device);
ac0acb9e
LE
1914 if (WORK_PENDING(RS_START, todo))
1915 do_start_resync(device);
e334f550
LE
1916}
1917
1918#define DRBD_DEVICE_WORK_MASK \
1919 ((1UL << GO_DISKLESS) \
1920 |(1UL << DESTROY_DISK) \
ac0acb9e
LE
1921 |(1UL << MD_SYNC) \
1922 |(1UL << RS_START) \
e334f550
LE
1923 |(1UL << RS_PROGRESS) \
1924 |(1UL << RS_DONE) \
1925 )
1926
1927static unsigned long get_work_bits(unsigned long *flags)
1928{
1929 unsigned long old, new;
1930 do {
1931 old = *flags;
1932 new = old & ~DRBD_DEVICE_WORK_MASK;
1933 } while (cmpxchg(flags, old, new) != old);
1934 return old & DRBD_DEVICE_WORK_MASK;
1935}
1936
1937static void do_unqueued_work(struct drbd_connection *connection)
c7a58db4
LE
1938{
1939 struct drbd_peer_device *peer_device;
1940 int vnr;
1941
1942 rcu_read_lock();
1943 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
1944 struct drbd_device *device = peer_device->device;
e334f550
LE
1945 unsigned long todo = get_work_bits(&device->flags);
1946 if (!todo)
c7a58db4 1947 continue;
5ab7d2c0 1948
c7a58db4
LE
1949 kref_get(&device->kref);
1950 rcu_read_unlock();
e334f550 1951 do_device_work(device, todo);
c7a58db4
LE
1952 kref_put(&device->kref, drbd_destroy_device);
1953 rcu_read_lock();
1954 }
1955 rcu_read_unlock();
1956}
1957
a186e478 1958static bool dequeue_work_batch(struct drbd_work_queue *queue, struct list_head *work_list)
8c0785a5
LE
1959{
1960 spin_lock_irq(&queue->q_lock);
1961 list_splice_init(&queue->q, work_list);
1962 spin_unlock_irq(&queue->q_lock);
1963 return !list_empty(work_list);
1964}
1965
a186e478 1966static bool dequeue_work_item(struct drbd_work_queue *queue, struct list_head *work_list)
8c0785a5
LE
1967{
1968 spin_lock_irq(&queue->q_lock);
1969 if (!list_empty(&queue->q))
1970 list_move(queue->q.next, work_list);
1971 spin_unlock_irq(&queue->q_lock);
1972 return !list_empty(work_list);
1973}
1974
bde89a9e 1975static void wait_for_work(struct drbd_connection *connection, struct list_head *work_list)
b6dd1a89
LE
1976{
1977 DEFINE_WAIT(wait);
1978 struct net_conf *nc;
1979 int uncork, cork;
1980
1981 dequeue_work_item(&connection->sender_work, work_list);
1982 if (!list_empty(work_list))
1983 return;
1984
1985 /* Still nothing to do?
1986 * Maybe we still need to close the current epoch,
1987 * even if no new requests are queued yet.
1988 *
1989 * Also, poke TCP, just in case.
1990 * Then wait for new work (or signal). */
1991 rcu_read_lock();
1992 nc = rcu_dereference(connection->net_conf);
1993 uncork = nc ? nc->tcp_cork : 0;
1994 rcu_read_unlock();
1995 if (uncork) {
1996 mutex_lock(&connection->data.mutex);
1997 if (connection->data.socket)
1998 drbd_tcp_uncork(connection->data.socket);
1999 mutex_unlock(&connection->data.mutex);
2000 }
2001
2002 for (;;) {
2003 int send_barrier;
2004 prepare_to_wait(&connection->sender_work.q_wait, &wait, TASK_INTERRUPTIBLE);
0500813f 2005 spin_lock_irq(&connection->resource->req_lock);
b6dd1a89 2006 spin_lock(&connection->sender_work.q_lock); /* FIXME get rid of this one? */
bc317a9e
LE
2007 /* dequeue single item only,
2008 * we still use drbd_queue_work_front() in some places */
2009 if (!list_empty(&connection->sender_work.q))
4dd726f0 2010 list_splice_tail_init(&connection->sender_work.q, work_list);
b6dd1a89
LE
2011 spin_unlock(&connection->sender_work.q_lock); /* FIXME get rid of this one? */
2012 if (!list_empty(work_list) || signal_pending(current)) {
0500813f 2013 spin_unlock_irq(&connection->resource->req_lock);
b6dd1a89
LE
2014 break;
2015 }
f9c78128
LE
2016
2017 /* We found nothing new to do, no to-be-communicated request,
2018 * no other work item. We may still need to close the last
2019 * epoch. Next incoming request epoch will be connection ->
2020 * current transfer log epoch number. If that is different
2021 * from the epoch of the last request we communicated, it is
2022 * safe to send the epoch separating barrier now.
2023 */
2024 send_barrier =
2025 atomic_read(&connection->current_tle_nr) !=
2026 connection->send.current_epoch_nr;
0500813f 2027 spin_unlock_irq(&connection->resource->req_lock);
f9c78128
LE
2028
2029 if (send_barrier)
2030 maybe_send_barrier(connection,
2031 connection->send.current_epoch_nr + 1);
5ab7d2c0 2032
e334f550 2033 if (test_bit(DEVICE_WORK_PENDING, &connection->flags))
5ab7d2c0
LE
2034 break;
2035
a80ca1ae
LE
2036 /* drbd_send() may have called flush_signals() */
2037 if (get_t_state(&connection->worker) != RUNNING)
2038 break;
5ab7d2c0 2039
b6dd1a89
LE
2040 schedule();
2041 /* may be woken up for other things but new work, too,
2042 * e.g. if the current epoch got closed.
2043 * In which case we send the barrier above. */
2044 }
2045 finish_wait(&connection->sender_work.q_wait, &wait);
2046
2047 /* someone may have changed the config while we have been waiting above. */
2048 rcu_read_lock();
2049 nc = rcu_dereference(connection->net_conf);
2050 cork = nc ? nc->tcp_cork : 0;
2051 rcu_read_unlock();
2052 mutex_lock(&connection->data.mutex);
2053 if (connection->data.socket) {
2054 if (cork)
2055 drbd_tcp_cork(connection->data.socket);
2056 else if (!uncork)
2057 drbd_tcp_uncork(connection->data.socket);
2058 }
2059 mutex_unlock(&connection->data.mutex);
2060}
2061
b411b363
PR
2062int drbd_worker(struct drbd_thread *thi)
2063{
bde89a9e 2064 struct drbd_connection *connection = thi->connection;
6db7e50a 2065 struct drbd_work *w = NULL;
c06ece6b 2066 struct drbd_peer_device *peer_device;
b411b363 2067 LIST_HEAD(work_list);
8c0785a5 2068 int vnr;
b411b363 2069
e77a0a5c 2070 while (get_t_state(thi) == RUNNING) {
80822284 2071 drbd_thread_current_set_cpu(thi);
b411b363 2072
8c0785a5 2073 if (list_empty(&work_list))
bde89a9e 2074 wait_for_work(connection, &work_list);
b411b363 2075
e334f550
LE
2076 if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags))
2077 do_unqueued_work(connection);
5ab7d2c0 2078
8c0785a5 2079 if (signal_pending(current)) {
b411b363 2080 flush_signals(current);
19393e10 2081 if (get_t_state(thi) == RUNNING) {
1ec861eb 2082 drbd_warn(connection, "Worker got an unexpected signal\n");
b411b363 2083 continue;
19393e10 2084 }
b411b363
PR
2085 break;
2086 }
2087
e77a0a5c 2088 if (get_t_state(thi) != RUNNING)
b411b363 2089 break;
b411b363 2090
8c0785a5 2091 while (!list_empty(&work_list)) {
6db7e50a
AG
2092 w = list_first_entry(&work_list, struct drbd_work, list);
2093 list_del_init(&w->list);
2094 if (w->cb(w, connection->cstate < C_WF_REPORT_PARAMS) == 0)
8c0785a5 2095 continue;
bde89a9e
AG
2096 if (connection->cstate >= C_WF_REPORT_PARAMS)
2097 conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD);
b411b363
PR
2098 }
2099 }
b411b363 2100
8c0785a5 2101 do {
e334f550
LE
2102 if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags))
2103 do_unqueued_work(connection);
b411b363 2104 while (!list_empty(&work_list)) {
6db7e50a
AG
2105 w = list_first_entry(&work_list, struct drbd_work, list);
2106 list_del_init(&w->list);
2107 w->cb(w, 1);
b411b363 2108 }
bde89a9e 2109 dequeue_work_batch(&connection->sender_work, &work_list);
e334f550 2110 } while (!list_empty(&work_list) || test_bit(DEVICE_WORK_PENDING, &connection->flags));
b411b363 2111
c141ebda 2112 rcu_read_lock();
c06ece6b
AG
2113 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
2114 struct drbd_device *device = peer_device->device;
0b0ba1ef 2115 D_ASSERT(device, device->state.disk == D_DISKLESS && device->state.conn == C_STANDALONE);
b30ab791 2116 kref_get(&device->kref);
c141ebda 2117 rcu_read_unlock();
b30ab791 2118 drbd_device_cleanup(device);
05a10ec7 2119 kref_put(&device->kref, drbd_destroy_device);
c141ebda 2120 rcu_read_lock();
0e29d163 2121 }
c141ebda 2122 rcu_read_unlock();
b411b363
PR
2123
2124 return 0;
2125}
This page took 0.301275 seconds and 5 git commands to generate.