Hi,
I finally got around to cleanup the patch for parted1.8. This adds two
things against current parted git:

0001-linux-device-mapper-map-type-detection.patch: detect the device map
type and store it in the device structure. This changes the size of the
structure so we might have to bump the so name. This feature is useful
in general since people might want to now what type of device they're
acting on. The type is display within parted too.

0002-fix-multipath-partition-naming.patch: based on 0001 this returns
the correct partiton names for device mapper devices.

Please apply. What are the plans for moving libparted 1.8 into unstable?
Besides the bootloader (which is less critical since it's not part of
the installer itself) this is the last missing part to enable
multipath-support in d-i.
Cheers,
 -- Guido
>From dfa381bcc0efb4aca7bc0ebeea9cff2982f5315c Mon Sep 17 00:00:00 2001
From: Guido Guenther <[EMAIL PROTECTED]>
Date: Wed, 23 Apr 2008 15:13:50 +0200
Subject: [PATCH] linux device-mapper map type detection

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

>From 0c8ae57ab0fc6bf43fbfca0927c378ec494dc344 Mon Sep 17 00:00:00 2001
From: Guido Guenther <[EMAIL PROTECTED]>
Date: Wed, 23 Apr 2008 15:16:13 +0200
Subject: [PATCH] fix multipath partition naming

Multipath partitions are named -partX according to the upstream udev
rule:
ENV{DM_STATE}=="ACTIVE", ENV{DM_UUID}=="mpath-*", \
        RUN+="/sbin/kpartx -a -p -part /dev/$kernel"
---
 libparted/arch/linux.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index da1c858..22deb9d 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2016,6 +2016,13 @@ _device_get_part_path (PedDevice* dev, int num)
                 /* replace /disc with /path%d */
                 strcpy (result, dev->path);
                 snprintf (result + path_len - 5, 16, "/part%d", num);
+#ifdef ENABLE_DEVICE_MAPPER
+        } else if (dev->type == PED_DEVICE_DM &&
+                   strcmp(dev->dmtype, "multipath") == 0) {
+                /* This is what multipath-tools upstream and Debian uses, it's
+                 * a pure userpace (udev) decision! */
+                snprintf (result, result_len, "%s-part%d", dev->path, num);
+#endif
         } else if (dev->type == PED_DEVICE_DAC960
                         || dev->type == PED_DEVICE_CPQARRAY
                         || dev->type == PED_DEVICE_ATARAID
-- 
1.5.5

Reply via email to