mirror of
https://github.com/systemd/systemd.git
synced 2024-11-23 10:13:34 +08:00
dissect: refuse to use diskseq if ID_IGNORE_DISKSEQ=1 is specified
Follow-up for 1a81ddef00
.
This commit is contained in:
parent
bfbd7ac96a
commit
e2f0876ecd
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user