Add method to remove/delete a LVM LV
authorDavid Zeuthen <davidz@redhat.com>
Tue, 12 Jan 2010 15:13:52 +0000 (10:13 -0500)
committerDavid Zeuthen <davidz@redhat.com>
Tue, 12 Jan 2010 15:13:52 +0000 (10:13 -0500)
data/org.freedesktop.UDisks.xml
src/daemon.h
src/device.c

index 0e8687c..7db6ff3 100644 (file)
 
     <!-- ************************************************************ -->
 
+    <method name="LinuxLvm2LVRemove">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+      <arg name="group_uuid" direction="in" type="s">
+        <doc:doc><doc:summary>The UUID of the volume group of the logical volume to start belongs to.</doc:summary></doc:doc>
+      </arg>
+      <arg name="uuid" direction="in" type="s">
+        <doc:doc><doc:summary>The UUID of the logical volume to remove.</doc:summary></doc:doc>
+      </arg>
+      <arg name="options" direction="in" type="as">
+        <doc:doc><doc:summary>Options for remove the logical volume. Currently no options are supported.</doc:summary></doc:doc>
+      </arg>
+
+      <doc:doc>
+        <doc:description>
+          <doc:para>
+            Removes a LVM2 logical volume.
+          </doc:para>
+        </doc:description>
+        <doc:permission>
+          The caller will need the following PolicyKit authorization:
+          <doc:list>
+            <doc:item>
+              <doc:term>org.freedesktop.udisks.linux-lvm2</doc:term>
+              <doc:definition>
+                Needed to configured Linux LVM2 devices.
+              </doc:definition>
+            </doc:item>
+          </doc:list>
+        </doc:permission>
+        <doc:errors>
+          <doc:error name="&ERROR_NOT_AUTHORIZED;">if the caller lacks the appropriate PolicyKit authorization</doc:error>
+          <doc:error name="&ERROR_BUSY;">if one of the given components are busy</doc:error>
+          <doc:error name="&ERROR_FAILED;">if the operation failed</doc:error>
+          <doc:error name="&ERROR_CANCELLED;">if the job was cancelled</doc:error>
+        </doc:errors>
+      </doc:doc>
+    </method>
+
+    <!-- ************************************************************ -->
+
     <method name="LinuxMdStart">
       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
       <arg name="components" direction="in" type="ao">
index b5bcdf9..026dd6a 100644 (file)
@@ -247,6 +247,12 @@ gboolean daemon_linux_lvm2_lv_set_name (Daemon *daemon,
                                         const gchar *name,
                                         DBusGMethodInvocation *context);
 
+gboolean daemon_linux_lvm2_lv_remove (Daemon *daemon,
+                                      const gchar *group_uuid,
+                                      const gchar *uuid,
+                                      char **options,
+                                      DBusGMethodInvocation *context);
+
 G_END_DECLS
 
 #endif /* __DAEMON_H__ */
index 7fb47dc..3c92579 100644 (file)
@@ -12158,7 +12158,7 @@ linux_lvm2_lv_set_name_completed_cb (DBusGMethodInvocation *context,
         {
           throw_error (context,
                        ERROR_FAILED,
-                       "Error setting name for LVM2 Volume Group: lvrename exited with exit code %d: %s",
+                       "Error setting name for LVM2 Logical Volume: lvrename exited with exit code %d: %s",
                        WEXITSTATUS (status),
                        stderr);
         }
@@ -12241,3 +12241,100 @@ daemon_linux_lvm2_lv_set_name (Daemon *daemon,
 
   return TRUE;
 }
+
+/*--------------------------------------------------------------------------------------------------------------*/
+
+static void
+linux_lvm2_lv_remove_completed_cb (DBusGMethodInvocation *context,
+                                   Device *device,
+                                   gboolean job_was_cancelled,
+                                   int status,
+                                   const char *stderr,
+                                   const char *stdout,
+                                   gpointer user_data)
+{
+  if (WEXITSTATUS (status) == 0 && !job_was_cancelled)
+    {
+      dbus_g_method_return (context);
+    }
+  else
+    {
+      if (job_was_cancelled)
+        {
+          throw_error (context, ERROR_CANCELLED, "Job was cancelled");
+        }
+      else
+        {
+          throw_error (context,
+                       ERROR_FAILED,
+                       "Error removing LVM2 Logical Volume: lvremove exited with exit code %d: %s",
+                       WEXITSTATUS (status),
+                       stderr);
+        }
+    }
+}
+
+static void
+daemon_linux_lvm2_lv_remove_authorized_cb (Daemon *daemon,
+                                           Device *device,
+                                           DBusGMethodInvocation *context,
+                                           const gchar *action_id,
+                                           guint num_user_data,
+                                           gpointer *user_data_elements)
+{
+  const gchar *group_uuid = user_data_elements[0];
+  const gchar *uuid = user_data_elements[1];
+  /* TODO: use options: gchar **options = user_data_elements[2]; */
+  gchar *lv_name;
+  guint n;
+  gchar *argv[10];
+
+  /* Unfortunately lvchange does not (yet - file a bug) accept UUIDs - so find the LV name for this
+   * UUID by looking at PVs
+   */
+  lv_name = find_lvm2_lv_name_for_uuids (daemon, group_uuid, uuid);
+  if (lv_name == NULL)
+    {
+      throw_error (context, ERROR_FAILED, "Cannot find LV with UUID `%s'", uuid);
+      goto out;
+    }
+
+  n = 0;
+  argv[n++] = "lvremove";
+  argv[n++] = lv_name;
+  argv[n++] = "--force";
+  argv[n++] = NULL;
+
+  if (!job_new (context, "LinuxLvm2LVRemove", TRUE, NULL, argv, NULL, linux_lvm2_lv_remove_completed_cb, FALSE, NULL, NULL))
+    {
+      goto out;
+    }
+
+ out:
+  g_free (lv_name);
+}
+
+gboolean
+daemon_linux_lvm2_lv_remove (Daemon *daemon,
+                             const gchar *group_uuid,
+                             const gchar *uuid,
+                             gchar **options,
+                             DBusGMethodInvocation *context)
+{
+  daemon_local_check_auth (daemon,
+                           NULL,
+                           "org.freedesktop.udisks.linux-lvm2",
+                           "LinuxLvm2LVRemove",
+                           TRUE,
+                           daemon_linux_lvm2_lv_remove_authorized_cb,
+                           context,
+                           3,
+                           g_strdup (group_uuid),
+                           g_free,
+                           g_strdup (uuid),
+                           g_free,
+                           g_strdupv (options),
+                           g_strfreev);
+
+  return TRUE;
+}