Blame SOURCES/0031-tests-Add-a-test-for-device-mapper-partition-sizes-1.patch

fc4a62
From 1c5b0b263f08faa0649bf673a685d93ed9319bef Mon Sep 17 00:00:00 2001
fc4a62
From: "Brian C. Lane" <bcl@redhat.com>
fc4a62
Date: Wed, 4 Feb 2015 16:31:00 -0800
fc4a62
Subject: [PATCH 31/32] tests: Add a test for device-mapper partition sizes
fc4a62
 (#1188431)
fc4a62
fc4a62
device-mapper uses 512b sector units, not device specific sector sizes.
fc4a62
This test ensures that the correct partition size is created, no matter
fc4a62
what the device's sector size is.
fc4a62
fc4a62
Related: rhbz#1188431
fc4a62
---
fc4a62
 tests/Makefile.am              |  1 +
fc4a62
 tests/t6004-dm-512b-sectors.sh | 68 ++++++++++++++++++++++++++++++++++++++++++
fc4a62
 2 files changed, 69 insertions(+)
fc4a62
 create mode 100644 tests/t6004-dm-512b-sectors.sh
fc4a62
fc4a62
diff --git a/tests/Makefile.am b/tests/Makefile.am
fc4a62
index faa0f37..1cf859c 100644
fc4a62
--- a/tests/Makefile.am
fc4a62
+++ b/tests/Makefile.am
fc4a62
@@ -57,6 +57,7 @@ TESTS = \
fc4a62
   t6001-psep.sh \
fc4a62
   t6002-dm-many-partitions.sh \
fc4a62
   t6003-dm-uuid.sh \
fc4a62
+  t6004-dm-512b-sectors.sh \
fc4a62
   t6100-mdraid-partitions.sh \
fc4a62
   t7000-scripting.sh \
fc4a62
   t8000-loop.sh \
fc4a62
diff --git a/tests/t6004-dm-512b-sectors.sh b/tests/t6004-dm-512b-sectors.sh
fc4a62
new file mode 100644
fc4a62
index 0000000..31abba9
fc4a62
--- /dev/null
fc4a62
+++ b/tests/t6004-dm-512b-sectors.sh
fc4a62
@@ -0,0 +1,68 @@
fc4a62
+#!/bin/sh
fc4a62
+# device-mapper sector sizes are 512b, make sure partitions are the correct
fc4a62
+# size when using larger sector sizes and a linear dm table.
fc4a62
+
fc4a62
+# Copyright (C) 2015 Free Software Foundation, Inc.
fc4a62
+
fc4a62
+# This program is free software; you can redistribute it and/or modify
fc4a62
+# it under the terms of the GNU General Public License as published by
fc4a62
+# the Free Software Foundation; either version 3 of the License, or
fc4a62
+# (at your option) any later version.
fc4a62
+
fc4a62
+# This program is distributed in the hope that it will be useful,
fc4a62
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
fc4a62
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
fc4a62
+# GNU General Public License for more details.
fc4a62
+
fc4a62
+# You should have received a copy of the GNU General Public License
fc4a62
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
fc4a62
+
fc4a62
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
fc4a62
+
fc4a62
+require_root_
fc4a62
+require_scsi_debug_module_
fc4a62
+
fc4a62
+grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
fc4a62
+  skip_ 'this system lacks a new-enough libblkid'
fc4a62
+
fc4a62
+(dmsetup --help) > /dev/null 2>&1 || skip_test_ "No dmsetup installed"
fc4a62
+
fc4a62
+# Device maps names - should be random to not conflict with existing ones on
fc4a62
+# the system
fc4a62
+linear_=plinear-$$test
fc4a62
+
fc4a62
+cleanup_fn_() {
fc4a62
+    i=0
fc4a62
+    udevadm settle
fc4a62
+    while [ $i -lt 10 ] ; do
fc4a62
+      [ -e "/dev/mapper/${linear_}1" ] && dmsetup remove ${linear_}1
fc4a62
+      sleep .2
fc4a62
+      [ -e "/dev/mapper/$linear_" ] && dmsetup remove $linear_
fc4a62
+      sleep .2
fc4a62
+      [ -e "/dev/mapper/${linear_}1" -o -e "/dev/mapper/$linear_" ] || i=10
fc4a62
+      i=$((i + 1))
fc4a62
+    done
fc4a62
+    udevadm settle
fc4a62
+}
fc4a62
+
fc4a62
+# Create a 500M device
fc4a62
+ss=$sector_size_
fc4a62
+scsi_debug_setup_ sector_size=$ss dev_size_mb=500 > dev-name ||
fc4a62
+  skip_ 'failed to create scsi_debug device'
fc4a62
+scsi_dev=$(cat dev-name)
fc4a62
+
fc4a62
+# Size of device, in 512b units
fc4a62
+scsi_dev_size=$(blockdev --getsz $scsi_dev) || framework_failure
fc4a62
+
fc4a62
+dmsetup create $linear_ --table "0 $scsi_dev_size linear $scsi_dev 0" || framework_failure
fc4a62
+dev="/dev/mapper/$linear_"
fc4a62
+
fc4a62
+# Create msdos partition table with a partition from 1MiB to 100MiB
fc4a62
+parted -s $dev mklabel msdos mkpart primary ext2 1MiB 101MiB > out 2>&1 || fail=1
fc4a62
+compare /dev/null out || fail=1
fc4a62
+
fc4a62
+# The size of the partition should be 100MiB, or 204800 512b sectors
fc4a62
+p1_size=$(blockdev --getsz ${dev}1) || framework_failure
fc4a62
+[ $p1_size == 204800 ] || fail=1
fc4a62
+
fc4a62
+Exit $fail
fc4a62
-- 
fc4a62
2.1.0
fc4a62