diff --git a/btrfs-fix-error-handling-in-btrfs_get_sub.patch b/btrfs-fix-error-handling-in-btrfs_get_sub.patch new file mode 100644 index 000000000..a91999510 --- /dev/null +++ b/btrfs-fix-error-handling-in-btrfs_get_sub.patch @@ -0,0 +1,65 @@ +From 8f172904b45a6b530eaa345b23956682629bddee Mon Sep 17 00:00:00 2001 +From: Josef Bacik +Date: Fri, 22 Oct 2010 15:26:53 -0400 +Subject: Btrfs: fix error handling in btrfs_get_sb + +If we failed to find the root subvol id, or the subvol=, we would +deactivate the locked super and close the devices. The problem is at this point +we have gotten the SB all setup, which includes setting super_operations, so +when we'd deactiveate the super, we'd do a close_ctree() which closes the +devices, so we'd end up closing the devices twice. So if you do something like +this + +mount /dev/sda1 /mnt/test1 +mount /dev/sda1 /mnt/test2 -o subvol=xxx +umount /mnt/test1 + +it would blow up (if subvol xxx doesn't exist). This patch fixes that problem. +Thanks, + +Signed-off-by: Josef Bacik +--- + fs/btrfs/super.c | 7 +++---- + 1 files changed, 3 insertions(+), 4 deletions(-) + +diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c +index f2393b3..c246f25 100644 +--- a/fs/btrfs/super.c ++++ b/fs/btrfs/super.c +@@ -629,7 +629,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, + if (IS_ERR(root)) { + error = PTR_ERR(root); + deactivate_locked_super(s); +- goto error; ++ goto error_free_subvol_name; + } + /* if they gave us a subvolume name bind mount into that */ + if (strcmp(subvol_name, ".")) { +@@ -643,14 +643,14 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, + deactivate_locked_super(s); + error = PTR_ERR(new_root); + dput(root); +- goto error_close_devices; ++ goto error_free_subvol_name; + } + if (!new_root->d_inode) { + dput(root); + dput(new_root); + deactivate_locked_super(s); + error = -ENXIO; +- goto error_close_devices; ++ goto error_free_subvol_name; + } + dput(root); + root = new_root; +@@ -668,7 +668,6 @@ error_close_devices: + btrfs_close_devices(fs_devices); + error_free_subvol_name: + kfree(subvol_name); +-error: + return error; + } + +-- +1.7.3.3 + diff --git a/btrfs-fix-race-between-btrfs_get_sb-and-unmount.patch b/btrfs-fix-race-between-btrfs_get_sb-and-unmount.patch new file mode 100644 index 000000000..7553b5fc8 --- /dev/null +++ b/btrfs-fix-race-between-btrfs_get_sb-and-unmount.patch @@ -0,0 +1,37 @@ +From 863472a34f271e546bf20550ad3571645c557ab3 Mon Sep 17 00:00:00 2001 +From: Ian Kent +Date: Mon, 22 Nov 2010 02:21:38 +0000 +Subject: [PATCH] Btrfs - fix race between btrfs_get_sb() and umount + +When mounting a btrfs file system btrfs_test_super() may attempt to +use sb->s_fs_info, the btrfs root, of a super block that is going away +and that has had the btrfs root set to NULL in its ->put_super(). But +if the super block is going away it cannot be an existing super block +so we can return false in this case. + +Signed-off-by: Ian Kent +Signed-off-by: Chris Mason +--- + fs/btrfs/super.c | 6 ++++++ + 1 files changed, 6 insertions(+), 0 deletions(-) + +diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c +index 66864bc..31d11c6 100644 +--- a/fs/btrfs/super.c ++++ b/fs/btrfs/super.c +@@ -551,6 +551,12 @@ static int btrfs_test_super(struct super_block *s, void *data) + struct btrfs_root *test_root = data; + struct btrfs_root *root = btrfs_sb(s); + ++ /* ++ * If this super block is going away, return false as it ++ * can't match as an existing super block. ++ */ ++ if (!atomic_read(&s->s_active)) ++ return 0; + return root->fs_info->fs_devices == test_fs_devices; + } + +-- +1.7.3.3 + diff --git a/btrfs-setup-blank-root-and-fs_info-for-mount-time.patch b/btrfs-setup-blank-root-and-fs_info-for-mount-time.patch new file mode 100644 index 000000000..877dc903e --- /dev/null +++ b/btrfs-setup-blank-root-and-fs_info-for-mount-time.patch @@ -0,0 +1,117 @@ +From 432400763c869563b2deb179d1bd8b11dcb18917 Mon Sep 17 00:00:00 2001 +From: Kyle McMartin +Date: Fri, 10 Dec 2010 10:09:15 -0500 +Subject: Btrfs: setup blank root and fs_info for mount time + +There is a problem with how we use sget, it searches through the list of supers +attached to the fs_type looking for a super with the same fs_devices as what +we're trying to mount. This depends on sb->s_fs_info being filled, but we don't +fill that in until we get to btrfs_fill_super, so we could hit supers on the +fs_type super list that have a null s_fs_info. In order to fix that we need to +go ahead and setup a blank root with a blank fs_info to hold fs_devices, that +way our test will work out right and then we can set s_fs_info in +btrfs_set_super, and then open_ctree will simply use our pre-allocated root and +fs_info when setting everything up. Thanks, + +Signed-off-by: Josef Bacik +Signed-off-by: Chris Mason + +Conflicts: + + fs/btrfs/super.c +--- + fs/btrfs/disk-io.c | 6 ++---- + fs/btrfs/super.c | 32 ++++++++++++++++++++++++++++++-- + 2 files changed, 32 insertions(+), 6 deletions(-) + +diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c +index 34f7c37..b6c3dad 100644 +--- a/fs/btrfs/disk-io.c ++++ b/fs/btrfs/disk-io.c +@@ -1539,10 +1539,8 @@ struct btrfs_root *open_ctree(struct super_block *sb, + GFP_NOFS); + struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), + GFP_NOFS); +- struct btrfs_root *tree_root = kzalloc(sizeof(struct btrfs_root), +- GFP_NOFS); +- struct btrfs_fs_info *fs_info = kzalloc(sizeof(*fs_info), +- GFP_NOFS); ++ struct btrfs_root *tree_root = btrfs_sb(sb); ++ struct btrfs_fs_info *fs_info = tree_root->fs_info; + struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), + GFP_NOFS); + struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), +diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c +index c246f25..66864bc 100644 +--- a/fs/btrfs/super.c ++++ b/fs/btrfs/super.c +@@ -548,13 +548,21 @@ static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs) + + static int btrfs_test_super(struct super_block *s, void *data) + { +- struct btrfs_fs_devices *test_fs_devices = data; ++ struct btrfs_root *test_root = data; + struct btrfs_root *root = btrfs_sb(s); + +- return root->fs_info->fs_devices == test_fs_devices; ++ return root->fs_info->fs_devices == test_root->fs_info->fs_devices; + } + ++static int btrfs_set_super(struct super_block *s, void *data) ++{ ++ s->s_fs_info = data; ++ ++ return set_anon_super(s, data); ++} ++ ++ + /* + * Find a superblock for the given device / mount point. + * +@@ -567,6 +575,8 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, + struct super_block *s; + struct dentry *root; + struct btrfs_fs_devices *fs_devices = NULL; ++ struct btrfs_root *tree_root = NULL; ++ struct btrfs_fs_info *fs_info = NULL; + fmode_t mode = FMODE_READ; + char *subvol_name = NULL; + u64 subvol_objectid = 0; +@@ -595,8 +605,24 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, + goto error_close_devices; + } + ++ /* ++ * Setup a dummy root and fs_info for test/set super. This is because ++ * we don't actually fill this stuff out until open_ctree, but we need ++ * it for searching for existing supers, so this lets us do that and ++ * then open_ctree will properly initialize everything later. ++ */ ++ fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS); ++ tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); ++ if (!fs_info || !tree_root) { ++ error = -ENOMEM; ++ goto error_close_devices; ++ } ++ fs_info->tree_root = tree_root; ++ fs_info->fs_devices = fs_devices; ++ tree_root->fs_info = fs_info; ++ + bdev = fs_devices->latest_bdev; +- s = sget(fs_type, btrfs_test_super, set_anon_super, fs_devices); ++ s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root); + if (IS_ERR(s)) + goto error_s; + +@@ -666,6 +692,8 @@ error_s: + error = PTR_ERR(s); + error_close_devices: + btrfs_close_devices(fs_devices); ++ kfree(fs_info); ++ kfree(tree_root); + error_free_subvol_name: + kfree(subvol_name); + return error; +-- +1.7.3.3 + diff --git a/kernel.spec b/kernel.spec index d727c0b97..959c9cbb5 100644 --- a/kernel.spec +++ b/kernel.spec @@ -814,6 +814,10 @@ Patch13692: orinoco-initialise-priv_hw-before-assigning-the-interrupt.patch Patch13693: ext4-always-journal-quota-file-modifications.patch +Patch13694: btrfs-fix-error-handling-in-btrfs_get_sub.patch +Patch13695: btrfs-setup-blank-root-and-fs_info-for-mount-time.patch +Patch13696: btrfs-fix-race-between-btrfs_get_sb-and-unmount.patch + %endif BuildRoot: %{_tmppath}/kernel-%{KVERREL}-root @@ -1274,6 +1278,10 @@ ApplyPatch ext4-always-journal-quota-file-modifications.patch # btrfs +# rhbz#656465 +ApplyPatch btrfs-fix-error-handling-in-btrfs_get_sub.patch +ApplyPatch btrfs-setup-blank-root-and-fs_info-for-mount-time.patch +ApplyPatch btrfs-fix-race-between-btrfs_get_sb-and-unmount.patch # eCryptfs @@ -2121,6 +2129,9 @@ fi # and build. %changelog +* Fri Dec 10 2010 Kyle McMartin +- Fix some issues mounting btrfs devices with subvolumes (#656465) + * Fri Dec 10 2010 Kyle McMartin - Fix jbd2 warnings when using quotas. (#578674)