[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Jim Meyering meyering at alioth.debian.org
Tue May 10 13:41:15 UTC 2011


 NEWS                                            |    5 +
 gnulib                                          |    2 
 libparted/arch/linux.c                          |   30 ++-----
 tests/Makefile.am                               |    3 
 tests/t-local.sh                                |    7 -
 tests/t1101-busy-partition.sh                   |    5 -
 tests/t9041-undetected-in-use-16th-partition.sh |   99 ++++++++++++++++++++++++
 7 files changed, 124 insertions(+), 27 deletions(-)

New commits:
commit 2b4317f9731a942adf781fe7ee846427312eed67
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon May 9 21:14:42 2011 +0200

    tests: add a NEWS entry and a test to exercise today's bug fix
    
    * tests/t9041-undetected-in-use-16th-partition: New file.
    * tests/Makefile.am (TESTS): Add it.
    * NEWS (Bug fixes): Describe it.

diff --git a/NEWS b/NEWS
index 92e8ea7..0ac69c8 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,11 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  parted no longer allows the modification of certain in-use partitions.
+  In particular, before this fix, parted would permit removal or modification
+  of any in-use partition on a dmraid and any in-use partition beyond the 15th
+  on a regular scsi disk.
+
   Improve support of DASD devices on the s390 architecture.
   Parted now supports all DASD types (CKD and FBA), DASD formats (CDL,
   LDL, CMS non-reserved, and CMS reserved), and DASD drivers (ECKD, FBA,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 93e5995..df9711c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -47,7 +47,8 @@ TESTS = \
   t9020-alignment.sh \
   t9021-maxima.sh \
   t9030-align-check.sh \
-  t9040-many-partitions.sh
+  t9040-many-partitions.sh \
+  t9041-undetected-in-use-16th-partition.sh
 
 EXTRA_DIST = \
   $(TESTS) lvm-utils.sh t-local.sh t-lvm.sh \
diff --git a/tests/t9041-undetected-in-use-16th-partition.sh b/tests/t9041-undetected-in-use-16th-partition.sh
new file mode 100644
index 0000000..74c30fc
--- /dev/null
+++ b/tests/t9041-undetected-in-use-16th-partition.sh
@@ -0,0 +1,99 @@
+#!/bin/sh
+# Ensure that parted knows when N'th (N>=16) partition is mounted
+
+# Copyright (C) 2010-2011 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_
+require_scsi_debug_module_
+
+grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
+  skip_ 'this system lacks a new-enough libblkid'
+
+ss=$sector_size_
+partition_sectors=256  # sectors per partition
+n_partitions=17        # how many partitions to create
+start=2048             # start sector for the first partition
+gpt_slop=34            # sectors at end of disk reserved for GPT
+
+n_sectors=$(($start + n_partitions * partition_sectors + gpt_slop))
+
+sectors_per_MiB=$((1024 * 1024 / ss))
+n_MiB=$(((n_sectors + sectors_per_MiB - 1) / sectors_per_MiB))
+# create memory-backed device
+scsi_debug_setup_ sector_size=$ss dev_size_mb=$n_MiB > dev-name ||
+  skip_ 'failed to create scsi_debug device'
+scsi_dev=$(cat dev-name)
+
+n=$((n_MiB * sectors_per_MiB))
+printf "BYT;\n$scsi_dev:${n}s:scsi:$ss:$ss:gpt:Linux scsi_debug;\n" \
+  > exp || fail=1
+
+parted -s $scsi_dev mklabel gpt || fail=1
+parted -s $scsi_dev u s p || fail=1
+
+i=1
+t0=$(date +%s.%N)
+while :; do
+    end=$((start + partition_sectors - 1))
+    parted -s $scsi_dev mkpart p$i ${start}s ${end}s || fail=1
+    printf "$i:${start}s:${end}s:${partition_sectors}s::p$i:;\n" >> exp
+    test $i = $n_partitions && break
+    start=$((start + partition_sectors))
+    i=$((i+1))
+done
+t_final=$(date +%s.%N)
+
+# Fail the test if it takes too long.
+# On Fedora 13, it takes about 15 seconds.
+# With older kernels, it typically takes more than 150 seconds.
+$AWK "BEGIN {d = $t_final - $t0; n = $n_partitions; st = 60 < d;"\
+' printf "created %d partitions in %.2f seconds\n", n, d; exit st }' /dev/null \
+    || fail=1
+
+parted -m -s $scsi_dev u s p > out || fail=1
+compare out exp || fail=1
+
+wait_for_dev_to_appear_ ${scsi_dev}16 || fail_ ${scsi_dev}16 did not appear
+
+partitions="${scsi_dev}14 ${scsi_dev}15 ${scsi_dev}16"
+for i in $partitions; do
+  mkfs.ext3 $i || skip_ mkfs.ext3 $i failed
+done
+
+# be sure to unmount upon interrupt, failure, etc.
+cleanup_fn_() { for i in $partitions; do umount "$i" > /dev/null 2>&1; done; }
+
+for part_dev in $partitions; do
+  n=${part_dev#$scsi_dev}
+  mount_point=$(pwd)/m-$n
+  mkdir $mount_point || fail=1
+  mount "$part_dev" "$mount_point" || fail=1
+
+  # Removal of mounted partition must fail.
+  parted -s $scsi_dev rm $n > out 2>&1 && fail=1
+
+  echo "Error: Partition $part_dev is being used." \
+	  'You must unmount it before you modify it with Parted.' \
+    > exp-error || framework_failure_
+
+  # expect error
+  compare out exp-error || fail=1
+
+done
+
+Exit $fail

commit db52898c214310dab4ed84e6cb2f9ffc8c3aa502
Author: Phillip Susi <psusi at cfl.rr.com>
Date:   Tue May 10 12:00:10 2011 +0200

    linux: also detect "in-use" dmraid and scsi-Nth (N>=16) partitions
    
    Prior to this change, Parted would fail to detect any in-use
    partition on a dmraid disk, as well as any in-use partition
    numbered 16 or greater on a regular scsi disk.
    This was because assumptions were being made about the device node
    major/minor numbers and how they relate to the partition number.
    These assumptions are invalid for dmraid devices, and for normal
    disks with >= 16 partitions.
    * libparted/arch/linux.c (_partition_get_part_dev): Remove function.
    (_partition_is_mounted): Rewrite to use _partition_is_mounted_by_path
    instead of _by_dev.

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index c108f5a..b56ce2b 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2238,19 +2238,6 @@ linux_partition_get_path (const PedPartition* part)
         return _device_get_part_path (part->disk->dev, part->num);
 }
 
-static dev_t
-_partition_get_part_dev (const PedPartition* part)
-{
-        struct stat dev_stat;
-        int dev_major, dev_minor;
-
-        if (stat (part->disk->dev->path, &dev_stat))
-                return (dev_t)0;
-        dev_major = major (dev_stat.st_rdev);
-        dev_minor = minor (dev_stat.st_rdev);
-        return (dev_t)makedev (dev_major, dev_minor + part->num);
-}
-
 static int
 _mount_table_search (const char* file_name, dev_t dev)
 {
@@ -2294,16 +2281,19 @@ _partition_is_mounted_by_path (const char *path)
         return _partition_is_mounted_by_dev (part_stat.st_rdev);
 }
 
+/* If partition PART is mounted, or if we encounter an out-of-memory error
+   while trying to determine its status, return 1.  Otherwise, return 0.  */
 static int
 _partition_is_mounted (const PedPartition *part)
 {
-        dev_t dev;
-        if (!ped_partition_is_active (part))
-                return 0;
-        dev = _partition_get_part_dev (part);
-        if (!dev)
-                return 0;
-        return _partition_is_mounted_by_dev (dev);
+	if (!ped_partition_is_active (part))
+		return 0;
+	char *part_name = _device_get_part_path (part->disk->dev, part->num);
+	if (!part_name)
+		return 1;
+	int status = _partition_is_mounted_by_path (part_name);
+	free (part_name);
+	return !!status;
 }
 
 static int

commit 197634f29c31b4d325194f91607d5b00eb6a66be
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon May 9 21:00:35 2011 +0200

    build: update gnulib submodule to latest

diff --git a/gnulib b/gnulib
index 36152fb..91fd934 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 36152fb50f3fbb0597793621cbfd10902ac4cf46
+Subproject commit 91fd934273607a4a395917d5230bd8dd5c866d94

commit e47ae2865e20fdc5c8c88921388c91dc671b04c1
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon May 9 22:00:57 2011 +0200

    tests: avoid subtle shell semantics bug
    
    This bug was causing some root-only tests to be mistakenly skipped.
    This bash command will always exit successfully,
    i.e., the "return 1" will never happen:
      bash -c 'f(){ local f=$(false)||return 1; return 0; }; f'
    That's because the assignment always succeeds, and that success
    is what determines the return value, not the $(...) command.
    This is very counter-intuitive, sigh.
    The work-around is to separate the declaration and assignment, as in
    local f; f=$(...) || ...
    * tests/t-local.sh (new_sdX_): Do that.
    (gpt_corrupt_primary_table_): Likewise.

diff --git a/tests/t-local.sh b/tests/t-local.sh
index 8e2ef07..b9b8b28 100644
--- a/tests/t-local.sh
+++ b/tests/t-local.sh
@@ -74,7 +74,7 @@ scsi_debug_acquire_lock_()
 # Otherwise, return 1.
 new_sdX_()
 {
-  local m=$(grep -lw scsi_debug /sys/block/sd*/device/model) || return 1
+  local m; m=$(grep -lw scsi_debug /sys/block/sd*/device/model) || return 1
 
   # Remove the /sys/block/ prefix, and then the /device/model suffix.
   m=${m#/sys/block/}
@@ -113,7 +113,7 @@ scsi_debug_setup_()
   case $new_dev in
     sd[a-z]) ;;
     sd[a-z][a-z]) ;;
-    *) return 1 ;;
+    *) warn_ $ME_ unexpected device name: $new_dev; return 1 ;;
   esac
   local t=/dev/$new_dev
   wait_for_dev_to_appear_ $t
@@ -162,7 +162,8 @@ gpt_corrupt_primary_table_()
   case $ss in *[^0-9]*) echo "$0: invalid sector size: $ss">&2; return 1;; esac
 
   # get the first byte of the name
-  local orig_pte_name_byte=$(peek_ $dev $(gpt1_pte_name_offset_ $ss)) || return 1
+  local orig_pte_name_byte
+  orig_pte_name_byte=$(peek_ $dev $(gpt1_pte_name_offset_ $ss)) || return 1
 
   local new_byte
   test x"$orig_pte_name_byte" = xA && new_byte=B || new_byte=A

commit 2c563e8a0ffaf8c02d5b050ee4ac97575bacd8d6
Author: Jim Meyering <meyering at redhat.com>
Date:   Tue May 10 11:37:06 2011 +0200

    tests: minor fix; add/adjust comments
    
    * tests/t1101-busy-partition.sh: Don't ignore failed comparison.
    Add a comment.

diff --git a/tests/t1101-busy-partition.sh b/tests/t1101-busy-partition.sh
index b8dab44..f7aab83 100755
--- a/tests/t1101-busy-partition.sh
+++ b/tests/t1101-busy-partition.sh
@@ -54,12 +54,13 @@ mount_point=$(pwd)/mnt
 mkdir $mount_point || fail=1
 mount "${dev}2" "$mount_point" || fail=1
 
-# removal of unmounted partition, must work.
+# Removal of unmounted partition must succeed.
 parted -s "$dev" rm 1 > out 2>&1 || fail=1
 
+# Removal of mounted partition must fail.
 parted -s "$dev" rm 2 > out 2>&1 && fail=1
 
 # expect error
-compare out exp-error
+compare out exp-error || fail=1
 
 Exit $fail



More information about the Parted-commits mailing list