Skip to contentSkip to conversation

btrfs: raid56: do blk_check_plugged check twice while writing

PATCH In review Yusuf Khan 2 participants 2 messages Mar 19, 2022 Btrfs file system

lore
Share & tools
lore

Yusuf Khan

author
#0 lore raw

PATCH 1/1 btrfs: raid56: do blk_check_plugged check twice while writing

Do the check to see if the drive was connected twice in case that the first was a fluke.

---
 fs/btrfs/raid56.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
fs/btrfs/raid56.c +15 -10
index 0e239a4c3b26..f652900d7569 100644
@@ -1750,18 +1750,23 @@ int raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc,
 
 	cb = blk_check_plugged(btrfs_raid_unplug, fs_info, sizeof(*plug));
 	if (cb) {
-		plug = container_of(cb, struct btrfs_plug_cb, cb);
-		if (!plug->info) {
-			plug->info = fs_info;
-			INIT_LIST_HEAD(&plug->rbio_list);
+		cpu_relax();
+		cb = blk_check_plugged(btrfs_raid_unplug, fs_info, sizeof(*plug));
+		if (cb) {
+			plug = container_of(cb, struct btrfs_plug_cb, cb);
+			if (!plug->info) {
+				plug->info = fs_info;
+				INIT_LIST_HEAD(&plug->rbio_list);
+			}
+			list_add_tail(&rbio->plug_list, &plug->rbio_list);
+			return 0;
 		}
-		list_add_tail(&rbio->plug_list, &plug->rbio_list);
-		ret = 0;
-	} else {
-		ret = __raid56_parity_write(rbio);
-		if (ret)
-			btrfs_bio_counter_dec(fs_info);
+		btrfs_warn(fs_info,
+"during a write operation, the first check to see if the drive was plugged in failed, seccond check succeeded, write continued");
 	}
+	ret = __raid56_parity_write(rbio);
+	if (ret)
+		btrfs_bio_counter_dec(fs_info);
 	return ret;
 }
 
Signature · 1 line
2.25.1
#1 lore raw

Hi Yusuf:

Quoted 2 lines · Yusuf Khan

Do the check to see if the drive was connected twice in case that the first was a fluke.

Block plugging is not actually about checking the connectivity of the drive; it's about batching IO submission. Specifically, when a client of the block layer (a filesystem or DM device, for instance) knows that it needs to send a whole batch of IO to disk from a thread, it can request the thread's be temporarily delayed, with blk_start_plug() (block/blk-core.c has a lengthy great comment about it). Then it submits its batch of requests. Finally, it requests the plug be released. This is useful because it can allow better IO by releasing a large, potentially better ordered batch at once.

In this particular case, to my understanding, blk_check_plug() checks whether the current thread is plugged, and, if it is, it adds the rbio to a list; when the plug expires, perhaps from the thread going to sleep, the plug callback gets called, specifically btrfs_raid_unplug(), which sorts the pending IOs.

As such, it shouldn't be necessary to check whether the thread is plugged twice. Your change description is a little light on *why* you'd like to check twice; maybe I'm missing something.

Hope this helps,

Sweet Tea