From 304de7f19b3d93c51cda40cbc6fa21d3184d58a6 Mon Sep 17 00:00:00 2001 From: Christos Longros <98426896+chrislongros@users.noreply.github.com> Date: Sun, 8 Mar 2026 20:59:10 +0100 Subject: [PATCH] libzfs: handle EDOM error in zpool_create When creating a pool with devices that have incompatible block sizes, the kernel returns EDOM. However, zpool_create() did not handle this errno, falling through to zpool_standard_error() which produced a confusing message about invalid property values. Add a case EDOM handler in zpool_create() to return EZFS_BADDEV with a descriptive auxiliary message, consistent with the existing EDOM handler in zpool_vdev_add(). Reviewed-by: Brian Behlendorf Signed-off-by: Christos Longros Closes #18268 --- lib/libzfs/libzfs_pool.c | 5 ++ tests/runfiles/common.run | 2 +- tests/runfiles/sanity.run | 2 +- tests/zfs-tests/tests/Makefile.am | 1 + .../zpool_create/zpool_create_edom_neg.ksh | 68 +++++++++++++++++++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_edom_neg.ksh diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 09cb7b2f3..3a1a87e85 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -1696,6 +1696,11 @@ zpool_create(libzfs_handle_t *hdl, const char *pool, nvlist_t *nvroot, "one or more devices could not be opened")); return (zfs_error(hdl, EZFS_BADDEV, errbuf)); + case EDOM: + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, + "block size out of range or does not match")); + return (zfs_error(hdl, EZFS_BADDEV, errbuf)); + default: return (zpool_standard_error(hdl, errno, errbuf)); } diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index 0266f22e4..7b0bfa90e 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -420,7 +420,7 @@ tests = ['zpool_create_001_pos', 'zpool_create_002_pos', 'zpool_create_017_neg', 'zpool_create_018_pos', 'zpool_create_019_pos', 'zpool_create_020_pos', 'zpool_create_021_pos', 'zpool_create_022_pos', 'zpool_create_023_neg', 'zpool_create_024_pos', - 'zpool_create_encrypted', 'zpool_create_crypt_combos', + 'zpool_create_encrypted', 'zpool_create_edom_neg', 'zpool_create_crypt_combos', 'zpool_create_draid_001_pos', 'zpool_create_draid_002_pos', 'zpool_create_draid_003_pos', 'zpool_create_draid_004_pos', 'zpool_create_features_001_pos', 'zpool_create_features_002_pos', diff --git a/tests/runfiles/sanity.run b/tests/runfiles/sanity.run index dad51d2e9..ad2533793 100644 --- a/tests/runfiles/sanity.run +++ b/tests/runfiles/sanity.run @@ -270,7 +270,7 @@ tests = ['zpool_create_001_pos', 'zpool_create_002_pos', 'zpool_create_012_neg', 'zpool_create_014_neg', 'zpool_create_015_neg', 'zpool_create_017_neg', 'zpool_create_018_pos', 'zpool_create_019_pos', 'zpool_create_020_pos', 'zpool_create_021_pos', 'zpool_create_022_pos', - 'zpool_create_encrypted', + 'zpool_create_encrypted', 'zpool_create_edom_neg', 'zpool_create_features_001_pos', 'zpool_create_features_002_pos', 'zpool_create_features_003_pos', 'zpool_create_features_004_neg', 'zpool_create_features_005_pos'] diff --git a/tests/zfs-tests/tests/Makefile.am b/tests/zfs-tests/tests/Makefile.am index 23c2d9e4b..1fc158f80 100644 --- a/tests/zfs-tests/tests/Makefile.am +++ b/tests/zfs-tests/tests/Makefile.am @@ -1082,6 +1082,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \ functional/cli_root/zpool_create/zpool_create_draid_004_pos.ksh \ functional/cli_root/zpool_create/zpool_create_dryrun_output.ksh \ functional/cli_root/zpool_create/zpool_create_encrypted.ksh \ + functional/cli_root/zpool_create/zpool_create_edom_neg.ksh \ functional/cli_root/zpool_create/zpool_create_features_001_pos.ksh \ functional/cli_root/zpool_create/zpool_create_features_002_pos.ksh \ functional/cli_root/zpool_create/zpool_create_features_003_pos.ksh \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_edom_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_edom_neg.ksh new file mode 100755 index 000000000..21ebae5ee --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_edom_neg.ksh @@ -0,0 +1,68 @@ +#!/bin/ksh -p +# SPDX-License-Identifier: CDDL-1.0 +# +# CDDL HEADER START +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# +# CDDL HEADER END +# + +# +# Copyright (c) 2026, Christos Longros. All rights reserved. +# + +# +# DESCRIPTION: +# Verify that zpool create with an out-of-range block size +# reports a clear error about block size rather than a +# misleading "invalid property value" message. +# +# STRATEGY: +# 1. Set vdev_file_logical_ashift above ASHIFT_MAX to force EDOM. +# 2. Attempt to create a pool. +# 3. Verify the error mentions "block size". +# 4. Verify it does not say "property". +# + +. $STF_SUITE/include/libtest.shlib + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL + log_must set_tunable64 VDEV_FILE_LOGICAL_ASHIFT 9 + rm -f $TEST_BASE_DIR/vdev_edom +} + +log_assert "zpool create with bad ashift reports block size error" +log_onexit cleanup + +truncate -s $MINVDEVSIZE $TEST_BASE_DIR/vdev_edom + +# Force ashift above ASHIFT_MAX (16) to trigger EDOM +log_must set_tunable64 VDEV_FILE_LOGICAL_ASHIFT 17 + +errmsg=$(zpool create $TESTPOOL $TEST_BASE_DIR/vdev_edom 2>&1) +typeset -i ret=$? + +log_note "Return code: $ret" +log_note "Error message: $errmsg" + +(( ret != 0 )) || log_fail "zpool create should have failed" + +echo "$errmsg" | grep -qi "block size" || \ + log_fail "Error should mention block size: $errmsg" + +echo "$errmsg" | grep -qi "property" && \ + log_fail "Error should not mention property: $errmsg" + +log_pass "zpool create with bad ashift reports block size error"