Add new LinuxMdComponentPosition property
authorDavid Zeuthen <davidz@redhat.com>
Wed, 28 Oct 2009 17:23:22 +0000 (13:23 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 28 Oct 2009 17:23:22 +0000 (13:23 -0400)
data/org.freedesktop.DeviceKit.Disks.Device.xml
src/devkit-disks-device-private.c
src/devkit-disks-device-private.h
src/devkit-disks-device.c
tools/devkit-disks.c

index 0984f82..2759f51 100644 (file)
             is TRUE.
       </doc:para></doc:description></doc:doc>
     </property>
+    <property name="LinuxMdComponentPosition" type="i" access="read">
+      <doc:doc><doc:description><doc:para>
+            The zero-based position of the component or -1 if not part of a running array.
+            This property is only valid if
+            <doc:ref type="property" to="Device:DeviceIsLinuxMdComponent">DeviceIsLinuxMdComponent</doc:ref>
+            is TRUE.
+      </doc:para></doc:description></doc:doc>
+    </property>
     <property name="LinuxMdComponentNumRaidDevices" type="i" access="read">
       <doc:doc><doc:description><doc:para>
             The number of component devices in the array the component is part of.
index 6ab05e5..c7c27c4 100644 (file)
@@ -866,6 +866,16 @@ devkit_disks_device_set_linux_md_component_level (DevkitDisksDevice *device, con
 }
 
 void
+devkit_disks_device_set_linux_md_component_position (DevkitDisksDevice *device, gint value)
+{
+  if (G_UNLIKELY (device->priv->linux_md_component_position != value))
+    {
+      device->priv->linux_md_component_position = value;
+      emit_changed (device, "linux_md_component_position");
+    }
+}
+
+void
 devkit_disks_device_set_linux_md_component_num_raid_devices (DevkitDisksDevice *device, gint value)
 {
   if (G_UNLIKELY (device->priv->linux_md_component_num_raid_devices != value))
index 038daf4..8b8d8d2 100644 (file)
@@ -170,6 +170,7 @@ struct DevkitDisksDevicePrivate
         uid_t luks_cleartext_unlocked_by_uid;
 
         char *linux_md_component_level;
+        int linux_md_component_position;
         int linux_md_component_num_raid_devices;
         char *linux_md_component_uuid;
         char *linux_md_component_home_host;
@@ -288,6 +289,7 @@ void devkit_disks_device_set_luks_cleartext_slave (DevkitDisksDevice *device, co
 void devkit_disks_device_set_luks_cleartext_unlocked_by_uid (DevkitDisksDevice *device, guint value);
 
 void devkit_disks_device_set_linux_md_component_level (DevkitDisksDevice *device, const gchar *value);
+void devkit_disks_device_set_linux_md_component_position (DevkitDisksDevice *device, gint value);
 void devkit_disks_device_set_linux_md_component_num_raid_devices (DevkitDisksDevice *device, gint value);
 void devkit_disks_device_set_linux_md_component_uuid (DevkitDisksDevice *device, const gchar *value);
 void devkit_disks_device_set_linux_md_component_home_host (DevkitDisksDevice *device, const gchar *value);
index 584fd02..19c0319 100644 (file)
@@ -226,6 +226,7 @@ enum
         PROP_DRIVE_ATA_SMART_BLOB,
 
         PROP_LINUX_MD_COMPONENT_LEVEL,
+        PROP_LINUX_MD_COMPONENT_POSITION,
         PROP_LINUX_MD_COMPONENT_NUM_RAID_DEVICES,
         PROP_LINUX_MD_COMPONENT_UUID,
         PROP_LINUX_MD_COMPONENT_HOME_HOST,
@@ -564,6 +565,9 @@ get_property (GObject         *object,
        case PROP_LINUX_MD_COMPONENT_LEVEL:
                g_value_set_string (value, device->priv->linux_md_component_level);
                break;
+       case PROP_LINUX_MD_COMPONENT_POSITION:
+               g_value_set_int (value, device->priv->linux_md_component_position);
+               break;
        case PROP_LINUX_MD_COMPONENT_NUM_RAID_DEVICES:
                g_value_set_int (value, device->priv->linux_md_component_num_raid_devices);
                break;
@@ -1014,6 +1018,10 @@ devkit_disks_device_class_init (DevkitDisksDeviceClass *klass)
                 g_param_spec_string ("linux-md-component-level", NULL, NULL, NULL, G_PARAM_READABLE));
         g_object_class_install_property (
                 object_class,
+                PROP_LINUX_MD_COMPONENT_POSITION,
+                g_param_spec_int ("linux-md-component-position", NULL, NULL, 0, G_MAXINT, 0, G_PARAM_READABLE));
+        g_object_class_install_property (
+                object_class,
                 PROP_LINUX_MD_COMPONENT_NUM_RAID_DEVICES,
                 g_param_spec_int ("linux-md-component-num-raid-devices", NULL, NULL, 0, G_MAXINT, 0, G_PARAM_READABLE));
         g_object_class_install_property (
@@ -2264,6 +2272,9 @@ update_info_linux_md_component (DevkitDisksDevice *device)
                 const gchar *md_comp_version;
                 gchar *md_name;
                 gchar *s;
+                int md_comp_position;
+
+                md_comp_position = -1;
 
                 devkit_disks_device_set_device_is_linux_md_component (device, TRUE);
 
@@ -2280,6 +2291,9 @@ update_info_linux_md_component (DevkitDisksDevice *device)
                                 gchar *dev_name;
                                 gchar *md_dev_path;
                                 gchar *state_contents;
+                                gchar *slot_contents;
+                                gint slot_number;
+                                gchar *endp;
 
                                 dev_name = g_path_get_basename (device->priv->native_path);
                                 md_dev_path = g_strdup_printf ("%s/md/dev-%s", holder->priv->native_path, dev_name);
@@ -2287,6 +2301,14 @@ update_info_linux_md_component (DevkitDisksDevice *device)
                                 g_strstrip (state_contents);
                                 state_tokens = g_strsplit (state_contents, ",", 0);
 
+                                slot_contents = sysfs_get_string (md_dev_path, "slot");
+                                g_strstrip (slot_contents);
+                                slot_number = strtol (slot_contents, &endp, 0);
+                                if (endp != NULL && *endp == '\0') {
+                                        md_comp_position = slot_number;
+                                }
+
+                                g_free (slot_contents);
                                 g_free (state_contents);
                                 g_free (md_dev_path);
                                 g_free (dev_name);
@@ -2319,6 +2341,7 @@ update_info_linux_md_component (DevkitDisksDevice *device)
                 md_comp_version = device->priv->id_version;
 
                 devkit_disks_device_set_linux_md_component_level (device, md_comp_level);
+                devkit_disks_device_set_linux_md_component_position (device, md_comp_position);
                 devkit_disks_device_set_linux_md_component_num_raid_devices (device, md_comp_num_raid_devices);
                 devkit_disks_device_set_linux_md_component_uuid (device, md_comp_uuid);
                 devkit_disks_device_set_linux_md_component_home_host (device, md_comp_home_host);
@@ -2329,6 +2352,7 @@ update_info_linux_md_component (DevkitDisksDevice *device)
         } else {
                 devkit_disks_device_set_device_is_linux_md_component (device, FALSE);
                 devkit_disks_device_set_linux_md_component_level (device, NULL);
+                devkit_disks_device_set_linux_md_component_position (device, -1);
                 devkit_disks_device_set_linux_md_component_num_raid_devices (device, 0);
                 devkit_disks_device_set_linux_md_component_uuid (device, NULL);
                 devkit_disks_device_set_linux_md_component_home_host (device, NULL);
index 0f7dcef..3dcc300 100644 (file)
@@ -382,6 +382,7 @@ typedef struct
         gsize drive_ata_smart_blob_size;
 
         char    *linux_md_component_level;
+        int      linux_md_component_position;
         int      linux_md_component_num_raid_devices;
         char    *linux_md_component_uuid;
         char    *linux_md_component_home_host;
@@ -584,6 +585,8 @@ collect_props (const char *key, const GValue *value, DeviceProperties *props)
 
         else if (strcmp (key, "LinuxMdComponentLevel") == 0)
                 props->linux_md_component_level = g_strdup (g_value_get_string (value));
+        else if (strcmp (key, "LinuxMdComponentPosition") == 0)
+                props->linux_md_component_position = g_value_get_int (value);
         else if (strcmp (key, "LinuxMdComponentNumRaidDevices") == 0)
                 props->linux_md_component_num_raid_devices = g_value_get_int (value);
         else if (strcmp (key, "LinuxMdComponentUuid") == 0)
@@ -1012,7 +1015,8 @@ do_show_info (const char *object_path)
         if (props->device_is_linux_md_component) {
                 g_print ("  linux md component:\n");
                 g_print ("    RAID level:                %s\n", props->linux_md_component_level);
-                g_print ("    num comp:                  %d\n", props->linux_md_component_num_raid_devices);
+                g_print ("    position:                  %d\n", props->linux_md_component_position);
+                g_print ("    num components:            %d\n", props->linux_md_component_num_raid_devices);
                 g_print ("    uuid:                      %s\n", props->linux_md_component_uuid);
                 g_print ("    home host:                 %s\n", props->linux_md_component_home_host);
                 g_print ("    name:                      %s\n", props->linux_md_component_name);