aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/zpool/zpool_main.c
diff options
context:
space:
mode:
authorRob Wing <[email protected]>2022-12-20 21:52:26 -0900
committerBrian Behlendorf <[email protected]>2023-01-17 09:47:24 -0800
commit7a85f58db6c8a80cabd42d608fd5f5b8d7c301c6 (patch)
tree930ea9115f281394fc8aca5626ee4be9ad69f322 /cmd/zpool/zpool_main.c
parenta0276f70480c7341ad3ebdf04dfe97e3f5e71182 (diff)
zpool-set: print error message when pool or vdev is not valid
Reviewed-by: Tony Hutter <[email protected]> Reviewed-by: Allan Jude <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Wing <[email protected]> Sponsored-by: Seagate Technology Submitted-by: Klara, Inc. Closes #14310
Diffstat (limited to 'cmd/zpool/zpool_main.c')
-rw-r--r--cmd/zpool/zpool_main.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index 95d0c279a..93d6a1898 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -10328,29 +10328,27 @@ zpool_do_set(int argc, char **argv)
argc -= 2;
argv += 2;
- if (are_vdevs_in_pool(argc, argv, NULL, &cb.cb_vdevs)) {
- /* Argument is a vdev */
- cb.cb_vdevs.cb_names = argv;
+ /* argv[0] is pool name */
+ if (!is_pool(argv[0])) {
+ (void) fprintf(stderr,
+ gettext("cannot open '%s': is not a pool\n"), argv[0]);
+ return (EINVAL);
+ }
+
+ /* argv[1], when supplied, is vdev name */
+ if (argc == 2) {
+ if (!are_vdevs_in_pool(1, argv + 1, argv[0], &cb.cb_vdevs)) {
+ (void) fprintf(stderr, gettext(
+ "cannot find '%s' in '%s': device not in pool\n"),
+ argv[1], argv[0]);
+ return (EINVAL);
+ }
+ cb.cb_vdevs.cb_names = argv + 1;
cb.cb_vdevs.cb_names_count = 1;
cb.cb_type = ZFS_TYPE_VDEV;
- argc = 0; /* No pools to process */
- } else if (are_all_pools(1, argv)) {
- /* The first arg is a pool name */
- if (are_vdevs_in_pool(argc - 1, argv + 1, argv[0],
- &cb.cb_vdevs)) {
- /* 2nd argument is a vdev */
- cb.cb_vdevs.cb_names = argv + 1;
- cb.cb_vdevs.cb_names_count = 1;
- cb.cb_type = ZFS_TYPE_VDEV;
- argc = 1; /* One pool to process */
- } else if (argc > 1) {
- (void) fprintf(stderr,
- gettext("too many pool names\n"));
- usage(B_FALSE);
- }
}
- error = for_each_pool(argc, argv, B_TRUE, NULL, ZFS_TYPE_POOL,
+ error = for_each_pool(1, argv, B_TRUE, NULL, ZFS_TYPE_POOL,
B_FALSE, set_callback, &cb);
return (error);