mirror of
https://github.com/morgan9e/systemd
synced 2026-04-16 01:16:10 +09:00
Merge pull request #11215 from poettering/gpt-auto-no-udev
gpt-auto-generator: don't wait for udev
This commit is contained in:
@@ -518,7 +518,7 @@ static int enumerate_partitions(dev_t devnum) {
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
r = dissect_image(fd, NULL, 0, DISSECT_IMAGE_GPT_ONLY, &m);
|
||||
r = dissect_image(fd, NULL, 0, DISSECT_IMAGE_GPT_ONLY|DISSECT_IMAGE_NO_UDEV, &m);
|
||||
if (r == -ENOPKG) {
|
||||
log_debug_errno(r, "No suitable partition table found, ignoring.");
|
||||
return 0;
|
||||
|
||||
@@ -102,6 +102,8 @@ not_found:
|
||||
static bool device_is_mmc_special_partition(sd_device *d) {
|
||||
const char *sysname;
|
||||
|
||||
assert(d);
|
||||
|
||||
if (sd_device_get_sysname(d, &sysname) < 0)
|
||||
return false;
|
||||
|
||||
@@ -112,6 +114,8 @@ static bool device_is_mmc_special_partition(sd_device *d) {
|
||||
static bool device_is_block(sd_device *d) {
|
||||
const char *ss;
|
||||
|
||||
assert(d);
|
||||
|
||||
if (sd_device_get_subsystem(d, &ss) < 0)
|
||||
return false;
|
||||
|
||||
@@ -122,6 +126,9 @@ static int enumerator_for_parent(sd_device *d, sd_device_enumerator **ret) {
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
int r;
|
||||
|
||||
assert(d);
|
||||
assert(ret);
|
||||
|
||||
r = sd_device_enumerator_new(&e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -145,6 +152,7 @@ static int wait_for_partitions_to_appear(
|
||||
int fd,
|
||||
sd_device *d,
|
||||
unsigned num_partitions,
|
||||
DissectImageFlags flags,
|
||||
sd_device_enumerator **ret_enumerator) {
|
||||
|
||||
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
|
||||
@@ -152,6 +160,10 @@ static int wait_for_partitions_to_appear(
|
||||
unsigned n;
|
||||
int r;
|
||||
|
||||
assert(fd >= 0);
|
||||
assert(d);
|
||||
assert(ret_enumerator);
|
||||
|
||||
r = enumerator_for_parent(d, &e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -166,9 +178,11 @@ static int wait_for_partitions_to_appear(
|
||||
if (device_is_mmc_special_partition(q))
|
||||
continue;
|
||||
|
||||
r = device_wait_for_initialization(q, "block", NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (!FLAGS_SET(flags, DISSECT_IMAGE_NO_UDEV)) {
|
||||
r = device_wait_for_initialization(q, "block", NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
n++;
|
||||
}
|
||||
@@ -223,18 +237,26 @@ static int loop_wait_for_partitions_to_appear(
|
||||
int fd,
|
||||
sd_device *d,
|
||||
unsigned num_partitions,
|
||||
DissectImageFlags flags,
|
||||
sd_device_enumerator **ret_enumerator) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||
int r;
|
||||
|
||||
assert(fd >= 0);
|
||||
assert(d);
|
||||
assert(ret_enumerator);
|
||||
|
||||
log_debug("Waiting for device (parent + %d partitions) to appear...", num_partitions);
|
||||
|
||||
r = device_wait_for_initialization(d, "block", &device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (!FLAGS_SET(flags, DISSECT_IMAGE_NO_UDEV)) {
|
||||
r = device_wait_for_initialization(d, "block", &device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else
|
||||
device = sd_device_ref(d);
|
||||
|
||||
for (unsigned i = 0; i < N_DEVICE_NODE_LIST_ATTEMPTS; i++) {
|
||||
r = wait_for_partitions_to_appear(fd, device, num_partitions, ret_enumerator);
|
||||
r = wait_for_partitions_to_appear(fd, device, num_partitions, flags, ret_enumerator);
|
||||
if (r != -EAGAIN)
|
||||
return r;
|
||||
}
|
||||
@@ -369,7 +391,7 @@ int dissect_image(
|
||||
|
||||
m->encrypted = streq_ptr(fstype, "crypto_LUKS");
|
||||
|
||||
r = loop_wait_for_partitions_to_appear(fd, d, 0, &e);
|
||||
r = loop_wait_for_partitions_to_appear(fd, d, 0, flags, &e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -394,7 +416,7 @@ int dissect_image(
|
||||
if (!pl)
|
||||
return -errno ?: -ENOMEM;
|
||||
|
||||
r = loop_wait_for_partitions_to_appear(fd, d, blkid_partlist_numof_partitions(pl), &e);
|
||||
r = loop_wait_for_partitions_to_appear(fd, d, blkid_partlist_numof_partitions(pl), flags, &e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ typedef enum DissectImageFlags {
|
||||
DISSECT_IMAGE_MOUNT_ROOT_ONLY = 1 << 6, /* Mount only the root partition */
|
||||
DISSECT_IMAGE_MOUNT_NON_ROOT_ONLY = 1 << 7, /* Mount only non-root partitions */
|
||||
DISSECT_IMAGE_VALIDATE_OS = 1 << 8, /* Refuse mounting images that aren't identifyable as OS images */
|
||||
DISSECT_IMAGE_NO_UDEV = 1 << 9, /* Don't wait for udev initializing things */
|
||||
} DissectImageFlags;
|
||||
|
||||
struct DissectedImage {
|
||||
|
||||
Reference in New Issue
Block a user