mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-01 06:50:25 +03:00
B #2109: Image error propagation during size estimation
This commit is contained in:
parent
7d7a2a5921
commit
ad9aa77353
@ -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}"
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
@ -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)
|
||||
@ -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}")
|
||||
@ -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
|
||||
@ -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}")
|
||||
@ -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")
|
||||
@ -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")
|
||||
@ -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
|
||||
;;
|
||||
*)
|
||||
@ -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
|
||||
;;
|
||||
@ -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 ]; then
|
||||
SIZE=0
|
||||
if [ $error -ne 0 ] || [ "${SIZE}" = '0' ]; then
|
||||
SIZE='Runtime error during size estimation'
|
||||
|
||||
if [ $error -eq 0 ]; then
|
||||
error=1
|
||||
fi
|
||||
else
|
||||
SIZE=$((($SIZE+1048575)/1048576))
|
||||
fi
|
||||
|
||||
echo "$SIZE"
|
||||
echo "${SIZE}"
|
||||
|
||||
return $error
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user