From f64064fe71363a14ab0c62359e451f9cdc39dc50 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Sun, 17 Mar 2013 20:54:04 +0100 Subject: [PATCH] Fix deactivation of device when failed underlying node disappeared If underlying device disappears (failed drive, removed flash drive etc) cryptsetup cannot report LUKS parameters (header no longer available). Fix return code of init_by name in this situation (crypt context is NULL). Report visible error if deactivation fails and device is still busy. Fixes issue#149. --- lib/setup.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/setup.c b/lib/setup.c index 052c08c..e72722c 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -749,8 +749,12 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name) free(cd->type); cd->type = NULL; r = 0; - goto out; } + } else { + log_dbg("LUKS device header not available."); + free(cd->type); + cd->type = NULL; + r = 0; } } else if (isTCRYPT(cd->type)) { r = TCRYPT_init_by_name(cd, name, &dmd, &cd->device, @@ -2160,6 +2164,10 @@ int crypt_deactivate(struct crypt_device *cd, const char *name) r = TCRYPT_deactivate(cd, name); else r = dm_remove_device(cd, name, 0, 0); + if (r < 0 && crypt_status(cd, name) == CRYPT_BUSY) { + log_err(cd, _("Device %s is still in use.\n"), name); + r = -EBUSY; + } break; case CRYPT_INACTIVE: log_err(cd, _("Device %s is not active.\n"), name); -- 2.7.4