btrfs: allow mounting btrfs subvolumes with different ro/rw options
PATCH 1/1 btrfs: allow mounting btrfs subvolumes with different ro/rw options
From: Harald Hoyer <[email protected]>
Given the following /etc/fstab entries:
/dev/sda3 /mnt/foo btrfs subvol=foo,ro 0/dev/sda3 /mnt/bar btrfs subvol=bar,rw 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 /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 --- fs/btrfs/super.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
fs/btrfs/super.c +22 -0
@@ -64,6 +64,8 @@static const struct super_operations btrfs_super_ops;static struct file_system_type btrfs_fs_type; +static int btrfs_remount (struct super_block *sb,int *flags,char *data); +static const char *btrfs_decode_error (int errno) {char *errstr ="unknown" ;
@@ -1036,6 +1038,26 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags, mnt =vfs_kern_mount (&btrfs_fs_type, flags, device_name, newargs);kfree (newargs); + +if (PTR_RET (mnt) == -EBUSY ) { +if (flags &MS_RDONLY ) { + mnt =vfs_kern_mount (&btrfs_fs_type, flags & ~MS_RDONLY , device_name, + newargs); + }else { +int r; + mnt =vfs_kern_mount (&btrfs_fs_type, flags |MS_RDONLY , device_name, + newargs); +if (IS_ERR (mnt)) +return ERR_CAST (mnt); + + r =btrfs_remount (mnt->mnt_sb, &flags,NULL ); +if (r <0 ) { +/* FIXME: release vfsmount mnt ??*/ +return ERR_PTR (r); + } + } + } +if (IS_ERR (mnt))return ERR_CAST (mnt);
Signature · 1 line
1.8.2.1
Quoted 68 lines · On 06/18/2013 05:29 PM, [email protected] wrote:
From: Harald Hoyer <[email protected]>
Given the following
/etc/fstabentries:
/dev/sda3/mnt/foobtrfs subvol=foo,ro 0/dev/sda3/mnt/barbtrfs subvol=bar,rw 0you can't issue:
$ mount /mnt/foo $ mount /mnt/barYou would have to do:
$ mount /mnt/foo $ mount -o remount,rw /mnt/foo $ mount --bind -o remount,ro /mnt/foo $ mount /baror
$ mount /mnt/bar $ mount --rw /mnt/foo $ mount --bind -o remount,ro /mnt/fooWith 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 --- fs/btrfs/super.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)fs/btrfs/super.c +15
-0@@ -64,6 +64,8 @@static const struct super_operations btrfs_super_ops;static struct file_system_type btrfs_fs_type; +static int btrfs_remount (struct super_block *sb,int *flags,char *data); +static const char *btrfs_decode_error (int errno) {char *errstr ="unknown" ;@@ -1036,6 +1038,26 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags, mnt =vfs_kern_mount (&btrfs_fs_type, flags, device_name, newargs);kfree (newargs); + +if (PTR_RET (mnt) == -EBUSY ) { +if (flags &MS_RDONLY ) { + mnt =vfs_kern_mount (&btrfs_fs_type, flags & ~MS_RDONLY , device_name, + newargs); + }else { +int r; + mnt =vfs_kern_mount (&btrfs_fs_type, flags |MS_RDONLY , device_name, + newargs); +if (IS_ERR (mnt)) +return ERR_CAST (mnt); + + r =btrfs_remount (mnt->mnt_sb, &flags,NULL );
fs/btrfs/super.c static struct dentry *mount_subvol(const char *subvol_name, int flags, · line 1063
Quoted 10 lines
fs/btrfs/super.c +7
-0+if (r <0 ) { +/* FIXME: release vfsmount mnt ??*/ +return ERR_PTR (r); + } + } + } +if (IS_ERR (mnt))return ERR_CAST (mnt);
Any comments?
Quoted 73 lines · Harald Hoyer
Quoted 72 lines · On 06/18/2013 05:29 PM, [email protected] wrote:
From: Harald Hoyer <[email protected]>
Given the following
/etc/fstabentries:
/dev/sda3/mnt/foobtrfs subvol=foo,ro 0/dev/sda3/mnt/barbtrfs subvol=bar,rw 0you can't issue:
$ mount /mnt/foo $ mount /mnt/barYou would have to do:
$ mount /mnt/foo $ mount -o remount,rw /mnt/foo $ mount --bind -o remount,ro /mnt/foo $ mount /baror
$ mount /mnt/bar $ mount --rw /mnt/foo $ mount --bind -o remount,ro /mnt/fooWith 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 --- fs/btrfs/super.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)fs/btrfs/super.c +20
-0@@ -64,6 +64,8 @@static const struct super_operations btrfs_super_ops;static struct file_system_type btrfs_fs_type; +static int btrfs_remount (struct super_block *sb,int *flags,char *data); +static const char *btrfs_decode_error (int errno) {char *errstr ="unknown" ;@@ -1036,6 +1038,26 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags, mnt =vfs_kern_mount (&btrfs_fs_type, flags, device_name, newargs);kfree (newargs); + +if (PTR_RET (mnt) == -EBUSY ) { +if (flags &MS_RDONLY ) { + mnt =vfs_kern_mount (&btrfs_fs_type, flags & ~MS_RDONLY , device_name, + newargs); + }else { +int r; + mnt =vfs_kern_mount (&btrfs_fs_type, flags |MS_RDONLY , device_name, + newargs); +if (IS_ERR (mnt)) +return ERR_CAST (mnt); + + r =btrfs_remount (mnt->mnt_sb, &flags,NULL ); +if (r <0 ) { +/* FIXME: release vfsmount mnt ??*/ +return ERR_PTR (r); + } + }
Quoted 9 lines
fs/btrfs/super.c static struct dentry *mount_subvol(const char *subvol_name, int flags, · line 1063
Quoted 6 lines
fs/btrfs/super.c +2
-0+ } +if (IS_ERR (mnt))return ERR_CAST (mnt);Any comments?
Not even a "no, we don't want that" ?
Quoted 2 lines · Harald Hoyer
Quoted 1 line
Any comments?
Not even a "no, we don't want that" ?
Please resend.
david
Quoted 8 lines · David Sterba
Quoted 2 lines · Harald Hoyer
Quoted 1 line
Any comments?
Not even a "no, we don't want that" ?
Please resend.
david
done