mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-04-13 07:01:46 +03:00
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 <behlendorf1@llnl.gov> Signed-off-by: Christos Longros <chris.longros@gmail.com> Closes #18268
This commit is contained in:
parent
c5905b2cb7
commit
304de7f19b
@ -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));
|
||||
}
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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']
|
||||
|
||||
@ -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 \
|
||||
|
||||
@ -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"
|
||||
Loading…
Reference in New Issue
Block a user