copy_vhd_from_secondarystorage implement coalesce

This commit is contained in:
anthony 2011-03-04 17:36:08 -08:00
parent 79dacfacb5
commit e01ca05208
4 changed files with 58 additions and 33 deletions

View File

@ -3,7 +3,7 @@
#set -x
usage() {
printf "Usage: %s [mountpoint in secondary storage] [uuid of the source sr]\n" $(basename $0)
printf "Usage: %s [vhd file in secondary storage] [uuid of the source sr] \n" $(basename $0)
}
cleanup()
@ -21,7 +21,8 @@ if [ -z $1 ]; then
echo "2#no mountpoint"
exit 0
else
mountpoint=$1
mountpoint=${1%/*}
vhdfilename=${1##*/}
fi
if [ -z $2 ]; then
@ -52,25 +53,61 @@ if [ $? -ne 0 ]; then
exit 0
fi
vhdfile=$(ls $localmp/*.vhd)
if [ $? -ne 0 ]; then
echo "7#There is no vhd file under $mountpoint"
cleanup
exit 0
fi
vhdfile=$localmp/$vhdfilename
if [ $type == "nfs" ]; then
uuid=$(uuidgen -r)
dd if=$vhdfile of=/var/run/sr-mount/$sruuid/$uuid bs=2M
VHDUTIL="/opt/xensource/bin/vhd-util"
copyvhd()
{
local desvhd=$1
local srcvhd=$2
local vsize=$3
local type=$4
local parent=`$VHDUTIL query -p -n $srcvhd`
if [ $? -ne 0 ]; then
echo "8#failed ot copy vhdfile to /var/run/sr-mount/sruuid/$uuid"
echo "30#failed to query $srcvhd"
cleanup
exit 0
fi
if [ "${parent##*vhd has}" = " no parent" ]; then
dd if=$srcvhd of=$desvhd bs=2M
if [ $? -ne 0 ]; then
echo "31#failed to dd $srcvhd to $desvhd"
cleanup
exit 0
fi
if [ $type != "nfs" ]; then
$VHDUTIL modify -s $vsize -n $desvhd
if [ $? -ne 0 ]; then
echo "32#failed to set new vhd physical size for vdi vdi $uuid"
cleanup
exit 0
fi
fi
else
copyvhd $desvhd $parent $vsize $type
$VHDUTIL coalesce -p $desvhd -n $srcvhd
if [ $? -ne 0 ]; then
echo "32#failed to coalesce $desvhd to $srcvhd"
cleanup
exit 0
fi
fi
}
if [ $type == "nfs" ]; then
uuid=$(uuidgen -r)
desvhd=/var/run/sr-mount/$sruuid/$uuid
copyvhd $desvhd $vhdfile 0 $type
mv /var/run/sr-mount/$sruuid/$uuid /var/run/sr-mount/$sruuid/${uuid}.vhd
xe sr-scan uuid=$sruuid
if [ $? -ne 0 ]; then
echo "14#failed to scan sr $sruuid"
cleanup
exit 0
fi
elif [ $type == "lvmoiscsi" -o $type == "lvm" -o $type == "lvmohba" ]; then
size=$(vhd-util query -v -n $vhdfile)
size=$($VHDUTIL query -v -n $vhdfile)
uuid=$(xe vdi-create sr-uuid=$sruuid virtual-size=${size}MiB type=user name-label="cloud")
if [ $? -ne 0 ]; then
echo "9#can not create vdi in sr $sruuid"
@ -83,24 +120,14 @@ elif [ $type == "lvmoiscsi" -o $type == "lvm" -o $type == "lvmohba" ]; then
cleanup
exit 0
fi
lvchange -ay /dev/VG_XenStorage-$sruuid/VHD-$uuid
desvhd=/dev/VG_XenStorage-$sruuid/VHD-$uuid
lvchange -ay $desvhd
if [ $? -ne 0 ]; then
echo "10#lvm can not make VDI $uuid visiable"
cleanup
exit 0
fi
dd if=$vhdfile of=/dev/VG_XenStorage-$sruuid/VHD-$uuid bs=2M
if [ $? -ne 0 ]; then
echo "11#failed to dd to sr $sruuid"
cleanup
exit 0
fi
vhd-util modify -s $lvsize -n /dev/VG_XenStorage-$sruuid/VHD-$uuid
if [ $? -ne 0 ]; then
echo "13#failed to set new vhd physical size for vdi vdi $uuid"
cleanup
exit 0
fi
copyvhd $desvhd $vhdfile $lvsize $type
xe sr-scan uuid=$sruuid
if [ $? -ne 0 ]; then
echo "14#failed to scan sr $sruuid"

View File

@ -8,7 +8,6 @@ SUBDIRS-y :=
SUBDIRS-y += include
SUBDIRS-y += lvm
SUBDIRS-y += vhd
SUBDIRS-y += drivers
clean:
rm -rf *.a *.so *.o *.rpm $(LIB) *~ $(DEPS) TAGS

View File

@ -21,7 +21,7 @@ ifeq ($(VHD_STATIC),y)
CFLAGS += -static
endif
LIBS := -Llib -lvhd
LIBS := -Llib
ifeq ($(CONFIG_Linux),y)
LIBS += -luuid
endif
@ -34,14 +34,14 @@ all: subdirs-all build
build: $(IBIN)
LIBS_DEPENDS := lib/libvhd.so lib/vhd.a
LIBS_DEPENDS := lib/libvhd.a
$(LIBS_DEPENDS):subdirs-all
vhd-util: vhd-util.o $(LIBS_DEPENDS)
$(CC) $(CFLAGS) -o vhd-util vhd-util.o $(LDFLAGS) $(LIBS)
$(CC) $(CFLAGS) -o vhd-util vhd-util.o $(LIBS_DEPENDS) $(LDFLAGS) $(LIBS)
vhd-update: vhd-update.o $(LIBS_DEPENDS)
$(CC) $(CFLAGS) -o vhd-update vhd-update.o $(LDFLAGS) $(LIBS)
$(CC) $(CFLAGS) -o vhd-update vhd-update.o $(LIBS_DEPENDS) $(LDFLAGS) $(LIBS)
install: all
$(MAKE) subdirs-install

View File

@ -131,10 +131,9 @@ vhd_util_coalesce(int argc, char **argv)
char *name, *pname;
vhd_context_t vhd, parent;
int parent_fd = -1;
int pflag = 0;
name = NULL;
pname = NULL;
int pflag = 0;
parent.file = NULL;
if (!argc || !argv)