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