Fix mapping removal if device disappeared but node still exists.
authorMilan Broz <gmazyland@gmail.com>
Sat, 29 Jan 2011 15:55:27 +0000 (15:55 +0000)
committerMilan Broz <gmazyland@gmail.com>
Sat, 29 Jan 2011 15:55:27 +0000 (15:55 +0000)
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@420 36d66b0a-2a48-0410-832c-cd162a569da5

ChangeLog
lib/setup.c
lib/utils.c
tests/compat-test

index 2f0ed03..16d9baf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2011-01-29  Milan Broz  <mbroz@redhat.com>
+       * Fix mapping removal if device disappeared but node still exists.
+
 2011-01-25  Milan Broz  <mbroz@redhat.com>
        * Add loop-AES handling (loopaesOpen and loopaesClose commands).
         (requires kernel 2.6.38 and above)
index 01b202e..a264fa2 100644 (file)
@@ -1024,13 +1024,21 @@ int crypt_init_by_name(struct crypt_device **cd, const char *name)
        if (r < 0)
                goto out;
 
+       *cd = NULL;
+       r = crypt_init(cd, device);
+
        /* Underlying device disappeared but mapping still active */
-       if (!device)
+       if (!device || r == -ENOTBLK)
                log_verbose(NULL, _("Underlying device for crypt device %s disappeared.\n"),
                            name);
 
-       *cd = NULL;
-       r = crypt_init(cd, device);
+       /* Underlying device is not readable but crypt mapping exists */
+       if (r == -ENOTBLK) {
+               free(device);
+               device = NULL;
+               r = crypt_init(cd, NULL);
+       }
+
        if (r < 0)
                goto out;
 
index d950a42..a7408e3 100644 (file)
@@ -260,7 +260,7 @@ int device_ready(struct crypt_device *cd, const char *device, int mode)
         /* Try to read first sector */
        s = read_blockwise(devfd, buf, sizeof(buf));
        if (s < 0 || s != sizeof(buf)) {
-               log_err(cd, _("Cannot read device %s.\n"), device);
+               log_verbose(cd, _("Cannot read device %s.\n"), device);
                r = 0;
        }
 
index 29cb943..c073765 100755 (executable)
@@ -278,5 +278,15 @@ echo "bad" | $CRYPTSETUP luksDump $LOOPDEV --dump-master-key 2>/dev/null && fail
 echo "key0" | $CRYPTSETUP luksDump $LOOPDEV --dump-master-key | grep -q "MK dump:" || fail
 $CRYPTSETUP luksDump -q $LOOPDEV --dump-master-key -d $KEY1 | grep -q "MK dump:" || fail
 
+prepare "[22] remove disappeared device" wipe
+dmsetup create $DEV_NAME --table "0 5000 linear $LOOPDEV 2" || fail
+echo "key0" | $CRYPTSETUP -q -i 0 luksFormat /dev/mapper/$DEV_NAME || fail
+echo "key0" | $CRYPTSETUP -q luksOpen /dev/mapper/$DEV_NAME $DEV_NAME2 || fail
+# underlying device now returns error but node is still present
+dmsetup load $DEV_NAME --table "0 5000 error" || fail
+dmsetup resume $DEV_NAME || fail
+$CRYPTSETUP -q luksClose $DEV_NAME2 || fail
+dmsetup remove $DEV_NAME || fail
+
 remove_mapping
 exit 0