[PATCH] linux device-mapper map type detection

Guido Guenther agx at sigxcpu.org
Wed Apr 23 14:13:50 BST 2008


detect the type of the device map and add it to the displayed type
information
---
 include/parted/device.h |    3 ++
 libparted/arch/linux.c  |   48 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/include/parted/device.h b/include/parted/device.h
index 2a9679f..64b4a0a 100644
--- a/include/parted/device.h
+++ b/include/parted/device.h
@@ -72,6 +72,9 @@ struct _PedDevice {
 
         PedDeviceType   type;           /**< SCSI, IDE, etc.
                                              \deprecated \sa PedDeviceType */
+#ifdef ENABLE_DEVICE_MAPPER
+        char*		dmtype;         /**< device map target type */
+#endif
         long long       sector_size;            /**< logical sector size */
         long long       phys_sector_size;       /**< physical sector size */
         PedSector       length;                 /**< device length (LBA) */
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 9854f51..da1c858 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -302,6 +302,39 @@ _is_sx8_major (int major)
 
 #ifdef ENABLE_DEVICE_MAPPER
 static int
+_dm_maptype (PedDevice* dev)
+{
+        struct dm_task *dmt;
+        void *next = NULL;
+        uint64_t start, length;
+        char *target_type = NULL;
+        char *params;
+        int r = -1;
+
+        if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
+                return r;
+
+        if (!dm_task_set_name(dmt, dev->path))
+                goto bad;
+
+        dm_task_no_open_count(dmt);
+
+        if (!dm_task_run(dmt))
+                goto bad;
+
+        next = dm_get_next_target(dmt, next, &start, &length,
+                                  &target_type, &params);
+
+        dev->dmtype = strdup(target_type);
+        if(dev->dmtype == NULL)
+                goto bad;
+        r = 0;
+bad:
+        dm_task_destroy(dmt);
+        return r;
+}
+
+static int
 readFD (int fd, char **buf)
 {
         char* p;
@@ -489,6 +522,13 @@ _device_probe_type (PedDevice* dev)
 #ifdef ENABLE_DEVICE_MAPPER
         } else if (_is_dm_major(dev_major)) {
                 dev->type = PED_DEVICE_DM;
+                if (_dm_maptype(dev)) {
+                        ped_exception_throw (
+                                PED_EXCEPTION_BUG,
+                                PED_EXCEPTION_CANCEL,
+                                _("Unable to determine the dm type of %s."),
+                                dev->path);
+                }
 #endif
         } else if (dev_major == XVD_MAJOR && (dev_minor % 0x10 == 0)) {
                 dev->type = PED_DEVICE_XVD;
@@ -1106,6 +1146,7 @@ static PedDevice*
 linux_new (const char* path)
 {
         PedDevice*      dev;
+        char* type;
 
         PED_ASSERT (path != NULL, return NULL);
 
@@ -1189,7 +1230,9 @@ linux_new (const char* path)
 
 #ifdef ENABLE_DEVICE_MAPPER
         case PED_DEVICE_DM:
-                if (!init_generic (dev, _("Linux device-mapper")))
+                if (asprintf(&type, _("Linux device-mapper (%s)"), dev->dmtype) == -1)
+                        goto error_free_arch_specific;
+                if (!init_generic (dev, type))
                         goto error_free_arch_specific;
                 break;
 #endif
@@ -1228,6 +1271,9 @@ linux_destroy (PedDevice* dev)
         ped_free (dev->arch_specific);
         ped_free (dev->path);
         ped_free (dev->model);
+#ifdef ENABLE_DEVICE_MAPPER
+        ped_free (dev->dmtype);
+#endif
         ped_free (dev);
 }
 
-- 
1.5.5


--LZvS9be/3tNcYl/X
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-fix-multipath-partition-naming.patch"



More information about the Parted-maintainers mailing list