[parted-devel] [PATCH 04/11] libparted: set dmraid partition uuid

Phillip Susi psusi at ubuntu.com
Mon Jan 7 04:44:29 UTC 2013


When dmraid creates the partition devices, it assigns them a UUID in the
form of "DMRAID-XXXXX".  When kpartx creates the partitions, it assigns
them a UUID of the form "partN-DMRAID-XXXX".  This patch has parted use
the kpartx style.
---
 NEWS                       |    6 +++++
 libparted/arch/linux.c     |    9 ++++++-
 tests/Makefile.am          |    1 +
 tests/t6004-dmraid-uuid.sh |   59 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 tests/t6004-dmraid-uuid.sh

diff --git a/NEWS b/NEWS
index 5b76b4d..c3d8797 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,12 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** Changes in behavior
 
+  libparted: set dmraid partition uuid.  When dmraid creates the
+  partition devices, it assigns them a UUID in the form of
+  "DMRAID-XXXXX".  When kpartx creates the partitions, it assigns
+  them a UUID of the form "partN-DMRAID-XXXX".  Parted will now
+  set the UUID and use the kpartx style.
+
   parted -l no longer lists device-mapper devices other than
   dmraid whole disks.
 
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 2bb8774..9cc8cb6 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2721,7 +2721,12 @@ _dm_add_partition (PedDisk* disk, const PedPartition* part)
                               part->num);
         if (vol_name == NULL)
                 goto err;
-
+        char *dm_uuid = NULL;
+        if (_is_dmraid_device (disk->dev->path)) {
+                dm_uuid = zasprintf ("part%d-DMRAID-%s", part->num, dev_name);
+                if (!dm_uuid)
+                        goto err;
+        }
         /* Caution: dm_task_destroy frees dev_name.  */
         dm_task_destroy (task);
         task = NULL;
@@ -2736,6 +2741,8 @@ _dm_add_partition (PedDisk* disk, const PedPartition* part)
         dm_task_set_name (task, vol_name);
         dm_task_add_target (task, 0, part->geom.length,
                 "linear", params);
+        if (dm_uuid)
+                dm_task_set_uuid (task, dm_uuid);
         if (dm_task_run (task)) {
                 dm_task_update_nodes ();
                 dm_task_destroy (task);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4ec08da..1669ff7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -60,6 +60,7 @@ TESTS = \
   t6001-psep.sh \
   t6002-dm-busy.sh \
   t6003-dm-hide.sh \
+  t6004-dmraid-uuid.sh \
   t6100-mdraid-partitions.sh \
   t7000-scripting.sh \
   t8000-loop.sh \
diff --git a/tests/t6004-dmraid-uuid.sh b/tests/t6004-dmraid-uuid.sh
new file mode 100644
index 0000000..cceb5de
--- /dev/null
+++ b/tests/t6004-dmraid-uuid.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# ensure that dmraid partitions have their uuid set
+
+# Copyright (C) 2008-2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+require_root_
+
+test "x$ENABLE_DEVICE_MAPPER" = xyes \
+  || skip_ "no device-mapper support"
+
+# Device maps names - should be random to not conflict with existing ones on
+# the system
+linear_=plinear-$$
+
+d1=
+f1=
+dev=
+cleanup_fn_() {
+    # Insist.  Sometimes the initial removal fails (race?).
+    # When that happens, a second removal appears to be sufficient.
+    dmsetup remove $linear_ || dmsetup remove $linear_
+
+    test -n "$d1" && losetup -d "$d1"
+    rm -f "$f1"
+}
+
+f1=$(pwd)/1; d1=$(loop_setup_ "$f1") \
+  || fail=1
+
+# set UUID to pretend it is a dmraid
+echo 0 2048 linear $d1 0 | dmsetup create $linear_ -u "DMRAID-$linear_" || fail=1
+
+# create partition
+parted -s /dev/mapper/$linear_ mklabel msdos || fail=1
+sleep 2
+parted -s -a min /dev/mapper/$linear_ mkpart primary 10s 20s || fail=1
+
+# make sure uuid is set on partition
+dmsetup info ${linear_}p1 | grep UUID > out || fail=1
+echo UUID: part1-DMRAID-$linear_ > exp
+compare out exp || fail=1
+
+parted -s /dev/mapper/$linear_ rm 1
+Exit $fail
-- 
1.7.10.4




More information about the parted-devel mailing list