ia64/xen-unstable

changeset 13014:ef5e6df3ba9e

[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.

Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com>
author kfraser@localhost.localdomain
date Thu Dec 14 10:17:37 2006 +0000 (2006-12-14)
parents 997f2bbb5cbc
children c09dab67c178
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/DevController.py tools/python/xen/xend/server/blkif.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Dec 14 10:01:17 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Dec 14 10:17:37 2006 +0000
     1.3 @@ -563,7 +563,7 @@ class XendDomainInfo:
     1.4          for devclass in XendDevices.valid_devices():
     1.5              self.getDeviceController(devclass).waitForDevices()
     1.6  
     1.7 -    def destroyDevice(self, deviceClass, devid):
     1.8 +    def destroyDevice(self, deviceClass, devid, force=None):
     1.9          try:
    1.10              devid = int(devid)
    1.11          except ValueError:
    1.12 @@ -578,7 +578,7 @@ class XendDomainInfo:
    1.13                      devid = entry
    1.14                      break
    1.15                  
    1.16 -        return self.getDeviceController(deviceClass).destroyDevice(devid)
    1.17 +        return self.getDeviceController(deviceClass).destroyDevice(devid, force)
    1.18  
    1.19  
    1.20  
     2.1 --- a/tools/python/xen/xend/server/DevController.py	Thu Dec 14 10:01:17 2006 +0000
     2.2 +++ b/tools/python/xen/xend/server/DevController.py	Thu Dec 14 10:17:37 2006 +0000
     2.3 @@ -195,7 +195,7 @@ class DevController:
     2.4          raise VmError('%s devices may not be reconfigured' % self.deviceClass)
     2.5  
     2.6  
     2.7 -    def destroyDevice(self, devid):
     2.8 +    def destroyDevice(self, devid, force):
     2.9          """Destroy the specified device.
    2.10  
    2.11          @param devid The device ID, or something device-specific from which
    2.12 @@ -216,6 +216,13 @@ class DevController:
    2.13          self.writeBackend(devid, 'online', "0")
    2.14          self.writeBackend(devid, 'state', str(xenbusState['Closing']))
    2.15  
    2.16 +        if force:
    2.17 +            frontpath = self.frontendPath(devid)
    2.18 +            backpath = xstransact.Read(frontpath, "backend")
    2.19 +            if backpath:
    2.20 +                xstransact.Remove(backpath)
    2.21 +            xstransact.Remove(frontpath)
    2.22 +
    2.23  
    2.24      def configurations(self):
    2.25          return map(self.configuration, self.deviceIDs())
     3.1 --- a/tools/python/xen/xend/server/blkif.py	Thu Dec 14 10:01:17 2006 +0000
     3.2 +++ b/tools/python/xen/xend/server/blkif.py	Thu Dec 14 10:17:37 2006 +0000
     3.3 @@ -133,7 +133,7 @@ class BlkifController(DevController):
     3.4  
     3.5          return config
     3.6  
     3.7 -    def destroyDevice(self, devid):
     3.8 +    def destroyDevice(self, devid, force):
     3.9          """@see DevController.destroyDevice"""
    3.10  
    3.11          # If we are given a device name, then look up the device ID from it,
    3.12 @@ -142,13 +142,13 @@ class BlkifController(DevController):
    3.13          # superclass's method.
    3.14  
    3.15          try:
    3.16 -            DevController.destroyDevice(self, int(devid))
    3.17 +            DevController.destroyDevice(self, int(devid), force)
    3.18          except ValueError:
    3.19              devid_end = type(devid) is str and devid.split('/')[-1] or None
    3.20  
    3.21              for i in self.deviceIDs():
    3.22                  d = self.readBackend(i, 'dev')
    3.23                  if d == devid or (devid_end and d == devid_end):
    3.24 -                    DevController.destroyDevice(self, i)
    3.25 +                    DevController.destroyDevice(self, i, force)
    3.26                      return
    3.27              raise VmError("Device %s not connected" % devid)
     4.1 --- a/tools/python/xen/xm/main.py	Thu Dec 14 10:01:17 2006 +0000
     4.2 +++ b/tools/python/xen/xm/main.py	Thu Dec 14 10:17:37 2006 +0000
     4.3 @@ -142,14 +142,14 @@ SUBCOMMAND_HELP = {
     4.4                          'Create a new virtual block device.'),
     4.5      'block-configure': ('<Domain> <BackDev> <FrontDev> <Mode> [BackDomain]',
     4.6                          'Change block device configuration'),
     4.7 -    'block-detach'  :  ('<Domain> <DevId>',
     4.8 +    'block-detach'  :  ('<Domain> <DevId> [-f|--force]',
     4.9                          'Destroy a domain\'s virtual block device.'),
    4.10      'block-list'    :  ('<Domain> [--long]',
    4.11                          'List virtual block devices for a domain.'),
    4.12      'network-attach':  ('<Domain> [--script=<script>] [--ip=<ip>] '
    4.13                          '[--mac=<mac>]',
    4.14                          'Create a new virtual network device.'),
    4.15 -    'network-detach':  ('<Domain> <DevId>',
    4.16 +    'network-detach':  ('<Domain> <DevId> [-f|--force]',
    4.17                          'Destroy a domain\'s virtual network device.'),
    4.18      'network-list'  :  ('<Domain> [--long]',
    4.19                          'List virtual network interfaces for a domain.'),
    4.20 @@ -1493,12 +1493,19 @@ def xm_network_attach(args):
    4.21  
    4.22  
    4.23  def detach(args, command, deviceClass):
    4.24 -    arg_check(args, command, 2)
    4.25 +    arg_check(args, command, 2, 3)
    4.26  
    4.27      dom = args[0]
    4.28      dev = args[1]
    4.29 +    try:
    4.30 +        force = args[2]
    4.31 +        if (force != "--force") and (force != "-f"):
    4.32 +            print "Ignoring option %s"%(force)
    4.33 +            force = None
    4.34 +    except IndexError:
    4.35 +        force = None
    4.36  
    4.37 -    server.xend.domain.destroyDevice(dom, deviceClass, dev)
    4.38 +    server.xend.domain.destroyDevice(dom, deviceClass, dev, force)
    4.39  
    4.40  
    4.41  def xm_block_detach(args):