Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: close any open devices if btrfs_mount fails
@ 2013-04-04 15:35 Eric Sandeen
  2013-04-04 16:32 ` [PATCH V2] " Eric Sandeen
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Sandeen @ 2013-04-04 15:35 UTC (permalink / raw)
  To: linux-btrfs, Jan Safranek

This:

   # mkfs.btrfs /dev/sdb{1,2} ; wipefs -a /dev/sdb1; mount /dev/sdb2 /mnt/test

would lead to a blkdev open/close mismatch when the mount fails, and
a permanently busy (opened O_EXCL) sdb2:

   # wipefs -a /dev/sdb2
   wipefs: error: /dev/sdb2: probing initialization failed: Device or resource busy

It's because btrfs_open_devices() may open some devices, and still
return failure.  So the error unwinding needs to close any open
devices in fs_devices before returning.

Reported-by: Jan Safranek <jsafrane@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

Note, __btrfs_open_devices is weird; it seems to return success or
failure based on the outcome of the result of the last call
to btrfs_get_bdev_and_sb().  But that's a different bug...

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index f6b8859..60c67fa 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1125,7 +1125,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
 
 	error = btrfs_open_devices(fs_devices, mode, fs_type);
 	if (error)
-		goto error_fs_info;
+		goto error_close_devices;
 
 	if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) {
 		error = -EACCES;
@@ -1161,7 +1161,8 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
 	return root;
 
 error_close_devices:
-	btrfs_close_devices(fs_devices);
+	if (fs_devices->opened)
+		btrfs_close_devices(fs_devices);
 error_fs_info:
 	free_fs_info(fs_info);
 	return ERR_PTR(error);


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

end of thread, other threads:[~2013-04-04 20:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-04 15:35 [PATCH] btrfs: close any open devices if btrfs_mount fails Eric Sandeen
2013-04-04 16:32 ` [PATCH V2] " Eric Sandeen
2013-04-04 18:46   ` Zach Brown
2013-04-04 19:45     ` Eric Sandeen
2013-04-04 19:50       ` Zach Brown
2013-04-04 20:05       ` Chris Mason
2013-04-04 20:45   ` [PATCH V3] btrfs: ignore device open failures in __btrfs_open_devices Eric Sandeen

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