diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-09-11 23:42:01 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-09-18 23:47:20 +0900 |
commit | 3044d343ddcd090214ac0fdfa2cc1a5b4da93dc1 (patch) | |
tree | 499ba2ab72047a31d91be029d98918feb5999ba6 | |
parent | f906075a1523ec807e4e6614f4bfdea687b558cd (diff) | |
download | systemd-3044d343ddcd090214ac0fdfa2cc1a5b4da93dc1.tar.gz |
tree-wide: use dissected_image_relinquish()
-rw-r--r-- | src/core/namespace.c | 15 | ||||
-rw-r--r-- | src/dissect/dissect.c | 25 | ||||
-rw-r--r-- | src/shared/dissect-image.c | 23 | ||||
-rw-r--r-- | src/sysext/sysext.c | 13 |
4 files changed, 24 insertions, 52 deletions
diff --git a/src/core/namespace.c b/src/core/namespace.c index 468b27905e..d377b44c04 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -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. */ diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index b075222ec5..a73d0f1905 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -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; diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 4949b4c9ee..e103ad3d86 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -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; } diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index e45fa61640..b257831554 100644 --- a/src/sysext/sysext.c +++ b/src/sysext/sysext.c @@ -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: |