Skip to contentSkip to conversation

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

PATCH Superseded Zhong, Xin 2 participants 3 messages Mar 31, 2011 – Apr 6, 2011 Btrfs file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zhong, Xin

author
#0 lore raw

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

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.

Detail information can be found in meego bugzilla:
https://bugs.meego.com/show_bug.cgi?id=15055

---
 fs/btrfs/super.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)
fs/btrfs/super.c +17 -6
index db0a827..138bc4c 100644
@@ -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;
Signature · 1 line
1.7.0.4
#1 lore raw

Excerpts from Zhong, Xin's message of 2011-03-31 03:59:22 -0400:

Quoted 9 lines

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

author
#2 lore raw

PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBDaHJpcyBNYXNvbiBbbWFpbHRv OmNocmlzLm1hc29uQG9yYWNsZS5jb21dDQo+IFNlbnQ6IFR1ZXNkYXksIEFwcmlsIDA1LCAyMDEx IDE6MDcgUE0NCj4gVG86IFpob25nLCBYaW4NCj4gQ2M6IGxpbnV4LWJ0cmZzDQo+IFN1YmplY3Q6 IFJlOiBbUEFUQ0hdIEJ0cmZzOiBmaXggc3Vidm9sdW1lIG1vdW50IGJ5IG5hbWUgcHJvYmxlbSB3 aGVuDQo+IGRlZmF1bHQgbW91bnQgc3Vidm9sdW1lIGlzIHNldA0KPiANCj4gRXhjZXJwdHMgZnJv bSBaaG9uZywgWGluJ3MgbWVzc2FnZSBvZiAyMDExLTAzLTMxIDAzOjU5OjIyIC0wNDAwOg0KPiA+ IFdlIGNyZWF0ZSB0d28gc3Vidm9sdW1lcyAobWVlZ29fcm9vdCBhbmQgbWVlZ29faG9tZSkgaW4N Cj4gPiBidHJmcyByb290IGRpcmVjdG9yeS4gQW5kIHNldCBtZWVnb19yb290IGFzIGRlZmF1bHQg bW91bnQNCj4gPiBz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