diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c index 1b2392aea..c6f7dd596 100644 --- a/module/zfs/zfs_ioctl.c +++ b/module/zfs/zfs_ioctl.c @@ -8151,10 +8151,16 @@ zfsdev_ioctl_common(uint_t vecnum, zfs_cmd_t *zc, int flag) * Can't use kmem_strdup() as we might truncate the string and * kmem_strfree() would then free with incorrect size. */ - saved_poolname_len = strlen(zc->zc_name) + 1; + const char *spa_name = zc->zc_name; + const char *tname; + if (nvlist_lookup_string(innvl, + zpool_prop_to_name(ZPOOL_PROP_TNAME), &tname) == 0) { + spa_name = tname; + } + saved_poolname_len = strlen(spa_name) + 1; saved_poolname = kmem_alloc(saved_poolname_len, KM_SLEEP); - strlcpy(saved_poolname, zc->zc_name, saved_poolname_len); + strlcpy(saved_poolname, spa_name, saved_poolname_len); saved_poolname[strcspn(saved_poolname, "/@#")] = '\0'; if (vec->zvec_func != NULL) { diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_tempname.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_tempname.ksh index fa0e913f8..234b0c36f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_tempname.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_tempname.ksh @@ -60,6 +60,8 @@ for poolprop in "${poolprops[@]}"; do log_must test "$(get_prop $propname $TEMPPOOL)" == "$propval" IFS='=' read -r propname propval <<<"$poolprop" log_must test "$(get_pool_prop $propname $TEMPPOOL)" == "$propval" + # 3. Verify the `zpool create` command is logged to the pool history + log_must eval "zpool history $TEMPPOOL | grep -q 'zpool create -t'" # Cleanup destroy_pool $TEMPPOOL done