Skip to content

Commit

Permalink
Make function get_disk_size () be more tolerant when querying /sys fo…
Browse files Browse the repository at this point in the history
…r number of disk blocks.

See issue #1370 for more details.
  • Loading branch information
gozora authored and schlomo committed Jul 24, 2017
1 parent e7dcb4e commit daaf5f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
10 changes: 10 additions & 0 deletions usr/share/rear/conf/default.conf
Expand Up @@ -474,6 +474,16 @@ PXE_CONFIG_GRUB_STYLE=
# Default is empty which means prompting what to do next and after a timeout boot next option defined by BIOS
PXE_RECOVER_MODE=

# Certain operation might need longer time to kick in and more retries might be desirable.
# REAR_SLEEP_DELAY (in sec.) is general delay for operation.
REAR_SLEEP_DELAY=1
# REAR_MAX_RETRIES is maximum number of attempts that should be executed before operation is aborted.
# Maximum timeout for operation calculates as REAR_SLEEP_DELAY * REAR_MAX_RETRIES
# This retries / timeout operation is currently implemented only in get_disk_size (),
# so if you have trouble with error messages like:
# 'Could not determine size of disk <device> ...' tweaking of REAR_SLEEP_DELAY and REAR_MAX_RETRIES might help.
REAR_MAX_RETRIES=5

##
# internal BACKUP stuff
##
Expand Down
29 changes: 25 additions & 4 deletions usr/share/rear/lib/layout-functions.sh
Expand Up @@ -530,10 +530,7 @@ get_disk_size() {

local block_size=$(get_block_size ${disk_name%/*})

[ -r /sys/block/$disk_name/size ]
BugIfError "Could not determine size of disk $disk_name, please file a bug."

local nr_blocks=$( < /sys/block/$disk_name/size)
local nr_blocks=$(retry_command "cat /sys/block/$disk_name/size")
local disk_size=$(( nr_blocks * block_size ))

### Make sure we always return a number
Expand Down Expand Up @@ -590,3 +587,27 @@ is_disk_a_pv() {
function is_multipath_path {
[ "$1" ] && type multipath &>/dev/null && multipath -c /dev/$1 &>/dev/null
}

# retry_command () is binded with REAR_SLEEP_DELAY and REAR_MAX_RETRIES.
# This function will do maximum of REAR_MAX_RETRIES command execution
# and will sleep REAR_SLEEP_DELAY after each unsuccessful command execution.
# Function returns command result as soon as it succeeded.
function retry_command () {
command="$1"

for pass in trial verification ; do
until result=$($command); do
sleep $REAR_SLEEP_DELAY

retry=$((retry+1))

if [[ $retry -eq $REAR_MAX_RETRIES ]]; then
# No success until now, we should end function and throw error.
Error "Could not successfully finish command: '$command'"
break 2;
fi
done
done

echo $result
}

0 comments on commit daaf5f0

Please sign in to comment.