repart: Allow keeping luks2 volumes opened

This commit is contained in:
Valentin David
2026-05-12 18:31:24 +02:00
parent d0d00297a4
commit 77b15343bc
+9 -5
View File
@@ -4920,6 +4920,7 @@ typedef struct DecryptedPartitionTarget {
int fd;
char *dm_name;
char *volume;
bool keep;
struct crypt_device *device;
} DecryptedPartitionTarget;
@@ -4932,11 +4933,14 @@ static DecryptedPartitionTarget* decrypted_partition_target_free(DecryptedPartit
safe_close(t->fd);
/* 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");
if (!t->keep) {
/* udev or so might access our 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");
} else
log_debug("Keeping encrypted device '%s' open.", t->dm_name);
sym_crypt_free(t->device);
free(t->dm_name);