Skip to content

fix: check symlink names when matching wwn/nvme-eui in get_unique_path_for_device - #4854

Open
Kolgrim33 wants to merge 1 commit into
archlinux:masterfrom
Kolgrim33:fix/unique-device-path-wwn-lookup
Open

Kolgrim33 wants to merge 1 commit into
archlinux:masterfrom
Kolgrim33:fix/unique-device-path-wwn-lookup

Conversation

@Kolgrim33

Copy link
Copy Markdown

PR Description:

In get_unique_path_for_device(), linked_targets = {p.resolve(): p for p in paths} uses the resolved device path (e.g. /dev/sda, /dev/nvme0n1) as the dictionary key and the /dev/disk/by-id/* symlink as the value.

Previously, linked_wwn_targets iterated over linked_targets (the resolved /dev/sdX / /dev/nvmeXnY keys) and checked if p.name.startswith('wwn-') or p.name.startswith('nvme-eui.'), which was always False because p.name was 'sda' / 'nvme0n1' rather than the /dev/disk/by-id/ symlink name. Furthermore, because a disk typically has multiple symlinks in /dev/disk/by-id/ (e.g. both ata-* and wwn-*), linked_targets could overwrite the wwn-* symlink with ata-*.

This PR materializes paths and builds linked_wwn_targets directly from paths by checking the symlink name, plus adds unit tests in tests/test_disk_utils.py.

Tests and Checks

  • I have tested the code!

…h_for_device

In get_unique_path_for_device(), linked_targets maps resolved device
paths (e.g. /dev/sda, /dev/nvme0n1) to their /dev/disk/by-id/* symlinks.

Previously, linked_wwn_targets iterated over the keys of linked_targets
(the resolved /dev/sdX or /dev/nvmeXnY paths) and checked whether the
resolved device name started with 'wwn-' or 'nvme-eui.', which was
always False. In addition, because multiple /dev/disk/by-id symlinks
resolve to the same block device, building linked_wwn_targets from
linked_targets would miss wwn-/nvme-eui. symlinks whenever another
symlink (such as ata-* or nvme-*) appeared later in the glob iteration.

Materialize the glob results and build linked_wwn_targets directly from
the /dev/disk/by-id symlink paths.
@Kolgrim33
Kolgrim33 requested a review from Torxed as a code owner October 25, 2026 17:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants