tree-wide: use dissected_image_relinquish()

This commit is contained in:
Yu Watanabe
2022-09-18 23:47:20 +09:00
parent f906075a15
commit 3044d343dd
4 changed files with 24 additions and 52 deletions
+5 -10
View 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. */
+8 -17
View 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;
+7 -16
View 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;
}
+4 -9
View 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: