[parted-devel] [PATCH] Don't fail if unable to reread partition table

Soren Hansen soren at canonical.com
Wed Aug 6 17:16:40 UTC 2008


Parted fails if telling the kernel to reread the partition table for the device
in question fails. However, for loop back devices and possibly other
types of disk images, this makes little sense.

This patch makes libparted consider (ioctl(fd, BLKRRPART) || errno
== EINVAL) succesful, and provides a test script as well.

Signed-off-by: Soren Hansen <soren at canonical.com>

---
 libparted/arch/linux.c |    4 ++--
 tests/Makefile.am      |    3 ++-
 tests/t8000-loop.sh    |   45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 3 deletions(-)
 create mode 100755 tests/t8000-loop.sh

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 75e709b..cf26322 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2179,7 +2179,7 @@ _blkpg_add_partition (PedDisk* disk, const PedPartition *part)
         free (dev_name);
 
         if (!_blkpg_part_command (disk->dev, &linux_part,
-                                  BLKPG_ADD_PARTITION)) {
+                                  BLKPG_ADD_PARTITION ) && (errno != EINVAL)) {
                 return ped_exception_throw (
                         PED_EXCEPTION_ERROR,
                         PED_EXCEPTION_IGNORE_CANCEL,
@@ -2462,7 +2462,7 @@ _kernel_reread_part_table (PedDevice* dev)
         int             retry_count = 5;
 
         sync();
-        while (ioctl (arch_specific->fd, BLKRRPART)) {
+        while (ioctl (arch_specific->fd, BLKRRPART) && (errno != EINVAL)) {
                 retry_count--;
                 sync();
                 if (!retry_count) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b9db0b1..1c8c753 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,7 +14,8 @@ TESTS = \
   t4200-partprobe.sh \
   t5000-tags.sh \
   t6000-dm.sh \
-  t7000-scripting.sh
+  t7000-scripting.sh \
+  t8000-loop.sh
 
 EXTRA_DIST = \
   $(TESTS) test-lib.sh lvm-utils.sh
diff --git a/tests/t8000-loop.sh b/tests/t8000-loop.sh
new file mode 100755
index 0000000..e3187da
--- /dev/null
+++ b/tests/t8000-loop.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+# Copyright (C) 2008 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/>.
+
+test_description='Test usage of loop devices'
+
+privileges_required_=1
+device_mapper_required_=1
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+cleanup_() {
+    test -n "$d1" && losetup -d "$d1"
+    rm -f "$f1";
+}
+
+test_expect_success \
+    "setup: create loop devices" \
+    'f1=$(pwd)/1 && d1=$(loop_setup_ "$f1")'
+
+test_expect_success \
+    'run parted -s "$d1" mklabel msdos' \
+    'parted -s $d1 mklabel msdos > out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_expect_success \
+    'run parted -s "$d1" mkpart primary 1 10' \
+    'parted -s $d1 mkpart primary 1 10 > out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_done
-- 
1.5.4.3


-- 
Soren Hansen               | 
Virtualisation specialist  | Ubuntu Server Team
Canonical Ltd.             | http://www.ubuntu.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: Digital signature
Url : http://lists.alioth.debian.org/pipermail/parted-devel/attachments/20080806/9973ba9c/attachment-0001.pgp 


More information about the parted-devel mailing list