From: David Zeuthen Date: Tue, 12 Jan 2010 15:13:52 +0000 (-0500) Subject: Add method to remove/delete a LVM LV X-Git-Tag: upstream/2.1.2~698 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=879ae9239cffee9e1a30293d78182fe3c09d4c27;p=platform%2Fupstream%2Fudisks2.git Add method to remove/delete a LVM LV --- diff --git a/data/org.freedesktop.UDisks.xml b/data/org.freedesktop.UDisks.xml index 0e8687c..7db6ff3 100644 --- a/data/org.freedesktop.UDisks.xml +++ b/data/org.freedesktop.UDisks.xml @@ -482,6 +482,46 @@ + + + + The UUID of the volume group of the logical volume to start belongs to. + + + The UUID of the logical volume to remove. + + + Options for remove the logical volume. Currently no options are supported. + + + + + + Removes a LVM2 logical volume. + + + + The caller will need the following PolicyKit authorization: + + + org.freedesktop.udisks.linux-lvm2 + + Needed to configured Linux LVM2 devices. + + + + + + if the caller lacks the appropriate PolicyKit authorization + if one of the given components are busy + if the operation failed + if the job was cancelled + + + + + + diff --git a/src/daemon.h b/src/daemon.h index b5bcdf9..026dd6a 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -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__ */ diff --git a/src/device.c b/src/device.c index 7fb47dc..3c92579 100644 --- a/src/device.c +++ b/src/device.c @@ -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; +}