Skip to content

Commit

Permalink
B #2109: Image error propagation during size estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlastimil Holer committed Jun 26, 2018
1 parent 484e412 commit 7b74aae
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
11 changes: 8 additions & 3 deletions src/datastore_mad/remotes/common/stat
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[i++]}"

SIZE=`fs_size "${SRC}" "${NO_DECOMPRESS}" "${LIMIT_TRANSFER_BW}"`

if [ "$SIZE" = "0" ]; then
log_error "Cannot determine size for $SRC"
if [ $? -ne 0 ]; then
if [ "${SIZE:-0}" = '0' ]; then
error_message "Cannot determine size for ${SRC}"
else
error_message "${SIZE}"
fi

exit -1
fi

echo "$SIZE"
echo "${SIZE}"
2 changes: 1 addition & 1 deletion src/datastore_mad/remotes/downloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function get_rbd_cmd
TEMP=`getopt -o m:s:l:c:n -l md5:,sha1:,limit:,max-size:,nodecomp -- "$@"`

if [ $? != 0 ] ; then
echo "Arguments error"
echo "Arguments error" >&2
exit -1
fi

Expand Down
57 changes: 34 additions & 23 deletions src/datastore_mad/remotes/libfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,12 @@ function bzip_file_size {
# @param $1 - Path to the image
# @param $2 - NO_DECOMPRESS
# @param $3 - BW LIMIT
# @return size of the image in Mb
# @return status code
# - on success: 0
# - on failure: != 0
# @return stdout with data
# - on success: size of image in MiB
# - on failure: error message
#-------------------------------------------------------------------------------
function fs_size {
SRC=$1
Expand All @@ -242,7 +247,7 @@ function fs_size {

# limit only on local or remote http(s)
if [ -d "${SRC}" ]; then
SIZE=`du -sb "${SRC}" | cut -f1`
SIZE=`set -o pipefail; du -sb "${SRC}" | cut -f1`
error=$?
elif [ -f "${SRC}" ] || (echo "${SRC}" | grep -qe '^https\?://'); then
IMAGE=$(mktemp)
Expand All @@ -258,9 +263,8 @@ function fs_size {
error=$?
if [ $error -ne 0 ]; then
# better fail here ...
log_error "Failed to download image head"
echo '0'
return
echo "Failed to get image head"
return 1
fi

TYPE=$(image_format "${IMAGE}")
Expand All @@ -272,9 +276,8 @@ function fs_size {
if [ -n "${NEW_HEAD_SIZE}" ] && [ "${NEW_HEAD_SIZE}" != "${HEAD_SIZE}" ]; then
continue # redownload more bytes
else
log_error "Failed to detect image format"
echo '0'
return
echo "Failed to detect image format"
return 1
fi
fi
done
Expand All @@ -287,9 +290,8 @@ function fs_size {
error=$?
if [ $error -ne 0 ]; then
# better fail here ...
log_error "Failed to download image head"
echo '0'
return
echo "Failed to get image head"
return 1
fi

ORIG_TYPE=$(file_type "${IMAGE}")
Expand Down Expand Up @@ -343,8 +345,8 @@ function fs_size {
error=$?
fi
else
log_error 'Unsupported remote image format'
error=1
echo 'Unsupported remote image format'
return 1
fi
;;
"application/x-xz")
Expand All @@ -356,8 +358,8 @@ function fs_size {
error=$?
fi
else
log_error 'Unsupported remote image format'
error=1
echo 'Unsupported remote image format'
return 1
fi
;;
"application/x-bzip2")
Expand All @@ -369,8 +371,8 @@ function fs_size {
error=$?
fi
else
log_error 'Unsupported remote image format'
error=1
echo 'Unsupported remote image format'
return 1
fi
;;
*)
Expand All @@ -387,8 +389,8 @@ function fs_size {
error=$?
fi
else
log_error 'Unsupported remote image format'
error=1
echo 'Unsupported remote image format'
return 1
fi
fi
;;
Expand All @@ -401,19 +403,28 @@ function fs_size {
if [ -f "${IMAGE}" ]; then
unlink "${IMAGE}" 2>/dev/null
fi
else
echo 'File not found'
return 1
fi

#####

SIZE=$(echo $SIZE | tr -d "\r")
SIZE=$(echo ${SIZE:-0} | tr -d "\r")

if [ $error -ne 0 ] || [ "${SIZE}" = '0' ]; then
SIZE='Runtime error during size estimation'

if [ $error -ne 0 ]; then
SIZE=0
if [ $error -eq 0 ]; then
error=1
fi
else
SIZE=$((($SIZE+1048575)/1048576))
fi

echo "$SIZE"
echo "${SIZE}"

return $error
}

#-------------------------------------------------------------------------------
Expand Down
12 changes: 8 additions & 4 deletions src/tm_mad/fs_lvm/clone
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ TM_MAD="${XPATH_ELEMENTS[j++]}"

FILE_SIZE=`fs_size "${SRC_PATH}" YES`

if [ $? -ne 0 ]; then
FILE_SIZE=0
fi

if [ $FILE_SIZE -gt $SIZE ]; then
SIZE="$FILE_SIZE"
fi
Expand All @@ -86,15 +90,15 @@ fi
# number of ONE or file image virtual size. We start to zero from
# 1 MiB before the end of image size prior to the copying.
if [ "${FILE_SIZE}" -lt "${SIZE}" ]; then
ZERO_SEEK_BYTES=$FILE_SIZE
ZERO_SEEK_BYTES=$FILE_SIZE
else
ZERO_SEEK_BYTES=$SIZE
ZERO_SEEK_BYTES=$SIZE
fi

if [ "${ZERO_SEEK_BYTES}" -gt 0 ]; then
ZERO_SEEK_BYTES=$(( (ZERO_SEEK_BYTES-1) * 1024 * 1024 ))
ZERO_SEEK_BYTES=$(( (ZERO_SEEK_BYTES-1) * 1024 * 1024 ))
else
ZERO_SEEK_BYTES=0
ZERO_SEEK_BYTES=0
fi

#-------------------------------------------------------------------------------
Expand Down

0 comments on commit 7b74aae

Please sign in to comment.