From mboxrd@z Thu Jan 1 00:00:00 1970 From: Murillo Fernandes Bernardes Subject: [PATCH] Add a mechanism to detect block device setup failure Date: Sat, 29 Oct 2005 01:11:07 -0200 Message-ID: <200510290111.07669.mfb@br.ibm.com> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_LhuYDBPDHeGPkjP" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --Boundary-00=_LhuYDBPDHeGPkjP Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline The problem is: There is no mechanism to detect block device setup failure Network devices have the same problem, and are fixed with this too. I handling this problem in the way suggested by aliguori: - hotplug scripts write a "hotplug-status" node on store - Xend DevController.createDevice() check verify this node and return success or throw an exception on failure. - If no changes in "hotplug-status" node after DEVICE_CREATE_TIMEOUT seconds Xend throw an exception showing the problem with hotplug scripts. Comments? Regards -- Murillo Fernandes Bernardes --Boundary-00=_LhuYDBPDHeGPkjP Content-Type: text/x-diff; charset="iso-8859-1"; name="DevController_device_create_check.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="DevController_device_create_check.patch" 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.""" --Boundary-00=_LhuYDBPDHeGPkjP Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --Boundary-00=_LhuYDBPDHeGPkjP--