Skip to contentSkip to conversation

Btrfs: replace: cache rbio when rebuild data on missing device

PATCH In review Liu Bo 3 participants 5 messages Mar 3, 2018 – Mar 22, 2018 Btrfs file system

lore
Share & tools
lore

Liu Bo

author
#0 lore raw

PATCH 1/1 Btrfs: replace: cache rbio when rebuild data on missing device

Rebuild on missing device is as same as recover, after it's done, rbio has data which is consistent with on-disk data, so it can be cached to avoid further reads.

---
 fs/btrfs/raid56.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/raid56.c +2 -3
index dec0907..bb8a3c5 100644
@@ -1986,7 +1986,8 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
 	kfree(pointers);
 
 cleanup_io:
-	if (rbio->operation == BTRFS_RBIO_READ_REBUILD) {
+	if (rbio->operation == BTRFS_RBIO_READ_REBUILD ||
+	    rbio->operation == BTRFS_RBIO_REBUILD_MISSING) {
 		/*
 		 * - In case of two failures, where rbio->failb != -1:
 		 *
@@ -2008,8 +2009,6 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
 			clear_bit(RBIO_CACHE_READY_BIT, &rbio->flags);
 
 		rbio_orig_end_io(rbio, err);
-	} else if (rbio->operation == BTRFS_RBIO_REBUILD_MISSING) {
-		rbio_orig_end_io(rbio, err);
 	} else if (err == BLK_STS_OK) {
 		rbio->faila = -1;
 		rbio->failb = -1;
Signature · 1 line
2.9.4
#1 lore raw
Quoted 3 lines · Liu Bo

Rebuild on missing device is as same as recover, after it's done, rbio has data which is consistent with on-disk data, so it can be cached to avoid further reads.

Please add a comment that describes why the READ and REBUILD can be merged together, it's not obvious from the code.

author
#2 lore raw
Quoted 7 lines · David Sterba
Quoted 3 lines · Liu Bo

Rebuild on missing device is as same as recover, after it's done, rbio has data which is consistent with on-disk data, so it can be cached to avoid further reads.

Please add a comment that describes why the READ and REBUILD can be merged together, it's not obvious from the code.

Will update it.

Thanks,

-liubo

#3 lore raw

PATCH v2 1/1 Btrfs: replace: cache rbio when rebuild data on missing device

In reply to Liu Bo

Rebuild on missing device is as same as recover, after it's done, rbio has data which is consistent with on-disk data, so it can be cached to avoid further reads.

---
v2: Add comments to explain why REBUILD needs to be merged.

 fs/btrfs/raid56.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/btrfs/raid56.c +7 -3
index fcfc20de2df3..154318249265 100644
@@ -1987,7 +1987,13 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
 	kfree(pointers);
 
 cleanup_io:
-	if (rbio->operation == BTRFS_RBIO_READ_REBUILD) {
+	/*
+	 * Similar to READ_REBUILD, REBUILD_MISSING at this point also has a
+	 * valid rbio which is consistent with ondisk content, thus such a valid
+	 * rbio can be cached to avoid further disk reads.
+	 */
+	if (rbio->operation == BTRFS_RBIO_READ_REBUILD ||
+	    rbio->operation == BTRFS_RBIO_REBUILD_MISSING) {
 		/*
 		 * - In case of two failures, where rbio->failb != -1:
 		 *
@@ -2008,8 +2014,6 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
 		else
 			clear_bit(RBIO_CACHE_READY_BIT, &rbio->flags);
 
-		rbio_orig_end_io(rbio, err);
-	} else if (rbio->operation == BTRFS_RBIO_REBUILD_MISSING) {
 		rbio_orig_end_io(rbio, err);
 	} else if (err == BLK_STS_OK) {
 		rbio->faila = -1;
Signature · 1 line
2.14.1.40.g8e62ba1