From d207450cf2731c6a2afa8c78fb31c7206cd35eba Mon Sep 17 00:00:00 2001
From: Philipp Reisner <philipp.reisner@linbit.com>
Date: Thu, 22 Jul 2010 15:27:27 +0200
Subject: [PATCH] drbd: Bugfix: rs_in_flight could become wrong if
 read_for_csum() requested reschedule later

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
---
 drivers/block/drbd/drbd_worker.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
index fd3e1e9561cb..30b8e466a224 100644
--- a/drivers/block/drbd/drbd_worker.c
+++ b/drivers/block/drbd/drbd_worker.c
@@ -512,7 +512,7 @@ int w_make_resync_request(struct drbd_conf *mdev,
 	sector_t sector;
 	const sector_t capacity = drbd_get_capacity(mdev->this_bdev);
 	int max_segment_size;
-	int number, i, size, pe, mx;
+	int number, i, rollback_i, size, pe, mx;
 	int align, queued, sndbuf;
 
 	if (unlikely(cancel))
@@ -613,6 +613,7 @@ int w_make_resync_request(struct drbd_conf *mdev,
 		 * be prepared for all stripe sizes of software RAIDs.
 		 */
 		align = 1;
+		rollback_i = i;
 		for (;;) {
 			if (size + BM_BLOCK_SIZE > max_segment_size)
 				break;
@@ -654,6 +655,7 @@ int w_make_resync_request(struct drbd_conf *mdev,
 			case 2: /* Allocation failed */
 				drbd_rs_complete_io(mdev, sector);
 				mdev->bm_resync_fo = BM_SECT_TO_BIT(sector);
+				i = rollback_i;
 				goto requeue;
 			/* case 1: everything ok */
 			}
-- 
GitLab