From 6be8bf5552b16475629a15ab62759eb7a6d73e3b Mon Sep 17 00:00:00 2001 From: Mateusz Piotrowski <0mp@FreeBSD.org> Date: Mon, 26 Aug 2024 18:27:24 +0200 Subject: 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 <0mp@FreeBSD.org> Reviewed-by: Rob Norris Reviewed-by: Brian Behlendorf Reviewed-by: Tony Hutter --- cmd/zpool/zpool_main.c | 23 ++++++++++++++++++----- cmd/ztest.c | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'cmd') 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] " "[ ...]\n")); case HELP_REGUID: - return (gettext("\treguid \n")); + return (gettext("\treguid [-g guid] \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 + * zpool reguid [-g ] */ 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); -- cgit v1.2.3