From 052eaf5c9302ac64f1de965babfaf9c120740f73 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Dec 2018 17:17:35 +0100 Subject: [PATCH 1/2] gpt-auto-generator: don't wait for udev Generators run in a context where waiting for udev is not an option, simply because it's not running there yet. Hence, let's not wait for it in this case. This is generally OK to do as we are operating on the root disk only here, which should have been probed already by the time we come this far. An alternative fix might be to remove the udev dependency from image dissection again in the long run (and thus replace reliance on /dev/block/x:y somehow with something else). Fixes: #11205 --- src/gpt-auto-generator/gpt-auto-generator.c | 2 +- src/shared/dissect-image.c | 25 +++++++++++++-------- src/shared/dissect-image.h | 1 + 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index a6d7bcc7552..e9f3d7dab2a 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -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; diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 4c2e41c8b8e..551a67b6c68 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -145,6 +145,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; @@ -166,9 +167,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 +226,22 @@ 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; 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 +376,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 +401,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; diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h index 0033921fa03..f50b40ea115 100644 --- a/src/shared/dissect-image.h +++ b/src/shared/dissect-image.h @@ -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 { From f70e7f70c9c5b640ca5b097d64da26e4c5d3fac9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Dec 2018 18:16:41 +0100 Subject: [PATCH 2/2] dissect: add some assert()s --- src/shared/dissect-image.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 551a67b6c68..3a46faf769e 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -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; @@ -153,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; @@ -231,6 +242,10 @@ static int loop_wait_for_partitions_to_appear( _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); if (!FLAGS_SET(flags, DISSECT_IMAGE_NO_UDEV)) {