Use LUKS2_reencrypt prefix for function defined in luks2.h.

This should clean up prefixes a little bit.
This commit is contained in:
Milan Broz
2020-07-04 11:48:23 +02:00
parent 286784c934
commit dc0ecd4288
4 changed files with 47 additions and 33 deletions

View File

@@ -426,15 +426,27 @@ int LUKS2_reencrypt_locked_recovery_by_passphrase(struct crypt_device *cd,
uint32_t flags, uint32_t flags,
struct volume_key **vks); struct volume_key **vks);
void LUKS2_reenc_context_free(struct crypt_device *cd, struct luks2_reenc_context *rh); void LUKS2_reencrypt_free(struct crypt_device *cd,
struct luks2_reenc_context *rh);
crypt_reencrypt_info LUKS2_reencrypt_status(struct crypt_device *cd, crypt_reencrypt_info LUKS2_reencrypt_status(struct crypt_device *cd,
struct crypt_params_reencrypt *params); struct crypt_params_reencrypt *params);
int crypt_reencrypt_lock(struct crypt_device *cd, struct crypt_lock_handle **reencrypt_lock); int LUKS2_reencrypt_lock(struct crypt_device *cd,
int crypt_reencrypt_lock_by_dm_uuid(struct crypt_device *cd, const char *dm_uuid, struct crypt_lock_handle **reencrypt_lock); struct crypt_lock_handle **reencrypt_lock);
void crypt_reencrypt_unlock(struct crypt_device *cd, struct crypt_lock_handle *reencrypt_lock);
int luks2_check_device_size(struct crypt_device *cd, struct luks2_hdr *hdr, uint64_t check_size, uint64_t *dev_size, bool activation, bool dynamic); int LUKS2_reencrypt_lock_by_dm_uuid(struct crypt_device *cd,
const char *dm_uuid,
struct crypt_lock_handle **reencrypt_lock);
void LUKS2_reencrypt_unlock(struct crypt_device *cd,
struct crypt_lock_handle *reencrypt_lock);
int LUKS2_reencrypt_check_device_size(struct crypt_device *cd,
struct luks2_hdr *hdr,
uint64_t check_size,
uint64_t *dev_size,
bool activation,
bool dynamic);
#endif #endif

View File

@@ -2260,7 +2260,7 @@ int LUKS2_deactivate(struct crypt_device *cd, const char *name, struct luks2_hdr
goto out; goto out;
if (contains_reencryption_helper(deps)) { if (contains_reencryption_helper(deps)) {
r = crypt_reencrypt_lock_by_dm_uuid(cd, dmd->uuid, &reencrypt_lock); r = LUKS2_reencrypt_lock_by_dm_uuid(cd, dmd->uuid, &reencrypt_lock);
if (r) { if (r) {
if (r == -EBUSY) if (r == -EBUSY)
log_err(cd, _("Reencryption in-progress. Cannot deactivate device.")); log_err(cd, _("Reencryption in-progress. Cannot deactivate device."));
@@ -2339,7 +2339,7 @@ int LUKS2_deactivate(struct crypt_device *cd, const char *name, struct luks2_hdr
} }
out: out:
crypt_reencrypt_unlock(cd, reencrypt_lock); LUKS2_reencrypt_unlock(cd, reencrypt_lock);
dep = deps; dep = deps;
while (*dep) while (*dep)
free(*dep++); free(*dep++);

View File

@@ -727,7 +727,7 @@ static crypt_reencrypt_direction_info reencrypt_direction(struct luks2_hdr *hdr)
typedef enum { REENC_OK = 0, REENC_ERR, REENC_ROLLBACK, REENC_FATAL } reenc_status_t; typedef enum { REENC_OK = 0, REENC_ERR, REENC_ROLLBACK, REENC_FATAL } reenc_status_t;
void LUKS2_reenc_context_free(struct crypt_device *cd, struct luks2_reenc_context *rh) void LUKS2_reencrypt_free(struct crypt_device *cd, struct luks2_reenc_context *rh)
{ {
if (!rh) if (!rh)
return; return;
@@ -1143,7 +1143,7 @@ static int reencrypt_load_clean(struct crypt_device *cd,
return 0; return 0;
err: err:
LUKS2_reenc_context_free(cd, tmp); LUKS2_reencrypt_free(cd, tmp);
return r; return r;
} }
@@ -1237,7 +1237,7 @@ static int reencrypt_load_crashed(struct crypt_device *cd,
r = reencrypt_make_segments_crashed(cd, hdr, *rh); r = reencrypt_make_segments_crashed(cd, hdr, *rh);
if (r) { if (r) {
LUKS2_reenc_context_free(cd, *rh); LUKS2_reencrypt_free(cd, *rh);
*rh = NULL; *rh = NULL;
} }
return r; return r;
@@ -2679,7 +2679,8 @@ out:
} }
/* internal only */ /* internal only */
int crypt_reencrypt_lock_by_dm_uuid(struct crypt_device *cd, const char *dm_uuid, struct crypt_lock_handle **reencrypt_lock) int LUKS2_reencrypt_lock_by_dm_uuid(struct crypt_device *cd, const char *dm_uuid,
struct crypt_lock_handle **reencrypt_lock)
{ {
int r; int r;
char hdr_uuid[37]; char hdr_uuid[37];
@@ -2700,7 +2701,7 @@ int crypt_reencrypt_lock_by_dm_uuid(struct crypt_device *cd, const char *dm_uuid
} }
/* internal only */ /* internal only */
int crypt_reencrypt_lock(struct crypt_device *cd, struct crypt_lock_handle **reencrypt_lock) int LUKS2_reencrypt_lock(struct crypt_device *cd, struct crypt_lock_handle **reencrypt_lock)
{ {
if (!cd || !crypt_get_type(cd) || strcmp(crypt_get_type(cd), CRYPT_LUKS2)) if (!cd || !crypt_get_type(cd) || strcmp(crypt_get_type(cd), CRYPT_LUKS2))
return -EINVAL; return -EINVAL;
@@ -2709,7 +2710,7 @@ int crypt_reencrypt_lock(struct crypt_device *cd, struct crypt_lock_handle **ree
} }
/* internal only */ /* internal only */
void crypt_reencrypt_unlock(struct crypt_device *cd, struct crypt_lock_handle *reencrypt_lock) void LUKS2_reencrypt_unlock(struct crypt_device *cd, struct crypt_lock_handle *reencrypt_lock)
{ {
crypt_unlock_internal(cd, reencrypt_lock); crypt_unlock_internal(cd, reencrypt_lock);
} }
@@ -2731,7 +2732,7 @@ static int reencrypt_lock_and_verify(struct crypt_device *cd, struct luks2_hdr *
return -EINVAL; return -EINVAL;
} }
r = crypt_reencrypt_lock(cd, &h); r = LUKS2_reencrypt_lock(cd, &h);
if (r < 0) { if (r < 0) {
if (r == -EBUSY) if (r == -EBUSY)
log_err(cd, _("Reencryption process is already running.")); log_err(cd, _("Reencryption process is already running."));
@@ -2743,7 +2744,7 @@ static int reencrypt_lock_and_verify(struct crypt_device *cd, struct luks2_hdr *
/* With reencryption lock held, reload device context and verify metadata state */ /* With reencryption lock held, reload device context and verify metadata state */
r = crypt_load(cd, CRYPT_LUKS2, NULL); r = crypt_load(cd, CRYPT_LUKS2, NULL);
if (r) { if (r) {
crypt_reencrypt_unlock(cd, h); LUKS2_reencrypt_unlock(cd, h);
return r; return r;
} }
@@ -2753,7 +2754,7 @@ static int reencrypt_lock_and_verify(struct crypt_device *cd, struct luks2_hdr *
return 0; return 0;
} }
crypt_reencrypt_unlock(cd, h); LUKS2_reencrypt_unlock(cd, h);
log_err(cd, _("Cannot proceed with reencryption. Run reencryption recovery first.")); log_err(cd, _("Cannot proceed with reencryption. Run reencryption recovery first."));
return -EINVAL; return -EINVAL;
} }
@@ -2790,7 +2791,7 @@ static int reencrypt_load_by_passphrase(struct crypt_device *cd,
rh = crypt_get_reenc_context(cd); rh = crypt_get_reenc_context(cd);
if (rh) { if (rh) {
LUKS2_reenc_context_free(cd, rh); LUKS2_reencrypt_free(cd, rh);
crypt_set_reenc_context(cd, NULL); crypt_set_reenc_context(cd, NULL);
rh = NULL; rh = NULL;
} }
@@ -2807,7 +2808,7 @@ static int reencrypt_load_by_passphrase(struct crypt_device *cd,
return -EINVAL; return -EINVAL;
/* some configurations provides fixed device size */ /* some configurations provides fixed device size */
r = luks2_check_device_size(cd, hdr, minimal_size, &device_size, false, dynamic); r = LUKS2_reencrypt_check_device_size(cd, hdr, minimal_size, &device_size, false, dynamic);
if (r) { if (r) {
r = -EINVAL; r = -EINVAL;
goto err; goto err;
@@ -2933,8 +2934,8 @@ static int reencrypt_load_by_passphrase(struct crypt_device *cd,
return 0; return 0;
err: err:
crypt_reencrypt_unlock(cd, reencrypt_lock); LUKS2_reencrypt_unlock(cd, reencrypt_lock);
LUKS2_reenc_context_free(cd, rh); LUKS2_reencrypt_free(cd, rh);
return r; return r;
} }
@@ -2949,7 +2950,7 @@ static int reencrypt_recovery_by_passphrase(struct crypt_device *cd,
crypt_reencrypt_info ri; crypt_reencrypt_info ri;
struct crypt_lock_handle *reencrypt_lock; struct crypt_lock_handle *reencrypt_lock;
r = crypt_reencrypt_lock(cd, &reencrypt_lock); r = LUKS2_reencrypt_lock(cd, &reencrypt_lock);
if (r) { if (r) {
if (r == -EBUSY) if (r == -EBUSY)
log_err(cd, _("Reencryption in-progress. Cannot perform recovery.")); log_err(cd, _("Reencryption in-progress. Cannot perform recovery."));
@@ -2959,13 +2960,13 @@ static int reencrypt_recovery_by_passphrase(struct crypt_device *cd,
} }
if ((r = crypt_load(cd, CRYPT_LUKS2, NULL))) { if ((r = crypt_load(cd, CRYPT_LUKS2, NULL))) {
crypt_reencrypt_unlock(cd, reencrypt_lock); LUKS2_reencrypt_unlock(cd, reencrypt_lock);
return r; return r;
} }
ri = LUKS2_reenc_status(hdr); ri = LUKS2_reenc_status(hdr);
if (ri == CRYPT_REENCRYPT_INVALID) { if (ri == CRYPT_REENCRYPT_INVALID) {
crypt_reencrypt_unlock(cd, reencrypt_lock); LUKS2_reencrypt_unlock(cd, reencrypt_lock);
return -EINVAL; return -EINVAL;
} }
@@ -2979,7 +2980,7 @@ static int reencrypt_recovery_by_passphrase(struct crypt_device *cd,
r = 0; r = 0;
} }
crypt_reencrypt_unlock(cd, reencrypt_lock); LUKS2_reencrypt_unlock(cd, reencrypt_lock);
return r; return r;
} }
@@ -3335,7 +3336,7 @@ static int reencrypt_teardown(struct crypt_device *cd, struct luks2_hdr *hdr,
} }
/* this frees reencryption lock */ /* this frees reencryption lock */
LUKS2_reenc_context_free(cd, rh); LUKS2_reencrypt_free(cd, rh);
crypt_set_reenc_context(cd, NULL); crypt_set_reenc_context(cd, NULL);
return r; return r;
@@ -3434,7 +3435,7 @@ static int reencrypt_recovery(struct crypt_device *cd,
if (!r) if (!r)
r = LUKS2_hdr_write(cd, hdr); r = LUKS2_hdr_write(cd, hdr);
err: err:
LUKS2_reenc_context_free(cd, rh); LUKS2_reencrypt_free(cd, rh);
return r; return r;
} }
@@ -3455,7 +3456,8 @@ int LUKS2_reencrypt_data_offset(struct luks2_hdr *hdr, bool blockwise)
} }
/* internal only */ /* internal only */
int luks2_check_device_size(struct crypt_device *cd, struct luks2_hdr *hdr, uint64_t check_size, uint64_t *dev_size, bool activation, bool dynamic) int LUKS2_reencrypt_check_device_size(struct crypt_device *cd, struct luks2_hdr *hdr,
uint64_t check_size, uint64_t *dev_size, bool activation, bool dynamic)
{ {
int r; int r;
uint64_t data_offset, real_size = 0; uint64_t data_offset, real_size = 0;
@@ -3529,7 +3531,7 @@ int LUKS2_reencrypt_locked_recovery_by_passphrase(struct crypt_device *cd,
vk = crypt_volume_key_next(vk); vk = crypt_volume_key_next(vk);
} }
if (luks2_check_device_size(cd, hdr, minimal_size, &device_size, true, false)) if (LUKS2_reencrypt_check_device_size(cd, hdr, minimal_size, &device_size, true, false))
goto err; goto err;
r = reencrypt_recovery(cd, hdr, device_size, _vks); r = reencrypt_recovery(cd, hdr, device_size, _vks);

View File

@@ -1113,7 +1113,7 @@ static void crypt_free_type(struct crypt_device *cd)
free(cd->u.plain.cipher); free(cd->u.plain.cipher);
free(cd->u.plain.cipher_spec); free(cd->u.plain.cipher_spec);
} else if (isLUKS2(cd->type)) { } else if (isLUKS2(cd->type)) {
LUKS2_reenc_context_free(cd, cd->u.luks2.rh); LUKS2_reencrypt_free(cd, cd->u.luks2.rh);
LUKS2_hdr_free(cd, &cd->u.luks2.hdr); LUKS2_hdr_free(cd, &cd->u.luks2.hdr);
free(cd->u.luks2.keyslot_cipher); free(cd->u.luks2.keyslot_cipher);
} else if (isLUKS1(cd->type)) { } else if (isLUKS1(cd->type)) {
@@ -3985,7 +3985,7 @@ static int _open_and_activate_reencrypt_device(struct crypt_device *cd,
if (crypt_use_keyring_for_vk(cd)) if (crypt_use_keyring_for_vk(cd))
flags |= CRYPT_ACTIVATE_KEYRING_KEY; flags |= CRYPT_ACTIVATE_KEYRING_KEY;
r = crypt_reencrypt_lock(cd, &reencrypt_lock); r = LUKS2_reencrypt_lock(cd, &reencrypt_lock);
if (r) { if (r) {
if (r == -EBUSY) if (r == -EBUSY)
log_err(cd, _("Reencryption in-progress. Cannot activate device.")); log_err(cd, _("Reencryption in-progress. Cannot activate device."));
@@ -4015,7 +4015,7 @@ static int _open_and_activate_reencrypt_device(struct crypt_device *cd,
if (ri == CRYPT_REENCRYPT_NONE) { if (ri == CRYPT_REENCRYPT_NONE) {
crypt_drop_keyring_key(cd, vks); crypt_drop_keyring_key(cd, vks);
crypt_free_volume_key(vks); crypt_free_volume_key(vks);
crypt_reencrypt_unlock(cd, reencrypt_lock); LUKS2_reencrypt_unlock(cd, reencrypt_lock);
return _open_and_activate(cd, keyslot, name, passphrase, passphrase_size, flags); return _open_and_activate(cd, keyslot, name, passphrase, passphrase_size, flags);
} }
@@ -4036,12 +4036,12 @@ static int _open_and_activate_reencrypt_device(struct crypt_device *cd,
log_dbg(cd, "Entering clean reencryption state mode."); log_dbg(cd, "Entering clean reencryption state mode.");
if (r >= 0) if (r >= 0)
r = luks2_check_device_size(cd, hdr, minimal_size, &device_size, true, dynamic_size); r = LUKS2_reencrypt_check_device_size(cd, hdr, minimal_size, &device_size, true, dynamic_size);
if (r >= 0) if (r >= 0)
r = LUKS2_activate_multi(cd, name, vks, device_size >> SECTOR_SHIFT, flags); r = LUKS2_activate_multi(cd, name, vks, device_size >> SECTOR_SHIFT, flags);
err: err:
crypt_reencrypt_unlock(cd, reencrypt_lock); LUKS2_reencrypt_unlock(cd, reencrypt_lock);
if (r < 0) if (r < 0)
crypt_drop_keyring_key(cd, vks); crypt_drop_keyring_key(cd, vks);
crypt_free_volume_key(vks); crypt_free_volume_key(vks);