diff --git a/src/datastore_mad/remotes/downloader.sh b/src/datastore_mad/remotes/downloader.sh index 10a5274dc0..c220eaee5d 100755 --- a/src/datastore_mad/remotes/downloader.sh +++ b/src/datastore_mad/remotes/downloader.sh @@ -418,6 +418,8 @@ if [ "$TO" != "-" ]; then convert_image fi + fallocate -d "$TO" + elif [ -n "$CONVERT" ]; then convert_image fi diff --git a/src/datastore_mad/remotes/fs/cp b/src/datastore_mad/remotes/fs/cp index b3fad22750..1c37785386 100755 --- a/src/datastore_mad/remotes/fs/cp +++ b/src/datastore_mad/remotes/fs/cp @@ -145,7 +145,7 @@ if [ -n "$BRIDGE_LIST" ]; then multiline_exec_and_log "set -e -o pipefail; $COPY_COMMAND | $SSH $DST_HOST $DD of=$TMP_DST bs=${DD_BLOCK_SIZE:-64k}" \ "Error dumping $SRC to $DST_HOST:$TMP_DST" - ssh_exec_and_log "$DST_HOST" "set -e -o pipefail; mkdir -p $BASE_PATH; mv -f $TMP_DST $DST" \ + ssh_exec_and_log "$DST_HOST" "set -e -o pipefail; mkdir -p $BASE_PATH; mv -f $TMP_DST $DST; fallocate -d $DST" \ "Error moving $TMP_DST to $DST in $DST_HOST" if [ "x$CONVERT" = 'xyes' ] && [ -n "$DRIVER" ]; then @@ -162,6 +162,8 @@ else multiline_exec_and_log "$CONVERT_CMD" "Error converting $DST" fi + fallocate -d "$DST" + FORMAT=$($QEMU_IMG info $DST | grep "^file format:" | awk '{print $3}' || :) fi diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 6543e01f9a..aafe8c00a5 100644 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -45,8 +45,6 @@ RBD=${RBD:-rbd} READLINK=${READLINK:-readlink} RM=${RM:-rm} CP=${CP:-cp} -SCP=${SCP:-scp} -SCP_FWD=${SCP_FWD:-scp -o ForwardAgent=yes -o ControlMaster=no -o ControlPath=none} SED=${SED:-sed} SSH=${SSH:-ssh} SSH_FWD=${SSH_FWD:-ssh -o ForwardAgent=yes -o ControlMaster=no -o ControlPath=none} @@ -78,7 +76,7 @@ SCRIPT_NAME=`basename $0` # /some//path///somewhere/ -> /some/path/somewhere function fix_dir_slashes { - dirname "$1/file" | $SED 's/\/+/\//g' + dirname "$1/file" | $SED 's/\/\+/\//g' } # ------------------------------------------------------------------------------ @@ -197,20 +195,22 @@ function retry_if # Executes a command, if it fails returns error message and exits # If a second parameter is present it is used as the error message when # the command fails +# args: [] function exec_and_log { - message=$2 + _cmd="$1" + _msg="$2" - EXEC_LOG_ERR=`$1 2>&1 1>/dev/null` + EXEC_LOG_ERR=$(${_cmd} 2>&1 1>/dev/null) EXEC_LOG_RC=$? if [ $EXEC_LOG_RC -ne 0 ]; then - log_error "Command \"$1\" failed: $EXEC_LOG_ERR" + log_error "Command \"${_cmd}\" failed: $EXEC_LOG_ERR" - if [ -n "$2" ]; then - error_message "$2" + if [ -n "${_msg}" ]; then + error_message "${_msg}" else - error_message "Error executing $1: $EXEC_LOG_ERR" + error_message "Error executing \"${_cmd}\": $EXEC_LOG_ERR" fi exit $EXEC_LOG_RC fi @@ -293,6 +293,32 @@ function exec_and_set_error fi } +# Like exec_and_log but does not exit on failure. Just sets the variable +# ERROR to the error message. +function multiline_exec_and_set_error +{ + message=$2 + + EXEC_LOG_ERR=`bash -s 2>&1 1>/dev/null < /dev/null 2>&1 diff --git a/src/tm_mad/ssh/clone b/src/tm_mad/ssh/clone index 11ab52c35f..d06c0fca45 100755 --- a/src/tm_mad/ssh/clone +++ b/src/tm_mad/ssh/clone @@ -48,16 +48,20 @@ XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" # Set dst path and dir #------------------------------------------------------------------------------- -SRC_PATH=`arg_path $SRC` -DST_PATH=`arg_path $DST` +SRC_PATH="$(arg_path $SRC)" +DST_PATH="$(arg_path $DST)" SRC_PATH_SNAP="${SRC_PATH}.snap" DST_PATH_SNAP="${DST_PATH}.snap" -SRC_HOST=`arg_host $SRC` -DST_HOST=`arg_host $DST` +SRC_HOST="$(arg_host $SRC)" +DST_HOST="$(arg_host $DST)" -DST_DIR=`dirname $DST_PATH` +SRC_FILE="$(basename $SRC_PATH)" +DST_FILE="$(basename $DST_PATH)" + +SRC_DIR="$(dirname $SRC_PATH)" +DST_DIR="$(dirname $DST_PATH)" ssh_make_path $DST_HOST $DST_DIR "ssh" @@ -93,15 +97,24 @@ fi #------------------------------------------------------------------------------- # Copy files to the remote host #------------------------------------------------------------------------------- -log "Cloning $SRC in $DST_PATH" -ssh_forward exec_and_log "$SCP -r $SRC $DST" "Error copying $SRC to $DST" +log "Cloning $SRC_PATH in $DST_PATH" -if [ -d "${SRC_PATH_SNAP}" ]; then - ssh_forward exec_and_log "$SCP -r $SRC_HOST:${SRC_PATH_SNAP} $DST_HOST:${DST_PATH_SNAP}" \ - "Error copying $SRC to $DST" -fi +COPY_CMD=$(cat </dev/null 2>&1; then exec_and_log "rsync -r --delete ${SRC_HOST}:${SRC_PATH_SNAP}/ ${DST_SNAP}"