summaryrefslogtreecommitdiffstats
path: root/src/shared/dissect-image.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-09-11 15:46:39 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-09-18 00:56:32 +0200
commit1e63dc4f1cbec8a2d2bc053b49db23fe9d47a524 (patch)
tree9d56cdd7ff9fbaae288adfb756dabc83bfbebe74 /src/shared/dissect-image.c
parentloop-util: introduce reference counter for LoopDevice (diff)
downloadsystemd-1e63dc4f1cbec8a2d2bc053b49db23fe9d47a524.tar.xz
systemd-1e63dc4f1cbec8a2d2bc053b49db23fe9d47a524.zip
dissect-image: take a reference of LoopDevice into DissectedImage
To make LoopDevice object freed after DissectedImage is freed. At least currently, this should not change anything. Preparation for later commits.
Diffstat (limited to 'src/shared/dissect-image.c')
-rw-r--r--src/shared/dissect-image.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index e97c22d796..ab8813447a 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -1120,6 +1120,10 @@ DissectedImage* dissected_image_unref(DissectedImage *m) {
* DecryptedImage may try to deactivate partitions. */
decrypted_image_unref(m->decrypted_image);
+ /* Third, unref LoopDevice. This must be called after the above two, as freeing LoopDevice may try to
+ * remove existing partitions on the loopback block device. */
+ loop_device_unref(m->loop);
+
free(m->image_name);
free(m->hostname);
strv_free(m->machine_info);
@@ -2794,8 +2798,31 @@ finish:
return r;
}
+int dissect_loop_device(
+ LoopDevice *loop,
+ const VeritySettings *verity,
+ const MountOptions *mount_options,
+ DissectImageFlags flags,
+ DissectedImage **ret) {
+
+ _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
+ int r;
+
+ assert(loop);
+ assert(ret);
+
+ r = dissect_image(loop->fd, loop->node, loop->backing_file ?: loop->node, verity, mount_options, flags, &m);
+ if (r < 0)
+ return r;
+
+ m->loop = loop_device_ref(loop);
+
+ *ret = TAKE_PTR(m);
+ return 0;
+}
+
int dissect_loop_device_and_warn(
- const LoopDevice *loop,
+ LoopDevice *loop,
const VeritySettings *verity,
const MountOptions *mount_options,
DissectImageFlags flags,