History

Merge branch 'for-3.17/drivers' of git://git.kernel.dk/linux-block

Pull block driver changes from Jens Axboe: "Nothing out of the ordinary here, this pull request contains: - A big round of fixes for bcache from Kent Overstreet, Slava Pestov, and Surbhi Palande. No new features, just a lot of fixes. - The usual round of drbd updates from Andreas Gruenbacher, Lars Ellenberg, and Philipp Reisner. - virtio_blk was converted to blk-mq back in 3.13, but now Ming Lei has taken it one step further and added support for actually using more than one queue. - Addition of an explicit SG_FLAG_Q_AT_HEAD for block/bsg, to compliment the the default behavior of adding to the tail of the queue. From Douglas Gilbert" * 'for-3.17/drivers' of git://git.kernel.dk/linux-block: (86 commits) bcache: Drop unneeded blk_sync_queue() calls bcache: add mutex lock for bch_is_open bcache: Correct printing of btree_gc_max_duration_ms bcache: try to set b->parent properly bcache: fix memory corruption in init error path bcache: fix crash with incomplete cache set bcache: Fix more early shutdown bugs bcache: fix use-after-free in btree_gc_coalesce() bcache: Fix an infinite loop in journal replay bcache: fix crash in bcache_btree_node_alloc_fail tracepoint bcache: bcache_write tracepoint was crashing bcache: fix typo in bch_bkey_equal_header bcache: Allocate bounce buffers with GFP_NOWAIT bcache: Make sure to pass GFP_WAIT to mempool_alloc() bcache: fix uninterruptible sleep in writeback thread bcache: wait for buckets when allocating new btree root bcache: fix crash on shutdown in passthrough mode bcache: fix lockdep warnings on shutdown bcache allocator: send discards with correct size bcache: Fix to remove the rcu_sched stalls. ...

Linus Torvalds committed 12 years ago

Commit d429a362 parents 4a319a4 99d540039 files · +2932 −1311Browse files

Unified · Split

39 files
  1. block/scsi_ioctl.c +4 −1
  2. drivers/block/drbd/Makefile +1 −0
  3. drivers/block/drbd/drbd_actlog.c +200 −318
  4. drivers/block/drbd/drbd_bitmap.c +52 −98
  5. drivers/block/drbd/drbd_debugfs.c +958 −0
  6. drivers/block/drbd/drbd_debugfs.h +39 −0
  7. drivers/block/drbd/drbd_int.h +252 −131
  8. drivers/block/drbd/drbd_interval.h +3 −1
  9. drivers/block/drbd/drbd_main.c +125 −177
  10. drivers/block/drbd/drbd_nl.c +66 −44
  11. drivers/block/drbd/drbd_proc.c +79 −46
  12. drivers/block/drbd/drbd_receiver.c +211 −105
  13. drivers/block/drbd/drbd_req.c +362 −165
  14. drivers/block/drbd/drbd_req.h +1 −0
  15. drivers/block/drbd/drbd_state.c +49 −41
  16. drivers/block/drbd/drbd_worker.c +276 −72
  17. drivers/block/virtio_blk.c +84 −20
  18. drivers/md/bcache/alloc.c +1 −1
  19. drivers/md/bcache/bcache.h +4 −0
  20. drivers/md/bcache/bset.c +1 −1
  21. drivers/md/bcache/bset.h +1 −1
  22. drivers/md/bcache/btree.c +31 −19
  23. drivers/md/bcache/btree.h +3 −2
  24. drivers/md/bcache/extents.c +9 −4
  25. drivers/md/bcache/extents.h +1 −0
  26. drivers/md/bcache/journal.c +15 −9
  27. drivers/md/bcache/request.c +2 −1
  28. drivers/md/bcache/super.c +37 −20
  29. drivers/md/bcache/util.h +2 −2
  30. drivers/md/bcache/writeback.c +10 −4
  31. drivers/md/bcache/writeback.h +2 −1
  32. include/linux/drbd.h +2 −2
  33. include/linux/drbd_genl.h +4 −0
  34. include/linux/drbd_limits.h +6 −0
  35. include/scsi/sg.h +3 −1
  36. include/trace/events/bcache.h +12 −9
  37. include/uapi/linux/bsg.h +6 −5
  38. include/uapi/linux/virtio_blk.h +5 −0
  39. lib/lru_cache.c +13 −10
block/scsi_ioctl.c+4−1
@@ -290,6 +290,7 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk, · 289 unmodified lines
290290 unsigned long start_time;
291291 ssize_t ret = 0;
292292 int writing = 0;
293+ int at_head = 0;
293294 struct request *rq;
294295 char sense[SCSI_SENSE_BUFFERSIZE];
295296 struct bio *bio;
@@ -313,6 +314,8 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk, · 17 unmodified lines
313314 case SG_DXFER_FROM_DEV:
314315 break;
315316 }
317+ if (hdr->flags & SG_FLAG_Q_AT_HEAD)
318+ at_head = 1;
316319
317320 rq = blk_get_request(q, writing ? WRITE : READ, GFP_KERNEL);
318321 if (!rq)
@@ -369,7 +372,7 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk, · 50 unmodified lines
369372 * (if he doesn't check that is his problem).
370373 * N.B. a non-zero SCSI status is _not_ necessarily an error.
371374 */
372− blk_execute_rq(q, bd_disk, rq, 0);
375+ blk_execute_rq(q, bd_disk, rq, at_head);
373376
374377 hdr->duration = jiffies_to_msecs(jiffies - start_time);
375378
drivers/block/drbd/Makefile+1−0
@@ -3,5 +3,6 @@ drbd-y += drbd_worker.o drbd_receiver.o drbd_req.o drbd_actlog.o · 2 unmodified lines
33 drbd-y += drbd_main.o drbd_strings.o drbd_nl.o
44 drbd-y += drbd_interval.o drbd_state.o
55 drbd-y += drbd_nla.o
6+drbd-$(CONFIG_DEBUG_FS) += drbd_debugfs.o
67
78 obj-$(CONFIG_BLK_DEV_DRBD) += drbd.o
drivers/block/drbd/drbd_actlog.c+200−318
@@ -92,34 +92,26 @@ struct __packed al_transaction_on_disk { · 91 unmodified lines
9292 __be32 context[AL_CONTEXT_PER_TRANSACTION];
9393 };
9494
95−struct update_odbm_work {
96− struct drbd_work w;
97− struct drbd_device *device;
98− unsigned int enr;
99−};
100−
101−struct update_al_work {
102− struct drbd_work w;
103− struct drbd_device *device;
104− struct completion event;
105− int err;
106−};
107−
108−
109−void *drbd_md_get_buffer(struct drbd_device *device)
95+void *drbd_md_get_buffer(struct drbd_device *device, const char *intent)
11096 {
11197 int r;
11298
11399 wait_event(device->misc_wait,
114− (r = atomic_cmpxchg(&device->md_io_in_use, 0, 1)) == 0 ||
100+ (r = atomic_cmpxchg(&device->md_io.in_use, 0, 1)) == 0 ||
115101 device->state.disk <= D_FAILED);
116102
117− return r ? NULL : page_address(device->md_io_page);
103+ if (r)
104+ return NULL;
105+
106+ device->md_io.current_use = intent;
107+ device->md_io.start_jif = jiffies;
108+ device->md_io.submit_jif = device->md_io.start_jif - 1;
109+ return page_address(device->md_io.page);
118110 }
119111
120112 void drbd_md_put_buffer(struct drbd_device *device)
121113 {
122− if (atomic_dec_and_test(&device->md_io_in_use))
114+ if (atomic_dec_and_test(&device->md_io.in_use))
123115 wake_up(&device->misc_wait);
124116 }
125117
@@ -145,10 +137,11 @@ void wait_until_done_or_force_detached(struct drbd_device *device, struct drbd_b · 19 unmodified lines
145137
146138 static int _drbd_md_sync_page_io(struct drbd_device *device,
147139 struct drbd_backing_dev *bdev,
148− struct page *page, sector_t sector,
149− int rw, int size)
140+ sector_t sector, int rw)
150141 {
151142 struct bio *bio;
143+ /* we do all our meta data IO in aligned 4k blocks. */
144+ const int size = 4096;
152145 int err;
153146
154147 device->md_io.done = 0;
@@ -156,15 +149,15 @@ static int _drbd_md_sync_page_io(struct drbd_device *device, · 1 unmodified line
156149
157150 if ((rw & WRITE) && !test_bit(MD_NO_FUA, &device->flags))
158151 rw |= REQ_FUA | REQ_FLUSH;
159− rw |= REQ_SYNC;
152+ rw |= REQ_SYNC | REQ_NOIDLE;
160153
161154 bio = bio_alloc_drbd(GFP_NOIO);
162155 bio->bi_bdev = bdev->md_bdev;
163156 bio->bi_iter.bi_sector = sector;
164157 err = -EIO;
165− if (bio_add_page(bio, page, size, 0) != size)
158+ if (bio_add_page(bio, device->md_io.page, size, 0) != size)
166159 goto out;
167− bio->bi_private = &device->md_io;
160+ bio->bi_private = device;
168161 bio->bi_end_io = drbd_md_io_complete;
169162 bio->bi_rw = rw;
170163
@@ -179,7 +172,8 @@ static int _drbd_md_sync_page_io(struct drbd_device *device, · 8 unmodified lines
179172 }
180173
181174 bio_get(bio); /* one bio_put() is in the completion handler */
182− atomic_inc(&device->md_io_in_use); /* drbd_md_put_buffer() is in the completion handler */
175+ atomic_inc(&device->md_io.in_use); /* drbd_md_put_buffer() is in the completion handler */
176+ device->md_io.submit_jif = jiffies;
183177 if (drbd_insert_fault(device, (rw & WRITE) ? DRBD_FAULT_MD_WR : DRBD_FAULT_MD_RD))
184178 bio_endio(bio, -EIO);
185179 else
@@ -197,9 +191,7 @@ int drbd_md_sync_page_io(struct drbd_device *device, struct drbd_backing_dev *bd · 11 unmodified lines
197191 sector_t sector, int rw)
198192 {
199193 int err;
200− struct page *iop = device->md_io_page;
201−
202− D_ASSERT(device, atomic_read(&device->md_io_in_use) == 1);
194+ D_ASSERT(device, atomic_read(&device->md_io.in_use) == 1);
203195
204196 BUG_ON(!bdev->md_bdev);
205197
@@ -214,8 +206,7 @@ int drbd_md_sync_page_io(struct drbd_device *device, struct drbd_backing_dev *bd · 8 unmodified lines
214206 current->comm, current->pid, __func__,
215207 (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ");
216208
217− /* we do all our meta data IO in aligned 4k blocks. */
218− err = _drbd_md_sync_page_io(device, bdev, iop, sector, rw, 4096);
209+ err = _drbd_md_sync_page_io(device, bdev, sector, rw);
219210 if (err) {
220211 drbd_err(device, "drbd_md_sync_page_io(,%llus,%s) failed with error %d\n",
221212 (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ", err);
@@ -297,26 +288,12 @@ bool drbd_al_begin_io_prepare(struct drbd_device *device, struct drbd_interval * · 75 unmodified lines
297288 return need_transaction;
298289 }
299290
300−static int al_write_transaction(struct drbd_device *device, bool delegate);
301−
302−/* When called through generic_make_request(), we must delegate
303− * activity log I/O to the worker thread: a further request
304− * submitted via generic_make_request() within the same task
305− * would be queued on current->bio_list, and would only start
306− * after this function returns (see generic_make_request()).
307− *
308− * However, if we *are* the worker, we must not delegate to ourselves.
309− */
291+static int al_write_transaction(struct drbd_device *device);
310292
311−/*
312− * @delegate: delegate activity log I/O to the worker thread
313− */
314−void drbd_al_begin_io_commit(struct drbd_device *device, bool delegate)
293+void drbd_al_begin_io_commit(struct drbd_device *device)
315294 {
316295 bool locked = false;
317296
318− BUG_ON(delegate && current == first_peer_device(device)->connection->worker.task);
319−
320297 /* Serialize multiple transactions.
321298 * This uses test_and_set_bit, memory barrier is implicit.
322299 */
@@ -335,7 +312,7 @@ void drbd_al_begin_io_commit(struct drbd_device *device, bool delegate) · 12 unmodified lines
335312 rcu_read_unlock();
336313
337314 if (write_al_updates)
338− al_write_transaction(device, delegate);
315+ al_write_transaction(device);
339316 spin_lock_irq(&device->al_lock);
340317 /* FIXME
341318 if (err)
@@ -352,12 +329,10 @@ void drbd_al_begin_io_commit(struct drbd_device *device, bool delegate) · 10 unmodified lines
352329 /*
353330 * @delegate: delegate activity log I/O to the worker thread
354331 */
355−void drbd_al_begin_io(struct drbd_device *device, struct drbd_interval *i, bool delegate)
332+void drbd_al_begin_io(struct drbd_device *device, struct drbd_interval *i)
356333 {
357− BUG_ON(delegate && current == first_peer_device(device)->connection->worker.task);
358−
359334 if (drbd_al_begin_io_prepare(device, i))
360− drbd_al_begin_io_commit(device, delegate);
335+ drbd_al_begin_io_commit(device);
361336 }
362337
363338 int drbd_al_begin_io_nonblock(struct drbd_device *device, struct drbd_interval *i)
@@ -380,8 +355,19 @@ int drbd_al_begin_io_nonblock(struct drbd_device *device, struct drbd_interval * · 16 unmodified lines
380355 /* We want all necessary updates for a given request within the same transaction
381356 * We could first check how many updates are *actually* needed,
382357 * and use that instead of the worst-case nr_al_extents */
383− if (available_update_slots < nr_al_extents)
384− return -EWOULDBLOCK;
358+ if (available_update_slots < nr_al_extents) {
359+ /* Too many activity log extents are currently "hot".
360+ *
361+ * If we have accumulated pending changes already,
362+ * we made progress.
363+ *
364+ * If we cannot get even a single pending change through,
365+ * stop the fast path until we made some progress,
366+ * or requests to "cold" extents could be starved. */
367+ if (!al->pending_changes)
368+ __set_bit(__LC_STARVING, &device->act_log->flags);
369+ return -ENOBUFS;
370+ }
385371
386372 /* Is resync active in this area? */
387373 for (enr = first; enr <= last; enr++) {
@@ -452,15 +438,6 @@ static unsigned int al_extent_to_bm_page(unsigned int al_enr) · 64 unmodified lines
452438 (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT));
453439 }
454440
455−static unsigned int rs_extent_to_bm_page(unsigned int rs_enr)
456−{
457− return rs_enr >>
458− /* bit to page */
459− ((PAGE_SHIFT + 3) -
460− /* resync extent number to bit */
461− (BM_EXT_SHIFT - BM_BLOCK_SHIFT));
462−}
463−
464441 static sector_t al_tr_number_to_on_disk_sector(struct drbd_device *device)
465442 {
466443 const unsigned int stripes = device->ldev->md.al_stripes;
@@ -479,8 +456,7 @@ static sector_t al_tr_number_to_on_disk_sector(struct drbd_device *device) · 12 unmodified lines
479456 return device->ldev->md.md_offset + device->ldev->md.al_offset + t;
480457 }
481458
482−static int
483−_al_write_transaction(struct drbd_device *device)
459+int al_write_transaction(struct drbd_device *device)
484460 {
485461 struct al_transaction_on_disk *buffer;
486462 struct lc_element *e;
@@ -505,7 +481,8 @@ _al_write_transaction(struct drbd_device *device) · 18 unmodified lines
505481 return -EIO;
506482 }
507483
508− buffer = drbd_md_get_buffer(device); /* protects md_io_buffer, al_tr_cycle, ... */
484+ /* protects md_io_buffer, al_tr_cycle, ... */
485+ buffer = drbd_md_get_buffer(device, __func__);
509486 if (!buffer) {
510487 drbd_err(device, "disk failed while waiting for md_io buffer\n");
511488 put_ldev(device);
@@ -590,38 +567,6 @@ _al_write_transaction(struct drbd_device *device) · 78 unmodified lines
590567 return err;
591568 }
592569
593−
594−static int w_al_write_transaction(struct drbd_work *w, int unused)
595−{
596− struct update_al_work *aw = container_of(w, struct update_al_work, w);
597− struct drbd_device *device = aw->device;
598− int err;
599−
600− err = _al_write_transaction(device);
601− aw->err = err;
602− complete(&aw->event);
603−
604− return err != -EIO ? err : 0;
605−}
606−
607−/* Calls from worker context (see w_restart_disk_io()) need to write the
608− transaction directly. Others came through generic_make_request(),
609− those need to delegate it to the worker. */
610−static int al_write_transaction(struct drbd_device *device, bool delegate)
611−{
612− if (delegate) {
613− struct update_al_work al_work;
614− init_completion(&al_work.event);
615− al_work.w.cb = w_al_write_transaction;
616− al_work.device = device;
617− drbd_queue_work_front(&first_peer_device(device)->connection->sender_work,
618− &al_work.w);
619− wait_for_completion(&al_work.event);
620− return al_work.err;
621− } else
622− return _al_write_transaction(device);
623−}
624−
625570 static int _try_lc_del(struct drbd_device *device, struct lc_element *al_ext)
626571 {
627572 int rv;
@@ -682,72 +627,56 @@ int drbd_initialize_al(struct drbd_device *device, void *buffer) · 54 unmodified lines
682627 return 0;
683628 }
684629
685−static int w_update_odbm(struct drbd_work *w, int unused)
686−{
687− struct update_odbm_work *udw = container_of(w, struct update_odbm_work, w);
688− struct drbd_device *device = udw->device;
689− struct sib_info sib = { .sib_reason = SIB_SYNC_PROGRESS, };
690−
691− if (!get_ldev(device)) {
692− if (__ratelimit(&drbd_ratelimit_state))
693− drbd_warn(device, "Can not update on disk bitmap, local IO disabled.\n");
694− kfree(udw);
695− return 0;
696− }
697−
698− drbd_bm_write_page(device, rs_extent_to_bm_page(udw->enr));
699− put_ldev(device);
700−
701− kfree(udw);
702−
703− if (drbd_bm_total_weight(device) <= device->rs_failed) {
704− switch (device->state.conn) {
705− case C_SYNC_SOURCE: case C_SYNC_TARGET:
706− case C_PAUSED_SYNC_S: case C_PAUSED_SYNC_T:
707− drbd_resync_finished(device);
708− default:
709− /* nothing to do */
710− break;
711− }
712− }
713− drbd_bcast_event(device, &sib);
714−
715− return 0;
716−}
717−
630+static const char *drbd_change_sync_fname[] = {
631+ [RECORD_RS_FAILED] = "drbd_rs_failed_io",
632+ [SET_IN_SYNC] = "drbd_set_in_sync",
633+ [SET_OUT_OF_SYNC] = "drbd_set_out_of_sync"
634+};
718635
719636 /* ATTENTION. The AL's extents are 4MB each, while the extents in the
720637 * resync LRU-cache are 16MB each.
721638 * The caller of this function has to hold an get_ldev() reference.
722639 *
640+ * Adjusts the caching members ->rs_left (success) or ->rs_failed (!success),
641+ * potentially pulling in (and recounting the corresponding bits)
642+ * this resync extent into the resync extent lru cache.
643+ *
644+ * Returns whether all bits have been cleared for this resync extent,
645+ * precisely: (rs_left <= rs_failed)
646+ *
723647 * TODO will be obsoleted once we have a caching lru of the on disk bitmap
724648 */
725−static void drbd_try_clear_on_disk_bm(struct drbd_device *device, sector_t sector,
726− int count, int success)
649+static bool update_rs_extent(struct drbd_device *device,
650+ unsigned int enr, int count,
651+ enum update_sync_bits_mode mode)
727652 {
728653 struct lc_element *e;
729− struct update_odbm_work *udw;
730−
731− unsigned int enr;
732654
733655 D_ASSERT(device, atomic_read(&device->local_cnt));
734656
735− /* I simply assume that a sector/size pair never crosses
736− * a 16 MB extent border. (Currently this is true...) */
737− enr = BM_SECT_TO_EXT(sector);
738−
739− e = lc_get(device->resync, enr);
657+ /* When setting out-of-sync bits,
658+ * we don't need it cached (lc_find).
659+ * But if it is present in the cache,
660+ * we should update the cached bit count.
661+ * Otherwise, that extent should be in the resync extent lru cache
662+ * already -- or we want to pull it in if necessary -- (lc_get),
663+ * then update and check rs_left and rs_failed. */
664+ if (mode == SET_OUT_OF_SYNC)
665+ e = lc_find(device->resync, enr);
666+ else
667+ e = lc_get(device->resync, enr);
740668 if (e) {
741669 struct bm_extent *ext = lc_entry(e, struct bm_extent, lce);
742670 if (ext->lce.lc_number == enr) {
743− if (success)
671+ if (mode == SET_IN_SYNC)
744672 ext->rs_left -= count;
673+ else if (mode == SET_OUT_OF_SYNC)
674+ ext->rs_left += count;
745675 else
746676 ext->rs_failed += count;
747677 if (ext->rs_left < ext->rs_failed) {
748− drbd_warn(device, "BAD! sector=%llus enr=%u rs_left=%d "
678+ drbd_warn(device, "BAD! enr=%u rs_left=%d "
749679 "rs_failed=%d count=%d cstate=%s\n",
750− (unsigned long long)sector,
751680 ext->lce.lc_number, ext->rs_left,
752681 ext->rs_failed, count,
753682 drbd_conn_str(device->state.conn));
@@ -781,34 +710,27 @@ static void drbd_try_clear_on_disk_bm(struct drbd_device *device, sector_t secto · 27 unmodified lines
781710 ext->lce.lc_number, ext->rs_failed);
782711 }
783712 ext->rs_left = rs_left;
784− ext->rs_failed = success ? 0 : count;
713+ ext->rs_failed = (mode == RECORD_RS_FAILED) ? count : 0;
785714 /* we don't keep a persistent log of the resync lru,
786715 * we can commit any change right away. */
787716 lc_committed(device->resync);
788717 }
789− lc_put(device->resync, &ext->lce);
718+ if (mode != SET_OUT_OF_SYNC)
719+ lc_put(device->resync, &ext->lce);
790720 /* no race, we are within the al_lock! */
791721
792− if (ext->rs_left == ext->rs_failed) {
722+ if (ext->rs_left <= ext->rs_failed) {
793723 ext->rs_failed = 0;
794−
795− udw = kmalloc(sizeof(*udw), GFP_ATOMIC);
796− if (udw) {
797− udw->enr = ext->lce.lc_number;
798− udw->w.cb = w_update_odbm;
799− udw->device = device;
800− drbd_queue_work_front(&first_peer_device(device)->connection->sender_work,
801− &udw->w);
802− } else {
803− drbd_warn(device, "Could not kmalloc an udw\n");
804− }
724+ return true;
805725 }
806− } else {
726+ } else if (mode != SET_OUT_OF_SYNC) {
727+ /* be quiet if lc_find() did not find it. */
807728 drbd_err(device, "lc_get() failed! locked=%d/%d flags=%lu\n",
808729 device->resync_locked,
809730 device->resync->nr_elements,
810731 device->resync->flags);
811732 }
733+ return false;
812734 }
813735
814736 void drbd_advance_rs_marks(struct drbd_device *device, unsigned long still_to_go)
@@ -827,105 +749,105 @@ void drbd_advance_rs_marks(struct drbd_device *device, unsigned long still_to_go · 12 unmodified lines
827749 }
828750 }
829751
830−/* clear the bit corresponding to the piece of storage in question:
831− * size byte of data starting from sector. Only clear a bits of the affected
832− * one ore more _aligned_ BM_BLOCK_SIZE blocks.
833− *
834− * called by worker on C_SYNC_TARGET and receiver on SyncSource.
835− *
836− */
837−void __drbd_set_in_sync(struct drbd_device *device, sector_t sector, int size,
838− const char *file, const unsigned int line)
752+/* It is called lazy update, so don't do write-out too often. */
753+static bool lazy_bitmap_update_due(struct drbd_device *device)
839754 {
840− /* Is called from worker and receiver context _only_ */
841− unsigned long sbnr, ebnr, lbnr;
842− unsigned long count = 0;
843− sector_t esector, nr_sectors;
844− int wake_up = 0;
845− unsigned long flags;
755+ return time_after(jiffies, device->rs_last_bcast + 2*HZ);
756+}
846757
847− if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_DISCARD_SIZE) {
848− drbd_err(device, "drbd_set_in_sync: sector=%llus size=%d nonsense!\n",
849− (unsigned long long)sector, size);
758+static void maybe_schedule_on_disk_bitmap_update(struct drbd_device *device, bool rs_done)
759+{
760+ if (rs_done)
761+ set_bit(RS_DONE, &device->flags);
762+ /* and also set RS_PROGRESS below */
763+ else if (!lazy_bitmap_update_due(device))
850764 return;
851− }
852−
853− if (!get_ldev(device))
854− return; /* no disk, no metadata, no bitmap to clear bits in */
855−
856− nr_sectors = drbd_get_capacity(device->this_bdev);
857− esector = sector + (size >> 9) - 1;
858−
859− if (!expect(sector < nr_sectors))
860− goto out;
861− if (!expect(esector < nr_sectors))
862− esector = nr_sectors - 1;
863−
864− lbnr = BM_SECT_TO_BIT(nr_sectors-1);
865−
866− /* we clear it (in sync).
867− * round up start sector, round down end sector. we make sure we only
868− * clear full, aligned, BM_BLOCK_SIZE (4K) blocks */
869− if (unlikely(esector < BM_SECT_PER_BIT-1))
870− goto out;
871− if (unlikely(esector == (nr_sectors-1)))
872− ebnr = lbnr;
873− else
874− ebnr = BM_SECT_TO_BIT(esector - (BM_SECT_PER_BIT-1));
875− sbnr = BM_SECT_TO_BIT(sector + BM_SECT_PER_BIT-1);
876765
877− if (sbnr > ebnr)
878− goto out;
766+ drbd_device_post_work(device, RS_PROGRESS);
767+}
879768
769+static int update_sync_bits(struct drbd_device *device,
770+ unsigned long sbnr, unsigned long ebnr,
771+ enum update_sync_bits_mode mode)
772+{
880773 /*
881− * ok, (capacity & 7) != 0 sometimes, but who cares...
882− * we count rs_{total,left} in bits, not sectors.
774+ * We keep a count of set bits per resync-extent in the ->rs_left
775+ * caching member, so we need to loop and work within the resync extent
776+ * alignment. Typically this loop will execute exactly once.
883777 */
884− count = drbd_bm_clear_bits(device, sbnr, ebnr);
885− if (count) {
886− drbd_advance_rs_marks(device, drbd_bm_total_weight(device));
887− spin_lock_irqsave(&device->al_lock, flags);
888− drbd_try_clear_on_disk_bm(device, sector, count, true);
889− spin_unlock_irqrestore(&device->al_lock, flags);
890−
891− /* just wake_up unconditional now, various lc_chaged(),
892− * lc_put() in drbd_try_clear_on_disk_bm(). */
893− wake_up = 1;
778+ unsigned long flags;
779+ unsigned long count = 0;
780+ unsigned int cleared = 0;
781+ while (sbnr <= ebnr) {
782+ /* set temporary boundary bit number to last bit number within
783+ * the resync extent of the current start bit number,
784+ * but cap at provided end bit number */
785+ unsigned long tbnr = min(ebnr, sbnr | BM_BLOCKS_PER_BM_EXT_MASK);
786+ unsigned long c;
787+
788+ if (mode == RECORD_RS_FAILED)
789+ /* Only called from drbd_rs_failed_io(), bits
790+ * supposedly still set. Recount, maybe some
791+ * of the bits have been successfully cleared
792+ * by application IO meanwhile.
793+ */
794+ c = drbd_bm_count_bits(device, sbnr, tbnr);
795+ else if (mode == SET_IN_SYNC)
796+ c = drbd_bm_clear_bits(device, sbnr, tbnr);
797+ else /* if (mode == SET_OUT_OF_SYNC) */
798+ c = drbd_bm_set_bits(device, sbnr, tbnr);
799+
800+ if (c) {
801+ spin_lock_irqsave(&device->al_lock, flags);
802+ cleared += update_rs_extent(device, BM_BIT_TO_EXT(sbnr), c, mode);
803+ spin_unlock_irqrestore(&device->al_lock, flags);
804+ count += c;
805+ }
806+ sbnr = tbnr + 1;
894807 }
895−out:
896− put_ldev(device);
897− if (wake_up)
808+ if (count) {
809+ if (mode == SET_IN_SYNC) {
810+ unsigned long still_to_go = drbd_bm_total_weight(device);
811+ bool rs_is_done = (still_to_go <= device->rs_failed);
812+ drbd_advance_rs_marks(device, still_to_go);
813+ if (cleared || rs_is_done)
814+ maybe_schedule_on_disk_bitmap_update(device, rs_is_done);
815+ } else if (mode == RECORD_RS_FAILED)
816+ device->rs_failed += count;
898817 wake_up(&device->al_wait);
818+ }
819+ return count;
899820 }
900821
901−/*
902− * this is intended to set one request worth of data out of sync.
903− * affects at least 1 bit,
904− * and at most 1+DRBD_MAX_BIO_SIZE/BM_BLOCK_SIZE bits.
822+/* clear the bit corresponding to the piece of storage in question:
823+ * size byte of data starting from sector. Only clear a bits of the affected
824+ * one ore more _aligned_ BM_BLOCK_SIZE blocks.
825+ *
826+ * called by worker on C_SYNC_TARGET and receiver on SyncSource.
905827 *
906− * called by tl_clear and drbd_send_dblock (==drbd_make_request).
907− * so this can be _any_ process.
908828 */
909−int __drbd_set_out_of_sync(struct drbd_device *device, sector_t sector, int size,
910− const char *file, const unsigned int line)
829+int __drbd_change_sync(struct drbd_device *device, sector_t sector, int size,
830+ enum update_sync_bits_mode mode,
831+ const char *file, const unsigned int line)
911832 {
912− unsigned long sbnr, ebnr, flags;
833+ /* Is called from worker and receiver context _only_ */
834+ unsigned long sbnr, ebnr, lbnr;
835+ unsigned long count = 0;
913836 sector_t esector, nr_sectors;
914− unsigned int enr, count = 0;
915− struct lc_element *e;
916837
917− /* this should be an empty REQ_FLUSH */
918− if (size == 0)
838+ /* This would be an empty REQ_FLUSH, be silent. */
839+ if ((mode == SET_OUT_OF_SYNC) && size == 0)
919840 return 0;
920841
921− if (size < 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_DISCARD_SIZE) {
922− drbd_err(device, "sector: %llus, size: %d\n",
923− (unsigned long long)sector, size);
842+ if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_DISCARD_SIZE) {
843+ drbd_err(device, "%s: sector=%llus size=%d nonsense!\n",
844+ drbd_change_sync_fname[mode],
845+ (unsigned long long)sector, size);
924846 return 0;
925847 }
926848
927849 if (!get_ldev(device))
928− return 0; /* no disk, no metadata, no bitmap to set bits in */
850+ return 0; /* no disk, no metadata, no bitmap to manipulate bits in */
929851
930852 nr_sectors = drbd_get_capacity(device->this_bdev);
931853 esector = sector + (size >> 9) - 1;
@@ -935,25 +857,28 @@ int __drbd_set_out_of_sync(struct drbd_device *device, sector_t sector, int size · 3 unmodified lines
935857 if (!expect(esector < nr_sectors))
936858 esector = nr_sectors - 1;
937859
938− /* we set it out of sync,
939− * we do not need to round anything here */
940− sbnr = BM_SECT_TO_BIT(sector);
941− ebnr = BM_SECT_TO_BIT(esector);
942−
943− /* ok, (capacity & 7) != 0 sometimes, but who cares...
944− * we count rs_{total,left} in bits, not sectors. */
945− spin_lock_irqsave(&device->al_lock, flags);
946− count = drbd_bm_set_bits(device, sbnr, ebnr);
860+ lbnr = BM_SECT_TO_BIT(nr_sectors-1);
947861
948− enr = BM_SECT_TO_EXT(sector);
949− e = lc_find(device->resync, enr);
950− if (e)
951− lc_entry(e, struct bm_extent, lce)->rs_left += count;
952− spin_unlock_irqrestore(&device->al_lock, flags);
862+ if (mode == SET_IN_SYNC) {
863+ /* Round up start sector, round down end sector. We make sure
864+ * we only clear full, aligned, BM_BLOCK_SIZE blocks. */
865+ if (unlikely(esector < BM_SECT_PER_BIT-1))
866+ goto out;
867+ if (unlikely(esector == (nr_sectors-1)))
868+ ebnr = lbnr;
869+ else
870+ ebnr = BM_SECT_TO_BIT(esector - (BM_SECT_PER_BIT-1));
871+ sbnr = BM_SECT_TO_BIT(sector + BM_SECT_PER_BIT-1);
872+ } else {
873+ /* We set it out of sync, or record resync failure.
874+ * Should not round anything here. */
875+ sbnr = BM_SECT_TO_BIT(sector);
876+ ebnr = BM_SECT_TO_BIT(esector);
877+ }
953878
879+ count = update_sync_bits(device, sbnr, ebnr, mode);
954880 out:
955881 put_ldev(device);
956−
957882 return count;
958883 }
959884
@@ -1075,6 +1000,15 @@ int drbd_try_rs_begin_io(struct drbd_device *device, sector_t sector) · 115 unmodified lines
10751000 struct lc_element *e;
10761001 struct bm_extent *bm_ext;
10771002 int i;
1003+ bool throttle = drbd_rs_should_slow_down(device, sector, true);
1004+
1005+ /* If we need to throttle, a half-locked (only marked BME_NO_WRITES,
1006+ * not yet BME_LOCKED) extent needs to be kicked out explicitly if we
1007+ * need to throttle. There is at most one such half-locked extent,
1008+ * which is remembered in resync_wenr. */
1009+
1010+ if (throttle && device->resync_wenr != enr)
1011+ return -EAGAIN;
10781012
10791013 spin_lock_irq(&device->al_lock);
10801014 if (device->resync_wenr != LC_FREE && device->resync_wenr != enr) {
@@ -1098,8 +1032,10 @@ int drbd_try_rs_begin_io(struct drbd_device *device, sector_t sector) · 17 unmodified lines
10981032 D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags));
10991033 clear_bit(BME_NO_WRITES, &bm_ext->flags);
11001034 device->resync_wenr = LC_FREE;
1101− if (lc_put(device->resync, &bm_ext->lce) == 0)
1035+ if (lc_put(device->resync, &bm_ext->lce) == 0) {
1036+ bm_ext->flags = 0;
11021037 device->resync_locked--;
1038+ }
11031039 wake_up(&device->al_wait);
11041040 } else {
11051041 drbd_alert(device, "LOGIC BUG\n");
@@ -1161,8 +1097,20 @@ proceed: · 55 unmodified lines
11611097 return 0;
11621098
11631099 try_again:
1164− if (bm_ext)
1165− device->resync_wenr = enr;
1100+ if (bm_ext) {
1101+ if (throttle) {
1102+ D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags));
1103+ D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags));
1104+ clear_bit(BME_NO_WRITES, &bm_ext->flags);
1105+ device->resync_wenr = LC_FREE;
1106+ if (lc_put(device->resync, &bm_ext->lce) == 0) {
1107+ bm_ext->flags = 0;
1108+ device->resync_locked--;
1109+ }
1110+ wake_up(&device->al_wait);
1111+ } else
1112+ device->resync_wenr = enr;
1113+ }
11661114 spin_unlock_irq(&device->al_lock);
11671115 return -EAGAIN;
11681116 }
@@ -1270,69 +1218,3 @@ int drbd_rs_del_all(struct drbd_device *device) · 101 unmodified lines
12701218
12711219 return 0;
12721220 }
1273−
1274−/**
1275− * drbd_rs_failed_io() - Record information on a failure to resync the specified blocks
1276− * @device: DRBD device.
1277− * @sector: The sector number.
1278− * @size: Size of failed IO operation, in byte.
1279− */
1280−void drbd_rs_failed_io(struct drbd_device *device, sector_t sector, int size)
1281−{
1282− /* Is called from worker and receiver context _only_ */
1283− unsigned long sbnr, ebnr, lbnr;
1284− unsigned long count;
1285− sector_t esector, nr_sectors;
1286− int wake_up = 0;
1287−
1288− if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_DISCARD_SIZE) {
1289− drbd_err(device, "drbd_rs_failed_io: sector=%llus size=%d nonsense!\n",
1290− (unsigned long long)sector, size);
1291− return;
1292− }
1293− nr_sectors = drbd_get_capacity(device->this_bdev);
1294− esector = sector + (size >> 9) - 1;
1295−
1296− if (!expect(sector < nr_sectors))
1297− return;
1298− if (!expect(esector < nr_sectors))
1299− esector = nr_sectors - 1;
1300−
1301− lbnr = BM_SECT_TO_BIT(nr_sectors-1);
1302−
1303− /*
1304− * round up start sector, round down end sector. we make sure we only
1305− * handle full, aligned, BM_BLOCK_SIZE (4K) blocks */
1306− if (unlikely(esector < BM_SECT_PER_BIT-1))
1307− return;
1308− if (unlikely(esector == (nr_sectors-1)))
1309− ebnr = lbnr;
1310− else
1311− ebnr = BM_SECT_TO_BIT(esector - (BM_SECT_PER_BIT-1));
1312− sbnr = BM_SECT_TO_BIT(sector + BM_SECT_PER_BIT-1);
1313−
1314− if (sbnr > ebnr)
1315− return;
1316−
1317− /*
1318− * ok, (capacity & 7) != 0 sometimes, but who cares...
1319− * we count rs_{total,left} in bits, not sectors.
1320− */
1321− spin_lock_irq(&device->al_lock);
1322− count = drbd_bm_count_bits(device, sbnr, ebnr);
1323− if (count) {
1324− device->rs_failed += count;
1325−
1326− if (get_ldev(device)) {
1327− drbd_try_clear_on_disk_bm(device, sector, count, false);
1328− put_ldev(device);
1329− }
1330−
1331− /* just wake_up unconditional now, various lc_chaged(),
1332− * lc_put() in drbd_try_clear_on_disk_bm(). */
1333− wake_up = 1;
1334− }
1335− spin_unlock_irq(&device->al_lock);
1336− if (wake_up)
1337− wake_up(&device->al_wait);
1338−}
drivers/block/drbd/drbd_bitmap.c+52−98
@@ -22,6 +22,8 @@ · 21 unmodified lines
2222 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
2323 */
2424
25+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26+
2527 #include <linux/bitops.h>
2628 #include <linux/vmalloc.h>
2729 #include <linux/string.h>
@@ -353,9 +355,8 @@ static void bm_free_pages(struct page **pages, unsigned long number) · 325 unmodified lines
353355
354356 for (i = 0; i < number; i++) {
355357 if (!pages[i]) {
356− printk(KERN_ALERT "drbd: bm_free_pages tried to free "
357− "a NULL pointer; i=%lu n=%lu\n",
358− i, number);
358+ pr_alert("bm_free_pages tried to free a NULL pointer; i=%lu n=%lu\n",
359+ i, number);
359360 continue;
360361 }
361362 __free_page(pages[i]);
@@ -592,7 +593,7 @@ static void bm_memset(struct drbd_bitmap *b, size_t offset, int c, size_t len) · 230 unmodified lines
592593 end = offset + len;
593594
594595 if (end > b->bm_words) {
595− printk(KERN_ALERT "drbd: bm_memset end > bm_words\n");
596+ pr_alert("bm_memset end > bm_words\n");
596597 return;
597598 }
598599
@@ -602,7 +603,7 @@ static void bm_memset(struct drbd_bitmap *b, size_t offset, int c, size_t len) · 3 unmodified lines
602603 p_addr = bm_map_pidx(b, idx);
603604 bm = p_addr + MLPP(offset);
604605 if (bm+do_now > p_addr + LWPP) {
605− printk(KERN_ALERT "drbd: BUG BUG BUG! p_addr:%p bm:%p do_now:%d\n",
606+ pr_alert("BUG BUG BUG! p_addr:%p bm:%p do_now:%d\n",
606607 p_addr, bm, (int)do_now);
607608 } else
608609 memset(bm, c, do_now * sizeof(long));
@@ -927,22 +928,14 @@ void drbd_bm_clear_all(struct drbd_device *device) · 318 unmodified lines
927928 spin_unlock_irq(&b->bm_lock);
928929 }
929930
930−struct bm_aio_ctx {
931− struct drbd_device *device;
932− atomic_t in_flight;
933− unsigned int done;
934− unsigned flags;
935−#define BM_AIO_COPY_PAGES 1
936−#define BM_AIO_WRITE_HINTED 2
937−#define BM_WRITE_ALL_PAGES 4
938− int error;
939− struct kref kref;
940−};
941−
942−static void bm_aio_ctx_destroy(struct kref *kref)
931+static void drbd_bm_aio_ctx_destroy(struct kref *kref)
943932 {
944− struct bm_aio_ctx *ctx = container_of(kref, struct bm_aio_ctx, kref);
933+ struct drbd_bm_aio_ctx *ctx = container_of(kref, struct drbd_bm_aio_ctx, kref);
934+ unsigned long flags;
945935
936+ spin_lock_irqsave(&ctx->device->resource->req_lock, flags);
937+ list_del(&ctx->list);
938+ spin_unlock_irqrestore(&ctx->device->resource->req_lock, flags);
946939 put_ldev(ctx->device);
947940 kfree(ctx);
948941 }
@@ -950,7 +943,7 @@ static void bm_aio_ctx_destroy(struct kref *kref) · 1 unmodified line
950943 /* bv_page may be a copy, or may be the original */
951944 static void bm_async_io_complete(struct bio *bio, int error)
952945 {
953− struct bm_aio_ctx *ctx = bio->bi_private;
946+ struct drbd_bm_aio_ctx *ctx = bio->bi_private;
954947 struct drbd_device *device = ctx->device;
955948 struct drbd_bitmap *b = device->bitmap;
956949 unsigned int idx = bm_page_to_idx(bio->bi_io_vec[0].bv_page);
@@ -993,17 +986,18 @@ static void bm_async_io_complete(struct bio *bio, int error) · 36 unmodified lines
993986 if (atomic_dec_and_test(&ctx->in_flight)) {
994987 ctx->done = 1;
995988 wake_up(&device->misc_wait);
996− kref_put(&ctx->kref, &bm_aio_ctx_destroy);
989+ kref_put(&ctx->kref, &drbd_bm_aio_ctx_destroy);
997990 }
998991 }
999992
1000−static void bm_page_io_async(struct bm_aio_ctx *ctx, int page_nr, int rw) __must_hold(local)
993+static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_hold(local)
1001994 {
1002995 struct bio *bio = bio_alloc_drbd(GFP_NOIO);
1003996 struct drbd_device *device = ctx->device;
1004997 struct drbd_bitmap *b = device->bitmap;
1005998 struct page *page;
1006999 unsigned int len;
1000+ unsigned int rw = (ctx->flags & BM_AIO_READ) ? READ : WRITE;
10071001
10081002 sector_t on_disk_sector =
10091003 device->ldev->md.md_offset + device->ldev->md.bm_offset;
@@ -1049,9 +1043,9 @@ static void bm_page_io_async(struct bm_aio_ctx *ctx, int page_nr, int rw) __must · 39 unmodified lines
10491043 /*
10501044 * bm_rw: read/write the whole bitmap from/to its on disk location.
10511045 */
1052−static int bm_rw(struct drbd_device *device, int rw, unsigned flags, unsigned lazy_writeout_upper_idx) __must_hold(local)
1046+static int bm_rw(struct drbd_device *device, const unsigned int flags, unsigned lazy_writeout_upper_idx) __must_hold(local)
10531047 {
1054− struct bm_aio_ctx *ctx;
1048+ struct drbd_bm_aio_ctx *ctx;
10551049 struct drbd_bitmap *b = device->bitmap;
10561050 int num_pages, i, count = 0;
10571051 unsigned long now;
@@ -1067,12 +1061,13 @@ static int bm_rw(struct drbd_device *device, int rw, unsigned flags, unsigned la · 9 unmodified lines
10671061 * as we submit copies of pages anyways.
10681062 */
10691063
1070− ctx = kmalloc(sizeof(struct bm_aio_ctx), GFP_NOIO);
1064+ ctx = kmalloc(sizeof(struct drbd_bm_aio_ctx), GFP_NOIO);
10711065 if (!ctx)
10721066 return -ENOMEM;
10731067
1074− *ctx = (struct bm_aio_ctx) {
1068+ *ctx = (struct drbd_bm_aio_ctx) {
10751069 .device = device,
1070+ .start_jif = jiffies,
10761071 .in_flight = ATOMIC_INIT(1),
10771072 .done = 0,
10781073 .flags = flags,
@@ -1080,15 +1075,21 @@ static int bm_rw(struct drbd_device *device, int rw, unsigned flags, unsigned la · 1 unmodified line
10801075 .kref = { ATOMIC_INIT(2) },
10811076 };
10821077
1083− if (!get_ldev_if_state(device, D_ATTACHING)) { /* put is in bm_aio_ctx_destroy() */
1078+ if (!get_ldev_if_state(device, D_ATTACHING)) { /* put is in drbd_bm_aio_ctx_destroy() */
10841079 drbd_err(device, "ASSERT FAILED: get_ldev_if_state() == 1 in bm_rw()\n");
10851080 kfree(ctx);
10861081 return -ENODEV;
10871082 }
1083+ /* Here D_ATTACHING is sufficient since drbd_bm_read() is called only from
1084+ drbd_adm_attach(), after device->ldev was assigned. */
10881085
1089− if (!ctx->flags)
1086+ if (0 == (ctx->flags & ~BM_AIO_READ))
10901087 WARN_ON(!(BM_LOCKED_MASK & b->bm_flags));
10911088
1089+ spin_lock_irq(&device->resource->req_lock);
1090+ list_add_tail(&ctx->list, &device->pending_bitmap_io);
1091+ spin_unlock_irq(&device->resource->req_lock);
1092+
10921093 num_pages = b->bm_number_of_pages;
10931094
10941095 now = jiffies;
@@ -1098,13 +1099,13 @@ static int bm_rw(struct drbd_device *device, int rw, unsigned flags, unsigned la · 3 unmodified lines
10981099 /* ignore completely unchanged pages */
10991100 if (lazy_writeout_upper_idx && i == lazy_writeout_upper_idx)
11001101 break;
1101− if (rw & WRITE) {
1102+ if (!(flags & BM_AIO_READ)) {
11021103 if ((flags & BM_AIO_WRITE_HINTED) &&
11031104 !test_and_clear_bit(BM_PAGE_HINT_WRITEOUT,
11041105 &page_private(b->bm_pages[i])))
11051106 continue;
11061107
1107− if (!(flags & BM_WRITE_ALL_PAGES) &&
1108+ if (!(flags & BM_AIO_WRITE_ALL_PAGES) &&
11081109 bm_test_page_unchanged(b->bm_pages[i])) {
11091110 dynamic_drbd_dbg(device, "skipped bm write for idx %u\n", i);
11101111 continue;
@@ -1118,7 +1119,7 @@ static int bm_rw(struct drbd_device *device, int rw, unsigned flags, unsigned la · 7 unmodified lines
11181119 }
11191120 }
11201121 atomic_inc(&ctx->in_flight);
1121− bm_page_io_async(ctx, i, rw);
1122+ bm_page_io_async(ctx, i);
11221123 ++count;
11231124 cond_resched();
11241125 }
@@ -1134,12 +1135,12 @@ static int bm_rw(struct drbd_device *device, int rw, unsigned flags, unsigned la · 9 unmodified lines
11341135 if (!atomic_dec_and_test(&ctx->in_flight))
11351136 wait_until_done_or_force_detached(device, device->ldev, &ctx->done);
11361137 else
1137− kref_put(&ctx->kref, &bm_aio_ctx_destroy);
1138+ kref_put(&ctx->kref, &drbd_bm_aio_ctx_destroy);
11381139
11391140 /* summary for global bitmap IO */
11401141 if (flags == 0)
11411142 drbd_info(device, "bitmap %s of %u pages took %lu jiffies\n",
1142− rw == WRITE ? "WRITE" : "READ",
1143+ (flags & BM_AIO_READ) ? "READ" : "WRITE",
11431144 count, jiffies - now);
11441145
11451146 if (ctx->error) {
@@ -1152,20 +1153,18 @@ static int bm_rw(struct drbd_device *device, int rw, unsigned flags, unsigned la · 6 unmodified lines
11521153 err = -EIO; /* Disk timeout/force-detach during IO... */
11531154
11541155 now = jiffies;
1155− if (rw == WRITE) {
1156− drbd_md_flush(device);
1157− } else /* rw == READ */ {
1156+ if (flags & BM_AIO_READ) {
11581157 b->bm_set = bm_count_bits(b);
11591158 drbd_info(device, "recounting of set bits took additional %lu jiffies\n",
11601159 jiffies - now);
11611160 }
11621161 now = b->bm_set;
11631162
1164− if (flags == 0)
1163+ if ((flags & ~BM_AIO_READ) == 0)
11651164 drbd_info(device, "%s (%lu bits) marked out-of-sync by on disk bit-map.\n",
11661165 ppsize(ppb, now << (BM_BLOCK_SHIFT-10)), now);
11671166
1168− kref_put(&ctx->kref, &bm_aio_ctx_destroy);
1167+ kref_put(&ctx->kref, &drbd_bm_aio_ctx_destroy);
11691168 return err;
11701169 }
11711170
@@ -1175,7 +1174,7 @@ static int bm_rw(struct drbd_device *device, int rw, unsigned flags, unsigned la · 3 unmodified lines
11751174 */
11761175 int drbd_bm_read(struct drbd_device *device) __must_hold(local)
11771176 {
1178− return bm_rw(device, READ, 0, 0);
1177+ return bm_rw(device, BM_AIO_READ, 0);
11791178 }
11801179
11811180 /**
@@ -1186,7 +1185,7 @@ int drbd_bm_read(struct drbd_device *device) __must_hold(local) · 4 unmodified lines
11861185 */
11871186 int drbd_bm_write(struct drbd_device *device) __must_hold(local)
11881187 {
1189− return bm_rw(device, WRITE, 0, 0);
1188+ return bm_rw(device, 0, 0);
11901189 }
11911190
11921191 /**
@@ -1197,7 +1196,17 @@ int drbd_bm_write(struct drbd_device *device) __must_hold(local) · 4 unmodified lines
11971196 */
11981197 int drbd_bm_write_all(struct drbd_device *device) __must_hold(local)
11991198 {
1200− return bm_rw(device, WRITE, BM_WRITE_ALL_PAGES, 0);
1199+ return bm_rw(device, BM_AIO_WRITE_ALL_PAGES, 0);
1200+}
1201+
1202+/**
1203+ * drbd_bm_write_lazy() - Write bitmap pages 0 to @upper_idx-1, if they have changed.
1204+ * @device: DRBD device.
1205+ * @upper_idx: 0: write all changed pages; +ve: page index to stop scanning for changed pages
1206+ */
1207+int drbd_bm_write_lazy(struct drbd_device *device, unsigned upper_idx) __must_hold(local)
1208+{
1209+ return bm_rw(device, BM_AIO_COPY_PAGES, upper_idx);
12011210 }
12021211
12031212 /**
@@ -1213,7 +1222,7 @@ int drbd_bm_write_all(struct drbd_device *device) __must_hold(local) · 9 unmodified lines
12131222 */
12141223 int drbd_bm_write_copy_pages(struct drbd_device *device) __must_hold(local)
12151224 {
1216− return bm_rw(device, WRITE, BM_AIO_COPY_PAGES, 0);
1225+ return bm_rw(device, BM_AIO_COPY_PAGES, 0);
12171226 }
12181227
12191228 /**
@@ -1222,62 +1231,7 @@ int drbd_bm_write_copy_pages(struct drbd_device *device) __must_hold(local) · 2 unmodified lines
12221231 */
12231232 int drbd_bm_write_hinted(struct drbd_device *device) __must_hold(local)
12241233 {
1225− return bm_rw(device, WRITE, BM_AIO_WRITE_HINTED | BM_AIO_COPY_PAGES, 0);
1226−}
1227−
1228−/**
1229− * drbd_bm_write_page() - Writes a PAGE_SIZE aligned piece of bitmap
1230− * @device: DRBD device.
1231− * @idx: bitmap page index
1232− *
1233− * We don't want to special case on logical_block_size of the backend device,
1234− * so we submit PAGE_SIZE aligned pieces.
1235− * Note that on "most" systems, PAGE_SIZE is 4k.
1236− *
1237− * In case this becomes an issue on systems with larger PAGE_SIZE,
1238− * we may want to change this again to write 4k aligned 4k pieces.
1239− */
1240−int drbd_bm_write_page(struct drbd_device *device, unsigned int idx) __must_hold(local)
1241−{
1242− struct bm_aio_ctx *ctx;
1243− int err;
1244−
1245− if (bm_test_page_unchanged(device->bitmap->bm_pages[idx])) {
1246− dynamic_drbd_dbg(device, "skipped bm page write for idx %u\n", idx);
1247− return 0;
1248− }
1249−
1250− ctx = kmalloc(sizeof(struct bm_aio_ctx), GFP_NOIO);
1251− if (!ctx)
1252− return -ENOMEM;
1253−
1254− *ctx = (struct bm_aio_ctx) {
1255− .device = device,
1256− .in_flight = ATOMIC_INIT(1),
1257− .done = 0,
1258− .flags = BM_AIO_COPY_PAGES,
1259− .error = 0,
1260− .kref = { ATOMIC_INIT(2) },
1261− };
1262−
1263− if (!get_ldev_if_state(device, D_ATTACHING)) { /* put is in bm_aio_ctx_destroy() */
1264− drbd_err(device, "ASSERT FAILED: get_ldev_if_state() == 1 in drbd_bm_write_page()\n");
1265− kfree(ctx);
1266− return -ENODEV;
1267− }
1268−
1269− bm_page_io_async(ctx, idx, WRITE_SYNC);
1270− wait_until_done_or_force_detached(device, device->ldev, &ctx->done);
1271−
1272− if (ctx->error)
1273− drbd_chk_io_error(device, 1, DRBD_META_IO_ERROR);
1274− /* that causes us to detach, so the in memory bitmap will be
1275− * gone in a moment as well. */
1276−
1277− device->bm_writ_cnt++;
1278− err = atomic_read(&ctx->in_flight) ? -EIO : ctx->error;
1279− kref_put(&ctx->kref, &bm_aio_ctx_destroy);
1280− return err;
1234+ return bm_rw(device, BM_AIO_WRITE_HINTED | BM_AIO_COPY_PAGES, 0);
12811235 }
12821236
12831237 /* NOTE
drivers/block/drbd/drbd_debugfs.c+958−0
@@ -0,0 +1,958 @@
1+#define pr_fmt(fmt) "drbd debugfs: " fmt
2+#include <linux/kernel.h>
3+#include <linux/module.h>
4+#include <linux/debugfs.h>
5+#include <linux/seq_file.h>
6+#include <linux/stat.h>
7+#include <linux/jiffies.h>
8+#include <linux/list.h>
9+
10+#include "drbd_int.h"
11+#include "drbd_req.h"
12+#include "drbd_debugfs.h"
13+
14+
15+/**********************************************************************
16+ * Whenever you change the file format, remember to bump the version. *
17+ **********************************************************************/
18+
19+static struct dentry *drbd_debugfs_root;
20+static struct dentry *drbd_debugfs_version;
21+static struct dentry *drbd_debugfs_resources;
22+static struct dentry *drbd_debugfs_minors;
23+
24+static void seq_print_age_or_dash(struct seq_file *m, bool valid, unsigned long dt)
25+{
26+ if (valid)
27+ seq_printf(m, "\t%d", jiffies_to_msecs(dt));
28+ else
29+ seq_printf(m, "\t-");
30+}
31+
32+static void __seq_print_rq_state_bit(struct seq_file *m,
33+ bool is_set, char *sep, const char *set_name, const char *unset_name)
34+{
35+ if (is_set && set_name) {
36+ seq_putc(m, *sep);
37+ seq_puts(m, set_name);
38+ *sep = '|';
39+ } else if (!is_set && unset_name) {
40+ seq_putc(m, *sep);
41+ seq_puts(m, unset_name);
42+ *sep = '|';
43+ }
44+}
45+
46+static void seq_print_rq_state_bit(struct seq_file *m,
47+ bool is_set, char *sep, const char *set_name)
48+{
49+ __seq_print_rq_state_bit(m, is_set, sep, set_name, NULL);
50+}
51+
52+/* pretty print enum drbd_req_state_bits req->rq_state */
53+static void seq_print_request_state(struct seq_file *m, struct drbd_request *req)
54+{
55+ unsigned int s = req->rq_state;
56+ char sep = ' ';
57+ seq_printf(m, "\t0x%08x", s);
58+ seq_printf(m, "\tmaster: %s", req->master_bio ? "pending" : "completed");
59+
60+ /* RQ_WRITE ignored, already reported */
61+ seq_puts(m, "\tlocal:");
62+ seq_print_rq_state_bit(m, s & RQ_IN_ACT_LOG, &sep, "in-AL");
63+ seq_print_rq_state_bit(m, s & RQ_POSTPONED, &sep, "postponed");
64+ seq_print_rq_state_bit(m, s & RQ_COMPLETION_SUSP, &sep, "suspended");
65+ sep = ' ';
66+ seq_print_rq_state_bit(m, s & RQ_LOCAL_PENDING, &sep, "pending");
67+ seq_print_rq_state_bit(m, s & RQ_LOCAL_COMPLETED, &sep, "completed");
68+ seq_print_rq_state_bit(m, s & RQ_LOCAL_ABORTED, &sep, "aborted");
69+ seq_print_rq_state_bit(m, s & RQ_LOCAL_OK, &sep, "ok");
70+ if (sep == ' ')
71+ seq_puts(m, " -");
72+
73+ /* for_each_connection ... */
74+ seq_printf(m, "\tnet:");
75+ sep = ' ';
76+ seq_print_rq_state_bit(m, s & RQ_NET_PENDING, &sep, "pending");
77+ seq_print_rq_state_bit(m, s & RQ_NET_QUEUED, &sep, "queued");
78+ seq_print_rq_state_bit(m, s & RQ_NET_SENT, &sep, "sent");
79+ seq_print_rq_state_bit(m, s & RQ_NET_DONE, &sep, "done");
80+ seq_print_rq_state_bit(m, s & RQ_NET_SIS, &sep, "sis");
81+ seq_print_rq_state_bit(m, s & RQ_NET_OK, &sep, "ok");
82+ if (sep == ' ')
83+ seq_puts(m, " -");
84+
85+ seq_printf(m, " :");
86+ sep = ' ';
87+ seq_print_rq_state_bit(m, s & RQ_EXP_RECEIVE_ACK, &sep, "B");
88+ seq_print_rq_state_bit(m, s & RQ_EXP_WRITE_ACK, &sep, "C");
89+ seq_print_rq_state_bit(m, s & RQ_EXP_BARR_ACK, &sep, "barr");
90+ if (sep == ' ')
91+ seq_puts(m, " -");
92+ seq_printf(m, "\n");
93+}
94+
95+static void seq_print_one_request(struct seq_file *m, struct drbd_request *req, unsigned long now)
96+{
97+ /* change anything here, fixup header below! */
98+ unsigned int s = req->rq_state;
99+
100+#define RQ_HDR_1 "epoch\tsector\tsize\trw"
101+ seq_printf(m, "0x%x\t%llu\t%u\t%s",
102+ req->epoch,
103+ (unsigned long long)req->i.sector, req->i.size >> 9,
104+ (s & RQ_WRITE) ? "W" : "R");
105+
106+#define RQ_HDR_2 "\tstart\tin AL\tsubmit"
107+ seq_printf(m, "\t%d", jiffies_to_msecs(now - req->start_jif));
108+ seq_print_age_or_dash(m, s & RQ_IN_ACT_LOG, now - req->in_actlog_jif);
109+ seq_print_age_or_dash(m, s & RQ_LOCAL_PENDING, now - req->pre_submit_jif);
110+
111+#define RQ_HDR_3 "\tsent\tacked\tdone"
112+ seq_print_age_or_dash(m, s & RQ_NET_SENT, now - req->pre_send_jif);
113+ seq_print_age_or_dash(m, (s & RQ_NET_SENT) && !(s & RQ_NET_PENDING), now - req->acked_jif);
114+ seq_print_age_or_dash(m, s & RQ_NET_DONE, now - req->net_done_jif);
115+
116+#define RQ_HDR_4 "\tstate\n"
117+ seq_print_request_state(m, req);
118+}
119+#define RQ_HDR RQ_HDR_1 RQ_HDR_2 RQ_HDR_3 RQ_HDR_4
120+
121+static void seq_print_minor_vnr_req(struct seq_file *m, struct drbd_request *req, unsigned long now)
122+{
123+ seq_printf(m, "%u\t%u\t", req->device->minor, req->device->vnr);
124+ seq_print_one_request(m, req, now);
125+}
126+
127+static void seq_print_resource_pending_meta_io(struct seq_file *m, struct drbd_resource *resource, unsigned long now)
128+{
129+ struct drbd_device *device;
130+ unsigned int i;
131+
132+ seq_puts(m, "minor\tvnr\tstart\tsubmit\tintent\n");
133+ rcu_read_lock();
134+ idr_for_each_entry(&resource->devices, device, i) {
135+ struct drbd_md_io tmp;
136+ /* In theory this is racy,
137+ * in the sense that there could have been a
138+ * drbd_md_put_buffer(); drbd_md_get_buffer();
139+ * between accessing these members here. */
140+ tmp = device->md_io;
141+ if (atomic_read(&tmp.in_use)) {
142+ seq_printf(m, "%u\t%u\t%d\t",
143+ device->minor, device->vnr,
144+ jiffies_to_msecs(now - tmp.start_jif));
145+ if (time_before(tmp.submit_jif, tmp.start_jif))
146+ seq_puts(m, "-\t");
147+ else
148+ seq_printf(m, "%d\t", jiffies_to_msecs(now - tmp.submit_jif));
149+ seq_printf(m, "%s\n", tmp.current_use);
150+ }
151+ }
152+ rcu_read_unlock();
153+}
154+
155+static void seq_print_waiting_for_AL(struct seq_file *m, struct drbd_resource *resource, unsigned long now)
156+{
157+ struct drbd_device *device;
158+ unsigned int i;
159+
160+ seq_puts(m, "minor\tvnr\tage\t#waiting\n");
161+ rcu_read_lock();
162+ idr_for_each_entry(&resource->devices, device, i) {
163+ unsigned long jif;
164+ struct drbd_request *req;
165+ int n = atomic_read(&device->ap_actlog_cnt);
166+ if (n) {
167+ spin_lock_irq(&device->resource->req_lock);
168+ req = list_first_entry_or_null(&device->pending_master_completion[1],
169+ struct drbd_request, req_pending_master_completion);
170+ /* if the oldest request does not wait for the activity log
171+ * it is not interesting for us here */
172+ if (req && !(req->rq_state & RQ_IN_ACT_LOG))
173+ jif = req->start_jif;
174+ else
175+ req = NULL;
176+ spin_unlock_irq(&device->resource->req_lock);
177+ }
178+ if (n) {
179+ seq_printf(m, "%u\t%u\t", device->minor, device->vnr);
180+ if (req)
181+ seq_printf(m, "%u\t", jiffies_to_msecs(now - jif));
182+ else
183+ seq_puts(m, "-\t");
184+ seq_printf(m, "%u\n", n);
185+ }
186+ }
187+ rcu_read_unlock();
188+}
189+
190+static void seq_print_device_bitmap_io(struct seq_file *m, struct drbd_device *device, unsigned long now)
191+{
192+ struct drbd_bm_aio_ctx *ctx;
193+ unsigned long start_jif;
194+ unsigned int in_flight;
195+ unsigned int flags;
196+ spin_lock_irq(&device->resource->req_lock);
197+ ctx = list_first_entry_or_null(&device->pending_bitmap_io, struct drbd_bm_aio_ctx, list);
198+ if (ctx && ctx->done)
199+ ctx = NULL;
200+ if (ctx) {
201+ start_jif = ctx->start_jif;
202+ in_flight = atomic_read(&ctx->in_flight);
203+ flags = ctx->flags;
204+ }
205+ spin_unlock_irq(&device->resource->req_lock);
206+ if (ctx) {
207+ seq_printf(m, "%u\t%u\t%c\t%u\t%u\n",
208+ device->minor, device->vnr,
209+ (flags & BM_AIO_READ) ? 'R' : 'W',
210+ jiffies_to_msecs(now - start_jif),
211+ in_flight);
212+ }
213+}
214+
215+static void seq_print_resource_pending_bitmap_io(struct seq_file *m, struct drbd_resource *resource, unsigned long now)
216+{
217+ struct drbd_device *device;
218+ unsigned int i;
219+
220+ seq_puts(m, "minor\tvnr\trw\tage\t#in-flight\n");
221+ rcu_read_lock();
222+ idr_for_each_entry(&resource->devices, device, i) {
223+ seq_print_device_bitmap_io(m, device, now);
224+ }
225+ rcu_read_unlock();
226+}
227+
228+/* pretty print enum peer_req->flags */
229+static void seq_print_peer_request_flags(struct seq_file *m, struct drbd_peer_request *peer_req)
230+{
231+ unsigned long f = peer_req->flags;
232+ char sep = ' ';
233+
234+ __seq_print_rq_state_bit(m, f & EE_SUBMITTED, &sep, "submitted", "preparing");
235+ __seq_print_rq_state_bit(m, f & EE_APPLICATION, &sep, "application", "internal");
236+ seq_print_rq_state_bit(m, f & EE_CALL_AL_COMPLETE_IO, &sep, "in-AL");
237+ seq_print_rq_state_bit(m, f & EE_SEND_WRITE_ACK, &sep, "C");
238+ seq_print_rq_state_bit(m, f & EE_MAY_SET_IN_SYNC, &sep, "set-in-sync");
239+
240+ if (f & EE_IS_TRIM) {
241+ seq_putc(m, sep);
242+ sep = '|';
243+ if (f & EE_IS_TRIM_USE_ZEROOUT)
244+ seq_puts(m, "zero-out");
245+ else
246+ seq_puts(m, "trim");
247+ }
248+ seq_putc(m, '\n');
249+}
250+
251+static void seq_print_peer_request(struct seq_file *m,
252+ struct drbd_device *device, struct list_head *lh,
253+ unsigned long now)
254+{
255+ bool reported_preparing = false;
256+ struct drbd_peer_request *peer_req;
257+ list_for_each_entry(peer_req, lh, w.list) {
258+ if (reported_preparing && !(peer_req->flags & EE_SUBMITTED))
259+ continue;
260+
261+ if (device)
262+ seq_printf(m, "%u\t%u\t", device->minor, device->vnr);
263+
264+ seq_printf(m, "%llu\t%u\t%c\t%u\t",
265+ (unsigned long long)peer_req->i.sector, peer_req->i.size >> 9,
266+ (peer_req->flags & EE_WRITE) ? 'W' : 'R',
267+ jiffies_to_msecs(now - peer_req->submit_jif));
268+ seq_print_peer_request_flags(m, peer_req);
269+ if (peer_req->flags & EE_SUBMITTED)
270+ break;
271+ else
272+ reported_preparing = true;
273+ }
274+}
275+
276+static void seq_print_device_peer_requests(struct seq_file *m,
277+ struct drbd_device *device, unsigned long now)
278+{
279+ seq_puts(m, "minor\tvnr\tsector\tsize\trw\tage\tflags\n");
280+ spin_lock_irq(&device->resource->req_lock);
281+ seq_print_peer_request(m, device, &device->active_ee, now);
282+ seq_print_peer_request(m, device, &device->read_ee, now);
283+ seq_print_peer_request(m, device, &device->sync_ee, now);
284+ spin_unlock_irq(&device->resource->req_lock);
285+ if (test_bit(FLUSH_PENDING, &device->flags)) {
286+ seq_printf(m, "%u\t%u\t-\t-\tF\t%u\tflush\n",
287+ device->minor, device->vnr,
288+ jiffies_to_msecs(now - device->flush_jif));
289+ }
290+}
291+
292+static void seq_print_resource_pending_peer_requests(struct seq_file *m,
293+ struct drbd_resource *resource, unsigned long now)
294+{
295+ struct drbd_device *device;
296+ unsigned int i;
297+
298+ rcu_read_lock();
299+ idr_for_each_entry(&resource->devices, device, i) {
300+ seq_print_device_peer_requests(m, device, now);
301+ }
302+ rcu_read_unlock();
303+}
304+
305+static void seq_print_resource_transfer_log_summary(struct seq_file *m,
306+ struct drbd_resource *resource,
307+ struct drbd_connection *connection,
308+ unsigned long now)
309+{
310+ struct drbd_request *req;
311+ unsigned int count = 0;
312+ unsigned int show_state = 0;
313+
314+ seq_puts(m, "n\tdevice\tvnr\t" RQ_HDR);
315+ spin_lock_irq(&resource->req_lock);
316+ list_for_each_entry(req, &connection->transfer_log, tl_requests) {
317+ unsigned int tmp = 0;
318+ unsigned int s;
319+ ++count;
320+
321+ /* don't disable irq "forever" */
322+ if (!(count & 0x1ff)) {
323+ struct drbd_request *req_next;
324+ kref_get(&req->kref);
325+ spin_unlock_irq(&resource->req_lock);
326+ cond_resched();
327+ spin_lock_irq(&resource->req_lock);
328+ req_next = list_next_entry(req, tl_requests);
329+ if (kref_put(&req->kref, drbd_req_destroy))
330+ req = req_next;
331+ if (&req->tl_requests == &connection->transfer_log)
332+ break;
333+ }
334+
335+ s = req->rq_state;
336+
337+ /* This is meant to summarize timing issues, to be able to tell
338+ * local disk problems from network problems.
339+ * Skip requests, if we have shown an even older request with
340+ * similar aspects already. */
341+ if (req->master_bio == NULL)
342+ tmp |= 1;
343+ if ((s & RQ_LOCAL_MASK) && (s & RQ_LOCAL_PENDING))
344+ tmp |= 2;
345+ if (s & RQ_NET_MASK) {
346+ if (!(s & RQ_NET_SENT))
347+ tmp |= 4;
348+ if (s & RQ_NET_PENDING)
349+ tmp |= 8;
350+ if (!(s & RQ_NET_DONE))
351+ tmp |= 16;
352+ }
353+ if ((tmp & show_state) == tmp)
354+ continue;
355+ show_state |= tmp;
356+ seq_printf(m, "%u\t", count);
357+ seq_print_minor_vnr_req(m, req, now);
358+ if (show_state == 0x1f)
359+ break;
360+ }
361+ spin_unlock_irq(&resource->req_lock);
362+}
363+
364+/* TODO: transfer_log and friends should be moved to resource */
365+static int in_flight_summary_show(struct seq_file *m, void *pos)
366+{
367+ struct drbd_resource *resource = m->private;
368+ struct drbd_connection *connection;
369+ unsigned long jif = jiffies;
370+
371+ connection = first_connection(resource);
372+ /* This does not happen, actually.
373+ * But be robust and prepare for future code changes. */
374+ if (!connection || !kref_get_unless_zero(&connection->kref))
375+ return -ESTALE;
376+
377+ /* BUMP me if you change the file format/content/presentation */
378+ seq_printf(m, "v: %u\n\n", 0);
379+
380+ seq_puts(m, "oldest bitmap IO\n");
381+ seq_print_resource_pending_bitmap_io(m, resource, jif);
382+ seq_putc(m, '\n');
383+
384+ seq_puts(m, "meta data IO\n");
385+ seq_print_resource_pending_meta_io(m, resource, jif);
386+ seq_putc(m, '\n');
387+
388+ seq_puts(m, "socket buffer stats\n");
389+ /* for each connection ... once we have more than one */
390+ rcu_read_lock();
391+ if (connection->data.socket) {
392+ /* open coded SIOCINQ, the "relevant" part */
393+ struct tcp_sock *tp = tcp_sk(connection->data.socket->sk);
394+ int answ = tp->rcv_nxt - tp->copied_seq;
395+ seq_printf(m, "unread receive buffer: %u Byte\n", answ);
396+ /* open coded SIOCOUTQ, the "relevant" part */
397+ answ = tp->write_seq - tp->snd_una;
398+ seq_printf(m, "unacked send buffer: %u Byte\n", answ);
399+ }
400+ rcu_read_unlock();
401+ seq_putc(m, '\n');
402+
403+ seq_puts(m, "oldest peer requests\n");
404+ seq_print_resource_pending_peer_requests(m, resource, jif);
405+ seq_putc(m, '\n');
406+
407+ seq_puts(m, "application requests waiting for activity log\n");
408+ seq_print_waiting_for_AL(m, resource, jif);
409+ seq_putc(m, '\n');
410+
411+ seq_puts(m, "oldest application requests\n");
412+ seq_print_resource_transfer_log_summary(m, resource, connection, jif);
413+ seq_putc(m, '\n');
414+
415+ jif = jiffies - jif;
416+ if (jif)
417+ seq_printf(m, "generated in %d ms\n", jiffies_to_msecs(jif));
418+ kref_put(&connection->kref, drbd_destroy_connection);
419+ return 0;
420+}
421+
422+/* simple_positive(file->f_dentry) respectively debugfs_positive(),
423+ * but neither is "reachable" from here.
424+ * So we have our own inline version of it above. :-( */
425+static inline int debugfs_positive(struct dentry *dentry)
426+{
427+ return dentry->d_inode && !d_unhashed(dentry);
428+}
429+
430+/* make sure at *open* time that the respective object won't go away. */
431+static int drbd_single_open(struct file *file, int (*show)(struct seq_file *, void *),
432+ void *data, struct kref *kref,
433+ void (*release)(struct kref *))
434+{
435+ struct dentry *parent;
436+ int ret = -ESTALE;
437+
438+ /* Are we still linked,
439+ * or has debugfs_remove() already been called? */
440+ parent = file->f_dentry->d_parent;
441+ /* not sure if this can happen: */
442+ if (!parent || !parent->d_inode)
443+ goto out;
444+ /* serialize with d_delete() */
445+ mutex_lock(&parent->d_inode->i_mutex);
446+ /* Make sure the object is still alive */
447+ if (debugfs_positive(file->f_dentry)
448+ && kref_get_unless_zero(kref))
449+ ret = 0;
450+ mutex_unlock(&parent->d_inode->i_mutex);
451+ if (!ret) {
452+ ret = single_open(file, show, data);
453+ if (ret)
454+ kref_put(kref, release);
455+ }
456+out:
457+ return ret;
458+}
459+
460+static int in_flight_summary_open(struct inode *inode, struct file *file)
461+{
462+ struct drbd_resource *resource = inode->i_private;
463+ return drbd_single_open(file, in_flight_summary_show, resource,
464+ &resource->kref, drbd_destroy_resource);
465+}
466+
467+static int in_flight_summary_release(struct inode *inode, struct file *file)
468+{
469+ struct drbd_resource *resource = inode->i_private;
470+ kref_put(&resource->kref, drbd_destroy_resource);
471+ return single_release(inode, file);
472+}
473+
474+static const struct file_operations in_flight_summary_fops = {
475+ .owner = THIS_MODULE,
476+ .open = in_flight_summary_open,
477+ .read = seq_read,
478+ .llseek = seq_lseek,
479+ .release = in_flight_summary_release,
480+};
481+
482+void drbd_debugfs_resource_add(struct drbd_resource *resource)
483+{
484+ struct dentry *dentry;
485+ if (!drbd_debugfs_resources)
486+ return;
487+
488+ dentry = debugfs_create_dir(resource->name, drbd_debugfs_resources);
489+ if (IS_ERR_OR_NULL(dentry))
490+ goto fail;
491+ resource->debugfs_res = dentry;
492+
493+ dentry = debugfs_create_dir("volumes", resource->debugfs_res);
494+ if (IS_ERR_OR_NULL(dentry))
495+ goto fail;
496+ resource->debugfs_res_volumes = dentry;
497+
498+ dentry = debugfs_create_dir("connections", resource->debugfs_res);
499+ if (IS_ERR_OR_NULL(dentry))
500+ goto fail;
501+ resource->debugfs_res_connections = dentry;
502+
503+ dentry = debugfs_create_file("in_flight_summary", S_IRUSR|S_IRGRP,
504+ resource->debugfs_res, resource,
505+ &in_flight_summary_fops);
506+ if (IS_ERR_OR_NULL(dentry))
507+ goto fail;
508+ resource->debugfs_res_in_flight_summary = dentry;
509+ return;
510+
511+fail:
512+ drbd_debugfs_resource_cleanup(resource);
513+ drbd_err(resource, "failed to create debugfs dentry\n");
514+}
515+
516+static void drbd_debugfs_remove(struct dentry **dp)
517+{
518+ debugfs_remove(*dp);
519+ *dp = NULL;
520+}
521+
522+void drbd_debugfs_resource_cleanup(struct drbd_resource *resource)
523+{
524+ /* it is ok to call debugfs_remove(NULL) */
525+ drbd_debugfs_remove(&resource->debugfs_res_in_flight_summary);
526+ drbd_debugfs_remove(&resource->debugfs_res_connections);
527+ drbd_debugfs_remove(&resource->debugfs_res_volumes);
528+ drbd_debugfs_remove(&resource->debugfs_res);
529+}
530+
531+static void seq_print_one_timing_detail(struct seq_file *m,
532+ const struct drbd_thread_timing_details *tdp,
533+ unsigned long now)
534+{
535+ struct drbd_thread_timing_details td;
536+ /* No locking...
537+ * use temporary assignment to get at consistent data. */
538+ do {
539+ td = *tdp;
540+ } while (td.cb_nr != tdp->cb_nr);
541+ if (!td.cb_addr)
542+ return;
543+ seq_printf(m, "%u\t%d\t%s:%u\t%ps\n",
544+ td.cb_nr,
545+ jiffies_to_msecs(now - td.start_jif),
546+ td.caller_fn, td.line,
547+ td.cb_addr);
548+}
549+
550+static void seq_print_timing_details(struct seq_file *m,
551+ const char *title,
552+ unsigned int cb_nr, struct drbd_thread_timing_details *tdp, unsigned long now)
553+{
554+ unsigned int start_idx;
555+ unsigned int i;
556+
557+ seq_printf(m, "%s\n", title);
558+ /* If not much is going on, this will result in natural ordering.
559+ * If it is very busy, we will possibly skip events, or even see wrap
560+ * arounds, which could only be avoided with locking.
561+ */
562+ start_idx = cb_nr % DRBD_THREAD_DETAILS_HIST;
563+ for (i = start_idx; i < DRBD_THREAD_DETAILS_HIST; i++)
564+ seq_print_one_timing_detail(m, tdp+i, now);
565+ for (i = 0; i < start_idx; i++)
566+ seq_print_one_timing_detail(m, tdp+i, now);
567+}
568+
569+static int callback_history_show(struct seq_file *m, void *ignored)
570+{
571+ struct drbd_connection *connection = m->private;
572+ unsigned long jif = jiffies;
573+
574+ /* BUMP me if you change the file format/content/presentation */
575+ seq_printf(m, "v: %u\n\n", 0);
576+
577+ seq_puts(m, "n\tage\tcallsite\tfn\n");
578+ seq_print_timing_details(m, "worker", connection->w_cb_nr, connection->w_timing_details, jif);
579+ seq_print_timing_details(m, "receiver", connection->r_cb_nr, connection->r_timing_details, jif);
580+ return 0;
581+}
582+
583+static int callback_history_open(struct inode *inode, struct file *file)
584+{
585+ struct drbd_connection *connection = inode->i_private;
586+ return drbd_single_open(file, callback_history_show, connection,
587+ &connection->kref, drbd_destroy_connection);
588+}
589+
590+static int callback_history_release(struct inode *inode, struct file *file)
591+{
592+ struct drbd_connection *connection = inode->i_private;
593+ kref_put(&connection->kref, drbd_destroy_connection);
594+ return single_release(inode, file);
595+}
596+
597+static const struct file_operations connection_callback_history_fops = {
598+ .owner = THIS_MODULE,
599+ .open = callback_history_open,
600+ .read = seq_read,
601+ .llseek = seq_lseek,
602+ .release = callback_history_release,
603+};
604+
605+static int connection_oldest_requests_show(struct seq_file *m, void *ignored)
606+{
607+ struct drbd_connection *connection = m->private;
608+ unsigned long now = jiffies;
609+ struct drbd_request *r1, *r2;
610+
611+ /* BUMP me if you change the file format/content/presentation */
612+ seq_printf(m, "v: %u\n\n", 0);
613+
614+ spin_lock_irq(&connection->resource->req_lock);
615+ r1 = connection->req_next;
616+ if (r1)
617+ seq_print_minor_vnr_req(m, r1, now);
618+ r2 = connection->req_ack_pending;
619+ if (r2 && r2 != r1) {
620+ r1 = r2;
621+ seq_print_minor_vnr_req(m, r1, now);
622+ }
623+ r2 = connection->req_not_net_done;
624+ if (r2 && r2 != r1)
625+ seq_print_minor_vnr_req(m, r2, now);
626+ spin_unlock_irq(&connection->resource->req_lock);
627+ return 0;
628+}
629+
630+static int connection_oldest_requests_open(struct inode *inode, struct file *file)
631+{
632+ struct drbd_connection *connection = inode->i_private;
633+ return drbd_single_open(file, connection_oldest_requests_show, connection,
634+ &connection->kref, drbd_destroy_connection);
635+}
636+
637+static int connection_oldest_requests_release(struct inode *inode, struct file *file)
638+{
639+ struct drbd_connection *connection = inode->i_private;
640+ kref_put(&connection->kref, drbd_destroy_connection);
641+ return single_release(inode, file);
642+}
643+
644+static const struct file_operations connection_oldest_requests_fops = {
645+ .owner = THIS_MODULE,
646+ .open = connection_oldest_requests_open,
647+ .read = seq_read,
648+ .llseek = seq_lseek,
649+ .release = connection_oldest_requests_release,
650+};
651+
652+void drbd_debugfs_connection_add(struct drbd_connection *connection)
653+{
654+ struct dentry *conns_dir = connection->resource->debugfs_res_connections;
655+ struct dentry *dentry;
656+ if (!conns_dir)
657+ return;
658+
659+ /* Once we enable mutliple peers,
660+ * these connections will have descriptive names.
661+ * For now, it is just the one connection to the (only) "peer". */
662+ dentry = debugfs_create_dir("peer", conns_dir);
663+ if (IS_ERR_OR_NULL(dentry))
664+ goto fail;
665+ connection->debugfs_conn = dentry;
666+
667+ dentry = debugfs_create_file("callback_history", S_IRUSR|S_IRGRP,
668+ connection->debugfs_conn, connection,
669+ &connection_callback_history_fops);
670+ if (IS_ERR_OR_NULL(dentry))
671+ goto fail;
672+ connection->debugfs_conn_callback_history = dentry;
673+
674+ dentry = debugfs_create_file("oldest_requests", S_IRUSR|S_IRGRP,
675+ connection->debugfs_conn, connection,
676+ &connection_oldest_requests_fops);
677+ if (IS_ERR_OR_NULL(dentry))
678+ goto fail;
679+ connection->debugfs_conn_oldest_requests = dentry;
680+ return;
681+
682+fail:
683+ drbd_debugfs_connection_cleanup(connection);
684+ drbd_err(connection, "failed to create debugfs dentry\n");
685+}
686+
687+void drbd_debugfs_connection_cleanup(struct drbd_connection *connection)
688+{
689+ drbd_debugfs_remove(&connection->debugfs_conn_callback_history);
690+ drbd_debugfs_remove(&connection->debugfs_conn_oldest_requests);
691+ drbd_debugfs_remove(&connection->debugfs_conn);
692+}
693+
694+static void resync_dump_detail(struct seq_file *m, struct lc_element *e)
695+{
696+ struct bm_extent *bme = lc_entry(e, struct bm_extent, lce);
697+
698+ seq_printf(m, "%5d %s %s %s\n", bme->rs_left,
699+ test_bit(BME_NO_WRITES, &bme->flags) ? "NO_WRITES" : "---------",
700+ test_bit(BME_LOCKED, &bme->flags) ? "LOCKED" : "------",
701+ test_bit(BME_PRIORITY, &bme->flags) ? "PRIORITY" : "--------"
702+ );
703+}
704+
705+static int device_resync_extents_show(struct seq_file *m, void *ignored)
706+{
707+ struct drbd_device *device = m->private;
708+
709+ /* BUMP me if you change the file format/content/presentation */
710+ seq_printf(m, "v: %u\n\n", 0);
711+
712+ if (get_ldev_if_state(device, D_FAILED)) {
713+ lc_seq_printf_stats(m, device->resync);
714+ lc_seq_dump_details(m, device->resync, "rs_left flags", resync_dump_detail);
715+ put_ldev(device);
716+ }
717+ return 0;
718+}
719+
720+static int device_act_log_extents_show(struct seq_file *m, void *ignored)
721+{
722+ struct drbd_device *device = m->private;
723+
724+ /* BUMP me if you change the file format/content/presentation */
725+ seq_printf(m, "v: %u\n\n", 0);
726+
727+ if (get_ldev_if_state(device, D_FAILED)) {
728+ lc_seq_printf_stats(m, device->act_log);
729+ lc_seq_dump_details(m, device->act_log, "", NULL);
730+ put_ldev(device);
731+ }
732+ return 0;
733+}
734+
735+static int device_oldest_requests_show(struct seq_file *m, void *ignored)
736+{
737+ struct drbd_device *device = m->private;
738+ struct drbd_resource *resource = device->resource;
739+ unsigned long now = jiffies;
740+ struct drbd_request *r1, *r2;
741+ int i;
742+
743+ /* BUMP me if you change the file format/content/presentation */
744+ seq_printf(m, "v: %u\n\n", 0);
745+
746+ seq_puts(m, RQ_HDR);
747+ spin_lock_irq(&resource->req_lock);
748+ /* WRITE, then READ */
749+ for (i = 1; i >= 0; --i) {
750+ r1 = list_first_entry_or_null(&device->pending_master_completion[i],
751+ struct drbd_request, req_pending_master_completion);
752+ r2 = list_first_entry_or_null(&device->pending_completion[i],
753+ struct drbd_request, req_pending_local);
754+ if (r1)
755+ seq_print_one_request(m, r1, now);
756+ if (r2 && r2 != r1)
757+ seq_print_one_request(m, r2, now);
758+ }
759+ spin_unlock_irq(&resource->req_lock);
760+ return 0;
761+}
762+
763+static int device_data_gen_id_show(struct seq_file *m, void *ignored)
764+{
765+ struct drbd_device *device = m->private;
766+ struct drbd_md *md;
767+ enum drbd_uuid_index idx;
768+
769+ if (!get_ldev_if_state(device, D_FAILED))
770+ return -ENODEV;
771+
772+ md = &device->ldev->md;
773+ spin_lock_irq(&md->uuid_lock);
774+ for (idx = UI_CURRENT; idx <= UI_HISTORY_END; idx++) {
775+ seq_printf(m, "0x%016llX\n", md->uuid[idx]);
776+ }
777+ spin_unlock_irq(&md->uuid_lock);
778+ put_ldev(device);
779+ return 0;
780+}
781+
782+#define drbd_debugfs_device_attr(name) \
783+static int device_ ## name ## _open(struct inode *inode, struct file *file) \
784+{ \
785+ struct drbd_device *device = inode->i_private; \
786+ return drbd_single_open(file, device_ ## name ## _show, device, \
787+ &device->kref, drbd_destroy_device); \
788+} \
789+static int device_ ## name ## _release(struct inode *inode, struct file *file) \
790+{ \
791+ struct drbd_device *device = inode->i_private; \
792+ kref_put(&device->kref, drbd_destroy_device); \
793+ return single_release(inode, file); \
794+} \
795+static const struct file_operations device_ ## name ## _fops = { \
796+ .owner = THIS_MODULE, \
797+ .open = device_ ## name ## _open, \
798+ .read = seq_read, \
799+ .llseek = seq_lseek, \
800+ .release = device_ ## name ## _release, \
801+};
802+
803+drbd_debugfs_device_attr(oldest_requests)
804+drbd_debugfs_device_attr(act_log_extents)
805+drbd_debugfs_device_attr(resync_extents)
806+drbd_debugfs_device_attr(data_gen_id)
807+
808+void drbd_debugfs_device_add(struct drbd_device *device)
809+{
810+ struct dentry *vols_dir = device->resource->debugfs_res_volumes;
811+ char minor_buf[8]; /* MINORMASK, MINORBITS == 20; */
812+ char vnr_buf[8]; /* volume number vnr is even 16 bit only; */
813+ char *slink_name = NULL;
814+
815+ struct dentry *dentry;
816+ if (!vols_dir || !drbd_debugfs_minors)
817+ return;
818+
819+ snprintf(vnr_buf, sizeof(vnr_buf), "%u", device->vnr);
820+ dentry = debugfs_create_dir(vnr_buf, vols_dir);
821+ if (IS_ERR_OR_NULL(dentry))
822+ goto fail;
823+ device->debugfs_vol = dentry;
824+
825+ snprintf(minor_buf, sizeof(minor_buf), "%u", device->minor);
826+ slink_name = kasprintf(GFP_KERNEL, "../resources/%s/volumes/%u",
827+ device->resource->name, device->vnr);
828+ if (!slink_name)
829+ goto fail;
830+ dentry = debugfs_create_symlink(minor_buf, drbd_debugfs_minors, slink_name);
831+ kfree(slink_name);
832+ slink_name = NULL;
833+ if (IS_ERR_OR_NULL(dentry))
834+ goto fail;
835+ device->debugfs_minor = dentry;
836+
837+#define DCF(name) do { \
838+ dentry = debugfs_create_file(#name, S_IRUSR|S_IRGRP, \
839+ device->debugfs_vol, device, \
840+ &device_ ## name ## _fops); \
841+ if (IS_ERR_OR_NULL(dentry)) \
842+ goto fail; \
843+ device->debugfs_vol_ ## name = dentry; \
844+ } while (0)
845+
846+ DCF(oldest_requests);
847+ DCF(act_log_extents);
848+ DCF(resync_extents);
849+ DCF(data_gen_id);
850+#undef DCF
851+ return;
852+
853+fail:
854+ drbd_debugfs_device_cleanup(device);
855+ drbd_err(device, "failed to create debugfs entries\n");
856+}
857+
858+void drbd_debugfs_device_cleanup(struct drbd_device *device)
859+{
860+ drbd_debugfs_remove(&device->debugfs_minor);
861+ drbd_debugfs_remove(&device->debugfs_vol_oldest_requests);
862+ drbd_debugfs_remove(&device->debugfs_vol_act_log_extents);
863+ drbd_debugfs_remove(&device->debugfs_vol_resync_extents);
864+ drbd_debugfs_remove(&device->debugfs_vol_data_gen_id);
865+ drbd_debugfs_remove(&device->debugfs_vol);
866+}
867+
868+void drbd_debugfs_peer_device_add(struct drbd_peer_device *peer_device)
869+{
870+ struct dentry *conn_dir = peer_device->connection->debugfs_conn;
871+ struct dentry *dentry;
872+ char vnr_buf[8];
873+
874+ if (!conn_dir)
875+ return;
876+
877+ snprintf(vnr_buf, sizeof(vnr_buf), "%u", peer_device->device->vnr);
878+ dentry = debugfs_create_dir(vnr_buf, conn_dir);
879+ if (IS_ERR_OR_NULL(dentry))
880+ goto fail;
881+ peer_device->debugfs_peer_dev = dentry;
882+ return;
883+
884+fail:
885+ drbd_debugfs_peer_device_cleanup(peer_device);
886+ drbd_err(peer_device, "failed to create debugfs entries\n");
887+}
888+
889+void drbd_debugfs_peer_device_cleanup(struct drbd_peer_device *peer_device)
890+{
891+ drbd_debugfs_remove(&peer_device->debugfs_peer_dev);
892+}
893+
894+static int drbd_version_show(struct seq_file *m, void *ignored)
895+{
896+ seq_printf(m, "# %s\n", drbd_buildtag());
897+ seq_printf(m, "VERSION=%s\n", REL_VERSION);
898+ seq_printf(m, "API_VERSION=%u\n", API_VERSION);
899+ seq_printf(m, "PRO_VERSION_MIN=%u\n", PRO_VERSION_MIN);
900+ seq_printf(m, "PRO_VERSION_MAX=%u\n", PRO_VERSION_MAX);
901+ return 0;
902+}
903+
904+static int drbd_version_open(struct inode *inode, struct file *file)
905+{
906+ return single_open(file, drbd_version_show, NULL);
907+}
908+
909+static struct file_operations drbd_version_fops = {
910+ .owner = THIS_MODULE,
911+ .open = drbd_version_open,
912+ .llseek = seq_lseek,
913+ .read = seq_read,
914+ .release = single_release,
915+};
916+
917+/* not __exit, may be indirectly called
918+ * from the module-load-failure path as well. */
919+void drbd_debugfs_cleanup(void)
920+{
921+ drbd_debugfs_remove(&drbd_debugfs_resources);
922+ drbd_debugfs_remove(&drbd_debugfs_minors);
923+ drbd_debugfs_remove(&drbd_debugfs_version);
924+ drbd_debugfs_remove(&drbd_debugfs_root);
925+}
926+
927+int __init drbd_debugfs_init(void)
928+{
929+ struct dentry *dentry;
930+
931+ dentry = debugfs_create_dir("drbd", NULL);
932+ if (IS_ERR_OR_NULL(dentry))
933+ goto fail;
934+ drbd_debugfs_root = dentry;
935+
936+ dentry = debugfs_create_file("version", 0444, drbd_debugfs_root, NULL, &drbd_version_fops);
937+ if (IS_ERR_OR_NULL(dentry))
938+ goto fail;
939+ drbd_debugfs_version = dentry;
940+
941+ dentry = debugfs_create_dir("resources", drbd_debugfs_root);
942+ if (IS_ERR_OR_NULL(dentry))
943+ goto fail;
944+ drbd_debugfs_resources = dentry;
945+
946+ dentry = debugfs_create_dir("minors", drbd_debugfs_root);
947+ if (IS_ERR_OR_NULL(dentry))
948+ goto fail;
949+ drbd_debugfs_minors = dentry;
950+ return 0;
951+
952+fail:
953+ drbd_debugfs_cleanup();
954+ if (dentry)
955+ return PTR_ERR(dentry);
956+ else
957+ return -EINVAL;
958+}
drivers/block/drbd/drbd_debugfs.h+39−0
@@ -0,0 +1,39 @@
1+#include <linux/kernel.h>
2+#include <linux/module.h>
3+#include <linux/debugfs.h>
4+
5+#include "drbd_int.h"
6+
7+#ifdef CONFIG_DEBUG_FS
8+int __init drbd_debugfs_init(void);
9+void drbd_debugfs_cleanup(void);
10+
11+void drbd_debugfs_resource_add(struct drbd_resource *resource);
12+void drbd_debugfs_resource_cleanup(struct drbd_resource *resource);
13+
14+void drbd_debugfs_connection_add(struct drbd_connection *connection);
15+void drbd_debugfs_connection_cleanup(struct drbd_connection *connection);
16+
17+void drbd_debugfs_device_add(struct drbd_device *device);
18+void drbd_debugfs_device_cleanup(struct drbd_device *device);
19+
20+void drbd_debugfs_peer_device_add(struct drbd_peer_device *peer_device);
21+void drbd_debugfs_peer_device_cleanup(struct drbd_peer_device *peer_device);
22+#else
23+
24+static inline int __init drbd_debugfs_init(void) { return -ENODEV; }
25+static inline void drbd_debugfs_cleanup(void) { }
26+
27+static inline void drbd_debugfs_resource_add(struct drbd_resource *resource) { }
28+static inline void drbd_debugfs_resource_cleanup(struct drbd_resource *resource) { }
29+
30+static inline void drbd_debugfs_connection_add(struct drbd_connection *connection) { }
31+static inline void drbd_debugfs_connection_cleanup(struct drbd_connection *connection) { }
32+
33+static inline void drbd_debugfs_device_add(struct drbd_device *device) { }
34+static inline void drbd_debugfs_device_cleanup(struct drbd_device *device) { }
35+
36+static inline void drbd_debugfs_peer_device_add(struct drbd_peer_device *peer_device) { }
37+static inline void drbd_debugfs_peer_device_cleanup(struct drbd_peer_device *peer_device) { }
38+
39+#endif
drivers/block/drbd/drbd_int.h+252−131
@@ -317,7 +317,63 @@ struct drbd_request { · 316 unmodified lines
317317
318318 struct list_head tl_requests; /* ring list in the transfer log */
319319 struct bio *master_bio; /* master bio pointer */
320− unsigned long start_time;
320+
321+ /* see struct drbd_device */
322+ struct list_head req_pending_master_completion;
323+ struct list_head req_pending_local;
324+
325+ /* for generic IO accounting */
326+ unsigned long start_jif;
327+
328+ /* for DRBD internal statistics */
329+
330+ /* Minimal set of time stamps to determine if we wait for activity log
331+ * transactions, local disk or peer. 32 bit "jiffies" are good enough,
332+ * we don't expect a DRBD request to be stalled for several month.
333+ */
334+
335+ /* before actual request processing */
336+ unsigned long in_actlog_jif;
337+
338+ /* local disk */
339+ unsigned long pre_submit_jif;
340+
341+ /* per connection */
342+ unsigned long pre_send_jif;
343+ unsigned long acked_jif;
344+ unsigned long net_done_jif;
345+
346+ /* Possibly even more detail to track each phase:
347+ * master_completion_jif
348+ * how long did it take to complete the master bio
349+ * (application visible latency)
350+ * allocated_jif
351+ * how long the master bio was blocked until we finally allocated
352+ * a tracking struct
353+ * in_actlog_jif
354+ * how long did we wait for activity log transactions
355+ *
356+ * net_queued_jif
357+ * when did we finally queue it for sending
358+ * pre_send_jif
359+ * when did we start sending it
360+ * post_send_jif
361+ * how long did we block in the network stack trying to send it
362+ * acked_jif
363+ * when did we receive (or fake, in protocol A) a remote ACK
364+ * net_done_jif
365+ * when did we receive final acknowledgement (P_BARRIER_ACK),
366+ * or decide, e.g. on connection loss, that we do no longer expect
367+ * anything from this peer for this request.
368+ *
369+ * pre_submit_jif
370+ * post_sub_jif
371+ * when did we start submiting to the lower level device,
372+ * and how long did we block in that submit function
373+ * local_completion_jif
374+ * how long did it take the lower level device to complete this request
375+ */
376+
321377
322378 /* once it hits 0, we may complete the master_bio */
323379 atomic_t completion_ref;
@@ -366,6 +422,7 @@ struct drbd_peer_request { · 42 unmodified lines
366422 struct drbd_interval i;
367423 /* see comments on ee flag bits below */
368424 unsigned long flags;
425+ unsigned long submit_jif;
369426 union {
370427 u64 block_id;
371428 struct digest_info *digest;
@@ -408,6 +465,17 @@ enum { · 36 unmodified lines
408465
409466 /* Is set when net_conf had two_primaries set while creating this peer_req */
410467 __EE_IN_INTERVAL_TREE,
468+
469+ /* for debugfs: */
470+ /* has this been submitted, or does it still wait for something else? */
471+ __EE_SUBMITTED,
472+
473+ /* this is/was a write request */
474+ __EE_WRITE,
475+
476+ /* this originates from application on peer
477+ * (not some resync or verify or other DRBD internal request) */
478+ __EE_APPLICATION,
411479 };
412480 #define EE_CALL_AL_COMPLETE_IO (1<<__EE_CALL_AL_COMPLETE_IO)
413481 #define EE_MAY_SET_IN_SYNC (1<<__EE_MAY_SET_IN_SYNC)
@@ -419,6 +487,9 @@ enum { · 5 unmodified lines
419487 #define EE_RESTART_REQUESTS (1<<__EE_RESTART_REQUESTS)
420488 #define EE_SEND_WRITE_ACK (1<<__EE_SEND_WRITE_ACK)
421489 #define EE_IN_INTERVAL_TREE (1<<__EE_IN_INTERVAL_TREE)
490+#define EE_SUBMITTED (1<<__EE_SUBMITTED)
491+#define EE_WRITE (1<<__EE_WRITE)
492+#define EE_APPLICATION (1<<__EE_APPLICATION)
422493
423494 /* flag bits per device */
424495 enum {
@@ -433,11 +504,11 @@ enum { · 8 unmodified lines
433504 CONSIDER_RESYNC,
434505
435506 MD_NO_FUA, /* Users wants us to not use FUA/FLUSH on meta data dev */
507+
436508 SUSPEND_IO, /* suspend application io */
437509 BITMAP_IO, /* suspend application io;
438510 once no more io in flight, start bitmap io */
439511 BITMAP_IO_QUEUED, /* Started bitmap IO */
440− GO_DISKLESS, /* Disk is being detached, on io-error or admin request. */
441512 WAS_IO_ERROR, /* Local disk failed, returned IO error */
442513 WAS_READ_ERROR, /* Local disk READ failed (set additionally to the above) */
443514 FORCE_DETACH, /* Force-detach from local disk, aborting any pending local IO */
@@ -450,6 +521,20 @@ enum { · 6 unmodified lines
450521 B_RS_H_DONE, /* Before resync handler done (already executed) */
451522 DISCARD_MY_DATA, /* discard_my_data flag per volume */
452523 READ_BALANCE_RR,
524+
525+ FLUSH_PENDING, /* if set, device->flush_jif is when we submitted that flush
526+ * from drbd_flush_after_epoch() */
527+
528+ /* cleared only after backing device related structures have been destroyed. */
529+ GOING_DISKLESS, /* Disk is being detached, because of io-error, or admin request. */
530+
531+ /* to be used in drbd_device_post_work() */
532+ GO_DISKLESS, /* tell worker to schedule cleanup before detach */
533+ DESTROY_DISK, /* tell worker to close backing devices and destroy related structures. */
534+ MD_SYNC, /* tell worker to call drbd_md_sync() */
535+ RS_START, /* tell worker to start resync/OV */
536+ RS_PROGRESS, /* tell worker that resync made significant progress */
537+ RS_DONE, /* tell worker that resync is done */
453538 };
454539
455540 struct drbd_bitmap; /* opaque for drbd_device */
@@ -531,6 +616,11 @@ struct drbd_backing_dev { · 75 unmodified lines
531616 };
532617
533618 struct drbd_md_io {
619+ struct page *page;
620+ unsigned long start_jif; /* last call to drbd_md_get_buffer */
621+ unsigned long submit_jif; /* last _drbd_md_sync_page_io() submit */
622+ const char *current_use;
623+ atomic_t in_use;
534624 unsigned int done;
535625 int error;
536626 };
@@ -577,10 +667,18 @@ enum { · 40 unmodified lines
577667 * and potentially deadlock on, this drbd worker.
578668 */
579669 DISCONNECT_SENT,
670+
671+ DEVICE_WORK_PENDING, /* tell worker that some device has pending work */
580672 };
581673
582674 struct drbd_resource {
583675 char *name;
676+#ifdef CONFIG_DEBUG_FS
677+ struct dentry *debugfs_res;
678+ struct dentry *debugfs_res_volumes;
679+ struct dentry *debugfs_res_connections;
680+ struct dentry *debugfs_res_in_flight_summary;
681+#endif
584682 struct kref kref;
585683 struct idr devices; /* volume number to device mapping */
586684 struct list_head connections;
@@ -594,12 +692,28 @@ struct drbd_resource { · 7 unmodified lines
594692 unsigned susp_nod:1; /* IO suspended because no data */
595693 unsigned susp_fen:1; /* IO suspended because fence peer handler runs */
596694
695+ enum write_ordering_e write_ordering;
696+
597697 cpumask_var_t cpu_mask;
598698 };
599699
700+struct drbd_thread_timing_details
701+{
702+ unsigned long start_jif;
703+ void *cb_addr;
704+ const char *caller_fn;
705+ unsigned int line;
706+ unsigned int cb_nr;
707+};
708+
600709 struct drbd_connection {
601710 struct list_head connections;
602711 struct drbd_resource *resource;
712+#ifdef CONFIG_DEBUG_FS
713+ struct dentry *debugfs_conn;
714+ struct dentry *debugfs_conn_callback_history;
715+ struct dentry *debugfs_conn_oldest_requests;
716+#endif
603717 struct kref kref;
604718 struct idr peer_devices; /* volume number to peer device mapping */
605719 enum drbd_conns cstate; /* Only C_STANDALONE to C_WF_REPORT_PARAMS */
@@ -636,7 +750,6 @@ struct drbd_connection { · 30 unmodified lines
636750 struct drbd_epoch *current_epoch;
637751 spinlock_t epoch_lock;
638752 unsigned int epochs;
639− enum write_ordering_e write_ordering;
640753 atomic_t current_tle_nr; /* transfer log epoch number */
641754 unsigned current_tle_writes; /* writes seen within this tl epoch */
642755
@@ -645,9 +758,22 @@ struct drbd_connection { · 2 unmodified lines
645758 struct drbd_thread worker;
646759 struct drbd_thread asender;
647760
761+ /* cached pointers,
762+ * so we can look up the oldest pending requests more quickly.
763+ * protected by resource->req_lock */
764+ struct drbd_request *req_next; /* DRBD 9: todo.req_next */
765+ struct drbd_request *req_ack_pending;
766+ struct drbd_request *req_not_net_done;
767+
648768 /* sender side */
649769 struct drbd_work_queue sender_work;
650770
771+#define DRBD_THREAD_DETAILS_HIST 16
772+ unsigned int w_cb_nr; /* keeps counting up */
773+ unsigned int r_cb_nr; /* keeps counting up */
774+ struct drbd_thread_timing_details w_timing_details[DRBD_THREAD_DETAILS_HIST];
775+ struct drbd_thread_timing_details r_timing_details[DRBD_THREAD_DETAILS_HIST];
776+
651777 struct {
652778 /* whether this sender thread
653779 * has processed a single write yet. */
@@ -663,11 +789,22 @@ struct drbd_connection { · 9 unmodified lines
663789 } send;
664790 };
665791
792+void __update_timing_details(
793+ struct drbd_thread_timing_details *tdp,
794+ unsigned int *cb_nr,
795+ void *cb,
796+ const char *fn, const unsigned int line);
797+
798+#define update_worker_timing_details(c, cb) \
799+ __update_timing_details(c->w_timing_details, &c->w_cb_nr, cb, __func__ , __LINE__ )
800+#define update_receiver_timing_details(c, cb) \
801+ __update_timing_details(c->r_timing_details, &c->r_cb_nr, cb, __func__ , __LINE__ )
802+
666803 struct submit_worker {
667804 struct workqueue_struct *wq;
668805 struct work_struct worker;
669806
670− spinlock_t lock;
807+ /* protected by ..->resource->req_lock */
671808 struct list_head writes;
672809 };
673810
@@ -675,12 +812,29 @@ struct drbd_peer_device { · 1 unmodified line
675812 struct list_head peer_devices;
676813 struct drbd_device *device;
677814 struct drbd_connection *connection;
815+#ifdef CONFIG_DEBUG_FS
816+ struct dentry *debugfs_peer_dev;
817+#endif
678818 };
679819
680820 struct drbd_device {
681821 struct drbd_resource *resource;
682822 struct list_head peer_devices;
683− int vnr; /* volume number within the connection */
823+ struct list_head pending_bitmap_io;
824+
825+ unsigned long flush_jif;
826+#ifdef CONFIG_DEBUG_FS
827+ struct dentry *debugfs_minor;
828+ struct dentry *debugfs_vol;
829+ struct dentry *debugfs_vol_oldest_requests;
830+ struct dentry *debugfs_vol_act_log_extents;
831+ struct dentry *debugfs_vol_resync_extents;
832+ struct dentry *debugfs_vol_data_gen_id;
833+#endif
834+
835+ unsigned int vnr; /* volume number within the connection */
836+ unsigned int minor; /* device minor number */
837+
684838 struct kref kref;
685839
686840 /* things that are stored as / read from meta data on disk */
@@ -697,19 +851,10 @@ struct drbd_device { · 10 unmodified lines
697851 unsigned long last_reattach_jif;
698852 struct drbd_work resync_work;
699853 struct drbd_work unplug_work;
700− struct drbd_work go_diskless;
701− struct drbd_work md_sync_work;
702− struct drbd_work start_resync_work;
703854 struct timer_list resync_timer;
704855 struct timer_list md_sync_timer;
705856 struct timer_list start_resync_timer;
706857 struct timer_list request_timer;
707−#ifdef DRBD_DEBUG_MD_SYNC
708− struct {
709− unsigned int line;
710− const char* func;
711− } last_md_mark_dirty;
712−#endif
713858
714859 /* Used after attach while negotiating new disk state. */
715860 union drbd_state new_state_tmp;
@@ -724,6 +869,7 @@ struct drbd_device { · 8 unmodified lines
724869 unsigned int al_writ_cnt;
725870 unsigned int bm_writ_cnt;
726871 atomic_t ap_bio_cnt; /* Requests we need to complete */
872+ atomic_t ap_actlog_cnt; /* Requests waiting for activity log */
727873 atomic_t ap_pending_cnt; /* AP data packets on the wire, ack expected */
728874 atomic_t rs_pending_cnt; /* RS request/data packets on the wire */
729875 atomic_t unacked_cnt; /* Need to send replies for */
@@ -733,6 +879,13 @@ struct drbd_device { · 3 unmodified lines
733879 struct rb_root read_requests;
734880 struct rb_root write_requests;
735881
882+ /* for statistics and timeouts */
883+ /* [0] read, [1] write */
884+ struct list_head pending_master_completion[2];
885+ struct list_head pending_completion[2];
886+
887+ /* use checksums for *this* resync */
888+ bool use_csums;
736889 /* blocks to resync in this run [unit BM_BLOCK_SIZE] */
737890 unsigned long rs_total;
738891 /* number of resync blocks that failed in this run */
@@ -788,9 +941,7 @@ struct drbd_device { · 49 unmodified lines
788941 atomic_t pp_in_use; /* allocated from page pool */
789942 atomic_t pp_in_use_by_net; /* sendpage()d, still referenced by tcp */
790943 wait_queue_head_t ee_wait;
791− struct page *md_io_page; /* one page buffer for md_io */
792944 struct drbd_md_io md_io;
793− atomic_t md_io_in_use; /* protects the md_io, md_io_page and md_io_tmpp */
794945 spinlock_t al_lock;
795946 wait_queue_head_t al_wait;
796947 struct lru_cache *act_log; /* activity log */
@@ -800,7 +951,6 @@ struct drbd_device { · 3 unmodified lines
800951 atomic_t packet_seq;
801952 unsigned int peer_seq;
802953 spinlock_t peer_seq_lock;
803− unsigned int minor;
804954 unsigned long comm_bm_set; /* communicated number of set bits. */
805955 struct bm_io_work bm_io_work;
806956 u64 ed_uuid; /* UUID of the exposed data */
@@ -824,6 +974,21 @@ struct drbd_device { · 17 unmodified lines
824974 struct submit_worker submit;
825975 };
826976
977+struct drbd_bm_aio_ctx {
978+ struct drbd_device *device;
979+ struct list_head list; /* on device->pending_bitmap_io */;
980+ unsigned long start_jif;
981+ atomic_t in_flight;
982+ unsigned int done;
983+ unsigned flags;
984+#define BM_AIO_COPY_PAGES 1
985+#define BM_AIO_WRITE_HINTED 2
986+#define BM_AIO_WRITE_ALL_PAGES 4
987+#define BM_AIO_READ 8
988+ int error;
989+ struct kref kref;
990+};
991+
827992 struct drbd_config_context {
828993 /* assigned from drbd_genlmsghdr */
829994 unsigned int minor;
@@ -949,7 +1114,7 @@ extern int drbd_send_ov_request(struct drbd_peer_device *, sector_t sector, int · 119 unmodified lines
9491114 extern int drbd_send_bitmap(struct drbd_device *device);
9501115 extern void drbd_send_sr_reply(struct drbd_peer_device *, enum drbd_state_rv retcode);
9511116 extern void conn_send_sr_reply(struct drbd_connection *connection, enum drbd_state_rv retcode);
952−extern void drbd_free_bc(struct drbd_backing_dev *ldev);
1117+extern void drbd_free_ldev(struct drbd_backing_dev *ldev);
9531118 extern void drbd_device_cleanup(struct drbd_device *device);
9541119 void drbd_print_uuids(struct drbd_device *device, const char *text);
9551120
@@ -966,13 +1131,7 @@ extern void __drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must · 10 unmodified lines
9661131 extern void drbd_md_set_flag(struct drbd_device *device, int flags) __must_hold(local);
9671132 extern void drbd_md_clear_flag(struct drbd_device *device, int flags)__must_hold(local);
9681133 extern int drbd_md_test_flag(struct drbd_backing_dev *, int);
969−#ifndef DRBD_DEBUG_MD_SYNC
9701134 extern void drbd_md_mark_dirty(struct drbd_device *device);
971−#else
972−#define drbd_md_mark_dirty(m) drbd_md_mark_dirty_(m, __LINE__ , __func__ )
973−extern void drbd_md_mark_dirty_(struct drbd_device *device,
974− unsigned int line, const char *func);
975−#endif
9761135 extern void drbd_queue_bitmap_io(struct drbd_device *device,
9771136 int (*io_fn)(struct drbd_device *),
9781137 void (*done)(struct drbd_device *, int),
@@ -983,9 +1142,8 @@ extern int drbd_bitmap_io(struct drbd_device *device, · 4 unmodified lines
9831142 extern int drbd_bitmap_io_from_worker(struct drbd_device *device,
9841143 int (*io_fn)(struct drbd_device *),
9851144 char *why, enum bm_flag flags);
986−extern int drbd_bmio_set_n_write(struct drbd_device *device);
987−extern int drbd_bmio_clear_n_write(struct drbd_device *device);
988−extern void drbd_ldev_destroy(struct drbd_device *device);
1145+extern int drbd_bmio_set_n_write(struct drbd_device *device) __must_hold(local);
1146+extern int drbd_bmio_clear_n_write(struct drbd_device *device) __must_hold(local);
9891147
9901148 /* Meta data layout
9911149 *
@@ -1105,17 +1263,21 @@ struct bm_extent { · 113 unmodified lines
11051263 /* in which _bitmap_ extent (resp. sector) the bit for a certain
11061264 * _storage_ sector is located in */
11071265 #define BM_SECT_TO_EXT(x) ((x)>>(BM_EXT_SHIFT-9))
1266+#define BM_BIT_TO_EXT(x) ((x) >> (BM_EXT_SHIFT - BM_BLOCK_SHIFT))
11081267
1109−/* how much _storage_ sectors we have per bitmap sector */
1268+/* first storage sector a bitmap extent corresponds to */
11101269 #define BM_EXT_TO_SECT(x) ((sector_t)(x) << (BM_EXT_SHIFT-9))
1270+/* how much _storage_ sectors we have per bitmap extent */
11111271 #define BM_SECT_PER_EXT BM_EXT_TO_SECT(1)
1272+/* how many bits are covered by one bitmap extent (resync extent) */
1273+#define BM_BITS_PER_EXT (1UL << (BM_EXT_SHIFT - BM_BLOCK_SHIFT))
1274+
1275+#define BM_BLOCKS_PER_BM_EXT_MASK (BM_BITS_PER_EXT - 1)
1276+
11121277
11131278 /* in one sector of the bitmap, we have this many activity_log extents. */
11141279 #define AL_EXT_PER_BM_SECT (1 << (BM_EXT_SHIFT - AL_EXTENT_SHIFT))
11151280
1116−#define BM_BLOCKS_PER_BM_EXT_B (BM_EXT_SHIFT - BM_BLOCK_SHIFT)
1117−#define BM_BLOCKS_PER_BM_EXT_MASK ((1<<BM_BLOCKS_PER_BM_EXT_B) - 1)
1118−
11191281 /* the extent in "PER_EXTENT" below is an activity log extent
11201282 * we need that many (long words/bytes) to store the bitmap
11211283 * of one AL_EXTENT_SIZE chunk of storage.
@@ -1195,11 +1357,11 @@ extern void _drbd_bm_set_bits(struct drbd_device *device, · 73 unmodified lines
11951357 const unsigned long s, const unsigned long e);
11961358 extern int drbd_bm_test_bit(struct drbd_device *device, unsigned long bitnr);
11971359 extern int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr);
1198−extern int drbd_bm_write_page(struct drbd_device *device, unsigned int idx) __must_hold(local);
11991360 extern int drbd_bm_read(struct drbd_device *device) __must_hold(local);
12001361 extern void drbd_bm_mark_for_writeout(struct drbd_device *device, int page_nr);
12011362 extern int drbd_bm_write(struct drbd_device *device) __must_hold(local);
12021363 extern int drbd_bm_write_hinted(struct drbd_device *device) __must_hold(local);
1364+extern int drbd_bm_write_lazy(struct drbd_device *device, unsigned upper_idx) __must_hold(local);
12031365 extern int drbd_bm_write_all(struct drbd_device *device) __must_hold(local);
12041366 extern int drbd_bm_write_copy_pages(struct drbd_device *device) __must_hold(local);
12051367 extern size_t drbd_bm_words(struct drbd_device *device);
@@ -1213,7 +1375,6 @@ extern unsigned long _drbd_bm_find_next(struct drbd_device *device, unsigned lon · 7 unmodified lines
12131375 extern unsigned long _drbd_bm_find_next_zero(struct drbd_device *device, unsigned long bm_fo);
12141376 extern unsigned long _drbd_bm_total_weight(struct drbd_device *device);
12151377 extern unsigned long drbd_bm_total_weight(struct drbd_device *device);
1216−extern int drbd_bm_rs_done(struct drbd_device *device);
12171378 /* for receive_bitmap */
12181379 extern void drbd_bm_merge_lel(struct drbd_device *device, size_t offset,
12191380 size_t number, unsigned long *buffer);
@@ -1312,7 +1473,7 @@ enum determine_dev_size { · 92 unmodified lines
13121473 extern enum determine_dev_size
13131474 drbd_determine_dev_size(struct drbd_device *, enum dds_flags, struct resize_parms *) __must_hold(local);
13141475 extern void resync_after_online_grow(struct drbd_device *);
1315−extern void drbd_reconsider_max_bio_size(struct drbd_device *device);
1476+extern void drbd_reconsider_max_bio_size(struct drbd_device *device, struct drbd_backing_dev *bdev);
13161477 extern enum drbd_state_rv drbd_set_role(struct drbd_device *device,
13171478 enum drbd_role new_role,
13181479 int force);
@@ -1333,7 +1494,7 @@ extern void resume_next_sg(struct drbd_device *device); · 14 unmodified lines
13331494 extern void suspend_other_sg(struct drbd_device *device);
13341495 extern int drbd_resync_finished(struct drbd_device *device);
13351496 /* maybe rather drbd_main.c ? */
1336−extern void *drbd_md_get_buffer(struct drbd_device *device);
1497+extern void *drbd_md_get_buffer(struct drbd_device *device, const char *intent);
13371498 extern void drbd_md_put_buffer(struct drbd_device *device);
13381499 extern int drbd_md_sync_page_io(struct drbd_device *device,
13391500 struct drbd_backing_dev *bdev, sector_t sector, int rw);
@@ -1380,7 +1541,8 @@ extern void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req); · 40 unmodified lines
13801541 extern int drbd_receiver(struct drbd_thread *thi);
13811542 extern int drbd_asender(struct drbd_thread *thi);
13821543 extern bool drbd_rs_c_min_rate_throttle(struct drbd_device *device);
1383−extern bool drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector);
1544+extern bool drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector,
1545+ bool throttle_if_app_is_waiting);
13841546 extern int drbd_submit_peer_request(struct drbd_device *,
13851547 struct drbd_peer_request *, const unsigned,
13861548 const int);
@@ -1464,10 +1626,7 @@ static inline void drbd_generic_make_request(struct drbd_device *device, · 77 unmodified lines
14641626 {
14651627 __release(local);
14661628 if (!bio->bi_bdev) {
1467− printk(KERN_ERR "drbd%d: drbd_generic_make_request: "
1468− "bio->bi_bdev == NULL\n",
1469− device_to_minor(device));
1470− dump_stack();
1629+ drbd_err(device, "drbd_generic_make_request: bio->bi_bdev == NULL\n");
14711630 bio_endio(bio, -ENODEV);
14721631 return;
14731632 }
@@ -1478,7 +1637,8 @@ static inline void drbd_generic_make_request(struct drbd_device *device, · 4 unmodified lines
14781637 generic_make_request(bio);
14791638 }
14801639
1481−void drbd_bump_write_ordering(struct drbd_connection *connection, enum write_ordering_e wo);
1640+void drbd_bump_write_ordering(struct drbd_resource *resource, struct drbd_backing_dev *bdev,
1641+ enum write_ordering_e wo);
14821642
14831643 /* drbd_proc.c */
14841644 extern struct proc_dir_entry *drbd_proc;
@@ -1489,9 +1649,9 @@ extern const char *drbd_role_str(enum drbd_role s); · 4 unmodified lines
14891649 /* drbd_actlog.c */
14901650 extern bool drbd_al_begin_io_prepare(struct drbd_device *device, struct drbd_interval *i);
14911651 extern int drbd_al_begin_io_nonblock(struct drbd_device *device, struct drbd_interval *i);
1492−extern void drbd_al_begin_io_commit(struct drbd_device *device, bool delegate);
1652+extern void drbd_al_begin_io_commit(struct drbd_device *device);
14931653 extern bool drbd_al_begin_io_fastpath(struct drbd_device *device, struct drbd_interval *i);
1494−extern void drbd_al_begin_io(struct drbd_device *device, struct drbd_interval *i, bool delegate);
1654+extern void drbd_al_begin_io(struct drbd_device *device, struct drbd_interval *i);
14951655 extern void drbd_al_complete_io(struct drbd_device *device, struct drbd_interval *i);
14961656 extern void drbd_rs_complete_io(struct drbd_device *device, sector_t sector);
14971657 extern int drbd_rs_begin_io(struct drbd_device *device, sector_t sector);
@@ -1501,14 +1661,17 @@ extern int drbd_rs_del_all(struct drbd_device *device); · 3 unmodified lines
15011661 extern void drbd_rs_failed_io(struct drbd_device *device,
15021662 sector_t sector, int size);
15031663 extern void drbd_advance_rs_marks(struct drbd_device *device, unsigned long still_to_go);
1504−extern void __drbd_set_in_sync(struct drbd_device *device, sector_t sector,
1505− int size, const char *file, const unsigned int line);
1664+
1665+enum update_sync_bits_mode { RECORD_RS_FAILED, SET_OUT_OF_SYNC, SET_IN_SYNC };
1666+extern int __drbd_change_sync(struct drbd_device *device, sector_t sector, int size,
1667+ enum update_sync_bits_mode mode,
1668+ const char *file, const unsigned int line);
15061669 #define drbd_set_in_sync(device, sector, size) \
1507− __drbd_set_in_sync(device, sector, size, __FILE__, __LINE__)
1508−extern int __drbd_set_out_of_sync(struct drbd_device *device, sector_t sector,
1509− int size, const char *file, const unsigned int line);
1670+ __drbd_change_sync(device, sector, size, SET_IN_SYNC, __FILE__, __LINE__)
15101671 #define drbd_set_out_of_sync(device, sector, size) \
1511− __drbd_set_out_of_sync(device, sector, size, __FILE__, __LINE__)
1672+ __drbd_change_sync(device, sector, size, SET_OUT_OF_SYNC, __FILE__, __LINE__)
1673+#define drbd_rs_failed_io(device, sector, size) \
1674+ __drbd_change_sync(device, sector, size, RECORD_RS_FAILED, __FILE__, __LINE__)
15121675 extern void drbd_al_shrink(struct drbd_device *device);
15131676 extern int drbd_initialize_al(struct drbd_device *, void *);
15141677
@@ -1764,25 +1927,38 @@ static inline sector_t drbd_md_ss(struct drbd_backing_dev *bdev) · 249 unmodified lines
17641927 }
17651928
17661929 static inline void
1767−drbd_queue_work_front(struct drbd_work_queue *q, struct drbd_work *w)
1930+drbd_queue_work(struct drbd_work_queue *q, struct drbd_work *w)
17681931 {
17691932 unsigned long flags;
17701933 spin_lock_irqsave(&q->q_lock, flags);
1771− list_add(&w->list, &q->q);
1934+ list_add_tail(&w->list, &q->q);
17721935 spin_unlock_irqrestore(&q->q_lock, flags);
17731936 wake_up(&q->q_wait);
17741937 }
17751938
17761939 static inline void
1777−drbd_queue_work(struct drbd_work_queue *q, struct drbd_work *w)
1940+drbd_queue_work_if_unqueued(struct drbd_work_queue *q, struct drbd_work *w)
17781941 {
17791942 unsigned long flags;
17801943 spin_lock_irqsave(&q->q_lock, flags);
1781− list_add_tail(&w->list, &q->q);
1944+ if (list_empty_careful(&w->list))
1945+ list_add_tail(&w->list, &q->q);
17821946 spin_unlock_irqrestore(&q->q_lock, flags);
17831947 wake_up(&q->q_wait);
17841948 }
17851949
1950+static inline void
1951+drbd_device_post_work(struct drbd_device *device, int work_bit)
1952+{
1953+ if (!test_and_set_bit(work_bit, &device->flags)) {
1954+ struct drbd_connection *connection =
1955+ first_peer_device(device)->connection;
1956+ struct drbd_work_queue *q = &connection->sender_work;
1957+ if (!test_and_set_bit(DEVICE_WORK_PENDING, &connection->flags))
1958+ wake_up(&q->q_wait);
1959+ }
1960+}
1961+
17861962 extern void drbd_flush_workqueue(struct drbd_work_queue *work_queue);
17871963
17881964 static inline void wake_asender(struct drbd_connection *connection)
@@ -1859,7 +2035,7 @@ static inline void inc_ap_pending(struct drbd_device *device) · 70 unmodified lines
18592035 func, line, \
18602036 atomic_read(&device->which))
18612037
1862−#define dec_ap_pending(device) _dec_ap_pending(device, __FUNCTION__, __LINE__)
2038+#define dec_ap_pending(device) _dec_ap_pending(device, __func__, __LINE__)
18632039 static inline void _dec_ap_pending(struct drbd_device *device, const char *func, int line)
18642040 {
18652041 if (atomic_dec_and_test(&device->ap_pending_cnt))
@@ -1878,7 +2054,7 @@ static inline void inc_rs_pending(struct drbd_device *device) · 12 unmodified lines
18782054 atomic_inc(&device->rs_pending_cnt);
18792055 }
18802056
1881−#define dec_rs_pending(device) _dec_rs_pending(device, __FUNCTION__, __LINE__)
2057+#define dec_rs_pending(device) _dec_rs_pending(device, __func__, __LINE__)
18822058 static inline void _dec_rs_pending(struct drbd_device *device, const char *func, int line)
18832059 {
18842060 atomic_dec(&device->rs_pending_cnt);
@@ -1899,20 +2075,29 @@ static inline void inc_unacked(struct drbd_device *device) · 14 unmodified lines
18992075 atomic_inc(&device->unacked_cnt);
19002076 }
19012077
1902−#define dec_unacked(device) _dec_unacked(device, __FUNCTION__, __LINE__)
2078+#define dec_unacked(device) _dec_unacked(device, __func__, __LINE__)
19032079 static inline void _dec_unacked(struct drbd_device *device, const char *func, int line)
19042080 {
19052081 atomic_dec(&device->unacked_cnt);
19062082 ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line);
19072083 }
19082084
1909−#define sub_unacked(device, n) _sub_unacked(device, n, __FUNCTION__, __LINE__)
2085+#define sub_unacked(device, n) _sub_unacked(device, n, __func__, __LINE__)
19102086 static inline void _sub_unacked(struct drbd_device *device, int n, const char *func, int line)
19112087 {
19122088 atomic_sub(n, &device->unacked_cnt);
19132089 ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line);
19142090 }
19152091
2092+static inline bool is_sync_state(enum drbd_conns connection_state)
2093+{
2094+ return
2095+ (connection_state == C_SYNC_SOURCE
2096+ || connection_state == C_SYNC_TARGET
2097+ || connection_state == C_PAUSED_SYNC_S
2098+ || connection_state == C_PAUSED_SYNC_T);
2099+}
2100+
19162101 /**
19172102 * get_ldev() - Increase the ref count on device->ldev. Returns 0 if there is no ldev
19182103 * @M: DRBD device.
@@ -1924,6 +2109,11 @@ static inline void _sub_unacked(struct drbd_device *device, int n, const char *f · 5 unmodified lines
19242109
19252110 static inline void put_ldev(struct drbd_device *device)
19262111 {
2112+ enum drbd_disk_state ds = device->state.disk;
2113+ /* We must check the state *before* the atomic_dec becomes visible,
2114+ * or we have a theoretical race where someone hitting zero,
2115+ * while state still D_FAILED, will then see D_DISKLESS in the
2116+ * condition below and calling into destroy, where he must not, yet. */
19272117 int i = atomic_dec_return(&device->local_cnt);
19282118
19292119 /* This may be called from some endio handler,
@@ -1932,15 +2122,13 @@ static inline void put_ldev(struct drbd_device *device) · 2 unmodified lines
19322122 __release(local);
19332123 D_ASSERT(device, i >= 0);
19342124 if (i == 0) {
1935− if (device->state.disk == D_DISKLESS)
2125+ if (ds == D_DISKLESS)
19362126 /* even internal references gone, safe to destroy */
1937− drbd_ldev_destroy(device);
1938− if (device->state.disk == D_FAILED) {
2127+ drbd_device_post_work(device, DESTROY_DISK);
2128+ if (ds == D_FAILED)
19392129 /* all application IO references gone. */
1940− if (!test_and_set_bit(GO_DISKLESS, &device->flags))
1941− drbd_queue_work(&first_peer_device(device)->connection->sender_work,
1942− &device->go_diskless);
1943− }
2130+ if (!test_and_set_bit(GOING_DISKLESS, &device->flags))
2131+ drbd_device_post_work(device, GO_DISKLESS);
19442132 wake_up(&device->misc_wait);
19452133 }
19462134 }
@@ -1964,54 +2152,6 @@ static inline int _get_ldev_if_state(struct drbd_device *device, enum drbd_disk_ · 17 unmodified lines
19642152 extern int _get_ldev_if_state(struct drbd_device *device, enum drbd_disk_state mins);
19652153 #endif
19662154
1967−/* you must have an "get_ldev" reference */
1968−static inline void drbd_get_syncer_progress(struct drbd_device *device,
1969− unsigned long *bits_left, unsigned int *per_mil_done)
1970−{
1971− /* this is to break it at compile time when we change that, in case we
1972− * want to support more than (1<<32) bits on a 32bit arch. */
1973− typecheck(unsigned long, device->rs_total);
1974−
1975− /* note: both rs_total and rs_left are in bits, i.e. in
1976− * units of BM_BLOCK_SIZE.
1977− * for the percentage, we don't care. */
1978−
1979− if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T)
1980− *bits_left = device->ov_left;
1981− else
1982− *bits_left = drbd_bm_total_weight(device) - device->rs_failed;
1983− /* >> 10 to prevent overflow,
1984− * +1 to prevent division by zero */
1985− if (*bits_left > device->rs_total) {
1986− /* doh. maybe a logic bug somewhere.
1987− * may also be just a race condition
1988− * between this and a disconnect during sync.
1989− * for now, just prevent in-kernel buffer overflow.
1990− */
1991− smp_rmb();
1992− drbd_warn(device, "cs:%s rs_left=%lu > rs_total=%lu (rs_failed %lu)\n",
1993− drbd_conn_str(device->state.conn),
1994− *bits_left, device->rs_total, device->rs_failed);
1995− *per_mil_done = 0;
1996− } else {
1997− /* Make sure the division happens in long context.
1998− * We allow up to one petabyte storage right now,
1999− * at a granularity of 4k per bit that is 2**38 bits.
2000− * After shift right and multiplication by 1000,
2001− * this should still fit easily into a 32bit long,
2002− * so we don't need a 64bit division on 32bit arch.
2003− * Note: currently we don't support such large bitmaps on 32bit
2004− * arch anyways, but no harm done to be prepared for it here.
2005− */
2006− unsigned int shift = device->rs_total > UINT_MAX ? 16 : 10;
2007− unsigned long left = *bits_left >> shift;
2008− unsigned long total = 1UL + (device->rs_total >> shift);
2009− unsigned long tmp = 1000UL - left * 1000UL/total;
2010− *per_mil_done = tmp;
2011− }
2012−}
2013−
2014−
20152155 /* this throttles on-the-fly application requests
20162156 * according to max_buffers settings;
20172157 * maybe re-implement using semaphores? */
@@ -2201,25 +2341,6 @@ static inline int drbd_queue_order_type(struct drbd_device *device) · 183 unmodified lines
22012341 return QUEUE_ORDERED_NONE;
22022342 }
22032343
2204−static inline void drbd_md_flush(struct drbd_device *device)
2205−{
2206− int r;
2207−
2208− if (device->ldev == NULL) {
2209− drbd_warn(device, "device->ldev == NULL in drbd_md_flush\n");
2210− return;
2211− }
2212−
2213− if (test_bit(MD_NO_FUA, &device->flags))
2214− return;
2215−
2216− r = blkdev_issue_flush(device->ldev->md_bdev, GFP_NOIO, NULL);
2217− if (r) {
2218− set_bit(MD_NO_FUA, &device->flags);
2219− drbd_err(device, "meta data flush failed with status %d, disabling md-flushes\n", r);
2220− }
2221−}
2222−
22232344 static inline struct drbd_connection *first_connection(struct drbd_resource *resource)
22242345 {
22252346 return list_first_entry_or_null(&resource->connections,
drivers/block/drbd/drbd_interval.h+3−1
@@ -10,7 +10,9 @@ struct drbd_interval { · 9 unmodified lines
1010 unsigned int size; /* size in bytes */
1111 sector_t end; /* highest interval end in subtree */
1212 int local:1 /* local or remote request? */;
13− int waiting:1;
13+ int waiting:1; /* someone is waiting for this to complete */
14+ int completed:1; /* this has been completed already;
15+ * ignore for conflict detection */
1416 };
1517
1618 static inline void drbd_clear_interval(struct drbd_interval *i)
drivers/block/drbd/drbd_main.c+125−177
@@ -26,7 +26,10 @@ · 25 unmodified lines
2626
2727 */
2828
29+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30+
2931 #include <linux/module.h>
32+#include <linux/jiffies.h>
3033 #include <linux/drbd.h>
3134 #include <asm/uaccess.h>
3235 #include <asm/types.h>
@@ -54,16 +57,14 @@ · 21 unmodified lines
5457 #include "drbd_int.h"
5558 #include "drbd_protocol.h"
5659 #include "drbd_req.h" /* only for _req_mod in tl_release and tl_clear */
57−
5860 #include "drbd_vli.h"
61+#include "drbd_debugfs.h"
5962
6063 static DEFINE_MUTEX(drbd_main_mutex);
6164 static int drbd_open(struct block_device *bdev, fmode_t mode);
6265 static void drbd_release(struct gendisk *gd, fmode_t mode);
63−static int w_md_sync(struct drbd_work *w, int unused);
6466 static void md_sync_timer_fn(unsigned long data);
6567 static int w_bitmap_io(struct drbd_work *w, int unused);
66−static int w_go_diskless(struct drbd_work *w, int unused);
6768
6869 MODULE_AUTHOR("Philipp Reisner <phil@linbit.com>, "
6970 "Lars Ellenberg <lars@linbit.com>");
@@ -264,7 +265,7 @@ bail: · 194 unmodified lines
264265
265266 /**
266267 * _tl_restart() - Walks the transfer log, and applies an action to all requests
267− * @device: DRBD device.
268+ * @connection: DRBD connection to operate on.
268269 * @what: The action/event to perform with all request objects
269270 *
270271 * @what might be one of CONNECTION_LOST_WHILE_PENDING, RESEND, FAIL_FROZEN_DISK_IO,
@@ -662,6 +663,11 @@ static int __send_command(struct drbd_connection *connection, int vnr, · 391 unmodified lines
662663 msg_flags);
663664 if (data && !err)
664665 err = drbd_send_all(connection, sock->socket, data, size, 0);
666+ /* DRBD protocol "pings" are latency critical.
667+ * This is supposed to trigger tcp_push_pending_frames() */
668+ if (!err && (cmd == P_PING || cmd == P_PING_ACK))
669+ drbd_tcp_nodelay(sock->socket);
670+
665671 return err;
666672 }
667673
@@ -1636,7 +1642,10 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request * · 968 unmodified lines
16361642 if (peer_device->connection->agreed_pro_version >= 100) {
16371643 if (req->rq_state & RQ_EXP_RECEIVE_ACK)
16381644 dp_flags |= DP_SEND_RECEIVE_ACK;
1639− if (req->rq_state & RQ_EXP_WRITE_ACK)
1645+ /* During resync, request an explicit write ack,
1646+ * even in protocol != C */
1647+ if (req->rq_state & RQ_EXP_WRITE_ACK
1648+ || (dp_flags & DP_MAY_SET_IN_SYNC))
16401649 dp_flags |= DP_SEND_WRITE_ACK;
16411650 }
16421651 p->dp_flags = cpu_to_be32(dp_flags);
@@ -1900,6 +1909,7 @@ void drbd_init_set_defaults(struct drbd_device *device) · 257 unmodified lines
19001909 drbd_set_defaults(device);
19011910
19021911 atomic_set(&device->ap_bio_cnt, 0);
1912+ atomic_set(&device->ap_actlog_cnt, 0);
19031913 atomic_set(&device->ap_pending_cnt, 0);
19041914 atomic_set(&device->rs_pending_cnt, 0);
19051915 atomic_set(&device->unacked_cnt, 0);
@@ -1908,7 +1918,7 @@ void drbd_init_set_defaults(struct drbd_device *device) · 2 unmodified lines
19081918 atomic_set(&device->rs_sect_in, 0);
19091919 atomic_set(&device->rs_sect_ev, 0);
19101920 atomic_set(&device->ap_in_flight, 0);
1911− atomic_set(&device->md_io_in_use, 0);
1921+ atomic_set(&device->md_io.in_use, 0);
19121922
19131923 mutex_init(&device->own_state_mutex);
19141924 device->state_mutex = &device->own_state_mutex;
@@ -1924,17 +1934,15 @@ void drbd_init_set_defaults(struct drbd_device *device) · 9 unmodified lines
19241934 INIT_LIST_HEAD(&device->resync_reads);
19251935 INIT_LIST_HEAD(&device->resync_work.list);
19261936 INIT_LIST_HEAD(&device->unplug_work.list);
1927− INIT_LIST_HEAD(&device->go_diskless.list);
1928− INIT_LIST_HEAD(&device->md_sync_work.list);
1929− INIT_LIST_HEAD(&device->start_resync_work.list);
19301937 INIT_LIST_HEAD(&device->bm_io_work.w.list);
1938+ INIT_LIST_HEAD(&device->pending_master_completion[0]);
1939+ INIT_LIST_HEAD(&device->pending_master_completion[1]);
1940+ INIT_LIST_HEAD(&device->pending_completion[0]);
1941+ INIT_LIST_HEAD(&device->pending_completion[1]);
19311942
19321943 device->resync_work.cb = w_resync_timer;
19331944 device->unplug_work.cb = w_send_write_hint;
1934− device->go_diskless.cb = w_go_diskless;
1935− device->md_sync_work.cb = w_md_sync;
19361945 device->bm_io_work.w.cb = w_bitmap_io;
1937− device->start_resync_work.cb = w_start_resync;
19381946
19391947 init_timer(&device->resync_timer);
19401948 init_timer(&device->md_sync_timer);
@@ -1992,7 +2000,7 @@ void drbd_device_cleanup(struct drbd_device *device) · 51 unmodified lines
19922000 drbd_bm_cleanup(device);
19932001 }
19942002
1995− drbd_free_bc(device->ldev);
2003+ drbd_free_ldev(device->ldev);
19962004 device->ldev = NULL;
19972005
19982006 clear_bit(AL_SUSPENDED, &device->flags);
@@ -2006,7 +2014,6 @@ void drbd_device_cleanup(struct drbd_device *device) · 7 unmodified lines
20062014 D_ASSERT(device, list_empty(&first_peer_device(device)->connection->sender_work.q));
20072015 D_ASSERT(device, list_empty(&device->resync_work.list));
20082016 D_ASSERT(device, list_empty(&device->unplug_work.list));
2009− D_ASSERT(device, list_empty(&device->go_diskless.list));
20102017
20112018 drbd_set_defaults(device);
20122019 }
@@ -2129,20 +2136,6 @@ Enomem: · 116 unmodified lines
21292136 return -ENOMEM;
21302137 }
21312138
2132−static int drbd_notify_sys(struct notifier_block *this, unsigned long code,
2133− void *unused)
2134−{
2135− /* just so we have it. you never know what interesting things we
2136− * might want to do here some day...
2137− */
2138−
2139− return NOTIFY_DONE;
2140−}
2141−
2142−static struct notifier_block drbd_notifier = {
2143− .notifier_call = drbd_notify_sys,
2144−};
2145−
21462139 static void drbd_release_all_peer_reqs(struct drbd_device *device)
21472140 {
21482141 int rr;
@@ -2173,7 +2166,7 @@ void drbd_destroy_device(struct kref *kref) · 24 unmodified lines
21732166 {
21742167 struct drbd_device *device = container_of(kref, struct drbd_device, kref);
21752168 struct drbd_resource *resource = device->resource;
2176− struct drbd_connection *connection;
2169+ struct drbd_peer_device *peer_device, *tmp_peer_device;
21772170
21782171 del_timer_sync(&device->request_timer);
21792172
@@ -2187,7 +2180,7 @@ void drbd_destroy_device(struct kref *kref) · 7 unmodified lines
21872180 if (device->this_bdev)
21882181 bdput(device->this_bdev);
21892182
2190− drbd_free_bc(device->ldev);
2183+ drbd_free_ldev(device->ldev);
21912184 device->ldev = NULL;
21922185
21932186 drbd_release_all_peer_reqs(device);
@@ -2200,15 +2193,20 @@ void drbd_destroy_device(struct kref *kref) · 6 unmodified lines
22002193
22012194 if (device->bitmap) /* should no longer be there. */
22022195 drbd_bm_cleanup(device);
2203− __free_page(device->md_io_page);
2196+ __free_page(device->md_io.page);
22042197 put_disk(device->vdisk);
22052198 blk_cleanup_queue(device->rq_queue);
22062199 kfree(device->rs_plan_s);
2207− kfree(first_peer_device(device));
2208− kfree(device);
22092200
2210− for_each_connection(connection, resource)
2211− kref_put(&connection->kref, drbd_destroy_connection);
2201+ /* not for_each_connection(connection, resource):
2202+ * those may have been cleaned up and disassociated already.
2203+ */
2204+ for_each_peer_device_safe(peer_device, tmp_peer_device, device) {
2205+ kref_put(&peer_device->connection->kref, drbd_destroy_connection);
2206+ kfree(peer_device);
2207+ }
2208+ memset(device, 0xfd, sizeof(*device));
2209+ kfree(device);
22122210 kref_put(&resource->kref, drbd_destroy_resource);
22132211 }
22142212
@@ -2236,7 +2234,7 @@ static void do_retry(struct work_struct *ws) · 21 unmodified lines
22362234 list_for_each_entry_safe(req, tmp, &writes, tl_requests) {
22372235 struct drbd_device *device = req->device;
22382236 struct bio *bio = req->master_bio;
2239− unsigned long start_time = req->start_time;
2237+ unsigned long start_jif = req->start_jif;
22402238 bool expected;
22412239
22422240 expected =
@@ -2271,10 +2269,12 @@ static void do_retry(struct work_struct *ws) · 28 unmodified lines
22712269 /* We are not just doing generic_make_request(),
22722270 * as we want to keep the start_time information. */
22732271 inc_ap_bio(device);
2274− __drbd_make_request(device, bio, start_time);
2272+ __drbd_make_request(device, bio, start_jif);
22752273 }
22762274 }
22772275
2276+/* called via drbd_req_put_completion_ref(),
2277+ * holds resource->req_lock */
22782278 void drbd_restart_request(struct drbd_request *req)
22792279 {
22802280 unsigned long flags;
@@ -2298,6 +2298,7 @@ void drbd_destroy_resource(struct kref *kref) · 17 unmodified lines
22982298 idr_destroy(&resource->devices);
22992299 free_cpumask_var(resource->cpu_mask);
23002300 kfree(resource->name);
2301+ memset(resource, 0xf2, sizeof(*resource));
23012302 kfree(resource);
23022303 }
23032304
@@ -2307,8 +2308,10 @@ void drbd_free_resource(struct drbd_resource *resource) · 3 unmodified lines
23072308
23082309 for_each_connection_safe(connection, tmp, resource) {
23092310 list_del(&connection->connections);
2311+ drbd_debugfs_connection_cleanup(connection);
23102312 kref_put(&connection->kref, drbd_destroy_connection);
23112313 }
2314+ drbd_debugfs_resource_cleanup(resource);
23122315 kref_put(&resource->kref, drbd_destroy_resource);
23132316 }
23142317
@@ -2318,8 +2321,6 @@ static void drbd_cleanup(void) · 3 unmodified lines
23182321 struct drbd_device *device;
23192322 struct drbd_resource *resource, *tmp;
23202323
2321− unregister_reboot_notifier(&drbd_notifier);
2322−
23232324 /* first remove proc,
23242325 * drbdsetup uses it's presence to detect
23252326 * whether DRBD is loaded.
@@ -2335,6 +2336,7 @@ static void drbd_cleanup(void) · 9 unmodified lines
23352336 destroy_workqueue(retry.wq);
23362337
23372338 drbd_genl_unregister();
2339+ drbd_debugfs_cleanup();
23382340
23392341 idr_for_each_entry(&drbd_devices, device, i)
23402342 drbd_delete_device(device);
@@ -2350,7 +2352,7 @@ static void drbd_cleanup(void) · 9 unmodified lines
23502352
23512353 idr_destroy(&drbd_devices);
23522354
2353− printk(KERN_INFO "drbd: module cleanup done.\n");
2355+ pr_info("module cleanup done.\n");
23542356 }
23552357
23562358 /**
@@ -2539,6 +2541,20 @@ int set_resource_options(struct drbd_resource *resource, struct res_opts *res_op · 182 unmodified lines
25392541 if (nr_cpu_ids > 1 && res_opts->cpu_mask[0] != 0) {
25402542 err = bitmap_parse(res_opts->cpu_mask, DRBD_CPU_MASK_SIZE,
25412543 cpumask_bits(new_cpu_mask), nr_cpu_ids);
2544+ if (err == -EOVERFLOW) {
2545+ /* So what. mask it out. */
2546+ cpumask_var_t tmp_cpu_mask;
2547+ if (zalloc_cpumask_var(&tmp_cpu_mask, GFP_KERNEL)) {
2548+ cpumask_setall(tmp_cpu_mask);
2549+ cpumask_and(new_cpu_mask, new_cpu_mask, tmp_cpu_mask);
2550+ drbd_warn(resource, "Overflow in bitmap_parse(%.12s%s), truncating to %u bits\n",
2551+ res_opts->cpu_mask,
2552+ strlen(res_opts->cpu_mask) > 12 ? "..." : "",
2553+ nr_cpu_ids);
2554+ free_cpumask_var(tmp_cpu_mask);
2555+ err = 0;
2556+ }
2557+ }
25422558 if (err) {
25432559 drbd_warn(resource, "bitmap_parse() failed with %d\n", err);
25442560 /* retcode = ERR_CPU_MASK_PARSE; */
@@ -2579,10 +2595,12 @@ struct drbd_resource *drbd_create_resource(const char *name) · 34 unmodified lines
25792595 kref_init(&resource->kref);
25802596 idr_init(&resource->devices);
25812597 INIT_LIST_HEAD(&resource->connections);
2598+ resource->write_ordering = WO_bdev_flush;
25822599 list_add_tail_rcu(&resource->resources, &drbd_resources);
25832600 mutex_init(&resource->conf_update);
25842601 mutex_init(&resource->adm_mutex);
25852602 spin_lock_init(&resource->req_lock);
2603+ drbd_debugfs_resource_add(resource);
25862604 return resource;
25872605
25882606 fail_free_name:
@@ -2593,7 +2611,7 @@ fail: · 4 unmodified lines
25932611 return NULL;
25942612 }
25952613
2596−/* caller must be under genl_lock() */
2614+/* caller must be under adm_mutex */
25972615 struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts)
25982616 {
25992617 struct drbd_resource *resource;
@@ -2617,7 +2635,6 @@ struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts) · 17 unmodified lines
26172635 INIT_LIST_HEAD(&connection->current_epoch->list);
26182636 connection->epochs = 1;
26192637 spin_lock_init(&connection->epoch_lock);
2620− connection->write_ordering = WO_bdev_flush;
26212638
26222639 connection->send.seen_any_write_yet = false;
26232640 connection->send.current_epoch_nr = 0;
@@ -2652,6 +2669,7 @@ struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts) · 28 unmodified lines
26522669
26532670 kref_get(&resource->kref);
26542671 list_add_tail_rcu(&connection->connections, &resource->connections);
2672+ drbd_debugfs_connection_add(connection);
26552673 return connection;
26562674
26572675 fail_resource:
@@ -2680,6 +2698,7 @@ void drbd_destroy_connection(struct kref *kref) · 22 unmodified lines
26802698 drbd_free_socket(&connection->data);
26812699 kfree(connection->int_dig_in);
26822700 kfree(connection->int_dig_vv);
2701+ memset(connection, 0xfc, sizeof(*connection));
26832702 kfree(connection);
26842703 kref_put(&resource->kref, drbd_destroy_resource);
26852704 }
@@ -2694,7 +2713,6 @@ static int init_submitter(struct drbd_device *device) · 8 unmodified lines
26942713 return -ENOMEM;
26952714
26962715 INIT_WORK(&device->submit.worker, do_submit);
2697− spin_lock_init(&device->submit.lock);
26982716 INIT_LIST_HEAD(&device->submit.writes);
26992717 return 0;
27002718 }
@@ -2764,8 +2782,8 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig · 63 unmodified lines
27642782 blk_queue_merge_bvec(q, drbd_merge_bvec);
27652783 q->queue_lock = &resource->req_lock;
27662784
2767− device->md_io_page = alloc_page(GFP_KERNEL);
2768− if (!device->md_io_page)
2785+ device->md_io.page = alloc_page(GFP_KERNEL);
2786+ if (!device->md_io.page)
27692787 goto out_no_io_page;
27702788
27712789 if (drbd_bm_init(device))
@@ -2794,6 +2812,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig · 22 unmodified lines
27942812 kref_get(&device->kref);
27952813
27962814 INIT_LIST_HEAD(&device->peer_devices);
2815+ INIT_LIST_HEAD(&device->pending_bitmap_io);
27972816 for_each_connection(connection, resource) {
27982817 peer_device = kzalloc(sizeof(struct drbd_peer_device), GFP_KERNEL);
27992818 if (!peer_device)
@@ -2829,7 +2848,10 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig · 29 unmodified lines
28292848 for_each_peer_device(peer_device, device)
28302849 drbd_connected(peer_device);
28312850 }
2832−
2851+ /* move to create_peer_device() */
2852+ for_each_peer_device(peer_device, device)
2853+ drbd_debugfs_peer_device_add(peer_device);
2854+ drbd_debugfs_device_add(device);
28332855 return NO_ERROR;
28342856
28352857 out_idr_remove_vol:
@@ -2853,7 +2875,7 @@ out_idr_remove_minor: · 17 unmodified lines
28532875 out_no_minor_idr:
28542876 drbd_bm_cleanup(device);
28552877 out_no_bitmap:
2856− __free_page(device->md_io_page);
2878+ __free_page(device->md_io.page);
28572879 out_no_io_page:
28582880 put_disk(disk);
28592881 out_no_disk:
@@ -2868,8 +2890,13 @@ void drbd_delete_device(struct drbd_device *device) · 8 unmodified lines
28682890 {
28692891 struct drbd_resource *resource = device->resource;
28702892 struct drbd_connection *connection;
2893+ struct drbd_peer_device *peer_device;
28712894 int refs = 3;
28722895
2896+ /* move to free_peer_device() */
2897+ for_each_peer_device(peer_device, device)
2898+ drbd_debugfs_peer_device_cleanup(peer_device);
2899+ drbd_debugfs_device_cleanup(device);
28732900 for_each_connection(connection, resource) {
28742901 idr_remove(&connection->peer_devices, device->vnr);
28752902 refs++;
@@ -2881,13 +2908,12 @@ void drbd_delete_device(struct drbd_device *device) · 5 unmodified lines
28812908 kref_sub(&device->kref, refs, drbd_destroy_device);
28822909 }
28832910
2884−int __init drbd_init(void)
2911+static int __init drbd_init(void)
28852912 {
28862913 int err;
28872914
28882915 if (minor_count < DRBD_MINOR_COUNT_MIN || minor_count > DRBD_MINOR_COUNT_MAX) {
2889− printk(KERN_ERR
2890− "drbd: invalid minor_count (%d)\n", minor_count);
2916+ pr_err("invalid minor_count (%d)\n", minor_count);
28912917 #ifdef MODULE
28922918 return -EINVAL;
28932919 #else
@@ -2897,14 +2923,11 @@ int __init drbd_init(void) · 3 unmodified lines
28972923
28982924 err = register_blkdev(DRBD_MAJOR, "drbd");
28992925 if (err) {
2900− printk(KERN_ERR
2901− "drbd: unable to register block device major %d\n",
2926+ pr_err("unable to register block device major %d\n",
29022927 DRBD_MAJOR);
29032928 return err;
29042929 }
29052930
2906− register_reboot_notifier(&drbd_notifier);
2907−
29082931 /*
29092932 * allocate all necessary structs
29102933 */
@@ -2918,7 +2941,7 @@ int __init drbd_init(void) · 7 unmodified lines
29182941
29192942 err = drbd_genl_register();
29202943 if (err) {
2921− printk(KERN_ERR "drbd: unable to register generic netlink family\n");
2944+ pr_err("unable to register generic netlink family\n");
29222945 goto fail;
29232946 }
29242947
@@ -2929,38 +2952,39 @@ int __init drbd_init(void) · 4 unmodified lines
29292952 err = -ENOMEM;
29302953 drbd_proc = proc_create_data("drbd", S_IFREG | S_IRUGO , NULL, &drbd_proc_fops, NULL);
29312954 if (!drbd_proc) {
2932− printk(KERN_ERR "drbd: unable to register proc file\n");
2955+ pr_err("unable to register proc file\n");
29332956 goto fail;
29342957 }
29352958
29362959 retry.wq = create_singlethread_workqueue("drbd-reissue");
29372960 if (!retry.wq) {
2938− printk(KERN_ERR "drbd: unable to create retry workqueue\n");
2961+ pr_err("unable to create retry workqueue\n");
29392962 goto fail;
29402963 }
29412964 INIT_WORK(&retry.worker, do_retry);
29422965 spin_lock_init(&retry.lock);
29432966 INIT_LIST_HEAD(&retry.writes);
29442967
2945− printk(KERN_INFO "drbd: initialized. "
2968+ if (drbd_debugfs_init())
2969+ pr_notice("failed to initialize debugfs -- will not be available\n");
2970+
2971+ pr_info("initialized. "
29462972 "Version: " REL_VERSION " (api:%d/proto:%d-%d)\n",
29472973 API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX);
2948− printk(KERN_INFO "drbd: %s\n", drbd_buildtag());
2949− printk(KERN_INFO "drbd: registered as block device major %d\n",
2950− DRBD_MAJOR);
2951−
2974+ pr_info("%s\n", drbd_buildtag());
2975+ pr_info("registered as block device major %d\n", DRBD_MAJOR);
29522976 return 0; /* Success! */
29532977
29542978 fail:
29552979 drbd_cleanup();
29562980 if (err == -ENOMEM)
2957− printk(KERN_ERR "drbd: ran out of memory\n");
2981+ pr_err("ran out of memory\n");
29582982 else
2959− printk(KERN_ERR "drbd: initialization failure\n");
2983+ pr_err("initialization failure\n");
29602984 return err;
29612985 }
29622986
2963−void drbd_free_bc(struct drbd_backing_dev *ldev)
2987+void drbd_free_ldev(struct drbd_backing_dev *ldev)
29642988 {
29652989 if (ldev == NULL)
29662990 return;
@@ -2972,24 +2996,29 @@ void drbd_free_bc(struct drbd_backing_dev *ldev) · 5 unmodified lines
29722996 kfree(ldev);
29732997 }
29742998
2975−void drbd_free_sock(struct drbd_connection *connection)
2999+static void drbd_free_one_sock(struct drbd_socket *ds)
29763000 {
2977− if (connection->data.socket) {
2978− mutex_lock(&connection->data.mutex);
2979− kernel_sock_shutdown(connection->data.socket, SHUT_RDWR);
2980− sock_release(connection->data.socket);
2981− connection->data.socket = NULL;
2982− mutex_unlock(&connection->data.mutex);
2983− }
2984− if (connection->meta.socket) {
2985− mutex_lock(&connection->meta.mutex);
2986− kernel_sock_shutdown(connection->meta.socket, SHUT_RDWR);
2987− sock_release(connection->meta.socket);
2988− connection->meta.socket = NULL;
2989− mutex_unlock(&connection->meta.mutex);
3001+ struct socket *s;
3002+ mutex_lock(&ds->mutex);
3003+ s = ds->socket;
3004+ ds->socket = NULL;
3005+ mutex_unlock(&ds->mutex);
3006+ if (s) {
3007+ /* so debugfs does not need to mutex_lock() */
3008+ synchronize_rcu();
3009+ kernel_sock_shutdown(s, SHUT_RDWR);
3010+ sock_release(s);
29903011 }
29913012 }
29923013
3014+void drbd_free_sock(struct drbd_connection *connection)
3015+{
3016+ if (connection->data.socket)
3017+ drbd_free_one_sock(&connection->data);
3018+ if (connection->meta.socket)
3019+ drbd_free_one_sock(&connection->meta);
3020+}
3021+
29933022 /* meta data management */
29943023
29953024 void conn_md_sync(struct drbd_connection *connection)
@@ -3093,7 +3122,7 @@ void drbd_md_sync(struct drbd_device *device) · 97 unmodified lines
30933122 if (!get_ldev_if_state(device, D_FAILED))
30943123 return;
30953124
3096− buffer = drbd_md_get_buffer(device);
3125+ buffer = drbd_md_get_buffer(device, __func__);
30973126 if (!buffer)
30983127 goto out;
30993128
@@ -3253,7 +3282,7 @@ int drbd_md_read(struct drbd_device *device, struct drbd_backing_dev *bdev) · 153 unmodified lines
32533282 if (device->state.disk != D_DISKLESS)
32543283 return ERR_DISK_CONFIGURED;
32553284
3256− buffer = drbd_md_get_buffer(device);
3285+ buffer = drbd_md_get_buffer(device, __func__);
32573286 if (!buffer)
32583287 return ERR_NOMEM;
32593288
@@ -3466,23 +3495,19 @@ void drbd_uuid_set_bm(struct drbd_device *device, u64 val) __must_hold(local) · 206 unmodified lines
34663495 *
34673496 * Sets all bits in the bitmap and writes the whole bitmap to stable storage.
34683497 */
3469−int drbd_bmio_set_n_write(struct drbd_device *device)
3498+int drbd_bmio_set_n_write(struct drbd_device *device) __must_hold(local)
34703499 {
34713500 int rv = -EIO;
34723501
3473− if (get_ldev_if_state(device, D_ATTACHING)) {
3474− drbd_md_set_flag(device, MDF_FULL_SYNC);
3475− drbd_md_sync(device);
3476− drbd_bm_set_all(device);
3477−
3478− rv = drbd_bm_write(device);
3502+ drbd_md_set_flag(device, MDF_FULL_SYNC);
3503+ drbd_md_sync(device);
3504+ drbd_bm_set_all(device);
34793505
3480− if (!rv) {
3481− drbd_md_clear_flag(device, MDF_FULL_SYNC);
3482− drbd_md_sync(device);
3483− }
3506+ rv = drbd_bm_write(device);
34843507
3485− put_ldev(device);
3508+ if (!rv) {
3509+ drbd_md_clear_flag(device, MDF_FULL_SYNC);
3510+ drbd_md_sync(device);
34863511 }
34873512
34883513 return rv;
@@ -3494,18 +3519,11 @@ int drbd_bmio_set_n_write(struct drbd_device *device) · 5 unmodified lines
34943519 *
34953520 * Clears all bits in the bitmap and writes the whole bitmap to stable storage.
34963521 */
3497−int drbd_bmio_clear_n_write(struct drbd_device *device)
3522+int drbd_bmio_clear_n_write(struct drbd_device *device) __must_hold(local)
34983523 {
3499− int rv = -EIO;
3500−
35013524 drbd_resume_al(device);
3502− if (get_ldev_if_state(device, D_ATTACHING)) {
3503− drbd_bm_clear_all(device);
3504− rv = drbd_bm_write(device);
3505− put_ldev(device);
3506− }
3507−
3508− return rv;
3525+ drbd_bm_clear_all(device);
3526+ return drbd_bm_write(device);
35093527 }
35103528
35113529 static int w_bitmap_io(struct drbd_work *w, int unused)
@@ -3537,61 +3555,6 @@ static int w_bitmap_io(struct drbd_work *w, int unused) · 25 unmodified lines
35373555 return 0;
35383556 }
35393557
3540−void drbd_ldev_destroy(struct drbd_device *device)
3541−{
3542− lc_destroy(device->resync);
3543− device->resync = NULL;
3544− lc_destroy(device->act_log);
3545− device->act_log = NULL;
3546− __no_warn(local,
3547− drbd_free_bc(device->ldev);
3548− device->ldev = NULL;);
3549−
3550− clear_bit(GO_DISKLESS, &device->flags);
3551−}
3552−
3553−static int w_go_diskless(struct drbd_work *w, int unused)
3554−{
3555− struct drbd_device *device =
3556− container_of(w, struct drbd_device, go_diskless);
3557−
3558− D_ASSERT(device, device->state.disk == D_FAILED);
3559− /* we cannot assert local_cnt == 0 here, as get_ldev_if_state will
3560− * inc/dec it frequently. Once we are D_DISKLESS, no one will touch
3561− * the protected members anymore, though, so once put_ldev reaches zero
3562− * again, it will be safe to free them. */
3563−
3564− /* Try to write changed bitmap pages, read errors may have just
3565− * set some bits outside the area covered by the activity log.
3566− *
3567− * If we have an IO error during the bitmap writeout,
3568− * we will want a full sync next time, just in case.
3569− * (Do we want a specific meta data flag for this?)
3570− *
3571− * If that does not make it to stable storage either,
3572− * we cannot do anything about that anymore.
3573− *
3574− * We still need to check if both bitmap and ldev are present, we may
3575− * end up here after a failed attach, before ldev was even assigned.
3576− */
3577− if (device->bitmap && device->ldev) {
3578− /* An interrupted resync or similar is allowed to recounts bits
3579− * while we detach.
3580− * Any modifications would not be expected anymore, though.
3581− */
3582− if (drbd_bitmap_io_from_worker(device, drbd_bm_write,
3583− "detach", BM_LOCKED_TEST_ALLOWED)) {
3584− if (test_bit(WAS_READ_ERROR, &device->flags)) {
3585− drbd_md_set_flag(device, MDF_FULL_SYNC);
3586− drbd_md_sync(device);
3587− }
3588− }
3589− }
3590−
3591− drbd_force_state(device, NS(disk, D_DISKLESS));
3592− return 0;
3593−}
3594−
35953558 /**
35963559 * drbd_queue_bitmap_io() - Queues an IO operation on the whole bitmap
35973560 * @device: DRBD device.
@@ -3603,6 +3566,9 @@ static int w_go_diskless(struct drbd_work *w, int unused) · 5 unmodified lines
36033566 * that drbd_set_out_of_sync() can not be called. This function MAY ONLY be
36043567 * called from worker context. It MUST NOT be used while a previous such
36053568 * work is still pending!
3569+ *
3570+ * Its worker function encloses the call of io_fn() by get_ldev() and
3571+ * put_ldev().
36063572 */
36073573 void drbd_queue_bitmap_io(struct drbd_device *device,
36083574 int (*io_fn)(struct drbd_device *),
@@ -3685,25 +3651,7 @@ int drbd_md_test_flag(struct drbd_backing_dev *bdev, int flag) · 76 unmodified lines
36853651 static void md_sync_timer_fn(unsigned long data)
36863652 {
36873653 struct drbd_device *device = (struct drbd_device *) data;
3688−
3689− /* must not double-queue! */
3690− if (list_empty(&device->md_sync_work.list))
3691− drbd_queue_work_front(&first_peer_device(device)->connection->sender_work,
3692− &device->md_sync_work);
3693−}
3694−
3695−static int w_md_sync(struct drbd_work *w, int unused)
3696−{
3697− struct drbd_device *device =
3698− container_of(w, struct drbd_device, md_sync_work);
3699−
3700− drbd_warn(device, "md_sync_timer expired! Worker calls drbd_md_sync().\n");
3701−#ifdef DEBUG
3702− drbd_warn(device, "last md_mark_dirty: %s:%u\n",
3703− device->last_md_mark_dirty.func, device->last_md_mark_dirty.line);
3704−#endif
3705− drbd_md_sync(device);
3706− return 0;
3654+ drbd_device_post_work(device, MD_SYNC);
37073655 }
37083656
37093657 const char *cmdname(enum drbd_packet cmd)
drivers/block/drbd/drbd_nl.c+66−44
@@ -23,6 +23,8 @@ · 22 unmodified lines
2323
2424 */
2525
26+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27+
2628 #include <linux/module.h>
2729 #include <linux/drbd.h>
2830 #include <linux/in.h>
@@ -85,7 +87,7 @@ static void drbd_adm_send_reply(struct sk_buff *skb, struct genl_info *info) · 56 unmodified lines
8587 {
8688 genlmsg_end(skb, genlmsg_data(nlmsg_data(nlmsg_hdr(skb))));
8789 if (genlmsg_reply(skb, info))
88− printk(KERN_ERR "drbd: error sending genl reply\n");
90+ pr_err("error sending genl reply\n");
8991 }
9092
9193 /* Used on a fresh "drbd_adm_prepare"d reply_skb, this cannot fail: The only
@@ -558,8 +560,10 @@ void conn_try_outdate_peer_async(struct drbd_connection *connection) · 466 unmodified lines
558560 }
559561
560562 enum drbd_state_rv
561−drbd_set_role(struct drbd_device *device, enum drbd_role new_role, int force)
563+drbd_set_role(struct drbd_device *const device, enum drbd_role new_role, int force)
562564 {
565+ struct drbd_peer_device *const peer_device = first_peer_device(device);
566+ struct drbd_connection *const connection = peer_device ? peer_device->connection : NULL;
563567 const int max_tries = 4;
564568 enum drbd_state_rv rv = SS_UNKNOWN_ERROR;
565569 struct net_conf *nc;
@@ -607,7 +611,7 @@ drbd_set_role(struct drbd_device *device, enum drbd_role new_role, int force) · 41 unmodified lines
607611 device->state.disk == D_CONSISTENT && mask.pdsk == 0) {
608612 D_ASSERT(device, device->state.pdsk == D_UNKNOWN);
609613
610− if (conn_try_outdate_peer(first_peer_device(device)->connection)) {
614+ if (conn_try_outdate_peer(connection)) {
611615 val.disk = D_UP_TO_DATE;
612616 mask.disk = D_MASK;
613617 }
@@ -617,7 +621,7 @@ drbd_set_role(struct drbd_device *device, enum drbd_role new_role, int force) · 3 unmodified lines
617621 if (rv == SS_NOTHING_TO_DO)
618622 goto out;
619623 if (rv == SS_PRIMARY_NOP && mask.pdsk == 0) {
620− if (!conn_try_outdate_peer(first_peer_device(device)->connection) && force) {
624+ if (!conn_try_outdate_peer(connection) && force) {
621625 drbd_warn(device, "Forced into split brain situation!\n");
622626 mask.pdsk = D_MASK;
623627 val.pdsk = D_OUTDATED;
@@ -630,7 +634,7 @@ drbd_set_role(struct drbd_device *device, enum drbd_role new_role, int force) · 6 unmodified lines
630634 retry at most once more in this case. */
631635 int timeo;
632636 rcu_read_lock();
633− nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
637+ nc = rcu_dereference(connection->net_conf);
634638 timeo = nc ? (nc->ping_timeo + 1) * HZ / 10 : 1;
635639 rcu_read_unlock();
636640 schedule_timeout_interruptible(timeo);
@@ -659,19 +663,17 @@ drbd_set_role(struct drbd_device *device, enum drbd_role new_role, int force) · 22 unmodified lines
659663 /* FIXME also wait for all pending P_BARRIER_ACK? */
660664
661665 if (new_role == R_SECONDARY) {
662− set_disk_ro(device->vdisk, true);
663666 if (get_ldev(device)) {
664667 device->ldev->md.uuid[UI_CURRENT] &= ~(u64)1;
665668 put_ldev(device);
666669 }
667670 } else {
668− /* Called from drbd_adm_set_role only.
669− * We are still holding the conf_update mutex. */
670− nc = first_peer_device(device)->connection->net_conf;
671+ mutex_lock(&device->resource->conf_update);
672+ nc = connection->net_conf;
671673 if (nc)
672674 nc->discard_my_data = 0; /* without copy; single bit op is atomic */
675+ mutex_unlock(&device->resource->conf_update);
673676
674− set_disk_ro(device->vdisk, false);
675677 if (get_ldev(device)) {
676678 if (((device->state.conn < C_CONNECTED ||
677679 device->state.pdsk <= D_FAILED)
@@ -689,12 +691,12 @@ drbd_set_role(struct drbd_device *device, enum drbd_role new_role, int force) · 11 unmodified lines
689691 if (device->state.conn >= C_WF_REPORT_PARAMS) {
690692 /* if this was forced, we should consider sync */
691693 if (forced)
692− drbd_send_uuids(first_peer_device(device));
693− drbd_send_current_state(first_peer_device(device));
694+ drbd_send_uuids(peer_device);
695+ drbd_send_current_state(peer_device);
694696 }
695697
696698 drbd_md_sync(device);
697−
699+ set_disk_ro(device->vdisk, new_role == R_SECONDARY);
698700 kobject_uevent(&disk_to_dev(device->vdisk)->kobj, KOBJ_CHANGE);
699701 out:
700702 mutex_unlock(device->state_mutex);
@@ -891,7 +893,7 @@ drbd_determine_dev_size(struct drbd_device *device, enum dds_flags flags, struct · 190 unmodified lines
891893 * still lock the act_log to not trigger ASSERTs there.
892894 */
893895 drbd_suspend_io(device);
894− buffer = drbd_md_get_buffer(device); /* Lock meta-data IO */
896+ buffer = drbd_md_get_buffer(device, __func__); /* Lock meta-data IO */
895897 if (!buffer) {
896898 drbd_resume_io(device);
897899 return DS_ERROR;
@@ -971,6 +973,10 @@ drbd_determine_dev_size(struct drbd_device *device, enum dds_flags flags, struct · 73 unmodified lines
971973 if (la_size_changed || md_moved || rs) {
972974 u32 prev_flags;
973975
976+ /* We do some synchronous IO below, which may take some time.
977+ * Clear the timer, to avoid scary "timer expired!" messages,
978+ * "Superblock" is written out at least twice below, anyways. */
979+ del_timer(&device->md_sync_timer);
974980 drbd_al_shrink(device); /* All extents inactive. */
975981
976982 prev_flags = md->flags;
@@ -1116,15 +1122,16 @@ static int drbd_check_al_size(struct drbd_device *device, struct disk_conf *dc) · 139 unmodified lines
11161122 return 0;
11171123 }
11181124
1119−static void drbd_setup_queue_param(struct drbd_device *device, unsigned int max_bio_size)
1125+static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backing_dev *bdev,
1126+ unsigned int max_bio_size)
11201127 {
11211128 struct request_queue * const q = device->rq_queue;
11221129 unsigned int max_hw_sectors = max_bio_size >> 9;
11231130 unsigned int max_segments = 0;
11241131 struct request_queue *b = NULL;
11251132
1126− if (get_ldev_if_state(device, D_ATTACHING)) {
1127− b = device->ldev->backing_bdev->bd_disk->queue;
1133+ if (bdev) {
1134+ b = bdev->backing_bdev->bd_disk->queue;
11281135
11291136 max_hw_sectors = min(queue_max_hw_sectors(b), max_bio_size >> 9);
11301137 rcu_read_lock();
@@ -1169,11 +1176,10 @@ static void drbd_setup_queue_param(struct drbd_device *device, unsigned int max_ · 38 unmodified lines
11691176 b->backing_dev_info.ra_pages);
11701177 q->backing_dev_info.ra_pages = b->backing_dev_info.ra_pages;
11711178 }
1172− put_ldev(device);
11731179 }
11741180 }
11751181
1176−void drbd_reconsider_max_bio_size(struct drbd_device *device)
1182+void drbd_reconsider_max_bio_size(struct drbd_device *device, struct drbd_backing_dev *bdev)
11771183 {
11781184 unsigned int now, new, local, peer;
11791185
@@ -1181,10 +1187,9 @@ void drbd_reconsider_max_bio_size(struct drbd_device *device) · 1 unmodified line
11811187 local = device->local_max_bio_size; /* Eventually last known value, from volatile memory */
11821188 peer = device->peer_max_bio_size; /* Eventually last known value, from meta data */
11831189
1184− if (get_ldev_if_state(device, D_ATTACHING)) {
1185− local = queue_max_hw_sectors(device->ldev->backing_bdev->bd_disk->queue) << 9;
1190+ if (bdev) {
1191+ local = queue_max_hw_sectors(bdev->backing_bdev->bd_disk->queue) << 9;
11861192 device->local_max_bio_size = local;
1187− put_ldev(device);
11881193 }
11891194 local = min(local, DRBD_MAX_BIO_SIZE);
11901195
@@ -1217,7 +1222,7 @@ void drbd_reconsider_max_bio_size(struct drbd_device *device) · 26 unmodified lines
12171222 if (new != now)
12181223 drbd_info(device, "max BIO size = %u\n", new);
12191224
1220− drbd_setup_queue_param(device, new);
1225+ drbd_setup_queue_param(device, bdev, new);
12211226 }
12221227
12231228 /* Starts the worker thread */
@@ -1299,6 +1304,13 @@ static unsigned int drbd_al_extents_max(struct drbd_backing_dev *bdev) · 75 unmodified lines
12991304 return (al_size_4k - 1) * AL_CONTEXT_PER_TRANSACTION;
13001305 }
13011306
1307+static bool write_ordering_changed(struct disk_conf *a, struct disk_conf *b)
1308+{
1309+ return a->disk_barrier != b->disk_barrier ||
1310+ a->disk_flushes != b->disk_flushes ||
1311+ a->disk_drain != b->disk_drain;
1312+}
1313+
13021314 int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
13031315 {
13041316 struct drbd_config_context adm_ctx;
@@ -1405,7 +1417,8 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) · 100 unmodified lines
14051417 else
14061418 set_bit(MD_NO_FUA, &device->flags);
14071419
1408− drbd_bump_write_ordering(first_peer_device(device)->connection, WO_bdev_flush);
1420+ if (write_ordering_changed(old_disk_conf, new_disk_conf))
1421+ drbd_bump_write_ordering(device->resource, NULL, WO_bdev_flush);
14091422
14101423 drbd_md_sync(device);
14111424
@@ -1440,6 +1453,8 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 28 unmodified lines
14401453 {
14411454 struct drbd_config_context adm_ctx;
14421455 struct drbd_device *device;
1456+ struct drbd_peer_device *peer_device;
1457+ struct drbd_connection *connection;
14431458 int err;
14441459 enum drbd_ret_code retcode;
14451460 enum determine_dev_size dd;
@@ -1462,7 +1477,9 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 16 unmodified lines
14621477
14631478 device = adm_ctx.device;
14641479 mutex_lock(&adm_ctx.resource->adm_mutex);
1465− conn_reconfig_start(first_peer_device(device)->connection);
1480+ peer_device = first_peer_device(device);
1481+ connection = peer_device ? peer_device->connection : NULL;
1482+ conn_reconfig_start(connection);
14661483
14671484 /* if you want to reconfigure, please tear down first */
14681485 if (device->state.disk > D_DISKLESS) {
@@ -1473,7 +1490,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 4 unmodified lines
14731490 * drbd_ldev_destroy is done already, we may end up here very fast,
14741491 * e.g. if someone calls attach from the on-io-error handler,
14751492 * to realize a "hot spare" feature (not that I'd recommend that) */
1476− wait_event(device->misc_wait, !atomic_read(&device->local_cnt));
1493+ wait_event(device->misc_wait, !test_bit(GOING_DISKLESS, &device->flags));
14771494
14781495 /* make sure there is no leftover from previous force-detach attempts */
14791496 clear_bit(FORCE_DETACH, &device->flags);
@@ -1529,7 +1546,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 49 unmodified lines
15291546 goto fail;
15301547
15311548 rcu_read_lock();
1532− nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
1549+ nc = rcu_dereference(connection->net_conf);
15331550 if (nc) {
15341551 if (new_disk_conf->fencing == FP_STONITH && nc->wire_protocol == DRBD_PROT_A) {
15351552 rcu_read_unlock();
@@ -1649,7 +1666,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 113 unmodified lines
16491666 */
16501667 wait_event(device->misc_wait, !atomic_read(&device->ap_pending_cnt) || drbd_suspended(device));
16511668 /* and for any other previously queued work */
1652− drbd_flush_workqueue(&first_peer_device(device)->connection->sender_work);
1669+ drbd_flush_workqueue(&connection->sender_work);
16531670
16541671 rv = _drbd_request_state(device, NS(disk, D_ATTACHING), CS_VERBOSE);
16551672 retcode = rv; /* FIXME: Type mismatch. */
@@ -1710,7 +1727,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 54 unmodified lines
17101727 new_disk_conf = NULL;
17111728 new_plan = NULL;
17121729
1713− drbd_bump_write_ordering(first_peer_device(device)->connection, WO_bdev_flush);
1730+ drbd_bump_write_ordering(device->resource, device->ldev, WO_bdev_flush);
17141731
17151732 if (drbd_md_test_flag(device->ldev, MDF_CRASHED_PRIMARY))
17161733 set_bit(CRASHED_PRIMARY, &device->flags);
@@ -1726,7 +1743,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 9 unmodified lines
17261743 device->read_cnt = 0;
17271744 device->writ_cnt = 0;
17281745
1729− drbd_reconsider_max_bio_size(device);
1746+ drbd_reconsider_max_bio_size(device, device->ldev);
17301747
17311748 /* If I am currently not R_PRIMARY,
17321749 * but meta data primary indicator is set,
@@ -1845,7 +1862,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 112 unmodified lines
18451862
18461863 kobject_uevent(&disk_to_dev(device->vdisk)->kobj, KOBJ_CHANGE);
18471864 put_ldev(device);
1848− conn_reconfig_done(first_peer_device(device)->connection);
1865+ conn_reconfig_done(connection);
18491866 mutex_unlock(&adm_ctx.resource->adm_mutex);
18501867 drbd_adm_finish(&adm_ctx, info, retcode);
18511868 return 0;
@@ -1856,7 +1873,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) · 4 unmodified lines
18561873 drbd_force_state(device, NS(disk, D_DISKLESS));
18571874 drbd_md_sync(device);
18581875 fail:
1859− conn_reconfig_done(first_peer_device(device)->connection);
1876+ conn_reconfig_done(connection);
18601877 if (nbc) {
18611878 if (nbc->backing_bdev)
18621879 blkdev_put(nbc->backing_bdev,
@@ -1888,7 +1905,7 @@ static int adm_detach(struct drbd_device *device, int force) · 25 unmodified lines
18881905 }
18891906
18901907 drbd_suspend_io(device); /* so no-one is stuck in drbd_al_begin_io */
1891− drbd_md_get_buffer(device); /* make sure there is no in-flight meta-data IO */
1908+ drbd_md_get_buffer(device, __func__); /* make sure there is no in-flight meta-data IO */
18921909 retcode = drbd_request_state(device, NS(disk, D_FAILED));
18931910 drbd_md_put_buffer(device);
18941911 /* D_FAILED will transition to DISKLESS. */
@@ -2654,8 +2671,13 @@ int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info) · 759 unmodified lines
26542671 if (retcode != NO_ERROR)
26552672 goto out;
26562673
2657− mutex_lock(&adm_ctx.resource->adm_mutex);
26582674 device = adm_ctx.device;
2675+ if (!get_ldev(device)) {
2676+ retcode = ERR_NO_DISK;
2677+ goto out;
2678+ }
2679+
2680+ mutex_lock(&adm_ctx.resource->adm_mutex);
26592681
26602682 /* If there is still bitmap IO pending, probably because of a previous
26612683 * resync just being finished, wait for it before requesting a new resync.
@@ -2679,6 +2701,7 @@ int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info) · 17 unmodified lines
26792701 retcode = drbd_request_state(device, NS(conn, C_STARTING_SYNC_T));
26802702 drbd_resume_io(device);
26812703 mutex_unlock(&adm_ctx.resource->adm_mutex);
2704+ put_ldev(device);
26822705 out:
26832706 drbd_adm_finish(&adm_ctx, info, retcode);
26842707 return 0;
@@ -2704,7 +2727,7 @@ out: · 19 unmodified lines
27042727 return 0;
27052728 }
27062729
2707−static int drbd_bmio_set_susp_al(struct drbd_device *device)
2730+static int drbd_bmio_set_susp_al(struct drbd_device *device) __must_hold(local)
27082731 {
27092732 int rv;
27102733
@@ -2725,8 +2748,13 @@ int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info) · 14 unmodified lines
27252748 if (retcode != NO_ERROR)
27262749 goto out;
27272750
2728− mutex_lock(&adm_ctx.resource->adm_mutex);
27292751 device = adm_ctx.device;
2752+ if (!get_ldev(device)) {
2753+ retcode = ERR_NO_DISK;
2754+ goto out;
2755+ }
2756+
2757+ mutex_lock(&adm_ctx.resource->adm_mutex);
27302758
27312759 /* If there is still bitmap IO pending, probably because of a previous
27322760 * resync just being finished, wait for it before requesting a new resync.
@@ -2753,6 +2781,7 @@ int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info) · 20 unmodified lines
27532781 retcode = drbd_request_state(device, NS(conn, C_STARTING_SYNC_S));
27542782 drbd_resume_io(device);
27552783 mutex_unlock(&adm_ctx.resource->adm_mutex);
2784+ put_ldev(device);
27562785 out:
27572786 drbd_adm_finish(&adm_ctx, info, retcode);
27582787 return 0;
@@ -2892,7 +2921,7 @@ static struct drbd_connection *the_only_connection(struct drbd_resource *resourc · 133 unmodified lines
28922921 return list_first_entry(&resource->connections, struct drbd_connection, connections);
28932922 }
28942923
2895−int nla_put_status_info(struct sk_buff *skb, struct drbd_device *device,
2924+static int nla_put_status_info(struct sk_buff *skb, struct drbd_device *device,
28962925 const struct sib_info *sib)
28972926 {
28982927 struct drbd_resource *resource = device->resource;
@@ -3622,13 +3651,6 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib) · 723 unmodified lines
36223651 unsigned seq;
36233652 int err = -ENOMEM;
36243653
3625− if (sib->sib_reason == SIB_SYNC_PROGRESS) {
3626− if (time_after(jiffies, device->rs_last_bcast + HZ))
3627− device->rs_last_bcast = jiffies;
3628− else
3629− return;
3630− }
3631−
36323654 seq = atomic_inc_return(&drbd_genl_seq);
36333655 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36343656 if (!msg)
drivers/block/drbd/drbd_proc.c+79−46
@@ -60,20 +60,65 @@ static void seq_printf_with_thousands_grouping(struct seq_file *seq, long v) · 59 unmodified lines
6060 seq_printf(seq, "%ld", v);
6161 }
6262
63+static void drbd_get_syncer_progress(struct drbd_device *device,
64+ union drbd_dev_state state, unsigned long *rs_total,
65+ unsigned long *bits_left, unsigned int *per_mil_done)
66+{
67+ /* this is to break it at compile time when we change that, in case we
68+ * want to support more than (1<<32) bits on a 32bit arch. */
69+ typecheck(unsigned long, device->rs_total);
70+ *rs_total = device->rs_total;
71+
72+ /* note: both rs_total and rs_left are in bits, i.e. in
73+ * units of BM_BLOCK_SIZE.
74+ * for the percentage, we don't care. */
75+
76+ if (state.conn == C_VERIFY_S || state.conn == C_VERIFY_T)
77+ *bits_left = device->ov_left;
78+ else
79+ *bits_left = drbd_bm_total_weight(device) - device->rs_failed;
80+ /* >> 10 to prevent overflow,
81+ * +1 to prevent division by zero */
82+ if (*bits_left > *rs_total) {
83+ /* D'oh. Maybe a logic bug somewhere. More likely just a race
84+ * between state change and reset of rs_total.
85+ */
86+ *bits_left = *rs_total;
87+ *per_mil_done = *rs_total ? 0 : 1000;
88+ } else {
89+ /* Make sure the division happens in long context.
90+ * We allow up to one petabyte storage right now,
91+ * at a granularity of 4k per bit that is 2**38 bits.
92+ * After shift right and multiplication by 1000,
93+ * this should still fit easily into a 32bit long,
94+ * so we don't need a 64bit division on 32bit arch.
95+ * Note: currently we don't support such large bitmaps on 32bit
96+ * arch anyways, but no harm done to be prepared for it here.
97+ */
98+ unsigned int shift = *rs_total > UINT_MAX ? 16 : 10;
99+ unsigned long left = *bits_left >> shift;
100+ unsigned long total = 1UL + (*rs_total >> shift);
101+ unsigned long tmp = 1000UL - left * 1000UL/total;
102+ *per_mil_done = tmp;
103+ }
104+}
105+
106+
63107 /*lge
64108 * progress bars shamelessly adapted from driver/md/md.c
65109 * output looks like
66110 * [=====>..............] 33.5% (23456/123456)
67111 * finish: 2:20:20 speed: 6,345 (6,456) K/sec
68112 */
69−static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *seq)
113+static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *seq,
114+ union drbd_dev_state state)
70115 {
71− unsigned long db, dt, dbdt, rt, rs_left;
116+ unsigned long db, dt, dbdt, rt, rs_total, rs_left;
72117 unsigned int res;
73118 int i, x, y;
74119 int stalled = 0;
75120
76− drbd_get_syncer_progress(device, &rs_left, &res);
121+ drbd_get_syncer_progress(device, state, &rs_total, &rs_left, &res);
77122
78123 x = res/50;
79124 y = 20-x;
@@ -85,21 +130,21 @@ static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *se · 5 unmodified lines
85130 seq_printf(seq, ".");
86131 seq_printf(seq, "] ");
87132
88− if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T)
133+ if (state.conn == C_VERIFY_S || state.conn == C_VERIFY_T)
89134 seq_printf(seq, "verified:");
90135 else
91136 seq_printf(seq, "sync'ed:");
92137 seq_printf(seq, "%3u.%u%% ", res / 10, res % 10);
93138
94139 /* if more than a few GB, display in MB */
95− if (device->rs_total > (4UL << (30 - BM_BLOCK_SHIFT)))
140+ if (rs_total > (4UL << (30 - BM_BLOCK_SHIFT)))
96141 seq_printf(seq, "(%lu/%lu)M",
97142 (unsigned long) Bit2KB(rs_left >> 10),
98− (unsigned long) Bit2KB(device->rs_total >> 10));
143+ (unsigned long) Bit2KB(rs_total >> 10));
99144 else
100145 seq_printf(seq, "(%lu/%lu)K\n\t",
101146 (unsigned long) Bit2KB(rs_left),
102− (unsigned long) Bit2KB(device->rs_total));
147+ (unsigned long) Bit2KB(rs_total));
103148
104149 /* see drivers/md/md.c
105150 * We do not want to overflow, so the order of operands and
@@ -150,13 +195,13 @@ static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *se · 44 unmodified lines
150195 dt = (jiffies - device->rs_start - device->rs_paused) / HZ;
151196 if (dt == 0)
152197 dt = 1;
153− db = device->rs_total - rs_left;
198+ db = rs_total - rs_left;
154199 dbdt = Bit2KB(db/dt);
155200 seq_printf_with_thousands_grouping(seq, dbdt);
156201 seq_printf(seq, ")");
157202
158− if (device->state.conn == C_SYNC_TARGET ||
159− device->state.conn == C_VERIFY_S) {
203+ if (state.conn == C_SYNC_TARGET ||
204+ state.conn == C_VERIFY_S) {
160205 seq_printf(seq, " want: ");
161206 seq_printf_with_thousands_grouping(seq, device->c_sync_rate);
162207 }
@@ -168,8 +213,8 @@ static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *se · 5 unmodified lines
168213 unsigned long bm_bits = drbd_bm_bits(device);
169214 unsigned long bit_pos;
170215 unsigned long long stop_sector = 0;
171− if (device->state.conn == C_VERIFY_S ||
172− device->state.conn == C_VERIFY_T) {
216+ if (state.conn == C_VERIFY_S ||
217+ state.conn == C_VERIFY_T) {
173218 bit_pos = bm_bits - device->ov_left;
174219 if (verify_can_do_stop_sector(device))
175220 stop_sector = device->ov_stop_sector;
@@ -188,22 +233,13 @@ static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *se · 12 unmodified lines
188233 }
189234 }
190235
191−static void resync_dump_detail(struct seq_file *seq, struct lc_element *e)
192−{
193− struct bm_extent *bme = lc_entry(e, struct bm_extent, lce);
194−
195− seq_printf(seq, "%5d %s %s\n", bme->rs_left,
196− bme->flags & BME_NO_WRITES ? "NO_WRITES" : "---------",
197− bme->flags & BME_LOCKED ? "LOCKED" : "------"
198− );
199−}
200−
201236 static int drbd_seq_show(struct seq_file *seq, void *v)
202237 {
203238 int i, prev_i = -1;
204239 const char *sn;
205240 struct drbd_device *device;
206241 struct net_conf *nc;
242+ union drbd_dev_state state;
207243 char wp;
208244
209245 static char write_ordering_chars[] = {
@@ -241,11 +277,12 @@ static int drbd_seq_show(struct seq_file *seq, void *v) · 31 unmodified lines
241277 seq_printf(seq, "\n");
242278 prev_i = i;
243279
244− sn = drbd_conn_str(device->state.conn);
280+ state = device->state;
281+ sn = drbd_conn_str(state.conn);
245282
246− if (device->state.conn == C_STANDALONE &&
247− device->state.disk == D_DISKLESS &&
248− device->state.role == R_SECONDARY) {
283+ if (state.conn == C_STANDALONE &&
284+ state.disk == D_DISKLESS &&
285+ state.role == R_SECONDARY) {
249286 seq_printf(seq, "%2d: cs:Unconfigured\n", i);
250287 } else {
251288 /* reset device->congestion_reason */
@@ -258,15 +295,15 @@ static int drbd_seq_show(struct seq_file *seq, void *v) · 6 unmodified lines
258295 " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
259296 "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
260297 i, sn,
261− drbd_role_str(device->state.role),
262− drbd_role_str(device->state.peer),
263− drbd_disk_str(device->state.disk),
264− drbd_disk_str(device->state.pdsk),
298+ drbd_role_str(state.role),
299+ drbd_role_str(state.peer),
300+ drbd_disk_str(state.disk),
301+ drbd_disk_str(state.pdsk),
265302 wp,
266303 drbd_suspended(device) ? 's' : 'r',
267− device->state.aftr_isp ? 'a' : '-',
268− device->state.peer_isp ? 'p' : '-',
269− device->state.user_isp ? 'u' : '-',
304+ state.aftr_isp ? 'a' : '-',
305+ state.peer_isp ? 'p' : '-',
306+ state.user_isp ? 'u' : '-',
270307 device->congestion_reason ?: '-',
271308 test_bit(AL_SUSPENDED, &device->flags) ? 's' : '-',
272309 device->send_cnt/2,
@@ -281,17 +318,17 @@ static int drbd_seq_show(struct seq_file *seq, void *v) · 8 unmodified lines
281318 atomic_read(&device->unacked_cnt),
282319 atomic_read(&device->ap_bio_cnt),
283320 first_peer_device(device)->connection->epochs,
284− write_ordering_chars[first_peer_device(device)->connection->write_ordering]
321+ write_ordering_chars[device->resource->write_ordering]
285322 );
286323 seq_printf(seq, " oos:%llu\n",
287324 Bit2KB((unsigned long long)
288325 drbd_bm_total_weight(device)));
289326 }
290− if (device->state.conn == C_SYNC_SOURCE ||
291− device->state.conn == C_SYNC_TARGET ||
292− device->state.conn == C_VERIFY_S ||
293− device->state.conn == C_VERIFY_T)
294− drbd_syncer_progress(device, seq);
327+ if (state.conn == C_SYNC_SOURCE ||
328+ state.conn == C_SYNC_TARGET ||
329+ state.conn == C_VERIFY_S ||
330+ state.conn == C_VERIFY_T)
331+ drbd_syncer_progress(device, seq, state);
295332
296333 if (proc_details >= 1 && get_ldev_if_state(device, D_FAILED)) {
297334 lc_seq_printf_stats(seq, device->resync);
@@ -299,12 +336,8 @@ static int drbd_seq_show(struct seq_file *seq, void *v) · 1 unmodified line
299336 put_ldev(device);
300337 }
301338
302− if (proc_details >= 2) {
303− if (device->resync) {
304− lc_seq_dump_details(seq, device->resync, "rs_left",
305− resync_dump_detail);
306− }
307− }
339+ if (proc_details >= 2)
340+ seq_printf(seq, "\tblocked on activity log: %d\n", atomic_read(&device->ap_actlog_cnt));
308341 }
309342 rcu_read_unlock();
310343
@@ -316,7 +349,7 @@ static int drbd_proc_open(struct inode *inode, struct file *file) · 5 unmodified lines
316349 int err;
317350
318351 if (try_module_get(THIS_MODULE)) {
319− err = single_open(file, drbd_seq_show, PDE_DATA(inode));
352+ err = single_open(file, drbd_seq_show, NULL);
320353 if (err)
321354 module_put(THIS_MODULE);
322355 return err;
drivers/block/drbd/drbd_receiver.c+211−105
@@ -362,17 +362,14 @@ drbd_alloc_peer_req(struct drbd_peer_device *peer_device, u64 id, sector_t secto · 361 unmodified lines
362362 goto fail;
363363 }
364364
365+ memset(peer_req, 0, sizeof(*peer_req));
366+ INIT_LIST_HEAD(&peer_req->w.list);
365367 drbd_clear_interval(&peer_req->i);
366368 peer_req->i.size = data_size;
367369 peer_req->i.sector = sector;
368− peer_req->i.local = false;
369− peer_req->i.waiting = false;
370−
371− peer_req->epoch = NULL;
370+ peer_req->submit_jif = jiffies;
372371 peer_req->peer_device = peer_device;
373372 peer_req->pages = page;
374− atomic_set(&peer_req->pending_bios, 0);
375− peer_req->flags = 0;
376373 /*
377374 * The block_id is opaque to the receiver. It is not endianness
378375 * converted, and sent back to the sender unchanged.
@@ -389,11 +386,16 @@ drbd_alloc_peer_req(struct drbd_peer_device *peer_device, u64 id, sector_t secto · 10 unmodified lines
389386 void __drbd_free_peer_req(struct drbd_device *device, struct drbd_peer_request *peer_req,
390387 int is_net)
391388 {
389+ might_sleep();
392390 if (peer_req->flags & EE_HAS_DIGEST)
393391 kfree(peer_req->digest);
394392 drbd_free_pages(device, peer_req->pages, is_net);
395393 D_ASSERT(device, atomic_read(&peer_req->pending_bios) == 0);
396394 D_ASSERT(device, drbd_interval_empty(&peer_req->i));
395+ if (!expect(!(peer_req->flags & EE_CALL_AL_COMPLETE_IO))) {
396+ peer_req->flags &= ~EE_CALL_AL_COMPLETE_IO;
397+ drbd_al_complete_io(device, &peer_req->i);
398+ }
397399 mempool_free(peer_req, drbd_ee_mempool);
398400 }
399401
@@ -791,8 +793,18 @@ static int receive_first_packet(struct drbd_connection *connection, struct socke · 391 unmodified lines
791793 {
792794 unsigned int header_size = drbd_header_size(connection);
793795 struct packet_info pi;
796+ struct net_conf *nc;
794797 int err;
795798
799+ rcu_read_lock();
800+ nc = rcu_dereference(connection->net_conf);
801+ if (!nc) {
802+ rcu_read_unlock();
803+ return -EIO;
804+ }
805+ sock->sk->sk_rcvtimeo = nc->ping_timeo * 4 * HZ / 10;
806+ rcu_read_unlock();
807+
796808 err = drbd_recv_short(sock, connection->data.rbuf, header_size, 0);
797809 if (err != header_size) {
798810 if (err >= 0)
@@ -809,7 +821,7 @@ static int receive_first_packet(struct drbd_connection *connection, struct socke · 10 unmodified lines
809821 * drbd_socket_okay() - Free the socket if its connection is not okay
810822 * @sock: pointer to the pointer to the socket.
811823 */
812−static int drbd_socket_okay(struct socket **sock)
824+static bool drbd_socket_okay(struct socket **sock)
813825 {
814826 int rr;
815827 char tb[4];
@@ -827,6 +839,30 @@ static int drbd_socket_okay(struct socket **sock) · 11 unmodified lines
827839 return false;
828840 }
829841 }
842+
843+static bool connection_established(struct drbd_connection *connection,
844+ struct socket **sock1,
845+ struct socket **sock2)
846+{
847+ struct net_conf *nc;
848+ int timeout;
849+ bool ok;
850+
851+ if (!*sock1 || !*sock2)
852+ return false;
853+
854+ rcu_read_lock();
855+ nc = rcu_dereference(connection->net_conf);
856+ timeout = (nc->sock_check_timeo ?: nc->ping_timeo) * HZ / 10;
857+ rcu_read_unlock();
858+ schedule_timeout_interruptible(timeout);
859+
860+ ok = drbd_socket_okay(sock1);
861+ ok = drbd_socket_okay(sock2) && ok;
862+
863+ return ok;
864+}
865+
830866 /* Gets called if a connection is established, or if a new minor gets created
831867 in a connection */
832868 int drbd_connected(struct drbd_peer_device *peer_device)
@@ -868,8 +904,8 @@ static int conn_connect(struct drbd_connection *connection) · 35 unmodified lines
868904 struct drbd_socket sock, msock;
869905 struct drbd_peer_device *peer_device;
870906 struct net_conf *nc;
871− int vnr, timeout, h, ok;
872− bool discard_my_data;
907+ int vnr, timeout, h;
908+ bool discard_my_data, ok;
873909 enum drbd_state_rv rv;
874910 struct accept_wait_data ad = {
875911 .connection = connection,
@@ -913,17 +949,8 @@ static int conn_connect(struct drbd_connection *connection) · 37 unmodified lines
913949 }
914950 }
915951
916− if (sock.socket && msock.socket) {
917− rcu_read_lock();
918− nc = rcu_dereference(connection->net_conf);
919− timeout = nc->ping_timeo * HZ / 10;
920− rcu_read_unlock();
921− schedule_timeout_interruptible(timeout);
922− ok = drbd_socket_okay(&sock.socket);
923− ok = drbd_socket_okay(&msock.socket) && ok;
924− if (ok)
925− break;
926− }
952+ if (connection_established(connection, &sock.socket, &msock.socket))
953+ break;
927954
928955 retry:
929956 s = drbd_wait_for_connect(connection, &ad);
@@ -969,8 +996,7 @@ randomize: · 39 unmodified lines
969996 goto out_release_sockets;
970997 }
971998
972− ok = drbd_socket_okay(&sock.socket);
973− ok = drbd_socket_okay(&msock.socket) && ok;
999+ ok = connection_established(connection, &sock.socket, &msock.socket);
9741000 } while (!ok);
9751001
9761002 if (ad.s_listen)
@@ -1151,7 +1177,7 @@ static void drbd_flush(struct drbd_connection *connection) · 174 unmodified lines
11511177 struct drbd_peer_device *peer_device;
11521178 int vnr;
11531179
1154− if (connection->write_ordering >= WO_bdev_flush) {
1180+ if (connection->resource->write_ordering >= WO_bdev_flush) {
11551181 rcu_read_lock();
11561182 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
11571183 struct drbd_device *device = peer_device->device;
@@ -1161,14 +1187,22 @@ static void drbd_flush(struct drbd_connection *connection) · 3 unmodified lines
11611187 kref_get(&device->kref);
11621188 rcu_read_unlock();
11631189
1190+ /* Right now, we have only this one synchronous code path
1191+ * for flushes between request epochs.
1192+ * We may want to make those asynchronous,
1193+ * or at least parallelize the flushes to the volume devices.
1194+ */
1195+ device->flush_jif = jiffies;
1196+ set_bit(FLUSH_PENDING, &device->flags);
11641197 rv = blkdev_issue_flush(device->ldev->backing_bdev,
11651198 GFP_NOIO, NULL);
1199+ clear_bit(FLUSH_PENDING, &device->flags);
11661200 if (rv) {
11671201 drbd_info(device, "local disk flush failed with status %d\n", rv);
11681202 /* would rather check on EOPNOTSUPP, but that is not reliable.
11691203 * don't try again for ANY return value != 0
11701204 * if (rv == -EOPNOTSUPP) */
1171− drbd_bump_write_ordering(connection, WO_drain_io);
1205+ drbd_bump_write_ordering(connection->resource, NULL, WO_drain_io);
11721206 }
11731207 put_ldev(device);
11741208 kref_put(&device->kref, drbd_destroy_device);
@@ -1257,15 +1291,30 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio · 82 unmodified lines
12571291 return rv;
12581292 }
12591293
1294+static enum write_ordering_e
1295+max_allowed_wo(struct drbd_backing_dev *bdev, enum write_ordering_e wo)
1296+{
1297+ struct disk_conf *dc;
1298+
1299+ dc = rcu_dereference(bdev->disk_conf);
1300+
1301+ if (wo == WO_bdev_flush && !dc->disk_flushes)
1302+ wo = WO_drain_io;
1303+ if (wo == WO_drain_io && !dc->disk_drain)
1304+ wo = WO_none;
1305+
1306+ return wo;
1307+}
1308+
12601309 /**
12611310 * drbd_bump_write_ordering() - Fall back to an other write ordering method
12621311 * @connection: DRBD connection.
12631312 * @wo: Write ordering method to try.
12641313 */
1265−void drbd_bump_write_ordering(struct drbd_connection *connection, enum write_ordering_e wo)
1314+void drbd_bump_write_ordering(struct drbd_resource *resource, struct drbd_backing_dev *bdev,
1315+ enum write_ordering_e wo)
12661316 {
1267− struct disk_conf *dc;
1268− struct drbd_peer_device *peer_device;
1317+ struct drbd_device *device;
12691318 enum write_ordering_e pwo;
12701319 int vnr;
12711320 static char *write_ordering_str[] = {
@@ -1274,26 +1323,27 @@ void drbd_bump_write_ordering(struct drbd_connection *connection, enum write_ord · 2 unmodified lines
12741323 [WO_bdev_flush] = "flush",
12751324 };
12761325
1277− pwo = connection->write_ordering;
1278− wo = min(pwo, wo);
1326+ pwo = resource->write_ordering;
1327+ if (wo != WO_bdev_flush)
1328+ wo = min(pwo, wo);
12791329 rcu_read_lock();
1280− idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
1281− struct drbd_device *device = peer_device->device;
1330+ idr_for_each_entry(&resource->devices, device, vnr) {
1331+ if (get_ldev(device)) {
1332+ wo = max_allowed_wo(device->ldev, wo);
1333+ if (device->ldev == bdev)
1334+ bdev = NULL;
1335+ put_ldev(device);
1336+ }
1337+ }
12821338
1283− if (!get_ldev_if_state(device, D_ATTACHING))
1284− continue;
1285− dc = rcu_dereference(device->ldev->disk_conf);
1339+ if (bdev)
1340+ wo = max_allowed_wo(bdev, wo);
12861341
1287− if (wo == WO_bdev_flush && !dc->disk_flushes)
1288− wo = WO_drain_io;
1289− if (wo == WO_drain_io && !dc->disk_drain)
1290− wo = WO_none;
1291− put_ldev(device);
1292− }
12931342 rcu_read_unlock();
1294− connection->write_ordering = wo;
1295− if (pwo != connection->write_ordering || wo == WO_bdev_flush)
1296− drbd_info(connection, "Method to ensure write ordering: %s\n", write_ordering_str[connection->write_ordering]);
1343+
1344+ resource->write_ordering = wo;
1345+ if (pwo != resource->write_ordering || wo == WO_bdev_flush)
1346+ drbd_info(resource, "Method to ensure write ordering: %s\n", write_ordering_str[resource->write_ordering]);
12971347 }
12981348
12991349 /**
@@ -1330,6 +1380,13 @@ int drbd_submit_peer_request(struct drbd_device *device, · 30 unmodified lines
13301380 /* wait for all pending IO completions, before we start
13311381 * zeroing things out. */
13321382 conn_wait_active_ee_empty(first_peer_device(device)->connection);
1383+ /* add it to the active list now,
1384+ * so we can find it to present it in debugfs */
1385+ peer_req->submit_jif = jiffies;
1386+ peer_req->flags |= EE_SUBMITTED;
1387+ spin_lock_irq(&device->resource->req_lock);
1388+ list_add_tail(&peer_req->w.list, &device->active_ee);
1389+ spin_unlock_irq(&device->resource->req_lock);
13331390 if (blkdev_issue_zeroout(device->ldev->backing_bdev,
13341391 sector, ds >> 9, GFP_NOIO))
13351392 peer_req->flags |= EE_WAS_ERROR;
@@ -1398,6 +1455,9 @@ submit: · 62 unmodified lines
13981455 D_ASSERT(device, page == NULL);
13991456
14001457 atomic_set(&peer_req->pending_bios, n_bios);
1458+ /* for debugfs: update timestamp, mark as submitted */
1459+ peer_req->submit_jif = jiffies;
1460+ peer_req->flags |= EE_SUBMITTED;
14011461 do {
14021462 bio = bios;
14031463 bios = bios->bi_next;
@@ -1471,7 +1531,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf · 67 unmodified lines
14711531 * R_PRIMARY crashes now.
14721532 * Therefore we must send the barrier_ack after the barrier request was
14731533 * completed. */
1474− switch (connection->write_ordering) {
1534+ switch (connection->resource->write_ordering) {
14751535 case WO_none:
14761536 if (rv == FE_RECYCLED)
14771537 return 0;
@@ -1498,7 +1558,8 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf · 20 unmodified lines
14981558
14991559 return 0;
15001560 default:
1501− drbd_err(connection, "Strangeness in connection->write_ordering %d\n", connection->write_ordering);
1561+ drbd_err(connection, "Strangeness in connection->write_ordering %d\n",
1562+ connection->resource->write_ordering);
15021563 return -EIO;
15031564 }
15041565
@@ -1531,7 +1592,7 @@ read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector, · 26 unmodified lines
15311592 struct drbd_peer_request *peer_req;
15321593 struct page *page;
15331594 int dgs, ds, err;
1534− int data_size = pi->size;
1595+ unsigned int data_size = pi->size;
15351596 void *dig_in = peer_device->connection->int_dig_in;
15361597 void *dig_vv = peer_device->connection->int_dig_vv;
15371598 unsigned long *data;
@@ -1578,6 +1639,7 @@ read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector, · 40 unmodified lines
15781639 if (!peer_req)
15791640 return NULL;
15801641
1642+ peer_req->flags |= EE_WRITE;
15811643 if (trim)
15821644 return peer_req;
15831645
@@ -1734,9 +1796,10 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto · 150 unmodified lines
17341796 * respective _drbd_clear_done_ee */
17351797
17361798 peer_req->w.cb = e_end_resync_block;
1799+ peer_req->submit_jif = jiffies;
17371800
17381801 spin_lock_irq(&device->resource->req_lock);
1739− list_add(&peer_req->w.list, &device->sync_ee);
1802+ list_add_tail(&peer_req->w.list, &device->sync_ee);
17401803 spin_unlock_irq(&device->resource->req_lock);
17411804
17421805 atomic_add(pi->size >> 9, &device->rs_sect_ev);
@@ -1889,6 +1952,7 @@ static int e_end_block(struct drbd_work *w, int cancel) · 146 unmodified lines
18891952 }
18901953 dec_unacked(device);
18911954 }
1955+
18921956 /* we delete from the conflict detection hash _after_ we sent out the
18931957 * P_WRITE_ACK / P_NEG_ACK, to get the sequence number right. */
18941958 if (peer_req->flags & EE_IN_INTERVAL_TREE) {
@@ -2115,6 +2179,8 @@ static int handle_write_conflicts(struct drbd_device *device, · 220 unmodified lines
21152179 drbd_for_each_overlap(i, &device->write_requests, sector, size) {
21162180 if (i == &peer_req->i)
21172181 continue;
2182+ if (i->completed)
2183+ continue;
21182184
21192185 if (!i->local) {
21202186 /*
@@ -2147,7 +2213,6 @@ static int handle_write_conflicts(struct drbd_device *device, · 26 unmodified lines
21472213 (unsigned long long)sector, size,
21482214 superseded ? "local" : "remote");
21492215
2150− inc_unacked(device);
21512216 peer_req->w.cb = superseded ? e_send_superseded :
21522217 e_send_retry_write;
21532218 list_add_tail(&peer_req->w.list, &device->done_ee);
@@ -2206,6 +2271,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info * · 52 unmodified lines
22062271 {
22072272 struct drbd_peer_device *peer_device;
22082273 struct drbd_device *device;
2274+ struct net_conf *nc;
22092275 sector_t sector;
22102276 struct drbd_peer_request *peer_req;
22112277 struct p_data *p = pi->data;
@@ -2245,6 +2311,8 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info * · 33 unmodified lines
22452311 }
22462312
22472313 peer_req->w.cb = e_end_block;
2314+ peer_req->submit_jif = jiffies;
2315+ peer_req->flags |= EE_APPLICATION;
22482316
22492317 dp_flags = be32_to_cpu(p->dp_flags);
22502318 rw |= wire_flags_to_bio(dp_flags);
@@ -2271,9 +2339,36 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info * · 20 unmodified lines
22712339 spin_unlock(&connection->epoch_lock);
22722340
22732341 rcu_read_lock();
2274− tp = rcu_dereference(peer_device->connection->net_conf)->two_primaries;
2342+ nc = rcu_dereference(peer_device->connection->net_conf);
2343+ tp = nc->two_primaries;
2344+ if (peer_device->connection->agreed_pro_version < 100) {
2345+ switch (nc->wire_protocol) {
2346+ case DRBD_PROT_C:
2347+ dp_flags |= DP_SEND_WRITE_ACK;
2348+ break;
2349+ case DRBD_PROT_B:
2350+ dp_flags |= DP_SEND_RECEIVE_ACK;
2351+ break;
2352+ }
2353+ }
22752354 rcu_read_unlock();
2355+
2356+ if (dp_flags & DP_SEND_WRITE_ACK) {
2357+ peer_req->flags |= EE_SEND_WRITE_ACK;
2358+ inc_unacked(device);
2359+ /* corresponding dec_unacked() in e_end_block()
2360+ * respective _drbd_clear_done_ee */
2361+ }
2362+
2363+ if (dp_flags & DP_SEND_RECEIVE_ACK) {
2364+ /* I really don't like it that the receiver thread
2365+ * sends on the msock, but anyways */
2366+ drbd_send_ack(first_peer_device(device), P_RECV_ACK, peer_req);
2367+ }
2368+
22762369 if (tp) {
2370+ /* two primaries implies protocol C */
2371+ D_ASSERT(device, dp_flags & DP_SEND_WRITE_ACK);
22772372 peer_req->flags |= EE_IN_INTERVAL_TREE;
22782373 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
22792374 if (err)
@@ -2297,44 +2392,18 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info * · 17 unmodified lines
22972392 * active_ee to become empty in drbd_submit_peer_request();
22982393 * better not add ourselves here. */
22992394 if ((peer_req->flags & EE_IS_TRIM_USE_ZEROOUT) == 0)
2300− list_add(&peer_req->w.list, &device->active_ee);
2395+ list_add_tail(&peer_req->w.list, &device->active_ee);
23012396 spin_unlock_irq(&device->resource->req_lock);
23022397
23032398 if (device->state.conn == C_SYNC_TARGET)
23042399 wait_event(device->ee_wait, !overlapping_resync_write(device, peer_req));
23052400
2306− if (peer_device->connection->agreed_pro_version < 100) {
2307− rcu_read_lock();
2308− switch (rcu_dereference(peer_device->connection->net_conf)->wire_protocol) {
2309− case DRBD_PROT_C:
2310− dp_flags |= DP_SEND_WRITE_ACK;
2311− break;
2312− case DRBD_PROT_B:
2313− dp_flags |= DP_SEND_RECEIVE_ACK;
2314− break;
2315− }
2316− rcu_read_unlock();
2317− }
2318−
2319− if (dp_flags & DP_SEND_WRITE_ACK) {
2320− peer_req->flags |= EE_SEND_WRITE_ACK;
2321− inc_unacked(device);
2322− /* corresponding dec_unacked() in e_end_block()
2323− * respective _drbd_clear_done_ee */
2324− }
2325−
2326− if (dp_flags & DP_SEND_RECEIVE_ACK) {
2327− /* I really don't like it that the receiver thread
2328− * sends on the msock, but anyways */
2329− drbd_send_ack(first_peer_device(device), P_RECV_ACK, peer_req);
2330− }
2331−
23322401 if (device->state.pdsk < D_INCONSISTENT) {
23332402 /* In case we have the only disk of the cluster, */
23342403 drbd_set_out_of_sync(device, peer_req->i.sector, peer_req->i.size);
2335− peer_req->flags |= EE_CALL_AL_COMPLETE_IO;
23362404 peer_req->flags &= ~EE_MAY_SET_IN_SYNC;
2337− drbd_al_begin_io(device, &peer_req->i, true);
2405+ drbd_al_begin_io(device, &peer_req->i);
2406+ peer_req->flags |= EE_CALL_AL_COMPLETE_IO;
23382407 }
23392408
23402409 err = drbd_submit_peer_request(device, peer_req, rw, DRBD_FAULT_DT_WR);
@@ -2347,8 +2416,10 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info * · 6 unmodified lines
23472416 list_del(&peer_req->w.list);
23482417 drbd_remove_epoch_entry_interval(device, peer_req);
23492418 spin_unlock_irq(&device->resource->req_lock);
2350− if (peer_req->flags & EE_CALL_AL_COMPLETE_IO)
2419+ if (peer_req->flags & EE_CALL_AL_COMPLETE_IO) {
2420+ peer_req->flags &= ~EE_CALL_AL_COMPLETE_IO;
23512421 drbd_al_complete_io(device, &peer_req->i);
2422+ }
23522423
23532424 out_interrupted:
23542425 drbd_may_finish_epoch(connection, peer_req->epoch, EV_PUT + EV_CLEANUP);
@@ -2368,13 +2439,14 @@ out_interrupted: · 13 unmodified lines
23682439 * The current sync rate used here uses only the most recent two step marks,
23692440 * to have a short time average so we can react faster.
23702441 */
2371−bool drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector)
2442+bool drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector,
2443+ bool throttle_if_app_is_waiting)
23722444 {
23732445 struct lc_element *tmp;
2374− bool throttle = true;
2446+ bool throttle = drbd_rs_c_min_rate_throttle(device);
23752447
2376− if (!drbd_rs_c_min_rate_throttle(device))
2377− return false;
2448+ if (!throttle || throttle_if_app_is_waiting)
2449+ return throttle;
23782450
23792451 spin_lock_irq(&device->al_lock);
23802452 tmp = lc_find(device->resync, BM_SECT_TO_EXT(sector));
@@ -2382,7 +2454,8 @@ bool drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector) · 1 unmodified line
23822454 struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce);
23832455 if (test_bit(BME_PRIORITY, &bm_ext->flags))
23842456 throttle = false;
2385− /* Do not slow down if app IO is already waiting for this extent */
2457+ /* Do not slow down if app IO is already waiting for this extent,
2458+ * and our progress is necessary for application IO to complete. */
23862459 }
23872460 spin_unlock_irq(&device->al_lock);
23882461
@@ -2407,7 +2480,9 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device) · 18 unmodified lines
24072480 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
24082481 (int)part_stat_read(&disk->part0, sectors[1]) -
24092482 atomic_read(&device->rs_sect_ev);
2410− if (!device->rs_last_events || curr_events - device->rs_last_events > 64) {
2483+
2484+ if (atomic_read(&device->ap_actlog_cnt)
2485+ || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
24112486 unsigned long rs_left;
24122487 int i;
24132488
@@ -2508,6 +2583,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet · 94 unmodified lines
25082583 peer_req->w.cb = w_e_end_data_req;
25092584 fault_type = DRBD_FAULT_DT_RD;
25102585 /* application IO, don't drbd_rs_begin_io */
2586+ peer_req->flags |= EE_APPLICATION;
25112587 goto submit;
25122588
25132589 case P_RS_DATA_REQUEST:
@@ -2538,6 +2614,8 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet · 24 unmodified lines
25382614 peer_req->w.cb = w_e_end_csum_rs_req;
25392615 /* used in the sector offset progress display */
25402616 device->bm_resync_fo = BM_SECT_TO_BIT(sector);
2617+ /* remember to report stats in drbd_resync_finished */
2618+ device->use_csums = true;
25412619 } else if (pi->cmd == P_OV_REPLY) {
25422620 /* track progress, we may need to throttle */
25432621 atomic_add(size >> 9, &device->rs_sect_in);
@@ -2595,8 +2673,20 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet · 51 unmodified lines
25952673 * we would also throttle its application reads.
25962674 * In that case, throttling is done on the SyncTarget only.
25972675 */
2598− if (device->state.peer != R_PRIMARY && drbd_rs_should_slow_down(device, sector))
2676+
2677+ /* Even though this may be a resync request, we do add to "read_ee";
2678+ * "sync_ee" is only used for resync WRITEs.
2679+ * Add to list early, so debugfs can find this request
2680+ * even if we have to sleep below. */
2681+ spin_lock_irq(&device->resource->req_lock);
2682+ list_add_tail(&peer_req->w.list, &device->read_ee);
2683+ spin_unlock_irq(&device->resource->req_lock);
2684+
2685+ update_receiver_timing_details(connection, drbd_rs_should_slow_down);
2686+ if (device->state.peer != R_PRIMARY
2687+ && drbd_rs_should_slow_down(device, sector, false))
25992688 schedule_timeout_uninterruptible(HZ/10);
2689+ update_receiver_timing_details(connection, drbd_rs_begin_io);
26002690 if (drbd_rs_begin_io(device, sector))
26012691 goto out_free_e;
26022692
@@ -2604,22 +2694,20 @@ submit_for_resync: · 1 unmodified line
26042694 atomic_add(size >> 9, &device->rs_sect_ev);
26052695
26062696 submit:
2697+ update_receiver_timing_details(connection, drbd_submit_peer_request);
26072698 inc_unacked(device);
2608− spin_lock_irq(&device->resource->req_lock);
2609− list_add_tail(&peer_req->w.list, &device->read_ee);
2610− spin_unlock_irq(&device->resource->req_lock);
2611−
26122699 if (drbd_submit_peer_request(device, peer_req, READ, fault_type) == 0)
26132700 return 0;
26142701
26152702 /* don't care for the reason here */
26162703 drbd_err(device, "submit failed, triggering re-connect\n");
2704+
2705+out_free_e:
26172706 spin_lock_irq(&device->resource->req_lock);
26182707 list_del(&peer_req->w.list);
26192708 spin_unlock_irq(&device->resource->req_lock);
26202709 /* no drbd_rs_complete_io(), we are dropping the connection anyways */
26212710
2622−out_free_e:
26232711 put_ldev(device);
26242712 drbd_free_peer_req(device, peer_req);
26252713 return -EIO;
@@ -2842,8 +2930,10 @@ static void drbd_uuid_dump(struct drbd_device *device, char *text, u64 *uuid, · 216 unmodified lines
28422930 -1091 requires proto 91
28432931 -1096 requires proto 96
28442932 */
2845−static int drbd_uuid_compare(struct drbd_device *device, int *rule_nr) __must_hold(local)
2933+static int drbd_uuid_compare(struct drbd_device *const device, int *rule_nr) __must_hold(local)
28462934 {
2935+ struct drbd_peer_device *const peer_device = first_peer_device(device);
2936+ struct drbd_connection *const connection = peer_device ? peer_device->connection : NULL;
28472937 u64 self, peer;
28482938 int i, j;
28492939
@@ -2869,7 +2959,7 @@ static int drbd_uuid_compare(struct drbd_device *device, int *rule_nr) __must_ho · 19 unmodified lines
28692959
28702960 if (device->p_uuid[UI_BITMAP] == (u64)0 && device->ldev->md.uuid[UI_BITMAP] != (u64)0) {
28712961
2872− if (first_peer_device(device)->connection->agreed_pro_version < 91)
2962+ if (connection->agreed_pro_version < 91)
28732963 return -1091;
28742964
28752965 if ((device->ldev->md.uuid[UI_BITMAP] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START] & ~((u64)1)) &&
@@ -2892,7 +2982,7 @@ static int drbd_uuid_compare(struct drbd_device *device, int *rule_nr) __must_ho · 16 unmodified lines
28922982
28932983 if (device->ldev->md.uuid[UI_BITMAP] == (u64)0 && device->p_uuid[UI_BITMAP] != (u64)0) {
28942984
2895− if (first_peer_device(device)->connection->agreed_pro_version < 91)
2985+ if (connection->agreed_pro_version < 91)
28962986 return -1091;
28972987
28982988 if ((device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (device->p_uuid[UI_BITMAP] & ~((u64)1)) &&
@@ -2925,7 +3015,7 @@ static int drbd_uuid_compare(struct drbd_device *device, int *rule_nr) __must_ho · 26 unmodified lines
29253015 case 1: /* self_pri && !peer_pri */ return 1;
29263016 case 2: /* !self_pri && peer_pri */ return -1;
29273017 case 3: /* self_pri && peer_pri */
2928− dc = test_bit(RESOLVE_CONFLICTS, &first_peer_device(device)->connection->flags);
3018+ dc = test_bit(RESOLVE_CONFLICTS, &connection->flags);
29293019 return dc ? -1 : 1;
29303020 }
29313021 }
@@ -2938,14 +3028,14 @@ static int drbd_uuid_compare(struct drbd_device *device, int *rule_nr) __must_ho · 6 unmodified lines
29383028 *rule_nr = 51;
29393029 peer = device->p_uuid[UI_HISTORY_START] & ~((u64)1);
29403030 if (self == peer) {
2941− if (first_peer_device(device)->connection->agreed_pro_version < 96 ?
3031+ if (connection->agreed_pro_version < 96 ?
29423032 (device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) ==
29433033 (device->p_uuid[UI_HISTORY_START + 1] & ~((u64)1)) :
29443034 peer + UUID_NEW_BM_OFFSET == (device->p_uuid[UI_BITMAP] & ~((u64)1))) {
29453035 /* The last P_SYNC_UUID did not get though. Undo the last start of
29463036 resync as sync source modifications of the peer's UUIDs. */
29473037
2948− if (first_peer_device(device)->connection->agreed_pro_version < 91)
3038+ if (connection->agreed_pro_version < 91)
29493039 return -1091;
29503040
29513041 device->p_uuid[UI_BITMAP] = device->p_uuid[UI_HISTORY_START];
@@ -2975,14 +3065,14 @@ static int drbd_uuid_compare(struct drbd_device *device, int *rule_nr) __must_ho · 23 unmodified lines
29753065 *rule_nr = 71;
29763066 self = device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1);
29773067 if (self == peer) {
2978− if (first_peer_device(device)->connection->agreed_pro_version < 96 ?
3068+ if (connection->agreed_pro_version < 96 ?
29793069 (device->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) ==
29803070 (device->p_uuid[UI_HISTORY_START] & ~((u64)1)) :
29813071 self + UUID_NEW_BM_OFFSET == (device->ldev->md.uuid[UI_BITMAP] & ~((u64)1))) {
29823072 /* The last P_SYNC_UUID did not get though. Undo the last start of
29833073 resync as sync source modifications of our UUIDs. */
29843074
2985− if (first_peer_device(device)->connection->agreed_pro_version < 91)
3075+ if (connection->agreed_pro_version < 91)
29863076 return -1091;
29873077
29883078 __drbd_uuid_set(device, UI_BITMAP, device->ldev->md.uuid[UI_HISTORY_START]);
@@ -3352,8 +3442,7 @@ disconnect: · 363 unmodified lines
33523442 * return: NULL (alg name was "")
33533443 * ERR_PTR(error) if something goes wrong
33543444 * or the crypto hash ptr, if it worked out ok. */
3355−static
3356−struct crypto_hash *drbd_crypto_alloc_digest_safe(const struct drbd_device *device,
3445+static struct crypto_hash *drbd_crypto_alloc_digest_safe(const struct drbd_device *device,
33573446 const char *alg, const char *name)
33583447 {
33593448 struct crypto_hash *tfm;
@@ -3639,7 +3728,7 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info · 279 unmodified lines
36393728 struct drbd_device *device;
36403729 struct p_sizes *p = pi->data;
36413730 enum determine_dev_size dd = DS_UNCHANGED;
3642− sector_t p_size, p_usize, my_usize;
3731+ sector_t p_size, p_usize, p_csize, my_usize;
36433732 int ldsc = 0; /* local disk size changed */
36443733 enum dds_flags ddsf;
36453734
@@ -3650,6 +3739,7 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info · 4 unmodified lines
36503739
36513740 p_size = be64_to_cpu(p->d_size);
36523741 p_usize = be64_to_cpu(p->u_size);
3742+ p_csize = be64_to_cpu(p->c_size);
36533743
36543744 /* just store the peer's disk size for now.
36553745 * we still need to figure out whether we accept that. */
@@ -3710,7 +3800,6 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info · 54 unmodified lines
37103800 }
37113801
37123802 device->peer_max_bio_size = be32_to_cpu(p->max_bio_size);
3713− drbd_reconsider_max_bio_size(device);
37143803 /* Leave drbd_reconsider_max_bio_size() before drbd_determine_dev_size().
37153804 In case we cleared the QUEUE_FLAG_DISCARD from our queue in
37163805 drbd_reconsider_max_bio_size(), we can be sure that after
@@ -3718,14 +3807,28 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info · 1 unmodified line
37183807
37193808 ddsf = be16_to_cpu(p->dds_flags);
37203809 if (get_ldev(device)) {
3810+ drbd_reconsider_max_bio_size(device, device->ldev);
37213811 dd = drbd_determine_dev_size(device, ddsf, NULL);
37223812 put_ldev(device);
37233813 if (dd == DS_ERROR)
37243814 return -EIO;
37253815 drbd_md_sync(device);
37263816 } else {
3727− /* I am diskless, need to accept the peer's size. */
3728− drbd_set_my_capacity(device, p_size);
3817+ /*
3818+ * I am diskless, need to accept the peer's *current* size.
3819+ * I must NOT accept the peers backing disk size,
3820+ * it may have been larger than mine all along...
3821+ *
3822+ * At this point, the peer knows more about my disk, or at
3823+ * least about what we last agreed upon, than myself.
3824+ * So if his c_size is less than his d_size, the most likely
3825+ * reason is that *my* d_size was smaller last time we checked.
3826+ *
3827+ * However, if he sends a zero current size,
3828+ * take his (user-capped or) backing disk size anyways.
3829+ */
3830+ drbd_reconsider_max_bio_size(device, NULL);
3831+ drbd_set_my_capacity(device, p_csize ?: p_usize ?: p_size);
37293832 }
37303833
37313834 if (get_ldev(device)) {
@@ -4501,6 +4604,7 @@ static void drbdd(struct drbd_connection *connection) · 769 unmodified lines
45014604 struct data_cmd *cmd;
45024605
45034606 drbd_thread_current_set_cpu(&connection->receiver);
4607+ update_receiver_timing_details(connection, drbd_recv_header);
45044608 if (drbd_recv_header(connection, &pi))
45054609 goto err_out;
45064610
@@ -4519,12 +4623,14 @@ static void drbdd(struct drbd_connection *connection) · 12 unmodified lines
45194623 }
45204624
45214625 if (shs) {
4626+ update_receiver_timing_details(connection, drbd_recv_all_warn);
45224627 err = drbd_recv_all_warn(connection, pi.data, shs);
45234628 if (err)
45244629 goto err_out;
45254630 pi.size -= shs;
45264631 }
45274632
4633+ update_receiver_timing_details(connection, cmd->fn);
45284634 err = cmd->fn(connection, &pi);
45294635 if (err) {
45304636 drbd_err(connection, "error receiving %s, e: %d l: %d!\n",
drivers/block/drbd/drbd_req.c+362−165
@@ -52,7 +52,7 @@ static void _drbd_start_io_acct(struct drbd_device *device, struct drbd_request · 51 unmodified lines
5252 static void _drbd_end_io_acct(struct drbd_device *device, struct drbd_request *req)
5353 {
5454 int rw = bio_data_dir(req->master_bio);
55− unsigned long duration = jiffies - req->start_time;
55+ unsigned long duration = jiffies - req->start_jif;
5656 int cpu;
5757 cpu = part_stat_lock();
5858 part_stat_add(cpu, &device->vdisk->part0, ticks[rw], duration);
@@ -66,7 +66,7 @@ static struct drbd_request *drbd_req_new(struct drbd_device *device, · 7 unmodified lines
6666 {
6767 struct drbd_request *req;
6868
69− req = mempool_alloc(drbd_request_mempool, GFP_NOIO);
69+ req = mempool_alloc(drbd_request_mempool, GFP_NOIO | __GFP_ZERO);
7070 if (!req)
7171 return NULL;
7272
@@ -84,6 +84,8 @@ static struct drbd_request *drbd_req_new(struct drbd_device *device, · 11 unmodified lines
8484
8585 INIT_LIST_HEAD(&req->tl_requests);
8686 INIT_LIST_HEAD(&req->w.list);
87+ INIT_LIST_HEAD(&req->req_pending_master_completion);
88+ INIT_LIST_HEAD(&req->req_pending_local);
8789
8890 /* one reference to be put by __drbd_make_request */
8991 atomic_set(&req->completion_ref, 1);
@@ -92,6 +94,19 @@ static struct drbd_request *drbd_req_new(struct drbd_device *device, · 2 unmodified lines
9294 return req;
9395 }
9496
97+static void drbd_remove_request_interval(struct rb_root *root,
98+ struct drbd_request *req)
99+{
100+ struct drbd_device *device = req->device;
101+ struct drbd_interval *i = &req->i;
102+
103+ drbd_remove_interval(root, i);
104+
105+ /* Wake up any processes waiting for this request to complete. */
106+ if (i->waiting)
107+ wake_up(&device->misc_wait);
108+}
109+
95110 void drbd_req_destroy(struct kref *kref)
96111 {
97112 struct drbd_request *req = container_of(kref, struct drbd_request, kref);
@@ -107,14 +122,30 @@ void drbd_req_destroy(struct kref *kref) · 9 unmodified lines
107122 return;
108123 }
109124
110− /* remove it from the transfer log.
111− * well, only if it had been there in the first
112− * place... if it had not (local only or conflicting
113− * and never sent), it should still be "empty" as
114− * initialized in drbd_req_new(), so we can list_del() it
115− * here unconditionally */
125+ /* If called from mod_rq_state (expected normal case) or
126+ * drbd_send_and_submit (the less likely normal path), this holds the
127+ * req_lock, and req->tl_requests will typicaly be on ->transfer_log,
128+ * though it may be still empty (never added to the transfer log).
129+ *
130+ * If called from do_retry(), we do NOT hold the req_lock, but we are
131+ * still allowed to unconditionally list_del(&req->tl_requests),
132+ * because it will be on a local on-stack list only. */
116133 list_del_init(&req->tl_requests);
117134
135+ /* finally remove the request from the conflict detection
136+ * respective block_id verification interval tree. */
137+ if (!drbd_interval_empty(&req->i)) {
138+ struct rb_root *root;
139+
140+ if (s & RQ_WRITE)
141+ root = &device->write_requests;
142+ else
143+ root = &device->read_requests;
144+ drbd_remove_request_interval(root, req);
145+ } else if (s & (RQ_NET_MASK & ~RQ_NET_DONE) && req->i.size != 0)
146+ drbd_err(device, "drbd_req_destroy: Logic BUG: interval empty, but: rq_state=0x%x, sect=%llu, size=%u\n",
147+ s, (unsigned long long)req->i.sector, req->i.size);
148+
118149 /* if it was a write, we may have to set the corresponding
119150 * bit(s) out-of-sync first. If it had a local part, we need to
120151 * release the reference to the activity log. */
@@ -188,19 +219,6 @@ void complete_master_bio(struct drbd_device *device, · 67 unmodified lines
188219 }
189220
190221
191−static void drbd_remove_request_interval(struct rb_root *root,
192− struct drbd_request *req)
193−{
194− struct drbd_device *device = req->device;
195− struct drbd_interval *i = &req->i;
196−
197− drbd_remove_interval(root, i);
198−
199− /* Wake up any processes waiting for this request to complete. */
200− if (i->waiting)
201− wake_up(&device->misc_wait);
202−}
203−
204222 /* Helper for __req_mod().
205223 * Set m->bio to the master bio, if it is fit to be completed,
206224 * or leave it alone (it is initialized to NULL in __req_mod),
@@ -254,18 +272,6 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m) · 47 unmodified lines
254272 ok = (s & RQ_LOCAL_OK) || (s & RQ_NET_OK);
255273 error = PTR_ERR(req->private_bio);
256274
257− /* remove the request from the conflict detection
258− * respective block_id verification hash */
259− if (!drbd_interval_empty(&req->i)) {
260− struct rb_root *root;
261−
262− if (rw == WRITE)
263− root = &device->write_requests;
264− else
265− root = &device->read_requests;
266− drbd_remove_request_interval(root, req);
267− }
268−
269275 /* Before we can signal completion to the upper layers,
270276 * we may need to close the current transfer log epoch.
271277 * We are within the request lock, so we can simply compare
@@ -301,9 +307,24 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m) · 29 unmodified lines
301307 m->error = ok ? 0 : (error ?: -EIO);
302308 m->bio = req->master_bio;
303309 req->master_bio = NULL;
310+ /* We leave it in the tree, to be able to verify later
311+ * write-acks in protocol != C during resync.
312+ * But we mark it as "complete", so it won't be counted as
313+ * conflict in a multi-primary setup. */
314+ req->i.completed = true;
304315 }
316+
317+ if (req->i.waiting)
318+ wake_up(&device->misc_wait);
319+
320+ /* Either we are about to complete to upper layers,
321+ * or we will restart this request.
322+ * In either case, the request object will be destroyed soon,
323+ * so better remove it from all lists. */
324+ list_del_init(&req->req_pending_master_completion);
305325 }
306326
327+/* still holds resource->req_lock */
307328 static int drbd_req_put_completion_ref(struct drbd_request *req, struct bio_and_error *m, int put)
308329 {
309330 struct drbd_device *device = req->device;
@@ -324,12 +345,91 @@ static int drbd_req_put_completion_ref(struct drbd_request *req, struct bio_and_ · 14 unmodified lines
324345 return 1;
325346 }
326347
348+static void set_if_null_req_next(struct drbd_peer_device *peer_device, struct drbd_request *req)
349+{
350+ struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
351+ if (!connection)
352+ return;
353+ if (connection->req_next == NULL)
354+ connection->req_next = req;
355+}
356+
357+static void advance_conn_req_next(struct drbd_peer_device *peer_device, struct drbd_request *req)
358+{
359+ struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
360+ if (!connection)
361+ return;
362+ if (connection->req_next != req)
363+ return;
364+ list_for_each_entry_continue(req, &connection->transfer_log, tl_requests) {
365+ const unsigned s = req->rq_state;
366+ if (s & RQ_NET_QUEUED)
367+ break;
368+ }
369+ if (&req->tl_requests == &connection->transfer_log)
370+ req = NULL;
371+ connection->req_next = req;
372+}
373+
374+static void set_if_null_req_ack_pending(struct drbd_peer_device *peer_device, struct drbd_request *req)
375+{
376+ struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
377+ if (!connection)
378+ return;
379+ if (connection->req_ack_pending == NULL)
380+ connection->req_ack_pending = req;
381+}
382+
383+static void advance_conn_req_ack_pending(struct drbd_peer_device *peer_device, struct drbd_request *req)
384+{
385+ struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
386+ if (!connection)
387+ return;
388+ if (connection->req_ack_pending != req)
389+ return;
390+ list_for_each_entry_continue(req, &connection->transfer_log, tl_requests) {
391+ const unsigned s = req->rq_state;
392+ if ((s & RQ_NET_SENT) && (s & RQ_NET_PENDING))
393+ break;
394+ }
395+ if (&req->tl_requests == &connection->transfer_log)
396+ req = NULL;
397+ connection->req_ack_pending = req;
398+}
399+
400+static void set_if_null_req_not_net_done(struct drbd_peer_device *peer_device, struct drbd_request *req)
401+{
402+ struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
403+ if (!connection)
404+ return;
405+ if (connection->req_not_net_done == NULL)
406+ connection->req_not_net_done = req;
407+}
408+
409+static void advance_conn_req_not_net_done(struct drbd_peer_device *peer_device, struct drbd_request *req)
410+{
411+ struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
412+ if (!connection)
413+ return;
414+ if (connection->req_not_net_done != req)
415+ return;
416+ list_for_each_entry_continue(req, &connection->transfer_log, tl_requests) {
417+ const unsigned s = req->rq_state;
418+ if ((s & RQ_NET_SENT) && !(s & RQ_NET_DONE))
419+ break;
420+ }
421+ if (&req->tl_requests == &connection->transfer_log)
422+ req = NULL;
423+ connection->req_not_net_done = req;
424+}
425+
327426 /* I'd like this to be the only place that manipulates
328427 * req->completion_ref and req->kref. */
329428 static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
330429 int clear, int set)
331430 {
332431 struct drbd_device *device = req->device;
432+ struct drbd_peer_device *peer_device = first_peer_device(device);
333433 unsigned s = req->rq_state;
334434 int c_put = 0;
335435 int k_put = 0;
@@ -356,14 +456,23 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, · 20 unmodified lines
356456 atomic_inc(&req->completion_ref);
357457 }
358458
359− if (!(s & RQ_NET_QUEUED) && (set & RQ_NET_QUEUED))
459+ if (!(s & RQ_NET_QUEUED) && (set & RQ_NET_QUEUED)) {
360460 atomic_inc(&req->completion_ref);
461+ set_if_null_req_next(peer_device, req);
462+ }
361463
362464 if (!(s & RQ_EXP_BARR_ACK) && (set & RQ_EXP_BARR_ACK))
363465 kref_get(&req->kref); /* wait for the DONE */
364466
365− if (!(s & RQ_NET_SENT) && (set & RQ_NET_SENT))
366− atomic_add(req->i.size >> 9, &device->ap_in_flight);
467+ if (!(s & RQ_NET_SENT) && (set & RQ_NET_SENT)) {
468+ /* potentially already completed in the asender thread */
469+ if (!(s & RQ_NET_DONE)) {
470+ atomic_add(req->i.size >> 9, &device->ap_in_flight);
471+ set_if_null_req_not_net_done(peer_device, req);
472+ }
473+ if (s & RQ_NET_PENDING)
474+ set_if_null_req_ack_pending(peer_device, req);
475+ }
367476
368477 if (!(s & RQ_COMPLETION_SUSP) && (set & RQ_COMPLETION_SUSP))
369478 atomic_inc(&req->completion_ref);
@@ -386,20 +495,34 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, · 16 unmodified lines
386495 ++k_put;
387496 else
388497 ++c_put;
498+ list_del_init(&req->req_pending_local);
389499 }
390500
391501 if ((s & RQ_NET_PENDING) && (clear & RQ_NET_PENDING)) {
392502 dec_ap_pending(device);
393503 ++c_put;
504+ req->acked_jif = jiffies;
505+ advance_conn_req_ack_pending(peer_device, req);
394506 }
395507
396− if ((s & RQ_NET_QUEUED) && (clear & RQ_NET_QUEUED))
508+ if ((s & RQ_NET_QUEUED) && (clear & RQ_NET_QUEUED)) {
397509 ++c_put;
510+ advance_conn_req_next(peer_device, req);
511+ }
398512
399− if ((s & RQ_EXP_BARR_ACK) && !(s & RQ_NET_DONE) && (set & RQ_NET_DONE)) {
400− if (req->rq_state & RQ_NET_SENT)
513+ if (!(s & RQ_NET_DONE) && (set & RQ_NET_DONE)) {
514+ if (s & RQ_NET_SENT)
401515 atomic_sub(req->i.size >> 9, &device->ap_in_flight);
402− ++k_put;
516+ if (s & RQ_EXP_BARR_ACK)
517+ ++k_put;
518+ req->net_done_jif = jiffies;
519+
520+ /* in ahead/behind mode, or just in case,
521+ * before we finally destroy this request,
522+ * the caching pointers must not reference it anymore */
523+ advance_conn_req_next(peer_device, req);
524+ advance_conn_req_ack_pending(peer_device, req);
525+ advance_conn_req_not_net_done(peer_device, req);
403526 }
404527
405528 /* potentially complete and destroy */
@@ -439,6 +562,19 @@ static void drbd_report_io_error(struct drbd_device *device, struct drbd_request · 33 unmodified lines
439562 bdevname(device->ldev->backing_bdev, b));
440563 }
441564
565+/* Helper for HANDED_OVER_TO_NETWORK.
566+ * Is this a protocol A write (neither WRITE_ACK nor RECEIVE_ACK expected)?
567+ * Is it also still "PENDING"?
568+ * --> If so, clear PENDING and set NET_OK below.
569+ * If it is a protocol A write, but not RQ_PENDING anymore, neg-ack was faster
570+ * (and we must not set RQ_NET_OK) */
571+static inline bool is_pending_write_protocol_A(struct drbd_request *req)
572+{
573+ return (req->rq_state &
574+ (RQ_WRITE|RQ_NET_PENDING|RQ_EXP_WRITE_ACK|RQ_EXP_RECEIVE_ACK))
575+ == (RQ_WRITE|RQ_NET_PENDING);
576+}
577+
442578 /* obviously this could be coded as many single functions
443579 * instead of one huge switch,
444580 * or by putting the code directly in the respective locations
@@ -454,7 +590,9 @@ static void drbd_report_io_error(struct drbd_device *device, struct drbd_request · 9 unmodified lines
454590 int __req_mod(struct drbd_request *req, enum drbd_req_event what,
455591 struct bio_and_error *m)
456592 {
457− struct drbd_device *device = req->device;
593+ struct drbd_device *const device = req->device;
594+ struct drbd_peer_device *const peer_device = first_peer_device(device);
595+ struct drbd_connection *const connection = peer_device ? peer_device->connection : NULL;
458596 struct net_conf *nc;
459597 int p, rv = 0;
460598
@@ -477,7 +615,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, · 16 unmodified lines
477615 * and from w_read_retry_remote */
478616 D_ASSERT(device, !(req->rq_state & RQ_NET_MASK));
479617 rcu_read_lock();
480− nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
618+ nc = rcu_dereference(connection->net_conf);
481619 p = nc->wire_protocol;
482620 rcu_read_unlock();
483621 req->rq_state |=
@@ -549,7 +687,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, · 65 unmodified lines
549687 D_ASSERT(device, (req->rq_state & RQ_LOCAL_MASK) == 0);
550688 mod_rq_state(req, m, 0, RQ_NET_QUEUED);
551689 req->w.cb = w_send_read_req;
552− drbd_queue_work(&first_peer_device(device)->connection->sender_work,
690+ drbd_queue_work(&connection->sender_work,
553691 &req->w);
554692 break;
555693
@@ -585,23 +723,23 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, · 29 unmodified lines
585723 D_ASSERT(device, req->rq_state & RQ_NET_PENDING);
586724 mod_rq_state(req, m, 0, RQ_NET_QUEUED|RQ_EXP_BARR_ACK);
587725 req->w.cb = w_send_dblock;
588− drbd_queue_work(&first_peer_device(device)->connection->sender_work,
726+ drbd_queue_work(&connection->sender_work,
589727 &req->w);
590728
591729 /* close the epoch, in case it outgrew the limit */
592730 rcu_read_lock();
593− nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
731+ nc = rcu_dereference(connection->net_conf);
594732 p = nc->max_epoch_size;
595733 rcu_read_unlock();
596− if (first_peer_device(device)->connection->current_tle_writes >= p)
597− start_new_tl_epoch(first_peer_device(device)->connection);
734+ if (connection->current_tle_writes >= p)
735+ start_new_tl_epoch(connection);
598736
599737 break;
600738
601739 case QUEUE_FOR_SEND_OOS:
602740 mod_rq_state(req, m, 0, RQ_NET_QUEUED);
603741 req->w.cb = w_send_out_of_sync;
604− drbd_queue_work(&first_peer_device(device)->connection->sender_work,
742+ drbd_queue_work(&connection->sender_work,
605743 &req->w);
606744 break;
607745
@@ -615,18 +753,16 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, · 7 unmodified lines
615753
616754 case HANDED_OVER_TO_NETWORK:
617755 /* assert something? */
618− if (bio_data_dir(req->master_bio) == WRITE &&
619− !(req->rq_state & (RQ_EXP_RECEIVE_ACK | RQ_EXP_WRITE_ACK))) {
756+ if (is_pending_write_protocol_A(req))
620757 /* this is what is dangerous about protocol A:
621758 * pretend it was successfully written on the peer. */
622− if (req->rq_state & RQ_NET_PENDING)
623− mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_OK);
624− /* else: neg-ack was faster... */
625− /* it is still not yet RQ_NET_DONE until the
626− * corresponding epoch barrier got acked as well,
627− * so we know what to dirty on connection loss */
628− }
629− mod_rq_state(req, m, RQ_NET_QUEUED, RQ_NET_SENT);
759+ mod_rq_state(req, m, RQ_NET_QUEUED|RQ_NET_PENDING,
760+ RQ_NET_SENT|RQ_NET_OK);
761+ else
762+ mod_rq_state(req, m, RQ_NET_QUEUED, RQ_NET_SENT);
763+ /* It is still not yet RQ_NET_DONE until the
764+ * corresponding epoch barrier got acked as well,
765+ * so we know what to dirty on connection loss. */
630766 break;
631767
632768 case OOS_HANDED_TO_NETWORK:
@@ -658,12 +794,13 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, · 25 unmodified lines
658794 case WRITE_ACKED_BY_PEER_AND_SIS:
659795 req->rq_state |= RQ_NET_SIS;
660796 case WRITE_ACKED_BY_PEER:
661− D_ASSERT(device, req->rq_state & RQ_EXP_WRITE_ACK);
662− /* protocol C; successfully written on peer.
797+ /* Normal operation protocol C: successfully written on peer.
798+ * During resync, even in protocol != C,
799+ * we requested an explicit write ack anyways.
800+ * Which means we cannot even assert anything here.
663801 * Nothing more to do here.
664802 * We want to keep the tl in place for all protocols, to cater
665803 * for volatile write-back caches on lower level devices. */
666−
667804 goto ack_common;
668805 case RECV_ACKED_BY_PEER:
669806 D_ASSERT(device, req->rq_state & RQ_EXP_RECEIVE_ACK);
@@ -671,7 +808,6 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, · 1 unmodified line
671808 * see also notes above in HANDED_OVER_TO_NETWORK about
672809 * protocol != C */
673810 ack_common:
674− D_ASSERT(device, req->rq_state & RQ_NET_PENDING);
675811 mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_OK);
676812 break;
677813
@@ -714,7 +850,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, · 36 unmodified lines
714850
715851 get_ldev(device); /* always succeeds in this call path */
716852 req->w.cb = w_restart_disk_io;
717− drbd_queue_work(&first_peer_device(device)->connection->sender_work,
853+ drbd_queue_work(&connection->sender_work,
718854 &req->w);
719855 break;
720856
@@ -736,7 +872,8 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, · 15 unmodified lines
736872
737873 mod_rq_state(req, m, RQ_COMPLETION_SUSP, RQ_NET_QUEUED|RQ_NET_PENDING);
738874 if (req->w.cb) {
739− drbd_queue_work(&first_peer_device(device)->connection->sender_work,
875+ /* w.cb expected to be w_send_dblock, or w_send_read_req */
876+ drbd_queue_work(&connection->sender_work,
740877 &req->w);
741878 rv = req->rq_state & RQ_WRITE ? MR_WRITE : MR_READ;
742879 } /* else: FIXME can this happen? */
@@ -769,7 +906,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, · 26 unmodified lines
769906 break;
770907
771908 case QUEUE_AS_DRBD_BARRIER:
772− start_new_tl_epoch(first_peer_device(device)->connection);
909+ start_new_tl_epoch(connection);
773910 mod_rq_state(req, m, 0, RQ_NET_OK|RQ_NET_DONE);
774911 break;
775912 };
@@ -886,6 +1023,9 @@ static void maybe_pull_ahead(struct drbd_device *device) · 110 unmodified lines
8861023 connection->agreed_pro_version < 96)
8871024 return;
8881025
1026+ if (on_congestion == OC_PULL_AHEAD && device->state.conn == C_AHEAD)
1027+ return; /* nothing to do ... */
1028+
8891029 /* If I don't even have good local storage, we can not reasonably try
8901030 * to pull ahead of the peer. We also need the local reference to make
8911031 * sure device->act_log is there.
@@ -1021,6 +1161,7 @@ drbd_submit_req_private_bio(struct drbd_request *req) · 129 unmodified lines
10211161 * stable storage, and this is a WRITE, we may not even submit
10221162 * this bio. */
10231163 if (get_ldev(device)) {
1164+ req->pre_submit_jif = jiffies;
10241165 if (drbd_insert_fault(device,
10251166 rw == WRITE ? DRBD_FAULT_DT_WR
10261167 : rw == READ ? DRBD_FAULT_DT_RD
@@ -1035,10 +1176,14 @@ drbd_submit_req_private_bio(struct drbd_request *req) · 8 unmodified lines
10351176
10361177 static void drbd_queue_write(struct drbd_device *device, struct drbd_request *req)
10371178 {
1038− spin_lock(&device->submit.lock);
1179+ spin_lock_irq(&device->resource->req_lock);
10391180 list_add_tail(&req->tl_requests, &device->submit.writes);
1040− spin_unlock(&device->submit.lock);
1181+ list_add_tail(&req->req_pending_master_completion,
1182+ &device->pending_master_completion[1 /* WRITE */]);
1183+ spin_unlock_irq(&device->resource->req_lock);
10411184 queue_work(device->submit.wq, &device->submit.worker);
1185+ /* do_submit() may sleep internally on al_wait, too */
1186+ wake_up(&device->al_wait);
10421187 }
10431188
10441189 /* returns the new drbd_request pointer, if the caller is expected to
@@ -1047,7 +1192,7 @@ static void drbd_queue_write(struct drbd_device *device, struct drbd_request *re · 2 unmodified lines
10471192 * Returns ERR_PTR(-ENOMEM) if we cannot allocate a drbd_request.
10481193 */
10491194 static struct drbd_request *
1050−drbd_request_prepare(struct drbd_device *device, struct bio *bio, unsigned long start_time)
1195+drbd_request_prepare(struct drbd_device *device, struct bio *bio, unsigned long start_jif)
10511196 {
10521197 const int rw = bio_data_dir(bio);
10531198 struct drbd_request *req;
@@ -1062,7 +1207,7 @@ drbd_request_prepare(struct drbd_device *device, struct bio *bio, unsigned long · 8 unmodified lines
10621207 bio_endio(bio, -ENOMEM);
10631208 return ERR_PTR(-ENOMEM);
10641209 }
1065− req->start_time = start_time;
1210+ req->start_jif = start_jif;
10661211
10671212 if (!get_ldev(device)) {
10681213 bio_put(req->private_bio);
@@ -1075,10 +1220,12 @@ drbd_request_prepare(struct drbd_device *device, struct bio *bio, unsigned long · 6 unmodified lines
10751220 if (rw == WRITE && req->private_bio && req->i.size
10761221 && !test_bit(AL_SUSPENDED, &device->flags)) {
10771222 if (!drbd_al_begin_io_fastpath(device, &req->i)) {
1223+ atomic_inc(&device->ap_actlog_cnt);
10781224 drbd_queue_write(device, req);
10791225 return NULL;
10801226 }
10811227 req->rq_state |= RQ_IN_ACT_LOG;
1228+ req->in_actlog_jif = jiffies;
10821229 }
10831230
10841231 return req;
@@ -1086,11 +1233,13 @@ drbd_request_prepare(struct drbd_device *device, struct bio *bio, unsigned long · 1 unmodified line
10861233
10871234 static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request *req)
10881235 {
1236+ struct drbd_resource *resource = device->resource;
10891237 const int rw = bio_rw(req->master_bio);
10901238 struct bio_and_error m = { NULL, };
10911239 bool no_remote = false;
1240+ bool submit_private_bio = false;
10921241
1093− spin_lock_irq(&device->resource->req_lock);
1242+ spin_lock_irq(&resource->req_lock);
10941243 if (rw == WRITE) {
10951244 /* This may temporarily give up the req_lock,
10961245 * but will re-aquire it before it returns here.
@@ -1148,13 +1297,18 @@ static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request · 51 unmodified lines
11481297 no_remote = true;
11491298 }
11501299
1300+ /* If it took the fast path in drbd_request_prepare, add it here.
1301+ * The slow path has added it already. */
1302+ if (list_empty(&req->req_pending_master_completion))
1303+ list_add_tail(&req->req_pending_master_completion,
1304+ &device->pending_master_completion[rw == WRITE]);
11511305 if (req->private_bio) {
11521306 /* needs to be marked within the same spinlock */
1307+ list_add_tail(&req->req_pending_local,
1308+ &device->pending_completion[rw == WRITE]);
11531309 _req_mod(req, TO_BE_SUBMITTED);
11541310 /* but we need to give up the spinlock to submit */
1155− spin_unlock_irq(&device->resource->req_lock);
1156− drbd_submit_req_private_bio(req);
1157− spin_lock_irq(&device->resource->req_lock);
1311+ submit_private_bio = true;
11581312 } else if (no_remote) {
11591313 nodata:
11601314 if (__ratelimit(&drbd_ratelimit_state))
@@ -1167,15 +1321,23 @@ nodata: · 6 unmodified lines
11671321 out:
11681322 if (drbd_req_put_completion_ref(req, &m, 1))
11691323 kref_put(&req->kref, drbd_req_destroy);
1170− spin_unlock_irq(&device->resource->req_lock);
1171−
1324+ spin_unlock_irq(&resource->req_lock);
1325+
1326+ /* Even though above is a kref_put(), this is safe.
1327+ * As long as we still need to submit our private bio,
1328+ * we hold a completion ref, and the request cannot disappear.
1329+ * If however this request did not even have a private bio to submit
1330+ * (e.g. remote read), req may already be invalid now.
1331+ * That's why we cannot check on req->private_bio. */
1332+ if (submit_private_bio)
1333+ drbd_submit_req_private_bio(req);
11721334 if (m.bio)
11731335 complete_master_bio(device, &m);
11741336 }
11751337
1176−void __drbd_make_request(struct drbd_device *device, struct bio *bio, unsigned long start_time)
1338+void __drbd_make_request(struct drbd_device *device, struct bio *bio, unsigned long start_jif)
11771339 {
1178− struct drbd_request *req = drbd_request_prepare(device, bio, start_time);
1340+ struct drbd_request *req = drbd_request_prepare(device, bio, start_jif);
11791341 if (IS_ERR_OR_NULL(req))
11801342 return;
11811343 drbd_send_and_submit(device, req);
@@ -1194,6 +1356,8 @@ static void submit_fast_path(struct drbd_device *device, struct list_head *incom · 12 unmodified lines
11941356 continue;
11951357
11961358 req->rq_state |= RQ_IN_ACT_LOG;
1359+ req->in_actlog_jif = jiffies;
1360+ atomic_dec(&device->ap_actlog_cnt);
11971361 }
11981362
11991363 list_del_init(&req->tl_requests);
@@ -1203,7 +1367,8 @@ static void submit_fast_path(struct drbd_device *device, struct list_head *incom · 3 unmodified lines
12031367
12041368 static bool prepare_al_transaction_nonblock(struct drbd_device *device,
12051369 struct list_head *incoming,
1206− struct list_head *pending)
1370+ struct list_head *pending,
1371+ struct list_head *later)
12071372 {
12081373 struct drbd_request *req, *tmp;
12091374 int wake = 0;
@@ -1212,45 +1377,105 @@ static bool prepare_al_transaction_nonblock(struct drbd_device *device, · 2 unmodified lines
12121377 spin_lock_irq(&device->al_lock);
12131378 list_for_each_entry_safe(req, tmp, incoming, tl_requests) {
12141379 err = drbd_al_begin_io_nonblock(device, &req->i);
1380+ if (err == -ENOBUFS)
1381+ break;
12151382 if (err == -EBUSY)
12161383 wake = 1;
12171384 if (err)
1218− continue;
1219− req->rq_state |= RQ_IN_ACT_LOG;
1220− list_move_tail(&req->tl_requests, pending);
1385+ list_move_tail(&req->tl_requests, later);
1386+ else
1387+ list_move_tail(&req->tl_requests, pending);
12211388 }
12221389 spin_unlock_irq(&device->al_lock);
12231390 if (wake)
12241391 wake_up(&device->al_wait);
1225−
12261392 return !list_empty(pending);
12271393 }
12281394
1395+void send_and_submit_pending(struct drbd_device *device, struct list_head *pending)
1396+{
1397+ struct drbd_request *req, *tmp;
1398+
1399+ list_for_each_entry_safe(req, tmp, pending, tl_requests) {
1400+ req->rq_state |= RQ_IN_ACT_LOG;
1401+ req->in_actlog_jif = jiffies;
1402+ atomic_dec(&device->ap_actlog_cnt);
1403+ list_del_init(&req->tl_requests);
1404+ drbd_send_and_submit(device, req);
1405+ }
1406+}
1407+
12291408 void do_submit(struct work_struct *ws)
12301409 {
12311410 struct drbd_device *device = container_of(ws, struct drbd_device, submit.worker);
1232− LIST_HEAD(incoming);
1233− LIST_HEAD(pending);
1234− struct drbd_request *req, *tmp;
1411+ LIST_HEAD(incoming); /* from drbd_make_request() */
1412+ LIST_HEAD(pending); /* to be submitted after next AL-transaction commit */
1413+ LIST_HEAD(busy); /* blocked by resync requests */
1414+
1415+ /* grab new incoming requests */
1416+ spin_lock_irq(&device->resource->req_lock);
1417+ list_splice_tail_init(&device->submit.writes, &incoming);
1418+ spin_unlock_irq(&device->resource->req_lock);
12351419
12361420 for (;;) {
1237− spin_lock(&device->submit.lock);
1238− list_splice_tail_init(&device->submit.writes, &incoming);
1239− spin_unlock(&device->submit.lock);
1421+ DEFINE_WAIT(wait);
12401422
1423+ /* move used-to-be-busy back to front of incoming */
1424+ list_splice_init(&busy, &incoming);
12411425 submit_fast_path(device, &incoming);
12421426 if (list_empty(&incoming))
12431427 break;
12441428
1245−skip_fast_path:
1246− wait_event(device->al_wait, prepare_al_transaction_nonblock(device, &incoming, &pending));
1247− /* Maybe more was queued, while we prepared the transaction?
1248− * Try to stuff them into this transaction as well.
1249− * Be strictly non-blocking here, no wait_event, we already
1250− * have something to commit.
1251− * Stop if we don't make any more progres.
1252− */
12531429 for (;;) {
1430+ prepare_to_wait(&device->al_wait, &wait, TASK_UNINTERRUPTIBLE);
1431+
1432+ list_splice_init(&busy, &incoming);
1433+ prepare_al_transaction_nonblock(device, &incoming, &pending, &busy);
1434+ if (!list_empty(&pending))
1435+ break;
1436+
1437+ schedule();
1438+
1439+ /* If all currently "hot" activity log extents are kept busy by
1440+ * incoming requests, we still must not totally starve new
1441+ * requests to "cold" extents.
1442+ * Something left on &incoming means there had not been
1443+ * enough update slots available, and the activity log
1444+ * has been marked as "starving".
1445+ *
1446+ * Try again now, without looking for new requests,
1447+ * effectively blocking all new requests until we made
1448+ * at least _some_ progress with what we currently have.
1449+ */
1450+ if (!list_empty(&incoming))
1451+ continue;
1452+
1453+ /* Nothing moved to pending, but nothing left
1454+ * on incoming: all moved to busy!
1455+ * Grab new and iterate. */
1456+ spin_lock_irq(&device->resource->req_lock);
1457+ list_splice_tail_init(&device->submit.writes, &incoming);
1458+ spin_unlock_irq(&device->resource->req_lock);
1459+ }
1460+ finish_wait(&device->al_wait, &wait);
1461+
1462+ /* If the transaction was full, before all incoming requests
1463+ * had been processed, skip ahead to commit, and iterate
1464+ * without splicing in more incoming requests from upper layers.
1465+ *
1466+ * Else, if all incoming have been processed,
1467+ * they have become either "pending" (to be submitted after
1468+ * next transaction commit) or "busy" (blocked by resync).
1469+ *
1470+ * Maybe more was queued, while we prepared the transaction?
1471+ * Try to stuff those into this transaction as well.
1472+ * Be strictly non-blocking here,
1473+ * we already have something to commit.
1474+ *
1475+ * Commit if we don't make any more progres.
1476+ */
1477+
1478+ while (list_empty(&incoming)) {
12541479 LIST_HEAD(more_pending);
12551480 LIST_HEAD(more_incoming);
12561481 bool made_progress;
@@ -1260,55 +1485,32 @@ skip_fast_path: · 3 unmodified lines
12601485 if (list_empty(&device->submit.writes))
12611486 break;
12621487
1263− spin_lock(&device->submit.lock);
1488+ spin_lock_irq(&device->resource->req_lock);
12641489 list_splice_tail_init(&device->submit.writes, &more_incoming);
1265− spin_unlock(&device->submit.lock);
1490+ spin_unlock_irq(&device->resource->req_lock);
12661491
12671492 if (list_empty(&more_incoming))
12681493 break;
12691494
1270− made_progress = prepare_al_transaction_nonblock(device, &more_incoming, &more_pending);
1495+ made_progress = prepare_al_transaction_nonblock(device, &more_incoming, &more_pending, &busy);
12711496
12721497 list_splice_tail_init(&more_pending, &pending);
12731498 list_splice_tail_init(&more_incoming, &incoming);
1274−
12751499 if (!made_progress)
12761500 break;
12771501 }
1278− drbd_al_begin_io_commit(device, false);
1279−
1280− list_for_each_entry_safe(req, tmp, &pending, tl_requests) {
1281− list_del_init(&req->tl_requests);
1282− drbd_send_and_submit(device, req);
1283− }
12841502
1285− /* If all currently hot activity log extents are kept busy by
1286− * incoming requests, we still must not totally starve new
1287− * requests to cold extents. In that case, prepare one request
1288− * in blocking mode. */
1289− list_for_each_entry_safe(req, tmp, &incoming, tl_requests) {
1290− list_del_init(&req->tl_requests);
1291− req->rq_state |= RQ_IN_ACT_LOG;
1292− if (!drbd_al_begin_io_prepare(device, &req->i)) {
1293− /* Corresponding extent was hot after all? */
1294− drbd_send_and_submit(device, req);
1295− } else {
1296− /* Found a request to a cold extent.
1297− * Put on "pending" list,
1298− * and try to cumulate with more. */
1299− list_add(&req->tl_requests, &pending);
1300− goto skip_fast_path;
1301− }
1302− }
1503+ drbd_al_begin_io_commit(device);
1504+ send_and_submit_pending(device, &pending);
13031505 }
13041506 }
13051507
13061508 void drbd_make_request(struct request_queue *q, struct bio *bio)
13071509 {
13081510 struct drbd_device *device = (struct drbd_device *) q->queuedata;
1309− unsigned long start_time;
1511+ unsigned long start_jif;
13101512
1311− start_time = jiffies;
1513+ start_jif = jiffies;
13121514
13131515 /*
13141516 * what we "blindly" assume:
@@ -1316,7 +1518,7 @@ void drbd_make_request(struct request_queue *q, struct bio *bio) · 1 unmodified line
13161518 D_ASSERT(device, IS_ALIGNED(bio->bi_iter.bi_size, 512));
13171519
13181520 inc_ap_bio(device);
1319− __drbd_make_request(device, bio, start_time);
1521+ __drbd_make_request(device, bio, start_jif);
13201522 }
13211523
13221524 /* This is called by bio_add_page().
@@ -1353,36 +1555,13 @@ int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct · 30 unmodified lines
13531555 return limit;
13541556 }
13551557
1356−static void find_oldest_requests(
1357− struct drbd_connection *connection,
1358− struct drbd_device *device,
1359− struct drbd_request **oldest_req_waiting_for_peer,
1360− struct drbd_request **oldest_req_waiting_for_disk)
1361−{
1362− struct drbd_request *r;
1363− *oldest_req_waiting_for_peer = NULL;
1364− *oldest_req_waiting_for_disk = NULL;
1365− list_for_each_entry(r, &connection->transfer_log, tl_requests) {
1366− const unsigned s = r->rq_state;
1367− if (!*oldest_req_waiting_for_peer
1368− && ((s & RQ_NET_MASK) && !(s & RQ_NET_DONE)))
1369− *oldest_req_waiting_for_peer = r;
1370−
1371− if (!*oldest_req_waiting_for_disk
1372− && (s & RQ_LOCAL_PENDING) && r->device == device)
1373− *oldest_req_waiting_for_disk = r;
1374−
1375− if (*oldest_req_waiting_for_peer && *oldest_req_waiting_for_disk)
1376− break;
1377− }
1378−}
1379−
13801558 void request_timer_fn(unsigned long data)
13811559 {
13821560 struct drbd_device *device = (struct drbd_device *) data;
13831561 struct drbd_connection *connection = first_peer_device(device)->connection;
1384− struct drbd_request *req_disk, *req_peer; /* oldest request */
1562+ struct drbd_request *req_read, *req_write, *req_peer; /* oldest request */
13851563 struct net_conf *nc;
1564+ unsigned long oldest_submit_jif;
13861565 unsigned long ent = 0, dt = 0, et, nt; /* effective timeout = ko_count * timeout */
13871566 unsigned long now;
13881567
@@ -1403,14 +1582,31 @@ void request_timer_fn(unsigned long data) · 14 unmodified lines
14031582 return; /* Recurring timer stopped */
14041583
14051584 now = jiffies;
1585+ nt = now + et;
14061586
14071587 spin_lock_irq(&device->resource->req_lock);
1408− find_oldest_requests(connection, device, &req_peer, &req_disk);
1409− if (req_peer == NULL && req_disk == NULL) {
1410− spin_unlock_irq(&device->resource->req_lock);
1411− mod_timer(&device->request_timer, now + et);
1412− return;
1413− }
1588+ req_read = list_first_entry_or_null(&device->pending_completion[0], struct drbd_request, req_pending_local);
1589+ req_write = list_first_entry_or_null(&device->pending_completion[1], struct drbd_request, req_pending_local);
1590+ req_peer = connection->req_not_net_done;
1591+ /* maybe the oldest request waiting for the peer is in fact still
1592+ * blocking in tcp sendmsg */
1593+ if (!req_peer && connection->req_next && connection->req_next->pre_send_jif)
1594+ req_peer = connection->req_next;
1595+
1596+ /* evaluate the oldest peer request only in one timer! */
1597+ if (req_peer && req_peer->device != device)
1598+ req_peer = NULL;
1599+
1600+ /* do we have something to evaluate? */
1601+ if (req_peer == NULL && req_write == NULL && req_read == NULL)
1602+ goto out;
1603+
1604+ oldest_submit_jif =
1605+ (req_write && req_read)
1606+ ? ( time_before(req_write->pre_submit_jif, req_read->pre_submit_jif)
1607+ ? req_write->pre_submit_jif : req_read->pre_submit_jif )
1608+ : req_write ? req_write->pre_submit_jif
1609+ : req_read ? req_read->pre_submit_jif : now;
14141610
14151611 /* The request is considered timed out, if
14161612 * - we have some effective timeout from the configuration,
@@ -1429,13 +1625,13 @@ void request_timer_fn(unsigned long data) · 12 unmodified lines
14291625 * to expire twice (worst case) to become effective. Good enough.
14301626 */
14311627 if (ent && req_peer &&
1432− time_after(now, req_peer->start_time + ent) &&
1628+ time_after(now, req_peer->pre_send_jif + ent) &&
14331629 !time_in_range(now, connection->last_reconnect_jif, connection->last_reconnect_jif + ent)) {
14341630 drbd_warn(device, "Remote failed to finish a request within ko-count * timeout\n");
14351631 _drbd_set_state(_NS(device, conn, C_TIMEOUT), CS_VERBOSE | CS_HARD, NULL);
14361632 }
1437− if (dt && req_disk &&
1438− time_after(now, req_disk->start_time + dt) &&
1633+ if (dt && oldest_submit_jif != now &&
1634+ time_after(now, oldest_submit_jif + dt) &&
14391635 !time_in_range(now, device->last_reattach_jif, device->last_reattach_jif + dt)) {
14401636 drbd_warn(device, "Local backing device failed to meet the disk-timeout\n");
14411637 __drbd_chk_io_error(device, DRBD_FORCE_DETACH);
@@ -1443,11 +1639,12 @@ void request_timer_fn(unsigned long data) · 1 unmodified line
14431639
14441640 /* Reschedule timer for the nearest not already expired timeout.
14451641 * Fallback to now + min(effective network timeout, disk timeout). */
1446− ent = (ent && req_peer && time_before(now, req_peer->start_time + ent))
1447− ? req_peer->start_time + ent : now + et;
1448− dt = (dt && req_disk && time_before(now, req_disk->start_time + dt))
1449− ? req_disk->start_time + dt : now + et;
1642+ ent = (ent && req_peer && time_before(now, req_peer->pre_send_jif + ent))
1643+ ? req_peer->pre_send_jif + ent : now + et;
1644+ dt = (dt && oldest_submit_jif != now && time_before(now, oldest_submit_jif + dt))
1645+ ? oldest_submit_jif + dt : now + et;
14501646 nt = time_before(ent, dt) ? ent : dt;
1647+out:
14511648 spin_unlock_irq(&connection->resource->req_lock);
14521649 mod_timer(&device->request_timer, nt);
14531650 }
drivers/block/drbd/drbd_req.h+1−0
@@ -288,6 +288,7 @@ extern void complete_master_bio(struct drbd_device *device, · 287 unmodified lines
288288 extern void request_timer_fn(unsigned long data);
289289 extern void tl_restart(struct drbd_connection *connection, enum drbd_req_event what);
290290 extern void _tl_restart(struct drbd_connection *connection, enum drbd_req_event what);
291+extern void tl_abort_disk_io(struct drbd_device *device);
291292
292293 /* this is in drbd_main.c */
293294 extern void drbd_restart_request(struct drbd_request *req);
drivers/block/drbd/drbd_state.c+49−41
@@ -410,7 +410,7 @@ _drbd_request_state(struct drbd_device *device, union drbd_state mask, · 409 unmodified lines
410410 return rv;
411411 }
412412
413−static void print_st(struct drbd_device *device, char *name, union drbd_state ns)
413+static void print_st(struct drbd_device *device, const char *name, union drbd_state ns)
414414 {
415415 drbd_err(device, " %s = { cs:%s ro:%s/%s ds:%s/%s %c%c%c%c%c%c }\n",
416416 name,
@@ -952,11 +952,12 @@ enum drbd_state_rv · 535 unmodified lines
952952 __drbd_set_state(struct drbd_device *device, union drbd_state ns,
953953 enum chg_state_flags flags, struct completion *done)
954954 {
955+ struct drbd_peer_device *peer_device = first_peer_device(device);
956+ struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
955957 union drbd_state os;
956958 enum drbd_state_rv rv = SS_SUCCESS;
957959 enum sanitize_state_warnings ssw;
958960 struct after_state_chg_work *ascw;
959− bool did_remote, should_do_remote;
960961
961962 os = drbd_read_state(device);
962963
@@ -978,9 +979,9 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, · 15 unmodified lines
978979 this happen...*/
979980
980981 if (is_valid_state(device, os) == rv)
981− rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection);
982+ rv = is_valid_soft_transition(os, ns, connection);
982983 } else
983− rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection);
984+ rv = is_valid_soft_transition(os, ns, connection);
984985 }
985986
986987 if (rv < SS_SUCCESS) {
@@ -997,7 +998,7 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, · 10 unmodified lines
997998 sanitize_state(). Only display it here if we where not called from
998999 _conn_request_state() */
9991000 if (!(flags & CS_DC_SUSP))
1000− conn_pr_state_change(first_peer_device(device)->connection, os, ns,
1001+ conn_pr_state_change(connection, os, ns,
10011002 (flags & ~CS_DC_MASK) | CS_DC_SUSP);
10021003
10031004 /* if we are going -> D_FAILED or D_DISKLESS, grab one extra reference
@@ -1008,28 +1009,35 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, · 4 unmodified lines
10081009 (os.disk != D_DISKLESS && ns.disk == D_DISKLESS))
10091010 atomic_inc(&device->local_cnt);
10101011
1011− did_remote = drbd_should_do_remote(device->state);
1012+ if (!is_sync_state(os.conn) && is_sync_state(ns.conn))
1013+ clear_bit(RS_DONE, &device->flags);
1014+
1015+ /* changes to local_cnt and device flags should be visible before
1016+ * changes to state, which again should be visible before anything else
1017+ * depending on that change happens. */
1018+ smp_wmb();
10121019 device->state.i = ns.i;
1013− should_do_remote = drbd_should_do_remote(device->state);
10141020 device->resource->susp = ns.susp;
10151021 device->resource->susp_nod = ns.susp_nod;
10161022 device->resource->susp_fen = ns.susp_fen;
1023+ smp_wmb();
10171024
10181025 /* put replicated vs not-replicated requests in seperate epochs */
1019− if (did_remote != should_do_remote)
1020− start_new_tl_epoch(first_peer_device(device)->connection);
1026+ if (drbd_should_do_remote((union drbd_dev_state)os.i) !=
1027+ drbd_should_do_remote((union drbd_dev_state)ns.i))
1028+ start_new_tl_epoch(connection);
10211029
10221030 if (os.disk == D_ATTACHING && ns.disk >= D_NEGOTIATING)
10231031 drbd_print_uuids(device, "attached to UUIDs");
10241032
10251033 /* Wake up role changes, that were delayed because of connection establishing */
10261034 if (os.conn == C_WF_REPORT_PARAMS && ns.conn != C_WF_REPORT_PARAMS &&
1027− no_peer_wf_report_params(first_peer_device(device)->connection))
1028− clear_bit(STATE_SENT, &first_peer_device(device)->connection->flags);
1035+ no_peer_wf_report_params(connection))
1036+ clear_bit(STATE_SENT, &connection->flags);
10291037
10301038 wake_up(&device->misc_wait);
10311039 wake_up(&device->state_wait);
1032− wake_up(&first_peer_device(device)->connection->ping_wait);
1040+ wake_up(&connection->ping_wait);
10331041
10341042 /* Aborted verify run, or we reached the stop sector.
10351043 * Log the last position, unless end-of-device. */
@@ -1118,21 +1126,21 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, · 82 unmodified lines
11181126
11191127 /* Receiver should clean up itself */
11201128 if (os.conn != C_DISCONNECTING && ns.conn == C_DISCONNECTING)
1121− drbd_thread_stop_nowait(&first_peer_device(device)->connection->receiver);
1129+ drbd_thread_stop_nowait(&connection->receiver);
11221130
11231131 /* Now the receiver finished cleaning up itself, it should die */
11241132 if (os.conn != C_STANDALONE && ns.conn == C_STANDALONE)
1125− drbd_thread_stop_nowait(&first_peer_device(device)->connection->receiver);
1133+ drbd_thread_stop_nowait(&connection->receiver);
11261134
11271135 /* Upon network failure, we need to restart the receiver. */
11281136 if (os.conn > C_WF_CONNECTION &&
11291137 ns.conn <= C_TEAR_DOWN && ns.conn >= C_TIMEOUT)
1130− drbd_thread_restart_nowait(&first_peer_device(device)->connection->receiver);
1138+ drbd_thread_restart_nowait(&connection->receiver);
11311139
11321140 /* Resume AL writing if we get a connection */
11331141 if (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED) {
11341142 drbd_resume_al(device);
1135− first_peer_device(device)->connection->connect_cnt++;
1143+ connection->connect_cnt++;
11361144 }
11371145
11381146 /* remember last attach time so request_timer_fn() won't
@@ -1150,7 +1158,7 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, · 11 unmodified lines
11501158 ascw->w.cb = w_after_state_ch;
11511159 ascw->device = device;
11521160 ascw->done = done;
1153− drbd_queue_work(&first_peer_device(device)->connection->sender_work,
1161+ drbd_queue_work(&connection->sender_work,
11541162 &ascw->w);
11551163 } else {
11561164 drbd_err(device, "Could not kmalloc an ascw\n");
@@ -1222,13 +1230,16 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 65 unmodified lines
12221230 union drbd_state ns, enum chg_state_flags flags)
12231231 {
12241232 struct drbd_resource *resource = device->resource;
1233+ struct drbd_peer_device *peer_device = first_peer_device(device);
1234+ struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
12251235 struct sib_info sib;
12261236
12271237 sib.sib_reason = SIB_STATE_CHANGE;
12281238 sib.os = os;
12291239 sib.ns = ns;
12301240
1231− if (os.conn != C_CONNECTED && ns.conn == C_CONNECTED) {
1241+ if ((os.disk != D_UP_TO_DATE || os.pdsk != D_UP_TO_DATE)
1242+ && (ns.disk == D_UP_TO_DATE && ns.pdsk == D_UP_TO_DATE)) {
12321243 clear_bit(CRASHED_PRIMARY, &device->flags);
12331244 if (device->p_uuid)
12341245 device->p_uuid[UI_FLAGS] &= ~((u64)2);
@@ -1245,7 +1256,6 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 10 unmodified lines
12451256 state change. This function might sleep */
12461257
12471258 if (ns.susp_nod) {
1248− struct drbd_connection *connection = first_peer_device(device)->connection;
12491259 enum drbd_req_event what = NOTHING;
12501260
12511261 spin_lock_irq(&device->resource->req_lock);
@@ -1267,8 +1277,6 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 15 unmodified lines
12671277 }
12681278
12691279 if (ns.susp_fen) {
1270− struct drbd_connection *connection = first_peer_device(device)->connection;
1271−
12721280 spin_lock_irq(&device->resource->req_lock);
12731281 if (resource->susp_fen && conn_lowest_conn(connection) >= C_CONNECTED) {
12741282 /* case2: The connection was established again: */
@@ -1294,8 +1302,8 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 19 unmodified lines
12941302 * which is unexpected. */
12951303 if ((os.conn != C_SYNC_SOURCE && os.conn != C_PAUSED_SYNC_S) &&
12961304 (ns.conn == C_SYNC_SOURCE || ns.conn == C_PAUSED_SYNC_S) &&
1297− first_peer_device(device)->connection->agreed_pro_version >= 96 && get_ldev(device)) {
1298− drbd_gen_and_send_sync_uuid(first_peer_device(device));
1305+ connection->agreed_pro_version >= 96 && get_ldev(device)) {
1306+ drbd_gen_and_send_sync_uuid(peer_device);
12991307 put_ldev(device);
13001308 }
13011309
@@ -1309,8 +1317,8 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 7 unmodified lines
13091317 atomic_set(&device->rs_pending_cnt, 0);
13101318 drbd_rs_cancel_all(device);
13111319
1312− drbd_send_uuids(first_peer_device(device));
1313− drbd_send_state(first_peer_device(device), ns);
1320+ drbd_send_uuids(peer_device);
1321+ drbd_send_state(peer_device, ns);
13141322 }
13151323 /* No point in queuing send_bitmap if we don't have a connection
13161324 * anymore, so check also the _current_ state, not only the new state
@@ -1335,7 +1343,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 18 unmodified lines
13351343 set_bit(NEW_CUR_UUID, &device->flags);
13361344 } else {
13371345 drbd_uuid_new_current(device);
1338− drbd_send_uuids(first_peer_device(device));
1346+ drbd_send_uuids(peer_device);
13391347 }
13401348 }
13411349 put_ldev(device);
@@ -1346,7 +1354,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 4 unmodified lines
13461354 if (os.peer == R_SECONDARY && ns.peer == R_PRIMARY &&
13471355 device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) {
13481356 drbd_uuid_new_current(device);
1349− drbd_send_uuids(first_peer_device(device));
1357+ drbd_send_uuids(peer_device);
13501358 }
13511359 /* D_DISKLESS Peer becomes secondary */
13521360 if (os.peer == R_PRIMARY && ns.peer == R_SECONDARY)
@@ -1373,16 +1381,16 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 20 unmodified lines
13731381 /* Last part of the attaching process ... */
13741382 if (ns.conn >= C_CONNECTED &&
13751383 os.disk == D_ATTACHING && ns.disk == D_NEGOTIATING) {
1376− drbd_send_sizes(first_peer_device(device), 0, 0); /* to start sync... */
1377− drbd_send_uuids(first_peer_device(device));
1378− drbd_send_state(first_peer_device(device), ns);
1384+ drbd_send_sizes(peer_device, 0, 0); /* to start sync... */
1385+ drbd_send_uuids(peer_device);
1386+ drbd_send_state(peer_device, ns);
13791387 }
13801388
13811389 /* We want to pause/continue resync, tell peer. */
13821390 if (ns.conn >= C_CONNECTED &&
13831391 ((os.aftr_isp != ns.aftr_isp) ||
13841392 (os.user_isp != ns.user_isp)))
1385− drbd_send_state(first_peer_device(device), ns);
1393+ drbd_send_state(peer_device, ns);
13861394
13871395 /* In case one of the isp bits got set, suspend other devices. */
13881396 if ((!os.aftr_isp && !os.peer_isp && !os.user_isp) &&
@@ -1392,10 +1400,10 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 3 unmodified lines
13921400 /* Make sure the peer gets informed about eventual state
13931401 changes (ISP bits) while we were in WFReportParams. */
13941402 if (os.conn == C_WF_REPORT_PARAMS && ns.conn >= C_CONNECTED)
1395− drbd_send_state(first_peer_device(device), ns);
1403+ drbd_send_state(peer_device, ns);
13961404
13971405 if (os.conn != C_AHEAD && ns.conn == C_AHEAD)
1398− drbd_send_state(first_peer_device(device), ns);
1406+ drbd_send_state(peer_device, ns);
13991407
14001408 /* We are in the progress to start a full sync... */
14011409 if ((os.conn != C_STARTING_SYNC_T && ns.conn == C_STARTING_SYNC_T) ||
@@ -1449,7 +1457,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 47 unmodified lines
14491457 drbd_disk_str(device->state.disk));
14501458
14511459 if (ns.conn >= C_CONNECTED)
1452− drbd_send_state(first_peer_device(device), ns);
1460+ drbd_send_state(peer_device, ns);
14531461
14541462 drbd_rs_cancel_all(device);
14551463
@@ -1473,7 +1481,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 17 unmodified lines
14731481 drbd_disk_str(device->state.disk));
14741482
14751483 if (ns.conn >= C_CONNECTED)
1476− drbd_send_state(first_peer_device(device), ns);
1484+ drbd_send_state(peer_device, ns);
14771485 /* corresponding get_ldev in __drbd_set_state
14781486 * this may finally trigger drbd_ldev_destroy. */
14791487 put_ldev(device);
@@ -1481,7 +1489,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 1 unmodified line
14811489
14821490 /* Notify peer that I had a local IO error, and did not detached.. */
14831491 if (os.disk == D_UP_TO_DATE && ns.disk == D_INCONSISTENT && ns.conn >= C_CONNECTED)
1484− drbd_send_state(first_peer_device(device), ns);
1492+ drbd_send_state(peer_device, ns);
14851493
14861494 /* Disks got bigger while they were detached */
14871495 if (ns.disk > D_NEGOTIATING && ns.pdsk > D_NEGOTIATING &&
@@ -1499,14 +1507,14 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, · 11 unmodified lines
14991507 /* sync target done with resync. Explicitly notify peer, even though
15001508 * it should (at least for non-empty resyncs) already know itself. */
15011509 if (os.disk < D_UP_TO_DATE && os.conn >= C_SYNC_SOURCE && ns.conn == C_CONNECTED)
1502− drbd_send_state(first_peer_device(device), ns);
1510+ drbd_send_state(peer_device, ns);
15031511
15041512 /* Verify finished, or reached stop sector. Peer did not know about
15051513 * the stop sector, and we may even have changed the stop sector during
15061514 * verify to interrupt/stop early. Send the new state. */
15071515 if (os.conn == C_VERIFY_S && ns.conn == C_CONNECTED
15081516 && verify_can_do_stop_sector(device))
1509− drbd_send_state(first_peer_device(device), ns);
1517+ drbd_send_state(peer_device, ns);
15101518
15111519 /* This triggers bitmap writeout of potentially still unwritten pages
15121520 * if the resync finished cleanly, or aborted because of peer disk
@@ -1563,7 +1571,7 @@ static int w_after_conn_state_ch(struct drbd_work *w, int unused) · 50 unmodified lines
15631571 old_conf = connection->net_conf;
15641572 connection->my_addr_len = 0;
15651573 connection->peer_addr_len = 0;
1566− rcu_assign_pointer(connection->net_conf, NULL);
1574+ RCU_INIT_POINTER(connection->net_conf, NULL);
15671575 conn_free_crypto(connection);
15681576 mutex_unlock(&connection->resource->conf_update);
15691577
@@ -1599,7 +1607,7 @@ static int w_after_conn_state_ch(struct drbd_work *w, int unused) · 29 unmodified lines
15991607 return 0;
16001608 }
16011609
1602−void conn_old_common_state(struct drbd_connection *connection, union drbd_state *pcs, enum chg_state_flags *pf)
1610+static void conn_old_common_state(struct drbd_connection *connection, union drbd_state *pcs, enum chg_state_flags *pf)
16031611 {
16041612 enum chg_state_flags flags = ~0;
16051613 struct drbd_peer_device *peer_device;
@@ -1688,7 +1696,7 @@ conn_is_valid_transition(struct drbd_connection *connection, union drbd_state ma · 82 unmodified lines
16881696 return rv;
16891697 }
16901698
1691−void
1699+static void
16921700 conn_set_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val,
16931701 union drbd_state *pns_min, union drbd_state *pns_max, enum chg_state_flags flags)
16941702 {
drivers/block/drbd/drbd_worker.c+276−72
@@ -67,13 +67,10 @@ rwlock_t global_state_lock; · 66 unmodified lines
6767 */
6868 void drbd_md_io_complete(struct bio *bio, int error)
6969 {
70− struct drbd_md_io *md_io;
7170 struct drbd_device *device;
7271
73− md_io = (struct drbd_md_io *)bio->bi_private;
74− device = container_of(md_io, struct drbd_device, md_io);
75−
76− md_io->error = error;
72+ device = bio->bi_private;
73+ device->md_io.error = error;
7774
7875 /* We grabbed an extra reference in _drbd_md_sync_page_io() to be able
7976 * to timeout on the lower level device, and eventually detach from it.
@@ -87,7 +84,7 @@ void drbd_md_io_complete(struct bio *bio, int error) · 7 unmodified lines
8784 * ASSERT(atomic_read(&device->md_io_in_use) == 1) there.
8885 */
8986 drbd_md_put_buffer(device);
90− md_io->done = 1;
87+ device->md_io.done = 1;
9188 wake_up(&device->misc_wait);
9289 bio_put(bio);
9390 if (device->ldev) /* special case: drbd_md_read() during drbd_adm_attach() */
@@ -135,6 +132,7 @@ void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req) __releases(l · 41 unmodified lines
135132 i = peer_req->i;
136133 do_al_complete_io = peer_req->flags & EE_CALL_AL_COMPLETE_IO;
137134 block_id = peer_req->block_id;
135+ peer_req->flags &= ~EE_CALL_AL_COMPLETE_IO;
138136
139137 spin_lock_irqsave(&device->resource->req_lock, flags);
140138 device->writ_cnt += peer_req->i.size >> 9;
@@ -398,9 +396,6 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector, · 257 unmodified lines
398396 if (!get_ldev(device))
399397 return -EIO;
400398
401− if (drbd_rs_should_slow_down(device, sector))
402− goto defer;
403−
404399 /* GFP_TRY, because if there is no memory available right now, this may
405400 * be rescheduled for later. It is "only" background resync, after all. */
406401 peer_req = drbd_alloc_peer_req(peer_device, ID_SYNCER /* unused */, sector,
@@ -410,7 +405,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector, · 3 unmodified lines
410405
411406 peer_req->w.cb = w_e_send_csum;
412407 spin_lock_irq(&device->resource->req_lock);
413− list_add(&peer_req->w.list, &device->read_ee);
408+ list_add_tail(&peer_req->w.list, &device->read_ee);
414409 spin_unlock_irq(&device->resource->req_lock);
415410
416411 atomic_add(size >> 9, &device->rs_sect_ev);
@@ -452,9 +447,9 @@ void resync_timer_fn(unsigned long data) · 35 unmodified lines
452447 {
453448 struct drbd_device *device = (struct drbd_device *) data;
454449
455− if (list_empty(&device->resync_work.list))
456− drbd_queue_work(&first_peer_device(device)->connection->sender_work,
457− &device->resync_work);
450+ drbd_queue_work_if_unqueued(
451+ &first_peer_device(device)->connection->sender_work,
452+ &device->resync_work);
458453 }
459454
460455 static void fifo_set(struct fifo_buffer *fb, int value)
@@ -504,9 +499,9 @@ struct fifo_buffer *fifo_alloc(int fifo_size) · 43 unmodified lines
504499 static int drbd_rs_controller(struct drbd_device *device, unsigned int sect_in)
505500 {
506501 struct disk_conf *dc;
507− unsigned int want; /* The number of sectors we want in the proxy */
502+ unsigned int want; /* The number of sectors we want in-flight */
508503 int req_sect; /* Number of sectors to request in this turn */
509− int correction; /* Number of sectors more we need in the proxy*/
504+ int correction; /* Number of sectors more we need in-flight */
510505 int cps; /* correction per invocation of drbd_rs_controller() */
511506 int steps; /* Number of time steps to plan ahead */
512507 int curr_corr;
@@ -577,20 +572,27 @@ static int drbd_rs_number_requests(struct drbd_device *device) · 64 unmodified lines
577572 * potentially causing a distributed deadlock on congestion during
578573 * online-verify or (checksum-based) resync, if max-buffers,
579574 * 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;
575+
576+ /* note that "number" is in units of "BM_BLOCK_SIZE" (which is 4k),
577+ * mxb (as used here, and in drbd_alloc_pages on the peer) is
578+ * "number of pages" (typically also 4k),
579+ * but "rs_in_flight" is in "sectors" (512 Byte). */
580+ if (mxb - device->rs_in_flight/8 < number)
581+ number = mxb - device->rs_in_flight/8;
582582
583583 return number;
584584 }
585585
586−static int make_resync_request(struct drbd_device *device, int cancel)
586+static int make_resync_request(struct drbd_device *const device, int cancel)
587587 {
588+ struct drbd_peer_device *const peer_device = first_peer_device(device);
589+ struct drbd_connection *const connection = peer_device ? peer_device->connection : NULL;
588590 unsigned long bit;
589591 sector_t sector;
590592 const sector_t capacity = drbd_get_capacity(device->this_bdev);
591593 int max_bio_size;
592594 int number, rollback_i, size;
593− int align, queued, sndbuf;
595+ int align, requeue = 0;
594596 int i = 0;
595597
596598 if (unlikely(cancel))
@@ -617,17 +619,22 @@ static int make_resync_request(struct drbd_device *device, int cancel) · 20 unmodified lines
617619 goto requeue;
618620
619621 for (i = 0; i < number; i++) {
620− /* Stop generating RS requests, when half of the send buffer is filled */
621− mutex_lock(&first_peer_device(device)->connection->data.mutex);
622− if (first_peer_device(device)->connection->data.socket) {
623− queued = first_peer_device(device)->connection->data.socket->sk->sk_wmem_queued;
624− sndbuf = first_peer_device(device)->connection->data.socket->sk->sk_sndbuf;
625− } else {
626− queued = 1;
627− sndbuf = 0;
628− }
629− mutex_unlock(&first_peer_device(device)->connection->data.mutex);
630− if (queued > sndbuf / 2)
622+ /* Stop generating RS requests when half of the send buffer is filled,
623+ * but notify TCP that we'd like to have more space. */
624+ mutex_lock(&connection->data.mutex);
625+ if (connection->data.socket) {
626+ struct sock *sk = connection->data.socket->sk;
627+ int queued = sk->sk_wmem_queued;
628+ int sndbuf = sk->sk_sndbuf;
629+ if (queued > sndbuf / 2) {
630+ requeue = 1;
631+ if (sk->sk_socket)
632+ set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
633+ }
634+ } else
635+ requeue = 1;
636+ mutex_unlock(&connection->data.mutex);
637+ if (requeue)
631638 goto requeue;
632639
633640 next_sector:
@@ -642,8 +649,7 @@ next_sector: · 8 unmodified lines
642649
643650 sector = BM_BIT_TO_SECT(bit);
644651
645− if (drbd_rs_should_slow_down(device, sector) ||
646− drbd_try_rs_begin_io(device, sector)) {
652+ if (drbd_try_rs_begin_io(device, sector)) {
647653 device->bm_resync_fo = bit;
648654 goto requeue;
649655 }
@@ -696,9 +702,9 @@ next_sector: · 46 unmodified lines
696702 /* adjust very last sectors, in case we are oddly sized */
697703 if (sector + (size>>9) > capacity)
698704 size = (capacity-sector)<<9;
699− if (first_peer_device(device)->connection->agreed_pro_version >= 89 &&
700− first_peer_device(device)->connection->csums_tfm) {
701− switch (read_for_csum(first_peer_device(device), sector, size)) {
705+
706+ if (device->use_csums) {
707+ switch (read_for_csum(peer_device, sector, size)) {
702708 case -EIO: /* Disk failure */
703709 put_ldev(device);
704710 return -EIO;
@@ -717,7 +723,7 @@ next_sector: · 12 unmodified lines
717723 int err;
718724
719725 inc_rs_pending(device);
720− err = drbd_send_drequest(first_peer_device(device), P_RS_DATA_REQUEST,
726+ err = drbd_send_drequest(peer_device, P_RS_DATA_REQUEST,
721727 sector, size, ID_SYNCER);
722728 if (err) {
723729 drbd_err(device, "drbd_send_drequest() failed, aborting...\n");
@@ -774,8 +780,7 @@ static int make_ov_request(struct drbd_device *device, int cancel) · 50 unmodified lines
774780
775781 size = BM_BLOCK_SIZE;
776782
777− if (drbd_rs_should_slow_down(device, sector) ||
778− drbd_try_rs_begin_io(device, sector)) {
783+ if (drbd_try_rs_begin_io(device, sector)) {
779784 device->ov_position = sector;
780785 goto requeue;
781786 }
@@ -911,7 +916,7 @@ int drbd_resync_finished(struct drbd_device *device) · 129 unmodified lines
911916 if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T)
912917 khelper_cmd = "after-resync-target";
913918
914− if (first_peer_device(device)->connection->csums_tfm && device->rs_total) {
919+ if (device->use_csums && device->rs_total) {
915920 const unsigned long s = device->rs_same_csum;
916921 const unsigned long t = device->rs_total;
917922 const int ratio =
@@ -1351,13 +1356,15 @@ int w_send_out_of_sync(struct drbd_work *w, int cancel) · 433 unmodified lines
13511356 {
13521357 struct drbd_request *req = container_of(w, struct drbd_request, w);
13531358 struct drbd_device *device = req->device;
1354− struct drbd_connection *connection = first_peer_device(device)->connection;
1359+ struct drbd_peer_device *const peer_device = first_peer_device(device);
1360+ struct drbd_connection *const connection = peer_device->connection;
13551361 int err;
13561362
13571363 if (unlikely(cancel)) {
13581364 req_mod(req, SEND_CANCELED);
13591365 return 0;
13601366 }
1367+ req->pre_send_jif = jiffies;
13611368
13621369 /* this time, no connection->send.current_epoch_writes++;
13631370 * If it was sent, it was the closing barrier for the last
@@ -1365,7 +1372,7 @@ int w_send_out_of_sync(struct drbd_work *w, int cancel) · 1 unmodified line
13651372 * No more barriers will be sent, until we leave AHEAD mode again. */
13661373 maybe_send_barrier(connection, req->epoch);
13671374
1368− err = drbd_send_out_of_sync(first_peer_device(device), req);
1375+ err = drbd_send_out_of_sync(peer_device, req);
13691376 req_mod(req, OOS_HANDED_TO_NETWORK);
13701377
13711378 return err;
@@ -1380,19 +1387,21 @@ int w_send_dblock(struct drbd_work *w, int cancel) · 8 unmodified lines
13801387 {
13811388 struct drbd_request *req = container_of(w, struct drbd_request, w);
13821389 struct drbd_device *device = req->device;
1383− struct drbd_connection *connection = first_peer_device(device)->connection;
1390+ struct drbd_peer_device *const peer_device = first_peer_device(device);
1391+ struct drbd_connection *connection = peer_device->connection;
13841392 int err;
13851393
13861394 if (unlikely(cancel)) {
13871395 req_mod(req, SEND_CANCELED);
13881396 return 0;
13891397 }
1398+ req->pre_send_jif = jiffies;
13901399
13911400 re_init_if_first_write(connection, req->epoch);
13921401 maybe_send_barrier(connection, req->epoch);
13931402 connection->send.current_epoch_writes++;
13941403
1395− err = drbd_send_dblock(first_peer_device(device), req);
1404+ err = drbd_send_dblock(peer_device, req);
13961405 req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK);
13971406
13981407 return err;
@@ -1407,19 +1416,21 @@ int w_send_read_req(struct drbd_work *w, int cancel) · 8 unmodified lines
14071416 {
14081417 struct drbd_request *req = container_of(w, struct drbd_request, w);
14091418 struct drbd_device *device = req->device;
1410− struct drbd_connection *connection = first_peer_device(device)->connection;
1419+ struct drbd_peer_device *const peer_device = first_peer_device(device);
1420+ struct drbd_connection *connection = peer_device->connection;
14111421 int err;
14121422
14131423 if (unlikely(cancel)) {
14141424 req_mod(req, SEND_CANCELED);
14151425 return 0;
14161426 }
1427+ req->pre_send_jif = jiffies;
14171428
14181429 /* Even read requests may close a write epoch,
14191430 * if there was any yet. */
14201431 maybe_send_barrier(connection, req->epoch);
14211432
1422− err = drbd_send_drequest(first_peer_device(device), P_DATA_REQUEST, req->i.sector, req->i.size,
1433+ err = drbd_send_drequest(peer_device, P_DATA_REQUEST, req->i.sector, req->i.size,
14231434 (unsigned long)req);
14241435
14251436 req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK);
@@ -1433,7 +1444,7 @@ int w_restart_disk_io(struct drbd_work *w, int cancel) · 7 unmodified lines
14331444 struct drbd_device *device = req->device;
14341445
14351446 if (bio_data_dir(req->master_bio) == WRITE && req->rq_state & RQ_IN_ACT_LOG)
1436− drbd_al_begin_io(device, &req->i, false);
1447+ drbd_al_begin_io(device, &req->i);
14371448
14381449 drbd_req_make_private_bio(req, req->master_bio);
14391450 req->private_bio->bi_bdev = device->ldev->backing_bdev;
@@ -1601,26 +1612,32 @@ void drbd_rs_controller_reset(struct drbd_device *device) · 161 unmodified lines
16011612 void start_resync_timer_fn(unsigned long data)
16021613 {
16031614 struct drbd_device *device = (struct drbd_device *) data;
1604−
1605− drbd_queue_work(&first_peer_device(device)->connection->sender_work,
1606− &device->start_resync_work);
1615+ drbd_device_post_work(device, RS_START);
16071616 }
16081617
1609−int w_start_resync(struct drbd_work *w, int cancel)
1618+static void do_start_resync(struct drbd_device *device)
16101619 {
1611− struct drbd_device *device =
1612− container_of(w, struct drbd_device, start_resync_work);
1613−
16141620 if (atomic_read(&device->unacked_cnt) || atomic_read(&device->rs_pending_cnt)) {
1615− drbd_warn(device, "w_start_resync later...\n");
1621+ drbd_warn(device, "postponing start_resync ...\n");
16161622 device->start_resync_timer.expires = jiffies + HZ/10;
16171623 add_timer(&device->start_resync_timer);
1618− return 0;
1624+ return;
16191625 }
16201626
16211627 drbd_start_resync(device, C_SYNC_SOURCE);
16221628 clear_bit(AHEAD_TO_SYNC_SOURCE, &device->flags);
1623− return 0;
1629+}
1630+
1631+static bool use_checksum_based_resync(struct drbd_connection *connection, struct drbd_device *device)
1632+{
1633+ bool csums_after_crash_only;
1634+ rcu_read_lock();
1635+ csums_after_crash_only = rcu_dereference(connection->net_conf)->csums_after_crash_only;
1636+ rcu_read_unlock();
1637+ return connection->agreed_pro_version >= 89 && /* supported? */
1638+ connection->csums_tfm && /* configured? */
1639+ (csums_after_crash_only == 0 /* use for each resync? */
1640+ || test_bit(CRASHED_PRIMARY, &device->flags)); /* or only after Primary crash? */
16241641 }
16251642
16261643 /**
@@ -1633,6 +1650,8 @@ int w_start_resync(struct drbd_work *w, int cancel) · 6 unmodified lines
16331650 */
16341651 void drbd_start_resync(struct drbd_device *device, enum drbd_conns side)
16351652 {
1653+ struct drbd_peer_device *peer_device = first_peer_device(device);
1654+ struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
16361655 union drbd_state ns;
16371656 int r;
16381657
@@ -1651,7 +1670,7 @@ void drbd_start_resync(struct drbd_device *device, enum drbd_conns side) · 12 unmodified lines
16511670 if (r > 0) {
16521671 drbd_info(device, "before-resync-target handler returned %d, "
16531672 "dropping connection.\n", r);
1654− conn_request_state(first_peer_device(device)->connection, NS(conn, C_DISCONNECTING), CS_HARD);
1673+ conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
16551674 return;
16561675 }
16571676 } else /* C_SYNC_SOURCE */ {
@@ -1664,7 +1683,7 @@ void drbd_start_resync(struct drbd_device *device, enum drbd_conns side) · 6 unmodified lines
16641683 } else {
16651684 drbd_info(device, "before-resync-source handler returned %d, "
16661685 "dropping connection.\n", r);
1667− conn_request_state(first_peer_device(device)->connection,
1686+ conn_request_state(connection,
16681687 NS(conn, C_DISCONNECTING), CS_HARD);
16691688 return;
16701689 }
@@ -1672,7 +1691,7 @@ void drbd_start_resync(struct drbd_device *device, enum drbd_conns side) · 1 unmodified line
16721691 }
16731692 }
16741693
1675− if (current == first_peer_device(device)->connection->worker.task) {
1694+ if (current == connection->worker.task) {
16761695 /* The worker should not sleep waiting for state_mutex,
16771696 that can take long */
16781697 if (!mutex_trylock(device->state_mutex)) {
@@ -1733,11 +1752,20 @@ void drbd_start_resync(struct drbd_device *device, enum drbd_conns side) · 54 unmodified lines
17331752 device->rs_mark_time[i] = now;
17341753 }
17351754 _drbd_pause_after(device);
1755+ /* Forget potentially stale cached per resync extent bit-counts.
1756+ * Open coded drbd_rs_cancel_all(device), we already have IRQs
1757+ * disabled, and know the disk state is ok. */
1758+ spin_lock(&device->al_lock);
1759+ lc_reset(device->resync);
1760+ device->resync_locked = 0;
1761+ device->resync_wenr = LC_FREE;
1762+ spin_unlock(&device->al_lock);
17361763 }
17371764 write_unlock(&global_state_lock);
17381765 spin_unlock_irq(&device->resource->req_lock);
17391766
17401767 if (r == SS_SUCCESS) {
1768+ wake_up(&device->al_wait); /* for lc_reset() above */
17411769 /* reset rs_last_bcast when a resync or verify is started,
17421770 * to deal with potential jiffies wrap. */
17431771 device->rs_last_bcast = jiffies - HZ;
@@ -1746,8 +1774,12 @@ void drbd_start_resync(struct drbd_device *device, enum drbd_conns side) · 2 unmodified lines
17461774 drbd_conn_str(ns.conn),
17471775 (unsigned long) device->rs_total << (BM_BLOCK_SHIFT-10),
17481776 (unsigned long) device->rs_total);
1749− if (side == C_SYNC_TARGET)
1777+ if (side == C_SYNC_TARGET) {
17501778 device->bm_resync_fo = 0;
1779+ device->use_csums = use_checksum_based_resync(connection, device);
1780+ } else {
1781+ device->use_csums = 0;
1782+ }
17511783
17521784 /* Since protocol 96, we must serialize drbd_gen_and_send_sync_uuid
17531785 * with w_send_oos, or the sync target will get confused as to
@@ -1756,12 +1788,10 @@ void drbd_start_resync(struct drbd_device *device, enum drbd_conns side) · 2 unmodified lines
17561788 * drbd_resync_finished from here in that case.
17571789 * We drbd_gen_and_send_sync_uuid here for protocol < 96,
17581790 * and from after_state_ch otherwise. */
1759− if (side == C_SYNC_SOURCE &&
1760− first_peer_device(device)->connection->agreed_pro_version < 96)
1761− drbd_gen_and_send_sync_uuid(first_peer_device(device));
1791+ if (side == C_SYNC_SOURCE && connection->agreed_pro_version < 96)
1792+ drbd_gen_and_send_sync_uuid(peer_device);
17621793
1763− if (first_peer_device(device)->connection->agreed_pro_version < 95 &&
1764− device->rs_total == 0) {
1794+ if (connection->agreed_pro_version < 95 && device->rs_total == 0) {
17651795 /* This still has a race (about when exactly the peers
17661796 * detect connection loss) that can lead to a full sync
17671797 * on next handshake. In 8.3.9 we fixed this with explicit
@@ -1777,7 +1807,7 @@ void drbd_start_resync(struct drbd_device *device, enum drbd_conns side) · 9 unmodified lines
17771807 int timeo;
17781808
17791809 rcu_read_lock();
1780− nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
1810+ nc = rcu_dereference(connection->net_conf);
17811811 timeo = nc->ping_int * HZ + nc->ping_timeo * HZ / 9;
17821812 rcu_read_unlock();
17831813 schedule_timeout_interruptible(timeo);
@@ -1799,10 +1829,165 @@ void drbd_start_resync(struct drbd_device *device, enum drbd_conns side) · 15 unmodified lines
17991829 mutex_unlock(device->state_mutex);
18001830 }
18011831
1832+static void update_on_disk_bitmap(struct drbd_device *device, bool resync_done)
1833+{
1834+ struct sib_info sib = { .sib_reason = SIB_SYNC_PROGRESS, };
1835+ device->rs_last_bcast = jiffies;
1836+
1837+ if (!get_ldev(device))
1838+ return;
1839+
1840+ drbd_bm_write_lazy(device, 0);
1841+ if (resync_done && is_sync_state(device->state.conn))
1842+ drbd_resync_finished(device);
1843+
1844+ drbd_bcast_event(device, &sib);
1845+ /* update timestamp, in case it took a while to write out stuff */
1846+ device->rs_last_bcast = jiffies;
1847+ put_ldev(device);
1848+}
1849+
1850+static void drbd_ldev_destroy(struct drbd_device *device)
1851+{
1852+ lc_destroy(device->resync);
1853+ device->resync = NULL;
1854+ lc_destroy(device->act_log);
1855+ device->act_log = NULL;
1856+ __no_warn(local,
1857+ drbd_free_ldev(device->ldev);
1858+ device->ldev = NULL;);
1859+ clear_bit(GOING_DISKLESS, &device->flags);
1860+ wake_up(&device->misc_wait);
1861+}
1862+
1863+static void go_diskless(struct drbd_device *device)
1864+{
1865+ D_ASSERT(device, device->state.disk == D_FAILED);
1866+ /* we cannot assert local_cnt == 0 here, as get_ldev_if_state will
1867+ * inc/dec it frequently. Once we are D_DISKLESS, no one will touch
1868+ * the protected members anymore, though, so once put_ldev reaches zero
1869+ * again, it will be safe to free them. */
1870+
1871+ /* Try to write changed bitmap pages, read errors may have just
1872+ * set some bits outside the area covered by the activity log.
1873+ *
1874+ * If we have an IO error during the bitmap writeout,
1875+ * we will want a full sync next time, just in case.
1876+ * (Do we want a specific meta data flag for this?)
1877+ *
1878+ * If that does not make it to stable storage either,
1879+ * we cannot do anything about that anymore.
1880+ *
1881+ * We still need to check if both bitmap and ldev are present, we may
1882+ * end up here after a failed attach, before ldev was even assigned.
1883+ */
1884+ if (device->bitmap && device->ldev) {
1885+ /* An interrupted resync or similar is allowed to recounts bits
1886+ * while we detach.
1887+ * Any modifications would not be expected anymore, though.
1888+ */
1889+ if (drbd_bitmap_io_from_worker(device, drbd_bm_write,
1890+ "detach", BM_LOCKED_TEST_ALLOWED)) {
1891+ if (test_bit(WAS_READ_ERROR, &device->flags)) {
1892+ drbd_md_set_flag(device, MDF_FULL_SYNC);
1893+ drbd_md_sync(device);
1894+ }
1895+ }
1896+ }
1897+
1898+ drbd_force_state(device, NS(disk, D_DISKLESS));
1899+}
1900+
1901+static int do_md_sync(struct drbd_device *device)
1902+{
1903+ drbd_warn(device, "md_sync_timer expired! Worker calls drbd_md_sync().\n");
1904+ drbd_md_sync(device);
1905+ return 0;
1906+}
1907+
1908+/* only called from drbd_worker thread, no locking */
1909+void __update_timing_details(
1910+ struct drbd_thread_timing_details *tdp,
1911+ unsigned int *cb_nr,
1912+ void *cb,
1913+ const char *fn, const unsigned int line)
1914+{
1915+ unsigned int i = *cb_nr % DRBD_THREAD_DETAILS_HIST;
1916+ struct drbd_thread_timing_details *td = tdp + i;
1917+
1918+ td->start_jif = jiffies;
1919+ td->cb_addr = cb;
1920+ td->caller_fn = fn;
1921+ td->line = line;
1922+ td->cb_nr = *cb_nr;
1923+
1924+ i = (i+1) % DRBD_THREAD_DETAILS_HIST;
1925+ td = tdp + i;
1926+ memset(td, 0, sizeof(*td));
1927+
1928+ ++(*cb_nr);
1929+}
1930+
1931+#define WORK_PENDING(work_bit, todo) (todo & (1UL << work_bit))
1932+static void do_device_work(struct drbd_device *device, const unsigned long todo)
1933+{
1934+ if (WORK_PENDING(MD_SYNC, todo))
1935+ do_md_sync(device);
1936+ if (WORK_PENDING(RS_DONE, todo) ||
1937+ WORK_PENDING(RS_PROGRESS, todo))
1938+ update_on_disk_bitmap(device, WORK_PENDING(RS_DONE, todo));
1939+ if (WORK_PENDING(GO_DISKLESS, todo))
1940+ go_diskless(device);
1941+ if (WORK_PENDING(DESTROY_DISK, todo))
1942+ drbd_ldev_destroy(device);
1943+ if (WORK_PENDING(RS_START, todo))
1944+ do_start_resync(device);
1945+}
1946+
1947+#define DRBD_DEVICE_WORK_MASK \
1948+ ((1UL << GO_DISKLESS) \
1949+ |(1UL << DESTROY_DISK) \
1950+ |(1UL << MD_SYNC) \
1951+ |(1UL << RS_START) \
1952+ |(1UL << RS_PROGRESS) \
1953+ |(1UL << RS_DONE) \
1954+ )
1955+
1956+static unsigned long get_work_bits(unsigned long *flags)
1957+{
1958+ unsigned long old, new;
1959+ do {
1960+ old = *flags;
1961+ new = old & ~DRBD_DEVICE_WORK_MASK;
1962+ } while (cmpxchg(flags, old, new) != old);
1963+ return old & DRBD_DEVICE_WORK_MASK;
1964+}
1965+
1966+static void do_unqueued_work(struct drbd_connection *connection)
1967+{
1968+ struct drbd_peer_device *peer_device;
1969+ int vnr;
1970+
1971+ rcu_read_lock();
1972+ idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
1973+ struct drbd_device *device = peer_device->device;
1974+ unsigned long todo = get_work_bits(&device->flags);
1975+ if (!todo)
1976+ continue;
1977+
1978+ kref_get(&device->kref);
1979+ rcu_read_unlock();
1980+ do_device_work(device, todo);
1981+ kref_put(&device->kref, drbd_destroy_device);
1982+ rcu_read_lock();
1983+ }
1984+ rcu_read_unlock();
1985+}
1986+
18021987 static bool dequeue_work_batch(struct drbd_work_queue *queue, struct list_head *work_list)
18031988 {
18041989 spin_lock_irq(&queue->q_lock);
1805− list_splice_init(&queue->q, work_list);
1990+ list_splice_tail_init(&queue->q, work_list);
18061991 spin_unlock_irq(&queue->q_lock);
18071992 return !list_empty(work_list);
18081993 }
@@ -1851,7 +2036,7 @@ static void wait_for_work(struct drbd_connection *connection, struct list_head * · 42 unmodified lines
18512036 /* dequeue single item only,
18522037 * we still use drbd_queue_work_front() in some places */
18532038 if (!list_empty(&connection->sender_work.q))
1854− list_move(connection->sender_work.q.next, work_list);
2039+ list_splice_tail_init(&connection->sender_work.q, work_list);
18552040 spin_unlock(&connection->sender_work.q_lock); /* FIXME get rid of this one? */
18562041 if (!list_empty(work_list) || signal_pending(current)) {
18572042 spin_unlock_irq(&connection->resource->req_lock);
@@ -1873,6 +2058,14 @@ static void wait_for_work(struct drbd_connection *connection, struct list_head * · 15 unmodified lines
18732058 if (send_barrier)
18742059 maybe_send_barrier(connection,
18752060 connection->send.current_epoch_nr + 1);
2061+
2062+ if (test_bit(DEVICE_WORK_PENDING, &connection->flags))
2063+ break;
2064+
2065+ /* drbd_send() may have called flush_signals() */
2066+ if (get_t_state(&connection->worker) != RUNNING)
2067+ break;
2068+
18762069 schedule();
18772070 /* may be woken up for other things but new work, too,
18782071 * e.g. if the current epoch got closed.
@@ -1906,10 +2099,15 @@ int drbd_worker(struct drbd_thread *thi) · 27 unmodified lines
19062099 while (get_t_state(thi) == RUNNING) {
19072100 drbd_thread_current_set_cpu(thi);
19082101
1909− /* as long as we use drbd_queue_work_front(),
1910− * we may only dequeue single work items here, not batches. */
1911− if (list_empty(&work_list))
2102+ if (list_empty(&work_list)) {
2103+ update_worker_timing_details(connection, wait_for_work);
19122104 wait_for_work(connection, &work_list);
2105+ }
2106+
2107+ if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) {
2108+ update_worker_timing_details(connection, do_unqueued_work);
2109+ do_unqueued_work(connection);
2110+ }
19132111
19142112 if (signal_pending(current)) {
19152113 flush_signals(current);
@@ -1926,6 +2124,7 @@ int drbd_worker(struct drbd_thread *thi) · 10 unmodified lines
19262124 while (!list_empty(&work_list)) {
19272125 w = list_first_entry(&work_list, struct drbd_work, list);
19282126 list_del_init(&w->list);
2127+ update_worker_timing_details(connection, w->cb);
19292128 if (w->cb(w, connection->cstate < C_WF_REPORT_PARAMS) == 0)
19302129 continue;
19312130 if (connection->cstate >= C_WF_REPORT_PARAMS)
@@ -1934,13 +2133,18 @@ int drbd_worker(struct drbd_thread *thi) · 2 unmodified lines
19342133 }
19352134
19362135 do {
2136+ if (test_and_clear_bit(DEVICE_WORK_PENDING, &connection->flags)) {
2137+ update_worker_timing_details(connection, do_unqueued_work);
2138+ do_unqueued_work(connection);
2139+ }
19372140 while (!list_empty(&work_list)) {
19382141 w = list_first_entry(&work_list, struct drbd_work, list);
19392142 list_del_init(&w->list);
2143+ update_worker_timing_details(connection, w->cb);
19402144 w->cb(w, 1);
19412145 }
19422146 dequeue_work_batch(&connection->sender_work, &work_list);
1943− } while (!list_empty(&work_list));
2147+ } while (!list_empty(&work_list) || test_bit(DEVICE_WORK_PENDING, &connection->flags));
19442148
19452149 rcu_read_lock();
19462150 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
drivers/block/virtio_blk.c+84−20
@@ -15,17 +15,22 @@ · 14 unmodified lines
1515 #include <linux/numa.h>
1616
1717 #define PART_BITS 4
18+#define VQ_NAME_LEN 16
1819
1920 static int major;
2021 static DEFINE_IDA(vd_index_ida);
2122
2223 static struct workqueue_struct *virtblk_wq;
2324
25+struct virtio_blk_vq {
26+ struct virtqueue *vq;
27+ spinlock_t lock;
28+ char name[VQ_NAME_LEN];
29+} ____cacheline_aligned_in_smp;
30+
2431 struct virtio_blk
2532 {
2633 struct virtio_device *vdev;
27− struct virtqueue *vq;
28− spinlock_t vq_lock;
2934
3035 /* The disk structure for the kernel. */
3136 struct gendisk *disk;
@@ -47,6 +52,10 @@ struct virtio_blk · 15 unmodified lines
4752
4853 /* Ida index - used to track minor number allocations. */
4954 int index;
55+
56+ /* num of vqs */
57+ int num_vqs;
58+ struct virtio_blk_vq *vqs;
5059 };
5160
5261 struct virtblk_req
@@ -133,14 +142,15 @@ static void virtblk_done(struct virtqueue *vq) · 80 unmodified lines
133142 {
134143 struct virtio_blk *vblk = vq->vdev->priv;
135144 bool req_done = false;
145+ int qid = vq->index;
136146 struct virtblk_req *vbr;
137147 unsigned long flags;
138148 unsigned int len;
139149
140− spin_lock_irqsave(&vblk->vq_lock, flags);
150+ spin_lock_irqsave(&vblk->vqs[qid].lock, flags);
141151 do {
142152 virtqueue_disable_cb(vq);
143− while ((vbr = virtqueue_get_buf(vblk->vq, &len)) != NULL) {
153+ while ((vbr = virtqueue_get_buf(vblk->vqs[qid].vq, &len)) != NULL) {
144154 blk_mq_complete_request(vbr->req);
145155 req_done = true;
146156 }
@@ -151,7 +161,7 @@ static void virtblk_done(struct virtqueue *vq) · 4 unmodified lines
151161 /* In case queue is stopped waiting for more buffers. */
152162 if (req_done)
153163 blk_mq_start_stopped_hw_queues(vblk->disk->queue, true);
154− spin_unlock_irqrestore(&vblk->vq_lock, flags);
164+ spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
155165 }
156166
157167 static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)
@@ -160,6 +170,7 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req) · 2 unmodified lines
160170 struct virtblk_req *vbr = blk_mq_rq_to_pdu(req);
161171 unsigned long flags;
162172 unsigned int num;
173+ int qid = hctx->queue_num;
163174 const bool last = (req->cmd_flags & REQ_END) != 0;
164175 int err;
165176 bool notify = false;
@@ -202,12 +213,12 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req) · 36 unmodified lines
202213 vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
203214 }
204215
205− spin_lock_irqsave(&vblk->vq_lock, flags);
206− err = __virtblk_add_req(vblk->vq, vbr, vbr->sg, num);
216+ spin_lock_irqsave(&vblk->vqs[qid].lock, flags);
217+ err = __virtblk_add_req(vblk->vqs[qid].vq, vbr, vbr->sg, num);
207218 if (err) {
208− virtqueue_kick(vblk->vq);
219+ virtqueue_kick(vblk->vqs[qid].vq);
209220 blk_mq_stop_hw_queue(hctx);
210− spin_unlock_irqrestore(&vblk->vq_lock, flags);
221+ spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
211222 /* Out of mem doesn't actually happen, since we fall back
212223 * to direct descriptors */
213224 if (err == -ENOMEM || err == -ENOSPC)
@@ -215,12 +226,12 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req) · 1 unmodified line
215226 return BLK_MQ_RQ_QUEUE_ERROR;
216227 }
217228
218− if (last && virtqueue_kick_prepare(vblk->vq))
229+ if (last && virtqueue_kick_prepare(vblk->vqs[qid].vq))
219230 notify = true;
220− spin_unlock_irqrestore(&vblk->vq_lock, flags);
231+ spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
221232
222233 if (notify)
223− virtqueue_notify(vblk->vq);
234+ virtqueue_notify(vblk->vqs[qid].vq);
224235 return BLK_MQ_RQ_QUEUE_OK;
225236 }
226237
@@ -377,12 +388,64 @@ static void virtblk_config_changed(struct virtio_device *vdev) · 150 unmodified lines
377388 static int init_vq(struct virtio_blk *vblk)
378389 {
379390 int err = 0;
391+ int i;
392+ vq_callback_t **callbacks;
393+ const char **names;
394+ struct virtqueue **vqs;
395+ unsigned short num_vqs;
396+ struct virtio_device *vdev = vblk->vdev;
397+
398+ err = virtio_cread_feature(vdev, VIRTIO_BLK_F_MQ,
399+ struct virtio_blk_config, num_queues,
400+ &num_vqs);
401+ if (err)
402+ num_vqs = 1;
403+
404+ vblk->vqs = kmalloc(sizeof(*vblk->vqs) * num_vqs, GFP_KERNEL);
405+ if (!vblk->vqs) {
406+ err = -ENOMEM;
407+ goto out;
408+ }
409+
410+ names = kmalloc(sizeof(*names) * num_vqs, GFP_KERNEL);
411+ if (!names)
412+ goto err_names;
413+
414+ callbacks = kmalloc(sizeof(*callbacks) * num_vqs, GFP_KERNEL);
415+ if (!callbacks)
416+ goto err_callbacks;
417+
418+ vqs = kmalloc(sizeof(*vqs) * num_vqs, GFP_KERNEL);
419+ if (!vqs)
420+ goto err_vqs;
380421
381− /* We expect one virtqueue, for output. */
382− vblk->vq = virtio_find_single_vq(vblk->vdev, virtblk_done, "requests");
383− if (IS_ERR(vblk->vq))
384− err = PTR_ERR(vblk->vq);
422+ for (i = 0; i < num_vqs; i++) {
423+ callbacks[i] = virtblk_done;
424+ snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req.%d", i);
425+ names[i] = vblk->vqs[i].name;
426+ }
427+
428+ /* Discover virtqueues and write information to configuration. */
429+ err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names);
430+ if (err)
431+ goto err_find_vqs;
385432
433+ for (i = 0; i < num_vqs; i++) {
434+ spin_lock_init(&vblk->vqs[i].lock);
435+ vblk->vqs[i].vq = vqs[i];
436+ }
437+ vblk->num_vqs = num_vqs;
438+
439+ err_find_vqs:
440+ kfree(vqs);
441+ err_vqs:
442+ kfree(callbacks);
443+ err_callbacks:
444+ kfree(names);
445+ err_names:
446+ if (err)
447+ kfree(vblk->vqs);
448+ out:
386449 return err;
387450 }
388451
@@ -551,7 +614,6 @@ static int virtblk_probe(struct virtio_device *vdev) · 162 unmodified lines
551614 err = init_vq(vblk);
552615 if (err)
553616 goto out_free_vblk;
554− spin_lock_init(&vblk->vq_lock);
555617
556618 /* FIXME: How many partitions? How long is a piece of string? */
557619 vblk->disk = alloc_disk(1 << PART_BITS);
@@ -562,7 +624,7 @@ static int virtblk_probe(struct virtio_device *vdev) · 4 unmodified lines
562624
563625 /* Default queue sizing is to fill the ring. */
564626 if (!virtblk_queue_depth) {
565− virtblk_queue_depth = vblk->vq->num_free;
627+ virtblk_queue_depth = vblk->vqs[0].vq->num_free;
566628 /* ... but without indirect descs, we use 2 descs per req */
567629 if (!virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC))
568630 virtblk_queue_depth /= 2;
@@ -570,7 +632,6 @@ static int virtblk_probe(struct virtio_device *vdev) · 1 unmodified line
570632
571633 memset(&vblk->tag_set, 0, sizeof(vblk->tag_set));
572634 vblk->tag_set.ops = &virtio_mq_ops;
573− vblk->tag_set.nr_hw_queues = 1;
574635 vblk->tag_set.queue_depth = virtblk_queue_depth;
575636 vblk->tag_set.numa_node = NUMA_NO_NODE;
576637 vblk->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
@@ -578,6 +639,7 @@ static int virtblk_probe(struct virtio_device *vdev) · 1 unmodified line
578639 sizeof(struct virtblk_req) +
579640 sizeof(struct scatterlist) * sg_elems;
580641 vblk->tag_set.driver_data = vblk;
642+ vblk->tag_set.nr_hw_queues = vblk->num_vqs;
581643
582644 err = blk_mq_alloc_tag_set(&vblk->tag_set);
583645 if (err)
@@ -727,6 +789,7 @@ static void virtblk_remove(struct virtio_device *vdev) · 143 unmodified lines
727789 refc = atomic_read(&disk_to_dev(vblk->disk)->kobj.kref.refcount);
728790 put_disk(vblk->disk);
729791 vdev->config->del_vqs(vdev);
792+ kfree(vblk->vqs);
730793 kfree(vblk);
731794
732795 /* Only free device id if we don't have any users */
@@ -777,7 +840,8 @@ static const struct virtio_device_id id_table[] = { · 44 unmodified lines
777840 static unsigned int features[] = {
778841 VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_GEOMETRY,
779842 VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, VIRTIO_BLK_F_SCSI,
780− VIRTIO_BLK_F_WCE, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_CONFIG_WCE
843+ VIRTIO_BLK_F_WCE, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_CONFIG_WCE,
844+ VIRTIO_BLK_F_MQ,
781845 };
782846
783847 static struct virtio_driver virtio_blk = {
drivers/md/bcache/alloc.c+1−1
@@ -331,7 +331,7 @@ static int bch_allocator_thread(void *arg) · 330 unmodified lines
331331 mutex_unlock(&ca->set->bucket_lock);
332332 blkdev_issue_discard(ca->bdev,
333333 bucket_to_sector(ca->set, bucket),
334− ca->sb.block_size, GFP_KERNEL, 0);
334+ ca->sb.bucket_size, GFP_KERNEL, 0);
335335 mutex_lock(&ca->set->bucket_lock);
336336 }
337337
drivers/md/bcache/bcache.h+4−0
@@ -477,9 +477,13 @@ struct gc_stat { · 476 unmodified lines
477477 * CACHE_SET_STOPPING always gets set first when we're closing down a cache set;
478478 * we'll continue to run normally for awhile with CACHE_SET_STOPPING set (i.e.
479479 * flushing dirty data).
480+ *
481+ * CACHE_SET_RUNNING means all cache devices have been registered and journal
482+ * replay is complete.
480483 */
481484 #define CACHE_SET_UNREGISTERING 0
482485 #define CACHE_SET_STOPPING 1
486+#define CACHE_SET_RUNNING 2
483487
484488 struct cache_set {
485489 struct closure cl;
drivers/md/bcache/bset.c+1−1
@@ -1182,7 +1182,7 @@ static void __btree_sort(struct btree_keys *b, struct btree_iter *iter, · 1181 unmodified lines
11821182 {
11831183 uint64_t start_time;
11841184 bool used_mempool = false;
1185− struct bset *out = (void *) __get_free_pages(__GFP_NOWARN|GFP_NOIO,
1185+ struct bset *out = (void *) __get_free_pages(__GFP_NOWARN|GFP_NOWAIT,
11861186 order);
11871187 if (!out) {
11881188 struct page *outp;
drivers/md/bcache/bset.h+1−1
@@ -453,7 +453,7 @@ static inline bool bch_bkey_equal_header(const struct bkey *l, · 452 unmodified lines
453453 {
454454 return (KEY_DIRTY(l) == KEY_DIRTY(r) &&
455455 KEY_PTRS(l) == KEY_PTRS(r) &&
456− KEY_CSUM(l) == KEY_CSUM(l));
456+ KEY_CSUM(l) == KEY_CSUM(r));
457457 }
458458
459459 /* Keylists */
drivers/md/bcache/btree.c+31−19
@@ -117,9 +117,9 @@ · 116 unmodified lines
117117 ({ \
118118 int _r, l = (b)->level - 1; \
119119 bool _w = l <= (op)->lock; \
120− struct btree *_child = bch_btree_node_get((b)->c, op, key, l, _w);\
120+ struct btree *_child = bch_btree_node_get((b)->c, op, key, l, \
121+ _w, b); \
121122 if (!IS_ERR(_child)) { \
122− _child->parent = (b); \
123123 _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__); \
124124 rw_unlock(_w, _child); \
125125 } else \
@@ -142,7 +142,6 @@ · 16 unmodified lines
142142 rw_lock(_w, _b, _b->level); \
143143 if (_b == (c)->root && \
144144 _w == insert_lock(op, _b)) { \
145− _b->parent = NULL; \
146145 _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__); \
147146 } \
148147 rw_unlock(_w, _b); \
@@ -202,7 +201,7 @@ void bch_btree_node_read_done(struct btree *b) · 53 unmodified lines
202201 struct bset *i = btree_bset_first(b);
203202 struct btree_iter *iter;
204203
205− iter = mempool_alloc(b->c->fill_iter, GFP_NOWAIT);
204+ iter = mempool_alloc(b->c->fill_iter, GFP_NOIO);
206205 iter->size = b->c->sb.bucket_size / b->c->sb.block_size;
207206 iter->used = 0;
208207
@@ -421,7 +420,7 @@ static void do_btree_node_write(struct btree *b) · 212 unmodified lines
421420 SET_PTR_OFFSET(&k.key, 0, PTR_OFFSET(&k.key, 0) +
422421 bset_sector_offset(&b->keys, i));
423422
424− if (!bio_alloc_pages(b->bio, GFP_NOIO)) {
423+ if (!bio_alloc_pages(b->bio, __GFP_NOWARN|GFP_NOWAIT)) {
425424 int j;
426425 struct bio_vec *bv;
427426 void *base = (void *) ((unsigned long) i & ~(PAGE_SIZE - 1));
@@ -967,7 +966,8 @@ err: · 539 unmodified lines
967966 * level and op->lock.
968967 */
969968 struct btree *bch_btree_node_get(struct cache_set *c, struct btree_op *op,
970− struct bkey *k, int level, bool write)
969+ struct bkey *k, int level, bool write,
970+ struct btree *parent)
971971 {
972972 int i = 0;
973973 struct btree *b;
@@ -1002,6 +1002,7 @@ retry: · 28 unmodified lines
10021002 BUG_ON(b->level != level);
10031003 }
10041004
1005+ b->parent = parent;
10051006 b->accessed = 1;
10061007
10071008 for (; i <= b->keys.nsets && b->keys.set[i].size; i++) {
@@ -1022,15 +1023,16 @@ retry: · 14 unmodified lines
10221023 return b;
10231024 }
10241025
1025−static void btree_node_prefetch(struct cache_set *c, struct bkey *k, int level)
1026+static void btree_node_prefetch(struct btree *parent, struct bkey *k)
10261027 {
10271028 struct btree *b;
10281029
1029− mutex_lock(&c->bucket_lock);
1030− b = mca_alloc(c, NULL, k, level);
1031− mutex_unlock(&c->bucket_lock);
1030+ mutex_lock(&parent->c->bucket_lock);
1031+ b = mca_alloc(parent->c, NULL, k, parent->level - 1);
1032+ mutex_unlock(&parent->c->bucket_lock);
10321033
10331034 if (!IS_ERR_OR_NULL(b)) {
1035+ b->parent = parent;
10341036 bch_btree_node_read(b);
10351037 rw_unlock(true, b);
10361038 }
@@ -1060,15 +1062,16 @@ static void btree_node_free(struct btree *b) · 23 unmodified lines
10601062 mutex_unlock(&b->c->bucket_lock);
10611063 }
10621064
1063−struct btree *bch_btree_node_alloc(struct cache_set *c, struct btree_op *op,
1064− int level)
1065+struct btree *__bch_btree_node_alloc(struct cache_set *c, struct btree_op *op,
1066+ int level, bool wait,
1067+ struct btree *parent)
10651068 {
10661069 BKEY_PADDED(key) k;
10671070 struct btree *b = ERR_PTR(-EAGAIN);
10681071
10691072 mutex_lock(&c->bucket_lock);
10701073 retry:
1071− if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, op != NULL))
1074+ if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, wait))
10721075 goto err;
10731076
10741077 bkey_put(c, &k.key);
@@ -1085,6 +1088,7 @@ retry: · 10 unmodified lines
10851088 }
10861089
10871090 b->accessed = 1;
1091+ b->parent = parent;
10881092 bch_bset_init_next(&b->keys, b->keys.set->data, bset_magic(&b->c->sb));
10891093
10901094 mutex_unlock(&c->bucket_lock);
@@ -1096,14 +1100,21 @@ err_free: · 5 unmodified lines
10961100 err:
10971101 mutex_unlock(&c->bucket_lock);
10981102
1099− trace_bcache_btree_node_alloc_fail(b);
1103+ trace_bcache_btree_node_alloc_fail(c);
11001104 return b;
11011105 }
11021106
1107+static struct btree *bch_btree_node_alloc(struct cache_set *c,
1108+ struct btree_op *op, int level,
1109+ struct btree *parent)
1110+{
1111+ return __bch_btree_node_alloc(c, op, level, op != NULL, parent);
1112+}
1113+
11031114 static struct btree *btree_node_alloc_replacement(struct btree *b,
11041115 struct btree_op *op)
11051116 {
1106− struct btree *n = bch_btree_node_alloc(b->c, op, b->level);
1117+ struct btree *n = bch_btree_node_alloc(b->c, op, b->level, b->parent);
11071118 if (!IS_ERR_OR_NULL(n)) {
11081119 mutex_lock(&n->write_lock);
11091120 bch_btree_sort_into(&b->keys, &n->keys, &b->c->sort);
@@ -1403,6 +1414,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, · 293 unmodified lines
14031414 BUG_ON(btree_bset_first(new_nodes[0])->keys);
14041415 btree_node_free(new_nodes[0]);
14051416 rw_unlock(true, new_nodes[0]);
1417+ new_nodes[0] = NULL;
14061418
14071419 for (i = 0; i < nodes; i++) {
14081420 if (__bch_keylist_realloc(&keylist, bkey_u64s(&r[i].b->key)))
@@ -1516,7 +1528,7 @@ static int btree_gc_recurse(struct btree *b, struct btree_op *op, · 107 unmodified lines
15161528 k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad);
15171529 if (k) {
15181530 r->b = bch_btree_node_get(b->c, op, k, b->level - 1,
1519− true);
1531+ true, b);
15201532 if (IS_ERR(r->b)) {
15211533 ret = PTR_ERR(r->b);
15221534 break;
@@ -1811,7 +1823,7 @@ static int bch_btree_check_recurse(struct btree *b, struct btree_op *op) · 288 unmodified lines
18111823 k = bch_btree_iter_next_filter(&iter, &b->keys,
18121824 bch_ptr_bad);
18131825 if (k)
1814− btree_node_prefetch(b->c, k, b->level - 1);
1826+ btree_node_prefetch(b, k);
18151827
18161828 if (p)
18171829 ret = btree(check_recurse, p, b, op);
@@ -1976,12 +1988,12 @@ static int btree_split(struct btree *b, struct btree_op *op, · 158 unmodified lines
19761988
19771989 trace_bcache_btree_node_split(b, btree_bset_first(n1)->keys);
19781990
1979− n2 = bch_btree_node_alloc(b->c, op, b->level);
1991+ n2 = bch_btree_node_alloc(b->c, op, b->level, b->parent);
19801992 if (IS_ERR(n2))
19811993 goto err_free1;
19821994
19831995 if (!b->parent) {
1984− n3 = bch_btree_node_alloc(b->c, op, b->level + 1);
1996+ n3 = bch_btree_node_alloc(b->c, op, b->level + 1, NULL);
19851997 if (IS_ERR(n3))
19861998 goto err_free2;
19871999 }
drivers/md/bcache/btree.h+3−2
@@ -242,9 +242,10 @@ void __bch_btree_node_write(struct btree *, struct closure *); · 241 unmodified lines
242242 void bch_btree_node_write(struct btree *, struct closure *);
243243
244244 void bch_btree_set_root(struct btree *);
245−struct btree *bch_btree_node_alloc(struct cache_set *, struct btree_op *, int);
245+struct btree *__bch_btree_node_alloc(struct cache_set *, struct btree_op *,
246+ int, bool, struct btree *);
246247 struct btree *bch_btree_node_get(struct cache_set *, struct btree_op *,
247− struct bkey *, int, bool);
248+ struct bkey *, int, bool, struct btree *);
248249
249250 int bch_btree_insert_check_key(struct btree *, struct btree_op *,
250251 struct bkey *);
drivers/md/bcache/extents.c+9−4
@@ -474,9 +474,8 @@ out: · 473 unmodified lines
474474 return false;
475475 }
476476
477−static bool bch_extent_invalid(struct btree_keys *bk, const struct bkey *k)
477+bool __bch_extent_invalid(struct cache_set *c, const struct bkey *k)
478478 {
479− struct btree *b = container_of(bk, struct btree, keys);
480479 char buf[80];
481480
482481 if (!KEY_SIZE(k))
@@ -485,16 +484,22 @@ static bool bch_extent_invalid(struct btree_keys *bk, const struct bkey *k) · 2 unmodified lines
485484 if (KEY_SIZE(k) > KEY_OFFSET(k))
486485 goto bad;
487486
488− if (__ptr_invalid(b->c, k))
487+ if (__ptr_invalid(c, k))
489488 goto bad;
490489
491490 return false;
492491 bad:
493492 bch_extent_to_text(buf, sizeof(buf), k);
494− cache_bug(b->c, "spotted extent %s: %s", buf, bch_ptr_status(b->c, k));
493+ cache_bug(c, "spotted extent %s: %s", buf, bch_ptr_status(c, k));
495494 return true;
496495 }
497496
497+static bool bch_extent_invalid(struct btree_keys *bk, const struct bkey *k)
498+{
499+ struct btree *b = container_of(bk, struct btree, keys);
500+ return __bch_extent_invalid(b->c, k);
501+}
502+
498503 static bool bch_extent_bad_expensive(struct btree *b, const struct bkey *k,
499504 unsigned ptr)
500505 {
drivers/md/bcache/extents.h+1−0
@@ -9,5 +9,6 @@ struct cache_set; · 8 unmodified lines
99
1010 void bch_extent_to_text(char *, size_t, const struct bkey *);
1111 bool __bch_btree_ptr_invalid(struct cache_set *, const struct bkey *);
12+bool __bch_extent_invalid(struct cache_set *, const struct bkey *);
1213
1314 #endif /* _BCACHE_EXTENTS_H */
drivers/md/bcache/journal.c+15−9
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 #include "bcache.h"
88 #include "btree.h"
99 #include "debug.h"
10+#include "extents.h"
1011
1112 #include <trace/events/bcache.h>
1213
@@ -189,11 +190,15 @@ int bch_journal_read(struct cache_set *c, struct list_head *list) · 176 unmodified lines
189190 if (read_bucket(l))
190191 goto bsearch;
191192
192− if (list_empty(list))
193+ /* no journal entries on this device? */
194+ if (l == ca->sb.njournal_buckets)
193195 continue;
194196 bsearch:
197+ BUG_ON(list_empty(list));
198+
195199 /* Binary search */
196− m = r = find_next_bit(bitmap, ca->sb.njournal_buckets, l + 1);
200+ m = l;
201+ r = find_next_bit(bitmap, ca->sb.njournal_buckets, l + 1);
197202 pr_debug("starting binary search, l %u r %u", l, r);
198203
199204 while (l + 1 < r) {
@@ -291,15 +296,16 @@ void bch_journal_mark(struct cache_set *c, struct list_head *list) · 91 unmodified lines
291296
292297 for (k = i->j.start;
293298 k < bset_bkey_last(&i->j);
294− k = bkey_next(k)) {
295− unsigned j;
299+ k = bkey_next(k))
300+ if (!__bch_extent_invalid(c, k)) {
301+ unsigned j;
296302
297− for (j = 0; j < KEY_PTRS(k); j++)
298− if (ptr_available(c, k, j))
299− atomic_inc(&PTR_BUCKET(c, k, j)->pin);
303+ for (j = 0; j < KEY_PTRS(k); j++)
304+ if (ptr_available(c, k, j))
305+ atomic_inc(&PTR_BUCKET(c, k, j)->pin);
300306
301− bch_initial_mark_key(c, 0, k);
302− }
307+ bch_initial_mark_key(c, 0, k);
308+ }
303309 }
304310 }
305311
drivers/md/bcache/request.c+2−1
@@ -311,7 +311,8 @@ void bch_data_insert(struct closure *cl) · 310 unmodified lines
311311 {
312312 struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
313313
314− trace_bcache_write(op->bio, op->writeback, op->bypass);
314+ trace_bcache_write(op->c, op->inode, op->bio,
315+ op->writeback, op->bypass);
315316
316317 bch_keylist_init(&op->insert_keys);
317318 bio_get(op->bio);
drivers/md/bcache/super.c+37−20
@@ -733,8 +733,6 @@ static void bcache_device_detach(struct bcache_device *d) · 732 unmodified lines
733733 static void bcache_device_attach(struct bcache_device *d, struct cache_set *c,
734734 unsigned id)
735735 {
736− BUG_ON(test_bit(CACHE_SET_STOPPING, &c->flags));
737−
738736 d->id = id;
739737 d->c = c;
740738 c->devices[id] = d;
@@ -927,6 +925,7 @@ static void cached_dev_detach_finish(struct work_struct *w) · 186 unmodified lines
927925 list_move(&dc->list, &uncached_devices);
928926
929927 clear_bit(BCACHE_DEV_DETACHING, &dc->disk.flags);
928+ clear_bit(BCACHE_DEV_UNLINK_DONE, &dc->disk.flags);
930929
931930 mutex_unlock(&bch_register_lock);
932931
@@ -1041,6 +1040,9 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c) · 108 unmodified lines
10411040 */
10421041 atomic_set(&dc->count, 1);
10431042
1043+ if (bch_cached_dev_writeback_start(dc))
1044+ return -ENOMEM;
1045+
10441046 if (BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY) {
10451047 bch_sectors_dirty_init(dc);
10461048 atomic_set(&dc->has_dirty, 1);
@@ -1070,7 +1072,8 @@ static void cached_dev_free(struct closure *cl) · 23 unmodified lines
10701072 struct cached_dev *dc = container_of(cl, struct cached_dev, disk.cl);
10711073
10721074 cancel_delayed_work_sync(&dc->writeback_rate_update);
1073− kthread_stop(dc->writeback_thread);
1075+ if (!IS_ERR_OR_NULL(dc->writeback_thread))
1076+ kthread_stop(dc->writeback_thread);
10741077
10751078 mutex_lock(&bch_register_lock);
10761079
@@ -1081,12 +1084,8 @@ static void cached_dev_free(struct closure *cl) · 4 unmodified lines
10811084
10821085 mutex_unlock(&bch_register_lock);
10831086
1084− if (!IS_ERR_OR_NULL(dc->bdev)) {
1085− if (dc->bdev->bd_disk)
1086− blk_sync_queue(bdev_get_queue(dc->bdev));
1087−
1087+ if (!IS_ERR_OR_NULL(dc->bdev))
10881088 blkdev_put(dc->bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1089− }
10901089
10911090 wake_up(&unregister_wait);
10921091
@@ -1213,7 +1212,9 @@ void bch_flash_dev_release(struct kobject *kobj) · 120 unmodified lines
12131212 static void flash_dev_free(struct closure *cl)
12141213 {
12151214 struct bcache_device *d = container_of(cl, struct bcache_device, cl);
1215+ mutex_lock(&bch_register_lock);
12161216 bcache_device_free(d);
1217+ mutex_unlock(&bch_register_lock);
12171218 kobject_put(&d->kobj);
12181219 }
12191220
@@ -1221,7 +1222,9 @@ static void flash_dev_flush(struct closure *cl) · 1 unmodified line
12211222 {
12221223 struct bcache_device *d = container_of(cl, struct bcache_device, cl);
12231224
1225+ mutex_lock(&bch_register_lock);
12241226 bcache_device_unlink(d);
1227+ mutex_unlock(&bch_register_lock);
12251228 kobject_del(&d->kobj);
12261229 continue_at(cl, flash_dev_free, system_wq);
12271230 }
@@ -1277,6 +1280,9 @@ int bch_flash_dev_create(struct cache_set *c, uint64_t size) · 49 unmodified lines
12771280 if (test_bit(CACHE_SET_STOPPING, &c->flags))
12781281 return -EINTR;
12791282
1283+ if (!test_bit(CACHE_SET_RUNNING, &c->flags))
1284+ return -EPERM;
1285+
12801286 u = uuid_find_empty(c);
12811287 if (!u) {
12821288 pr_err("Can't create volume, no room for UUID");
@@ -1346,8 +1352,11 @@ static void cache_set_free(struct closure *cl) · 63 unmodified lines
13461352 bch_journal_free(c);
13471353
13481354 for_each_cache(ca, c, i)
1349− if (ca)
1355+ if (ca) {
1356+ ca->set = NULL;
1357+ c->cache[ca->sb.nr_this_dev] = NULL;
13501358 kobject_put(&ca->kobj);
1359+ }
13511360
13521361 bch_bset_sort_state_free(&c->sort);
13531362 free_pages((unsigned long) c->uuids, ilog2(bucket_pages(c)));
@@ -1405,9 +1414,11 @@ static void cache_set_flush(struct closure *cl) · 51 unmodified lines
14051414 if (ca->alloc_thread)
14061415 kthread_stop(ca->alloc_thread);
14071416
1408− cancel_delayed_work_sync(&c->journal.work);
1409− /* flush last journal entry if needed */
1410− c->journal.work.work.func(&c->journal.work.work);
1417+ if (c->journal.cur) {
1418+ cancel_delayed_work_sync(&c->journal.work);
1419+ /* flush last journal entry if needed */
1420+ c->journal.work.work.func(&c->journal.work.work);
1421+ }
14111422
14121423 closure_return(cl);
14131424 }
@@ -1586,7 +1597,7 @@ static void run_cache_set(struct cache_set *c) · 172 unmodified lines
15861597 goto err;
15871598
15881599 err = "error reading btree root";
1589− c->root = bch_btree_node_get(c, NULL, k, j->btree_level, true);
1600+ c->root = bch_btree_node_get(c, NULL, k, j->btree_level, true, NULL);
15901601 if (IS_ERR_OR_NULL(c->root))
15911602 goto err;
15921603
@@ -1661,7 +1672,7 @@ static void run_cache_set(struct cache_set *c) · 68 unmodified lines
16611672 goto err;
16621673
16631674 err = "cannot allocate new btree root";
1664− c->root = bch_btree_node_alloc(c, NULL, 0);
1675+ c->root = __bch_btree_node_alloc(c, NULL, 0, true, NULL);
16651676 if (IS_ERR_OR_NULL(c->root))
16661677 goto err;
16671678
@@ -1697,6 +1708,7 @@ static void run_cache_set(struct cache_set *c) · 29 unmodified lines
16971708
16981709 flash_devs_run(c);
16991710
1711+ set_bit(CACHE_SET_RUNNING, &c->flags);
17001712 return;
17011713 err:
17021714 closure_sync(&cl);
@@ -1760,6 +1772,7 @@ found: · 57 unmodified lines
17601772 pr_debug("set version = %llu", c->sb.version);
17611773 }
17621774
1775+ kobject_get(&ca->kobj);
17631776 ca->set = c;
17641777 ca->set->cache[ca->sb.nr_this_dev] = ca;
17651778 c->cache_by_alloc[c->caches_loaded++] = ca;
@@ -1780,8 +1793,10 @@ void bch_cache_release(struct kobject *kobj) · 14 unmodified lines
17801793 struct cache *ca = container_of(kobj, struct cache, kobj);
17811794 unsigned i;
17821795
1783− if (ca->set)
1796+ if (ca->set) {
1797+ BUG_ON(ca->set->cache[ca->sb.nr_this_dev] != ca);
17841798 ca->set->cache[ca->sb.nr_this_dev] = NULL;
1799+ }
17851800
17861801 bio_split_pool_free(&ca->bio_split_hook);
17871802
@@ -1798,10 +1813,8 @@ void bch_cache_release(struct kobject *kobj) · 10 unmodified lines
17981813 if (ca->sb_bio.bi_inline_vecs[0].bv_page)
17991814 put_page(ca->sb_bio.bi_io_vec[0].bv_page);
18001815
1801− if (!IS_ERR_OR_NULL(ca->bdev)) {
1802− blk_sync_queue(bdev_get_queue(ca->bdev));
1816+ if (!IS_ERR_OR_NULL(ca->bdev))
18031817 blkdev_put(ca->bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1804− }
18051818
18061819 kfree(ca);
18071820 module_put(THIS_MODULE);
@@ -1844,7 +1857,7 @@ static int cache_alloc(struct cache_sb *sb, struct cache *ca) · 36 unmodified lines
18441857 }
18451858
18461859 static void register_cache(struct cache_sb *sb, struct page *sb_page,
1847− struct block_device *bdev, struct cache *ca)
1860+ struct block_device *bdev, struct cache *ca)
18481861 {
18491862 char name[BDEVNAME_SIZE];
18501863 const char *err = "cannot allocate memory";
@@ -1877,10 +1890,12 @@ static void register_cache(struct cache_sb *sb, struct page *sb_page, · 26 unmodified lines
18771890 goto err;
18781891
18791892 pr_info("registered cache device %s", bdevname(bdev, name));
1893+out:
1894+ kobject_put(&ca->kobj);
18801895 return;
18811896 err:
18821897 pr_notice("error opening %s: %s", bdevname(bdev, name), err);
1883− kobject_put(&ca->kobj);
1898+ goto out;
18841899 }
18851900
18861901 /* Global interfaces/init */
@@ -1945,10 +1960,12 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 58 unmodified lines
19451960 if (IS_ERR(bdev)) {
19461961 if (bdev == ERR_PTR(-EBUSY)) {
19471962 bdev = lookup_bdev(strim(path));
1963+ mutex_lock(&bch_register_lock);
19481964 if (!IS_ERR(bdev) && bch_is_open(bdev))
19491965 err = "device already registered";
19501966 else
19511967 err = "device busy";
1968+ mutex_unlock(&bch_register_lock);
19521969 }
19531970 goto err;
19541971 }
drivers/md/bcache/util.h+2−2
@@ -416,8 +416,8 @@ do { \ · 415 unmodified lines
416416 average_frequency, frequency_units); \
417417 __print_time_stat(stats, name, \
418418 average_duration, duration_units); \
419− __print_time_stat(stats, name, \
420− max_duration, duration_units); \
419+ sysfs_print(name ## _ ##max_duration ## _ ## duration_units, \
420+ div_u64((stats)->max_duration, NSEC_PER_ ## duration_units));\
421421 \
422422 sysfs_print(name ## _last_ ## frequency_units, (stats)->last \
423423 ? div_s64(local_clock() - (stats)->last, \
drivers/md/bcache/writeback.c+10−4
@@ -239,7 +239,7 @@ static void read_dirty(struct cached_dev *dc) · 238 unmodified lines
239239 if (KEY_START(&w->key) != dc->last_read ||
240240 jiffies_to_msecs(delay) > 50)
241241 while (!kthread_should_stop() && delay)
242− delay = schedule_timeout_uninterruptible(delay);
242+ delay = schedule_timeout_interruptible(delay);
243243
244244 dc->last_read = KEY_OFFSET(&w->key);
245245
@@ -436,7 +436,7 @@ static int bch_writeback_thread(void *arg) · 190 unmodified lines
436436 while (delay &&
437437 !kthread_should_stop() &&
438438 !test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags))
439− delay = schedule_timeout_uninterruptible(delay);
439+ delay = schedule_timeout_interruptible(delay);
440440 }
441441 }
442442
@@ -478,7 +478,7 @@ void bch_sectors_dirty_init(struct cached_dev *dc) · 35 unmodified lines
478478 dc->disk.sectors_dirty_last = bcache_dev_sectors_dirty(&dc->disk);
479479 }
480480
481−int bch_cached_dev_writeback_init(struct cached_dev *dc)
481+void bch_cached_dev_writeback_init(struct cached_dev *dc)
482482 {
483483 sema_init(&dc->in_flight, 64);
484484 init_rwsem(&dc->writeback_lock);
@@ -494,14 +494,20 @@ int bch_cached_dev_writeback_init(struct cached_dev *dc) · 9 unmodified lines
494494 dc->writeback_rate_d_term = 30;
495495 dc->writeback_rate_p_term_inverse = 6000;
496496
497+ INIT_DELAYED_WORK(&dc->writeback_rate_update, update_writeback_rate);
498+}
499+
500+int bch_cached_dev_writeback_start(struct cached_dev *dc)
501+{
497502 dc->writeback_thread = kthread_create(bch_writeback_thread, dc,
498503 "bcache_writeback");
499504 if (IS_ERR(dc->writeback_thread))
500505 return PTR_ERR(dc->writeback_thread);
501506
502− INIT_DELAYED_WORK(&dc->writeback_rate_update, update_writeback_rate);
503507 schedule_delayed_work(&dc->writeback_rate_update,
504508 dc->writeback_rate_update_seconds * HZ);
505509
510+ bch_writeback_queue(dc);
511+
506512 return 0;
507513 }
drivers/md/bcache/writeback.h+2−1
@@ -85,6 +85,7 @@ static inline void bch_writeback_add(struct cached_dev *dc) · 84 unmodified lines
8585 void bcache_dev_sectors_dirty_add(struct cache_set *, unsigned, uint64_t, int);
8686
8787 void bch_sectors_dirty_init(struct cached_dev *dc);
88−int bch_cached_dev_writeback_init(struct cached_dev *);
88+void bch_cached_dev_writeback_init(struct cached_dev *);
89+int bch_cached_dev_writeback_start(struct cached_dev *);
8990
9091 #endif
include/linux/drbd.h+2−2
@@ -52,7 +52,7 @@ · 51 unmodified lines
5252 #endif
5353
5454 extern const char *drbd_buildtag(void);
55−#define REL_VERSION "8.4.3"
55+#define REL_VERSION "8.4.5"
5656 #define API_VERSION 1
5757 #define PRO_VERSION_MIN 86
5858 #define PRO_VERSION_MAX 101
@@ -245,7 +245,7 @@ enum drbd_disk_state { · 186 unmodified lines
245245 D_DISKLESS,
246246 D_ATTACHING, /* In the process of reading the meta-data */
247247 D_FAILED, /* Becomes D_DISKLESS as soon as we told it the peer */
248− /* when >= D_FAILED it is legal to access mdev->bc */
248+ /* when >= D_FAILED it is legal to access mdev->ldev */
249249 D_NEGOTIATING, /* Late attaching state, we need to talk to the peer */
250250 D_INCONSISTENT,
251251 D_OUTDATED,
include/linux/drbd_genl.h+4−0
@@ -171,6 +171,10 @@ GENL_struct(DRBD_NLA_NET_CONF, 5, net_conf, · 170 unmodified lines
171171 __flg_field(28, DRBD_GENLA_F_MANDATORY | DRBD_F_INVARIANT, tentative)
172172 __flg_field_def(29, DRBD_GENLA_F_MANDATORY, use_rle, DRBD_USE_RLE_DEF)
173173 /* 9: __u32_field_def(30, DRBD_GENLA_F_MANDATORY, fencing_policy, DRBD_FENCING_DEF) */
174+ /* 9: __str_field_def(31, DRBD_GENLA_F_MANDATORY, name, SHARED_SECRET_MAX) */
175+ /* 9: __u32_field(32, DRBD_F_REQUIRED | DRBD_F_INVARIANT, peer_node_id) */
176+ __flg_field_def(33, 0 /* OPTIONAL */, csums_after_crash_only, DRBD_CSUMS_AFTER_CRASH_ONLY_DEF)
177+ __u32_field_def(34, 0 /* OPTIONAL */, sock_check_timeo, DRBD_SOCKET_CHECK_TIMEO_DEF)
174178 )
175179
176180 GENL_struct(DRBD_NLA_SET_ROLE_PARMS, 6, set_role_parms,
include/linux/drbd_limits.h+6−0
@@ -214,6 +214,7 @@ · 213 unmodified lines
214214 #define DRBD_ALLOW_TWO_PRIMARIES_DEF 0
215215 #define DRBD_ALWAYS_ASBP_DEF 0
216216 #define DRBD_USE_RLE_DEF 1
217+#define DRBD_CSUMS_AFTER_CRASH_ONLY_DEF 0
217218
218219 #define DRBD_AL_STRIPES_MIN 1
219220 #define DRBD_AL_STRIPES_MAX 1024
@@ -224,4 +225,9 @@ · 4 unmodified lines
224225 #define DRBD_AL_STRIPE_SIZE_MAX 16777216
225226 #define DRBD_AL_STRIPE_SIZE_DEF 32
226227 #define DRBD_AL_STRIPE_SIZE_SCALE 'k' /* kilobytes */
228+
229+#define DRBD_SOCKET_CHECK_TIMEO_MIN 0
230+#define DRBD_SOCKET_CHECK_TIMEO_MAX DRBD_PING_TIMEO_MAX
231+#define DRBD_SOCKET_CHECK_TIMEO_DEF 0
232+#define DRBD_SOCKET_CHECK_TIMEO_SCALE '1'
227233 #endif
include/scsi/sg.h+3−1
@@ -86,7 +86,9 @@ typedef struct sg_io_hdr · 85 unmodified lines
8686 #define SG_FLAG_MMAP_IO 4 /* request memory mapped IO */
8787 #define SG_FLAG_NO_DXFER 0x10000 /* no transfer of kernel buffers to/from */
8888 /* user space (debug indirect IO) */
89−#define SG_FLAG_Q_AT_TAIL 0x10 /* default is Q_AT_HEAD */
89+/* defaults:: for sg driver: Q_AT_HEAD; for block layer: Q_AT_TAIL */
90+#define SG_FLAG_Q_AT_TAIL 0x10
91+#define SG_FLAG_Q_AT_HEAD 0x20
9092
9193 /* following 'info' values are "or"-ed together */
9294 #define SG_INFO_OK_MASK 0x1
include/trace/events/bcache.h+12−9
@@ -148,11 +148,13 @@ TRACE_EVENT(bcache_read, · 147 unmodified lines
148148 );
149149
150150 TRACE_EVENT(bcache_write,
151− TP_PROTO(struct bio *bio, bool writeback, bool bypass),
152− TP_ARGS(bio, writeback, bypass),
151+ TP_PROTO(struct cache_set *c, u64 inode, struct bio *bio,
152+ bool writeback, bool bypass),
153+ TP_ARGS(c, inode, bio, writeback, bypass),
153154
154155 TP_STRUCT__entry(
155− __field(dev_t, dev )
156+ __array(char, uuid, 16 )
157+ __field(u64, inode )
156158 __field(sector_t, sector )
157159 __field(unsigned int, nr_sector )
158160 __array(char, rwbs, 6 )
@@ -161,7 +163,8 @@ TRACE_EVENT(bcache_write, · 2 unmodified lines
161163 ),
162164
163165 TP_fast_assign(
164− __entry->dev = bio->bi_bdev->bd_dev;
166+ memcpy(__entry->uuid, c->sb.set_uuid, 16);
167+ __entry->inode = inode;
165168 __entry->sector = bio->bi_iter.bi_sector;
166169 __entry->nr_sector = bio->bi_iter.bi_size >> 9;
167170 blk_fill_rwbs(__entry->rwbs, bio->bi_rw, bio->bi_iter.bi_size);
@@ -169,8 +172,8 @@ TRACE_EVENT(bcache_write, · 1 unmodified line
169172 __entry->bypass = bypass;
170173 ),
171174
172− TP_printk("%d,%d %s %llu + %u hit %u bypass %u",
173− MAJOR(__entry->dev), MINOR(__entry->dev),
175+ TP_printk("%pU inode %llu %s %llu + %u hit %u bypass %u",
176+ __entry->uuid, __entry->inode,
174177 __entry->rwbs, (unsigned long long)__entry->sector,
175178 __entry->nr_sector, __entry->writeback, __entry->bypass)
176179 );
@@ -258,9 +261,9 @@ DEFINE_EVENT(btree_node, bcache_btree_node_alloc, · 81 unmodified lines
258261 TP_ARGS(b)
259262 );
260263
261−DEFINE_EVENT(btree_node, bcache_btree_node_alloc_fail,
262− TP_PROTO(struct btree *b),
263− TP_ARGS(b)
264+DEFINE_EVENT(cache_set, bcache_btree_node_alloc_fail,
265+ TP_PROTO(struct cache_set *c),
266+ TP_ARGS(c)
264267 );
265268
266269 DEFINE_EVENT(btree_node, bcache_btree_node_free,
include/uapi/linux/bsg.h+6−5
@@ -10,12 +10,13 @@ · 9 unmodified lines
1010 #define BSG_SUB_PROTOCOL_SCSI_TRANSPORT 2
1111
1212 /*
13− * For flags member below
14− * sg.h sg_io_hdr also has bits defined for it's flags member. However
15− * none of these bits are implemented/used by bsg. The bits below are
16− * allocated to not conflict with sg.h ones anyway.
13+ * For flag constants below:
14+ * sg.h sg_io_hdr also has bits defined for it's flags member. These
15+ * two flag values (0x10 and 0x20) have the same meaning in sg.h . For
16+ * bsg the BSG_FLAG_Q_AT_HEAD flag is ignored since it is the deafult.
1717 */
18−#define BSG_FLAG_Q_AT_TAIL 0x10 /* default, == 0 at this bit, is Q_AT_HEAD */
18+#define BSG_FLAG_Q_AT_TAIL 0x10 /* default is Q_AT_HEAD */
19+#define BSG_FLAG_Q_AT_HEAD 0x20
1920
2021 struct sg_io_v4 {
2122 __s32 guard; /* [i] 'Q' to differentiate from v3 */
include/uapi/linux/virtio_blk.h+5−0
@@ -40,6 +40,7 @@ · 39 unmodified lines
4040 #define VIRTIO_BLK_F_WCE 9 /* Writeback mode enabled after reset */
4141 #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
4242 #define VIRTIO_BLK_F_CONFIG_WCE 11 /* Writeback mode available in config */
43+#define VIRTIO_BLK_F_MQ 12 /* support more than one vq */
4344
4445 #ifndef __KERNEL__
4546 /* Old (deprecated) name for VIRTIO_BLK_F_WCE. */
@@ -77,6 +78,10 @@ struct virtio_blk_config { · 31 unmodified lines
7778
7879 /* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */
7980 __u8 wce;
81+ __u8 unused;
82+
83+ /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */
84+ __u16 num_queues;
8085 } __attribute__((packed));
8186
8287 /*
lib/lru_cache.c+13−10
@@ -169,7 +169,7 @@ out_fail: · 168 unmodified lines
169169 return NULL;
170170 }
171171
172−void lc_free_by_index(struct lru_cache *lc, unsigned i)
172+static void lc_free_by_index(struct lru_cache *lc, unsigned i)
173173 {
174174 void *p = lc->lc_element[i];
175175 WARN_ON(!p);
@@ -643,9 +643,10 @@ void lc_set(struct lru_cache *lc, unsigned int enr, int index) · 467 unmodified lines
643643 * lc_dump - Dump a complete LRU cache to seq in textual form.
644644 * @lc: the lru cache to operate on
645645 * @seq: the &struct seq_file pointer to seq_printf into
646− * @utext: user supplied "heading" or other info
646+ * @utext: user supplied additional "heading" or other info
647647 * @detail: function pointer the user may provide to dump further details
648− * of the object the lc_element is embedded in.
648+ * of the object the lc_element is embedded in. May be NULL.
649+ * Note: a leading space ' ' and trailing newline '\n' is implied.
649650 */
650651 void lc_seq_dump_details(struct seq_file *seq, struct lru_cache *lc, char *utext,
651652 void (*detail) (struct seq_file *, struct lc_element *))
@@ -654,16 +655,18 @@ void lc_seq_dump_details(struct seq_file *seq, struct lru_cache *lc, char *utext · 2 unmodified lines
654655 struct lc_element *e;
655656 int i;
656657
657− seq_printf(seq, "\tnn: lc_number refcnt %s\n ", utext);
658+ seq_printf(seq, "\tnn: lc_number (new nr) refcnt %s\n ", utext);
658659 for (i = 0; i < nr_elements; i++) {
659660 e = lc_element_by_index(lc, i);
660− if (e->lc_number == LC_FREE) {
661− seq_printf(seq, "\t%2d: FREE\n", i);
662− } else {
663− seq_printf(seq, "\t%2d: %4u %4u ", i,
664− e->lc_number, e->refcnt);
661+ if (e->lc_number != e->lc_new_number)
662+ seq_printf(seq, "\t%5d: %6d %8d %6d ",
663+ i, e->lc_number, e->lc_new_number, e->refcnt);
664+ else
665+ seq_printf(seq, "\t%5d: %6d %-8s %6d ",
666+ i, e->lc_number, "-\"-", e->refcnt);
667+ if (detail)
665668 detail(seq, e);
666− }
669+ seq_putc(seq, '\n');
667670 }
668671 }
669672