Simplify load_luks2_by_name.

Also adds specific error messsage when device
is not actualy LUKS2.
This commit is contained in:
Ondrej Kozina
2022-03-21 12:00:41 +01:00
committed by Milan Broz
parent f388662418
commit b10c0b6a02

View File

@@ -843,18 +843,19 @@ out:
static enum device_status_info load_luks2_by_name(struct crypt_device **r_cd, const char *active_name, const char *header_device) static enum device_status_info load_luks2_by_name(struct crypt_device **r_cd, const char *active_name, const char *header_device)
{ {
int r; int r;
struct crypt_device *cd = NULL; struct crypt_device *cd;
assert(r_cd); assert(r_cd);
assert(active_name); assert(active_name);
r = crypt_init_by_name_and_header(&cd, active_name, header_device); r = crypt_init_by_name_and_header(&cd, active_name, header_device);
if (r || !isLUKS2(crypt_get_type(cd))) { if (r)
crypt_free(cd); return DEVICE_INVALID;
if (r == -EBUSY) /* luks2 locking error (message printed by libcryptsetup) */
return DEVICE_INVALID;
return DEVICE_NOT_LUKS; if (!isLUKS2(crypt_get_type(cd))) {
log_err(_("Active device %s is not LUKS2."), active_name);
crypt_free(cd);
return DEVICE_INVALID;
} }
r = luks2_reencrypt_in_progress(cd); r = luks2_reencrypt_in_progress(cd);