* [PATCH] Add a mechanism to detect block device setup failure
@ 2005-10-28 18:42 Murillo Fernandes Bernardes
0 siblings, 0 replies; 3+ messages in thread
From: Murillo Fernandes Bernardes @ 2005-10-28 18:42 UTC (permalink / raw)
To: xen-devel, aliguori
[-- Attachment #1: Type: text/plain, Size: 576 bytes --]
Hi
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
[-- Attachment #2: DevController_device_create_check.patch --]
[-- Type: text/x-diff, Size: 4398 bytes --]
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."""
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] Add a mechanism to detect block device setup failure
@ 2005-10-29 3:11 Murillo Fernandes Bernardes
2005-10-31 16:16 ` Ewan Mellor
0 siblings, 1 reply; 3+ messages in thread
From: Murillo Fernandes Bernardes @ 2005-10-29 3:11 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 572 bytes --]
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
[-- Attachment #2: DevController_device_create_check.patch --]
[-- Type: text/x-diff, Size: 4398 bytes --]
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."""
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Add a mechanism to detect block device setup failure
2005-10-29 3:11 Murillo Fernandes Bernardes
@ 2005-10-31 16:16 ` Ewan Mellor
0 siblings, 0 replies; 3+ messages in thread
From: Ewan Mellor @ 2005-10-31 16:16 UTC (permalink / raw)
To: Murillo Fernandes Bernardes; +Cc: xen-devel
On Sat, Oct 29, 2005 at 01:11:07AM -0200, Murillo Fernandes Bernardes wrote:
> 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?
Thanks a lot for this, Murillo. I have a concern that this patch only
protects us against failure of hotplugging, and not, for example, a failure of
the backend driver, but it's certainly a good step in the right direction, so
I've applied it. I'll be working myself in this area over the next day or two
to improve this further.
Thanks again,
Ewan.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-10-31 16:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-28 18:42 [PATCH] Add a mechanism to detect block device setup failure Murillo Fernandes Bernardes
-- strict thread matches above, loose matches on Subject: below --
2005-10-29 3:11 Murillo Fernandes Bernardes
2005-10-31 16:16 ` Ewan Mellor
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.