diff mbox

Btrfs: fix subvolume mount by name problem when default mount subvolume is set

Message ID 1301558362-2650-1-git-send-email-xin.zhong@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Xin Zhong March 31, 2011, 7:59 a.m. UTC
None

Comments

Chris Mason April 5, 2011, 5:07 a.m. UTC | #1
Excerpts from Zhong, Xin's message of 2011-03-31 03:59:22 -0400:
> We create two subvolumes (meego_root and meego_home) in
> btrfs root directory. And set meego_root as default mount
> subvolume. After we remount btrfs, meego_root is mounted
> to top directory by default. Then when we try to mount
> meego_home (subvol=meego_home) to a subdirectory, it failed.
> The problem is when default mount subvolume is set to
> meego_root, we search meego_home in it but can not find it.
> So the solution is to search meego_home in btrfs root
> directory instead when subvol=meego_home is given.

I think this one is difficult because if they have set the default
subvolume they might have done so because the original default has the
result of a busted upgrade or something in it.

So, I think the subvol= should be relative to the default.  Would it
work for you to add a new mount option to specify the subvol id to
search for subvol=?

-chris
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index db0a827..138bc4c 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -786,15 +786,18 @@  static int btrfs_get_sb(struct file_system_type *fs_type, int flags,
 		s->s_flags |= MS_ACTIVE;
 	}
 
-	root = get_default_root(s, subvol_objectid);
-	if (IS_ERR(root)) {
-		error = PTR_ERR(root);
-		deactivate_locked_super(s);
-		goto error_free_subvol_name;
-	}
 	/* if they gave us a subvolume name bind mount into that */
 	if (strcmp(subvol_name, ".")) {
 		struct dentry *new_root;
+		
+		/* we search subvolume name in the btrfs root, not the default mount subvolume */
+		root = get_default_root(s, BTRFS_FS_TREE_OBJECTID);
+		if (IS_ERR(root)) {
+			error = PTR_ERR(root);
+			deactivate_locked_super(s);
+			goto error_free_subvol_name;
+		}
+
 		mutex_lock(&root->d_inode->i_mutex);
 		new_root = lookup_one_len(subvol_name, root,
 				      strlen(subvol_name));
@@ -816,6 +819,14 @@  static int btrfs_get_sb(struct file_system_type *fs_type, int flags,
 		dput(root);
 		root = new_root;
 	}
+	else {
+		root = get_default_root(s, subvol_objectid);
+		if (IS_ERR(root)) {
+			error = PTR_ERR(root);
+			deactivate_locked_super(s);
+			goto error_free_subvol_name;
+		}
+	}
 
 	mnt->mnt_sb = s;
 	mnt->mnt_root = root;