]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use dissected_image_relinquish()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 11 Sep 2022 14:42:01 +0000 (23:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 18 Sep 2022 14:47:20 +0000 (23:47 +0900)
src/core/namespace.c
src/dissect/dissect.c
src/shared/dissect-image.c
src/sysext/sysext.c

index 468b27905e7e9fdb788e2217e9a15615e7515133..d377b44c041df503b5e9437d3a4d4c19bd879e6c 100644 (file)
@@ -2003,7 +2003,6 @@ int setup_namespace(
                 char **error_path) {
 
         _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
-        _cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
         _cleanup_(dissected_image_unrefp) DissectedImage *dissected_image = NULL;
         _cleanup_(verity_settings_done) VeritySettings verity = VERITY_SETTINGS_DEFAULT;
         _cleanup_strv_free_ char **hierarchies = NULL;
@@ -2084,7 +2083,7 @@ int setup_namespace(
                                 NULL,
                                 &verity,
                                 dissect_image_flags,
-                                &decrypted_image);
+                                NULL);
                 if (r < 0)
                         return log_debug_errno(r, "Failed to decrypt dissected image: %m");
         }
@@ -2416,16 +2415,12 @@ int setup_namespace(
                         goto finish;
                 }
 
-                if (decrypted_image) {
-                        r = decrypted_image_relinquish(decrypted_image);
-                        if (r < 0) {
-                                log_debug_errno(r, "Failed to relinquish decrypted image: %m");
-                                goto finish;
-                        }
+                r = dissected_image_relinquish(dissected_image);
+                if (r < 0) {
+                        log_debug_errno(r, "Failed to relinquish dissected image: %m");
+                        goto finish;
                 }
 
-                loop_device_relinquish(loop_device);
-
         } else if (root_directory) {
 
                 /* A root directory is specified. Turn its directory into bind mount, if it isn't one yet. */
index b075222ec5622a9bb389596548429abcbb7e389e..a73d0f1905639c6dde854552d5c500a53973fe23 100644 (file)
@@ -657,7 +657,6 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
 }
 
 static int action_mount(DissectedImage *m, LoopDevice *d) {
-        _cleanup_(decrypted_image_unrefp) DecryptedImage *di = NULL;
         int r;
 
         assert(m);
@@ -667,7 +666,7 @@ static int action_mount(DissectedImage *m, LoopDevice *d) {
                         m, NULL,
                         &arg_verity_settings,
                         arg_flags,
-                        &di);
+                        NULL);
         if (r < 0)
                 return r;
 
@@ -679,19 +678,15 @@ static int action_mount(DissectedImage *m, LoopDevice *d) {
         if (r < 0)
                 return log_error_errno(r, "Failed to unlock loopback block device: %m");
 
-        if (di) {
-                r = decrypted_image_relinquish(di);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to relinquish DM devices: %m");
-        }
+        r = dissected_image_relinquish(m);
+        if (r < 0)
+                return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
 
-        loop_device_relinquish(d);
         return 0;
 }
 
 static int action_copy(DissectedImage *m, LoopDevice *d) {
         _cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
-        _cleanup_(decrypted_image_unrefp) DecryptedImage *di = NULL;
         _cleanup_(rmdir_and_freep) char *created_dir = NULL;
         _cleanup_free_ char *temp = NULL;
         int r;
@@ -703,7 +698,7 @@ static int action_copy(DissectedImage *m, LoopDevice *d) {
                         m, NULL,
                         &arg_verity_settings,
                         arg_flags,
-                        &di);
+                        NULL);
         if (r < 0)
                 return r;
 
@@ -731,13 +726,9 @@ static int action_copy(DissectedImage *m, LoopDevice *d) {
         if (r < 0)
                 return log_error_errno(r, "Failed to unlock loopback block device: %m");
 
-        if (di) {
-                r = decrypted_image_relinquish(di);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to relinquish DM devices: %m");
-        }
-
-        loop_device_relinquish(d);
+        r = dissected_image_relinquish(m);
+        if (r < 0)
+                return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
 
         if (arg_action == ACTION_COPY_FROM) {
                 _cleanup_close_ int source_fd = -1, target_fd = -1;
index 4949b4c9ee1b08c8f5ece9c7deb9ba3bf8830229..e103ad3d86605815a5b1edcfe75c529da33ae02e 100644 (file)
@@ -3063,13 +3063,9 @@ int mount_image_privately_interactively(
         if (r < 0)
                 return r;
 
-        if (decrypted_image) {
-                r = decrypted_image_relinquish(decrypted_image);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to relinquish DM devices: %m");
-        }
-
-        loop_device_relinquish(d);
+        r = dissected_image_relinquish(dissected_image);
+        if (r < 0)
+                return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
 
         *ret_directory = TAKE_PTR(created_dir);
         *ret_loop_device = TAKE_PTR(d);
@@ -3117,7 +3113,6 @@ int verity_dissect_and_mount(
                 const char *required_sysext_scope) {
 
         _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
-        _cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
         _cleanup_(dissected_image_unrefp) DissectedImage *dissected_image = NULL;
         _cleanup_(verity_settings_done) VeritySettings verity = VERITY_SETTINGS_DEFAULT;
         DissectImageFlags dissect_image_flags;
@@ -3170,7 +3165,7 @@ int verity_dissect_and_mount(
                         NULL,
                         &verity,
                         dissect_image_flags,
-                        &decrypted_image);
+                        NULL);
         if (r < 0)
                 return log_debug_errno(r, "Failed to decrypt dissected image: %m");
 
@@ -3216,13 +3211,9 @@ int verity_dissect_and_mount(
                         return log_debug_errno(r, "Failed to compare image %s extension-release metadata with the root's os-release: %m", dissected_image->image_name);
         }
 
-        if (decrypted_image) {
-                r = decrypted_image_relinquish(decrypted_image);
-                if (r < 0)
-                        return log_debug_errno(r, "Failed to relinquish decrypted image: %m");
-        }
-
-        loop_device_relinquish(loop_device);
+        r = dissected_image_relinquish(dissected_image);
+        if (r < 0)
+                return log_debug_errno(r, "Failed to relinquish dissected image: %m");
 
         return 0;
 }
index e45fa61640c90f8fc371019c8c6ba6d73d15c6cd..b2578315540d4dd5ae2a12790c470102070b5c68 100644 (file)
@@ -514,7 +514,6 @@ static int merge_subprocess(Hashmap *images, const char *workspace) {
                 case IMAGE_BLOCK: {
                         _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
                         _cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
-                        _cleanup_(decrypted_image_unrefp) DecryptedImage *di = NULL;
                         _cleanup_(verity_settings_done) VeritySettings verity_settings = VERITY_SETTINGS_DEFAULT;
                         DissectImageFlags flags =
                                 DISSECT_IMAGE_READ_ONLY |
@@ -559,7 +558,7 @@ static int merge_subprocess(Hashmap *images, const char *workspace) {
                                         m, NULL,
                                         &verity_settings,
                                         flags,
-                                        &di);
+                                        NULL);
                         if (r < 0)
                                 return r;
 
@@ -572,13 +571,9 @@ static int merge_subprocess(Hashmap *images, const char *workspace) {
                         if (r < 0)
                                 return r;
 
-                        if (di) {
-                                r = decrypted_image_relinquish(di);
-                                if (r < 0)
-                                        return log_error_errno(r, "Failed to relinquish DM devices: %m");
-                        }
-
-                        loop_device_relinquish(d);
+                        r = dissected_image_relinquish(m);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
                         break;
                 }
                 default: