Skip to content

Commit

Permalink
udev: correctly handle partition #16 and later
Browse files Browse the repository at this point in the history
If a zvol has more than 15 partitions, the minor device number exhausts
the slot count reserved for partitions next to the zvol itself. As a
result, the minor number cannot be used to determine the partition
number for the higher partition, and doing so results in wrong named
symlinks being generated by udev.

Since the partition number is encoded in the block device name anyway,
let's just extract it from there instead.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Closes #15904
Closes #15970
  • Loading branch information
Fabian-Gruenbichler authored and tonyhutter committed Apr 22, 2024
1 parent fa2cbd4 commit 3fb0942
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions udev/zvol_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const char *__asan_default_options(void) {
int
main(int argc, const char *const *argv)
{
if (argc != 2) {
if (argc != 2 || strncmp(argv[1], "/dev/zd", 7) != 0) {
fprintf(stderr, "usage: %s /dev/zdX\n", argv[0]);
return (1);
}
Expand All @@ -72,9 +72,10 @@ main(int argc, const char *const *argv)
return (1);
}

unsigned int dev_part = minor(sb.st_rdev) % ZVOL_MINORS;
if (dev_part != 0)
sprintf(zvol_name + strlen(zvol_name), "-part%u", dev_part);
const char *dev_part = strrchr(dev_name, 'p');
if (dev_part != NULL) {
sprintf(zvol_name + strlen(zvol_name), "-part%s", dev_part + 1);
}

for (size_t i = 0; i < strlen(zvol_name); ++i)
if (isblank(zvol_name[i]))
Expand Down

0 comments on commit 3fb0942

Please sign in to comment.