summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-04-05 06:45:52 +0200
committerLennart Poettering <lennart@poettering.net>2024-04-15 16:50:45 +0200
commite2f0876ecdd366d44f981e1bb3d3ba5be73647aa (patch)
tree99ca9e7bea0bde9f886ad5c72f0caf575bfeff82
parentcreds: update --help text regarding tpm2-absent → null rename (diff)
downloadsystemd-e2f0876ecdd366d44f981e1bb3d3ba5be73647aa.tar.xz
systemd-e2f0876ecdd366d44f981e1bb3d3ba5be73647aa.zip
dissect: refuse to use diskseq if ID_IGNORE_DISKSEQ=1 is specified
Follow-up for 1a81ddef00a0a25f6bcdd1e6633430e8b240b87f.
-rw-r--r--src/shared/dissect-image.c39
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