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

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