Skip to content

Commit 0723a04

Browse files
haraldhmasoncl
authored andcommitted
btrfs: allow mounting btrfs subvolumes with different ro/rw options
Given the following /etc/fstab entries: /dev/sda3 /mnt/foo btrfs subvol=foo,ro 0 0 /dev/sda3 /mnt/bar btrfs subvol=bar,rw 0 0 you can't issue: $ mount /mnt/foo $ mount /mnt/bar You would have to do: $ mount /mnt/foo $ mount -o remount,rw /mnt/foo $ mount --bind -o remount,ro /mnt/foo $ mount /mnt/bar or $ mount /mnt/bar $ mount --rw /mnt/foo $ mount --bind -o remount,ro /mnt/foo With this patch you can do $ mount /mnt/foo $ mount /mnt/bar $ cat /proc/self/mountinfo 49 33 0:41 /foo /mnt/foo ro,relatime shared:36 - btrfs /dev/sda3 rw,ssd,space_cache 87 33 0:41 /bar /mnt/bar rw,relatime shared:74 - btrfs /dev/sda3 rw,ssd,space_cache Signed-off-by: Chris Mason <[email protected]>
1 parent 36523e9 commit 0723a04

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

fs/btrfs/super.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
static const struct super_operations btrfs_super_ops;
6767
static struct file_system_type btrfs_fs_type;
6868

69+
static int btrfs_remount(struct super_block *sb, int *flags, char *data);
70+
6971
static const char *btrfs_decode_error(int errno)
7072
{
7173
char *errstr = "unknown";
@@ -1185,6 +1187,26 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags,
11851187
mnt = vfs_kern_mount(&btrfs_fs_type, flags, device_name,
11861188
newargs);
11871189
kfree(newargs);
1190+
1191+
if (PTR_RET(mnt) == -EBUSY) {
1192+
if (flags & MS_RDONLY) {
1193+
mnt = vfs_kern_mount(&btrfs_fs_type, flags & ~MS_RDONLY, device_name,
1194+
newargs);
1195+
} else {
1196+
int r;
1197+
mnt = vfs_kern_mount(&btrfs_fs_type, flags | MS_RDONLY, device_name,
1198+
newargs);
1199+
if (IS_ERR(mnt))
1200+
return ERR_CAST(mnt);
1201+
1202+
r = btrfs_remount(mnt->mnt_sb, &flags, NULL);
1203+
if (r < 0) {
1204+
/* FIXME: release vfsmount mnt ??*/
1205+
return ERR_PTR(r);
1206+
}
1207+
}
1208+
}
1209+
11881210
if (IS_ERR(mnt))
11891211
return ERR_CAST(mnt);
11901212

0 commit comments

Comments
 (0)