]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt-auto-generator: don't wait for udev
authorLennart Poettering <lennart@poettering.net>
Wed, 19 Dec 2018 16:17:35 +0000 (17:17 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 19 Dec 2018 22:27:47 +0000 (23:27 +0100)
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
src/shared/dissect-image.c
src/shared/dissect-image.h

index a6d7bcc7552f4dc567847b81de1e7fa5e301efe1..e9f3d7dab2a2a99b0ecf2317b71a6721eb540b23 100644 (file)
@@ -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;
index 4c2e41c8b8ee16b57d7cab7807b981d6f4273e56..551a67b6c689364268b43243a66feb7c5c76744b 100644 (file)
@@ -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;
 
index 0033921fa033233933f8c0aaaea6b8ecc3fb3920..f50b40ea1154775380aec52a1bd68ffd454a2906 100644 (file)
@@ -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 {