btrfs: match btrfs_device->mode same as it used for open
PATCH 1/2 btrfs: match btrfs_device->mode same as it used for open
We aren't saving the fmode_t flags at %struct btrfs_device->mode same as it used to open the device at device replace, so fix that.
--- fs/btrfs/volumes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/btrfs/volumes.c +8 -8
@@ -2323,12 +2323,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathu64 tmp;int seeding_dev =0 ;int ret =0 ; +fmode_t flag =FMODE_WRITE |FMODE_EXCL ;if (sb_rdonly (sb) && !fs_info->fs_devices->seeding)return -EROFS ; - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flag, fs_info->bdev_holder);if (IS_ERR (bdev))return PTR_ERR (bdev);
@@ -2392,7 +2392,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =0 ; - device->mode =FMODE_EXCL ; + device->mode = flag; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE );
@@ -2506,7 +2506,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathbtrfs_sysfs_rm_device_link (fs_info->fs_devices, device);kfree (device); error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flag);if (seeding_dev) {mutex_unlock (&uuid_mutex);up_write (&sb->s_umount);
@@ -2526,6 +2526,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,struct rcu_string *name;u64 devid =BTRFS_DEV_REPLACE_DEVID ;int ret =0 ; +fmode_t flags =FMODE_WRITE |FMODE_EXCL ; *device_out =NULL ;if (fs_info->fs_devices->seeding) {
@@ -2533,8 +2534,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return -EINVAL ; } - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flags, fs_info->bdev_holder);if (IS_ERR (bdev)) {btrfs_err (fs_info,"target device %s is invalid!" , device_path);return PTR_ERR (bdev);
@@ -2595,7 +2595,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =1 ; - device->mode =FMODE_EXCL ; + device->mode = flags; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE ); device->fs_devices = fs_info->fs_devices;
@@ -2608,7 +2608,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return ret; error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flags);return ret; }
Signature · 1 line
2.13.1
PATCH 2/2 btrfs: maintain consistent fmode flags for device open
Devices opened through replace/add would have FMODE_WRITE | FMODE_EXCL, as compared with devices opened through the mount which will have FMODE_READ | FMODE_WRITE | FMODE_EXCL. So maintain consistency.
--- fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +2 -2
@@ -2323,7 +2323,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathu64 tmp;int seeding_dev =0 ;int ret =0 ; -fmode_t flag =FMODE_WRITE |FMODE_EXCL ; +fmode_t flag =FMODE_READ |FMODE_WRITE |FMODE_EXCL ;if (sb_rdonly (sb) && !fs_info->fs_devices->seeding)return -EROFS ;
@@ -2526,7 +2526,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,struct rcu_string *name;u64 devid =BTRFS_DEV_REPLACE_DEVID ;int ret =0 ; -fmode_t flags =FMODE_WRITE |FMODE_EXCL ; +fmode_t flags =FMODE_READ |FMODE_WRITE |FMODE_EXCL ; *device_out =NULL ;if (fs_info->fs_devices->seeding) {
Signature · 1 line
2.13.1
Quoted 2 lines · Anand Jain
We aren't saving the
fmode_tflags at %structbtrfs_device->modesame as it used to open the device at device replace, so fix that.
I think this could use a bit of rewording to better explain what the problem and what it can potentially cause.
Quoted 26 lines
Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)fs/btrfs/volumes.c +2
-2@@ -2323,12 +2323,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathu64 tmp;int seeding_dev =0 ;int ret =0 ; +fmode_t flag =FMODE_WRITE |FMODE_EXCL ;if (sb_rdonly (sb) && !fs_info->fs_devices->seeding)return -EROFS ; - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flag, fs_info->bdev_holder);if (IS_ERR (bdev))return PTR_ERR (bdev);
fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2395
Quoted 5 lines
fs/btrfs/volumes.c +1
-1@@ -2392,7 +2392,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =0 ; - device->mode =FMODE_EXCL ; + device->mode = flag;
So the actual bug being fixed by this patch is that currently we aren't setting the FMODE_WRITE when initializing btrfs_device structure and when calling blkdev_put, correct?
Quoted 49 lines
fs/btrfs/volumes.c +5
-5device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE );@@ -2506,7 +2506,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathbtrfs_sysfs_rm_device_link (fs_info->fs_devices, device);kfree (device); error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flag);if (seeding_dev) {mutex_unlock (&uuid_mutex);up_write (&sb->s_umount);@@ -2526,6 +2526,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,struct rcu_string *name;u64 devid =BTRFS_DEV_REPLACE_DEVID ;int ret =0 ; +fmode_t flags =FMODE_WRITE |FMODE_EXCL ; *device_out =NULL ;if (fs_info->fs_devices->seeding) {@@ -2533,8 +2534,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return -EINVAL ; } - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flags, fs_info->bdev_holder);if (IS_ERR (bdev)) {btrfs_err (fs_info,"target device %s is invalid!" , device_path);return PTR_ERR (bdev);@@ -2595,7 +2595,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =1 ; - device->mode =FMODE_EXCL ; + device->mode = flags; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE ); device->fs_devices = fs_info->fs_devices;@@ -2608,7 +2608,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return ret; error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flags);return ret; }
Quoted 8 lines · Nikolay Borisov
Quoted 2 lines · Anand Jain
We aren't saving the
fmode_tflags at %structbtrfs_device->modesame as it used to open the device at device replace, so fix that.I think this could use a bit of rewording to better explain what the problem and what it can potentially cause.
OK will do it.
Quoted 25 lines
Quoted 25 lines
Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)fs/btrfs/volumes.c +2
-2@@ -2323,12 +2323,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathu64 tmp;int seeding_dev =0 ;int ret =0 ; +fmode_t flag =FMODE_WRITE |FMODE_EXCL ;if (sb_rdonly (sb) && !fs_info->fs_devices->seeding)return -EROFS ; - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flag, fs_info->bdev_holder);if (IS_ERR (bdev))return PTR_ERR (bdev);
Quoted 10 lines
fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2395
Quoted 6 lines
fs/btrfs/volumes.c +1
-1@@ -2392,7 +2392,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =0 ; - device->mode =FMODE_EXCL ; + device->mode = flag;So the actual bug being fixed by this patch is that currently we aren't setting the
FMODE_WRITEwhen initializingbtrfs_devicestructure and when callingblkdev_put, correct?
yes.
Thanks, Anand
Quoted 49 lines
Quoted 49 lines
fs/btrfs/volumes.c +5
-5device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE );@@ -2506,7 +2506,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathbtrfs_sysfs_rm_device_link (fs_info->fs_devices, device);kfree (device); error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flag);if (seeding_dev) {mutex_unlock (&uuid_mutex);up_write (&sb->s_umount);@@ -2526,6 +2526,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,struct rcu_string *name;u64 devid =BTRFS_DEV_REPLACE_DEVID ;int ret =0 ; +fmode_t flags =FMODE_WRITE |FMODE_EXCL ; *device_out =NULL ;if (fs_info->fs_devices->seeding) {@@ -2533,8 +2534,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return -EINVAL ; } - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flags, fs_info->bdev_holder);if (IS_ERR (bdev)) {btrfs_err (fs_info,"target device %s is invalid!" , device_path);return PTR_ERR (bdev);@@ -2595,7 +2595,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =1 ; - device->mode =FMODE_EXCL ; + device->mode = flags; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE ); device->fs_devices = fs_info->fs_devices;@@ -2608,7 +2608,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return ret; error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flags);return ret; }
PATCH v2 1/2 btrfs: match btrfs_device->mode same as it used for open
In reply to Anand JainWe aren't setting the FMODE_WRITE when initializing btrfs_device structure and when calling blkdev_put, however we are setting it only when calling blkdev_get_by_path().
---
v2: Reword commit log.
fs/btrfs/volumes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/btrfs/volumes.c +8 -8
@@ -2323,12 +2323,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathu64 tmp;int seeding_dev =0 ;int ret =0 ; +fmode_t flag =FMODE_WRITE |FMODE_EXCL ;if (sb_rdonly (sb) && !fs_info->fs_devices->seeding)return -EROFS ; - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flag, fs_info->bdev_holder);if (IS_ERR (bdev))return PTR_ERR (bdev);
@@ -2392,7 +2392,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =0 ; - device->mode =FMODE_EXCL ; + device->mode = flag; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE );
@@ -2506,7 +2506,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathbtrfs_sysfs_rm_device_link (fs_info->fs_devices, device);kfree (device); error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flag);if (seeding_dev) {mutex_unlock (&uuid_mutex);up_write (&sb->s_umount);
@@ -2526,6 +2526,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,struct rcu_string *name;u64 devid =BTRFS_DEV_REPLACE_DEVID ;int ret =0 ; +fmode_t flags =FMODE_WRITE |FMODE_EXCL ; *device_out =NULL ;if (fs_info->fs_devices->seeding) {
@@ -2533,8 +2534,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return -EINVAL ; } - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flags, fs_info->bdev_holder);if (IS_ERR (bdev)) {btrfs_err (fs_info,"target device %s is invalid!" , device_path);return PTR_ERR (bdev);
@@ -2595,7 +2595,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =1 ; - device->mode =FMODE_EXCL ; + device->mode = flags; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE ); device->fs_devices = fs_info->fs_devices;
@@ -2608,7 +2608,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return ret; error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flags);return ret; }
Signature · 1 line
2.13.1
Quoted 3 lines · Anand Jain
We aren't setting the
FMODE_WRITEwhen initializingbtrfs_devicestructure and when callingblkdev_put, however we are setting it only when callingblkdev_get_by_path().
But this still does not say why this is a problem worth fixing. Nikolay asked for it, and I would do the same, but why do we even have to ask for that?
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
Quoted 8 lines · David Sterba
Quoted 3 lines · Anand Jain
We aren't setting the
FMODE_WRITEwhen initializingbtrfs_devicestructure and when callingblkdev_put, however we are setting it only when callingblkdev_get_by_path().But this still does not say why this is a problem worth fixing. Nikolay asked for it, and I would do the same, but why do we even have to ask for that?
Here its just a cleanup of miss match of open mode and close modes. And there isn't any problem that I noticed.
Thanks, Anand
Quoted 6 lines
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Anand Jain
Quoted 5 lines · David Sterba
Quoted 3 lines · Anand Jain
We aren't setting the
FMODE_WRITEwhen initializingbtrfs_devicestructure and when callingblkdev_put, however we are setting it only when callingblkdev_get_by_path().
Quoted 5 lines
Quoted 3 lines
But this still does not say why this is a problem worth fixing. Nikolay asked for it, and I would do the same, but why do we even have to ask for that?
Here its just a cleanup of miss match of open mode and close modes.> And there isn't any problem that I noticed.
Even if that's the case, please state that explicitly in your changelog and also put "No functional changes" if you expect it to not introduce any change in behavior.
Quoted 16 lines
Thanks, Anand
Quoted 7 lines
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 15 lines · Nikolay Borisov
Quoted 12 lines · Anand Jain
Quoted 8 lines · David Sterba
Quoted 3 lines · Anand Jain
We aren't setting the
FMODE_WRITEwhen initializingbtrfs_devicestructure and when callingblkdev_put, however we are setting it only when callingblkdev_get_by_path().But this still does not say why this is a problem worth fixing. Nikolay asked for it, and I would do the same, but why do we even have to ask for that?
Quoted 6 lines
Quoted 1 line
Here its just a cleanup of miss match of open mode and close modes.> And there isn't any problem that I noticed.
Even if that's the case, please state that explicitly in your changelog and also put "No functional changes" if you expect it to not introduce any change in behavior.
Ah. Will update change log.
Thanks, Anand
Quoted 21 lines
Quoted 4 lines
Thanks, Anand
Quoted 12 lines
Quoted 7 lines
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 1/2 btrfs: match btrfs_device->mode same as it used for open
In reply to Anand JainThis patch maintains consistency of mode in device get and put. And is just a cleanup patch. There isn't any problem that was noticed, so no functional changes.
---
v2: commit update
v3: commit update
fs/btrfs/volumes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/btrfs/volumes.c +8 -8
@@ -2323,12 +2323,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathu64 tmp;int seeding_dev =0 ;int ret =0 ; +fmode_t flag =FMODE_WRITE |FMODE_EXCL ;if (sb_rdonly (sb) && !fs_info->fs_devices->seeding)return -EROFS ; - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flag, fs_info->bdev_holder);if (IS_ERR (bdev))return PTR_ERR (bdev);
@@ -2392,7 +2392,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =0 ; - device->mode =FMODE_EXCL ; + device->mode = flag; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE );
@@ -2506,7 +2506,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathbtrfs_sysfs_rm_device_link (fs_info->fs_devices, device);kfree (device); error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flag);if (seeding_dev) {mutex_unlock (&uuid_mutex);up_write (&sb->s_umount);
@@ -2526,6 +2526,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,struct rcu_string *name;u64 devid =BTRFS_DEV_REPLACE_DEVID ;int ret =0 ; +fmode_t flags =FMODE_WRITE |FMODE_EXCL ; *device_out =NULL ;if (fs_info->fs_devices->seeding) {
@@ -2533,8 +2534,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return -EINVAL ; } - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flags, fs_info->bdev_holder);if (IS_ERR (bdev)) {btrfs_err (fs_info,"target device %s is invalid!" , device_path);return PTR_ERR (bdev);
@@ -2595,7 +2595,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =1 ; - device->mode =FMODE_EXCL ; + device->mode = flags; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE ); device->fs_devices = fs_info->fs_devices;
@@ -2608,7 +2608,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return ret; error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flags);return ret; }
Signature · 1 line
2.13.1
Quoted 6 lines · Anand Jain
This patch maintains consistency of mode in device get and put. And is just a cleanup patch. There isn't any problem that was noticed, so no functional changes.
Signed-off-by Anand Jain <[email protected]>---
Quoted 80 lines
v2: commit update
v3: commit updatefs/btrfs/volumes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)fs/btrfs/volumes.c +8
-8@@ -2323,12 +2323,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathu64 tmp;int seeding_dev =0 ;int ret =0 ; +fmode_t flag =FMODE_WRITE |FMODE_EXCL ;if (sb_rdonly (sb) && !fs_info->fs_devices->seeding)return -EROFS ; - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flag, fs_info->bdev_holder);if (IS_ERR (bdev))return PTR_ERR (bdev);@@ -2392,7 +2392,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =0 ; - device->mode =FMODE_EXCL ; + device->mode = flag; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE );@@ -2506,7 +2506,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathbtrfs_sysfs_rm_device_link (fs_info->fs_devices, device);kfree (device); error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flag);if (seeding_dev) {mutex_unlock (&uuid_mutex);up_write (&sb->s_umount);@@ -2526,6 +2526,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,struct rcu_string *name;u64 devid =BTRFS_DEV_REPLACE_DEVID ;int ret =0 ; +fmode_t flags =FMODE_WRITE |FMODE_EXCL ; *device_out =NULL ;if (fs_info->fs_devices->seeding) {@@ -2533,8 +2534,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return -EINVAL ; } - bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + bdev =blkdev_get_by_path (device_path, flags, fs_info->bdev_holder);if (IS_ERR (bdev)) {btrfs_err (fs_info,"target device %s is invalid!" , device_path);return PTR_ERR (bdev);@@ -2595,7 +2595,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, device->bdev = bdev; device->in_fs_metadata =1 ; device->is_tgtdev_for_dev_replace =1 ; - device->mode =FMODE_EXCL ; + device->mode = flags; device->dev_stats_valid =1 ;set_blocksize (device->bdev,BTRFS_BDEV_BLOCKSIZE ); device->fs_devices = fs_info->fs_devices;@@ -2608,7 +2608,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,return ret; error: -blkdev_put (bdev,FMODE_EXCL ); +blkdev_put (bdev, flags);return ret; }