Add cli and ioctl to ignore a scanned device
cover Add cli and ioctl to ignore a scanned device
Patch 1/2 is preparatory patch to get a function to delete a device
from the list.
Patch 2/2 adds the ioctl and feature to delete a device from the device list.
Anand Jain (2):
btrfs: refactor btrfs_free_stale_device() to get device list delete
btrfs: introduce feature to ignore a btrfs device
fs/btrfs/super.c | 4 ++ fs/btrfs/volumes.c | 97 +++++++++++++++++++++++++++++++++++++++++----- fs/btrfs/volumes.h | 2 + include/uapi/linux/btrfs.h | 2 + 4 files changed, 95 insertions(+), 10 deletions(-)
Signature · 1 line
2.13.1
PATCH 1/2 btrfs: refactor btrfs_free_stale_device() to get device list delete
We need to delete a device from the dev_list, so refactor btrfs_free_stale_device() for delete_device_from_list().
--- fs/btrfs/volumes.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
fs/btrfs/volumes.c +17 -10
@@ -546,6 +546,22 @@ static void pending_bios_fn(struct btrfs_work *work)run_scheduled_bios (device); } +void delete_device_from_list (struct btrfs_device *dev) +{ +struct btrfs_fs_devices *fs_devs; + fs_devs = dev->fs_devices; + +if (fs_devs->num_devices ==1 ) { +btrfs_sysfs_remove_fsid (fs_devs); +list_del (&fs_devs->list); +free_fs_devices (fs_devs); + }else { + fs_devs->num_devices--; +list_del (&dev->dev_list); +rcu_string_free (dev->name); +kfree (dev); + } +}void btrfs_free_stale_device (struct btrfs_device *cur_dev) {
@@ -586,16 +602,7 @@ void btrfs_free_stale_device(struct btrfs_device *cur_dev)if (!del) {/* delete the stale device */ -if (fs_devs->num_devices ==1 ) { -btrfs_sysfs_remove_fsid (fs_devs); -list_del (&fs_devs->list); -free_fs_devices (fs_devs); - }else { - fs_devs->num_devices--; -list_del (&dev->dev_list); -rcu_string_free (dev->name); -kfree (dev); - } +delete_device_from_list (dev);break ; } }
Signature · 1 line
2.13.1
Re: [PATCH 1/2] btrfs: refactor btrfs_free_stale_device() to get device list delete
Quoted 13 lines · Anand Jain
We need to delete a device from the
dev_list, so refactorbtrfs_free_stale_device()fordelete_device_from_list().Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)fs/btrfs/volumes.c +0
-0
fs/btrfs/volumes.c static void pending_bios_fn(struct btrfs_work *work) · line 549
Quoted 4 lines
fs/btrfs/volumes.c +1
-0@@ -546,6 +546,22 @@ static void pending_bios_fn(struct btrfs_work *work)run_scheduled_bios (device); } +void delete_device_from_list (struct btrfs_device *dev)
In this patch and the other one this function is used only in volume.c so make static. Also if it relies on some particular lock being held why not add lockdep_assert_held(xxx) as a means of documenting that ?
Quoted 37 lines
fs/btrfs/volumes.c +16
-10+{ +struct btrfs_fs_devices *fs_devs; + fs_devs = dev->fs_devices; + +if (fs_devs->num_devices ==1 ) { +btrfs_sysfs_remove_fsid (fs_devs); +list_del (&fs_devs->list); +free_fs_devices (fs_devs); + }else { + fs_devs->num_devices--; +list_del (&dev->dev_list); +rcu_string_free (dev->name); +kfree (dev); + } +}void btrfs_free_stale_device (struct btrfs_device *cur_dev) {@@ -586,16 +602,7 @@ void btrfs_free_stale_device(struct btrfs_device *cur_dev)if (!del) {/* delete the stale device */ -if (fs_devs->num_devices ==1 ) { -btrfs_sysfs_remove_fsid (fs_devs); -list_del (&fs_devs->list); -free_fs_devices (fs_devs); - }else { - fs_devs->num_devices--; -list_del (&dev->dev_list); -rcu_string_free (dev->name); -kfree (dev); - } +delete_device_from_list (dev);break ; } }
Re: [PATCH 1/2] btrfs: refactor btrfs_free_stale_device() to get device list delete
Quoted 19 lines · Nikolay Borisov
Quoted 16 lines · Anand Jain
We need to delete a device from the
dev_list, so refactorbtrfs_free_stale_device()fordelete_device_from_list().Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)fs/btrfs/volumes.c +0
-0@@ -546,6 +546,22 @@ static void pending_bios_fn(struct btrfs_work *work)run_scheduled_bios (device); }
Quoted 4 lines
fs/btrfs/volumes.c static void pending_bios_fn(struct btrfs_work *work) · line 549
Quoted 1 line
fs/btrfs/volumes.c +1
-0+void delete_device_from_list (struct btrfs_device *dev)In this patch and the other one this function is used only in
volume.cso make static.
Right. Will do.
Quoted 2 lines
Also if it relies on some particular lock being held why not add
lockdep_assert_held(xxx)as a means of documenting that ?
Actually, btrfs_free_stale_device() should be holding device_list_mutex but it didn't so I would like to fix it separately. So here I shall create a new function instead of peal from btrfs_free_stale_device(), which I think btrfs_free_stale_device() can use it later.
Thanks, Anand
Quoted 42 lines
Quoted 27 lines
fs/btrfs/volumes.c +15
-4+{ +struct btrfs_fs_devices *fs_devs; + fs_devs = dev->fs_devices; + +if (fs_devs->num_devices ==1 ) { +btrfs_sysfs_remove_fsid (fs_devs); +list_del (&fs_devs->list); +free_fs_devices (fs_devs); + }else { + fs_devs->num_devices--; +list_del (&dev->dev_list); +rcu_string_free (dev->name); +kfree (dev); + } +}void btrfs_free_stale_device (struct btrfs_device *cur_dev) {@@ -586,16 +602,7 @@ void btrfs_free_stale_device(struct btrfs_device *cur_dev)if (!del) {/* delete the stale device */ -if (fs_devs->num_devices ==1 ) { -btrfs_sysfs_remove_fsid (fs_devs); -list_del (&fs_devs->list); -free_fs_devices (fs_devs);fs/btrfs/volumes.c void btrfs_free_stale_device(struct btrfs_device *cur_dev) · line 608
Quoted 10 lines
fs/btrfs/volumes.c +1
-6- }else { - fs_devs->num_devices--; -list_del (&dev->dev_list); -rcu_string_free (dev->name); -kfree (dev); - } +delete_device_from_list (dev);break ; } }--
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 2/2 btrfs: introduce feature to ignore a btrfs device
In reply to Anand JainSupport for a new command is being added here:
btrfs dev ignore <dev>
Which shall undo the effects of the command
btrfs dev scan <dev>
This cli/ioctl is needed as there is no way to continue to mount in degraded mode if the device is already scanned, which is required to recover from the split brain raid conditions.
This patch proposes to use ioctl #5 as it was empty.
IOW(BTRFS_IOCTL_MAGIC, 5, ..)
If #5 is reserved for some other purpose, I think I should change this.
--- fs/btrfs/super.c | 4 +++ fs/btrfs/volumes.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 2 ++ 4 files changed, 78 insertions(+)
fs/btrfs/super.c +4 -0
@@ -2183,6 +2183,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);break ; +case BTRFS_IOC_IGNORE_DEV : + ret =btrfs_ignore_one_device (vol->name,FMODE_READ , + &btrfs_fs_type, &fs_devices); +break ;case BTRFS_IOC_DEVICES_READY : ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);
fs/btrfs/volumes.c +70 -0
76 lines not on this page · raw message
fs/btrfs/volumes.h +2 -0
@@ -421,6 +421,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder);int btrfs_scan_one_device (const char *path,fmode_t flags,void *holder,struct btrfs_fs_devices **fs_devices_ret); +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret);int btrfs_close_devices (struct btrfs_fs_devices *fs_devices);void btrfs_close_extra_devices (struct btrfs_fs_devices *fs_devices,int step); void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,
include/uapi/linux/btrfs.h +2 -0
@@ -739,6 +739,8 @@ enum btrfs_err_code { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
Signature · 1 line
2.13.1
Re: [PATCH 2/2] btrfs: introduce feature to ignore a btrfs device
Quoted 46 lines · Anand Jain
Support for a new command is being added here:
btrfs dev ignore <dev>
Which shall undo the effects of the command
btrfs dev scan <dev>This cli/ioctl is needed as there is no way to continue to mount in degraded mode if the device is already scanned, which is required to recover from the split brain raid conditions.
This patch proposes to use ioctl #5 as it was empty.
IOW(BTRFS_IOCTL_MAGIC, 5, ..)If #5 is reserved for some other purpose, I think I should change this.
Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/super.c | 4 +++ fs/btrfs/volumes.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 2 ++ 4 files changed, 78 insertions(+)fs/btrfs/super.c +4
-0@@ -2183,6 +2183,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);break ; +case BTRFS_IOC_IGNORE_DEV : + ret =btrfs_ignore_one_device (vol->name,FMODE_READ , + &btrfs_fs_type, &fs_devices); +break ;case BTRFS_IOC_DEVICES_READY : ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);fs/btrfs/volumes.c +2
-0@@ -1181,6 +1181,76 @@ int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr,return 0 ; } +static int device_list_remove (struct btrfs_super_block *disk_super,u64 devid) +{
fs/btrfs/volumes.c int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, · line 1195
Quoted 10 lines
fs/btrfs/volumes.c +10
-0+int ret =0 ; +struct btrfs_fs_devices *fs_devices; +struct btrfs_device *device; + + fs_devices =find_fsid (disk_super->fsid); +if (!fs_devices) +return -ENOENT ; + +if (fs_devices->opened) +return -EPERM ;
Isn't -EBUSY more appropriate?
Quoted 88 lines
fs/btrfs/volumes.c +58
-0+ +mutex_lock (&uuid_mutex); +mutex_lock (&fs_devices->device_list_mutex); + device =find_device (fs_devices, devid, disk_super->dev_item.uuid); +if (!device) { + ret = -ENOENT ; + goto error; + } + +delete_device_from_list (device); + +error: +mutex_unlock (&fs_devices->device_list_mutex); +mutex_unlock (&uuid_mutex); + +return ret; +} + +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret) +{ +struct btrfs_super_block *disk_super; +struct block_device *bdev; +struct page *page; +int ret = -EINVAL ; +u64 devid; +u64 bytenr; + + bytenr =btrfs_sb_offset (0 ); + flags |=FMODE_EXCL ; + + bdev =blkdev_get_by_path (path, flags, holder); +if (IS_ERR (bdev)) { + ret =PTR_ERR (bdev); + goto error; + } + +if (btrfs_read_disk_super (bdev, bytenr, &page, &disk_super)) + goto error_bdev_put; + + devid =btrfs_stack_device_id (&disk_super->dev_item); + + ret =device_list_remove (disk_super, devid); +if (ret) +pr_err ("BTRFS: %pU: device %s uuid %pU devid %llu failed to unscan: %d" , + disk_super->fsid, path, disk_super->dev_item.uuid, devid, ret); +else +pr_info ("BTRFS: %pU: device %s uuid %pU devid %llu ran undo scan" , + disk_super->fsid, path, disk_super->dev_item.uuid, devid); + +btrfs_release_disk_super (page); + +error_bdev_put: +blkdev_put (bdev, flags); +error: +return ret; +} +/* * Look for a btrfs signature on a device. This may be called out of the mount path * and we are not allowed to call set_blocksize during the scan. The superblock fs/btrfs/volumes.h +2
-0@@ -421,6 +421,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder);int btrfs_scan_one_device (const char *path,fmode_t flags,void *holder,struct btrfs_fs_devices **fs_devices_ret); +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret);int btrfs_close_devices (struct btrfs_fs_devices *fs_devices);void btrfs_close_extra_devices (struct btrfs_fs_devices *fs_devices,int step); void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,include/uapi/linux/btrfs.h +2
-0@@ -739,6 +739,8 @@ enum btrfs_err_code { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
Re: [PATCH 2/2] btrfs: introduce feature to ignore a btrfs device
Quoted 47 lines · Nikolay Borisov
Quoted 44 lines · Anand Jain
Support for a new command is being added here:
btrfs dev ignore <dev>
Which shall undo the effects of the command
btrfs dev scan <dev>This cli/ioctl is needed as there is no way to continue to mount in degraded mode if the device is already scanned, which is required to recover from the split brain raid conditions.
This patch proposes to use ioctl #5 as it was empty.
IOW(BTRFS_IOCTL_MAGIC, 5, ..)If #5 is reserved for some other purpose, I think I should change this.
Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/super.c | 4 +++ fs/btrfs/volumes.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 2 ++ 4 files changed, 78 insertions(+)fs/btrfs/super.c +4
-0@@ -2183,6 +2183,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);break ; +case BTRFS_IOC_IGNORE_DEV : + ret =btrfs_ignore_one_device (vol->name,FMODE_READ , + &btrfs_fs_type, &fs_devices); +break ;case BTRFS_IOC_DEVICES_READY : ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);fs/btrfs/volumes.c +0
-0@@ -1181,6 +1181,76 @@ int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr,return 0 ; }
Quoted 14 lines
fs/btrfs/volumes.c int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, · line 1195
Quoted 12 lines
fs/btrfs/volumes.c +12
-0+static int device_list_remove (struct btrfs_super_block *disk_super,u64 devid) +{ +int ret =0 ; +struct btrfs_fs_devices *fs_devices; +struct btrfs_device *device; + + fs_devices =find_fsid (disk_super->fsid); +if (!fs_devices) +return -ENOENT ; + +if (fs_devices->opened) +return -EPERM ;Isn't
-EBUSYmore appropriate?
Right added.
Thanks, Anand
Quoted 89 lines
Quoted 89 lines
fs/btrfs/volumes.c +58
-0+ +mutex_lock (&uuid_mutex); +mutex_lock (&fs_devices->device_list_mutex); + device =find_device (fs_devices, devid, disk_super->dev_item.uuid); +if (!device) { + ret = -ENOENT ; + goto error; + } + +delete_device_from_list (device); + +error: +mutex_unlock (&fs_devices->device_list_mutex); +mutex_unlock (&uuid_mutex); + +return ret; +} + +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret) +{ +struct btrfs_super_block *disk_super; +struct block_device *bdev; +struct page *page; +int ret = -EINVAL ; +u64 devid; +u64 bytenr; + + bytenr =btrfs_sb_offset (0 ); + flags |=FMODE_EXCL ; + + bdev =blkdev_get_by_path (path, flags, holder); +if (IS_ERR (bdev)) { + ret =PTR_ERR (bdev); + goto error; + } + +if (btrfs_read_disk_super (bdev, bytenr, &page, &disk_super)) + goto error_bdev_put; + + devid =btrfs_stack_device_id (&disk_super->dev_item); + + ret =device_list_remove (disk_super, devid); +if (ret) +pr_err ("BTRFS: %pU: device %s uuid %pU devid %llu failed to unscan: %d" , + disk_super->fsid, path, disk_super->dev_item.uuid, devid, ret); +else +pr_info ("BTRFS: %pU: device %s uuid %pU devid %llu ran undo scan" , + disk_super->fsid, path, disk_super->dev_item.uuid, devid); + +btrfs_release_disk_super (page); + +error_bdev_put: +blkdev_put (bdev, flags); +error: +return ret; +} +/* * Look for a btrfs signature on a device. This may be called out of the mount path * and we are not allowed to call set_blocksize during the scan. The superblock fs/btrfs/volumes.h +2
-0@@ -421,6 +421,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder);int btrfs_scan_one_device (const char *path,fmode_t flags,void *holder,struct btrfs_fs_devices **fs_devices_ret); +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret);int btrfs_close_devices (struct btrfs_fs_devices *fs_devices);void btrfs_close_extra_devices (struct btrfs_fs_devices *fs_devices,int step); void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,include/uapi/linux/btrfs.h +2
-0@@ -739,6 +739,8 @@ enum btrfs_err_code { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
Re: [PATCH 2/2] btrfs: introduce feature to ignore a btrfs device
In reply to Anand JainQuoted 95 lines · Anand Jain
Support for a new command is being added here:
btrfs dev ignore <dev>
Which shall undo the effects of the command
btrfs dev scan <dev>This cli/ioctl is needed as there is no way to continue to mount in degraded mode if the device is already scanned, which is required to recover from the split brain raid conditions.
This patch proposes to use ioctl #5 as it was empty.
IOW(BTRFS_IOCTL_MAGIC, 5, ..)If #5 is reserved for some other purpose, I think I should change this.
Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/super.c | 4 +++ fs/btrfs/volumes.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 2 ++ 4 files changed, 78 insertions(+)fs/btrfs/super.c +4
-0@@ -2183,6 +2183,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);break ; +case BTRFS_IOC_IGNORE_DEV : + ret =btrfs_ignore_one_device (vol->name,FMODE_READ , + &btrfs_fs_type, &fs_devices); +break ;case BTRFS_IOC_DEVICES_READY : ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);fs/btrfs/volumes.c +51
-0@@ -1181,6 +1181,76 @@ int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr,return 0 ; } +static int device_list_remove (struct btrfs_super_block *disk_super,u64 devid) +{ +int ret =0 ; +struct btrfs_fs_devices *fs_devices; +struct btrfs_device *device; + + fs_devices =find_fsid (disk_super->fsid); +if (!fs_devices) +return -ENOENT ; + +if (fs_devices->opened) +return -EPERM ; + +mutex_lock (&uuid_mutex); +mutex_lock (&fs_devices->device_list_mutex); + device =find_device (fs_devices, devid, disk_super->dev_item.uuid); +if (!device) { + ret = -ENOENT ; + goto error; + } + +delete_device_from_list (device); + +error: +mutex_unlock (&fs_devices->device_list_mutex); +mutex_unlock (&uuid_mutex); + +return ret; +} + +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret) +{ +struct btrfs_super_block *disk_super; +struct block_device *bdev; +struct page *page; +int ret = -EINVAL ; +u64 devid; +u64 bytenr; + + bytenr =btrfs_sb_offset (0 ); + flags |=FMODE_EXCL ; + + bdev =blkdev_get_by_path (path, flags, holder); +if (IS_ERR (bdev)) { + ret =PTR_ERR (bdev); + goto error; + } + +if (btrfs_read_disk_super (bdev, bytenr, &page, &disk_super)) + goto error_bdev_put;
fs/btrfs/volumes.c int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, · line 1244
Quoted 10 lines
fs/btrfs/volumes.c +10
-0+ + devid =btrfs_stack_device_id (&disk_super->dev_item); + + ret =device_list_remove (disk_super, devid); +if (ret) +pr_err ("BTRFS: %pU: device %s uuid %pU devid %llu failed to unscan: %d" , + disk_super->fsid, path, disk_super->dev_item.uuid, devid, ret); +else +pr_info ("BTRFS: %pU: device %s uuid %pU devid %llu ran undo scan" , + disk_super->fsid, path, disk_super->dev_item.uuid, devid);
There is already btrfs_err and btrfs_info, use those. This will allow to uniquely identify the failing btrfs file system also the pr_* statements need to be indented after the if/else.
Quoted 39 lines
fs/btrfs/volumes.c +9
-0+ +btrfs_release_disk_super (page); + +error_bdev_put: +blkdev_put (bdev, flags); +error: +return ret; +} +/* * Look for a btrfs signature on a device. This may be called out of the mount path * and we are not allowed to call set_blocksize during the scan. The superblock fs/btrfs/volumes.h +2
-0@@ -421,6 +421,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder);int btrfs_scan_one_device (const char *path,fmode_t flags,void *holder,struct btrfs_fs_devices **fs_devices_ret); +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret);int btrfs_close_devices (struct btrfs_fs_devices *fs_devices);void btrfs_close_extra_devices (struct btrfs_fs_devices *fs_devices,int step); void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,include/uapi/linux/btrfs.h +2
-0@@ -739,6 +739,8 @@ enum btrfs_err_code { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
Re: [PATCH 2/2] btrfs: introduce feature to ignore a btrfs device
Quoted 103 lines · Nikolay Borisov
Quoted 100 lines · Anand Jain
Support for a new command is being added here:
btrfs dev ignore <dev>
Which shall undo the effects of the command
btrfs dev scan <dev>This cli/ioctl is needed as there is no way to continue to mount in degraded mode if the device is already scanned, which is required to recover from the split brain raid conditions.
This patch proposes to use ioctl #5 as it was empty.
IOW(BTRFS_IOCTL_MAGIC, 5, ..)If #5 is reserved for some other purpose, I think I should change this.
Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/super.c | 4 +++ fs/btrfs/volumes.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 2 ++ 4 files changed, 78 insertions(+)fs/btrfs/super.c +4
-0@@ -2183,6 +2183,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);break ; +case BTRFS_IOC_IGNORE_DEV : + ret =btrfs_ignore_one_device (vol->name,FMODE_READ , + &btrfs_fs_type, &fs_devices); +break ;case BTRFS_IOC_DEVICES_READY : ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);fs/btrfs/volumes.c +56
-0@@ -1181,6 +1181,76 @@ int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr,return 0 ; } +static int device_list_remove (struct btrfs_super_block *disk_super,u64 devid) +{ +int ret =0 ; +struct btrfs_fs_devices *fs_devices; +struct btrfs_device *device; + + fs_devices =find_fsid (disk_super->fsid); +if (!fs_devices) +return -ENOENT ; + +if (fs_devices->opened) +return -EPERM ; + +mutex_lock (&uuid_mutex); +mutex_lock (&fs_devices->device_list_mutex); + device =find_device (fs_devices, devid, disk_super->dev_item.uuid); +if (!device) { + ret = -ENOENT ; + goto error; + } + +delete_device_from_list (device); + +error: +mutex_unlock (&fs_devices->device_list_mutex); +mutex_unlock (&uuid_mutex); + +return ret; +} + +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret) +{ +struct btrfs_super_block *disk_super; +struct block_device *bdev; +struct page *page; +int ret = -EINVAL ; +u64 devid; +u64 bytenr; + + bytenr =btrfs_sb_offset (0 ); + flags |=FMODE_EXCL ; + + bdev =blkdev_get_by_path (path, flags, holder); +if (IS_ERR (bdev)) { + ret =PTR_ERR (bdev); + goto error; + } + +if (btrfs_read_disk_super (bdev, bytenr, &page, &disk_super)) + goto error_bdev_put; + + devid =btrfs_stack_device_id (&disk_super->dev_item); + + ret =device_list_remove (disk_super, devid); +if (ret)
Quoted 8 lines
fs/btrfs/volumes.c int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, · line 1244
Quoted 5 lines
fs/btrfs/volumes.c +5
-0+pr_err ("BTRFS: %pU: device %s uuid %pU devid %llu failed to unscan: %d" , + disk_super->fsid, path, disk_super->dev_item.uuid, devid, ret); + else + pr_info("BTRFS: %pU: device %s uuid %pU devid %llu ran undo scan", + disk_super->fsid, path, disk_super->dev_item.uuid, devid);There is already
btrfs_errandbtrfs_info, use those. This will allow to uniquely identify the failing btrfs file system
We don't have fs_info in this context, btrfs_err/info can't be used.
Quoted 2 lines
also the pr_* statements
need to be indented after the if/else.
Will do.
Thanks, Anand
Quoted 44 lines
Quoted 31 lines
fs/btrfs/volumes.c +9
-0+ +btrfs_release_disk_super (page); + +error_bdev_put: +blkdev_put (bdev, flags); +error: +return ret; +} +/* * Look for a btrfs signature on a device. This may be called out of the mount path * and we are not allowed to call set_blocksize during the scan. The superblock fs/btrfs/volumes.h +2
-0@@ -421,6 +421,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder);int btrfs_scan_one_device (const char *path,fmode_t flags,void *holder,struct btrfs_fs_devices **fs_devices_ret); +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret);int btrfs_close_devices (struct btrfs_fs_devices *fs_devices);void btrfs_close_extra_devices (struct btrfs_fs_devices *fs_devices,int step); void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,include/uapi/linux/btrfs.h +0
-0include/uapi/linux/btrfs.h enum btrfs_err_code { · line 746
Quoted 8 lines
include/uapi/linux/btrfs.h +2
-0@@ -739,6 +739,8 @@ enum btrfs_err_code { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks --
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
Re: [PATCH 2/2] btrfs: introduce feature to ignore a btrfs device
Quoted 120 lines · Anand Jain
Quoted 108 lines · Nikolay Borisov
Quoted 105 lines · Anand Jain
Support for a new command is being added here:
btrfs dev ignore <dev>
Which shall undo the effects of the command
btrfs dev scan <dev>This cli/ioctl is needed as there is no way to continue to mount in degraded mode if the device is already scanned, which is required to recover from the split brain raid conditions.
This patch proposes to use ioctl #5 as it was empty.
IOW(BTRFS_IOCTL_MAGIC, 5, ..)
If #5 is reserved for some other purpose, I think I should change this.Signed-off-by Anand Jain <[email protected]>---
fs/btrfs/super.c | 4 +++
fs/btrfs/volumes.c | 70
++++++++++++++++++++++++++++++++++++++++++++++
fs/btrfs/volumes.h | 2 ++
include/uapi/linux/btrfs.h| 2 ++4 files changed, 78 insertions(+)fs/btrfs/super.c +4
-0@@ -2183,6 +2183,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, ret = btrfs_scan_one_device(vol->name, FMODE_READ, &btrfs_fs_type, &fs_devices); break; + case BTRFS_IOC_IGNORE_DEV: + ret = btrfs_ignore_one_device(vol->name, FMODE_READ, + &btrfs_fs_type, &fs_devices); + break;case
BTRFS_IOC_DEVICES_READY:
ret =btrfs_scan_one_device(vol->name, FMODE_READ, &btrfs_fs_type, &fs_devices);fs/btrfs/volumes.c +0
-0@@ -1181,6 +1181,76 @@ int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, return 0; }+static int
device_list_remove(struct btrfs_super_block *disk_super, u64 devid)fs/btrfs/volumes.c +30
-0+{ + int ret = 0; + struct btrfs_fs_devices *fs_devices; + struct btrfs_device *device; + + fs_devices = find_fsid(disk_super->fsid); + if (!fs_devices) + return -ENOENT; + + if (fs_devices->opened) + return -EPERM; + + mutex_lock(&uuid_mutex); + mutex_lock(&fs_devices->device_list_mutex); + device = find_device(fs_devices, devid, disk_super->dev_item.uuid); + if (!device) { + ret = -ENOENT; + goto error; + } + + delete_device_from_list(device); + +error: + mutex_unlock(&fs_devices->device_list_mutex); + mutex_unlock(&uuid_mutex); + + return ret; +} + +int btrfs_ignore_one_device(const char *path, fmode_t flags, void*holder,
+ structbtrfs_fs_devices**fs_devices_ret)fs/btrfs/volumes.c +25
-0+{ + struct btrfs_super_block *disk_super; + struct block_device *bdev; + struct page *page; + int ret = -EINVAL; + u64 devid; + u64 bytenr; + + bytenr = btrfs_sb_offset(0); + flags |= FMODE_EXCL; + + bdev = blkdev_get_by_path(path, flags, holder); + if (IS_ERR(bdev)) { + ret = PTR_ERR(bdev); + goto error; + } + + if (btrfs_read_disk_super(bdev, bytenr, &page, &disk_super)) + goto error_bdev_put; + + devid = btrfs_stack_device_id(&disk_super->dev_item); + + ret = device_list_remove(disk_super, devid); + if (ret) + pr_err("BTRFS: %pU: device %s uuid %pU devid %llu failed toQuoted 8 lines
Quoted 5 lines
unscan: %d",
+disk_super->fsid, path,disk_super->dev_item.uuid, devid, ret); + else
+ pr_info("BTRFS: %pU: device %s uuid %pU devid %llu ran undo scan", +disk_super->fsid, path,disk_super->dev_item.uuid, devid);There is already
btrfs_errandbtrfs_info, use those. This will allow to uniquely identify the failing btrfs file system
Quoted 1 line
We don't have
fs_infoin this context, btrfs_err/info can't be used.
Yes, but we have struct file in btrfs_control_ioctl then can't we do :
struct btrfs_fs_info = btrfs_sb(file_inode(file)->i_sb)
Quoted 59 lines
Quoted 3 lines
also the pr_* statements
need to be indented after the if/else.Will do.
Thanks, Anand
Quoted 50 lines
Quoted 45 lines
fs/btrfs/volumes.c +9
-0+ + btrfs_release_disk_super(page); + +error_bdev_put: + blkdev_put(bdev, flags); +error: + return ret; +} +/*
* Look for a btrfs signature on a device. This may be called out of the mount path
* and we are not allowed to callset_blocksizeduring the scan. The superblockfs/btrfs/volumes.h +0
-0@@ -421,6 +421,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder);int btrfs_scan_one_device(const char *path,
fmode_tflags, void *holder,
structbtrfs_fs_devices**fs_devices_ret); +int btrfs_ignore_one_device(const char *path,fmode_tflags, void *holder,
+ structbtrfs_fs_devices**fs_devices_ret); intbtrfs_close_devices(struct btrfs_fs_devices *fs_devices); voidbtrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step);
void btrfs_assign_next_active_device(structbtrfs_fs_info*fs_info,include/uapi/linux/btrfs.h +2
-0@@ -739,6 +739,8 @@ enum btrfs_err_code { struct btrfs_ioctl_vol_args) #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args) /* trans start and trans end are dangerous, and only for* use by applications that know how to avoid the * resulting deadlocks 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.html
Re: [PATCH 2/2] btrfs: introduce feature to ignore a btrfs device
Quoted 123 lines · Nikolay Borisov
Quoted 120 lines · Anand Jain
Quoted 116 lines · Nikolay Borisov
Quoted 105 lines · Anand Jain
Support for a new command is being added here:
btrfs dev ignore <dev>
Which shall undo the effects of the command
btrfs dev scan <dev>This cli/ioctl is needed as there is no way to continue to mount in degraded mode if the device is already scanned, which is required to recover from the split brain raid conditions.
This patch proposes to use ioctl #5 as it was empty.
IOW(BTRFS_IOCTL_MAGIC, 5, ..)
If #5 is reserved for some other purpose, I think I should change this.Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/super.c | 4 +++ fs/btrfs/volumes.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 2 ++ 4 files changed, 78 insertions(+)fs/btrfs/super.c +4
-0@@ -2183,6 +2183,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, ret = btrfs_scan_one_device(vol->name, FMODE_READ, &btrfs_fs_type, &fs_devices); break; + case BTRFS_IOC_IGNORE_DEV: + ret = btrfs_ignore_one_device(vol->name, FMODE_READ, + &btrfs_fs_type, &fs_devices); + break; case BTRFS_IOC_DEVICES_READY: ret = btrfs_scan_one_device(vol->name, FMODE_READ,
&btrfs_fs_type,&fs_devices);fs/btrfs/volumes.c +56
-0@@ -1181,6 +1181,76 @@ int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, return 0; } +static int device_list_remove(struct btrfs_super_block *disk_super,u64 devid) +{ + int ret = 0; + struct btrfs_fs_devices *fs_devices; + struct btrfs_device *device; + + fs_devices = find_fsid(disk_super->fsid); + if (!fs_devices) + return -ENOENT; + + if (fs_devices->opened) + return -EPERM; + + mutex_lock(&uuid_mutex); + mutex_lock(&fs_devices->device_list_mutex); + device = find_device(fs_devices, devid, disk_super->dev_item.uuid); + if (!device) { + ret = -ENOENT; + goto error; + } + + delete_device_from_list(device); + +error: + mutex_unlock(&fs_devices->device_list_mutex); + mutex_unlock(&uuid_mutex); + + return ret; +} + +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, + struct btrfs_fs_devices **fs_devices_ret) +{ + struct btrfs_super_block *disk_super; + struct block_device *bdev; + struct page *page; + int ret = -EINVAL; + u64 devid; + u64 bytenr; + + bytenr = btrfs_sb_offset(0); + flags |= FMODE_EXCL; + + bdev = blkdev_get_by_path(path, flags, holder); + if (IS_ERR(bdev)) { + ret = PTR_ERR(bdev); + goto error; + } + + if (btrfs_read_disk_super(bdev, bytenr, &page, &disk_super)) + goto error_bdev_put; + + devid = btrfs_stack_device_id(&disk_super->dev_item); + + ret = device_list_remove(disk_super, devid); + if (ret) + pr_err("BTRFS: %pU: device %s uuid %pU devid %llu failed toQuoted 5 lines
unscan: %d",
+disk_super->fsid, path,disk_super->dev_item.uuid, devid, ret); + else
+ pr_info("BTRFS: %pU: device %s uuid %pU devid %llu ran undo scan", +disk_super->fsid, path,disk_super->dev_item.uuid, devid);There is already
btrfs_errandbtrfs_info, use those. This will allow to uniquely identify the failing btrfs file system
Quoted 5 lines
Quoted 1 line
We don't have
fs_infoin this context, btrfs_err/info can't be used.Yes, but we have struct file in
btrfs_control_ioctlthen can't we do :struct
btrfs_fs_info= btrfs_sb(file_inode(file)->i_sb)
Nikolay, We are in the device scan context where btrfs_fs_info does not exist yet.
Thanks, Anand
Quoted 65 lines
Quoted 60 lines
Quoted 4 lines
also the pr_* statements
need to be indented after the if/else.Will do.
Thanks, Anand
Quoted 50 lines
Quoted 45 lines
fs/btrfs/volumes.c +9
-0+ + btrfs_release_disk_super(page); + +error_bdev_put: + blkdev_put(bdev, flags); +error: + return ret; +} + /** Look for a btrfs signature on a device. This may be called out of the mount path
* and we are not allowed to callset_blocksizeduring the scan.
The superblockfs/btrfs/volumes.h +2
-0@@ -421,6 +421,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder); int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, struct btrfs_fs_devices **fs_devices_ret); +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, + struct btrfs_fs_devices **fs_devices_ret);int
btrfs_close_devices(struct btrfs_fs_devices *fs_devices); void btrfs_close_extra_devices(structbtrfs_fs_devices*fs_devices,
int step);
void btrfs_assign_next_active_device(structbtrfs_fs_info*fs_info,include/uapi/linux/btrfs.h +2
-0@@ -739,6 +739,8 @@ enum btrfs_err_code { struct btrfs_ioctl_vol_args) #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args) /* trans start and trans end are dangerous, and only for* use by applications that know how to avoid the * resulting deadlocks 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.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 1/1 btrfs-progs: add 'btrfs device ignore' cli
In reply to Anand JainThis patch adds
btrfs device ignode <dev>
so that a device can be ignored/missed during mount if the device is already been scanned. Basically, this command will undo the effect of the command
btrfs device scan <dev>
This change is compatible with older kernel without the ioctl BTRFS_IOC_IGNORE_DEV which is added here. At which it shall report 'Inappropriate ioctl for device'. And will report 'Operation not permitted' on mounted device.
--- cmds-device.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ioctl.h | 2 ++ 2 files changed, 56 insertions(+)
cmds-device.c +54 -0
@@ -320,6 +320,59 @@ out:return !!ret; } +static const char *const cmd_device_ignore_usage[] = { +"btrfs device ignore [<device>]" , +"Ignore a device in the btrfs kernel module." , +NULL +}; + +static int btrfs_ignore_one_device (char *path) +{ +struct btrfs_ioctl_vol_args args; +int fd; +int ret; + + fd =open ("/dev/btrfs-control" ,O_RDWR ); +if (fd <0 ) +return -errno; + +memset (&args,0 ,sizeof (args)); +strncpy_null (args.name, path); + ret =ioctl (fd,BTRFS_IOC_IGNORE_DEV , &args); +if (ret) + ret = -errno; +close (fd); +return ret; +} + +static int cmd_device_ignore (int argc,char **argv) +{ +int ret =0 ; +char *path; + +if (check_argc_max (argc - optind,1 )) +usage (cmd_device_ignore_usage); + +if (is_block_device (argv[1 ]) !=1 ) { +error ("Not a block device: %s" , argv[1 ]); +return -ENOENT ; + } + + path =canonicalize_path (argv[1 ]); +if (!path) { +error ("Could not canonicalize path '%s': %s" , + argv[1 ],strerror (errno)); +return -ENOENT ; + } + + ret =btrfs_ignore_one_device (path); +if (ret) +error ("Can't ignore %s: %s" , path,strerror (-ret)); + +free (path); +return ret; +} +static const char *const cmd_device_ready_usage[] = {"btrfs device ready <device>" ,"Check device to see if it has all of its devices in cache for mounting" ,
@@ -595,6 +648,7 @@ const struct cmd_group device_cmd_group = { CMD_ALIAS }, { "remove", cmd_device_remove, cmd_device_remove_usage, NULL, 0 }, { "scan", cmd_device_scan, cmd_device_scan_usage, NULL, 0 }, + { "ignore", cmd_device_ignore, cmd_device_ignore_usage, NULL, 0 }, { "ready", cmd_device_ready, cmd_device_ready_usage, NULL, 0 }, { "stats", cmd_device_stats, cmd_device_stats_usage, NULL, 0 }, { "usage", cmd_device_usage,
ioctl.h +2 -0
@@ -721,6 +721,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
Signature · 1 line
2.13.1
PATCH v2 1/2 btrfs: add function to device list delete
In reply to Anand JainWe need device delete from the dev_list so create a new function, instead of refactor of btrfs_free_stale_device() because, btrfs_free_stale_device() doesn't hold device_list_mutex which is actually needed here.
---
v1: title of this patch
btrfs: refactor btrfs_free_stale_device() to get device list delete
v2:
add new function instead of peal from btrfs_free_stale_device() to delete a device from the device list, since btrfs_free_stale_device() does not hold device_list_mutex, may be it can be fixed later.
/btrfs/volumes.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
fs/btrfs/volumes.c +21 -0
@@ -546,6 +546,27 @@ static void pending_bios_fn(struct btrfs_work *work)run_scheduled_bios (device); } +static void delete_device_from_list (struct btrfs_device *device) +{ +struct btrfs_fs_devices *fs_devices; + fs_devices = device->fs_devices; + +lockdep_assert_held (&uuid_mutex); + +mutex_lock (&fs_devices->device_list_mutex); + fs_devices->num_devices--; +list_del (&device->dev_list); +mutex_unlock (&fs_devices->device_list_mutex); + +rcu_string_free (device->name); +kfree (device); + +if (fs_devices->num_devices ==0 ) { +btrfs_sysfs_remove_fsid (fs_devices); +list_del (&fs_devices->list); +free_fs_devices (fs_devices); + } +}void btrfs_free_stale_device (struct btrfs_device *cur_dev) {
Signature · 1 line
2.15.0
PATCH v2 2/2 btrfs: introduce feature to ignore a btrfs device
Support for a new command is being added here:
btrfs dev ignore <dev>
Which shall undo the effects of the command
btrfs dev scan <dev>
This cli/ioctl is needed as there is no way to continue to mount in degraded mode if the device is already scanned, which is required to recover from the split brain raid conditions.
This patch proposes to use ioctl #5 as it was empty.
IOW(BTRFS_IOCTL_MAGIC, 5, ..)
If #5 is reserved for some other purpose, I think I should change this.
---
v2: Use -EBUSY instead of -ENOENT
Since now delete_device_from_list() holds device_list_mutex more fine grined as required, so dont hole device_list_mutex here. Reword and indent pr_err/info.
fs/btrfs/super.c | 4 +++ fs/btrfs/volumes.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 2 ++ 4 files changed, 72 insertions(+)
fs/btrfs/super.c +4 -0
@@ -2183,6 +2183,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);break ; +case BTRFS_IOC_IGNORE_DEV : + ret =btrfs_ignore_one_device (vol->name,FMODE_READ , + &btrfs_fs_type, &fs_devices); +break ;case BTRFS_IOC_DEVICES_READY : ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);
fs/btrfs/volumes.c +64 -0
70 lines not on this page · raw message
fs/btrfs/volumes.h +2 -0
@@ -421,6 +421,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder);int btrfs_scan_one_device (const char *path,fmode_t flags,void *holder,struct btrfs_fs_devices **fs_devices_ret); +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret);int btrfs_close_devices (struct btrfs_fs_devices *fs_devices);void btrfs_close_extra_devices (struct btrfs_fs_devices *fs_devices,int step); void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,
include/uapi/linux/btrfs.h +2 -0
@@ -740,6 +740,8 @@ enum btrfs_err_code { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
Signature · 1 line
2.15.0
Re: [PATCH v2 1/2] btrfs: add function to device list delete
In reply to Anand JainWrong ML. Pls ignore.
Thanks, Anand
Quoted 52 lines · Anand Jain
We need device delete from the
dev_listso create a new function, instead of refactor ofbtrfs_free_stale_device()because,btrfs_free_stale_device()doesn't holddevice_list_mutexwhich is actually needed here.Signed-off-by Anand Jain <[email protected]>---
v1: title of this patch
btrfs: refactorbtrfs_free_stale_device()to get device list delete
v2:
add new function instead of peal frombtrfs_free_stale_device()to delete a device from the device list, sincebtrfs_free_stale_device()does not holddevice_list_mutex, may be it can be fixed later./btrfs/volumes.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)fs/btrfs/volumes.c +21
-0@@ -546,6 +546,27 @@ static void pending_bios_fn(struct btrfs_work *work)run_scheduled_bios (device); } +static void delete_device_from_list (struct btrfs_device *device) +{ +struct btrfs_fs_devices *fs_devices; + fs_devices = device->fs_devices; + +lockdep_assert_held (&uuid_mutex); + +mutex_lock (&fs_devices->device_list_mutex); + fs_devices->num_devices--; +list_del (&device->dev_list); +mutex_unlock (&fs_devices->device_list_mutex); + +rcu_string_free (device->name); +kfree (device); + +if (fs_devices->num_devices ==0 ) { +btrfs_sysfs_remove_fsid (fs_devices); +list_del (&fs_devices->list); +free_fs_devices (fs_devices); + } +}void btrfs_free_stale_device (struct btrfs_device *cur_dev) {
PATCH v3 1/2 btrfs: add function to device list delete
In reply to Anand JainWe need device delete from the dev_list so create a new function. New instead of refactor of btrfs_free_stale_device() because, btrfs_free_stale_device() doesn't hold device_list_mutex which is actually needed here.
---
v1: title of this patch
btrfs: refactor btrfs_free_stale_device() to get device list delete
v2:
delete_device_from_list() is not pealed from btrfs_free_stale_device() as this needs device_list_mutex. And its static now.
v3: Send to correct ML
fs/btrfs/volumes.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
fs/btrfs/volumes.c +21 -0
@@ -546,6 +546,27 @@ static void pending_bios_fn(struct btrfs_work *work)run_scheduled_bios (device); } +static void delete_device_from_list (struct btrfs_device *device) +{ +struct btrfs_fs_devices *fs_devices; + fs_devices = device->fs_devices; + +lockdep_assert_held (&uuid_mutex); + +mutex_lock (&fs_devices->device_list_mutex); + fs_devices->num_devices--; +list_del (&device->dev_list); +mutex_unlock (&fs_devices->device_list_mutex); + +rcu_string_free (device->name); +kfree (device); + +if (fs_devices->num_devices ==0 ) { +btrfs_sysfs_remove_fsid (fs_devices); +list_del (&fs_devices->list); +free_fs_devices (fs_devices); + } +}void btrfs_free_stale_device (struct btrfs_device *cur_dev) {
Signature · 6 lines
2.15.0 -- 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-
PATCH v3 2/2 btrfs: introduce feature to ignore a btrfs device
Support for a new command is being added here:
btrfs dev ignore <dev>
Which shall undo the effects of the command
btrfs dev scan <dev>
This cli/ioctl is needed as there is no way to continue to mount in degraded mode if the device is already scanned, which is required to recover from the split brain raid conditions.
This patch proposes to use ioctl #5 as it was empty.
IOW(BTRFS_IOCTL_MAGIC, 5, ..)
If #5 is reserved for some other purpose, I think I should change this.
---
v2: Use -EBUSY instead of -ENOENT
Since now delete_device_from_list() holds device_list_mutex so dont hold device_list_mutex in its parent. Reword and indent pr_err/info.
v3: Send to correct ML
fs/btrfs/super.c | 4 +++ fs/btrfs/volumes.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 2 ++ 4 files changed, 72 insertions(+)
fs/btrfs/super.c +4 -0
@@ -2183,6 +2183,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);break ; +case BTRFS_IOC_IGNORE_DEV : + ret =btrfs_ignore_one_device (vol->name,FMODE_READ , + &btrfs_fs_type, &fs_devices); +break ;case BTRFS_IOC_DEVICES_READY : ret =btrfs_scan_one_device (vol->name,FMODE_READ , &btrfs_fs_type, &fs_devices);
fs/btrfs/volumes.c +64 -0
70 lines not on this page · raw message
fs/btrfs/volumes.h +2 -0
@@ -421,6 +421,8 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, fmode_t flags, void *holder);int btrfs_scan_one_device (const char *path,fmode_t flags,void *holder,struct btrfs_fs_devices **fs_devices_ret); +int btrfs_ignore_one_device (const char *path,fmode_t flags,void *holder, +struct btrfs_fs_devices **fs_devices_ret);int btrfs_close_devices (struct btrfs_fs_devices *fs_devices);void btrfs_close_extra_devices (struct btrfs_fs_devices *fs_devices,int step); void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,
include/uapi/linux/btrfs.h +2 -0
@@ -740,6 +740,8 @@ enum btrfs_err_code { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_IGNORE_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_vol_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
Signature · 6 lines
2.15.0 -- 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