diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 9c73da315a8..264a6a9bce1 100755 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -2271,24 +2271,59 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe throw new CloudRuntimeException(results); } } + + boolean killCopyProcess(Connection conn, String nameLabel) { + String results = callHostPluginAsync(conn, "vmops", "kill_copy_process", + 60, "namelabel", nameLabel); + String errMsg = null; + if (results == null || results.equals("false")) { + errMsg = "kill_copy_process failed"; + s_logger.warn(errMsg); + return false; + } else { + return true; + } + } + + void destroyVDIbyNameLabel(Connection conn, String nameLabel) { + try { + Set vdis = VDI.getByNameLabel(conn, nameLabel); + if ( vdis.size() != 1 ) { + s_logger.warn("destoryVDIbyNameLabel failed due to there are " + vdis.size() + " VDIs with name " + nameLabel); + return; + } + for (VDI vdi : vdis) { + try { + vdi.destroy(conn); + } catch (Exception e) { + } + } + } catch (Exception e){ + } + } String copy_vhd_from_secondarystorage(Connection conn, String mountpoint, String sruuid, int wait) { + String nameLabel = "cloud-" + UUID.randomUUID().toString(); String results = callHostPluginAsync(conn, "vmopspremium", "copy_vhd_from_secondarystorage", - wait, "mountpoint", mountpoint, "sruuid", sruuid); - + wait, "mountpoint", mountpoint, "sruuid", sruuid, "namelabel", nameLabel); + String errMsg = null; if (results == null || results.isEmpty()) { - String msg = "copy_vhd_from_secondarystorage return null"; - s_logger.warn(msg); - throw new CloudRuntimeException(msg); - } - String[] tmp = results.split("#"); - String status = tmp[0]; - if (status.equals("0")) { - return tmp[1]; + errMsg = "copy_vhd_from_secondarystorage return null"; } else { - s_logger.warn(tmp[1]); - throw new CloudRuntimeException(tmp[1]); + String[] tmp = results.split("#"); + String status = tmp[0]; + if (status.equals("0")) { + return tmp[1]; + } else { + errMsg = tmp[1]; + } } + String source = mountpoint.substring(mountpoint.lastIndexOf('/') + 1); + if( killCopyProcess(conn, source) ) { + destroyVDIbyNameLabel(conn, nameLabel); + } + s_logger.warn(errMsg); + throw new CloudRuntimeException(errMsg); } public PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) { @@ -3102,6 +3137,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } finally { if (task != null) { try { + task.cancel(conn); task.destroy(conn); } catch (Exception e1) { s_logger.warn("unable to destroy task(" + task.toString() + ") on host(" + _host.uuid + ") due to ", e1); diff --git a/scripts/vm/hypervisor/xenserver/copy_vhd_from_secondarystorage.sh b/scripts/vm/hypervisor/xenserver/copy_vhd_from_secondarystorage.sh index 1aca2790340..ef0795cae51 100755 --- a/scripts/vm/hypervisor/xenserver/copy_vhd_from_secondarystorage.sh +++ b/scripts/vm/hypervisor/xenserver/copy_vhd_from_secondarystorage.sh @@ -4,7 +4,7 @@ #set -x usage() { - printf "Usage: %s [vhd file in secondary storage] [uuid of the source sr] \n" $(basename $0) + printf "Usage: %s [vhd file in secondary storage] [uuid of the source sr] [name label] \n" $(basename $0) } cleanup() @@ -40,6 +40,14 @@ if [ $? -ne 0 ]; then exit 0 fi +if [ -z $3 ]; then + usage + echo "3#no namelabel" + exit 0 +else + namelabel=$3 +fi + localmp=/var/run/cloud_mount/$(uuidgen -r) mkdir -p $localmp @@ -107,31 +115,20 @@ copyvhd() fi } +size=$($VHDUTIL query -v -n $vhdfile) +uuid=$(xe vdi-create sr-uuid=$sruuid virtual-size=${size}MiB type=user name-label=$namelabel) +if [ $? -ne 0 ]; then + echo "9#can not create vdi in sr $sruuid" + cleanup + exit 0 +fi + + if [ $type == "nfs" -o $type == "ext" ]; then - uuid=$(uuidgen -r) - desvhd=/var/run/sr-mount/$sruuid/$uuid + desvhd=/var/run/sr-mount/$sruuid/$uuid.vhd copyvhd $desvhd $vhdfile 0 $type - $VHDUTIL set -n $desvhd -f "hidden" -v "0" > /dev/null - if [ $? -ne 0 ]; then - echo "21#failed to set hidden to 0 $desvhd" - cleanup - exit 0 - fi - 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=$($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" - cleanup - exit 0 - fi lvsize=$(xe vdi-param-get uuid=$uuid param-name=physical-utilisation) if [ $? -ne 0 ]; then echo "12#failed to get physical size of vdi $uuid" @@ -146,24 +143,25 @@ elif [ $type == "lvmoiscsi" -o $type == "lvm" -o $type == "lvmohba" ]; then exit 0 fi copyvhd $desvhd $vhdfile $lvsize $type - $VHDUTIL set -n $desvhd -f "hidden" -v "0" > /dev/null - if [ $? -ne 0 ]; then - echo "22#failed to set hidden to 0 $desvhd" - cleanup - exit 0 - fi - xe sr-scan uuid=$sruuid - if [ $? -ne 0 ]; then - echo "14#failed to scan sr $sruuid" - cleanup - exit 0 - fi else echo "15#doesn't support sr type $type" cleanup exit 0 fi +$VHDUTIL set -n $desvhd -f "hidden" -v "0" > /dev/null +if [ $? -ne 0 ]; then + echo "21#failed to set hidden to 0 $desvhd" + cleanup + exit 0 +fi +xe sr-scan uuid=$sruuid +if [ $? -ne 0 ]; then + echo "14#failed to scan sr $sruuid" + cleanup + exit 0 +fi + echo "0#$uuid" cleanup exit 0 diff --git a/scripts/vm/hypervisor/xenserver/kill_copy_process.sh b/scripts/vm/hypervisor/xenserver/kill_copy_process.sh new file mode 100755 index 00000000000..e36b22cb427 --- /dev/null +++ b/scripts/vm/hypervisor/xenserver/kill_copy_process.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Version @VERSION@ + +#set -x + +usage() { + printf "Usage: %s [name label] \n" $(basename $0) +} + +if [ -z $1 ]; then + usage + echo "3#no namelabel" + exit 0 +else + namelabel=$1 +fi + +pid=`ps -ef | grep "dd" | grep $namelabel | grep -v "grep" | awk '{print $2}'` +if [ -z $pid ]; then + echo "true" + exit 0 +fi + +kill -9 $pid +if [ $? -ne 0 ]; then + echo "false" + exit 0 +fi +echo "true" +exit 0 diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index addc314deea..cd06152854e 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -124,6 +124,16 @@ def pingdomr(session, args): return txt +@echo +def kill_copy_process(session, args): + namelabel = args['namelabel'] + try: + cmd = ["bash", "/opt/xensource/bin/kill_copy_process.sh", namelabel] + txt = util.pread2(cmd) + except: + txt = 'false' + return txt + @echo def pingxenserver(session, args): txt = 'success' @@ -1428,4 +1438,5 @@ if __name__ == "__main__": "get_rule_logs_for_vms":get_rule_logs_for_vms, "setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn, "cleanup_rules":cleanup_rules, "checkRouter":checkRouter, - "bumpUpPriority":bumpUpPriority, "getDomRVersion":getDomRVersion }) + "bumpUpPriority":bumpUpPriority, "getDomRVersion":getDomRVersion, + "kill_copy_process":kill_copy_process}) diff --git a/scripts/vm/hypervisor/xenserver/vmopspremium b/scripts/vm/hypervisor/xenserver/vmopspremium index 07f2a6007ee..f305a5a27d5 100755 --- a/scripts/vm/hypervisor/xenserver/vmopspremium +++ b/scripts/vm/hypervisor/xenserver/vmopspremium @@ -67,8 +67,9 @@ def copy_vhd_to_secondarystorage(session, args): def copy_vhd_from_secondarystorage(session, args): mountpoint = args['mountpoint'] sruuid = args['sruuid'] + namelabel = args['namelabel'] try: - cmd = ["bash", "/opt/xensource/bin/copy_vhd_from_secondarystorage.sh", mountpoint, sruuid] + cmd = ["bash", "/opt/xensource/bin/copy_vhd_from_secondarystorage.sh", mountpoint, sruuid, namelabel] txt = util.pread2(cmd) except: txt = '10#failed' diff --git a/scripts/vm/hypervisor/xenserver/xenserver56/patch b/scripts/vm/hypervisor/xenserver/xenserver56/patch index 8f1f4e04f30..20f622778a7 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56/patch @@ -31,6 +31,7 @@ call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin +kill_copy_process.sh=..,0755,/opt/xensource/bin setup_heartbeat_sr.sh=..,0755,/opt/xensource/bin setup_heartbeat_file.sh=..,0755,/opt/xensource/bin check_heartbeat.sh=..,0755,/opt/xensource/bin diff --git a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch index 3283ee87b03..a3c1f91e319 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch @@ -33,6 +33,7 @@ l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin cloud-setup-bonding.sh=..,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin +kill_copy_process.sh=..,0755,/opt/xensource/bin setup_heartbeat_sr.sh=..,0755,/opt/xensource/bin setup_heartbeat_file.sh=..,0755,/opt/xensource/bin check_heartbeat.sh=..,0755,/opt/xensource/bin diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch index 3283ee87b03..a3c1f91e319 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver60/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch @@ -33,6 +33,7 @@ l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin cloud-setup-bonding.sh=..,0755,/opt/xensource/bin copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin +kill_copy_process.sh=..,0755,/opt/xensource/bin setup_heartbeat_sr.sh=..,0755,/opt/xensource/bin setup_heartbeat_file.sh=..,0755,/opt/xensource/bin check_heartbeat.sh=..,0755,/opt/xensource/bin