[parted-devel] [PATCH 1/2] tests: exercise dm partition sync with in use partition

Phillip Susi phillsusi at gmail.com
Thu Jan 12 02:29:18 UTC 2012


From: Phillip Susi <psusi at cfl.rr.com>

New test to verify that this commit works:
libparted: refactor device-mapper partition sync code
---
 tests/Makefile.am      |    1 +
 tests/t6002-dm-busy.sh |   94 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100644 tests/t6002-dm-busy.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 89162ba..174bed9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -50,6 +50,7 @@ TESTS = \
   t5000-tags.sh \
   t6000-dm.sh \
   t6001-psep.sh \
+  t6002-dm-busy.sh \
   t6100-mdraid-partitions.sh \
   t7000-scripting.sh \
   t8000-loop.sh \
diff --git a/tests/t6002-dm-busy.sh b/tests/t6002-dm-busy.sh
new file mode 100644
index 0000000..040f18f
--- /dev/null
+++ b/tests/t6002-dm-busy.sh
@@ -0,0 +1,94 @@
+#!/bin/sh
+# ensure that parted can alter a partition on a dmraid disk
+# while another one is mounted
+
+# 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_
+lvm_init_root_dir_
+
+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_() {
+    umount "${dev}p2" > /dev/null 2>&1
+    dmsetup remove ${linear_}p1
+    dmsetup remove ${linear_}p2
+    dmsetup remove $linear_
+    test -n "$d1" && losetup -d "$d1"
+    rm -f "$f1"
+}
+
+f1=$(pwd)/1; d1=$(loop_setup_ "$f1") \
+  || fail=1
+
+# setup: create a mapping
+echo "0 2048 linear $d1 0" | dmsetup create $linear_ || fail=1
+dev="$DM_DEV_DIR/mapper/$linear_"
+
+# Create msdos partition table
+parted -s $dev mklabel msdos > out 2>&1 || fail=1
+compare /dev/null out || fail=1
+
+parted -s $dev -a none mkpart primary fat32 1s 1000s > out 2>&1 || fail=1
+compare /dev/null out || fail=1
+
+parted -s $dev -a none mkpart primary fat32 1001s 2000s > out 2>&1 || fail=1
+compare /dev/null out || fail=1
+
+# wait for new partition device to appear
+wait_for_dev_to_appear_ ${dev}p2 || fail_ ${dev}p2 did not appear
+
+mkfs.vfat -F 32 ${dev}p2 || fail_ mkfs.vfat failed
+
+mount_point=$(pwd)/mnt
+
+mkdir $mount_point || fail=1
+mount "${dev}p2" "$mount_point" || fail=1
+
+# Removal of unmounted partition must succeed.
+parted -s "$dev" rm 1 > /dev/null 2>&1 || fail=1
+
+# Removal of mounted partition must fail.
+parted -s "$dev" rm 2 > /dev/null 2>&1 && fail=1
+
+parted -s "$dev" print > out 2>&1 || fail=1
+sed 's/^Disk .*: /Disk DEV: /' out > k; mv k out
+
+# Create expected output file.
+cat <<EOF >> exp || fail=1
+Model: Linux device-mapper (linear) (dm)
+Disk DEV: 1049kB
+Sector size (logical/physical): 512B/512B
+Partition Table: msdos
+
+Number  Start  End     Size   Type     File system  Flags
+ 2      513kB  1025kB  512kB  primary  fat32        lba
+
+EOF
+
+compare exp out || fail=1
+
+Exit $fail
-- 
1.7.5.4




More information about the parted-devel mailing list