From 4dc243478f39583a8a0f2207f4d4e3e33fa21508 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 14 Sep 2015 11:31:28 +0200 Subject: [PATCH 01/10] Feature #3362: optimize ceph driver --- install.sh | 3 +- src/datastore_mad/remotes/ceph/ceph_utils.sh | 36 ++++++++++ src/datastore_mad/remotes/ceph/clone | 15 +++- src/datastore_mad/remotes/ceph/cp | 6 ++ src/datastore_mad/remotes/ceph/mkfs | 6 ++ src/datastore_mad/remotes/ceph/rm | 43 +++--------- src/datastore_mad/remotes/ceph/snap_delete | 11 +-- src/datastore_mad/remotes/ceph/snap_flatten | 31 ++------- src/datastore_mad/remotes/ceph/snap_revert | 10 ++- src/mad/sh/scripts_common.sh | 30 ++++++++ src/tm_mad/ceph/clone | 23 +++++-- src/tm_mad/ceph/cpds | 12 +++- src/tm_mad/ceph/delete | 50 +++----------- src/tm_mad/ceph/mvds | 72 ++++++++++++++++++++ src/tm_mad/ceph/snap_delete | 13 ++-- src/tm_mad/ceph/snap_revert | 12 ++-- 16 files changed, 242 insertions(+), 131 deletions(-) create mode 100644 src/datastore_mad/remotes/ceph/ceph_utils.sh diff --git a/install.sh b/install.sh index 5107f273e2..3a75e4bfcd 100755 --- a/install.sh +++ b/install.sh @@ -1181,7 +1181,8 @@ DATASTORE_DRIVER_CEPH_SCRIPTS="src/datastore_mad/remotes/ceph/cp \ src/datastore_mad/remotes/ceph/snap_delete \ src/datastore_mad/remotes/ceph/snap_revert \ src/datastore_mad/remotes/ceph/snap_flatten \ - src/datastore_mad/remotes/ceph/ceph.conf" + src/datastore_mad/remotes/ceph/ceph.conf \ + src/datastore_mad/remotes/ceph/ceph_utils.sh" DATASTORE_DRIVER_DEV_SCRIPTS="src/datastore_mad/remotes/dev/cp \ src/datastore_mad/remotes/dev/mkfs \ diff --git a/src/datastore_mad/remotes/ceph/ceph_utils.sh b/src/datastore_mad/remotes/ceph/ceph_utils.sh new file mode 100644 index 0000000000..96571a3eb8 --- /dev/null +++ b/src/datastore_mad/remotes/ceph/ceph_utils.sh @@ -0,0 +1,36 @@ +rbd_rm_r() { + local rbd rbd_base children snaps + + rbd=$1 # one/one-86-0@0 -or- one/one-86- + rbd_base=${rbd%%@*} # one/one-86-0 + + if [ "$rbd" != "$rbd_base" ]; then + # arg is a snapshot (rbd=one/one-rbd86-0@0) => find children + children=$($RBD children $rbd 2>/dev/null) + + for child in $children; do + rbd_rm_r $child + done + + $RBD snap unprotect $rbd + $RBD snap rm $rbd + else + # arg is an rbd (rbd=one/one-86-0) => find snaps + snaps=$($RBD snap ls $rbd 2>/dev/null| awk 'NR > 1 {print $2}') + + for snap in $snaps; do + rbd_rm_r $rbd@$snap + done + + $RBD rm $rbd + fi +} + + +rbd_format() { + $RBD info $RBD_SRC | sed -n 's/.*format: // p' +} + +has_snapshots() { + $RBD info $RBD_SRC-0@0 2>/dev/null +} diff --git a/src/datastore_mad/remotes/ceph/clone b/src/datastore_mad/remotes/ceph/clone index 9450770fce..bf02ad8c57 100755 --- a/src/datastore_mad/remotes/ceph/clone +++ b/src/datastore_mad/remotes/ceph/clone @@ -47,6 +47,7 @@ while IFS= read -r -d '' element; do done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RBD_FORMAT \ /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ /DS_DRIVER_ACTION_DATA/IMAGE/SIZE \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER) @@ -56,6 +57,7 @@ unset i BASE_PATH="${XPATH_ELEMENTS[i++]}" BRIDGE_LIST="${XPATH_ELEMENTS[i++]}" POOL_NAME="${XPATH_ELEMENTS[i++]:-$POOL_NAME}" +RBD_FORMAT="${XPATH_ELEMENTS[i++]:-$RBD_FORMAT}" SRC="${XPATH_ELEMENTS[i++]}" SIZE="${XPATH_ELEMENTS[i++]}" CEPH_USER="${XPATH_ELEMENTS[i++]}" @@ -76,7 +78,18 @@ SAFE_DIRS="" IMAGE_NAME="one-${ID}" RBD_DST="${POOL_NAME}/${IMAGE_NAME}" -ssh_exec_and_log "$DST_HOST" "$RBD copy $SRC $RBD_DST" \ +COPY_CMD=$(cat </dev/null) - - for child in \$CHILDREN; do - snap_id=\${child##*-} - child=\$child@\$snap_id - rm_children \$child - done - - $RBD snap unprotect \$rbd_snap - $RBD snap rm \$rbd_snap - fi - - $RBD rm \$rbd - } - - RBD_FORMAT=\$($RBD info $RBD_SRC | sed -n 's/.*format: // p') - - if [ "\$RBD_FORMAT" = "2" ]; then - has_snap_shots=\$($RBD info $RBD_SRC-0@0 2>/dev/null) - - if [ -n "\$has_snap_shots" ]; then - rm_children $RBD_SRC-0@0 + if [ "\$(rbd_format)" = "2" ]; then + if [ -n "\$(has_snapshots)" ]; then + rbd_rm_r $RBD_SRC-0 else - $RBD rm $RBD_SRC + rbd_rm_r $RBD_SRC fi else $RBD rm $RBD_SRC @@ -108,7 +85,5 @@ DELETE_CMD=$(cat </dev/null) - - for child in \$CHILDREN; do - snap_id=\${child##*-} - child=\$child@\$snap_id - rm_children \$child - done - - $RBD snap unprotect \$rbd_snap - $RBD snap rm \$rbd_snap - fi - - $RBD rm \$rbd - } + RBD="${RBD}" + RBD_SRC="${RBD_SRC}" RBD_FORMAT=\$($RBD info $RBD_SRC | sed -n 's/.*format: // p') @@ -105,11 +86,11 @@ SNAP_FLATTEN_CMD=$(cat <&1 1>/dev/null < /dev/null 2>&1 && exit 0 + # Exit if destination rbd already exists + $RBD info $RBD_DST >/dev/null 2>&1 && exit 0 RBD_FORMAT=\$($RBD info $SRC_PATH | sed -n 's/.*format: // p') if [ "\$RBD_FORMAT" = "2" ]; then - $RBD snap create "$SRC_PATH@$RBD_SNAP" - $RBD snap protect "$SRC_PATH@$RBD_SNAP" - $RBD clone "$SRC_PATH@$RBD_SNAP" $RBD_DST + + # Feature #3362: migrate now to new schema + ( + set +e + + # Check if @snap exists + $RBD info $SRC_PATH@snap >/dev/null 2>&1 + + if [ "$?" != "0" ]; then + # It does not exist, create it now + $RBD snap create "$SRC_PATH@snap" + $RBD snap protect "$SRC_PATH@snap" + fi + ) + + $RBD clone "$SRC_PATH@snap" $RBD_DST else $RBD copy $SRC_PATH $RBD_DST fi diff --git a/src/tm_mad/ceph/cpds b/src/tm_mad/ceph/cpds index 32c8b5146c..99047f9968 100755 --- a/src/tm_mad/ceph/cpds +++ b/src/tm_mad/ceph/cpds @@ -86,7 +86,13 @@ if [ -n "$CEPH_USER" ]; then RBD="$RBD --id ${CEPH_USER}" fi -ssh_exec_and_log "$SRC_HOST" "$RBD copy $RBD_DST $DST" \ - "Error cloning $RBD_DST to $DST in $SRC_HOST" +COPY_CMD=$(cat </one---" RBD_SRC="${SRC}-${VM_ID}-${DISK_ID}" -RBD_SNAP="${VM_ID}-${DISK_ID}" #------------------------------------------------------------------------------- # Delete the device @@ -97,53 +98,18 @@ log "Deleting $DST_PATH" # drivers, is executed in the worker node and not in the CEPH frontend. DELETE_CMD=$(cat </dev/null) - - for child in \$CHILDREN; do - snap_id=\${child##*-} - child=\$child@\$snap_id - rm_children \$child - done - - $RBD snap unprotect \$rbd_snap - $RBD snap rm \$rbd_snap - fi - - $RBD rm \$rbd - } + RBD="${RBD}" + RBD_SRC="${RBD_SRC}" RBD_FORMAT=\$($RBD info $RBD_SRC | sed -n 's/.*format: // p') - if [ "\$RBD_FORMAT" = "2" ]; then - has_snap_shots=\$($RBD info $RBD_SRC-0@0 2>/dev/null) - - if [ -n "\$has_snap_shots" ]; then - rm_children $RBD_SRC-0@0 - else - $RBD rm $RBD_SRC - fi - else + if [ "\$RBD_FORMAT" != "2" -o -z "\$(has_snapshots)" ]; then $RBD rm $RBD_SRC - fi - - # Remove the snapshot of the original image used to create a CLONE - if [ "\$RBD_FORMAT" = "2" ]; then - $RBD snap unprotect $SRC@$RBD_SNAP - $RBD snap rm $SRC@$RBD_SNAP + else + rbd_rm_r $RBD_SRC-0 fi EOF ) -ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" \ +ssh_exec_and_log_stdin "$DST_HOST" "$DELETE_CMD" "$CEPH_UTILS" \ "Error deleting $RBD_SRC in $DST_HOST" - -exit 0 diff --git a/src/tm_mad/ceph/mvds b/src/tm_mad/ceph/mvds index 8c976fe703..ab01024810 100755 --- a/src/tm_mad/ceph/mvds +++ b/src/tm_mad/ceph/mvds @@ -16,4 +16,76 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# cpds host:remote_system_ds/disk.i fe:SOURCE snapid vmid dsid +# - fe is the front-end hostname +# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host +# - snapid is the snapshot id. "-1" for none + +SRC=$1 +DST=$2 + +VMID=$3 +DSID=$4 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +DRIVER_PATH=$(dirname $0) + +source $TMCOMMON +source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf + +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- + +SRC_HOST=`arg_host $SRC` +RBD_SRC=`arg_path $SRC` + +#------------------------------------------------------------------------------- +# Get Image information +#------------------------------------------------------------------------------- + +DISK_ID=$(echo "$RBD_SRC" | $AWK -F. '{print $NF}') + +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]/SOURCE \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_USER) + +RBD_SRC="${XPATH_ELEMENTS[j++]}" +CLONE="${XPATH_ELEMENTS[j++]}" +CEPH_USER="${XPATH_ELEMENTS[j++]}" + +#------------------------------------------------------------------------------- +# Copy Image back to the datastore +#------------------------------------------------------------------------------- + +if [ -n "$CEPH_USER" ]; then + RBD="$RBD --id ${CEPH_USER}" +fi + +REFRESH_SNAP=$(cat < Date: Fri, 2 Oct 2015 19:21:11 +0200 Subject: [PATCH 02/10] feautre #3362: Delay clone operations for snapshots, this also to perform live snapshots --- src/tm_mad/ceph/snap_create | 4 +--- src/tm_mad/ceph/snap_delete | 35 ++++++++++++++++++++++++++++++----- src/tm_mad/ceph/snap_revert | 29 +++++++++++++++++++++-------- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/tm_mad/ceph/snap_create b/src/tm_mad/ceph/snap_create index 8fc9242b7c..664c979810 100755 --- a/src/tm_mad/ceph/snap_create +++ b/src/tm_mad/ceph/snap_create @@ -69,7 +69,7 @@ else fi #------------------------------------------------------------------------------- -# Create snapshots +# Create snapshots (stored in the current volume) #------------------------------------------------------------------------------- if [ -n "$CEPH_USER" ]; then @@ -88,8 +88,6 @@ SNAP_CREATE_CMD=$(cat <&2 + exit 1 + fi + + $RBD snap unprotect \${RBD_TGT}@$SNAP_ID + $RBD snap rm \${RBD_TGT}@$SNAP_ID + + SNAPIDS=\$($RBD --format json snap ls \${RBD_TGT} | \ + grep -Po '(?<="name":")\d+' | \ + paste -d: -s) + + if [ -z "\${SNAPIDS}" ]; then + $RBD rm \${RBD_TGT} + else + $RBD rename \${RBD_TGT} ${RBD_DST}-\${SNAPIDS} + fi EOF ) -ssh_exec_and_log_stdin "$SRC_HOST" "$SNAP_DELETE_CMD" "$CEPH_UTILS" \ +ssh_exec_and_log "$SRC_HOST" "$SNAP_DELETE_CMD" \ "Error deleting snapshot $RBD_DST-$SNAP_ID@$SNAP_ID" diff --git a/src/tm_mad/ceph/snap_revert b/src/tm_mad/ceph/snap_revert index 567624a9b7..3c918bd417 100755 --- a/src/tm_mad/ceph/snap_revert +++ b/src/tm_mad/ceph/snap_revert @@ -34,8 +34,6 @@ DRIVER_PATH=$(dirname $0) source $TMCOMMON source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf -CEPH_UTILS=${DRIVER_PATH}/../../datastore/ceph/ceph_utils.sh - #------------------------------------------------------------------------------- # Set dst path and dir #------------------------------------------------------------------------------- @@ -79,9 +77,6 @@ if [ -n "$CEPH_USER" ]; then fi SNAP_REVERT_CMD=$(cat <&2 + exit 1 + fi + + $RBD clone \${POOL_NAME}/\${RBD_TGT}@$SNAP_ID $RBD_DST EOF ) -ssh_exec_and_log_stdin "$SRC_HOST" "$SNAP_REVERT_CMD" "$CEPH_UTILS" \ +ssh_exec_and_log "$SRC_HOST" "$SNAP_REVERT_CMD" \ "Error reverting snapshot $RBD_DST-$SNAP_ID@$SNAP_ID" From dcf32ff64af7974ec3d2e3a895a1b094a67be19f Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 4 Oct 2015 20:19:48 +0200 Subject: [PATCH 03/10] feature #3362: Restore non-live snapshot support --- src/tm_mad/ceph/snap_create | 6 +- src/tm_mad/ceph/snap_create_live | 98 +++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 3 deletions(-) mode change 120000 => 100755 src/tm_mad/ceph/snap_create_live diff --git a/src/tm_mad/ceph/snap_create b/src/tm_mad/ceph/snap_create index 664c979810..d8cca4a229 100755 --- a/src/tm_mad/ceph/snap_create +++ b/src/tm_mad/ceph/snap_create @@ -1,7 +1,7 @@ #!/bin/bash # -------------------------------------------------------------------------- # -# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs # +# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems # # # # 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 # @@ -69,7 +69,7 @@ else fi #------------------------------------------------------------------------------- -# Create snapshots (stored in the current volume) +# Create snapshots #------------------------------------------------------------------------------- if [ -n "$CEPH_USER" ]; then @@ -88,6 +88,8 @@ SNAP_CREATE_CMD=$(cat <&2 + exit 1 + fi + + $RBD snap create $RBD_DST@$SNAP_ID + $RBD snap protect $RBD_DST@$SNAP_ID +EOF +) + +ssh_exec_and_log "$SRC_HOST" "$SNAP_CREATE_CMD" \ + "Error creating snapshot $RBD_DST@$SNAP_ID" + +exit 0 From 4c523c716c59e4b4493a10dc6cec619fa6e1a017 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 8 Oct 2015 16:30:37 +0200 Subject: [PATCH 04/10] feature #3362: Update Ceph DS & TM drivers with clone optimization --- share/etc/oned.conf | 2 +- src/datastore_mad/remotes/ceph/ceph_utils.sh | 158 +++++++++++++++++-- src/datastore_mad/remotes/ceph/clone | 14 +- src/datastore_mad/remotes/ceph/cp | 6 - src/datastore_mad/remotes/ceph/mkfs | 6 - src/datastore_mad/remotes/ceph/rm | 7 +- src/datastore_mad/remotes/ceph/snap_delete | 15 +- src/datastore_mad/remotes/ceph/snap_flatten | 15 +- src/datastore_mad/remotes/ceph/snap_revert | 14 +- src/tm_mad/ceph/clone | 36 ++--- src/tm_mad/ceph/cpds | 25 ++- src/tm_mad/ceph/delete | 17 +- src/tm_mad/ceph/ln | 63 ++++++++ src/tm_mad/ceph/mvds | 74 +-------- src/tm_mad/ceph/snap_create | 18 ++- src/tm_mad/ceph/snap_create_live | 16 +- src/tm_mad/ceph/snap_delete | 47 ++---- src/tm_mad/ceph/snap_revert | 62 ++++---- src/vmm_mad/exec/vmm_execrc | 2 +- 19 files changed, 343 insertions(+), 254 deletions(-) diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 93333acbce..cb83ed0e98 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -432,7 +432,7 @@ IM_MAD = [ VM_MAD = [ name = "kvm", executable = "one_vmm_exec", - arguments = "-t 15 -r 0 kvm", + arguments = "-t 15 -r 0 -i kvm", default = "vmm_exec/vmm_exec_kvm.conf", type = "kvm" ] diff --git a/src/datastore_mad/remotes/ceph/ceph_utils.sh b/src/datastore_mad/remotes/ceph/ceph_utils.sh index 96571a3eb8..7a8245986e 100644 --- a/src/datastore_mad/remotes/ceph/ceph_utils.sh +++ b/src/datastore_mad/remotes/ceph/ceph_utils.sh @@ -1,11 +1,153 @@ +# ----------------------------------------------------------------------------- # +# 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. # +#------------------------------------------------------------------------------ # + + +#-------------------------------------------------------------------------------- +# Make a base @snap for image clones +# @param $1 the volume +#-------------------------------------------------------------------------------- +rbd_make_snap() { + if [ "rbd_format $1" = "2" ]; then + $RBD info "$1@snap" >/dev/null 2>&1 + + if [ "$?" != "0" ]; then + $RBD snap create "$1@snap" + $RBD snap protect "$1@snap" + fi + fi +} + +#-------------------------------------------------------------------------------- +# Remove thea base @snap for image clones +# @param $1 the volume +#-------------------------------------------------------------------------------- +rbd_rm_snap() { + if [ "rbd_format $1" = "2" ]; then + $RBD info "$1@snap" >/dev/null 2>&1 + + if [ "$?" == "0" ]; then + $RBD snap unprotect "$1@snap" + $RBD snap rm "$1@snap" + fi + fi +} + +#-------------------------------------------------------------------------------- +# Find the snapshot in current volume or any of the snapshot volumes +# @param $1 volume base, i.e. /one-[--] +# @param $2 snapshot id +# @return volume name, exits if not found +#-------------------------------------------------------------------------------- +rbd_find_snap() { + local rbd_tgt pool vol + + $($RBD --format json snap ls $1 2>/dev/null | grep -Pq "(?<=\"name\":\")$2") + + if [ $? -eq 0 ]; then + rbd_tgt=$1 + else + pool=$(echo $1 | cut -f1 -d'/') + vol=$(echo $1 | cut -f2 -d'/') + + rbd_tgt=$($RBD ls $pool | grep "$vol-[^-]*$2[^-]*") + + if [ -z "${rbd_tgt}" ]; then + echo "Could not find a volume with snapshot $2" >&2 + exit 1 + fi + + rbd_tgt=$pool/$rbd_tgt + fi + + echo $rbd_tgt +} + +#-------------------------------------------------------------------------------- +# Rename the target volume to include the snapshot list or remove it if it has +# no snapshots +# @param $1 volume base, i.e. /one-[--] +# @param $2 volume to rename or remove +#-------------------------------------------------------------------------------- +rbd_rename_rm() { + local snapids + + snapids=$($RBD --format json snap ls $2 | \ + grep -Po '(?<="name":")\d+' | \ + paste -d: -s) + + if [ -z "$snapids" ]; then + $RBD rm $2 + else + $RBD rename $2 $1-$snapids + fi +} + +#-------------------------------------------------------------------------------- +# Return format of rbd volume +# @param $1 the volume +# @return the format of the volume +#-------------------------------------------------------------------------------- +rbd_format() { + $RBD info $1 | sed -n 's/.*format: // p' +} + +#-------------------------------------------------------------------------------- +# Check if given volume id formta 2, exits otherwise +# @param $1 the volume +#-------------------------------------------------------------------------------- +rbd_check_2() { + if [ $(rbd_format $1) != "2" ]; then + echo "Only RBD Format 2 is supported for this operation" >&2 + exit 1 + fi +} + +#-------------------------------------------------------------------------------- +# Get top parent of a snapshot hierarchy if the volume has snapshots. +# @param $1 the volume +# @return the top parent or volume in no snapshots found +#-------------------------------------------------------------------------------- +rbd_top_parent() { + local pool snap0 volume + + pool=$(echo $1 | cut -f1 -d'/') + volume=$(echo $1 | cut -f2 -d'/') + + snap0=$($RBD ls -l $pool | grep "$volume.*@0") + + if [ -n "$snap0" ]; then + volume=$pool/${snap0%%@*} + else + volume=$1 + fi + + echo $volume +} + +#-------------------------------------------------------------------------------- +# Remove all the images and snapshots from a given volume +# @param $1 the volume (or snapshot to delete) +#-------------------------------------------------------------------------------- rbd_rm_r() { local rbd rbd_base children snaps - rbd=$1 # one/one-86-0@0 -or- one/one-86- - rbd_base=${rbd%%@*} # one/one-86-0 + rbd=$1 + rbd_base=${rbd%%@*} if [ "$rbd" != "$rbd_base" ]; then - # arg is a snapshot (rbd=one/one-rbd86-0@0) => find children children=$($RBD children $rbd 2>/dev/null) for child in $children; do @@ -15,7 +157,6 @@ rbd_rm_r() { $RBD snap unprotect $rbd $RBD snap rm $rbd else - # arg is an rbd (rbd=one/one-86-0) => find snaps snaps=$($RBD snap ls $rbd 2>/dev/null| awk 'NR > 1 {print $2}') for snap in $snaps; do @@ -25,12 +166,3 @@ rbd_rm_r() { $RBD rm $rbd fi } - - -rbd_format() { - $RBD info $RBD_SRC | sed -n 's/.*format: // p' -} - -has_snapshots() { - $RBD info $RBD_SRC-0@0 2>/dev/null -} diff --git a/src/datastore_mad/remotes/ceph/clone b/src/datastore_mad/remotes/ceph/clone index bf02ad8c57..db49dfeb79 100755 --- a/src/datastore_mad/remotes/ceph/clone +++ b/src/datastore_mad/remotes/ceph/clone @@ -78,19 +78,7 @@ SAFE_DIRS="" IMAGE_NAME="one-${ID}" RBD_DST="${POOL_NAME}/${IMAGE_NAME}" -COPY_CMD=$(cat <&2 - exit 1 + RBD_TGT=\$(rbd_find_snap $RBD_SRC $SNAP_ID) + + $RBD snap unprotect \${RBD_TGT}@$SNAP_ID + $RBD snap rm \${RBD_TGT}@$SNAP_ID + + if [ "\${RBD_TGT}" != "$RBD_SRC" ]; then + rbd_rename_rm $RBD_SRC \${RBD_TGT} fi - - rbd_rm_r $RBD_SRC-$SNAP_ID EOF ) diff --git a/src/datastore_mad/remotes/ceph/snap_flatten b/src/datastore_mad/remotes/ceph/snap_flatten index 25c3911f95..72ba22817e 100755 --- a/src/datastore_mad/remotes/ceph/snap_flatten +++ b/src/datastore_mad/remotes/ceph/snap_flatten @@ -74,23 +74,20 @@ fi SNAP_FLATTEN_CMD=$(cat <&2 - exit 1 - fi + RBD_TGT=\$(rbd_find_snap $RBD_SRC $SNAP_ID) + + $RBD clone \${RBD_TGT}@$SNAP_ID $RBD_SRC.flatten - $RBD clone $RBD_SRC-$SNAP_ID@$SNAP_ID $RBD_SRC.flatten $RBD flatten $RBD_SRC.flatten - rbd_rm_r $RBD_SRC-0 + rbd_rm_r \$(rbd_top_parent $RBD_SRC) $RBD rename $RBD_SRC.flatten $RBD_SRC EOF ) ssh_exec_and_log_stdin "$DST_HOST" "$SNAP_FLATTEN_CMD" "$CEPH_UTILS" \ - "Error flattening snapshot $RBD_SRC-$SNAP_ID@$SNAP_ID" + "Error flattening snapshot $SNAP_ID for $RBD_SRC" diff --git a/src/datastore_mad/remotes/ceph/snap_revert b/src/datastore_mad/remotes/ceph/snap_revert index 40032b0cb0..6d515de07d 100755 --- a/src/datastore_mad/remotes/ceph/snap_revert +++ b/src/datastore_mad/remotes/ceph/snap_revert @@ -74,20 +74,16 @@ fi SNAP_REVERT_CMD=$(cat <&2 - exit 1 - fi + rbd_rename_rm $RBD_SRC $RBD_SRC - rbd_rm_r $RBD_SRC + RBD_TGT=\$(rbd_find_snap $RBD_SRC $SNAP_ID) - $RBD clone $RBD_SRC-$SNAP_ID@$SNAP_ID $RBD_SRC + $RBD clone \${RBD_TGT}@$SNAP_ID $RBD_SRC EOF ) ssh_exec_and_log_stdin "$DST_HOST" "$SNAP_REVERT_CMD" "$CEPH_UTILS" \ - "Error reverting snapshot $RBD_SRC-$SNAP_ID@$SNAP_ID" + "Error reverting snapshot $SNAP_ID for $RBD_DST" diff --git a/src/tm_mad/ceph/clone b/src/tm_mad/ceph/clone index 2abc5b6c49..e7f2403ee8 100755 --- a/src/tm_mad/ceph/clone +++ b/src/tm_mad/ceph/clone @@ -27,22 +27,30 @@ DST=$2 VM_ID=$3 DS_ID=$4 +#-------------------------------------------------------------------------------- + if [ -z "${ONE_LOCATION}" ]; then TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh + LIB_LOCATION=/usr/lib/one else TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh + LIB_LOCATION=$ONE_LOCATION/lib fi DRIVER_PATH=$(dirname $0) +source $LIB_LOCATION/sh/scripts_common.sh source $TMCOMMON +source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf -DST_HOST=`arg_host $DST` +CEPH_UTILS=${DRIVER_PATH}/../../datastore/ceph/ceph_utils.sh #------------------------------------------------------------------------------- # Compute the destination image name #------------------------------------------------------------------------------- +DST_HOST=`arg_host $DST` + SRC_PATH=`arg_path $SRC` DISK_ID=$(echo $DST|awk -F. '{print $NF}') @@ -68,7 +76,7 @@ SIZE="${XPATH_ELEMENTS[j++]}" ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}" #------------------------------------------------------------------------------- -# Clone the image +# Clone the image and create @snap if it does not exists #------------------------------------------------------------------------------- if [ -n "$CEPH_USER" ]; then @@ -76,29 +84,15 @@ if [ -n "$CEPH_USER" ]; then fi CLONE_CMD=$(cat </dev/null 2>&1 && exit 0 - RBD_FORMAT=\$($RBD info $SRC_PATH | sed -n 's/.*format: // p') + rbd_make_snap $SRC_PATH - if [ "\$RBD_FORMAT" = "2" ]; then - - # Feature #3362: migrate now to new schema - ( - set +e - - # Check if @snap exists - $RBD info $SRC_PATH@snap >/dev/null 2>&1 - - if [ "$?" != "0" ]; then - # It does not exist, create it now - $RBD snap create "$SRC_PATH@snap" - $RBD snap protect "$SRC_PATH@snap" - fi - ) + set -e + if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then $RBD clone "$SRC_PATH@snap" $RBD_DST else $RBD copy $SRC_PATH $RBD_DST @@ -110,6 +104,6 @@ CLONE_CMD=$(cat < persistnet) +#------------------------------------------------------------------------------- + +if [ -n "$CEPH_USER" ]; then + RBD="$RBD --id ${CEPH_USER}" +fi + +CLONE_CMD=$(cat <&2 - exit 1 - fi + rbd_check_2 $RBD_DST $RBD snap create $RBD_DST@$SNAP_ID $RBD snap protect $RBD_DST@$SNAP_ID @@ -93,7 +97,7 @@ SNAP_CREATE_CMD=$(cat <&2 - exit 1 - fi + rbd_check_2 $RBD_DST $RBD snap create $RBD_DST@$SNAP_ID $RBD snap protect $RBD_DST@$SNAP_ID EOF ) -ssh_exec_and_log "$SRC_HOST" "$SNAP_CREATE_CMD" \ +ssh_exec_and_log_stdin "$SRC_HOST" "$SNAP_CREATE_CMD" "$CEPH_UTILS" \ "Error creating snapshot $RBD_DST@$SNAP_ID" exit 0 diff --git a/src/tm_mad/ceph/snap_delete b/src/tm_mad/ceph/snap_delete index 7c7e3942d4..37ccf56e36 100755 --- a/src/tm_mad/ceph/snap_delete +++ b/src/tm_mad/ceph/snap_delete @@ -23,14 +23,19 @@ SNAP_ID=$2 VM_ID=$3 DS_ID=$4 +#-------------------------------------------------------------------------------- + if [ -z "${ONE_LOCATION}" ]; then TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh + LIB_LOCATION=/usr/lib/one else TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh + LIB_LOCATION=$ONE_LOCATION/lib fi DRIVER_PATH=$(dirname $0) +source $LIB_LOCATION/sh/scripts_common.sh source $TMCOMMON source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf @@ -71,7 +76,9 @@ else fi #------------------------------------------------------------------------------- -# Delete snapshots +# Delete snapshot. Look for the snapshot in: +# 1.- current volume one- +# 2.- any of the snapshot volumes: one-[--]- #------------------------------------------------------------------------------- if [ -n "$CEPH_USER" ]; then @@ -79,44 +86,20 @@ if [ -n "$CEPH_USER" ]; then fi SNAP_DELETE_CMD=$(cat <&2 - exit 1 - fi + rbd_check_2 $RBD_DST - \$($RBD --format json snap ls $RBD_DST | grep -Pq "(?<=\"name\":\")$SNAP_ID") - - if [ \$? -eq 0 ]; then - RBD_TGT=$RBD_DST - else - POOL_NAME=\$(echo $RBD_DST | cut -f1 -d'/') - VOL_NAME=\$(echo $RBD_DST | cut -f2 -d'/') - - RBD_TGT=\$($RBD ls \${POOL_NAME} | grep "\${VOL_NAME}-[^-]*$SNAP_ID[^-]*") - RBD_TGT="\${POOL_NAME}/\${RBD_TGT}" - fi - - if [ -z "\${RBD_TGT}" ]; then - echo "Could not find a volume with snapshot $SNAP_ID" >&2 - exit 1 - fi + RBD_TGT=\$(rbd_find_snap $RBD_DST $SNAP_ID) $RBD snap unprotect \${RBD_TGT}@$SNAP_ID $RBD snap rm \${RBD_TGT}@$SNAP_ID - SNAPIDS=\$($RBD --format json snap ls \${RBD_TGT} | \ - grep -Po '(?<="name":")\d+' | \ - paste -d: -s) - - if [ -z "\${SNAPIDS}" ]; then - $RBD rm \${RBD_TGT} - else - $RBD rename \${RBD_TGT} ${RBD_DST}-\${SNAPIDS} + if [ "\${RBD_TGT}" != "$RBD_DST" ]; then + rbd_rename_rm $RBD_DST \${RBD_TGT} fi EOF ) -ssh_exec_and_log "$SRC_HOST" "$SNAP_DELETE_CMD" \ - "Error deleting snapshot $RBD_DST-$SNAP_ID@$SNAP_ID" +ssh_exec_and_log_stdin "$SRC_HOST" "$SNAP_DELETE_CMD" "$CEPH_UTILS" \ + "Error deleting snapshot $SNAP_ID" diff --git a/src/tm_mad/ceph/snap_revert b/src/tm_mad/ceph/snap_revert index 3c918bd417..77d46f0548 100755 --- a/src/tm_mad/ceph/snap_revert +++ b/src/tm_mad/ceph/snap_revert @@ -23,17 +23,24 @@ SNAP_ID=$2 VM_ID=$3 DS_ID=$4 +#-------------------------------------------------------------------------------- + if [ -z "${ONE_LOCATION}" ]; then TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh + LIB_LOCATION=/usr/lib/one else TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh + LIB_LOCATION=$ONE_LOCATION/lib fi DRIVER_PATH=$(dirname $0) +source $LIB_LOCATION/sh/scripts_common.sh source $TMCOMMON source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf +CEPH_UTILS=${DRIVER_PATH}/../../datastore/ceph/ceph_utils.sh + #------------------------------------------------------------------------------- # Set dst path and dir #------------------------------------------------------------------------------- @@ -69,7 +76,26 @@ else fi #------------------------------------------------------------------------------- -# Create snapshots +# Revert to Snapshot. Using the following tree structure +# +# one-3-13-0-1:2:3 +# ---------------- +# | @1 (snap 1) | revert to 2 +# | @2 (snap 2) |------------ +# | @3 (snap 3) | clone | +# ---------------- | +# V +# one-3-13-0-4:5 (stores snaps @4,@5 children of @2) +# -------------- +# revert to 4 | @4 (snap 4)| +# --------------| @5 (snap 5)| +# | clone -------------- +# | +# V +# one-3-13-0 (current volume) +# -------------- +# | @6 (snap 6)| +# -------------- #------------------------------------------------------------------------------- if [ -n "$CEPH_USER" ]; then @@ -77,36 +103,18 @@ if [ -n "$CEPH_USER" ]; then fi SNAP_REVERT_CMD=$(cat <&2 - exit 1 - fi + rbd_check_2 $RBD_DST - SNAPIDS=\$($RBD --format json snap ls $RBD_DST | \ - grep -Po '(?<="name":")\d+' | \ - paste -d: -s) + rbd_rename_rm $RBD_DST $RBD_DST - if [ -z "\${SNAPIDS}" ]; then - $RBD rm $RBD_DST - else - $RBD rename $RBD_DST $RBD_DST-\${SNAPIDS} - fi + RBD_TGT=\$(rbd_find_snap $RBD_DST $SNAP_ID) - POOL_NAME=\$(echo $RBD_DST | cut -f1 -d'/') - VOL_NAME=\$(echo $RBD_DST | cut -f2 -d'/') - - RBD_TGT=\$($RBD ls \${POOL_NAME} | grep "\${VOL_NAME}-[^-]*$SNAP_ID[^-]*") - - if [ -z "\$RBD_TGT" ]; then - echo "Could not find a volume with snapshot $SNAP_ID" >&2 - exit 1 - fi - - $RBD clone \${POOL_NAME}/\${RBD_TGT}@$SNAP_ID $RBD_DST + $RBD clone \${RBD_TGT}@$SNAP_ID $RBD_DST EOF ) -ssh_exec_and_log "$SRC_HOST" "$SNAP_REVERT_CMD" \ - "Error reverting snapshot $RBD_DST-$SNAP_ID@$SNAP_ID" +ssh_exec_and_log_stdin "$SRC_HOST" "$SNAP_REVERT_CMD" "$CEPH_UTILS" \ + "Error reverting snapshot $SNAP_ID for $RBD_DST" + diff --git a/src/vmm_mad/exec/vmm_execrc b/src/vmm_mad/exec/vmm_execrc index bd3c55f03a..f15bcfc776 100644 --- a/src/vmm_mad/exec/vmm_execrc +++ b/src/vmm_mad/exec/vmm_execrc @@ -16,4 +16,4 @@ # Space separated list of VMM-TM pairs that support live disk snapshots. VMM # and TM must be separated by '-' -LIVE_DISK_SNAPSHOTS="kvm-qcow2" +LIVE_DISK_SNAPSHOTS="kvm-qcow2 kvm-ceph" From fd93ebbefc978406d8e2539d2fda5ec567e9b442 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 8 Oct 2015 22:12:26 +0200 Subject: [PATCH 05/10] feature #3362: Fixes for ceph drivers --- src/datastore_mad/remotes/ceph/ceph_utils.sh | 9 ++++----- src/datastore_mad/remotes/ceph/rm | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/datastore_mad/remotes/ceph/ceph_utils.sh b/src/datastore_mad/remotes/ceph/ceph_utils.sh index 7a8245986e..906716bc2f 100644 --- a/src/datastore_mad/remotes/ceph/ceph_utils.sh +++ b/src/datastore_mad/remotes/ceph/ceph_utils.sh @@ -14,13 +14,12 @@ # limitations under the License. # #------------------------------------------------------------------------------ # - #-------------------------------------------------------------------------------- # Make a base @snap for image clones # @param $1 the volume #-------------------------------------------------------------------------------- rbd_make_snap() { - if [ "rbd_format $1" = "2" ]; then + if [ "$(rbd_format $1)" = "2" ]; then $RBD info "$1@snap" >/dev/null 2>&1 if [ "$?" != "0" ]; then @@ -35,10 +34,10 @@ rbd_make_snap() { # @param $1 the volume #-------------------------------------------------------------------------------- rbd_rm_snap() { - if [ "rbd_format $1" = "2" ]; then + if [ "$(rbd_format $1)" = "2" ]; then $RBD info "$1@snap" >/dev/null 2>&1 - if [ "$?" == "0" ]; then + if [ "$?" = "0" ]; then $RBD snap unprotect "$1@snap" $RBD snap rm "$1@snap" fi @@ -109,7 +108,7 @@ rbd_format() { # @param $1 the volume #-------------------------------------------------------------------------------- rbd_check_2() { - if [ $(rbd_format $1) != "2" ]; then + if [ "$(rbd_format $1)" != "2" ]; then echo "Only RBD Format 2 is supported for this operation" >&2 exit 1 fi diff --git a/src/datastore_mad/remotes/ceph/rm b/src/datastore_mad/remotes/ceph/rm index 1e16d130ca..bdb57c7623 100755 --- a/src/datastore_mad/remotes/ceph/rm +++ b/src/datastore_mad/remotes/ceph/rm @@ -72,7 +72,7 @@ log "Removing $RBD_SRC from the rbd image repository in $DST_HOST" DELETE_CMD=$(cat < Date: Wed, 14 Oct 2015 16:57:45 +0200 Subject: [PATCH 06/10] feature #3362: fine-tune the regular expressions --- src/datastore_mad/remotes/ceph/ceph_utils.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/datastore_mad/remotes/ceph/ceph_utils.sh b/src/datastore_mad/remotes/ceph/ceph_utils.sh index 906716bc2f..4336e05582 100644 --- a/src/datastore_mad/remotes/ceph/ceph_utils.sh +++ b/src/datastore_mad/remotes/ceph/ceph_utils.sh @@ -30,7 +30,7 @@ rbd_make_snap() { } #-------------------------------------------------------------------------------- -# Remove thea base @snap for image clones +# Remove the base @snap for image clones # @param $1 the volume #-------------------------------------------------------------------------------- rbd_rm_snap() { @@ -53,15 +53,15 @@ rbd_rm_snap() { rbd_find_snap() { local rbd_tgt pool vol - $($RBD --format json snap ls $1 2>/dev/null | grep -Pq "(?<=\"name\":\")$2") + $RBD --format json snap ls $1 2>/dev/null | grep -q "\"name\":\"$2\"" - if [ $? -eq 0 ]; then + if [ "$?" = "0" ]; then rbd_tgt=$1 else pool=$(echo $1 | cut -f1 -d'/') vol=$(echo $1 | cut -f2 -d'/') - rbd_tgt=$($RBD ls $pool | grep "$vol-[^-]*$2[^-]*") + rbd_tgt=$($RBD ls $pool | grep -E "$vol-(.+:)?$2(:|$)") if [ -z "${rbd_tgt}" ]; then echo "Could not find a volume with snapshot $2" >&2 @@ -125,7 +125,7 @@ rbd_top_parent() { pool=$(echo $1 | cut -f1 -d'/') volume=$(echo $1 | cut -f2 -d'/') - snap0=$($RBD ls -l $pool | grep "$volume.*@0") + snap0=$($RBD ls -l $pool | grep -E "$volume(-.+)?@0") if [ -n "$snap0" ]; then volume=$pool/${snap0%%@*} From 32b6267001358e942dd7a6e055d4f98a763a52b5 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 14 Oct 2015 16:57:52 +0200 Subject: [PATCH 07/10] feature #3362: Return error if RBD target not found --- src/datastore_mad/remotes/ceph/snap_delete | 5 +++++ src/datastore_mad/remotes/ceph/snap_flatten | 5 +++++ src/datastore_mad/remotes/ceph/snap_revert | 5 +++++ src/tm_mad/ceph/cpds | 6 ++++++ src/tm_mad/ceph/snap_delete | 5 +++++ src/tm_mad/ceph/snap_revert | 5 +++++ 6 files changed, 31 insertions(+) diff --git a/src/datastore_mad/remotes/ceph/snap_delete b/src/datastore_mad/remotes/ceph/snap_delete index 27c01cd8eb..e8486c084f 100755 --- a/src/datastore_mad/remotes/ceph/snap_delete +++ b/src/datastore_mad/remotes/ceph/snap_delete @@ -79,6 +79,11 @@ SNAP_DELETE_CMD=$(cat <&2 + exit 1 + fi + $RBD snap unprotect \${RBD_TGT}@$SNAP_ID $RBD snap rm \${RBD_TGT}@$SNAP_ID diff --git a/src/datastore_mad/remotes/ceph/snap_flatten b/src/datastore_mad/remotes/ceph/snap_flatten index 72ba22817e..0c10c30f44 100755 --- a/src/datastore_mad/remotes/ceph/snap_flatten +++ b/src/datastore_mad/remotes/ceph/snap_flatten @@ -79,6 +79,11 @@ SNAP_FLATTEN_CMD=$(cat <&2 + exit 1 + fi + $RBD clone \${RBD_TGT}@$SNAP_ID $RBD_SRC.flatten $RBD flatten $RBD_SRC.flatten diff --git a/src/datastore_mad/remotes/ceph/snap_revert b/src/datastore_mad/remotes/ceph/snap_revert index 6d515de07d..88f09ec3b2 100755 --- a/src/datastore_mad/remotes/ceph/snap_revert +++ b/src/datastore_mad/remotes/ceph/snap_revert @@ -81,6 +81,11 @@ SNAP_REVERT_CMD=$(cat <&2 + exit 1 + fi + $RBD clone \${RBD_TGT}@$SNAP_ID $RBD_SRC EOF ) diff --git a/src/tm_mad/ceph/cpds b/src/tm_mad/ceph/cpds index 323b9ee0e9..0f99bfeeba 100755 --- a/src/tm_mad/ceph/cpds +++ b/src/tm_mad/ceph/cpds @@ -96,6 +96,12 @@ COPY_CMD=$(cat <&2 + exit 1 + fi + RBD_DST=\$RBD_DST@$SNAP_ID fi diff --git a/src/tm_mad/ceph/snap_delete b/src/tm_mad/ceph/snap_delete index 37ccf56e36..bc86cf8145 100755 --- a/src/tm_mad/ceph/snap_delete +++ b/src/tm_mad/ceph/snap_delete @@ -92,6 +92,11 @@ SNAP_DELETE_CMD=$(cat <&2 + exit 1 + fi + $RBD snap unprotect \${RBD_TGT}@$SNAP_ID $RBD snap rm \${RBD_TGT}@$SNAP_ID diff --git a/src/tm_mad/ceph/snap_revert b/src/tm_mad/ceph/snap_revert index 77d46f0548..c771555a86 100755 --- a/src/tm_mad/ceph/snap_revert +++ b/src/tm_mad/ceph/snap_revert @@ -111,6 +111,11 @@ SNAP_REVERT_CMD=$(cat <&2 + exit 1 + fi + $RBD clone \${RBD_TGT}@$SNAP_ID $RBD_DST EOF ) From e87ace631008383c22d8d5efd72b5473276bb732 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 15 Oct 2015 17:06:25 +0200 Subject: [PATCH 08/10] feature #3362: Fix bug in finding the parent of an rbd --- src/datastore_mad/remotes/ceph/ceph_utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datastore_mad/remotes/ceph/ceph_utils.sh b/src/datastore_mad/remotes/ceph/ceph_utils.sh index 4336e05582..5e6ff6315a 100644 --- a/src/datastore_mad/remotes/ceph/ceph_utils.sh +++ b/src/datastore_mad/remotes/ceph/ceph_utils.sh @@ -125,7 +125,7 @@ rbd_top_parent() { pool=$(echo $1 | cut -f1 -d'/') volume=$(echo $1 | cut -f2 -d'/') - snap0=$($RBD ls -l $pool | grep -E "$volume(-.+)?@0") + snap0=$($RBD ls -l $pool | awk '{print $1}' | grep -E "$volume(-.+)?@0") if [ -n "$snap0" ]; then volume=$pool/${snap0%%@*} From 4bd40a051f99b71f0a63d37d9610ede17d496b2e Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 15 Oct 2015 17:06:53 +0200 Subject: [PATCH 09/10] feature #3362: Remove unnecessary snapshots in rbd schema --- src/datastore_mad/remotes/ceph/ceph_utils.sh | 10 +++++++--- src/tm_mad/ceph/delete | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/datastore_mad/remotes/ceph/ceph_utils.sh b/src/datastore_mad/remotes/ceph/ceph_utils.sh index 5e6ff6315a..b79d6bb467 100644 --- a/src/datastore_mad/remotes/ceph/ceph_utils.sh +++ b/src/datastore_mad/remotes/ceph/ceph_utils.sh @@ -32,14 +32,18 @@ rbd_make_snap() { #-------------------------------------------------------------------------------- # Remove the base @snap for image clones # @param $1 the volume +# @param $2 (Optional) the snapshot name. If empty it defaults to 'snap' #-------------------------------------------------------------------------------- rbd_rm_snap() { + local snap + snap=${2:-snap} + if [ "$(rbd_format $1)" = "2" ]; then - $RBD info "$1@snap" >/dev/null 2>&1 + $RBD info "$1@$snap" >/dev/null 2>&1 if [ "$?" = "0" ]; then - $RBD snap unprotect "$1@snap" - $RBD snap rm "$1@snap" + $RBD snap unprotect "$1@$snap" + $RBD snap rm "$1@$snap" fi fi } diff --git a/src/tm_mad/ceph/delete b/src/tm_mad/ceph/delete index f39874ef4c..bc8f29cbef 100755 --- a/src/tm_mad/ceph/delete +++ b/src/tm_mad/ceph/delete @@ -92,6 +92,7 @@ fi # cloned, so the name will be "/one---" RBD_SRC="${SRC}-${VM_ID}-${DISK_ID}" +RBD_SNAP="${VM_ID}-${DISK_ID}" #------------------------------------------------------------------------------- # Delete the device @@ -104,6 +105,7 @@ DELETE_CMD=$(cat < Date: Thu, 15 Oct 2015 17:41:11 +0200 Subject: [PATCH 10/10] feature #3362: Add configuration option for ceph: CEPH_CONF --- share/etc/oned.conf | 1 + src/datastore_mad/remotes/ceph/clone | 8 +++++++- src/datastore_mad/remotes/ceph/cp | 8 +++++++- src/datastore_mad/remotes/ceph/mkfs | 8 +++++++- src/datastore_mad/remotes/ceph/monitor | 9 ++++++++- src/datastore_mad/remotes/ceph/rm | 8 +++++++- src/datastore_mad/remotes/ceph/snap_delete | 8 +++++++- src/datastore_mad/remotes/ceph/snap_flatten | 8 +++++++- src/datastore_mad/remotes/ceph/snap_revert | 8 +++++++- src/tm_mad/ceph/clone | 6 ++++++ src/tm_mad/ceph/cpds | 8 +++++++- src/tm_mad/ceph/delete | 8 +++++++- src/tm_mad/ceph/ln | 8 +++++++- src/tm_mad/ceph/snap_create | 8 +++++++- src/tm_mad/ceph/snap_create_live | 8 +++++++- src/tm_mad/ceph/snap_delete | 8 +++++++- src/tm_mad/ceph/snap_revert | 8 +++++++- 17 files changed, 113 insertions(+), 15 deletions(-) diff --git a/share/etc/oned.conf b/share/etc/oned.conf index cb83ed0e98..1c8a82cc2e 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -840,6 +840,7 @@ VNET_RESTRICTED_ATTR = "AR/BRIDGE" INHERIT_DATASTORE_ATTR = "CEPH_HOST" INHERIT_DATASTORE_ATTR = "CEPH_SECRET" INHERIT_DATASTORE_ATTR = "CEPH_USER" +INHERIT_DATASTORE_ATTR = "CEPH_CONF" INHERIT_DATASTORE_ATTR = "GLUSTER_HOST" INHERIT_DATASTORE_ATTR = "GLUSTER_VOLUME" diff --git a/src/datastore_mad/remotes/ceph/clone b/src/datastore_mad/remotes/ceph/clone index db49dfeb79..8c6b1a70ff 100755 --- a/src/datastore_mad/remotes/ceph/clone +++ b/src/datastore_mad/remotes/ceph/clone @@ -50,7 +50,8 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RBD_FORMAT \ /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ /DS_DRIVER_ACTION_DATA/IMAGE/SIZE \ - /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER) + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_CONF) unset i @@ -61,6 +62,7 @@ RBD_FORMAT="${XPATH_ELEMENTS[i++]:-$RBD_FORMAT}" SRC="${XPATH_ELEMENTS[i++]}" SIZE="${XPATH_ELEMENTS[i++]}" CEPH_USER="${XPATH_ELEMENTS[i++]}" +CEPH_CONF="${XPATH_ELEMENTS[i++]}" DST_HOST=`get_destination_host $ID` @@ -69,6 +71,10 @@ if [ -z "$DST_HOST" ]; then exit -1 fi +if [ -n "$CEPH_CONF" ]; then + RBD="$RBD --conf ${CEPH_CONF}" +fi + if [ -n "$CEPH_USER" ]; then RBD="$RBD --id ${CEPH_USER}" fi diff --git a/src/datastore_mad/remotes/ceph/cp b/src/datastore_mad/remotes/ceph/cp index dd122f8238..58143e38b5 100755 --- a/src/datastore_mad/remotes/ceph/cp +++ b/src/datastore_mad/remotes/ceph/cp @@ -61,7 +61,8 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ /DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1 \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/NO_DECOMPRESS \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LIMIT_TRANSFER_BW \ - /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER) + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_CONF) unset i @@ -79,6 +80,7 @@ SHA1="${XPATH_ELEMENTS[i++]}" NO_DECOMPRESS="${XPATH_ELEMENTS[i++]}" LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[i++]}" CEPH_USER="${XPATH_ELEMENTS[i++]}" +CEPH_CONF="${XPATH_ELEMENTS[i++]}" DST_HOST=`get_destination_host $ID` @@ -91,6 +93,10 @@ if [ -n "$CEPH_USER" ]; then RBD="$RBD --id ${CEPH_USER}" fi +if [ -n "$CEPH_CONF" ]; then + RBD="$RBD --conf ${CEPH_CONF}" +fi + set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" IMAGE_HASH=`generate_image_hash` diff --git a/src/datastore_mad/remotes/ceph/mkfs b/src/datastore_mad/remotes/ceph/mkfs index 047d2ab5fb..ba6cfa0709 100755 --- a/src/datastore_mad/remotes/ceph/mkfs +++ b/src/datastore_mad/remotes/ceph/mkfs @@ -55,7 +55,8 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RBD_FORMAT \ /DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \ /DS_DRIVER_ACTION_DATA/IMAGE/SIZE \ - /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER) + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_CONF) unset i @@ -69,6 +70,7 @@ RBD_FORMAT="${XPATH_ELEMENTS[i++]:-$RBD_FORMAT}" FSTYPE="${XPATH_ELEMENTS[i++]}" SIZE="${XPATH_ELEMENTS[i++]}" CEPH_USER="${XPATH_ELEMENTS[i++]}" +CEPH_CONF="${XPATH_ELEMENTS[i++]}" DST_HOST=`get_destination_host $ID` @@ -81,6 +83,10 @@ if [ -n "$CEPH_USER" ]; then RBD="$RBD --id ${CEPH_USER}" fi +if [ -n "$CEPH_CONF" ]; then + RBD="$RBD --conf ${CEPH_CONF}" +fi + set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" IMAGE_HASH=`generate_image_hash` diff --git a/src/datastore_mad/remotes/ceph/monitor b/src/datastore_mad/remotes/ceph/monitor index 02a22c2aba..9915197ec9 100755 --- a/src/datastore_mad/remotes/ceph/monitor +++ b/src/datastore_mad/remotes/ceph/monitor @@ -47,11 +47,13 @@ while IFS= read -r -d '' element; do XPATH_ELEMENTS[i++]="$element" done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \ - /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER) + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_CONF) BRIDGE_LIST="${XPATH_ELEMENTS[j++]}" POOL_NAME="${XPATH_ELEMENTS[j++]:-$POOL_NAME}" CEPH_USER="${XPATH_ELEMENTS[j++]}" +CEPH_CONF="${XPATH_ELEMENTS[j++]}" HOST=`get_destination_host` @@ -64,6 +66,11 @@ if [ -n "$CEPH_USER" ]; then CEPH="$CEPH --id ${CEPH_USER}" fi +if [ -n "$CEPH_CONF" ]; then + CEPH="$CEPH --conf ${CEPH_CONF}" + RADOS="$RADOS --conf ${CEPH_CONF}" +fi + # ------------ Compute datastore usage ------------- MONITOR_SCRIPT=$(cat </one---" RBD_SRC="${SRC}-${VM_ID}-${DISK_ID}" RBD_SNAP="${VM_ID}-${DISK_ID}" diff --git a/src/tm_mad/ceph/ln b/src/tm_mad/ceph/ln index 825fe263a4..3ae97f2382 100755 --- a/src/tm_mad/ceph/ln +++ b/src/tm_mad/ceph/ln @@ -64,9 +64,11 @@ unset i j XPATH_ELEMENTS while IFS= read -r -d '' element; do XPATH_ELEMENTS[i++]="$element" done < <(onevm show -x $VM_ID| $XPATH \ - /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_USER) + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_USER \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_CONF) CEPH_USER="${XPATH_ELEMENTS[j++]}" +CEPH_CONF="${XPATH_ELEMENTS[j++]}" #------------------------------------------------------------------------------- # Remove any @snap in image (non persistent -> persistnet) @@ -76,6 +78,10 @@ if [ -n "$CEPH_USER" ]; then RBD="$RBD --id ${CEPH_USER}" fi +if [ -n "$CEPH_CONF" ]; then + RBD="$RBD --conf ${CEPH_CONF}" +fi + CLONE_CMD=$(cat <