add support for recognizing Linux md components
authorDavid Zeuthen <davidz@redhat.com>
Sun, 30 Mar 2008 23:49:28 +0000 (19:49 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Sun, 30 Mar 2008 23:49:28 +0000 (19:49 -0400)
Depends on a patch to udev for making vol_id export some more
information. Sent to Kay for review.

src/devkit-disks-device-private.h
src/devkit-disks-device.c
src/org.freedesktop.DeviceKit.Disks.Device.xml
tools/devkit-disks.c

index 46f6a0e..28b307e 100644 (file)
@@ -61,6 +61,7 @@ struct DevkitDisksDevicePrivate
                 gboolean device_is_read_only;
                 gboolean device_is_drive;
                 gboolean device_is_crypto_cleartext;
+                gboolean device_is_linux_md_component;
                 guint64 device_size;
                 guint64 device_block_size;
                 gboolean device_is_mounted;
@@ -99,6 +100,12 @@ struct DevkitDisksDevicePrivate
 
                 char *crypto_cleartext_slave;
 
+                int linux_md_component_level;
+                int linux_md_component_num_raid_devices;
+                char *linux_md_component_uuid;
+                char *linux_md_component_name;
+                char *linux_md_component_version;
+
                 /* the following properties are not (yet) exported */
                 char *dm_name;
                 GPtrArray *slaves_objpath;
index abf47a7..11f96f1 100644 (file)
@@ -125,6 +125,7 @@ enum
         PROP_DEVICE_IS_READ_ONLY,
         PROP_DEVICE_IS_DRIVE,
         PROP_DEVICE_IS_CRYPTO_CLEARTEXT,
+        PROP_DEVICE_IS_LINUX_MD_COMPONENT,
         PROP_DEVICE_SIZE,
         PROP_DEVICE_BLOCK_SIZE,
         PROP_DEVICE_IS_MOUNTED,
@@ -171,6 +172,12 @@ enum
         PROP_DRIVE_CONNECTION_SPEED,
         PROP_DRIVE_MEDIA_COMPATIBILITY,
         PROP_DRIVE_MEDIA,
+
+        PROP_LINUX_MD_COMPONENT_LEVEL,
+        PROP_LINUX_MD_COMPONENT_NUM_RAID_DEVICES,
+        PROP_LINUX_MD_COMPONENT_UUID,
+        PROP_LINUX_MD_COMPONENT_NAME,
+        PROP_LINUX_MD_COMPONENT_VERSION,
 };
 
 enum
@@ -302,6 +309,9 @@ get_property (GObject         *object,
        case PROP_DEVICE_IS_CRYPTO_CLEARTEXT:
                g_value_set_boolean (value, device->priv->info.device_is_crypto_cleartext);
                break;
+       case PROP_DEVICE_IS_LINUX_MD_COMPONENT:
+               g_value_set_boolean (value, device->priv->info.device_is_linux_md_component);
+               break;
        case PROP_DEVICE_SIZE:
                g_value_set_uint64 (value, device->priv->info.device_size);
                break;
@@ -436,6 +446,22 @@ get_property (GObject         *object,
                g_value_set_string (value, device->priv->info.drive_media);
                break;
 
+       case PROP_LINUX_MD_COMPONENT_LEVEL:
+               g_value_set_int (value, device->priv->info.linux_md_component_level);
+               break;
+       case PROP_LINUX_MD_COMPONENT_NUM_RAID_DEVICES:
+               g_value_set_int (value, device->priv->info.linux_md_component_num_raid_devices);
+               break;
+       case PROP_LINUX_MD_COMPONENT_UUID:
+               g_value_set_string (value, device->priv->info.linux_md_component_uuid);
+               break;
+       case PROP_LINUX_MD_COMPONENT_NAME:
+               g_value_set_string (value, device->priv->info.linux_md_component_name);
+               break;
+       case PROP_LINUX_MD_COMPONENT_VERSION:
+               g_value_set_string (value, device->priv->info.linux_md_component_version);
+               break;
+
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
@@ -535,6 +561,10 @@ devkit_disks_device_class_init (DevkitDisksDeviceClass *klass)
                 g_param_spec_boolean ("device-is-crypto-cleartext", NULL, NULL, FALSE, G_PARAM_READABLE));
         g_object_class_install_property (
                 object_class,
+                PROP_DEVICE_IS_LINUX_MD_COMPONENT,
+                g_param_spec_boolean ("device-is-linux-md-component", NULL, NULL, FALSE, G_PARAM_READABLE));
+        g_object_class_install_property (
+                object_class,
                 PROP_DEVICE_SIZE,
                 g_param_spec_uint64 ("device-size", NULL, NULL, 0, G_MAXUINT64, 0, G_PARAM_READABLE));
         g_object_class_install_property (
@@ -707,6 +737,28 @@ devkit_disks_device_class_init (DevkitDisksDeviceClass *klass)
                 object_class,
                 PROP_DRIVE_MEDIA,
                 g_param_spec_string ("drive-media", NULL, NULL, NULL, G_PARAM_READABLE));
+
+
+        g_object_class_install_property (
+                object_class,
+                PROP_LINUX_MD_COMPONENT_LEVEL,
+                g_param_spec_int ("linux-md-component-level", 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 (
+                object_class,
+                PROP_LINUX_MD_COMPONENT_UUID,
+                g_param_spec_string ("linux-md-component-uuid", NULL, NULL, NULL, G_PARAM_READABLE));
+        g_object_class_install_property (
+                object_class,
+                PROP_LINUX_MD_COMPONENT_NAME,
+                g_param_spec_string ("linux-md-component-name", NULL, NULL, NULL, G_PARAM_READABLE));
+        g_object_class_install_property (
+                object_class,
+                PROP_LINUX_MD_COMPONENT_VERSION,
+                g_param_spec_string ("linux-md-component-version", NULL, NULL, NULL, G_PARAM_READABLE));
 }
 
 static void
@@ -1066,10 +1118,22 @@ update_info_properties_cb (DevKitInfo *info, const char *key, void *user_data)
                 device->priv->info.id_type    = _dupv8 (devkit_info_property_get_string (info, key));
         } else if (strcmp (key, "ID_FS_VERSION") == 0) {
                 device->priv->info.id_version = _dupv8 (devkit_info_property_get_string (info, key));
+                if (device->priv->info.device_is_linux_md_component) {
+                        device->priv->info.linux_md_component_version =
+                                _dupv8 (devkit_info_property_get_string (info, key));
+                }
         } else if (strcmp (key, "ID_FS_UUID") == 0) {
                 device->priv->info.id_uuid    = _dupv8 (devkit_info_property_get_string (info, key));
+                if (device->priv->info.device_is_linux_md_component) {
+                        device->priv->info.linux_md_component_uuid =
+                                _dupv8 (devkit_info_property_get_string (info, key));
+                }
         } else if (strcmp (key, "ID_FS_LABEL") == 0) {
                 device->priv->info.id_label   = _dupv8 (devkit_info_property_get_string (info, key));
+                if (device->priv->info.device_is_linux_md_component) {
+                        device->priv->info.linux_md_component_name =
+                                _dupv8 (devkit_info_property_get_string (info, key));
+                }
 
         } else if (strcmp (key, "ID_VENDOR") == 0) {
                 if (device->priv->info.device_is_drive && device->priv->info.drive_vendor == NULL)
@@ -1149,6 +1213,12 @@ update_info_properties_cb (DevKitInfo *info, const char *key, void *user_data)
                         }
                 }
 
+        } else if (strcmp (key, "ID_FS_MD_RAID_DISKS") == 0) {
+                device->priv->info.linux_md_component_num_raid_devices = devkit_info_property_get_int (info, key);
+
+        } else if (strcmp (key, "ID_FS_MD_RAID_LEVEL") == 0) {
+                device->priv->info.linux_md_component_level = devkit_info_property_get_int (info, key);
+
         } else if (strcmp (key, "DM_NAME") == 0) {
                 const char *dm_name;
                 dm_name = devkit_info_property_get_string (info, key);
@@ -1375,6 +1445,7 @@ update_info (DevkitDisksDevice *device)
         GDir *dir;
         const char *name;
         GList *l;
+        const char *fstype;
 
         ret = FALSE;
         info = NULL;
@@ -1520,13 +1591,23 @@ update_info (DevkitDisksDevice *device)
         }
         g_free (path);
 
+        /* ------------------------------------- */
+        /* Now set all properties from udev data */
+        /* ------------------------------------- */
+
+        /* set this first since e.g. ID_FS_LABEL et. al. needs to be redirected/copied */
+        fstype = devkit_info_property_get_string (info, "ID_FS_TYPE");
+        if (fstype != NULL && strcmp (fstype, "linux_raid_member") == 0) {
+                device->priv->info.device_is_linux_md_component = TRUE;
+        }
+
         if (devkit_info_property_foreach (info, update_info_properties_cb, device)) {
                 goto out;
         }
 
         update_slaves (device);
 
-        /* update whether device is mounted */
+        /* Update whether device is mounted */
         l = g_list_prepend (NULL, device);
         devkit_disks_daemon_local_update_mount_state (device->priv->daemon, l, FALSE);
         g_list_free (l);
index cfbacf2..50f5929 100644 (file)
     <property name="device-is-mounted" type="b" access="read"/>
     <property name="device-is-crypto-cleartext" type="b" access="read"/>
     <property name="device-is-busy" type="b" access="read"/>
+    <property name="device-is-linux-md-component" type="b" access="read"/>
     <property name="device-mount-path" type="s" access="read"/>
     <property name="device-size" type="t" access="read"/>
     <property name="device-block-size" type="t" access="read"/>
     <property name="drive-media-compatibility" type="as" access="read"/>
     <property name="drive-media" type="s" access="read"/>
 
+    <!-- The device is a component of a Linux MD (Software RAID) array;
+         see property device-is-linux-md-component
+      -->
+    <property name="linux-md-component-level" type="i" access="read"/>
+    <property name="linux-md-component-num-raid-devices" type="i" access="read"/>
+    <property name="linux-md-component-uuid" type="s" access="read"/>
+    <property name="linux-md-component-name" type="s" access="read"/>
+    <property name="linux-md-component-version" type="s" access="read"/>
+
   </interface>
 
 </node>
index abab62a..83eebd8 100644 (file)
@@ -452,6 +452,7 @@ typedef struct
         gboolean device_is_crypto_cleartext;
         gboolean device_is_mounted;
         gboolean device_is_busy;
+        gboolean device_is_linux_md_component;
         char    *device_mount_path;
         guint64  device_size;
         guint64  device_block_size;
@@ -496,6 +497,12 @@ typedef struct
         guint64  drive_connection_speed;
         char   **drive_media_compatibility;
         char    *drive_media;
+
+        int      linux_md_component_level;
+        int      linux_md_component_num_raid_devices;
+        char    *linux_md_component_uuid;
+        char    *linux_md_component_name;
+        char    *linux_md_component_version;
 } DeviceProperties;
 
 static void
@@ -526,6 +533,8 @@ collect_props (const char *key, const GValue *value, DeviceProperties *props)
                 props->device_is_drive = g_value_get_boolean (value);
         else if (strcmp (key, "device-is-crypto-cleartext") == 0)
                 props->device_is_crypto_cleartext = g_value_get_boolean (value);
+        else if (strcmp (key, "device-is-linux-md-component") == 0)
+                props->device_is_linux_md_component = g_value_get_boolean (value);
         else if (strcmp (key, "device-is-mounted") == 0)
                 props->device_is_mounted = g_value_get_boolean (value);
         else if (strcmp (key, "device-is-busy") == 0)
@@ -620,6 +629,17 @@ collect_props (const char *key, const GValue *value, DeviceProperties *props)
         else if (strcmp (key, "drive-media") == 0)
                 props->drive_media = g_strdup (g_value_get_string (value));
 
+        else if (strcmp (key, "linux-md-component-level") == 0)
+                props->linux_md_component_level = g_value_get_int (value);
+        else if (strcmp (key, "linux-md-component-num-raid-devices") == 0)
+                props->linux_md_component_num_raid_devices = g_value_get_int (value);
+        else if (strcmp (key, "linux-md-component-uuid") == 0)
+                props->linux_md_component_uuid = g_strdup (g_value_get_string (value));
+        else if (strcmp (key, "linux-md-component-name") == 0)
+                props->linux_md_component_name = g_strdup (g_value_get_string (value));
+        else if (strcmp (key, "linux-md-component-version") == 0)
+                props->linux_md_component_version = g_strdup (g_value_get_string (value));
+
         else
                 handled = FALSE;
 
@@ -698,6 +718,9 @@ device_properties_free (DeviceProperties *props)
         g_free (props->drive_connection_interface);
         g_strfreev (props->drive_media_compatibility);
         g_free (props->drive_media);
+        g_free (props->linux_md_component_uuid);
+        g_free (props->linux_md_component_name);
+        g_free (props->linux_md_component_version);
         g_free (props);
 }
 
@@ -768,6 +791,14 @@ do_show_info (const char *object_path)
         g_print ("  version:       %s\n", props->id_version);
         g_print ("  uuid:          %s\n", props->id_uuid);
         g_print ("  label:         %s\n", props->id_label);
+        if (props->device_is_linux_md_component) {
+                g_print ("  linux md component:\n");
+                g_print ("    RAID level:  %d\n", props->linux_md_component_level);
+                g_print ("    num comp:    %d\n", props->linux_md_component_num_raid_devices);
+                g_print ("    uuid:        %s\n", props->linux_md_component_uuid);
+                g_print ("    name:        %s\n", props->linux_md_component_name);
+                g_print ("    version:     %s\n", props->linux_md_component_version);
+        }
         if (props->device_is_crypto_cleartext) {
                 g_print ("  cleartext crypto device:\n");
                 g_print ("    backed by:   %s\n", props->crypto_cleartext_slave);