Blame SOURCES/0001-growpart-fix-bug-occurring-if-start-sector-and-size-.patch

d5a816
From 827ca9237044f4821eb442fee1eef07ec7c3448c Mon Sep 17 00:00:00 2001
d5a816
From: Lars Kellogg-Stedman <lars@redhat.com>
d5a816
Date: Thu, 6 Dec 2018 15:32:35 -0500
d5a816
Subject: [PATCH] growpart: fix bug occurring if start sector and size were the
d5a816
 same.
d5a816
d5a816
The existing sed expression would erroneously change the start sector
d5a816
of a partition, rather than the size, if the start sector and size
d5a816
were identical.  This commit modifies the sed expression so that it
d5a816
will only operate on the final match in the line.
d5a816
d5a816
bzr-revno: 338.1.1
d5a816
(cherry picked from commit 7b11ac4d3abe16525639cff9198f5e7f8303280b)
d5a816
---
d5a816
 bin/growpart                          |  2 +-
d5a816
 test/test-growpart-start-matches-size | 75 +++++++++++++++++++++++++++
d5a816
 2 files changed, 76 insertions(+), 1 deletion(-)
d5a816
 create mode 100755 test/test-growpart-start-matches-size
d5a816
d5a816
diff --git a/bin/growpart b/bin/growpart
d5a816
index 13eda6e..4069fd4 100755
d5a816
--- a/bin/growpart
d5a816
+++ b/bin/growpart
d5a816
@@ -314,7 +314,7 @@ resize_sfdisk() {
d5a816
 	# now, change the size for this partition in ${dump_out} to be the
d5a816
 	# new size
d5a816
 	new_size=$((${max_end}-${pt_start}))
d5a816
-	sed "\|^\s*${dpart} |s/${pt_size},/${new_size},/" "${dump_out}" \
d5a816
+	sed "\|^\s*${dpart} |s/\(.*\)${pt_size},/\1${new_size},/" "${dump_out}" \
d5a816
 		>"${new_out}" ||
d5a816
 		fail "failed to change size in output"
d5a816
 
d5a816
diff --git a/test/test-growpart-start-matches-size b/test/test-growpart-start-matches-size
d5a816
new file mode 100755
d5a816
index 0000000..9967827
d5a816
--- /dev/null
d5a816
+++ b/test/test-growpart-start-matches-size
d5a816
@@ -0,0 +1,75 @@
d5a816
+#!/bin/bash
d5a816
+#
d5a816
+# Create a disk image where there exists a partition whose sizes matches the
d5a816
+# start sector.
d5a816
+# brought up under bug 1807171, which describes an error in the sed expression
d5a816
+# used to generate the replacement partition map
d5a816
+
d5a816
+set -e
d5a816
+
d5a816
+TEMP_D=""
d5a816
+
d5a816
+rq() {
d5a816
+	local out="${TEMP_D}/out"
d5a816
+	"$@" > "$out" 2>&1 || { echo "FAILED:" "$@"; cat "$out"; return 1; }
d5a816
+}
d5a816
+fail() { echo "FAILED:" "$@" 1>&2; exit 1; }
d5a816
+
d5a816
+setup_img() {
d5a816
+	local img_fp="$1" img=""
d5a816
+	img=$(basename "$img_fp")
d5a816
+	sfdisk "${img_fp}" <
d5a816
+label: gpt
d5a816
+label-id: db24000c-6ef3-4a17-b71c-1064baa29514
d5a816
+device: ${img}
d5a816
+unit: sectors
d5a816
+first-lba: 2048
d5a816
+last-lba: 4194270
d5a816
+
d5a816
+${img}1 : start=        2048, size=     1024000, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=5bc16165-bfc0-4e13-94eb-b898dc0bca41
d5a816
+${img}2 : start=     1026048, size=     1026048, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=a0e1636e-b759-4e7a-bd14-6f3d6c04745d
d5a816
+EOF
d5a816
+}
d5a816
+
d5a816
+cleanup() {
d5a816
+	[ ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
d5a816
+}
d5a816
+TEMP_D=$(mktemp -d ${TMPDIR:-/tmp}/${0##*/}.XXXXXX)
d5a816
+trap cleanup EXIT
d5a816
+
d5a816
+expected_sfdisk="CHANGED: partition=2 start=1026048 old: size=1026048 end=2052096 new: size=3168223 end=4194271"
d5a816
+expected_sgdisk="CHANGED: partition=2 start=1026048 old: size=1026048 end=2052096 new: size=3166208 end=4192256"
d5a816
+CR='
d5a816
+'
d5a816
+for resizer in sfdisk sgdisk; do
d5a816
+    expected_var_name="expected_$resizer"
d5a816
+	expected="${!expected_var_name}"
d5a816
+
d5a816
+	img="${TEMP_D}/disk-$resizer.img"
d5a816
+	echo "====== Testing with resizer=$resizer ====="
d5a816
+	rq truncate "--size=2G" "$img"
d5a816
+	( cd ${TEMP_D} && rq setup_img "${img##*/}" ) || fail "setup image $img"
d5a816
+	echo "==== before ===="
d5a816
+	( cd "${TEMP_D}" && sfdisk --dump "${img##*/}" )
d5a816
+	err="${TEMP_D}/gp.err"
d5a816
+	out="${TEMP_D}/gp.out"
d5a816
+	if ! GROWPART_RESIZER=$resizer \
d5a816
+			growpart -v -v "$img" 2 2>"$err" > "$out"; then
d5a816
+		cat "$err" "$out"
d5a816
+		fail "[resizer=$resizer] growpart failed"
d5a816
+	fi
d5a816
+	echo "==== after ===="
d5a816
+	( cd "${TEMP_D}" && sfdisk --dump "${img##*/}" )
d5a816
+	echo
d5a816
+    echo "==== after sgdisk ==="
d5a816
+	( cd "${TEMP_D}" && sgdisk --print "${img##*/}" )
d5a816
+	echo "==== growpart-stderr ==="
d5a816
+	cat "$err"
d5a816
+	echo "==== growpart-stdout ===="
d5a816
+	cat "$out"
d5a816
+	[ "$(cat $out)" = "$expected" ] || {
d5a816
+        fail "[resizer=$resizer] output ^^^ did not match expected vvv:${CR}$expected"
d5a816
+	}
d5a816
+done
d5a816
+
d5a816
+# vi: ts=4 noexpandtab
d5a816
-- 
d5a816
2.17.2
d5a816