Bug 30332 — udisks does not tear down LUKS devices when the slave is forcibly removed
authorMathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
Mon, 27 Sep 2010 12:52:26 +0000 (14:52 +0200)
committerMartin Pitt <martin.pitt@ubuntu.com>
Mon, 27 Sep 2010 12:52:35 +0000 (14:52 +0200)
In the event of the forced removal of a crypto device, use the luks_holder
property since it is still available to figure out which underlying cleartext
LUKS device to teardown, instead of scanning through all available devices
(because the cleartext device already has had its properties cleaned up).

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
src/device.c

index 0bb6ec5..3602f0f 100644 (file)
@@ -11772,32 +11772,25 @@ force_removal (Device *device,
         }
     }
 
-  if (device->priv->id_usage != NULL && strcmp (device->priv->id_usage, "crypto") == 0)
+  if (device->priv->id_usage != NULL && device->priv->luks_holder != NULL && strcmp (device->priv->id_usage, "crypto") == 0)
     {
-      GList *devices;
-      GList *l;
+      Device *d;
 
       /* look for cleartext device  */
-      devices = daemon_local_get_all_devices (device->priv->daemon);
-      for (l = devices; l != NULL; l = l->next)
+      d = daemon_local_find_by_object_path (device->priv->daemon, device->priv->luks_holder);
+      if (strcmp (d->priv->object_path, device->priv->luks_holder) == 0)
         {
-          Device *d = DEVICE (l->data);
-          if (d->priv->device_is_luks_cleartext && d->priv->luks_cleartext_slave != NULL
-              && strcmp (d->priv->luks_cleartext_slave, device->priv->object_path) == 0)
+          /* Check whether it is set up by us */
+          if (d->priv->dm_name != NULL && g_str_has_prefix (d->priv->dm_name, "udisks-luks-uuid-"))
             {
 
-              /* Check whether it is set up by us */
-              if (d->priv->dm_name != NULL && g_str_has_prefix (d->priv->dm_name, "udisks-luks-uuid-"))
-                {
-
-                  g_print ("**** NOTE: Force luks teardown device %s (cleartext %s)\n",
-                           device->priv->device_file,
-                           d->priv->device_file);
+              g_print ("**** NOTE: Force luks teardown device %s (cleartext %s)\n",
+                       device->priv->device_file,
+                       d->priv->device_file);
 
-                  /* Gotcha */
-                  force_luks_teardown (device, d, callback, user_data);
-                  goto pending;
-                }
+              /* Gotcha */
+              force_luks_teardown (device, d, callback, user_data);
+              goto pending;
             }
         }
     }