Skip to content

Commit

Permalink
B #6583: SPARSE attribute considered on resize (#3350)
Browse files Browse the repository at this point in the history
Signed-off-by: Guillermo Ramos <[email protected]>
(cherry picked from commit d1e6a7c)
  • Loading branch information
1gramos authored and rsmontero committed Jan 17, 2025
1 parent 3dcecfc commit 0dafeb3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion share/etc/oned.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# MONITORING_INTERVAL_DATASTORE: Time in seconds between image monitorization.
# monitoring information. -1 to disable DB updating and 0 to write every update
#
# DS_MONITOR_VM_DISK: Number of MONIROTING_INTERVAL_DATASTORE intervals to monitor
# DS_MONITOR_VM_DISK: Number of MONITORING_INTERVAL_DATASTORE intervals to monitor
# VM disks. 0 to disable. Only applies to fs and fs_lvm datastores
#
# SCRIPTS_REMOTE_DIR: Remote path to store the monitoring and VM management
Expand Down
25 changes: 24 additions & 1 deletion src/tm_mad/common/resize
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ fi

. $TMCOMMON

DRIVER_PATH=$(dirname $0)

SRC_PATH=$(arg_path $SRC)
SRC_HOST=$(arg_host $SRC)

Expand All @@ -41,5 +43,26 @@ if [ `lcm_state $VMID` -eq 62 ]; then
exit 0
fi

ssh_exec_and_log "${SRC_HOST}" "qemu-img resize ${SRC_PATH} ${SIZE}M" \
#-------------------------------------------------------------------------------
# Get Image information
#-------------------------------------------------------------------------------

DISK_ID=$(basename ${SRC_PATH} | cut -d. -f2)

XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
unset i j XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VMID| $XPATH \
/VM/TEMPLATE/DISK\[DISK_ID=$DISK_ID\]/SPARSE)
SPARSE="${XPATH_ELEMENTS[j++]}"


if [[ "${SPARSE}" =~ ^(no|NO)$ ]]; then
RESIZE_CMD="qemu-img resize --preallocation=falloc ${SRC_PATH} ${SIZE}M"
else
RESIZE_CMD="qemu-img resize ${SRC_PATH} ${SIZE}M"
fi

ssh_exec_and_log "${SRC_HOST}" "$RESIZE_CMD" \
"Error resizing image ${SRC_PATH}"
7 changes: 5 additions & 2 deletions src/tm_mad/qcow2/clone
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ disable_local_monitoring $DST_HOST $DST_DIR
#-------------------------------------------------------------------------------

if [ -n "$ORIGINAL_SIZE" ] && [ "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
[[ "${SPARSE}" =~ ^(no|NO)$ ]] && RESIZE_CMD="qemu-img resize --preallocation=falloc ${DST_PATH} ${SIZE}M"
if [[ "${SPARSE}" =~ ^(no|NO)$ ]]; then
RESIZE_CMD="qemu-img resize --preallocation=falloc ${DST_PATH} ${SIZE}M"
else
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
fi
fi

if [ "$FORMAT" = "qcow2" ] && is_yes "${QCOW2_STANDALONE}"; then
Expand Down

0 comments on commit 0dafeb3

Please sign in to comment.