public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: free device if we fail to open it
@ 2021-12-01 21:18 Josef Bacik
  2021-12-02  7:09 ` Anand Jain
  0 siblings, 1 reply; 8+ messages in thread
From: Josef Bacik @ 2021-12-01 21:18 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We've been having transient failures of btrfs/197 because sometimes we
don't show a missing device.

This turned out to be because I use LVM for my devices, and sometimes we
race with udev and get the "/dev/dm-#" device registered as a device in
the fs_devices list instead of "/dev/mapper/vg0-lv#" device.  Thus when
the test adds a device to the existing mount it doesn't find the old
device in the original fs_devices list and remove it properly.

This is fine in general, because when we open the devices we check the
UUID, and properly skip using the device that we added to the other file
system.  However we do not remove it from our fs_devices, so when we get
the device info we still see this old device and think that everything
is ok.

We have a check for -ENODATA coming back from reading the super off of
the device to catch the wipefs case, but we don't catch literally any
other error where the device is no longer valid and thus do not remove
the device.

Fix this to not special case an empty device when reading the super
block, and simply remove any device we are unable to open.

With this fix we properly print out missing devices in the test case,
and after 500 iterations I'm no longer able to reproduce the problem,
whereas I could usually reproduce within 200 iterations.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/disk-io.c | 2 +-
 fs/btrfs/volumes.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 5c598e124c25..fa34b8807f8d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3924,7 +3924,7 @@ struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
 	super = page_address(page);
 	if (btrfs_super_magic(super) != BTRFS_MAGIC) {
 		btrfs_release_disk_super(super);
-		return ERR_PTR(-ENODATA);
+		return ERR_PTR(-EINVAL);
 	}
 
 	if (btrfs_super_bytenr(super) != bytenr_orig) {
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index f38c230111be..890153dd2a2b 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1223,7 +1223,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
 		if (ret == 0 &&
 		    (!latest_dev || device->generation > latest_dev->generation)) {
 			latest_dev = device;
-		} else if (ret == -ENODATA) {
+		} else if (ret) {
 			fs_devices->num_devices--;
 			list_del(&device->dev_list);
 			btrfs_free_device(device);
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-06 22:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-01 21:18 [PATCH] btrfs: free device if we fail to open it Josef Bacik
2021-12-02  7:09 ` Anand Jain
2021-12-02 16:02   ` Josef Bacik
2021-12-03  8:31     ` Anand Jain
2021-12-03 15:08       ` Josef Bacik
2021-12-06 14:32         ` Anand Jain
2021-12-06 19:16           ` Josef Bacik
2021-12-06 22:23             ` Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox