Skip to content

zpool create: report which device caused failure#18213

Merged
behlendorf merged 1 commit intoopenzfs:masterfrom
chrislongros:feature/zpool-create-device-errors
Apr 3, 2026
Merged

zpool create: report which device caused failure#18213
behlendorf merged 1 commit intoopenzfs:masterfrom
chrislongros:feature/zpool-create-device-errors

Conversation

@chrislongros
Copy link
Copy Markdown
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 <[email protected]>
Signed-off-by: Christos Longros <[email protected]>

@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
Copy Markdown
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
@chrislongros chrislongros force-pushed the feature/zpool-create-device-errors branch from e533157 to 8a053f5 Compare February 26, 2026 21:26
@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
@chrislongros chrislongros force-pushed the feature/zpool-create-device-errors branch from 8a053f5 to 4818a2a Compare March 27, 2026 20:17
@github-actions github-actions bot removed the Status: Revision Needed Changes are required for the PR to be accepted label Mar 27, 2026
@chrislongros chrislongros force-pushed the feature/zpool-create-device-errors branch 2 times, most recently from fd7b80e to 4aca7e5 Compare March 28, 2026 10:31
@chrislongros
Copy link
Copy Markdown
Contributor Author

chrislongros commented Mar 28, 2026

Updated with @behlendorf suggestions from 2c5fa0d — also added zpool_create_info() to the EBUSY case since that's what vdev_inuse() returns.

Tested on Arch Linux (6.19.10) with two loop devices on the same backing file:

$ zpool create testpool mirror /dev/loop0 /dev/loop1
cannot create 'testpool': device '/dev/loop1' is part of active pool 'testpool'

Also built and tested on FreeBSD 16.0-CURRENT — module loads fine, normal pool ops and ztest work.

@behlendorf behlendorf force-pushed the feature/zpool-create-device-errors branch from 4aca7e5 to 39989c5 Compare March 31, 2026 17:01
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Mar 31, 2026
When zpool create fails because a vdev is already in use, the
error message now identifies the problematic device and the pool
it belongs to, e.g.:

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

Implementation follows the ZPOOL_CONFIG_LOAD_INFO pattern used
by zpool import:

  - 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, zpool_create_info() unwraps the nvlist and
    formats the device-specific error message

Restructure zpool_create() error handling so all switch cases
use break instead of return, eliminating duplicated cleanup
code and using the single create_failed exit path.

Suggested-by: Brian Behlendorf <[email protected]>
Signed-off-by: Christos Longros <[email protected]>
@chrislongros chrislongros force-pushed the feature/zpool-create-device-errors branch from 39989c5 to d6839be Compare April 1, 2026 16:17
@behlendorf behlendorf requested a review from tonyhutter April 1, 2026 20:56
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Apr 1, 2026
@behlendorf behlendorf merged commit 33ed68f into openzfs:master Apr 3, 2026
39 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Accepted Ready to integrate (reviewed, tested)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants