Blame SOURCES/rear-bz1388653-pr1418.patch

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