Skip to content

zpool create: report which device caused failure#18213

Open
chrislongros wants to merge 1 commit intoopenzfs:masterfrom
chrislongros:feature/zpool-create-device-errors
Open

zpool create: report which device caused failure#18213
chrislongros wants to merge 1 commit intoopenzfs:masterfrom
chrislongros:feature/zpool-create-device-errors

Conversation

@chrislongros
Copy link
Contributor

@chrislongros chrislongros commented Feb 13, 2026

Motivation

When zpool create fails because a vdev is already in use, the error message does not identify which device caused the problem:

cannot create 'tank': one or more vdevs refer to the same device

This is frustrating when creating pools with many disks, as there is no way to tell which device is the culprit without manually checking each one.

Description

This patch adds device-specific error reporting so the message now identifies the problematic device and the pool it belongs to:

cannot create 'tank': device '/dev/sdb1' is part of active pool 'rpool'

Implementation follows the ZPOOL_CONFIG_LOAD_INFO pattern used by zpool import, as suggested in #18184:

  • Add spa_create_info to spa_t to capture error info during vdev_label_init(), before vdev_close() resets vdev state
  • When vdev_inuse() detects a conflict, read the on-disk label to extract the pool name and store it with the device path
  • Return the info wrapped under ZPOOL_CONFIG_CREATE_INFO through the ioctl zc_nvlist_dst to userspace
  • In libzfs, the zpool_create_info() helper unwraps the nvlist and formats the device-specific error message

If the pool name cannot be read from the label, the device path alone is reported as a fallback.

Testing

  • New ZTS test zpool_create_errinfo_001_neg verifies the error message names the device and the active pool when creating a mirror with duplicate loopback vdevs (portable across Linux and FreeBSD)
  • Normal pool creation still succeeds
  • checkstyle passes

Suggested-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Christos Longros <chris.longros@gmail.com>

@chrislongros chrislongros force-pushed the feature/zpool-create-device-errors branch 2 times, most recently from 298ce20 to a22cd15 Compare February 13, 2026 21:23
Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Feb 13, 2026
@chrislongros chrislongros force-pushed the feature/zpool-create-device-errors branch from a22cd15 to cc184fe Compare February 14, 2026 09:04
@chrislongros chrislongros reopened this Feb 14, 2026
@chrislongros chrislongros force-pushed the feature/zpool-create-device-errors branch 2 times, most recently from f2bd62e to e533157 Compare February 14, 2026 13:12
When zpool create fails because a vdev is already in use, the error
message now identifies the specific device and the pool it belongs
to.

Before:
  cannot create 'tank': one or more vdevs refer to the same device
After:
  cannot create 'tank': device '/dev/sdb1' is part of
  active pool 'rpool'

Add a spa_create_info field to spa_t to capture device-level
error information during vdev_label_init(), before vdev_close()
resets vdev state.  When vdev_inuse() detects a conflict, the
device path and pool name (read from the on-disk label) are stored
in the nvlist.  This is returned to userspace wrapped under
ZPOOL_CONFIG_CREATE_INFO, following the ZPOOL_CONFIG_LOAD_INFO
pattern used by zpool import.  If the pool name is not available,
the device path alone is reported.

New ZTS test zpool_create_errinfo_001_neg verifies device-specific
error messages by creating duplicate loopback vdevs and checking
that the output names the device and the active pool.

Tested:
  - Duplicate loopback vdevs correctly report the device and
    active pool name in the error message
  - Normal pool creation succeeds
  - New ZTS test passes on all platforms
  - Clean build with no warnings

Suggested-by: Brian Behlendorf
Signed-off-by: Christos Longros <chris.longros@gmail.com>
@chrislongros chrislongros force-pushed the feature/zpool-create-device-errors branch from e533157 to 8a053f5 Compare February 26, 2026 21:26

if ((ret = zfs_ioctl(hdl, ZFS_IOC_POOL_CREATE, &zc)) != 0) {

if (zpool_create_info(hdl, &zc)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we're going to have infrastructure to report more detailed errors in zpool create I suspect we'll want to make use of it in some of the other error cases. I've thrown together a completely untested commit which restructures things so we can access the nvlists where we need them. Can you take a look at 2c5fa0d, refine as needed, and then squash something that's actually tested in to this PR!

@behlendorf behlendorf added Status: Revision Needed Changes are required for the PR to be accepted and removed Status: Code Review Needed Ready for review and testing labels Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Revision Needed Changes are required for the PR to be accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants