From 822a050cedfe540dafc3b2784c5296cdb61ed0d4 Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Fri, 9 Feb 2024 20:36:23 +0100 Subject: [PATCH] Skip invalid disk drives when saving layout Upstream PR #3047 Resolves: RHEL-22863 --- rear-skip-invalid-drives-RHEL-22863.patch | 60 +++++++++++++++++++++++ rear.spec | 4 ++ 2 files changed, 64 insertions(+) create mode 100644 rear-skip-invalid-drives-RHEL-22863.patch diff --git a/rear-skip-invalid-drives-RHEL-22863.patch b/rear-skip-invalid-drives-RHEL-22863.patch new file mode 100644 index 0000000..557e03a --- /dev/null +++ b/rear-skip-invalid-drives-RHEL-22863.patch @@ -0,0 +1,60 @@ +diff --git a/usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh b/usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh +index da6ce64c4..ab14ec83f 100644 +--- a/usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh ++++ b/usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh +@@ -395,6 +395,10 @@ Log "Saving disk partitions." + elif [[ ! ($blockd = *rpmb || $blockd = *[0-9]boot[0-9]) ]]; then # Silently skip Replay Protected Memory Blocks and others + devname=$(get_device_name $disk) + devsize=$(get_disk_size ${disk#/sys/block/}) ++ if ! validation_error=$(is_disk_valid $devname) ; then ++ LogPrintError "Ignoring $blockd: $validation_error" ++ continue ++ fi + disktype=$(parted -s $devname print | grep -E "Partition Table|Disk label" | cut -d ":" -f "2" | tr -d " ") + if [ "$disktype" != "dasd" ]; then + echo "# Disk $devname" +diff --git a/usr/share/rear/lib/layout-functions.sh b/usr/share/rear/lib/layout-functions.sh +index f5fc7538e..90b16cb20 100644 +--- a/usr/share/rear/lib/layout-functions.sh ++++ b/usr/share/rear/lib/layout-functions.sh +@@ -834,6 +834,40 @@ is_disk_a_pv() { + return 1 + } + ++# Check whether disk is suitable for being added to layout ++# Can be used to skip obviously unsuitable/broken devices ++# (missing device node, zero size, device can't be opened). ++# Should not be used to skip potential mapping targets before layout restoration ++# - an invalid disk may become valid later, for example if it is a DASD that needs ++# low-level formatting (see 090_include_dasd_code.sh and 360_generate_dasd_format_code.sh), ++# unformatted DASDs show zero size. ++# Returns 0 if the device is ok ++# Returns nonzero code if it should be skipped, and a text describing the error ++# (without the device name) on stdout ++# usage example: ++# local err ++# if ! err=$(is_disk_valid /dev/sda); then ++ ++function is_disk_valid { ++ local disk="$1" ++ local size ++ ++ if ! test -b "$disk" ; then ++ echo "$disk is not a block device" ++ return 1 ++ fi ++ # capture stdout in a variable and redirect stderr to stdout - the error message ++ # will be our output ++ if { size=$(blockdev --getsize64 "$disk") ; } 2>&1 ; then ++ if ! test "$size" -gt 0 2>/dev/null ; then ++ echo "$disk has invalid size $size" ++ return 1 ++ fi ++ else ++ return 1 ++ fi ++} ++ + function is_multipath_path { + # Return 'false' if there is no device as argument: + test "$1" || return 1 diff --git a/rear.spec b/rear.spec index af759fe..1f9847f 100644 --- a/rear.spec +++ b/rear.spec @@ -66,6 +66,10 @@ Patch113: rear-restore-hybrid-bootloader-RHEL-16864.patch # https://github.com/rear/rear/commit/9f859c13f5ba285cd1d5983c9b595975c21888d3 Patch114: rear-resolve-libraries-for-symlinks-in-COPY_AS_IS-RHEL-15108.patch +# Skip invalid disk drives (zero sized, no media) when saving layout +# https://github.com/rear/rear/commit/808b15a677191aac62faadd1bc71885484091316 +Patch115: rear-skip-invalid-drives-RHEL-22863.patch + ###################### # downstream patches # ######################