From 53c575029cc7edc3c1d392456e7abf555030e4b6 Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Mon, 24 Jul 2023 09:49:22 +0200 Subject: [PATCH] F OpenNebula/one#6265: Fix recovery_snap_create_live (#2659) Disk is not a symlik any more + don't delete rs_tmp if used + run blockcommit in trap --- src/tm_mad/ssh/clone.replica | 3 ++ src/tm_mad/ssh/recovery_snap_create_live | 35 ++++++++++++++++-------- src/tm_mad/ssh/snap_create_live | 4 ++- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/tm_mad/ssh/clone.replica b/src/tm_mad/ssh/clone.replica index 7c89852e3a..ab3da766d6 100755 --- a/src/tm_mad/ssh/clone.replica +++ b/src/tm_mad/ssh/clone.replica @@ -177,6 +177,9 @@ EOF create_base "$DST_PATH" "$DST_PATH" "mv" EOF ) + else + # when recovery running create only ". -> disk.X.snap" symlink + MAKE_SNAP_CMD="cd $DST_PATH.snap; ln -s . $DST_FILE.snap" fi fi diff --git a/src/tm_mad/ssh/recovery_snap_create_live b/src/tm_mad/ssh/recovery_snap_create_live index 156e318ff1..f339f795e4 100755 --- a/src/tm_mad/ssh/recovery_snap_create_live +++ b/src/tm_mad/ssh/recovery_snap_create_live @@ -32,6 +32,7 @@ source ${DRIVER_PATH}/../../scripts_common.sh mkdir -p "${DISK_PATH}.snap" SNAP_PATH="${DISK_PATH}.snap/rs_tmp" DISK_NAME="$(basename $DISK_PATH)" +REAL_DISK="$(dirname $DISK_PATH)/$(readlink $DISK_PATH)" if [ -f $SNAP_PATH ]; then SNAP_OLD=$(stat -c "%Y" $SNAP_PATH) @@ -40,7 +41,18 @@ if [ -f $SNAP_PATH ]; then echo "$SNAP_OLD" exit 0 else - rm $SNAP_PATH + # if rs_tmp is found in domain block devices -> last time + # the blockcommit failed, try again now and exit + if virsh -c ${LIBVIRT_URI} domblklist one-${VMID} | grep "snap/rs_tmp" ; then + virsh -c ${LIBVIRT_URI} blockcommit one-${VMID} $SNAP_PATH \ + --base $REAL_DISK \ + --top $SNAP_PATH \ + --active --pivot --wait >/dev/null + + exit 1 + else + rm $SNAP_PATH + fi fi fi @@ -59,7 +71,7 @@ fi DISKS=$(virsh -c ${LIBVIRT_URI} domblklist one-${VMID} | grep disk | awk '{print $2}') OTHER_DISK_STR="" for DISK in $DISKS; do - [ "$DISK" = "$DISK_PATH" ] && continue + [ "$DISK" = "$REAL_DISK" ] && continue OTHER_DISK_STR+="--diskspec $DISK,snapshot=no " done @@ -69,7 +81,7 @@ done touch $SNAP_PATH SNAP_CMD=$(cat </dev/null || $SNAP_CMD >/dev/null -# copy base.1 to the replica -ssh $REPLICA_HOST "mkdir -p $REPLICA_RECOVERY_SNAPS_DIR/$VMID/$DISK_NAME.snap" -rsync -q $DISK_PATH.snap/base.1 \ - $REPLICA_HOST:$REPLICA_RECOVERY_SNAPS_DIR/$VMID/$DISK_NAME.snap/ > /dev/null - +# Once recovery_snap is created, always do blockcommit before end -> use trap # reduce the backing-chain using blockcommit # base <- base.1 <- rs_tmp is reduced to base <- base.1 # outdated rs_tmp is deleted next cycle -virsh -c ${LIBVIRT_URI} blockcommit one-${VMID} $SNAP_PATH \ - --base $DISK_PATH.snap/base.1 \ +trap "virsh -c ${LIBVIRT_URI} blockcommit one-${VMID} $SNAP_PATH \ + --base $REAL_DISK \ --top $SNAP_PATH \ - --active --pivot --wait >/dev/null + --active --pivot --wait >/dev/null" EXIT + +# copy base.1 to the replica +ssh $REPLICA_HOST "mkdir -p $REPLICA_RECOVERY_SNAPS_DIR/$VMID/$DISK_NAME.snap" +rsync -q $REAL_DISK \ + $REPLICA_HOST:$REPLICA_RECOVERY_SNAPS_DIR/$VMID/$DISK_NAME.snap/ > /dev/null stat -c "%Y" $SNAP_PATH diff --git a/src/tm_mad/ssh/snap_create_live b/src/tm_mad/ssh/snap_create_live index 3edb208815..ad6dbcc82b 100755 --- a/src/tm_mad/ssh/snap_create_live +++ b/src/tm_mad/ssh/snap_create_live @@ -73,8 +73,10 @@ $(type retry_if_no_error| grep -v 'is a function') mkdir -p "${SNAP_DIR}" touch $SNAP_PATH +REAL_DISK="\$(dirname $SRC_PATH)/\$(readlink $SRC_PATH)" + retry_if_no_error "active block job" 3 5 virsh -q -c ${LIBVIRT_URI} blockcopy ${DEPLOY_ID} \ - --path ${SRC_PATH} --dest $SNAP_PATH --wait --finish + --path \${REAL_DISK} --dest $SNAP_PATH --wait --finish if [ -n "$REPLICA_HOST" ]; then ssh $REPLICA_HOST "mkdir -p $REPLICA_RECOVERY_SNAPS_DIR/$VMID"