Skip to content

vdev_to_nvlist_iter: ignore draid parameters when matching names #17228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025

Conversation

robn
Copy link
Member

@robn robn commented Apr 8, 2025

[Sponsors: Klara, Inc., Wasabi Technology, Inc.]

Motivation and Context

Various tools will display draid vdev names with parameters embedded in them, but would not accept them as valid vdev names when looking them up, making it difficult to build pipelines involving draid vdevs.

# zpool create testpool draid2 /var/tmp/testdir1/*
# zpool get name testpool all-vdevs
NAME      PROPERTY  VALUE     SOURCE
root-0    name      testpool  -
can not find draid2:8d:10c:0s-0 in testpool: no such device in pool
can not find draid2:8d:10c:0s-0 in testpool: no such device in pool
can not find draid2:8d:10c:0s-0 in testpool: no such device in pool
/var/tmp/testdir1/testfile.0  name      /var/tmp/testdir1/testfile.0  -
/var/tmp/testdir1/testfile.1  name      /var/tmp/testdir1/testfile.1  -
/var/tmp/testdir1/testfile.2  name      /var/tmp/testdir1/testfile.2  -
/var/tmp/testdir1/testfile.3  name      /var/tmp/testdir1/testfile.3  -
/var/tmp/testdir1/testfile.4  name      /var/tmp/testdir1/testfile.4  -
/var/tmp/testdir1/testfile.5  name      /var/tmp/testdir1/testfile.5  -
/var/tmp/testdir1/testfile.6  name      /var/tmp/testdir1/testfile.6  -
/var/tmp/testdir1/testfile.7  name      /var/tmp/testdir1/testfile.7  -
/var/tmp/testdir1/testfile.8  name      /var/tmp/testdir1/testfile.8  -
/var/tmp/testdir1/testfile.9  name      /var/tmp/testdir1/testfile.9  -

Description

This commit updates vdev_to_nvlist_iter() so that when matching vdev types it will truncate vdev types starting with draid at the first ':', eg draid2:8d:10c:0s becomes simply draid2.

How Has This Been Tested?

New test is included, that exercises zpool get name <pool> all-vdevs to make sure it produces a row for each vdev with a plausible value. That's not a test of the matcher exactly, but is the place I found a bug, and it seems useful to at least make sure that all-vdevs produces something for every vdev.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

Various tools will display draid vdev names with parameters embedded in
them, but would not accept them as valid vdev names when looking them
up, making it difficult to build pipelines involving draid vdevs.

This commit makes it so that if a full draid name is offered for match,
it gets truncated at the first ':' character.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <[email protected]>
@allanjude
Copy link
Contributor

I think to be unique, it would be draid2-0 and draid2-1. When you say truncated at the first :, does it still include the -index?

Providing an example of the updated output would be helpful

@amotin
Copy link
Member

amotin commented Apr 8, 2025

@allanjude As I see, the index is split just before that.

@amotin amotin added the Status: Code Review Needed Ready for review and testing label Apr 8, 2025
@robn
Copy link
Member Author

robn commented Apr 8, 2025

Sorry, I wasn't clear. This is just for matching; nothing changes display. The reason for the errors in zpool get is that it was passing back in the display form of the vdev name, eg draid2:8d:10c:0s-0. The matching code chops off the trailing -N index, and then for RAIDZ and DRAID vdevs, looks for <five arbitrary chars><optional parity char>\0. The ':<params> stuff meant that didn't match, so it decides that the named vdev is not found. So I do the dumbest possibly thing - zero out the params before that check.

@tonyhutter
Copy link
Contributor

The PR works for me. @allanjude here's what the output looks like:

$ zpool get name tank4 all-vdevs
NAME    PROPERTY  VALUE   SOURCE
root-0  name      tank4   -
draid2:8d:10c:0s-0  name      draid-0  -
/tmp/file1  name      /tmp/file1  -
/tmp/file10  name      /tmp/file10  -
/tmp/file2  name      /tmp/file2  -
/tmp/file3  name      /tmp/file3  -
/tmp/file4  name      /tmp/file4  -
/tmp/file5  name      /tmp/file5  -
/tmp/file6  name      /tmp/file6  -
/tmp/file7  name      /tmp/file7  -
/tmp/file8  name      /tmp/file8  -
/tmp/file9  name      /tmp/file9  -

@tonyhutter tonyhutter merged commit 131df3b into openzfs:master Apr 15, 2025
20 of 23 checks passed
snajpa pushed a commit to vpsfreecz/zfs that referenced this pull request May 2, 2025
…nzfs#17228)

Various tools will display draid vdev names with parameters embedded in
them, but would not accept them as valid vdev names when looking them
up, making it difficult to build pipelines involving draid vdevs.

This commit makes it so that if a full draid name is offered for match,
it gets truncated at the first ':' character.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.

Signed-off-by: Rob Norris <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Reviewed-by: Tony Hutter <[email protected]>
robn added a commit to robn/zfs that referenced this pull request May 23, 2025
…nzfs#17228)

Various tools will display draid vdev names with parameters embedded in
them, but would not accept them as valid vdev names when looking them
up, making it difficult to build pipelines involving draid vdevs.

This commit makes it so that if a full draid name is offered for match,
it gets truncated at the first ':' character.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.

Signed-off-by: Rob Norris <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Reviewed-by: Tony Hutter <[email protected]>
(cherry picked from commit 131df3b)
@robn robn mentioned this pull request May 23, 2025
14 tasks
tonyhutter pushed a commit that referenced this pull request May 28, 2025
)

Various tools will display draid vdev names with parameters embedded in
them, but would not accept them as valid vdev names when looking them
up, making it difficult to build pipelines involving draid vdevs.

This commit makes it so that if a full draid name is offered for match,
it gets truncated at the first ':' character.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.

Signed-off-by: Rob Norris <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Reviewed-by: Tony Hutter <[email protected]>
(cherry picked from commit 131df3b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Code Review Needed Ready for review and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants