1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #3782: add qcow2 tm/snap_{create,revert}

This commit is contained in:
Javi Fontan 2015-06-10 18:44:03 -04:00
parent 80c06dca38
commit 943e0e5292
2 changed files with 123 additions and 2 deletions

View File

@ -1 +0,0 @@
../common/not_supported.sh

74
src/tm_mad/qcow2/snap_create Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash -x
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
# snap_create host:parent_image snap_id vmid ds_id
SRC=$1
SNAP_ID=$2
VMID=$3
DSID=$4
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
DATASTORES=/var/lib/one/datastores
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
DATASTORES=$ONE_LOCATION/var/datastores
fi
. $TMCOMMON
SRC_PATH=`arg_path $SRC`
SYSTEM_DS_PATH=$(dirname ${SRC_PATH})
DISK_ID=$(basename ${SRC} | cut -d. -f2)
DISK_PATH="${SYSTEM_DS_PATH}/disk.${DISK_ID}"
SNAP_DIR="${DISK_PATH}.snap"
SNAP_PATH="${SNAP_DIR}/${SNAP_ID}"
SNAP_PATH_RELATIVE=$(basename ${SNAP_PATH})
CURRENT_PATH=${DISK_PATH}
if [ ! -d ${SNAP_PATH} ]; then
mkdir ${SNAP_DIR}
fi
# Move save current snapshot and create a new one. The snapshot uses
# absolute path name as the qemu-img has problems with relative backing
# file paths and symlinks
mv ${CURRENT_PATH} ${SNAP_PATH}
qemu-img create -f qcow2 -b ${SNAP_PATH} ${CURRENT_PATH}
# TODO: Check that the new snapshot can be created. Roll back in case
# of error
# Convert backing file absolute path to relative path so it works outside
# the system directory. Do not do this for snapshot one as:
# * It could be a non backed file (persistent)
# * The backing file is in images directory, is not relative
if [ "$SNAP_ID" != "0" ]; then
BACKING_FILE=$(qemu-img info ${SNAP_PATH} | grep '^backing file:' | \
cut -d: -f2 | sed 's/^ //')
if [ -n "$BACKING_FILE" ]; then
RELATIVE_BACKING_FILE=$(basename ${BACKING_FILE})
qemu-img rebase -u -b ${RELATIVE_BACKING_FILE} ${SNAP_PATH}
fi
fi

View File

@ -1 +0,0 @@
../common/not_supported.sh

49
src/tm_mad/qcow2/snap_revert Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
# snap_create host:parent_image snap_id vmid ds_id
SRC=$1
SNAP_ID=$2
VMID=$3
DSID=$4
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
DATASTORES=/var/lib/one/datastores
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
DATASTORES=$ONE_LOCATION/var/datastores
fi
. $TMCOMMON
SRC_PATH=`arg_path $SRC`
SYSTEM_DS_PATH=$(dirname ${SRC_PATH})
DISK_ID=$(basename ${SRC} | cut -d. -f2)
DISK_PATH="${SYSTEM_DS_PATH}/disk.${DISK_ID}"
SNAP_DIR="${DISK_PATH}.snap"
SNAP_PATH="${SNAP_DIR}/${SNAP_ID}"
SNAP_PATH_RELATIVE=$(basename ${SNAP_PATH})
CURRENT_PATH=${DISK_PATH}
rm ${CURRENT_PATH}
qemu-img create -f qcow2 -b ${SNAP_PATH} ${CURRENT_PATH}