Fix deactivation of device when failed underlying node disappeared
authorMilan Broz <gmazyland@gmail.com>
Sun, 17 Mar 2013 19:54:04 +0000 (20:54 +0100)
committerMilan Broz <gmazyland@gmail.com>
Sun, 17 Mar 2013 19:54:04 +0000 (20:54 +0100)
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

index 052c08c..e72722c 100644 (file)
@@ -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);