aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorMateusz Piotrowski <[email protected]>2024-08-26 18:27:24 +0200
committerGitHub <[email protected]>2024-08-26 09:27:24 -0700
commit6be8bf5552b16475629a15ab62759eb7a6d73e3b (patch)
tree952fdb553ed76d231396e80fc72d030d60889b4e /cmd
parent2420ee6e12cb4bc4918fc88d44d59b486b86e58b (diff)
zpool: Provide GUID to zpool-reguid(8) with -g (#16239)
This commit extends the zpool-reguid(8) command with a -g flag, which allows the user to specify the GUID to set. This change also adds some general tests for zpool-reguid(8). Sponsored-by: Wasabi Technology, Inc. Sponsored-by: Klara, Inc. Signed-off-by: Mateusz Piotrowski <[email protected]> Reviewed-by: Rob Norris <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tony Hutter <[email protected]>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zpool/zpool_main.c23
-rw-r--r--cmd/ztest.c2
2 files changed, 19 insertions, 6 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index 620746f8e..9cd26a865 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -537,7 +537,7 @@ get_usage(zpool_help_t idx)
"\t [-o property=value] <pool> <newpool> "
"[<device> ...]\n"));
case HELP_REGUID:
- return (gettext("\treguid <pool>\n"));
+ return (gettext("\treguid [-g guid] <pool>\n"));
case HELP_SYNC:
return (gettext("\tsync [pool] ...\n"));
case HELP_VERSION:
@@ -2025,7 +2025,7 @@ zpool_do_create(int argc, char **argv)
char *end;
u_longlong_t ver;
- ver = strtoull(propval, &end, 10);
+ ver = strtoull(propval, &end, 0);
if (*end == '\0' &&
ver < SPA_VERSION_FEATURES) {
enable_pool_features = B_FALSE;
@@ -8232,19 +8232,32 @@ zpool_do_clear(int argc, char **argv)
}
/*
- * zpool reguid <pool>
+ * zpool reguid [-g <guid>] <pool>
*/
int
zpool_do_reguid(int argc, char **argv)
{
+ uint64_t guid;
+ uint64_t *guidp = NULL;
int c;
+ char *endptr;
char *poolname;
zpool_handle_t *zhp;
int ret = 0;
/* check options */
- while ((c = getopt(argc, argv, "")) != -1) {
+ while ((c = getopt(argc, argv, "g:")) != -1) {
switch (c) {
+ case 'g':
+ errno = 0;
+ guid = strtoull(optarg, &endptr, 10);
+ if (errno != 0 || *endptr != '\0') {
+ (void) fprintf(stderr,
+ gettext("invalid GUID: %s\n"), optarg);
+ usage(B_FALSE);
+ }
+ guidp = &guid;
+ break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
@@ -8270,7 +8283,7 @@ zpool_do_reguid(int argc, char **argv)
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
return (1);
- ret = zpool_reguid(zhp);
+ ret = zpool_set_guid(zhp, guidp);
zpool_close(zhp);
return (ret);
diff --git a/cmd/ztest.c b/cmd/ztest.c
index 6a9264ddc..7c9db84d4 100644
--- a/cmd/ztest.c
+++ b/cmd/ztest.c
@@ -6746,7 +6746,7 @@ ztest_reguid(ztest_ds_t *zd, uint64_t id)
load = spa_load_guid(spa);
(void) pthread_rwlock_wrlock(&ztest_name_lock);
- error = spa_change_guid(spa);
+ error = spa_change_guid(spa, NULL);
zs->zs_guid = spa_guid(spa);
(void) pthread_rwlock_unlock(&ztest_name_lock);