* [PATCH 0/2] Btrfs-progs: device delete to accept devid @ 2015-08-14 10:36 Anand Jain 2015-08-14 10:36 ` [PATCH 1/2] btrfs-progs: move is_numerical to utils-lib.h and make it non static Anand Jain 2015-08-14 10:36 ` [PATCH 2/2] btrfs-progs: device delete to accept devid Anand Jain 0 siblings, 2 replies; 10+ messages in thread From: Anand Jain @ 2015-08-14 10:36 UTC (permalink / raw) To: linux-btrfs; +Cc: clm, dsterba This is btrfs-progs side of the patch. Kernel patch is Btrfs: device delete by devid Anand Jain (2): btrfs-progs: move is_numerical to utils-lib.h and make it non static btrfs-progs: device delete to accept devid Documentation/btrfs-device.asciidoc | 2 +- cmds-device.c | 45 ++++++++++++++++++++++++++++--------- cmds-replace.c | 11 --------- ioctl.h | 8 +++++++ utils-lib.c | 11 +++++++++ utils.h | 1 + 6 files changed, 56 insertions(+), 22 deletions(-) -- 2.4.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2] btrfs-progs: move is_numerical to utils-lib.h and make it non static 2015-08-14 10:36 [PATCH 0/2] Btrfs-progs: device delete to accept devid Anand Jain @ 2015-08-14 10:36 ` Anand Jain 2015-08-14 10:36 ` [PATCH 2/2] btrfs-progs: device delete to accept devid Anand Jain 1 sibling, 0 replies; 10+ messages in thread From: Anand Jain @ 2015-08-14 10:36 UTC (permalink / raw) To: linux-btrfs; +Cc: clm, dsterba Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-replace.c | 11 ----------- utils-lib.c | 11 +++++++++++ utils.h | 1 + 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cmds-replace.c b/cmds-replace.c index 85365e3..e6a27e3 100644 --- a/cmds-replace.c +++ b/cmds-replace.c @@ -65,17 +65,6 @@ static const char * const replace_cmd_group_usage[] = { NULL }; -static int is_numerical(const char *str) -{ - if (!(*str >= '0' && *str <= '9')) - return 0; - while (*str >= '0' && *str <= '9') - str++; - if (*str != '\0') - return 0; - return 1; -} - static int dev_replace_cancel_fd = -1; static void dev_replace_sigint_handler(int signal) { diff --git a/utils-lib.c b/utils-lib.c index 79ef35e..9ac0b7b 100644 --- a/utils-lib.c +++ b/utils-lib.c @@ -38,3 +38,14 @@ u64 arg_strtou64(const char *str) } return value; } + +int is_numerical(const char *str) +{ + if (!(*str >= '0' && *str <= '9')) + return 0; + while (*str >= '0' && *str <= '9') + str++; + if (*str != '\0') + return 0; + return 1; +} diff --git a/utils.h b/utils.h index 94606ed..0975301 100644 --- a/utils.h +++ b/utils.h @@ -243,5 +243,6 @@ int btrfs_tree_search2_ioctl_supported(int fd); int btrfs_check_nodesize(u32 nodesize, u32 sectorsize); const char *get_argv0_buf(void); +int is_numerical(const char *str); #endif -- 2.4.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/2] btrfs-progs: device delete to accept devid 2015-08-14 10:36 [PATCH 0/2] Btrfs-progs: device delete to accept devid Anand Jain 2015-08-14 10:36 ` [PATCH 1/2] btrfs-progs: move is_numerical to utils-lib.h and make it non static Anand Jain @ 2015-08-14 10:36 ` Anand Jain 2015-08-17 7:00 ` Goffredo Baroncelli 2015-08-20 11:29 ` Goffredo Baroncelli 1 sibling, 2 replies; 10+ messages in thread From: Anand Jain @ 2015-08-14 10:36 UTC (permalink / raw) To: linux-btrfs; +Cc: clm, dsterba This patch introduces new option <devid> for the command btrfs device delete <device_path|devid>[..] <mnt> In a user reported issue on a 3-disk-RAID1, one disk failed with its SB unreadable. Now with this patch user will have a choice to delete the device using devid. The other method we could do, is to match the input device_path to the available device_paths with in the kernel. But that won't work in all the cases, like what if user provided mapper path when the path within the kernel is a non-mapper path. This patch depends on the below kernel patch for the new feature to work, however it will fail-back to the old interface for the kernel without the patch Btrfs: device delete by devid Signed-off-by: Anand Jain <anand.jain@oracle.com> --- Documentation/btrfs-device.asciidoc | 2 +- cmds-device.c | 45 ++++++++++++++++++++++++++++--------- ioctl.h | 8 +++++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/Documentation/btrfs-device.asciidoc b/Documentation/btrfs-device.asciidoc index 2827598..61ede6e 100644 --- a/Documentation/btrfs-device.asciidoc +++ b/Documentation/btrfs-device.asciidoc @@ -74,7 +74,7 @@ do not perform discard by default -f|--force:::: force overwrite of existing filesystem on the given disk(s) -*remove* <dev> [<dev>...] <path>:: +*remove* <dev>|<devid> [<dev>|<devid>...] <path>:: Remove device(s) from a filesystem identified by <path>. *delete* <dev> [<dev>...] <path>:: diff --git a/cmds-device.c b/cmds-device.c index 0e60500..eb4358d 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -164,16 +164,34 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) struct btrfs_ioctl_vol_args arg; int res; - if (!is_block_device(argv[i])) { + struct btrfs_ioctl_vol_args_v3 argv3 = {0}; + int its_num = false; + + if (is_numerical(argv[i])) { + argv3.devid = arg_strtou64(argv[i]); + its_num = true; + } else if (is_block_device(argv[i])) { + strncpy_null(argv3.name, argv[i]); + } else { fprintf(stderr, - "ERROR: %s is not a block device\n", argv[i]); + "ERROR: %s is not a block device or devid\n", argv[i]); ret++; continue; } - memset(&arg, 0, sizeof(arg)); - strncpy_null(arg.name, argv[i]); - res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV_V2, &argv3); e = errno; + if (res && e == ENOTTY) { + if (its_num) { + fprintf(stderr, + "Error: Kernel does not support delete by devid\n"); + ret = 1; + continue; + } + memset(&arg, 0, sizeof(arg)); + strncpy_null(arg.name, argv[i]); + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); + e = errno; + } if (res) { const char *msg; @@ -181,9 +199,16 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) msg = btrfs_err_str(res); else msg = strerror(e); - fprintf(stderr, - "ERROR: error removing the device '%s' - %s\n", - argv[i], msg); + + if (its_num) + fprintf(stderr, + "ERROR: error removing the devid '%llu' - %s\n", + argv3.devid, msg); + else + fprintf(stderr, + "ERROR: error removing the device '%s' - %s\n", + argv[i], msg); + ret++; } } @@ -193,7 +218,7 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) } static const char * const cmd_rm_dev_usage[] = { - "btrfs device remove <device> [<device>...] <path>", + "btrfs device remove <device>|<devid> [<device>|<devid>...] <path>", "Remove a device from a filesystem", NULL }; @@ -204,7 +229,7 @@ static int cmd_rm_dev(int argc, char **argv) } static const char * const cmd_del_dev_usage[] = { - "btrfs device delete <device> [<device>...] <path>", + "btrfs device delete <device>|<devid> [<device>|<devid>...] <path>", "Remove a device from a filesystem", NULL }; diff --git a/ioctl.h b/ioctl.h index dff015a..6870931 100644 --- a/ioctl.h +++ b/ioctl.h @@ -40,6 +40,12 @@ struct btrfs_ioctl_vol_args { char name[BTRFS_PATH_NAME_MAX + 1]; }; +struct btrfs_ioctl_vol_args_v3 { + __s64 fd; + char name[BTRFS_PATH_NAME_MAX + 1]; + __u64 devid; +}; + #define BTRFS_DEVICE_PATH_NAME_MAX 1024 #define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0) @@ -683,6 +689,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) struct btrfs_ioctl_feature_flags[2]) #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ struct btrfs_ioctl_feature_flags[3]) +#define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \ + struct btrfs_ioctl_vol_args_v3) #ifdef __cplusplus } #endif -- 2.4.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: device delete to accept devid 2015-08-14 10:36 ` [PATCH 2/2] btrfs-progs: device delete to accept devid Anand Jain @ 2015-08-17 7:00 ` Goffredo Baroncelli 2015-08-17 11:17 ` Anand Jain 2015-08-20 11:29 ` Goffredo Baroncelli 1 sibling, 1 reply; 10+ messages in thread From: Goffredo Baroncelli @ 2015-08-17 7:00 UTC (permalink / raw) To: Anand Jain, linux-btrfs; +Cc: clm, dsterba On 2015-08-14 12:36, Anand Jain wrote: > This patch introduces new option <devid> for the command > > btrfs device delete <device_path|devid>[..] <mnt> > > In a user reported issue on a 3-disk-RAID1, one disk failed with its > SB unreadable. Now with this patch user will have a choice to delete > the device using devid. > > The other method we could do, is to match the input device_path > to the available device_paths with in the kernel. But that won't > work in all the cases, like what if user provided mapper path > when the path within the kernel is a non-mapper path. > > This patch depends on the below kernel patch for the new feature to work, > however it will fail-back to the old interface for the kernel without the > patch > > Btrfs: device delete by devid > > Signed-off-by: Anand Jain <anand.jain@oracle.com> > --- > Documentation/btrfs-device.asciidoc | 2 +- > cmds-device.c | 45 ++++++++++++++++++++++++++++--------- > ioctl.h | 8 +++++++ > 3 files changed, 44 insertions(+), 11 deletions(-) > > diff --git a/Documentation/btrfs-device.asciidoc b/Documentation/btrfs-device.asciidoc > index 2827598..61ede6e 100644 > --- a/Documentation/btrfs-device.asciidoc > +++ b/Documentation/btrfs-device.asciidoc > @@ -74,7 +74,7 @@ do not perform discard by default > -f|--force:::: > force overwrite of existing filesystem on the given disk(s) > > -*remove* <dev> [<dev>...] <path>:: > +*remove* <dev>|<devid> [<dev>|<devid>...] <path>:: > Remove device(s) from a filesystem identified by <path>. > > *delete* <dev> [<dev>...] <path>:: also here is missing <devid> (below you added) > diff --git a/cmds-device.c b/cmds-device.c > index 0e60500..eb4358d 100644 > --- a/cmds-device.c > +++ b/cmds-device.c > @@ -164,16 +164,34 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) > struct btrfs_ioctl_vol_args arg; > int res; > > - if (!is_block_device(argv[i])) { > + struct btrfs_ioctl_vol_args_v3 argv3 = {0}; > + int its_num = false; > + > + if (is_numerical(argv[i])) { > + argv3.devid = arg_strtou64(argv[i]); > + its_num = true; > + } else if (is_block_device(argv[i])) { > + strncpy_null(argv3.name, argv[i]); > + } else { > fprintf(stderr, > - "ERROR: %s is not a block device\n", argv[i]); > + "ERROR: %s is not a block device or devid\n", argv[i]); > ret++; > continue; > } > - memset(&arg, 0, sizeof(arg)); > - strncpy_null(arg.name, argv[i]); > - res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); > + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV_V2, &argv3); > e = errno; > + if (res && e == ENOTTY) { > + if (its_num) { > + fprintf(stderr, > + "Error: Kernel does not support delete by devid\n"); > + ret = 1; > + continue; > + } > + memset(&arg, 0, sizeof(arg)); > + strncpy_null(arg.name, argv[i]); > + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); > + e = errno; > + } > if (res) { > const char *msg; > > @@ -181,9 +199,16 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) > msg = btrfs_err_str(res); > else > msg = strerror(e); > - fprintf(stderr, > - "ERROR: error removing the device '%s' - %s\n", > - argv[i], msg); > + > + if (its_num) > + fprintf(stderr, > + "ERROR: error removing the devid '%llu' - %s\n", > + argv3.devid, msg); > + else > + fprintf(stderr, > + "ERROR: error removing the device '%s' - %s\n", > + argv[i], msg); > + > ret++; > } > } > @@ -193,7 +218,7 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) > } > > static const char * const cmd_rm_dev_usage[] = { > - "btrfs device remove <device> [<device>...] <path>", > + "btrfs device remove <device>|<devid> [<device>|<devid>...] <path>", > "Remove a device from a filesystem", > NULL > }; > @@ -204,7 +229,7 @@ static int cmd_rm_dev(int argc, char **argv) > } > > static const char * const cmd_del_dev_usage[] = { > - "btrfs device delete <device> [<device>...] <path>", > + "btrfs device delete <device>|<devid> [<device>|<devid>...] <path>", > "Remove a device from a filesystem", > NULL > }; > diff --git a/ioctl.h b/ioctl.h > index dff015a..6870931 100644 > --- a/ioctl.h > +++ b/ioctl.h > @@ -40,6 +40,12 @@ struct btrfs_ioctl_vol_args { > char name[BTRFS_PATH_NAME_MAX + 1]; > }; > > +struct btrfs_ioctl_vol_args_v3 { > + __s64 fd; > + char name[BTRFS_PATH_NAME_MAX + 1]; > + __u64 devid; > +}; > + > #define BTRFS_DEVICE_PATH_NAME_MAX 1024 > > #define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0) > @@ -683,6 +689,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) > struct btrfs_ioctl_feature_flags[2]) > #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ > struct btrfs_ioctl_feature_flags[3]) > +#define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \ > + struct btrfs_ioctl_vol_args_v3) > #ifdef __cplusplus > } > #endif > -- gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: device delete to accept devid 2015-08-17 7:00 ` Goffredo Baroncelli @ 2015-08-17 11:17 ` Anand Jain 0 siblings, 0 replies; 10+ messages in thread From: Anand Jain @ 2015-08-17 11:17 UTC (permalink / raw) To: kreijack, linux-btrfs; +Cc: clm, dsterba >> >> -*remove* <dev> [<dev>...] <path>:: >> +*remove* <dev>|<devid> [<dev>|<devid>...] <path>:: >> Remove device(s) from a filesystem identified by <path>. >> >> *delete* <dev> [<dev>...] <path>:: > also here is missing <devid> (below you added) Thank you. Got this fixed. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: device delete to accept devid 2015-08-14 10:36 ` [PATCH 2/2] btrfs-progs: device delete to accept devid Anand Jain 2015-08-17 7:00 ` Goffredo Baroncelli @ 2015-08-20 11:29 ` Goffredo Baroncelli 2015-08-28 14:17 ` Anand Jain 1 sibling, 1 reply; 10+ messages in thread From: Goffredo Baroncelli @ 2015-08-20 11:29 UTC (permalink / raw) To: Anand Jain, linux-btrfs; +Cc: clm, dsterba Hi Anand On 2015-08-14 12:36, Anand Jain wrote: > This patch introduces new option <devid> for the command > [...] > + > + if (is_numerical(argv[i])) { > + argv3.devid = arg_strtou64(argv[i]); > + its_num = true; > + } else if (is_block_device(argv[i])) { please be aware that is_block_device(), returns - 1 if the file is a block device, - < 0 in case of an error (eg: file not found) - 0 otherwise so I suggest to change the check in + } else if (is_block_device(argv[i]) == 1) { [...] -- gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: device delete to accept devid 2015-08-20 11:29 ` Goffredo Baroncelli @ 2015-08-28 14:17 ` Anand Jain 2015-08-28 16:56 ` Goffredo Baroncelli 2015-08-28 16:57 ` Goffredo Baroncelli 0 siblings, 2 replies; 10+ messages in thread From: Anand Jain @ 2015-08-28 14:17 UTC (permalink / raw) To: kreijack, linux-btrfs; +Cc: clm, dsterba Hi Goffredo, sorry to have missed this. On 08/20/2015 07:29 PM, Goffredo Baroncelli wrote: > Hi Anand > On 2015-08-14 12:36, Anand Jain wrote: >> This patch introduces new option <devid> for the command >> > [...] > >> + >> + if (is_numerical(argv[i])) { >> + argv3.devid = arg_strtou64(argv[i]); >> + its_num = true; >> + } else if (is_block_device(argv[i])) { > > > please be aware that is_block_device(), returns > - 1 if the file is a block device, > - < 0 in case of an error (eg: file not found) > - 0 otherwise > > so I suggest to change the check in > > + } else if (is_block_device(argv[i]) == 1) { > > [...] > oh yes. I didn't notice that. In fact everywhere we didn't check the return properly. I wrote a new patch to fix this. Thanks, Anand ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: device delete to accept devid 2015-08-28 14:17 ` Anand Jain @ 2015-08-28 16:56 ` Goffredo Baroncelli 2015-08-28 16:57 ` Goffredo Baroncelli 1 sibling, 0 replies; 10+ messages in thread From: Goffredo Baroncelli @ 2015-08-28 16:56 UTC (permalink / raw) To: Anand Jain, linux-btrfs; +Cc: clm, dsterba On 2015-08-28 16:17, Anand Jain wrote: > > Hi Goffredo, > > sorry to have missed this. > [...] > > In fact everywhere we didn't check the return properly. > I wrote a new patch to fix this. > > Thanks, Anand Many thanks for your work BR Goffredo -- gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: device delete to accept devid 2015-08-28 14:17 ` Anand Jain 2015-08-28 16:56 ` Goffredo Baroncelli @ 2015-08-28 16:57 ` Goffredo Baroncelli 1 sibling, 0 replies; 10+ messages in thread From: Goffredo Baroncelli @ 2015-08-28 16:57 UTC (permalink / raw) To: linux-btrfs; +Cc: clm, dsterba On 2015-08-28 16:17, Anand Jain wrote: > > Hi Goffredo, > > sorry to have missed this. > [...] > > In fact everywhere we didn't check the return properly. > I wrote a new patch to fix this. > > Thanks, Anand Many thanks for your work BR Goffredo -- gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] device delete by devid @ 2015-04-20 10:29 Anand Jain 2015-04-20 10:29 ` [PATCH 2/2] btrfs-progs: device delete to accept devid Anand Jain 0 siblings, 1 reply; 10+ messages in thread From: Anand Jain @ 2015-04-20 10:29 UTC (permalink / raw) To: linux-btrfs; +Cc: dsterba, m_btrfs Current method to identify and verify the user provided device_path needs device SB to be accessible. In situations where SB isn't accessible or read fails. Using devid will help. Anand Jain (1): Btrfs: device delete by devid fs/btrfs/ioctl.c | 50 +++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/volumes.c | 33 +++++++++++++++++++++--------- fs/btrfs/volumes.h | 2 +- include/uapi/linux/btrfs.h | 8 ++++++++ 4 files changed, 82 insertions(+), 11 deletions(-) Anand Jain (2): btrfs-progs: move is_numerical to utils-lib.h and make it non static btrfs-progs: device delete to accept devid Documentation/btrfs-device.txt | 2 +- cmds-device.c | 47 ++++++++++++++++++++++++++++++++---------- cmds-replace.c | 11 ---------- ioctl.h | 8 +++++++ utils-lib.c | 11 ++++++++++ utils.h | 1 + 6 files changed, 57 insertions(+), 23 deletions(-) -- 2.0.0.153.g79dcccc ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] btrfs-progs: device delete to accept devid 2015-04-20 10:29 [PATCH] device delete by devid Anand Jain @ 2015-04-20 10:29 ` Anand Jain 0 siblings, 0 replies; 10+ messages in thread From: Anand Jain @ 2015-04-20 10:29 UTC (permalink / raw) To: linux-btrfs; +Cc: dsterba, m_btrfs This patch introduces new option <devid> for the command btrfs device delete <device_path|devid>[..] <mnt> In a user reported issue on a 3-disk-RAID1, one disk failed with its SB unreadable. Now with this patch user will have a choice to delete the device using devid. The other method we could do, is to match the input device_path to the available device_paths with in the kernel. But that won't work in all the cases, like what if user provided mapper path when the path within the kernel is a non-mapper path. This patch depends on the below kernel patch for the new feature to work, however it will fail-back to the old interface for the kernel without the patch Btrfs: device delete by devid Signed-off-by: Anand Jain <anand.jain@oracle.com> --- Documentation/btrfs-device.txt | 2 +- cmds-device.c | 47 ++++++++++++++++++++++++++++++++---------- ioctl.h | 8 +++++++ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/Documentation/btrfs-device.txt b/Documentation/btrfs-device.txt index 66be6b3..4bb5ea5 100644 --- a/Documentation/btrfs-device.txt +++ b/Documentation/btrfs-device.txt @@ -74,7 +74,7 @@ do not perform discard by default -f|--force:::: force overwrite of existing filesystem on the given disk(s) -*delete* <dev> [<dev>...] <path>:: +*delete* <dev>|<devid> [<dev>|<devid>...] <path>:: Remove device(s) from a filesystem identified by <path>. *ready* <device>:: diff --git a/cmds-device.c b/cmds-device.c index 1c32771..69e79d4 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -145,7 +145,7 @@ error_out: } static const char * const cmd_rm_dev_usage[] = { - "btrfs device delete <device> [<device>...] <path>", + "btrfs device delete <device>|<devid> [<device>|<devid>...] <path>", "Remove a device from a filesystem", NULL }; @@ -169,26 +169,51 @@ static int cmd_rm_dev(int argc, char **argv) for(i=1 ; i < argc - 1; i++ ){ struct btrfs_ioctl_vol_args arg; + struct btrfs_ioctl_vol_args_v3 argv3 = {0}; int res; + int its_num = false; - if (!is_block_device(argv[i])) { + if (is_numerical(argv[i])) { + argv3.devid = arg_strtou64(argv[i]); + its_num = true; + } else if (is_block_device(argv[i])) { + strncpy_null(argv3.name, argv[i]); + } else { fprintf(stderr, - "ERROR: %s is not a block device\n", argv[i]); + "ERROR: %s is not a block device or devid\n", argv[i]); ret++; continue; } - strncpy_null(arg.name, argv[i]); - res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV_V2, &argv3); e = errno; + if (res && e == ENOTTY) { + if (its_num) { + fprintf(stderr, "Error: Kernel does not support delete by devid\n"); + continue; + } + strncpy_null(arg.name, argv[i]); + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); + e = errno; + } if (res > 0) { - fprintf(stderr, - "ERROR: error removing the device '%s' - %s\n", - argv[i], btrfs_err_str(res)); + if (its_num) + fprintf(stderr, + "ERROR: removing the devid '%llu' - %s\n", + argv3.devid, btrfs_err_str(res)); + else + fprintf(stderr, + "ERROR: removing the device '%s' - %s\n", + argv[i], btrfs_err_str(res)); ret++; } else if (res < 0) { - fprintf(stderr, - "ERROR: ioctl error removing the device '%s' - %s\n", - argv[i], strerror(e)); + if (its_num) + fprintf(stderr, + "ERROR: ioctl removing the devid '%llu' - %s\n", + argv3.devid, strerror(e)); + else + fprintf(stderr, + "ERROR: ioctl removing the device '%s' - %s\n", + argv[i], strerror(e)); ret++; } } diff --git a/ioctl.h b/ioctl.h index d550ca6..4354c37 100644 --- a/ioctl.h +++ b/ioctl.h @@ -37,6 +37,12 @@ struct btrfs_ioctl_vol_args { char name[BTRFS_PATH_NAME_MAX + 1]; }; +struct btrfs_ioctl_vol_args_v3 { + __s64 fd; + char name[BTRFS_PATH_NAME_MAX + 1]; + __u64 devid; +}; + #define BTRFS_DEVICE_PATH_NAME_MAX 1024 #define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0) @@ -621,6 +627,8 @@ struct btrfs_ioctl_clone_range_args { struct btrfs_ioctl_feature_flags[2]) #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ struct btrfs_ioctl_feature_flags[3]) +#define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \ + struct btrfs_ioctl_vol_args_v3) #ifdef __cplusplus } #endif -- 2.0.0.153.g79dcccc ^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-08-28 16:57 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-08-14 10:36 [PATCH 0/2] Btrfs-progs: device delete to accept devid Anand Jain 2015-08-14 10:36 ` [PATCH 1/2] btrfs-progs: move is_numerical to utils-lib.h and make it non static Anand Jain 2015-08-14 10:36 ` [PATCH 2/2] btrfs-progs: device delete to accept devid Anand Jain 2015-08-17 7:00 ` Goffredo Baroncelli 2015-08-17 11:17 ` Anand Jain 2015-08-20 11:29 ` Goffredo Baroncelli 2015-08-28 14:17 ` Anand Jain 2015-08-28 16:56 ` Goffredo Baroncelli 2015-08-28 16:57 ` Goffredo Baroncelli -- strict thread matches above, loose matches on Subject: below -- 2015-04-20 10:29 [PATCH] device delete by devid Anand Jain 2015-04-20 10:29 ` [PATCH 2/2] btrfs-progs: device delete to accept devid Anand Jain
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).