drbd: Work on the Ahead -> SyncSource transition
authorPhilipp Reisner <philipp.reisner@linbit.com>
Fri, 14 Jan 2011 15:03:11 +0000 (16:03 +0100)
committerPhilipp Reisner <philipp.reisner@linbit.com>
Thu, 10 Mar 2011 10:45:36 +0000 (11:45 +0100)
The test if rs_pending_cnt == 0 was too weak. Using Test for
unacked_cnt == 0 instead. Moved that into the worker.

Since unacked_cnt gets already increased when an P_RS_DATA_REQ
comes in.

Also using a timer to make Ahead -> SyncSource -> Ahead cycles
slower...

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
drivers/block/drbd/drbd_int.h
drivers/block/drbd/drbd_main.c
drivers/block/drbd/drbd_receiver.c
drivers/block/drbd/drbd_worker.c

index 3c8eecd9666d86dc43e8ec3ea41286299d817bd3..cfe7fff459e30e862231b248f36be97d71513a4f 100644 (file)
@@ -850,6 +850,7 @@ enum {
        GOT_PING_ACK,           /* set when we receive a ping_ack packet, misc wait gets woken */
        NEW_CUR_UUID,           /* Create new current UUID when thawing IO */
        AL_SUSPENDED,           /* Activity logging is currently suspended. */
+       AHEAD_TO_SYNC_SOURCE,   /* Ahead -> SyncSource queued */
 };
 
 struct drbd_bitmap; /* opaque for drbd_conf */
@@ -961,6 +962,7 @@ struct drbd_conf {
                          start_resync_work;
        struct timer_list resync_timer;
        struct timer_list md_sync_timer;
+       struct timer_list start_resync_timer;
 #ifdef DRBD_DEBUG_MD_SYNC
        struct {
                unsigned int line;
@@ -1544,6 +1546,7 @@ extern int w_send_oos(struct drbd_conf *, struct drbd_work *, int);
 extern int w_start_resync(struct drbd_conf *, struct drbd_work *, int);
 
 extern void resync_timer_fn(unsigned long data);
+extern void start_resync_timer_fn(unsigned long data);
 
 /* drbd_receiver.c */
 extern int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector);
index b3b6d3190f652f15b439ba7cda0551d8f1597192..8ec7c65988befd1c9dcfbe50a5c1a70559dc0d65 100644 (file)
@@ -2984,12 +2984,16 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
        mdev->go_diskless.cb  = w_go_diskless;
        mdev->md_sync_work.cb = w_md_sync;
        mdev->bm_io_work.w.cb = w_bitmap_io;
+       mdev->start_resync_work.cb = w_start_resync;
        init_timer(&mdev->resync_timer);
        init_timer(&mdev->md_sync_timer);
+       init_timer(&mdev->start_resync_timer);
        mdev->resync_timer.function = resync_timer_fn;
        mdev->resync_timer.data = (unsigned long) mdev;
        mdev->md_sync_timer.function = md_sync_timer_fn;
        mdev->md_sync_timer.data = (unsigned long) mdev;
+       mdev->start_resync_timer.function = start_resync_timer_fn;
+       mdev->start_resync_timer.data = (unsigned long) mdev;
 
        init_waitqueue_head(&mdev->misc_wait);
        init_waitqueue_head(&mdev->state_wait);
index 7991183749e382f8cafc4e8dcaa98d190b6359a2..18cb8b609fe4848d46adabdf6b3eb3b00fb8ae92 100644 (file)
@@ -4392,11 +4392,9 @@ static int got_BarrierAck(struct drbd_conf *mdev, struct p_header80 *h)
 
        if (mdev->state.conn == C_AHEAD &&
            atomic_read(&mdev->ap_in_flight) == 0 &&
-           atomic_read(&mdev->rs_pending_cnt) == 0 &&
-           list_empty(&mdev->start_resync_work.list)) {
-                   struct drbd_work *w = &mdev->start_resync_work;
-                   w->cb = w_start_resync;
-                   drbd_queue_work(&mdev->data.work, w);
+           !test_and_set_bit(AHEAD_TO_SYNC_SOURCE, &mdev->current_epoch->flags)) {
+               mdev->start_resync_timer.expires = jiffies + HZ;
+               add_timer(&mdev->start_resync_timer);
        }
 
        return true;
index 147f76b2681022173f59419ba480963cdcfc1256..3a95b701b5d09e2d5228fe6a671de590189b7a85 100644 (file)
@@ -712,10 +712,24 @@ static int w_make_ov_request(struct drbd_conf *mdev, struct drbd_work *w, int ca
 }
 
 
+void start_resync_timer_fn(unsigned long data)
+{
+       struct drbd_conf *mdev = (struct drbd_conf *) data;
+
+       drbd_queue_work(&mdev->data.work, &mdev->start_resync_work);
+}
+
 int w_start_resync(struct drbd_conf *mdev, struct drbd_work *w, int cancel)
 {
-       drbd_start_resync(mdev, C_SYNC_SOURCE);
+       if (atomic_read(&mdev->unacked_cnt) || atomic_read(&mdev->rs_pending_cnt)) {
+               dev_warn(DEV, "w_start_resync later...\n");
+               mdev->start_resync_timer.expires = jiffies + HZ/10;
+               add_timer(&mdev->start_resync_timer);
+               return 1;
+       }
 
+       drbd_start_resync(mdev, C_SYNC_SOURCE);
+       clear_bit(AHEAD_TO_SYNC_SOURCE, &mdev->current_epoch->flags);
        return 1;
 }