diff -r 20d1a79ebe31 tools/examples/block-common.sh --- a/tools/examples/block-common.sh Wed Oct 26 15:59:13 2005 +++ b/tools/examples/block-common.sh Thu Oct 27 20:15:02 2005 @@ -42,10 +42,17 @@ local major local minor local pdev - + major=$(stat -L -c %t "$1") minor=$(stat -L -c %T "$1") + + if [ -z $major -o -z $minor ]; then + fatal "Backend device does not exist" + fi + pdev=$(printf "0x%02x%02x" "0x$major" "0x$minor") xenstore_write "$XENBUS_PATH"/physical-device "$pdev" \ "$XENBUS_PATH"/node "$1" + + success } diff -r 20d1a79ebe31 tools/examples/vif-bridge --- a/tools/examples/vif-bridge Wed Oct 26 15:59:13 2005 +++ b/tools/examples/vif-bridge Thu Oct 27 20:15:02 2005 @@ -45,6 +45,7 @@ fatal "brctl addif $bridge $vif failed" ifconfig "$vif" up || fatal "ifconfig $vif up failed" + success ;; down) # vifs are auto-removed from bridge. @@ -55,3 +56,4 @@ handle_iptable log debug "vif-bridge operation for $vif successful." + diff -r 20d1a79ebe31 tools/examples/vif-nat --- a/tools/examples/vif-nat Wed Oct 26 15:59:13 2005 +++ b/tools/examples/vif-nat Thu Oct 27 20:15:02 2005 @@ -54,3 +54,5 @@ ip r ${ipcmd} ${ip} dev ${vif} src ${main_ip} handle_iptable() + +success diff -r 20d1a79ebe31 tools/examples/vif-route --- a/tools/examples/vif-route Wed Oct 26 15:59:13 2005 +++ b/tools/examples/vif-route Thu Oct 27 20:15:02 2005 @@ -46,3 +46,5 @@ fi handle_iptable() + +success diff -r 20d1a79ebe31 tools/examples/xen-hotplug-common.sh --- a/tools/examples/xen-hotplug-common.sh Wed Oct 26 15:59:13 2005 +++ b/tools/examples/xen-hotplug-common.sh Thu Oct 27 20:15:02 2005 @@ -29,8 +29,14 @@ } fatal() { + xenstore_write "$XENBUS_PATH"/hotplug-status error log err "$@" exit 1 +} + +success() { + # Tell DevController that backend is "connected" + xenstore_write "$XENBUS_PATH"/hotplug-status connected } xenstore_read() { diff -r 20d1a79ebe31 tools/python/xen/xend/server/DevController.py --- a/tools/python/xen/xend/server/DevController.py Wed Oct 26 15:59:13 2005 +++ b/tools/python/xen/xend/server/DevController.py Thu Oct 27 20:15:02 2005 @@ -16,12 +16,19 @@ # Copyright (C) 2005 XenSource Ltd #============================================================================ +import time +from threading import Event from xen.xend import sxp from xen.xend.XendError import VmError from xen.xend.XendLogging import log + from xen.xend.xenstore.xstransact import xstransact - +from xen.xend.xenstore.xswatch import xswatch + +DEVICE_CREATE_TIMEOUT = 120 +HOTPLUG_STATUS_NODE = "hotplug-status" +HOTPLUG_STATUS_ERROR = "error" class DevController: """Abstract base class for a device controller. Device controllers create @@ -54,6 +61,18 @@ self.writeDetails(config, devid, back, front) + status, fn_ret = self.waitForBackend(devid) + if status: + self.destroyDevice(devid) + raise VmError( ("Device %s (%s) could not be connected. " + "Hotplug scripts not working") + % (devid, self.deviceClass)) + + elif fn_ret == HOTPLUG_STATUS_ERROR: + self.destroyDevice(devid) + raise VmError( ("Device %s (%s) could not be connected. " + "Backend device not found!") + % (devid, self.deviceClass)) return devid @@ -234,6 +253,29 @@ xstransact.Write(frontpath, frontDetails) xstransact.Write(backpath, backDetails) + def waitForBackend(self,devid): + ev = Event() + + def hotplugStatus(): + status = self.readBackend(devid, HOTPLUG_STATUS_NODE) + if status is not None: + watch.xs.unwatch(backpath, watch) + hotplugStatus.value = status + ev.set() + + hotplugStatus.value = None + frontpath = self.frontendPath(devid) + backpath = xstransact.Read(frontpath, "backend") + + watch = xswatch(backpath, hotplugStatus) + + ev.wait(DEVICE_CREATE_TIMEOUT) + if ev.isSet(): + return (0, hotplugStatus.value) + else: + return (-1, hotplugStatus.value) + + def backendPath(self, backdom, devid): """@param backdom [XendDomainInfo] The backend domain info."""