Add a --force option to detach operations
PATCH 1/1 Add a --force option to detach operations
The following patch adds a --force option to detach operations. It avoids the device being held forever when frontend fails.
Comments welcome,
Signature · 3 lines
Glauber de Oliveira Costa Red Hat Inc. "Free as in Freedom"
# HG changeset patch
# User [email protected]
# Date 1166052970 18000
# Node ID 0c146c72637357ed3011f248c3e6952fface55a6 # Parent 360eb996fa38319867a74bf581c734a80bf6839d [Xend] Add a --force option to detach operations
In some situations triggered by errors found on guest side, the device will be held forever, due to the online flag being still on. Detach operations mostly fails from this point on, as the backend will not see frontend's state change anymore.
We have to take care about the possibility of of leaking if we drop entries too early (mostly netfront), or not forcing if for any reason frontend refused to disconnect device (mostly blkfront)
Signed-off-by Glauber de Oliveira Costa <[email protected]>
tools/python/xen/xend/XendDomainInfo.py +2 -2
@@ -563,7 +563,7 @@ class XendDomainInfo: for devclass in XendDevices.valid_devices(): self.getDeviceController(devclass).waitForDevices() - def destroyDevice(self, deviceClass, devid): + def destroyDevice(self, deviceClass, devid, force=None): try: devid = int(devid) except ValueError:
@@ -578,7 +578,7 @@ class XendDomainInfo: devid = entry break - return self.getDeviceController(deviceClass).destroyDevice(devid) + return self.getDeviceController(deviceClass).destroyDevice(devid, force)
tools/python/xen/xend/server/DevController.py +21 -1
@@ -191,7 +191,7 @@ class DevController: raise VmError('%s devices may not be reconfigured' % self.deviceClass) - def destroyDevice(self, devid): + def destroyDevice(self, devid, force): """Destroy the specified device. @param devid The device ID, or something device-specific from which
@@ -211,6 +211,26 @@ class DevController: # drivers, so this ordering avoids a race). self.writeBackend(devid, 'online', "0") self.writeBackend(devid, 'state', str(xenbusState['Closing'])) + + if force: + frontpath = self.frontendPath(devid) + backpath = xstransact.Read(frontpath, "backend") + # give frontend its last chance + if not backpath: + # we're done + return + ev = Event() + # leave a reasonable time for cleanups that may rely upon + # xenstore entries + ev.wait(2) + + fstate = xstransact.Read(frontpath,"state") + # It is not safe to force anything if guest is in connected + # state, as it may cause it to leak. + if fstate == str(xenbusState['Connected']): + raise VmError("Device %d still connected"%(devid)) + xstransact.Remove(backpath) + xstransact.Remove(frontpath) def configurations(self):
tools/python/xen/xend/server/blkif.py +3 -3
@@ -133,7 +133,7 @@ class BlkifController(DevController): return config - def destroyDevice(self, devid): + def destroyDevice(self, devid, force): """@see DevController.destroyDevice""" # If we are given a device name, then look up the device ID from it,
@@ -142,13 +142,13 @@ class BlkifController(DevController): # superclass's method. try: - DevController.destroyDevice(self, int(devid)) + DevController.destroyDevice(self, int(devid), force) except ValueError: devid_end = type(devid) is str and devid.split('/')[-1] or None for i in self.deviceIDs(): d = self.readBackend(i, 'dev') if d == devid or (devid_end and d == devid_end): - DevController.destroyDevice(self, i) + DevController.destroyDevice(self, i, force) return raise VmError("Device %s not connected" % devid)
tools/python/xen/xm/main.py +12 -5
@@ -142,14 +142,14 @@ SUBCOMMAND_HELP = { 'Create a new virtual block device.'), 'block-configure': ('<Domain> <BackDev> <FrontDev> <Mode> [BackDomain]', 'Change block device configuration'), - 'block-detach' : ('<Domain> <DevId>', + 'block-detach' : ('<Domain> <DevId> [-f|--force]', 'Destroy a domain\'s virtual block device.'), 'block-list' : ('<Domain> [--long]', 'List virtual block devices for a domain.'), 'network-attach': ('<Domain> [--script=<script>] [--ip=<ip>] ' '[--mac=<mac>]', 'Create a new virtual network device.'), - 'network-detach': ('<Domain> <DevId>', + 'network-detach': ('<Domain> <DevId> [-f|--force]', 'Destroy a domain\'s virtual network device.'), 'network-list' : ('<Domain> [--long]', 'List virtual network interfaces for a domain.'),
@@ -1493,12 +1493,19 @@ def xm_network_attach(args): def detach(args, command, deviceClass): - arg_check(args, command, 2) + arg_check(args, command, 2, 3) dom = args[0] dev = args[1] - - server.xend.domain.destroyDevice(dom, deviceClass, dev) + try: + force = args[2] + if (force != "--force") and (force != "-f"): + print "Ignoring option %s"%(force) + force = None + except IndexError: + force = None + + server.xend.domain.destroyDevice(dom, deviceClass, dev, force) def xm_block_detach(args):
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 2 lines · Glauber de Oliveira Costa
The following patch adds a --force option to detach operations. It avoids the device being held forever when frontend fails.
Looks good. I think --force should be more brutal (i.e., assume that we have already politely requested the disconnection, if that's what we really wanted).
Apart from that, we should remember that if we need to use --force then it probably indicates a problem in the frontend driver. If you can repro a situation that requires --force then we should investigate that (and work out a patch for blkfront).
Thanks,
Keir
Quoted 8 lines · Keir Fraser
Quoted 2 lines · Glauber de Oliveira Costa
The following patch adds a --force option to detach operations. It avoids the device being held forever when frontend fails.
Looks good. I think --force should be more brutal (i.e., assume that we have already politely requested the disconnection, if that's what we really wanted).
How can we be more brutal than that ? The only non-brutal thing I've put there is denying disconnection when still in Connected state. But if for some reason the frontend does not want to disconnect, then the tools have no power over it. It can simply crash guest.
Example: attach a device, mount it at guest, and try to detach it using --force. It should not force it, as it crashes the guest.
Quoted 5 lines
Apart from that, we should remember that if we need to use --force then it probably indicates a problem in the frontend driver. If you can repro a situation that requires --force then we should investigate that (and work out a patch for blkfront).
Not exactly. The example I'm tracking is as follow:
* try attaching a file:///<valid_file> as sda, after modprobing sd_mod at guest.
* guest is not able to allocate it a major, and fails like this:
Registering block device major 8register_blkdev: cannot get major 8 for sdxen_blk: can't get major 8 with name sd
Besides, there are many situations in which the underlying block layer can fail (out of memory, and so on). And it does not necessarily means a bug in the frontend device.
I do however agree that in the general case, it is a good indicator.
Signature · 5 lines
Glauber de Oliveira Costa. "Free as in Freedom" Add your comments to GPLv3 at: http://gplv3.fsf.org/comments/gplv3-draft-2.html
Quoted 7 lines · Glauber de Oliveira Costa
How can we be more brutal than that ? The only non-brutal thing I've put there is denying disconnection when still in Connected state. But if for some reason the frontend does not want to disconnect, then the tools have no power over it. It can simply crash guest.
Example: attach a device, mount it at guest, and try to detach it using --force. It should not force it, as it crashes the guest.
Don't use --force if you don't know what you're doing is a reasonable caveat. You're on flakey ground if you have to use it in any case as something is obviously screwed.
-- Keir
Quoted 7 lines · Keir Fraser
Quoted 5 lines · Glauber de Oliveira Costa
How can we be more brutal than that ? The only non-brutal thing I've put there is denying disconnection when still in Connected state. But if for some reason the frontend does not want to disconnect, then the tools have no power over it. It can simply crash guest.
Quoted 6 lines
Quoted 2 lines
Example: attach a device, mount it at guest, and try to detach it using --force. It should not force it, as it crashes the guest.
Don't use --force if you don't know what you're doing is a reasonable caveat. You're on flakey ground if you have to use it in any case as something is obviously screwed.
These kind of things can happen by accident. And in case an accident happens, it does not seems a good idea to crash the guest.
Moreover, the lack of any kind of timeout can lead netfront to leak memory. If the stores are released too early, backend may be unable to release the references, and frontend will leak. I see no way of having any guarantee of being in a termination state, so we will not be able to to be sure it is safe to remove the entries anyway. But tests I made with that timeout value lead to no leaks.