summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-06-13 15:52:03 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-06-13 16:13:19 +0200
commitfd9b68d925f3dc76ba5a87b08967ca720b877986 (patch)
treeeeee7cd4ac72b23e9eac6280280dae99726d6a63
parentMerge pull request #28010 from DaanDeMeyer/vsock-type (diff)
downloadsystemd-fd9b68d925f3dc76ba5a87b08967ca720b877986.tar.xz
systemd-fd9b68d925f3dc76ba5a87b08967ca720b877986.zip
repart: Store dm_name in DecryptedPartitionTarget
This means we don't have to do a fallible allocation in the DecryptedPartitionTarget destructor. Also use log_warning_error_errno() for the failure we ignore in the destructor.
-rw-r--r--src/partition/repart.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c
index 4cf4e4c1f7..634eb2e50c 100644
--- a/src/partition/repart.c
+++ b/src/partition/repart.c
@@ -3157,35 +3157,28 @@ static int context_wipe_and_discard(Context *context) {
typedef struct DecryptedPartitionTarget {
int fd;
+ char *dm_name;
char *volume;
struct crypt_device *device;
} DecryptedPartitionTarget;
static DecryptedPartitionTarget* decrypted_partition_target_free(DecryptedPartitionTarget *t) {
#ifdef HAVE_LIBCRYPTSETUP
- _cleanup_free_ char *name = NULL;
int r;
if (!t)
return NULL;
- r = path_extract_filename(t->volume, &name);
- if (r < 0) {
- assert(r == -ENOMEM);
- log_oom();
- }
-
safe_close(t->fd);
- if (name) {
- /* udev or so might access out block device in the background while we are done. Let's hence
- * force detach the volume. We sync'ed before, hence this should be safe. */
- r = sym_crypt_deactivate_by_name(t->device, name, CRYPT_DEACTIVATE_FORCE);
- if (r < 0)
- log_error_errno(r, "Failed to deactivate LUKS device: %m");
- }
+ /* udev or so might access out block device in the background while we are done. Let's hence
+ * force detach the volume. We sync'ed before, hence this should be safe. */
+ r = sym_crypt_deactivate_by_name(t->device, t->dm_name, CRYPT_DEACTIVATE_FORCE);
+ if (r < 0)
+ log_warning_errno(r, "Failed to deactivate LUKS device, ignoring: %m");
sym_crypt_free(t->device);
+ free(t->dm_name);
free(t->volume);
free(t);
#endif
@@ -3662,6 +3655,7 @@ static int partition_encrypt(Context *context, Partition *p, PartitionTarget *ta
*t = (DecryptedPartitionTarget) {
.fd = TAKE_FD(dev_fd),
+ .dm_name = TAKE_PTR(dm_name),
.volume = TAKE_PTR(vol),
.device = TAKE_PTR(cd),
};