int crypt_deactivate(struct crypt_device *cd, const char *name)
{
+ struct crypt_device *fake_cd = NULL;
int r;
if (!name)
log_dbg("Deactivating volume %s.", name);
- if (!cd)
- dm_backend_init();
+ if (!cd) {
+ r = crypt_init_by_name(&fake_cd, name);
+ if (r < 0)
+ return r;
+ cd = fake_cd;
+ }
switch (crypt_status(cd, name)) {
case CRYPT_ACTIVE:
case CRYPT_BUSY:
- if (cd && isTCRYPT(cd->type))
+ if (isTCRYPT(cd->type))
r = TCRYPT_deactivate(cd, name);
else
r = dm_remove_device(cd, name, 0, 0);
r = -EINVAL;
}
- if (!cd)
- dm_backend_exit();
+ crypt_free(fake_cd);
return r;
}