mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
B #2217: Zero LVM space
This commit is contained in:
parent
fbb1ba8d18
commit
fb7e22f416
@ -82,6 +82,21 @@ if [ $FILE_SIZE -gt $SIZE ]; then
|
||||
SIZE="$FILE_SIZE"
|
||||
fi
|
||||
|
||||
# Compute the seek start for zeroing of the new LV as the smaller
|
||||
# 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
|
||||
else
|
||||
ZERO_SEEK_BYTES=$SIZE
|
||||
fi
|
||||
|
||||
if [ "${ZERO_SEEK_BYTES}" -gt 0 ]; then
|
||||
ZERO_SEEK_BYTES=$(( (ZERO_SEEK_BYTES-1) * 1024 * 1024 ))
|
||||
else
|
||||
ZERO_SEEK_BYTES=0
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Create the snapshot and link it
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -109,6 +124,12 @@ CLONE_CMD=$(cat <<EOF
|
||||
|
||||
hostname -f >"${DST_DIR}/.host" || :
|
||||
|
||||
# zero trailing space
|
||||
LVSIZE=\$(${SUDO} ${LVS} --nosuffix --noheadings --units B -o lv_size "${DEV}" | tr -d '[:blank:]')
|
||||
${DD} if=/dev/zero of="${DEV}" bs=64k \
|
||||
oflag=seek_bytes iflag=count_bytes \
|
||||
seek="${ZERO_SEEK_BYTES}" count="\$(( LVSIZE - ${ZERO_SEEK_BYTES} ))"
|
||||
|
||||
$QEMU_IMG convert -O raw "$SRC_PATH" "$DEV"
|
||||
rm -f "$DST_PATH"
|
||||
ln -s "$DEV" "$DST_PATH"
|
||||
|
@ -41,6 +41,17 @@ DST_HOST=`arg_host $DST`
|
||||
|
||||
DS_SYS_ID=$(echo $DST_PATH | grep -E '\/disk\.[[:digit:]]+$' | $AWK -F '/' '{print $(NF-2)}')
|
||||
|
||||
# Zero space
|
||||
ZERO_CMD=$(cat <<EOF
|
||||
set -x
|
||||
DEV=\$(readlink $DST_PATH)
|
||||
|
||||
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then
|
||||
${DD} if=/dev/zero of="\${DEV}" bs=64k || :
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
# Delete the device if it's a clone (LVM snapshot)
|
||||
DELETE_CMD=$(cat <<EOF
|
||||
set -x
|
||||
@ -63,6 +74,9 @@ EOF
|
||||
)
|
||||
|
||||
if [ -n "${DS_SYS_ID}" ]; then
|
||||
ssh_exec_and_log "$DST_HOST" "$ZERO_CMD" \
|
||||
"Error cleaning $DST_PATH"
|
||||
|
||||
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
|
||||
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" \
|
||||
"Error deleting $DST_PATH"
|
||||
|
@ -57,6 +57,22 @@ LV_NAME="lv-one-$VM_ID-$DISK_ID"
|
||||
VG_NAME="vg-one-$DS_SYS_ID"
|
||||
DEV="/dev/${VG_NAME}/${LV_NAME}"
|
||||
|
||||
# Get current LV size
|
||||
LVSIZE_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
${SUDO} ${LVS} --nosuffix --noheadings --units B -o lv_size "${DEV}" | \
|
||||
tr -d '[:blank:]'
|
||||
EOF
|
||||
)
|
||||
|
||||
LVSIZE_OLD=$(ssh_monitor_and_log "$SRC_HOST" "$LVSIZE_CMD" \
|
||||
"Failed to get current LV size")
|
||||
|
||||
if [ $? -ne 0 ] || [ -z "${LVSIZE_OLD}" ]; then
|
||||
error_message "$script_name: Could not detect current size of LV ${LV_NAME}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Execute lvextend with a lock in the frontend
|
||||
RESIZE_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
@ -69,4 +85,21 @@ EOF
|
||||
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
|
||||
exclusive "${LOCK}" 120 ssh_exec_and_log "$SRC_HOST" "$RESIZE_CMD" \
|
||||
"Error resizing LV named $LV_NAME"
|
||||
|
||||
# Zero additional space
|
||||
ZERO_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
|
||||
LVSIZE_NEW=\$(${SUDO} ${LVS} --nosuffix --noheadings --units B -o lv_size "${DEV}" | \
|
||||
tr -d '[:blank:]')
|
||||
|
||||
${DD} if=/dev/zero of="${DEV}" bs=64k \
|
||||
oflag=seek_bytes iflag=count_bytes \
|
||||
seek="${LVSIZE_OLD}" count="\$(( LVSIZE_NEW - ${LVSIZE_OLD} ))"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$ZERO_CMD" \
|
||||
"Error preparing additional space on LV $LV_NAME"
|
||||
|
||||
exit 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user