]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-image: introduce dissect_loop_device() which takes LoopDevice object 24536/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Sep 2022 10:09:51 +0000 (19:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Sep 2022 16:32:01 +0000 (01:32 +0900)
src/core/namespace.c
src/dissect/dissect.c
src/nspawn/nspawn.c
src/portable/portable.c
src/shared/discover-image.c
src/shared/dissect-image.c
src/shared/dissect-image.h
src/sysext/sysext.c
src/test/test-loop-block.c

index 831dcaa81ec2e3050d10e3cfa3a9627a29bdb758..468b27905e7e9fdb788e2217e9a15615e7515133 100644 (file)
@@ -2063,13 +2063,10 @@ int setup_namespace(
                 if (r < 0)
                         return log_debug_errno(r, "Failed to create loop device for root image: %m");
 
-                r = dissect_image(
-                                loop_device->fd,
+                r = dissect_loop_device(
+                                loop_device,
                                 &verity,
                                 root_image_options,
-                                loop_device->diskseq,
-                                loop_device->uevent_seqnum_not_before,
-                                loop_device->timestamp_not_before,
                                 dissect_image_flags,
                                 &dissected_image);
                 if (r < 0)
index 2c169fcea1bc006a415f299ce478785bfb9af58a..22872d803cf19fdad24a2dea759f8fb6e5fc3bfa 100644 (file)
@@ -945,14 +945,11 @@ static int run(int argc, char *argv[]) {
         if (r < 0)
                 return log_error_errno(r, "Failed to set up loopback device for %s: %m", arg_image);
 
-        r = dissect_image_and_warn(
-                        d->fd,
+        r = dissect_loop_device_and_warn(
                         arg_image,
+                        d,
                         &arg_verity_settings,
                         NULL,
-                        d->diskseq,
-                        d->uevent_seqnum_not_before,
-                        d->timestamp_not_before,
                         arg_flags,
                         &m);
         if (r < 0)
index 45e138d48a91665fa48bf0f8075aaa62b4de617b..ca87bffd0b7093314892686ea4d3124b492261fa 100644 (file)
@@ -5753,14 +5753,11 @@ static int run(int argc, char *argv[]) {
                         goto finish;
                 }
 
-                r = dissect_image_and_warn(
-                                loop->fd,
+                r = dissect_loop_device_and_warn(
                                 arg_image,
+                                loop,
                                 &arg_verity_settings,
                                 NULL,
-                                loop->diskseq,
-                                loop->uevent_seqnum_not_before,
-                                loop->timestamp_not_before,
                                 dissect_image_flags,
                                 &dissected_image);
                 if (r == -ENOPKG) {
index 0f6c71042eb09cbedfc662edda485f12c255af18..5d0a965db5fedb90aeb30f89cb072a0301cd6039 100644 (file)
@@ -365,12 +365,9 @@ static int portable_extract_by_path(
                 if (r < 0)
                         return log_debug_errno(r, "Failed to create temporary directory: %m");
 
-                r = dissect_image(
-                                d->fd,
+                r = dissect_loop_device(
+                                d,
                                 NULL, NULL,
-                                d->diskseq,
-                                d->uevent_seqnum_not_before,
-                                d->timestamp_not_before,
                                 DISSECT_IMAGE_READ_ONLY |
                                 DISSECT_IMAGE_GENERIC_ROOT |
                                 DISSECT_IMAGE_REQUIRE_ROOT |
index 3733cf06b2f6cc7e2bdd1c52ffc08b9fccb84d13..b3b59fc0bb46bf908f6d6acdca664aec71e1e3de 100644 (file)
@@ -1196,12 +1196,9 @@ int image_read_metadata(Image *i) {
                 if (r < 0)
                         return r;
 
-                r = dissect_image(
-                                d->fd,
+                r = dissect_loop_device(
+                                d,
                                 NULL, NULL,
-                                d->diskseq,
-                                d->uevent_seqnum_not_before,
-                                d->timestamp_not_before,
                                 DISSECT_IMAGE_GENERIC_ROOT |
                                 DISSECT_IMAGE_REQUIRE_ROOT |
                                 DISSECT_IMAGE_RELAX_VAR_CHECK |
index 6b3a18c011fd3a0feb019ef39ca42ca26d508dd4..ba0bdbbfb6a060aa78f91f8ce308dd6e2db83e7b 100644 (file)
@@ -2796,29 +2796,23 @@ finish:
         return r;
 }
 
-int dissect_image_and_warn(
-                int fd,
+int dissect_loop_device_and_warn(
                 const char *name,
+                const LoopDevice *loop,
                 const VeritySettings *verity,
                 const MountOptions *mount_options,
-                uint64_t diskseq,
-                uint64_t uevent_seqnum_not_before,
-                usec_t timestamp_not_before,
                 DissectImageFlags flags,
                 DissectedImage **ret) {
 
-        _cleanup_free_ char *buffer = NULL;
         int r;
 
-        if (!name) {
-                r = fd_get_path(fd, &buffer);
-                if (r < 0)
-                        return r;
+        assert(loop);
+        assert(loop->fd >= 0);
 
-                name = buffer;
-        }
+        if (!name)
+                name = ASSERT_PTR(loop->node);
 
-        r = dissect_image(fd, verity, mount_options, diskseq, uevent_seqnum_not_before, timestamp_not_before, flags, ret);
+        r = dissect_loop_device(loop, verity, mount_options, flags, ret);
         switch (r) {
 
         case -EOPNOTSUPP:
@@ -2971,7 +2965,7 @@ int mount_image_privately_interactively(
         if (r < 0)
                 return log_error_errno(r, "Failed to set up loopback device for %s: %m", image);
 
-        r = dissect_image_and_warn(d->fd, image, &verity, NULL, d->diskseq, d->uevent_seqnum_not_before, d->timestamp_not_before, flags, &dissected_image);
+        r = dissect_loop_device_and_warn(image, d, &verity, NULL, flags, &dissected_image);
         if (r < 0)
                 return r;
 
@@ -3082,24 +3076,18 @@ int verity_dissect_and_mount(
         if (r < 0)
                 return log_debug_errno(r, "Failed to create loop device for image: %m");
 
-        r = dissect_image(
-                        loop_device->fd,
+        r = dissect_loop_device(
+                        loop_device,
                         &verity,
                         options,
-                        loop_device->diskseq,
-                        loop_device->uevent_seqnum_not_before,
-                        loop_device->timestamp_not_before,
                         dissect_image_flags,
                         &dissected_image);
         /* No partition table? Might be a single-filesystem image, try again */
         if (!verity.data_path && r == -ENOPKG)
-                 r = dissect_image(
-                                loop_device->fd,
+                 r = dissect_loop_device(
+                                loop_device,
                                 &verity,
                                 options,
-                                loop_device->diskseq,
-                                loop_device->uevent_seqnum_not_before,
-                                loop_device->timestamp_not_before,
                                 dissect_image_flags | DISSECT_IMAGE_NO_PARTITION_TABLE,
                                 &dissected_image);
         if (r < 0)
index 55bb8a1dadc27ccc61370774a051476078881617..2e71fda8b448ea63792384eea1c435a905310e73 100644 (file)
@@ -254,7 +254,11 @@ const char* mount_options_from_designator(const MountOptions *options, Partition
 
 int probe_filesystem(const char *node, char **ret_fstype);
 int dissect_image(int fd, const VeritySettings *verity, const MountOptions *mount_options, uint64_t diskseq, uint64_t uevent_seqnum_not_before, usec_t timestamp_not_before, DissectImageFlags flags, DissectedImage **ret);
-int dissect_image_and_warn(int fd, const char *name, const VeritySettings *verity, const MountOptions *mount_options, uint64_t diskseq, uint64_t uevent_seqnum_not_before, usec_t timestamp_not_before, DissectImageFlags flags, DissectedImage **ret);
+static inline int dissect_loop_device(const LoopDevice *loop, const VeritySettings *verity, const MountOptions *mount_options, DissectImageFlags flags, DissectedImage **ret) {
+        assert(loop);
+        return dissect_image(loop->fd, verity, mount_options, loop->diskseq, loop->uevent_seqnum_not_before, loop->timestamp_not_before, flags, ret);
+}
+int dissect_loop_device_and_warn(const char *name, const LoopDevice *loop, const VeritySettings *verity, const MountOptions *mount_options, DissectImageFlags flags, DissectedImage **ret);
 
 DissectedImage* dissected_image_unref(DissectedImage *m);
 DEFINE_TRIVIAL_CLEANUP_FUNC(DissectedImage*, dissected_image_unref);
index 6e533f335c4431db658d9b24e879002aacd50ee1..93ddc73b4624431011ec5aaa5b75f01dc433f8fd 100644 (file)
@@ -539,14 +539,11 @@ static int merge_subprocess(Hashmap *images, const char *workspace) {
                         if (r < 0)
                                 return log_error_errno(r, "Failed to set up loopback device for %s: %m", img->path);
 
-                        r = dissect_image_and_warn(
-                                        d->fd,
+                        r = dissect_loop_device_and_warn(
                                         img->path,
+                                        d,
                                         &verity_settings,
                                         NULL,
-                                        d->diskseq,
-                                        d->uevent_seqnum_not_before,
-                                        d->timestamp_not_before,
                                         flags,
                                         &m);
                         if (r < 0)
index fb5e0a2fc9902680c629d6b84dbfdd883eae06f0..effd6535af94f178468060245c7f213ae810e84c 100644 (file)
@@ -56,7 +56,7 @@ static void* thread_func(void *ptr) {
 
                 log_notice("Acquired loop device %s, will mount on %s", loop->node, mounted);
 
-                r = dissect_image(loop->fd, NULL, NULL, loop->diskseq, loop->uevent_seqnum_not_before, loop->timestamp_not_before, DISSECT_IMAGE_READ_ONLY, &dissected);
+                r = dissect_loop_device(loop, NULL, NULL, DISSECT_IMAGE_READ_ONLY, &dissected);
                 if (r < 0)
                         log_error_errno(r, "Failed dissect loopback device %s: %m", loop->node);
                 assert_se(r >= 0);
@@ -220,7 +220,7 @@ static int run(int argc, char *argv[]) {
         pthread_t threads[arg_n_threads];
         sd_id128_t id;
 
-        assert_se(dissect_image(loop->fd, NULL, NULL, loop->diskseq, loop->uevent_seqnum_not_before, loop->timestamp_not_before, 0, &dissected) >= 0);
+        assert_se(dissect_loop_device(loop, NULL, NULL, 0, &dissected) >= 0);
 
         assert_se(dissected->partitions[PARTITION_ESP].found);
         assert_se(dissected->partitions[PARTITION_ESP].node);
@@ -244,7 +244,7 @@ static int run(int argc, char *argv[]) {
         assert_se(make_filesystem(dissected->partitions[PARTITION_HOME].node, "ext4", "home", id, true) >= 0);
 
         dissected = dissected_image_unref(dissected);
-        assert_se(dissect_image(loop->fd, NULL, NULL, loop->diskseq, loop->uevent_seqnum_not_before, loop->timestamp_not_before, 0, &dissected) >= 0);
+        assert_se(dissect_loop_device(loop, NULL, NULL, 0, &dissected) >= 0);
 
         assert_se(mkdtemp_malloc(NULL, &mounted) >= 0);