[gnome-disk-utility] Also use the create_volume() method on GduDrive to add PVs to a VG
- From: David Zeuthen <davidz src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility] Also use the create_volume() method on GduDrive to add PVs to a VG
- Date: Fri, 5 Feb 2010 00:17:13 +0000 (UTC)
commit fb47c1254516b280e0d687de216fdb642adb60b6
Author: David Zeuthen <davidz redhat com>
Date: Thu Feb 4 19:15:13 2010 -0500
Also use the create_volume() method on GduDrive to add PVs to a VG
This way we can now create LVs on another VG when creating a PV.
.../gdu-section-linux-lvm2-volume-group.c | 171 +++---------------
src/palimpsest/gdu-section-linux-md-drive.c | 185 ++++----------------
2 files changed, 64 insertions(+), 292 deletions(-)
---
diff --git a/src/palimpsest/gdu-section-linux-lvm2-volume-group.c b/src/palimpsest/gdu-section-linux-lvm2-volume-group.c
index e3d2c5c..d23fa59 100644
--- a/src/palimpsest/gdu-section-linux-lvm2-volume-group.c
+++ b/src/palimpsest/gdu-section-linux-lvm2-volume-group.c
@@ -266,158 +266,42 @@ add_pv_cb (GduPool *pool,
}
static void
-add_pv_create_part_cb (GduDevice *device,
- gchar *created_device_object_path,
- GError *error,
- gpointer user_data)
+new_pv_create_volume_cb (GduDrive *drive,
+ GAsyncResult *res,
+ gpointer user_data)
{
AddPvData *data = user_data;
-
- if (error != NULL) {
- GtkWidget *dialog;
- dialog = gdu_error_dialog_new_for_drive (GTK_WINDOW (gdu_shell_get_toplevel (data->shell)),
- device,
- _("Error creating partition for RAID pv"),
- error);
- gtk_widget_show_all (dialog);
- gtk_window_present (GTK_WINDOW (dialog));
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
+ GduVolume *volume;
+ GError *error;
+
+ error = NULL;
+ volume = gdu_drive_create_volume_finish (drive,
+ res,
+ &error);
+ if (volume == NULL) {
+ gdu_shell_raise_error (data->shell,
+ NULL,
+ error,
+ _("Error creating PV for VG"));
g_error_free (error);
-
- if (data != NULL)
add_pv_data_free (data);
} else {
GduPool *pool;
- pool = gdu_device_get_pool (device);
+ GduDevice *pv_device;
+
+ pv_device = gdu_presentable_get_device (GDU_PRESENTABLE (volume));
+ pool = gdu_device_get_pool (pv_device);
+
gdu_pool_op_linux_lvm2_vg_add_pv (pool,
gdu_linux_lvm2_volume_group_get_uuid (data->vg),
- created_device_object_path,
+ gdu_device_get_object_path (pv_device),
add_pv_cb,
data);
- g_free (created_device_object_path);
- g_object_unref (pool);
- }
-}
-
-static void do_add_pv (AddPvData *data);
-static void
-add_pv_create_part_table_cb (GduDevice *device,
- GError *error,
- gpointer user_data)
-{
- AddPvData *data = user_data;
-
- if (error != NULL) {
- GtkWidget *dialog;
- dialog = gdu_error_dialog_new_for_drive (GTK_WINDOW (gdu_shell_get_toplevel (data->shell)),
- device,
- _("Error creating partition table for LVM2 PV"),
- error);
- gtk_widget_show_all (dialog);
- gtk_window_present (GTK_WINDOW (dialog));
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- g_error_free (error);
-
- add_pv_data_free (data);
- } else {
- do_add_pv (data);
- }
-}
-
-static void
-do_add_pv (AddPvData *data)
-{
- gboolean whole_disk_is_uninitialized;
- guint64 largest_segment;
- GduPresentable *p;
- GduDevice *d;
-
- p = NULL;
- d = NULL;
-
- g_warn_if_fail (gdu_drive_can_create_volume (data->drive_to_add_to,
- &whole_disk_is_uninitialized,
- &largest_segment,
- NULL, /* total_free */
- &p));
- g_assert (p != NULL);
- g_assert_cmpint (data->size, <=, largest_segment);
-
- d = gdu_presentable_get_device (GDU_PRESENTABLE (data->drive_to_add_to));
-
- if (GDU_IS_VOLUME_HOLE (p)) {
- guint64 offset;
- const gchar *scheme;
- const gchar *type;
- gchar *name;
- gchar *label;
-
- offset = gdu_presentable_get_offset (p);
-
- g_debug ("Creating partition for PV of "
- "size %" G_GUINT64_FORMAT " bytes at offset %" G_GUINT64_FORMAT " on %s",
- data->size,
- offset,
- gdu_device_get_device_file (d));
-
- scheme = gdu_device_partition_table_get_scheme (d);
- type = "";
- label = NULL;
- name = gdu_presentable_get_name (GDU_PRESENTABLE (data->vg));
-
- if (g_strcmp0 (scheme, "mbr") == 0) {
- type = "0x8e";
- } else if (g_strcmp0 (scheme, "gpt") == 0) {
- type = "E6D6D379-F507-44C2-A23C-238F2A3DF928";
- /* Limited to 36 UTF-16LE characters according to on-disk format..
- * Since a RAID array name is limited to 32 chars this should fit */
- if (name != NULL && strlen (name) > 0) {
- gchar cut_name[31 * 4 + 1];
- g_utf8_strncpy (cut_name, name, 31);
- label = g_strdup_printf ("LVM2: %s", cut_name);
- } else {
- label = g_strdup ("LVM2 Physical Volume");
- }
- } else if (g_strcmp0 (scheme, "apt") == 0) {
- type = "Apple_Unix_SVR2";
- if (name != NULL && strlen (name) > 0)
- label = g_strdup_printf ("LVM2: %s", name);
- else
- label = g_strdup ("LVM2 Physical Volume");
- }
-
- gdu_device_op_partition_create (d,
- offset,
- data->size,
- type,
- label != NULL ? label : "",
- NULL,
- "",
- "",
- "",
- FALSE,
- add_pv_create_part_cb,
- data);
- g_free (label);
- g_free (name);
- } else {
- /* otherwise the whole disk must be uninitialized... */
- g_assert (whole_disk_is_uninitialized);
-
- /* so create a partition table... */
- gdu_device_op_partition_table_create (d,
- "mbr",
- add_pv_create_part_table_cb,
- data);
+ g_object_unref (pool);
+ g_object_unref (pv_device);
+ g_object_unref (volume);
}
-
- if (p != NULL)
- g_object_unref (p);
- if (d != NULL)
- g_object_unref (d);
}
static void
@@ -450,7 +334,12 @@ on_pvs_dialog_new_button_clicked (GduEditLinuxMdDialog *_dialog,
data->drive_to_add_to = gdu_add_pv_linux_lvm2_dialog_get_drive (GDU_ADD_PV_LINUX_LVM2_DIALOG (dialog));
data->size = gdu_add_pv_linux_lvm2_dialog_get_size (GDU_ADD_PV_LINUX_LVM2_DIALOG (dialog));
- do_add_pv (data);
+ gdu_drive_create_volume (data->drive_to_add_to,
+ data->size,
+ gdu_linux_lvm2_volume_group_get_uuid (vg), /* TODO: name */
+ GDU_CREATE_VOLUME_FLAGS_LINUX_LVM2,
+ (GAsyncReadyCallback) new_pv_create_volume_cb,
+ data);
out:
if (dialog != NULL)
diff --git a/src/palimpsest/gdu-section-linux-md-drive.c b/src/palimpsest/gdu-section-linux-md-drive.c
index cbbb010..48637af 100644
--- a/src/palimpsest/gdu-section-linux-md-drive.c
+++ b/src/palimpsest/gdu-section-linux-md-drive.c
@@ -630,184 +630,62 @@ add_component_cb (GduDevice *device,
GError *error,
gpointer user_data)
{
- GduShell *shell = GDU_SHELL (user_data);
-
- if (error != NULL) {
- GtkWidget *dialog;
- dialog = gdu_error_dialog_new_for_drive (GTK_WINDOW (gdu_shell_get_toplevel (shell)),
- device,
- _("Error adding component to RAID Array"),
- error);
- gtk_widget_show_all (dialog);
- gtk_window_present (GTK_WINDOW (dialog));
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- g_error_free (error);
- }
- g_object_unref (shell);
-}
-
-static void
-add_component_create_part_cb (GduDevice *device,
- gchar *created_device_object_path,
- GError *error,
- gpointer user_data)
-{
AddComponentData *data = user_data;
if (error != NULL) {
GtkWidget *dialog;
dialog = gdu_error_dialog_new_for_drive (GTK_WINDOW (gdu_shell_get_toplevel (data->shell)),
device,
- _("Error creating partition for RAID component"),
+ _("Error adding component to RAID Array"),
error);
gtk_widget_show_all (dialog);
gtk_window_present (GTK_WINDOW (dialog));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_error_free (error);
- } else {
- GduDevice *array_device;
- array_device = gdu_presentable_get_device (GDU_PRESENTABLE (data->linux_md_drive));
- gdu_device_op_linux_md_add_component (array_device,
- created_device_object_path,
- add_component_cb,
- g_object_ref (data->shell));
- g_free (created_device_object_path);
- g_object_unref (array_device);
}
- if (data != NULL)
- add_component_data_free (data);
+ add_component_data_free (data);
}
-static void do_add_component (AddComponentData *data);
-
static void
-add_component_create_part_table_cb (GduDevice *device,
- GError *error,
- gpointer user_data)
+new_component_create_volume_cb (GduDrive *drive,
+ GAsyncResult *res,
+ gpointer user_data)
{
AddComponentData *data = user_data;
-
- if (error != NULL) {
- GtkWidget *dialog;
- dialog = gdu_error_dialog_new_for_drive (GTK_WINDOW (gdu_shell_get_toplevel (data->shell)),
- device,
- _("Error creating partition table for RAID component"),
- error);
- gtk_widget_show_all (dialog);
- gtk_window_present (GTK_WINDOW (dialog));
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
+ GduVolume *volume;
+ GError *error;
+
+ error = NULL;
+ volume = gdu_drive_create_volume_finish (drive,
+ res,
+ &error);
+ if (volume == NULL) {
+ gdu_shell_raise_error (data->shell,
+ NULL,
+ error,
+ _("Error creating component for RAID array"));
g_error_free (error);
-
add_component_data_free (data);
} else {
- do_add_component (data);
- }
-}
-
-static void
-do_add_component (AddComponentData *data)
-{
- gboolean whole_disk_is_uninitialized;
- guint64 largest_segment;
- GduPresentable *p;
- GduDevice *linux_md_device;
- GduDevice *d;
-
- p = NULL;
- d = NULL;
- linux_md_device = NULL;
-
- linux_md_device = gdu_presentable_get_device (GDU_PRESENTABLE (data->linux_md_drive));
- g_warn_if_fail (linux_md_device != NULL);
- if (linux_md_device == NULL)
- goto out;
-
- g_warn_if_fail (gdu_drive_can_create_volume (data->drive_to_add_to,
- &whole_disk_is_uninitialized,
- &largest_segment,
- NULL, /* total_free */
- &p));
- g_assert (p != NULL);
- g_assert_cmpint (data->size, <=, largest_segment);
-
- d = gdu_presentable_get_device (GDU_PRESENTABLE (data->drive_to_add_to));
-
- if (GDU_IS_VOLUME_HOLE (p)) {
- guint64 offset;
- const gchar *scheme;
- const gchar *type;
- const gchar *name;
- gchar *label;
-
- offset = gdu_presentable_get_offset (p);
-
- /*g_debug ("Creating partition for component of "
- "size %" G_GUINT64_FORMAT " bytes at offset %" G_GUINT64_FORMAT " on %s",
- size,
- offset,
- gdu_device_get_device_file (d));*/
-
- scheme = gdu_device_partition_table_get_scheme (d);
- type = "";
- label = NULL;
- name = gdu_device_linux_md_get_name (linux_md_device);
-
- if (g_strcmp0 (scheme, "mbr") == 0) {
- type = "0xfd";
- } else if (g_strcmp0 (scheme, "gpt") == 0) {
- type = "A19D880F-05FC-4D3B-A006-743F0F84911E";
- /* Limited to 36 UTF-16LE characters according to on-disk format..
- * Since a RAID array name is limited to 32 chars this should fit */
- if (name != NULL && strlen (name) > 0)
- label = g_strdup_printf ("RAID: %s", name);
- else
- label = g_strdup ("RAID Component");
- } else if (g_strcmp0 (scheme, "apt") == 0) {
- type = "Apple_Unix_SVR2";
- if (name != NULL && strlen (name) > 0)
- label = g_strdup_printf ("RAID: %s", name);
- else
- label = g_strdup ("RAID Component");
- }
+ GduDevice *component_device;
+ GduDevice *array_device;
- gdu_device_op_partition_create (d,
- offset,
- data->size,
- type,
- label != NULL ? label : "",
- NULL,
- "",
- "",
- "",
- FALSE,
- add_component_create_part_cb,
- data);
- g_free (label);
- } else {
- /* otherwise the whole disk must be uninitialized... */
- g_assert (whole_disk_is_uninitialized);
+ component_device = gdu_presentable_get_device (GDU_PRESENTABLE (volume));
+ array_device = gdu_presentable_get_device (GDU_PRESENTABLE (data->linux_md_drive));
- /* so create a partition table... */
- gdu_device_op_partition_table_create (d,
- "mbr",
- add_component_create_part_table_cb,
+ gdu_device_op_linux_md_add_component (array_device,
+ gdu_device_get_object_path (component_device),
+ add_component_cb,
data);
- }
- out:
- if (p != NULL)
- g_object_unref (p);
- if (d != NULL)
- g_object_unref (d);
- if (linux_md_device != NULL)
- g_object_unref (linux_md_device);
+ g_object_unref (array_device);
+ g_object_unref (component_device);
+ g_object_unref (volume);
+ }
}
-
static void
on_components_dialog_new_button_clicked (GduEditLinuxMdDialog *_dialog,
gpointer user_data)
@@ -843,7 +721,12 @@ on_components_dialog_new_button_clicked (GduEditLinuxMdDialog *_dialog,
data->drive_to_add_to = gdu_add_component_linux_md_dialog_get_drive (GDU_ADD_COMPONENT_LINUX_MD_DIALOG (dialog));
data->size = gdu_add_component_linux_md_dialog_get_size (GDU_ADD_COMPONENT_LINUX_MD_DIALOG (dialog));
- do_add_component (data);
+ gdu_drive_create_volume (data->drive_to_add_to,
+ data->size,
+ gdu_device_linux_md_get_name (device),
+ GDU_CREATE_VOLUME_FLAGS_LINUX_MD,
+ (GAsyncReadyCallback) new_component_create_volume_cb,
+ data);
out:
if (dialog != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]