diff options
-rw-r--r-- | src/shared/dissect-image.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 1901fa70e2..da3b00260f 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -32,6 +32,7 @@ #include "copy.h" #include "cryptsetup-util.h" #include "device-nodes.h" +#include "device-private.h" #include "device-util.h" #include "devnum-util.h" #include "discover-image.h" @@ -516,6 +517,38 @@ static void dissected_partition_done(DissectedPartition *p) { } #if HAVE_BLKID +static int diskseq_should_be_used( + const char *whole_devname, + uint64_t diskseq, + DissectImageFlags flags) { + + int r; + + assert(whole_devname); + + /* No diskseq. We cannot use by-diskseq symlink. */ + if (diskseq == 0) + return false; + + /* Do not use by-diskseq link unless DISSECT_IMAGE_DISKSEQ_DEVNODE flag is explicitly set. */ + if (!FLAGS_SET(flags, DISSECT_IMAGE_DISKSEQ_DEVNODE)) + return false; + + _cleanup_(sd_device_unrefp) sd_device *dev = NULL; + r = sd_device_new_from_devname(&dev, whole_devname); + if (r < 0) + return r; + + /* When ID_IGNORE_DISKSEQ udev property is set, the by-diskseq symlink will not be created. */ + r = device_get_property_bool(dev, "ID_IGNORE_DISKSEQ"); + if (r >= 0) + return !r; /* If explicitly specified, use it. */ + if (r != -ENOENT) + return r; + + return true; +} + static int make_partition_devname( const char *whole_devname, uint64_t diskseq, @@ -530,8 +563,10 @@ static int make_partition_devname( assert(nr != 0); /* zero is not a valid partition nr */ assert(ret); - if (!FLAGS_SET(flags, DISSECT_IMAGE_DISKSEQ_DEVNODE) || diskseq == 0) { - + r = diskseq_should_be_used(whole_devname, diskseq, flags); + if (r < 0) + log_debug_errno(r, "Failed to determine if diskseq should be used for %s, assuming no, ignoring: %m", whole_devname); + if (r <= 0) { /* Given a whole block device node name (e.g. /dev/sda or /dev/loop7) generate a partition * device name (e.g. /dev/sda7 or /dev/loop7p5). The rule the kernel uses is simple: if whole * block device node name ends in a digit, then suffix a 'p', followed by the partition |