mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-03 01:17:41 +03:00
B OpenNebula/one#6487: Fix SPARSE parameter ignored (#3033)
in TM cloning script - Added function get_ds_attribute to tm_common.sh to get a given attribute from a Datastore - Using falloc preallocation mode on the qemu-img commands since it is faster than using full preallocation - Note the cloning script when using the TM_MAD = ssh does not use qemu-img command. Instead it uses the tar command, hence it ignores the QCOW2_OPTIONS parameter - Deleted get_ds_attribute function since it is no longer needed - SPARSE is inherited from Datastore on oned.conf - Changed resize statement so it uses same syntax as the clone statement Signed-off-by: Alejandro Mosteiro <amosteiro@opennebula.io> Co-authored-by: Tino Vázquez <cvazquez@opennebula.io>
This commit is contained in:
parent
e1b5bc6b44
commit
1f9b15cd95
@ -1097,6 +1097,7 @@ INHERIT_DATASTORE_ATTR = "GLUSTER_VOLUME"
|
|||||||
INHERIT_DATASTORE_ATTR = "DISK_TYPE"
|
INHERIT_DATASTORE_ATTR = "DISK_TYPE"
|
||||||
INHERIT_DATASTORE_ATTR = "ALLOW_ORPHANS"
|
INHERIT_DATASTORE_ATTR = "ALLOW_ORPHANS"
|
||||||
INHERIT_DATASTORE_ATTR = "QCOW2_STANDALONE"
|
INHERIT_DATASTORE_ATTR = "QCOW2_STANDALONE"
|
||||||
|
INHERIT_DATASTORE_ATTR = "SPARSE"
|
||||||
|
|
||||||
INHERIT_DATASTORE_ATTR = "VCENTER_ADAPTER_TYPE"
|
INHERIT_DATASTORE_ATTR = "VCENTER_ADAPTER_TYPE"
|
||||||
INHERIT_DATASTORE_ATTR = "VCENTER_DISK_TYPE"
|
INHERIT_DATASTORE_ATTR = "VCENTER_DISK_TYPE"
|
||||||
|
@ -68,12 +68,14 @@ done < <(onevm show -x $VMID| $XPATH \
|
|||||||
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/SIZE \
|
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/SIZE \
|
||||||
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/FORMAT \
|
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/FORMAT \
|
||||||
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/ORIGINAL_SIZE \
|
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/ORIGINAL_SIZE \
|
||||||
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/QCOW2_STANDALONE)
|
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/QCOW2_STANDALONE \
|
||||||
|
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/SPARSE)
|
||||||
|
|
||||||
SIZE="${XPATH_ELEMENTS[j++]}"
|
SIZE="${XPATH_ELEMENTS[j++]}"
|
||||||
FORMAT="${XPATH_ELEMENTS[j++]}"
|
FORMAT="${XPATH_ELEMENTS[j++]}"
|
||||||
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
||||||
QCOW2_STANDALONE="${XPATH_ELEMENTS[j++]}"
|
QCOW2_STANDALONE="${XPATH_ELEMENTS[j++]}"
|
||||||
|
SPARSE="${XPATH_ELEMENTS[j++]}"
|
||||||
|
|
||||||
ssh_make_path $DST_HOST $DST_DIR
|
ssh_make_path $DST_HOST $DST_DIR
|
||||||
disable_local_monitoring $DST_HOST $DST_DIR
|
disable_local_monitoring $DST_HOST $DST_DIR
|
||||||
@ -83,11 +85,13 @@ disable_local_monitoring $DST_HOST $DST_DIR
|
|||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
if [ -n "$ORIGINAL_SIZE" ] && [ "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
|
if [ -n "$ORIGINAL_SIZE" ] && [ "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
|
||||||
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
|
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
|
||||||
|
[[ "${SPARSE}" =~ ^(no|NO)$ ]] && RESIZE_CMD="qemu-img resize --preallocation=falloc ${DST_PATH} ${SIZE}M"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$FORMAT" = "qcow2" ] && is_yes "${QCOW2_STANDALONE}"; then
|
if [ "$FORMAT" = "qcow2" ] && is_yes "${QCOW2_STANDALONE}"; then
|
||||||
CLONE_CMD=$(qcow_dir_cmd "$SRC_PATH" "$DST_PATH" "convert")
|
CLONE_CMD=$(qcow_dir_cmd "$SRC_PATH" "$DST_PATH" "convert")
|
||||||
|
[[ "${SPARSE}" =~ ^(no|NO)$ ]] && CLONE_CMD="${CLONE_CMD/-O qcow2/-O qcow2 -S 0}"
|
||||||
elif [ "$FORMAT" = "qcow2" ]; then
|
elif [ "$FORMAT" = "qcow2" ]; then
|
||||||
CLONE_CMD=$(qcow_dir_cmd $SRC_PATH $DST_PATH "create")
|
CLONE_CMD=$(qcow_dir_cmd $SRC_PATH $DST_PATH "create")
|
||||||
else
|
else
|
||||||
|
@ -66,11 +66,13 @@ while IFS= read -r -d '' element; do
|
|||||||
done < <(onevm show -x $VMID| $XPATH \
|
done < <(onevm show -x $VMID| $XPATH \
|
||||||
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/SIZE \
|
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/SIZE \
|
||||||
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/FORMAT \
|
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/FORMAT \
|
||||||
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/ORIGINAL_SIZE)
|
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/ORIGINAL_SIZE \
|
||||||
|
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/SPARSE)
|
||||||
|
|
||||||
SIZE="${XPATH_ELEMENTS[j++]}"
|
SIZE="${XPATH_ELEMENTS[j++]}"
|
||||||
FORMAT="${XPATH_ELEMENTS[j++]}"
|
FORMAT="${XPATH_ELEMENTS[j++]}"
|
||||||
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
||||||
|
SPARSE="${XPATH_ELEMENTS[j++]}"
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Copy files to the remote host
|
# Copy files to the remote host
|
||||||
@ -78,10 +80,12 @@ ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
|||||||
|
|
||||||
if [ -n "$ORIGINAL_SIZE" ] && [ "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
|
if [ -n "$ORIGINAL_SIZE" ] && [ "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
|
||||||
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
|
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
|
||||||
|
[[ "${SPARSE}" =~ ^(no|NO)$ ]] && RESIZE_CMD="qemu-img resize --preallocation=falloc ${DST_PATH} ${SIZE}M"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$FORMAT" = "qcow2" ]; then
|
if [ "$FORMAT" = "qcow2" ]; then
|
||||||
CLONE_CMD=$(qcow_dir_cmd "$SRC_PATH" "$DST_PATH" "convert")
|
CLONE_CMD=$(qcow_dir_cmd "$SRC_PATH" "$DST_PATH" "convert")
|
||||||
|
[[ "${SPARSE}" =~ ^(no|NO)$ ]] && CLONE_CMD="${CLONE_CMD/-O qcow2/-O qcow2 -S 0}"
|
||||||
else
|
else
|
||||||
CLONE_CMD="cp $SRC_PATH $DST_PATH"
|
CLONE_CMD="cp $SRC_PATH $DST_PATH"
|
||||||
fi
|
fi
|
||||||
|
@ -79,11 +79,11 @@ while IFS= read -r -d '' element; do
|
|||||||
done < <(onevm show -x $VMID| $XPATH \
|
done < <(onevm show -x $VMID| $XPATH \
|
||||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \
|
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \
|
||||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE \
|
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE \
|
||||||
/VM/HISTORY_RECORDS/HISTORY[last\(\)]/DS_ID)
|
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SPARSE)
|
||||||
|
|
||||||
SIZE="${XPATH_ELEMENTS[j++]}"
|
SIZE="${XPATH_ELEMENTS[j++]}"
|
||||||
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
||||||
SYS_DS_ID="${XPATH_ELEMENTS[j++]}"
|
SPARSE="${XPATH_ELEMENTS[j++]}"
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Check for REPLICA_HOST in DATASTORE TEMPLATE and exec ./$0.replica if found
|
# Check for REPLICA_HOST in DATASTORE TEMPLATE and exec ./$0.replica if found
|
||||||
@ -107,8 +107,13 @@ COPY_CMD=$(cat <<EOF
|
|||||||
SRC_SNAP="${SRC_FILE}.snap"
|
SRC_SNAP="${SRC_FILE}.snap"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$TAR -C $SRC_DIR --transform="flags=r;s|$SRC_FILE|$DST_FILE|" -cSf - $SRC_FILE \$SRC_SNAP | \
|
if [[ "${SPARSE}" =~ ^(no|NO)$ ]]; then
|
||||||
$SSH $DST_HOST "$TAR -xSf - -C $DST_DIR"
|
$TAR -C $SRC_DIR --transform="flags=r;s|$SRC_FILE|$DST_FILE|" -cf - $SRC_FILE \$SRC_SNAP | \
|
||||||
|
$SSH $DST_HOST "$TAR -xf - -C $DST_DIR"
|
||||||
|
else
|
||||||
|
$TAR -C $SRC_DIR --transform="flags=r;s|$SRC_FILE|$DST_FILE|" -cSf - $SRC_FILE \$SRC_SNAP | \
|
||||||
|
$SSH $DST_HOST "$TAR -xSf - -C $DST_DIR"
|
||||||
|
fi
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -116,7 +121,12 @@ ssh_forward ssh_exec_and_log "$SRC_HOST" "$COPY_CMD" \
|
|||||||
"Error copying $SRC_PATH to $DST"
|
"Error copying $SRC_PATH to $DST"
|
||||||
|
|
||||||
if [ -n "$ORIGINAL_SIZE" ] && [ "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
|
if [ -n "$ORIGINAL_SIZE" ] && [ "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
|
||||||
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
|
if [[ "${SPARSE}" =~ ^(no|NO)$ ]]; then
|
||||||
ssh_exec_and_log "$DST_HOST" "$RESIZE_CMD" \
|
RESIZE_CMD="qemu-img resize --preallocation=falloc ${DST_PATH} ${SIZE}M"
|
||||||
"Error resizing image $DST"
|
else
|
||||||
|
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ssh_exec_and_log "$DST_HOST" "$RESIZE_CMD" \
|
||||||
|
"Error resizing image $DST"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user