diff options
author | Dimitri John Ledkov <xnox@ubuntu.com> | 2016-05-10 10:13:23 +0100 |
---|---|---|
committer | Dimitri John Ledkov <xnox@ubuntu.com> | 2016-05-10 10:13:23 +0100 |
commit | 58e631d01823afd60e52f3a09887f270a91889a0 (patch) | |
tree | 6afbca5492c1ad1040608e01fe0c9d909482adeb /cmds-device.c | |
parent | cec572daccafa1e912cbed363df6f84687778c6f (diff) |
New upstream release 4.5.2.
* Thanks for NMU of package rename.
* New upstream release 4.5.2.
* Upload using dgit.
* Source-only upload.
* btrfs-convert should not be included in the initramfs, but should be
compiled. Using btrfs-convert is not a trivial operation, and
especially not from a minimal shell. Also it is known to fail, and for
a sophisticated user it is trivial to include it in the
initramfs. Thus won't fix Closes: #801192
* No sponsorship required Closes: #823474
* Add Provides btrfs-tools-udeb to the -progs-udeb package.
Diffstat (limited to 'cmds-device.c')
-rw-r--r-- | cmds-device.c | 90 |
1 files changed, 69 insertions, 21 deletions
diff --git a/cmds-device.c b/cmds-device.c index 50c1c5df..1c886ad5 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -146,7 +146,9 @@ static int _cmd_device_remove(int argc, char **argv, int i, fdmnt, ret = 0; DIR *dirstream = NULL; - if (check_argc_min(argc, 3)) + clean_args_no_options(argc, argv, usagestr); + + if (check_argc_min(argc - optind, 2)) usage(usagestr); mntpnt = argv[argc - 1]; @@ -155,22 +157,48 @@ static int _cmd_device_remove(int argc, char **argv, if (fdmnt < 0) return 1; - for(i=1 ; i < argc - 1; i++ ){ + for(i = optind; i < argc - 1; i++) { struct btrfs_ioctl_vol_args arg; + struct btrfs_ioctl_vol_args_v2 argv2 = {0}; + int is_devid = 0; int res; - if (is_block_device(argv[i]) != 1 && strcmp(argv[i], "missing")) { + if (string_is_numerical(argv[i])) { + argv2.devid = arg_strtou64(argv[i]); + argv2.flags = BTRFS_DEVICE_SPEC_BY_ID; + is_devid = 1; + } else if (is_block_device(argv[i]) == 1 || + strcmp(argv[i], "missing") == 0) { + strncpy_null(argv2.name, argv[i]); + } else { error("not a block device: %s", argv[i]); ret++; continue; } - memset(&arg, 0, sizeof(arg)); - strncpy_null(arg.name, argv[i]); + /* * Positive values are from BTRFS_ERROR_DEV_*, * otherwise it's a generic error, one of errnos */ - res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV_V2, &argv2); + + /* + * If BTRFS_IOC_RM_DEV_V2 is not supported we get ENOTTY and if + * argv2.flags includes a flag which kernel doesn't understand then + * we shall get EOPNOTSUPP + */ + if (res < 0 && (errno == ENOTTY || errno == EOPNOTSUPP)) { + if (is_devid) { + error("device delete by id failed: %s", + strerror(errno)); + ret++; + continue; + } + memset(&arg, 0, sizeof(arg)); + strncpy_null(arg.name, argv[i]); + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); + } + if (res) { const char *msg; @@ -178,8 +206,13 @@ static int _cmd_device_remove(int argc, char **argv, msg = btrfs_err_str(res); else msg = strerror(errno); - error("error removing device '%s': %s", - argv[i], msg); + if (is_devid) { + error("error removing devid %llu: %s", + (unsigned long long)argv2.devid, msg); + } else { + error("error removing device '%s': %s", + argv[i], msg); + } ret++; } } @@ -189,7 +222,7 @@ static int _cmd_device_remove(int argc, char **argv, } static const char * const cmd_device_remove_usage[] = { - "btrfs device remove <device> [<device>...] <path>", + "btrfs device remove <device>|<devid> [<device>|<devid>...] <path>", "Remove a device from a filesystem", NULL }; @@ -200,7 +233,7 @@ static int cmd_device_remove(int argc, char **argv) } static const char * const cmd_device_delete_usage[] = { - "btrfs device delete <device> [<device>...] <path>", + "btrfs device delete <device>|<devid> [<device>|<devid>...] <path>", "Remove a device from a filesystem", NULL }; @@ -220,7 +253,7 @@ static const char * const cmd_device_scan_usage[] = { static int cmd_device_scan(int argc, char **argv) { int i; - int devstart = 1; + int devstart; int all = 0; int ret = 0; @@ -243,16 +276,17 @@ static int cmd_device_scan(int argc, char **argv) usage(cmd_device_scan_usage); } } + devstart = optind; - if (all && check_argc_max(argc, 2)) + if (all && check_argc_max(argc - optind, 1)) usage(cmd_device_scan_usage); - if (all || argc == 1) { + if (all || argc - optind == 0) { printf("Scanning for Btrfs filesystems\n"); ret = btrfs_scan_lblkid(); error_on(ret, "error %d while scanning", ret); ret = btrfs_register_all_devices(); - error_on(ret, "error %d while registering devices", ret); + error_on(ret, "there are %d errors while registering devices", ret); goto out; } @@ -297,7 +331,9 @@ static int cmd_device_ready(int argc, char **argv) int ret; char *path; - if (check_argc_min(argc, 2)) + clean_args_no_options(argc, argv, cmd_device_ready_usage); + + if (check_argc_exact(argc - optind, 1)) usage(cmd_device_ready_usage); fd = open("/dev/btrfs-control", O_RDWR); @@ -306,10 +342,10 @@ static int cmd_device_ready(int argc, char **argv) return 1; } - path = canonicalize_path(argv[argc - 1]); + path = canonicalize_path(argv[optind]); if (!path) { error("could not canonicalize pathname '%s': %s", - argv[argc - 1], strerror(errno)); + argv[optind], strerror(errno)); ret = 1; goto out; } @@ -368,8 +404,7 @@ static int cmd_device_stats(int argc, char **argv) } } - argc = argc - optind; - if (check_argc_exact(argc, 1)) + if (check_argc_exact(argc - optind, 1)) usage(cmd_device_stats_usage); dev_path = argv[optind]; @@ -412,6 +447,17 @@ static int cmd_device_stats(int argc, char **argv) canonical_path = canonicalize_path((char *)path); + /* No path when device is missing. */ + if (!canonical_path) { + canonical_path = malloc(32); + if (!canonical_path) { + error("not enough memory for path buffer"); + goto out; + } + snprintf(canonical_path, 32, + "devid:%llu", args.devid); + } + if (args.nr_items >= BTRFS_DEV_STAT_WRITE_ERRS + 1) printf("[%s].write_io_errs %llu\n", canonical_path, @@ -493,10 +539,12 @@ static int cmd_device_usage(int argc, char **argv) unit_mode = get_unit_mode_from_arg(&argc, argv, 1); - if (check_argc_min(argc, 2) || argv[1][0] == '-') + clean_args_no_options(argc, argv, cmd_device_usage_usage); + + if (check_argc_min(argc - optind, 1)) usage(cmd_device_usage_usage); - for (i = 1; i < argc; i++) { + for (i = optind; i < argc; i++) { int fd; DIR *dirstream = NULL; |