1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-21 13:57:56 +03:00

B #6207: tm_mad ceph: fix delete, ln, flatt. trash (#2607)

When cloned rbd is moved to the CEPH_TRASH, the
clone snapshot (@snap) could not be deleted which
can lead to data loss when switching the image to
persistent and back. Flattening rbd before moving
to trash should fix it.
This commit is contained in:
Jan Orel 2023-05-17 11:36:47 +02:00 committed by GitHub
parent b0db9f9832
commit 420cd10c50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -167,7 +167,11 @@ rbd_top_parent() {
#--------------------------------------------------------------------------------
# Remove all the images and snapshots from a given volume
# if $2 is yes/true the rbd volume is moved to ceph
# trash instead, before that it is flattend
#
# @param $1 the volume (or snapshot to delete)
# @param $2 [yes|no] if move img to ceph trash instead
#--------------------------------------------------------------------------------
rbd_rm_r() {
local rbd rbd_base children snaps
@ -187,6 +191,7 @@ rbd_rm_r() {
$RBD snap rm $rbd
else
if [[ $move_to_trash =~ ^(yes|YES|true|TRUE)$ ]]; then
$RBD flatten $rbd
$RBD trash move $rbd
else
snaps=$($RBD snap ls $rbd 2>/dev/null| awk 'NR > 1 {print $2}')

View File

@ -171,11 +171,9 @@ fi
if [ -n "$SRC" ]; then
# cloned, so the name will be "<pool>/one-<imageid>-<vmid>-<diskid>"
RBD_SRC="${SRC}-${VM_ID}-${DISK_ID}"
RBD_SNAP="${VM_ID}-${DISK_ID}"
else
# volatile
RBD_SRC="${POOL_NAME}/one-sys-${VM_ID}-${DISK_ID}"
RBD_SNAP=""
fi
#-------------------------------------------------------------------------------
@ -190,8 +188,8 @@ DELETE_CMD=$(cat <<EOF
if [ "\$(rbd_format $RBD_SRC)" = "2" ]; then
rbd_rm_r \$(rbd_top_parent $RBD_SRC) "$CEPH_MOVE_TO_TRASH"
if [ -n "$RBD_SNAP" ]; then
rbd_rm_snap $SRC $RBD_SNAP
if [ -n "$SRC" ]; then
rbd_rm_snap $SRC ||: # delete the snap if not used
fi
else
$RBD $RM_CMD $RBD_SRC

View File

@ -88,10 +88,13 @@ if [ -n "$CEPH_CONF" ]; then
RBD="$RBD --conf ${CEPH_CONF}"
fi
# snapshot delete is mandatory as it could lead to data loss after
# persitent/nonpersistent image switch
LN_CMD=$(cat <<EOF
RBD="${RBD}"
rbd_rm_snap $SRC_PATH ||:
rbd_rm_snap $SRC_PATH
EOF
)