summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-09-02 12:09:51 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-09-02 18:32:01 +0200
commitbad31660eda404b034d20ea0d4b22ca45009f183 (patch)
tree63902b397a92a24e9404543e352b176efdfba7b1 /src
parentloop-util: always set LoopDevice.node (diff)
downloadsystemd-bad31660eda404b034d20ea0d4b22ca45009f183.tar.xz
systemd-bad31660eda404b034d20ea0d4b22ca45009f183.zip
dissect-image: introduce dissect_loop_device() which takes LoopDevice object
Diffstat (limited to 'src')
-rw-r--r--src/core/namespace.c7
-rw-r--r--src/dissect/dissect.c7
-rw-r--r--src/nspawn/nspawn.c7
-rw-r--r--src/portable/portable.c7
-rw-r--r--src/shared/discover-image.c7
-rw-r--r--src/shared/dissect-image.c36
-rw-r--r--src/shared/dissect-image.h6
-rw-r--r--src/sysext/sysext.c7
-rw-r--r--src/test/test-loop-block.c6
9 files changed, 32 insertions, 58 deletions
diff --git a/src/core/namespace.c b/src/core/namespace.c
index 831dcaa81e..468b27905e 100644
--- a/src/core/namespace.c
+++ b/src/core/namespace.c
@@ -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)
diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c
index 2c169fcea1..22872d803c 100644
--- a/src/dissect/dissect.c
+++ b/src/dissect/dissect.c
@@ -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)
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 45e138d48a..ca87bffd0b 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -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) {
diff --git a/src/portable/portable.c b/src/portable/portable.c
index 0f6c71042e..5d0a965db5 100644
--- a/src/portable/portable.c
+++ b/src/portable/portable.c
@@ -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 |
diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c
index 3733cf06b2..b3b59fc0bb 100644
--- a/src/shared/discover-image.c
+++ b/src/shared/discover-image.c
@@ -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 |
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index 6b3a18c011..ba0bdbbfb6 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -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)
diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h
index 55bb8a1dad..2e71fda8b4 100644
--- a/src/shared/dissect-image.h
+++ b/src/shared/dissect-image.h
@@ -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);
diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c
index 6e533f335c..93ddc73b46 100644
--- a/src/sysext/sysext.c
+++ b/src/sysext/sysext.c
@@ -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)
diff --git a/src/test/test-loop-block.c b/src/test/test-loop-block.c
index fb5e0a2fc9..effd6535af 100644
--- a/src/test/test-loop-block.c
+++ b/src/test/test-loop-block.c
@@ -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);