Skip to content

Commit

Permalink
WIP - Expose sub-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Jul 4, 2022
1 parent 39a00f3 commit 0a389d2
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 3 deletions.
6 changes: 6 additions & 0 deletions modules/lvm2/data/org.freedesktop.UDisks2.lvm2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@
-->
<property name="Layout" type="s" access="read"/>

<!-- Structure:
The detailed structure of how this logical volume is stored on physical volumes.
-->
<property name="Structure" type="a{sv}" access="read"/>

<!-- SyncRatio:
How far along the logical volume is with resynchronizing. A
Expand Down
2 changes: 1 addition & 1 deletion modules/lvm2/jobhelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void lvs_task_func (GTask *task,
BDLVMLVdata **ret = NULL;
gchar *vg_name = (gchar*) task_data;

ret = bd_lvm_lvs (vg_name, &error);
ret = bd_lvm_lvs_tree (vg_name, &error);
if (!ret)
g_task_return_error (task, error);
else
Expand Down
104 changes: 102 additions & 2 deletions modules/lvm2/udiskslinuxlogicalvolume.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,94 @@ udisks_linux_logical_volume_new (void)

/* ---------------------------------------------------------------------------------------------------- */

// XXX
// - names without brackets

static GVariant *
build_segment (UDisksDaemon *daemon,
UDisksVolumeGroup *group,
BDLVMSEGdata *seg)
{
GVariantBuilder seg_builder;
UDisksObject *block_object;
guint64 extent_size = udisks_volume_group_get_extent_size (group);

g_variant_builder_init (&seg_builder, G_VARIANT_TYPE ("(tto)"));
g_variant_builder_add (&seg_builder, "t", seg->pv_start_pe * extent_size);
g_variant_builder_add (&seg_builder, "t", seg->size_pe * extent_size);
block_object = udisks_daemon_find_block_by_device_file (daemon, seg->pvdev);
if (block_object)
{
g_variant_builder_add (&seg_builder, "o", g_dbus_object_get_object_path (G_DBUS_OBJECT (block_object)));
g_object_unref (block_object);
}
else
g_variant_builder_add (&seg_builder, "o", "/");
return g_variant_builder_end (&seg_builder);
}

static GVariant *build_structure (UDisksDaemon *daemon, UDisksVolumeGroup *group, BDLVMLVdata *lv, BDLVMLVdata **all);

static gboolean
lvnameeq (gchar *name, gchar *maybe_bracketed_name)
{
size_t len = strlen (maybe_bracketed_name);
return (g_strcmp0 (name, maybe_bracketed_name) == 0
|| (maybe_bracketed_name[0] == '['
&& maybe_bracketed_name[len-1] == ']'
&& strlen (name) == len-2
&& strncmp (name, maybe_bracketed_name+1, len-2) == 0));
}

static GVariant *
build_structures (UDisksDaemon *daemon,
UDisksVolumeGroup *group,
gchar **lv_names,
BDLVMLVdata **all)
{
GVariantBuilder list_builder;
g_variant_builder_init (&list_builder, G_VARIANT_TYPE ("aa{sv}"));
for (int i = 0; lv_names[i]; i++)
{
int j;
for (j = 0; all[j]; j++) {
if (lvnameeq (lv_names[i], all[j]->lv_name))
break;
}
if (all[j])
g_variant_builder_add_value (&list_builder, build_structure (daemon, group, all[j], all));
}
return g_variant_builder_end (&list_builder);
}

static GVariant *
build_structure (UDisksDaemon *daemon,
UDisksVolumeGroup *group,
BDLVMLVdata *lv,
BDLVMLVdata **all)
{
GVariantBuilder lv_builder;
g_variant_builder_init (&lv_builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&lv_builder, "{sv}", "name", g_variant_new_string (lv->lv_name));
g_variant_builder_add (&lv_builder, "{sv}", "type", g_variant_new_string (lv->segtype));
g_variant_builder_add (&lv_builder, "{sv}", "size", g_variant_new_uint64 (lv->size));

if (lv->segs) {
GVariantBuilder segs_builder;
g_variant_builder_init (&segs_builder, G_VARIANT_TYPE_ARRAY);
for (int i = 0; lv->segs[i]; i++)
g_variant_builder_add_value (&segs_builder, build_segment (daemon, group, lv->segs[i]));
g_variant_builder_add (&lv_builder, "{sv}", "segments", g_variant_builder_end (&segs_builder));
} else {
if (lv->data_lvs)
g_variant_builder_add (&lv_builder, "{sv}", "data", build_structures (daemon, group, lv->data_lvs, all));
if (lv->metadata_lvs)
g_variant_builder_add (&lv_builder, "{sv}", "metadata", build_structures (daemon, group, lv->metadata_lvs, all));
}

return g_variant_builder_end (&lv_builder);
}

/**
* udisks_linux_logical_volume_update:
* @logical_volume: A #UDisksLinuxLogicalVolume.
Expand All @@ -148,14 +236,21 @@ udisks_linux_logical_volume_update (UDisksLinuxLogicalVolume *logical_volume
BDLVMLVdata **all_lv_infos,
gboolean *needs_polling_ret)
{
UDisksLinuxModuleLVM2 *module;
UDisksDaemon *daemon;
UDisksLogicalVolume *iface;
UDisksVolumeGroup *group;
const char *type;
gboolean active;
const char *pool_objpath;
const char *origin_objpath;
guint64 size = 0;

module = udisks_linux_volume_group_object_get_module (group_object);
daemon = udisks_module_get_daemon (UDISKS_MODULE (module));

iface = UDISKS_LOGICAL_VOLUME (logical_volume);
group = udisks_object_get_volume_group (UDISKS_OBJECT (group_object));

udisks_logical_volume_set_name (iface, lv_info->lv_name);
udisks_logical_volume_set_uuid (iface, lv_info->uuid);
Expand Down Expand Up @@ -183,8 +278,11 @@ udisks_linux_logical_volume_update (UDisksLinuxLogicalVolume *logical_volume
active = TRUE;
}
udisks_logical_volume_set_type_ (iface, type);
udisks_logical_volume_set_layout (iface, lv_info->segtype);
if (g_str_has_prefix (lv_info->segtype, "raid") || g_strcmp0 (lv_info->segtype, "mirror"))
if (g_strcmp0 (lv_info->segtype, "error") == 0)
udisks_logical_volume_set_layout (iface, "linear");
else
udisks_logical_volume_set_layout (iface, lv_info->segtype);
if (g_str_has_prefix (lv_info->segtype, "raid") || g_strcmp0 (lv_info->segtype, "mirror") == 0)
{
udisks_logical_volume_set_sync_ratio (iface, lv_info->copy_percent / 100.0);
if (lv_info->copy_percent != 100)
Expand Down Expand Up @@ -243,6 +341,8 @@ udisks_linux_logical_volume_update (UDisksLinuxLogicalVolume *logical_volume
g_free (dev_file);
}

udisks_logical_volume_set_structure (iface, build_structure (daemon, group, lv_info, all_lv_infos));

g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (iface));
}

Expand Down

0 comments on commit 0a389d2

Please sign in to comment.