1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-10 01:17:40 +03:00

Ceph: better management of RBD_FORMAT parameter. Default is RBD_FORMAT 2

This commit is contained in:
Ruben S. Montero 2014-07-08 11:00:39 +02:00
parent 95ce712797
commit ccc47d6534
11 changed files with 38 additions and 51 deletions

View File

@ -693,7 +693,6 @@ IMAGE_RESTRICTED_ATTR = "SOURCE"
INHERIT_DATASTORE_ATTR = "CEPH_HOST"
INHERIT_DATASTORE_ATTR = "CEPH_SECRET"
INHERIT_DATASTORE_ATTR = "CEPH_USER"
INHERIT_DATASTORE_ATTR = "RBD_FORMAT"
INHERIT_DATASTORE_ATTR = "GLUSTER_HOST"
INHERIT_DATASTORE_ATTR = "GLUSTER_VOLUME"

View File

@ -698,7 +698,6 @@ IMAGE_RESTRICTED_ATTR = "SOURCE"
INHERIT_DATASTORE_ATTR = "CEPH_HOST"
INHERIT_DATASTORE_ATTR = "CEPH_SECRET"
INHERIT_DATASTORE_ATTR = "CEPH_USER"
INHERIT_DATASTORE_ATTR = "RBD_FORMAT"
INHERIT_DATASTORE_ATTR = "GLUSTER_HOST"
INHERIT_DATASTORE_ATTR = "GLUSTER_VOLUME"

View File

@ -27,9 +27,4 @@ STAGING_DIR=/var/tmp
# following options to enable support for RBD 2. This value affects all the ceph
# datastores, however it can be enabled per ceph datastore using the same
# option in the datastore template
# RBD_FORMAT=2
# Extra arguments send to "qemu-img convert". Depending on the qemu-img version
# it using "-O rbd" can be either recommended or may cause segfaults. Uncomment
# the following line to add "-O rbd" to the qemu-img convert command
# QEMU_IMG_CONVERT_ARGS="-O rbd"
RBD_FORMAT=2

View File

@ -71,6 +71,6 @@ IMAGE_NAME="one-${ID}"
RBD_DST="${POOL_NAME}/${IMAGE_NAME}"
ssh_exec_and_log "$DST_HOST" "$RBD copy $SRC $RBD_DST" \
"Error cloning $SRC to $RBD_DST in $DST_HOST"
"Error cloning $SRC to $RBD_DST in $DST_HOST"
echo "$RBD_DST"

View File

@ -118,24 +118,24 @@ http://*|https://*)
esac
exec_and_log "eval $DUMP | $SSH $DST_HOST $DD of=$TMP_DST bs=64k" \
"Error dumping $SRC to $DST_HOST:$TMP_DST"
"Error dumping $SRC to $DST_HOST:$TMP_DST"
if [ "$RBD_FORMAT" = "2" ]; then
FORMAT_OPT="--image-format 2"
fi
REGISTER_CMD=$(cat <<EOF
set -e
if [ "$RBD_FORMAT" = "2" ]; then
FORMAT=\$($QEMU_IMG info $TMP_DST | grep "^file format:" | awk '{print $3}')
FORMAT=\$($QEMU_IMG info $TMP_DST | grep "^file format:" | awk '{print $3}')
if [ "\$FORMAT" != "raw" ]; then
$QEMU_IMG convert -O raw $TMP_DST $TMP_DST.raw
mv $TMP_DST.raw $TMP_DST
fi
$RBD import --format 2 $TMP_DST $RBD_SOURCE
else
$QEMU_IMG convert $QEMU_IMG_CONVERT_ARGS $TMP_DST rbd:$RBD_SOURCE
if [ "\$FORMAT" != "raw" ]; then
$QEMU_IMG convert -O raw $TMP_DST $TMP_DST.raw
mv $TMP_DST.raw $TMP_DST
fi
$RBD import $FORMAT_OPT $TMP_DST $RBD_SOURCE
# remove original
$RM -f $TMP_DST
EOF

View File

@ -52,6 +52,7 @@ 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/STAGING_DIR \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RBD_FORMAT \
/DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE)
@ -63,6 +64,7 @@ SAFE_DIRS="${XPATH_ELEMENTS[i++]}"
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
POOL_NAME="${XPATH_ELEMENTS[i++]:-$POOL_NAME}"
STAGING_DIR="${XPATH_ELEMENTS[i++]:-$STAGING_DIR}"
RBD_FORMAT="${XPATH_ELEMENTS[i++]:-$RBD_FORMAT}"
FSTYPE="${XPATH_ELEMENTS[i++]}"
SIZE="${XPATH_ELEMENTS[i++]}"

View File

@ -57,9 +57,10 @@ if [ -z "$DST_HOST" ]; then
exit -1
fi
# -------- Remove Image from Datastore ------------
log "Removing $SRC from the rbd image repository in $DST_HOST"
ssh_exec_and_log "$DST_HOST" "$RBD rm $SRC" \
"Error removing $SRC in $DST_HOST"
ssh_exec_and_log "$DST_HOST" "$RBD rm $SRC" "Error removing $SRC in $DST_HOST"
exit 0

View File

@ -49,21 +49,6 @@ DISK_ID=$(echo $DST|awk -F. '{print $NF}')
RBD_DST="${SRC_PATH}-${VM_ID}-${DISK_ID}"
RBD_SNAP="${VM_ID}-${DISK_ID}"
#-------------------------------------------------------------------------------
# Get Image information
#-------------------------------------------------------------------------------
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 $VM_ID| $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/RBD_FORMAT)
RBD_FORMAT="${XPATH_ELEMENTS[j++]}"
#-------------------------------------------------------------------------------
# Clone the image
#-------------------------------------------------------------------------------
@ -71,7 +56,9 @@ RBD_FORMAT="${XPATH_ELEMENTS[j++]}"
CLONE_CMD=$(cat <<EOF
set -e
if [ "$RBD_FORMAT" = "2" ]; then
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
@ -82,5 +69,5 @@ EOF
)
ssh_exec_and_log "$DST_HOST" "$CLONE_CMD" \
"Error cloning $SRC_PATH to $RBD_DST in $DST_HOST"
"Error cloning $SRC_PATH to $RBD_DST in $DST_HOST"
exit 0

View File

@ -64,6 +64,10 @@ done < <(onevm show -x $VM_ID| $XPATH \
RBD_SRC="${XPATH_ELEMENTS[j++]}"
PERSISTENT="${XPATH_ELEMENTS[j++]}"
#-------------------------------------------------------------------------------
# Copy Image back to the datastore
#-------------------------------------------------------------------------------
if [ "$PERSISTENT" = "YES" ]; then
RBD_DST="${RBD_SRC}"
else
@ -71,6 +75,6 @@ else
fi
ssh_exec_and_log "$SRC_HOST" "$RBD copy $RBD_DST $DST" \
"Error cloning $RBD_DST to $DST in $DST_HOST"
"Error cloning $RBD_DST to $DST in $SRC_HOST"
exit 0

View File

@ -67,12 +67,10 @@ 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]/SOURCE \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/RBD_FORMAT)
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT)
SRC="${XPATH_ELEMENTS[j++]}"
PERSISTENT="${XPATH_ELEMENTS[j++]}"
RBD_FORMAT="${XPATH_ELEMENTS[j++]}"
# Exit if persistent
[ -n "$PERSISTENT" ] && exit 0
@ -93,9 +91,11 @@ log "Deleting $DST_PATH"
DELETE_CMD=$(cat <<EOF
set -e
RBD_FORMAT=`rbd info $SRC_PATH | sed -n 's/.*format: // p'`
$RBD rm $RBD_SRC
if [ "$RBD_FORMAT" = "2" ]; then
if [ "\$RBD_FORMAT" = "2" ]; then
$RBD snap unprotect $SRC@$RBD_SNAP
$RBD snap rm $SRC@$RBD_SNAP
fi
@ -103,6 +103,6 @@ EOF
)
ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" \
"Error deleting $RBD_SRC in $DST_HOST"
"Error deleting $RBD_SRC in $DST_HOST"
exit 0

View File

@ -59,12 +59,10 @@ 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]/SOURCE \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/RBD_FORMAT)
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT)
RBD_SRC="${XPATH_ELEMENTS[j++]}"
PERSISTENT="${XPATH_ELEMENTS[j++]}"
RBD_FORMAT="${XPATH_ELEMENTS[j++]}"
# Exit if persistent
[ -n "$PERSISTENT" ] && exit 0
@ -82,7 +80,9 @@ log "Dumping $RBD_DST to $DST"
DUMP_CMD=$(cat <<EOF
set -e
if [ "$RBD_FORMAT" = "2" ]; then
RBD_FORMAT=`rbd info $SRC_PATH | sed -n 's/.*format: // p'`
if [ "\$RBD_FORMAT" = "2" ]; then
$RBD flatten $RBD_DST
$RBD snap unprotect $RBD_SRC@$RBD_SNAP
$RBD snap rm $RBD_SRC@$RBD_SNAP
@ -92,7 +92,7 @@ DUMP_CMD=$(cat <<EOF
EOF
)
ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" \
"Error saving $RBD_DST as $DST in $SRC_HOST"
ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" \
"Error saving $RBD_DST as $DST in $SRC_HOST"
exit 0