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

Merge branch 'bug-1521'

This commit is contained in:
Ruben S. Montero 2013-02-20 13:06:34 +01:00
commit 00b664dc8d
4 changed files with 25 additions and 14 deletions

View File

@ -28,6 +28,7 @@ GREP=grep
ISCSIADM=iscsiadm
LVCREATE=lvcreate
LVREMOVE=lvremove
LVRENAME=lvrename
LVS=lvs
LN=ln
MD5SUM=md5sum

View File

@ -69,8 +69,8 @@ LV_NAME=`echo $SRC_PATH|cut -d. -f2`
VG_NAME=`echo $SRC_PATH|cut -d. -f1`
TARGET_DEV="/dev/$VG_NAME/$LV_NAME"
LV_SNAPSHOT="$LV_NAME-$VM_ID-$DISK_ID"
LV_SNAPSHOT_DEV="/dev/$VG_NAME/$LV_SNAPSHOT"
LV_CLONE="$LV_NAME-$VM_ID-$DISK_ID"
LV_CLONE_DEV="/dev/$VG_NAME/$LV_CLONE"
#-------------------------------------------------------------------------------
# Create the snapshot and link it
@ -79,11 +79,12 @@ LV_SNAPSHOT_DEV="/dev/$VG_NAME/$LV_SNAPSHOT"
CLONE_CMD=$(cat <<EOF
set -e
mkdir -p $DST_DIR
$SUDO $LVCREATE -s -L$SIZE -n $LV_SNAPSHOT $TARGET_DEV
ln -s "$LV_SNAPSHOT_DEV" "$DST_PATH"
$SUDO $LVCREATE -L$SIZE -n $LV_CLONE $VG_NAME
$SUDO $DD if=$TARGET_DEV of=$LV_CLONE_DEV bs=64k
ln -s "$LV_CLONE_DEV" "$DST_PATH"
EOF
)
ssh_exec_and_log "$DST_HOST" "$CLONE_CMD" \
"Error cloning $TARGET_DEV to $LV_SNAPSHOT_DEV"
"Error cloning $TARGET_DEV to $LV_CLONE_DEV"
exit 0

View File

@ -42,10 +42,22 @@ DST_HOST=`arg_host $DST`
# Delete the device if it's a clone (LVM snapshot)
DELETE_CMD=$(cat <<EOF
DEV=\$(readlink $DST_PATH)
$SUDO $LVREMOVE -f \$DEV
LV_NAME=\$(basename \$DEV)
# remove link
rm -f $DST_PATH
# The following attrs will only be there if the image is non-persistent
# lv-one-<image> ==> persistent
# lv-one-<image>-<vmid>-<diskid> ==> non-persistent (clone)
VMID=\$(echo \$LV_NAME|cut -d- -f4)
DISKID=\$(echo \$LV_NAME|cut -d- -f5)
if [ -n "\$VMID" -a -n "\$DISKID" ]; then
# this is a cloned image
$SUDO $LVREMOVE -f \$DEV
fi
EOF
)

View File

@ -33,7 +33,10 @@ else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
fi
. $TMCOMMON
DRIVER_PATH=$(dirname $0)
source $TMCOMMON
source ${DRIVER_PATH}/../../datastore/lvm/lvm.conf
#-------------------------------------------------------------------------------
# Set dst path and dir
@ -55,14 +58,8 @@ DUMP_CMD=$(cat <<EOF
VM=\$(echo \$LV|cut -d- -f4)
DISK_ID=\$(echo \$LV|cut -d- -f5)
SOURCE_DEV=\$(echo \$DEV|sed 's/-[0-9]*-[0-9]*$//')
SIZE=\$($SUDO $LVS \$SOURCE_DEV --noheadings|awk '{print \$4}'|tr -d m)
$SUDO $LVCREATE -L\${SIZE}M ${VG_NAME} -n ${LV_NAME}
$SUDO $DD if=$SRC_PATH of=$TARGET_DEV bs=64k
if [ -n "\$VM" -a -n "\$DISK_ID" ]; then
$SUDO $LVREMOVE -f \$DEV
$SUDO $LVRENAME ${VG_NAME} \${LV} ${LV_NAME}
fi
EOF
)