mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-14 04:10:06 +01:00
Switch crypt_resize to reload internally.
This ties up few loose ends with regard to target device parameters verification.
This commit is contained in:
committed by
Milan Broz
parent
bdce4b84d8
commit
b9373700a2
27
lib/setup.c
27
lib/setup.c
@@ -2336,11 +2336,7 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size)
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME: check context uuid matches the dm-crypt device uuid.
|
* FIXME: Also with LUKS2 we must not allow resize when there's
|
||||||
* Currently it's possible to resize device (name)
|
|
||||||
* unrelated to device loaded in context.
|
|
||||||
*
|
|
||||||
* Also with LUKS2 we must not allow resize when there's
|
|
||||||
* explicit size stored in metadata (length != "dynamic")
|
* explicit size stored in metadata (length != "dynamic")
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -2350,19 +2346,22 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size)
|
|||||||
|
|
||||||
log_dbg(cd, "Resizing device %s to %" PRIu64 " sectors.", name, new_size);
|
log_dbg(cd, "Resizing device %s to %" PRIu64 " sectors.", name, new_size);
|
||||||
|
|
||||||
r = dm_query_device(cd, name, DM_ACTIVE_DEVICE | DM_ACTIVE_CRYPT_CIPHER |
|
r = dm_query_device(cd, name, DM_ACTIVE_CRYPT_KEYSIZE | DM_ACTIVE_CRYPT_KEY, &dmd);
|
||||||
DM_ACTIVE_UUID | DM_ACTIVE_CRYPT_KEYSIZE |
|
|
||||||
DM_ACTIVE_CRYPT_KEY, &dmd);
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_err(cd, _("Device %s is not active."), name);
|
log_err(cd, _("Device %s is not active."), name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dmd.uuid || dmd.target != DM_CRYPT) {
|
if (dmd.target != DM_CRYPT) {
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dmd.uuid = crypt_get_uuid(cd);
|
||||||
|
dmd.data_device = crypt_data_device(cd);
|
||||||
|
dmd.u.crypt.cipher = crypt_get_cipher_spec(cd);
|
||||||
|
dmd.u.crypt.integrity = crypt_get_integrity(cd);
|
||||||
|
|
||||||
if ((dmd.flags & CRYPT_ACTIVATE_KEYRING_KEY) && !crypt_key_in_keyring(cd)) {
|
if ((dmd.flags & CRYPT_ACTIVATE_KEYRING_KEY) && !crypt_key_in_keyring(cd)) {
|
||||||
r = -EPERM;
|
r = -EPERM;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -2407,21 +2406,17 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size)
|
|||||||
r = 0;
|
r = 0;
|
||||||
} else {
|
} else {
|
||||||
dmd.size = new_size;
|
dmd.size = new_size;
|
||||||
|
dmd.flags |= CRYPT_ACTIVATE_REFRESH;
|
||||||
if (isTCRYPT(cd->type))
|
if (isTCRYPT(cd->type))
|
||||||
r = -ENOTSUP;
|
r = -ENOTSUP;
|
||||||
else if (isLUKS2(cd->type))
|
else if (isLUKS2(cd->type))
|
||||||
r = LUKS2_unmet_requirements(cd, &cd->u.luks2.hdr, 0, 0);
|
r = LUKS2_unmet_requirements(cd, &cd->u.luks2.hdr, 0, 0);
|
||||||
if (!r)
|
if (!r)
|
||||||
r = dm_reload_device(cd, name, &dmd, 1);
|
r = _reload_device(cd, name, &dmd);
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
if (dmd.target == DM_CRYPT) {
|
if (dmd.target == DM_CRYPT)
|
||||||
crypt_free_volume_key(dmd.u.crypt.vk);
|
crypt_free_volume_key(dmd.u.crypt.vk);
|
||||||
free(CONST_CAST(void*)dmd.u.crypt.cipher);
|
|
||||||
free(CONST_CAST(void*)dmd.u.crypt.integrity);
|
|
||||||
}
|
|
||||||
device_free(cd, dmd.data_device);
|
|
||||||
free(CONST_CAST(void*)dmd.uuid);
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user