Do not query non-existent device twice:
authorMilan Broz <gmazyland@gmail.com>
Fri, 13 Aug 2010 14:05:34 +0000 (14:05 +0000)
committerMilan Broz <gmazyland@gmail.com>
Fri, 13 Aug 2010 14:05:34 +0000 (14:05 +0000)
  # cryptsetup status /dev/nonexistent
  Device /dev/nonexistent not found
  Device /dev/nonexistent not found

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@330 36d66b0a-2a48-0410-832c-cd162a569da5

ChangeLog
lib/libdevmapper.c
lib/setup.c
tests/api-test.c

index fce1cf5..de3b7d4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
        * Rewrite file differ test to C (and fix it to really work).
        * Switch to 1MiB default alignment of data.
          For more info see https://bugzilla.redhat.com/show_bug.cgi?id=621684
+       * Do not query non-existent device twice (cryptsetup status /dev/nonexistent).
 
 2010-07-28  Arno Wagner <arno@wagner.name>
        * Add FAQ (Frequently Asked Questions) file to distribution.
index 3d3c1a4..ec83ec1 100644 (file)
@@ -534,22 +534,16 @@ int dm_status_device(const char *name)
        int r = -EINVAL;
 
        if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
-               return -EINVAL;
+               goto out;
 
-       if (!dm_task_set_name(dmt, name)) {
-               r = -EINVAL;
+       if (!dm_task_set_name(dmt, name))
                goto out;
-       }
 
-       if (!dm_task_run(dmt)) {
-               r = -EINVAL;
+       if (!dm_task_run(dmt))
                goto out;
-       }
 
-       if (!dm_task_get_info(dmt, &dmi)) {
-               r = -EINVAL;
+       if (!dm_task_get_info(dmt, &dmi))
                goto out;
-       }
 
        if (!dmi.exists) {
                r = -ENODEV;
index 06ee656..bf9da03 100644 (file)
@@ -698,26 +698,27 @@ int crypt_query_device(struct crypt_options *options)
                return -ENOSYS;
 
        r = dm_status_device(options->name);
-       if (r == -ENODEV) {
-               dm_exit();
-               return 0;
-       }
+       if (r < 0)
+               goto out;
 
        r = dm_query_device(options->name, (char **)&options->device, &options->size,
                            &options->skip, &options->offset, (char **)&options->cipher,
                            &options->key_size, NULL, &read_only, NULL, NULL);
+       if (r >= 0) {
+               if (read_only)
+                       options->flags |= CRYPT_FLAG_READONLY;
 
-       dm_exit();
-       if (r < 0)
-               return r;
-
-       if (read_only)
-               options->flags |= CRYPT_FLAG_READONLY;
+               options->flags |= CRYPT_FLAG_FREE_DEVICE;
+               options->flags |= CRYPT_FLAG_FREE_CIPHER;
 
-       options->flags |= CRYPT_FLAG_FREE_DEVICE;
-       options->flags |= CRYPT_FLAG_FREE_CIPHER;
+               r = 1;
+       }
+out:
+       if (r == -ENODEV)
+               r = 0;
 
-       return 1;
+       dm_exit();
+       return r;
 }
 
 /* OPTIONS: name, icb */
index a888090..3108fe8 100644 (file)
@@ -293,7 +293,7 @@ static void LuksOpen(void)
 
 static void query_device(void)
 {
-       struct crypt_options co = {. icb = &cmd_icb };
+       struct crypt_options co = {.icb = &cmd_icb };
 
        co.name = CDEVICE_WRONG;
        EQ_(crypt_query_device(&co), 0);
@@ -313,7 +313,7 @@ static void query_device(void)
 static void remove_device(void)
 {
        int fd;
-       struct crypt_options co = {. icb = &cmd_icb };
+       struct crypt_options co = {.icb = &cmd_icb };
 
        co.name = CDEVICE_WRONG;
        EQ_(crypt_remove_device(&co), -ENODEV);