- use dm_udev_wait to synchronize with udev

- use largest_partnum in dm_reread_part_table (#803108)
- preserve the uuid on dm partitions (#832145)
This commit is contained in:
Brian C. Lane 2012-08-03 16:50:43 -07:00
parent 0a9f435399
commit 5c7b01233e
6 changed files with 395 additions and 1 deletions

View File

@ -0,0 +1,86 @@
From e3f74af78b774b235123b9d5fa40fead3b003bb2 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Fri, 20 Jan 2012 15:31:43 -0800
Subject: [PATCH] libparted: use dm_udev_wait (#698121)
This applies Peter Rajnoha's patch to use dm_udev_wait to
synchronize with udev.
This requires libdevmapper v1.02.39 and higher.
Patch is from:
https://lists.gnu.org/archive/html/bug-parted/2010-09/msg00007.html
Resolves: rhbz#698121
---
libparted/arch/linux.c | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index e2c4139..1fcbcad 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -1319,6 +1319,10 @@ linux_new (const char* path)
dev->dirty = 0;
dev->boot_dirty = 0;
+#ifdef ENABLE_DEVICE_MAPPER
+ dm_udev_set_sync_support(1);
+#endif
+
if (!_device_probe_type (dev))
goto error_free_arch_specific;
@@ -2676,16 +2680,21 @@ static int
_dm_remove_map_name(char *name)
{
struct dm_task *task = NULL;
- int rc;
+ int rc = 0;
+ uint32_t cookie = 0;
task = dm_task_create(DM_DEVICE_REMOVE);
if (!task)
return 1;
dm_task_set_name (task, name);
+ if (!dm_task_set_cookie(task, &cookie, 0))
+ goto err;
rc = dm_task_run(task);
+ dm_udev_wait(cookie);
dm_task_update_nodes();
+err:
dm_task_destroy(task);
if (!rc)
return 1;
@@ -2796,6 +2805,7 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
const char* dev_name = NULL;
char* params = NULL;
LinuxSpecific* arch_specific = LINUX_SPECIFIC (disk->dev);
+ uint32_t cookie = 0;
/* Get map name from devicemapper */
struct dm_task *task = dm_task_create (DM_DEVICE_INFO);
@@ -2832,14 +2842,18 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
dm_task_set_name (task, vol_name);
dm_task_add_target (task, 0, part->geom.length,
"linear", params);
+ if (!dm_task_set_cookie(task, &cookie, 0))
+ goto err;
if (dm_task_run (task)) {
//printf("0 %ld linear %s\n", part->geom.length, params);
+ dm_udev_wait(cookie);
dm_task_update_nodes();
dm_task_destroy(task);
free(params);
free(vol_name);
return 1;
} else {
+ dm_udev_wait(cookie);
_dm_remove_map_name(vol_name);
}
err:
--
1.7.7.6

View File

@ -0,0 +1,71 @@
From 399cfc2a9cfc60a46ab9094b4c999bb11a36033e Mon Sep 17 00:00:00 2001
From: Fedora Ninjas <parted-owner@fedoraproject.org>
Date: Fri, 3 Aug 2012 17:03:50 -0700
Subject: [PATCH] libparted: preserve the uuid on dm partitions (#832145)
* libparted/arch/linux.c (_dm_add_partition): Set the uuid if there was
one.
---
libparted/arch/linux.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 37ddb5f..9f0434a 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2803,6 +2803,8 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
{
char* vol_name = NULL;
const char* dev_name = NULL;
+ char* vol_uuid = NULL;
+ const char* dev_uuid = NULL;
char* params = NULL;
LinuxSpecific* arch_specific = LINUX_SPECIFIC (disk->dev);
uint32_t cookie = 0;
@@ -2820,6 +2822,7 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
goto err;
dev_name = dm_task_get_name (task);
+ dev_uuid = dm_task_get_uuid (task);
if (isdigit (dev_name[strlen (dev_name) - 1])) {
if ( ! (vol_name = zasprintf ("%sp%d", dev_name, part->num)))
@@ -2827,6 +2830,10 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
} else if ( ! (vol_name = zasprintf ("%s%d", dev_name, part->num)))
goto err;
+ if ( dev_uuid && (strlen(dev_uuid) > 0) \
+ && ! (vol_uuid = zasprintf ("%sp%d", dev_uuid, part->num)))
+ goto err;
+
/* Caution: dm_task_destroy frees dev_name. */
dm_task_destroy (task);
task = NULL;
@@ -2840,6 +2847,8 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
goto err;
dm_task_set_name (task, vol_name);
+ if (vol_uuid)
+ dm_task_set_uuid (task, vol_uuid);
dm_task_add_target (task, 0, part->geom.length,
"linear", params);
if (!dm_task_set_cookie(task, &cookie, 0))
@@ -2850,6 +2859,7 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
dm_task_update_nodes();
dm_task_destroy(task);
free(params);
+ free(vol_uuid);
free(vol_name);
return 1;
} else {
@@ -2861,6 +2871,7 @@ err:
if (task)
dm_task_destroy (task);
free (params);
+ free (vol_uuid);
free (vol_name);
return 0;
}
--
1.7.7.6

View File

@ -0,0 +1,41 @@
From 26fbffe8389e732be29225bd649adfdd5588b131 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Wed, 21 Mar 2012 15:34:20 -0700
Subject: [PATCH] libparted: use largest_partnum in dm_reread_part_table
(#803108)
DM devices can have more than 16 partitions, notify the kernel about
all of them.
Resolves: rhbz#803108
* libparted/arch/linux.c (dm_reread_part_table): Use largest_partnum
fixup
---
libparted/arch/linux.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 7dd664e..ed14f50 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2516,14 +2516,13 @@ _dm_reread_part_table (PedDisk* disk)
return 1;
int rc = 1;
- int last = PED_MIN (largest_partnum, 16);
int i;
sync();
if (!_dm_remove_parts(disk->dev))
rc = 0;
- for (i = 1; i <= last; i++) {
+ for (i = 1; i <= largest_partnum; i++) {
PedPartition* part;
part = ped_disk_get_partition (disk, i);
--
1.7.7.6

View File

@ -0,0 +1,94 @@
From 166491bd870df6877e04831c9da593e2f8e77ca8 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Thu, 19 Apr 2012 17:11:09 -0700
Subject: [PATCH] tests: test creating 20 device-mapper partitions (#803108)
* tests/t6002-dm-many-partitions.sh: Make sure > 17 partitions appear in
device mapper.
---
tests/Makefile.am | 1 +
tests/t6002-dm-many-partitions.sh | 60 +++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 0 deletions(-)
create mode 100755 tests/t6002-dm-many-partitions.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1b37fd9..57771be 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -55,6 +55,7 @@ TESTS = \
t5000-tags.sh \
t6000-dm.sh \
t6001-psep.sh \
+ t6002-dm-many-partitions.sh \
t6100-mdraid-partitions.sh \
t7000-scripting.sh \
t8000-loop.sh \
diff --git a/tests/t6002-dm-many-partitions.sh b/tests/t6002-dm-many-partitions.sh
new file mode 100755
index 0000000..4d08e72
--- /dev/null
+++ b/tests/t6002-dm-many-partitions.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+# device-mapper: create many partitions
+# This would not create partitions > 16 when using device-mapper
+
+# Copyright (C) 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_
+(dmsetup --help) > /dev/null 2>&1 || skip_test_ "No dmsetup installed"
+
+ss=$sector_size_
+ns=300
+n_partitions=20
+start_sector=34
+loop_file=loop-file-$$
+dm_name=dm-test-$$
+
+cleanup_() {
+ dmsetup remove $dm_name
+ test -n "$dev" && losetup -d "$dev"
+ rm -f $loop_file;
+}
+
+# create a file large enough to hold a GPT partition table
+dd if=/dev/null of=$loop_file bs=$ss seek=$ns || framework_failure
+dev=$(losetup --show -f $loop_file) || framework_failure
+dmsetup create $dm_name --table "0 $ns linear $dev 0" || framework_failure
+
+cmd=
+for ((i=1; i<=$n_partitions; i+=1)); do
+ s=$((start_sector + i - 1))
+ cmd="$cmd mkpart p$i ${s}s ${s}s"
+done
+parted -m -a min -s /dev/mapper/$dm_name mklabel gpt $cmd > /dev/null 2>&1 || fail=1
+
+# Make sure all the partitions appeared under /dev/mapper/
+for ((i=1; i<=$n_partitions; i+=1)); do
+ if [ ! -e "/dev/mapper/${dm_name}p$i" ]; then
+ fail=1
+ break
+ fi
+ # remove the partitions as we go, otherwise cleanup won't work.
+ dmsetup remove /dev/mapper/${dm_name}p$i
+done
+
+Exit $fail
--
1.7.7.6

View File

@ -0,0 +1,92 @@
From cc96f793bb4fb088123a40fb9d802e7db1fdbffb Mon Sep 17 00:00:00 2001
From: Fedora Ninjas <parted-owner@fedoraproject.org>
Date: Tue, 7 Aug 2012 10:14:03 -0700
Subject: [PATCH] tests: Make sure dm UUIDs are not erased
* tests/t6003-dm-uuid.sh: Make sure dm UUIDs are not erased
---
tests/Makefile.am | 1 +
tests/t6003-dm-uuid.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 0 deletions(-)
create mode 100755 tests/t6003-dm-uuid.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 57771be..98310f2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -56,6 +56,7 @@ TESTS = \
t6000-dm.sh \
t6001-psep.sh \
t6002-dm-many-partitions.sh \
+ t6003-dm-uuid.sh \
t6100-mdraid-partitions.sh \
t7000-scripting.sh \
t8000-loop.sh \
diff --git a/tests/t6003-dm-uuid.sh b/tests/t6003-dm-uuid.sh
new file mode 100755
index 0000000..1751cb4
--- /dev/null
+++ b/tests/t6003-dm-uuid.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# device-mapper: preserve uuid
+# The dm's partitions uuid would be removed when creating new partitions
+
+# Copyright (C) 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_
+(dmsetup --help) > /dev/null 2>&1 || skip_test_ "No dmsetup installed"
+
+ss=$sector_size_
+ns=300
+n_partitions=3
+start_sector=34
+loop_file=loop-file-$$
+dm_name=dm-test-$$
+
+cleanup_() {
+ dmsetup remove $dm_name
+ test -n "$dev" && losetup -d "$dev"
+ rm -f $loop_file;
+}
+
+# create a file large enough to hold a GPT partition table
+dd if=/dev/null of=$loop_file bs=$ss seek=$ns || framework_failure
+dev=$(losetup --show -f $loop_file) || framework_failure
+dmsetup create $dm_name --table "0 $ns linear $dev 0" || framework_failure
+dmsetup rename $dm_name --setuuid f139317b-f98a-45d7-ab3b-9b4e0a336872 || framework_failure
+
+cmd=
+for ((i=1; i<=$n_partitions; i+=1)); do
+ s=$((start_sector + i - 1))
+ cmd="$cmd mkpart p$i ${s}s ${s}s"
+done
+parted -m -a min -s /dev/mapper/$dm_name mklabel gpt $cmd > /dev/null 2>&1 || fail=1
+
+# Make sure all the partitions have UUIDs
+for ((i=1; i<=$n_partitions; i+=1)); do
+ dmsetup info /dev/mapper/${dm_name}p$i | grep UUID || fail=1
+
+ # remove the partitions as we go, otherwise cleanup won't work.
+ dmsetup remove /dev/mapper/${dm_name}p$i
+done
+
+Exit $fail
--
1.7.7.6

View File

@ -4,7 +4,7 @@
Summary: The GNU disk partition manipulation program
Name: parted
Version: 3.1
Release: 5%{?dist}
Release: 6%{?dist}
License: GPLv3+
Group: Applications/System
URL: http://www.gnu.org/software/parted
@ -17,6 +17,11 @@ Patch0: parted-3.0-libparted-copy-pmbr_boot-when-duplicating-GPT-disk.patch
Patch1: parted-3.1-libparted-check-PMBR-before-GPT-partition-table-8052.patch
Patch2: parted-3.1-tests-add-t0301-overwrite-gpt-pmbr.sh.patch
Patch3: parted-3.1-libparted-Fix-endian-error-with-FirstUsableLBA.patch
Patch4: parted-2.1-libparted-use-dm_udev_wait-698121.patch
Patch5: parted-3.1-libparted-use-largest_partnum-in-dm_reread_part_tabl.patch
patch6: parted-3.1-test-creating-20-device-mapper-partitions.patch
Patch7: parted-3.1-libparted-preserve-the-uuid-on-dm-partitions.patch
Patch8: parted-3.1-tests-Make-sure-dm-UUIDs-are-not-erased.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: e2fsprogs-devel
@ -152,6 +157,11 @@ fi
%changelog
* Fri Aug 03 2012 Brian C. Lane <bcl@redhat.com> 3.1-6
- Use dm_udev_wait for dm operations (#844257) (bcl)
- use largest_partnum in _dm_reread_part_table (bcl)
- set uuid on dm partitions (#832145) (bcl)
* Fri Jul 20 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 3.1-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild