Blame SOURCES/rear-bz1388653-pr1418.patch

bddade
diff --git a/usr/share/rear/conf/default.conf b/usr/share/rear/conf/default.conf
bddade
index 3be1552..b392d6d 100644
bddade
--- a/usr/share/rear/conf/default.conf
bddade
+++ b/usr/share/rear/conf/default.conf
bddade
@@ -409,6 +409,16 @@ PXE_REMOVE_OLD_LINKS=
bddade
 # Default is empty which means prompting what to do next and after a timeout boot next option defined by BIOS
bddade
 PXE_RECOVER_MODE=
bddade
 
bddade
+# Certain operation might need longer time to kick in and more retries might be desirable.
bddade
+# REAR_SLEEP_DELAY (in sec.) is general delay for operation.
bddade
+REAR_SLEEP_DELAY=1
bddade
+# REAR_MAX_RETRIES is maximum number of attempts that should be executed before operation is aborted.
bddade
+# Maximum timeout for operation calculates as REAR_SLEEP_DELAY * REAR_MAX_RETRIES
bddade
+# This retries / timeout operation is currently implemented only in get_disk_size (),
bddade
+# so if you have trouble with error messages like:
bddade
+# 'Could not determine size of disk <device> ...' tweaking of REAR_SLEEP_DELAY and REAR_MAX_RETRIES might help.
bddade
+REAR_MAX_RETRIES=5
bddade
+
bddade
 ##
bddade
 # internal BACKUP stuff
bddade
 ##
bddade
diff --git a/usr/share/rear/lib/layout-functions.sh b/usr/share/rear/lib/layout-functions.sh
bddade
index 75a59bb..052a752 100644
bddade
--- a/usr/share/rear/lib/layout-functions.sh
bddade
+++ b/usr/share/rear/lib/layout-functions.sh
bddade
@@ -530,8 +530,7 @@ get_disk_size() {
bddade
 
bddade
     local block_size=$(get_block_size ${disk_name%/*})
bddade
 
bddade
-    [ -r /sys/block/$disk_name/size ]
bddade
-    BugIfError "Could not determine size of disk $disk_name, please file a bug."
bddade
+    retry_command test -r /sys/block/$disk_name/size || Error "Could not determine size of disk $disk_name"
bddade
 
bddade
     local nr_blocks=$( < /sys/block/$disk_name/size)
bddade
     local disk_size=$(( nr_blocks * block_size ))
bddade
@@ -586,3 +585,25 @@ is_disk_a_pv() {
bddade
         return 1
bddade
     fi
bddade
 }
bddade
+
bddade
+# retry_command () is binded with REAR_SLEEP_DELAY and REAR_MAX_RETRIES.
bddade
+# This function will do maximum of REAR_MAX_RETRIES command execution
bddade
+# and will sleep REAR_SLEEP_DELAY after each unsuccessful command execution.
bddade
+# It outputs command stdout if succeeded or returns 1 on failure.
bddade
+retry_command ()
bddade
+{
bddade
+    local retry=0
bddade
+
bddade
+    until command_stdout=$(eval "$@"); do
bddade
+        sleep $REAR_SLEEP_DELAY
bddade
+
bddade
+        let retry++
bddade
+
bddade
+        if (( retry >= REAR_MAX_RETRIES )) ; then
bddade
+            Log "retry_command '$*' failed"
bddade
+            return 1
bddade
+        fi
bddade
+    done
bddade
+    # Have no additional trailing newline for the command stdout:
bddade
+    echo -n "$command_stdout"
bddade
+}