From 1c5b0b263f08faa0649bf673a685d93ed9319bef Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Wed, 4 Feb 2015 16:31:00 -0800
Subject: [PATCH 31/32] tests: Add a test for device-mapper partition sizes
(#1188431)
device-mapper uses 512b sector units, not device specific sector sizes.
This test ensures that the correct partition size is created, no matter
what the device's sector size is.
Related: rhbz#1188431
---
tests/Makefile.am | 1 +
tests/t6004-dm-512b-sectors.sh | 68 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+)
create mode 100644 tests/t6004-dm-512b-sectors.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index faa0f37..1cf859c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,6 +57,7 @@ TESTS = \
t6001-psep.sh \
t6002-dm-many-partitions.sh \
t6003-dm-uuid.sh \
+ t6004-dm-512b-sectors.sh \
t6100-mdraid-partitions.sh \
t7000-scripting.sh \
t8000-loop.sh \
diff --git a/tests/t6004-dm-512b-sectors.sh b/tests/t6004-dm-512b-sectors.sh
new file mode 100644
index 0000000..31abba9
--- /dev/null
+++ b/tests/t6004-dm-512b-sectors.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+# device-mapper sector sizes are 512b, make sure partitions are the correct
+# size when using larger sector sizes and a linear dm table.
+
+# Copyright (C) 2015 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'
+
+(dmsetup --help) > /dev/null 2>&1 || skip_test_ "No dmsetup installed"
+
+# Device maps names - should be random to not conflict with existing ones on
+# the system
+linear_=plinear-$$test
+
+cleanup_fn_() {
+ i=0
+ udevadm settle
+ while [ $i -lt 10 ] ; do
+ [ -e "/dev/mapper/${linear_}1" ] && dmsetup remove ${linear_}1
+ sleep .2
+ [ -e "/dev/mapper/$linear_" ] && dmsetup remove $linear_
+ sleep .2
+ [ -e "/dev/mapper/${linear_}1" -o -e "/dev/mapper/$linear_" ] || i=10
+ i=$((i + 1))
+ done
+ udevadm settle
+}
+
+# Create a 500M device
+ss=$sector_size_
+scsi_debug_setup_ sector_size=$ss dev_size_mb=500 > dev-name ||
+ skip_ 'failed to create scsi_debug device'
+scsi_dev=$(cat dev-name)
+
+# Size of device, in 512b units
+scsi_dev_size=$(blockdev --getsz $scsi_dev) || framework_failure
+
+dmsetup create $linear_ --table "0 $scsi_dev_size linear $scsi_dev 0" || framework_failure
+dev="/dev/mapper/$linear_"
+
+# Create msdos partition table with a partition from 1MiB to 100MiB
+parted -s $dev mklabel msdos mkpart primary ext2 1MiB 101MiB > out 2>&1 || fail=1
+compare /dev/null out || fail=1
+
+# The size of the partition should be 100MiB, or 204800 512b sectors
+p1_size=$(blockdev --getsz ${dev}1) || framework_failure
+[ $p1_size == 204800 ] || fail=1
+
+Exit $fail
--
2.1.0