mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2026-01-05 23:15:34 +01:00
Take optimal io size in account with LUKS2 reencryption.
If device properly exposes optimal io size, let's align reencryption hotzone to it. Otherwise device-mapper driver complaints about misaligned tables and reencryption performance is not optimal.
This commit is contained in:
committed by
Milan Broz
parent
09066b1ba6
commit
d13a6f7487
@@ -817,8 +817,13 @@ static int reencrypt_offset(struct luks2_hdr *hdr,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static uint64_t reencrypt_length(struct luks2_hdr *hdr, struct luks2_reenc_context *rh, uint64_t keyslot_area_length, uint64_t length_max)
|
||||
static uint64_t reencrypt_length(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
struct luks2_reenc_context *rh,
|
||||
uint64_t keyslot_area_length,
|
||||
uint64_t length_max)
|
||||
{
|
||||
unsigned long dummy, optimal_alignment;
|
||||
uint64_t length;
|
||||
|
||||
if (rh->rp.type == REENC_PROTECTION_NONE)
|
||||
@@ -835,6 +840,20 @@ static uint64_t reencrypt_length(struct luks2_hdr *hdr, struct luks2_reenc_conte
|
||||
|
||||
length -= (length % rh->alignment);
|
||||
|
||||
/* Emits error later */
|
||||
if (!length)
|
||||
return length;
|
||||
|
||||
device_topology_alignment(cd, crypt_data_device(cd), &optimal_alignment, &dummy, length);
|
||||
|
||||
/* we have to stick with encryption sector size alignment */
|
||||
if (optimal_alignment % rh->alignment)
|
||||
return length;
|
||||
|
||||
/* align to opt-io size only if remaining size allows it */
|
||||
if (length > optimal_alignment)
|
||||
length -= (length % optimal_alignment);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
@@ -920,7 +939,7 @@ static int reencrypt_context_init(struct crypt_device *cd, struct luks2_hdr *hdr
|
||||
} else
|
||||
rh->fixed_length = false;
|
||||
|
||||
rh->length = reencrypt_length(hdr, rh, area_length, params->max_hotzone_size << SECTOR_SHIFT);
|
||||
rh->length = reencrypt_length(cd, hdr, rh, area_length, params->max_hotzone_size << SECTOR_SHIFT);
|
||||
if (reencrypt_offset(hdr, rh->direction, device_size, &rh->length, &rh->offset)) {
|
||||
log_dbg(cd, "Failed to get reencryption offset.");
|
||||
return -EINVAL;
|
||||
|
||||
Reference in New Issue
Block a user