ia64/xen-unstable

changeset 7223:b4800e204757

Recover from name uniqueness violation by renaming. Fixes bug #277.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Wed Oct 05 14:38:19 2005 +0100 (2005-10-05)
parents c60036fe7418
children 6bbfd6a98974
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Wed Oct 05 11:43:23 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Wed Oct 05 14:38:19 2005 +0100
     1.3 @@ -309,10 +309,12 @@ class XendDomain:
     1.4              if n == 1:
     1.5                  return matching[0]
     1.6              elif n > 1:
     1.7 -                raise XendError(
     1.8 -                    'Name uniqueness has been violated for name %s' % name)
     1.9 -            else:
    1.10 -                return None
    1.11 +                log.error('Name uniqueness has been violated for name %s!  '
    1.12 +                          'Recovering by renaming:', name)
    1.13 +                for d in matching:
    1.14 +                    d.renameUniquely()
    1.15 +
    1.16 +            return None
    1.17          finally:
    1.18              self.domains_lock.release()
    1.19  
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Oct 05 11:43:23 2005 +0100
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Oct 05 14:38:19 2005 +0100
     2.3 @@ -1288,7 +1288,7 @@ class XendDomainInfo:
     2.4          preserving the restart semantics (name and UUID preserved).
     2.5          """
     2.6          
     2.7 -        new_name = self.generateShutdownName()
     2.8 +        new_name = self.generateUniqueName()
     2.9          new_uuid = getUuid()
    2.10          log.info("Renaming dead domain %s (%d, %s) to %s (%s).",
    2.11                   self.info['name'], self.domid, self.uuid, new_name, new_uuid)
    2.12 @@ -1307,7 +1307,23 @@ class XendDomainInfo:
    2.13          self.state_set(STATE_VM_TERMINATED)
    2.14  
    2.15  
    2.16 -    def generateShutdownName(self):
    2.17 +    ## public:
    2.18 +
    2.19 +    def renameUniquely(self):
    2.20 +        """Rename this domain so that it has a unique name.  This is used by
    2.21 +        XendDomain to recover from non-uniqueness errors; we should never have
    2.22 +        allowed the system to reach this state in the first place."""
    2.23 +        new_name = self.generateUniqueName()
    2.24 +        
    2.25 +        log.error('Renaming %s (%d, %s) to %s', self.info['name'], self.domid,
    2.26 +                  self.uuid, new_name)
    2.27 +
    2.28 +        self.setName(new_name)
    2.29 +
    2.30 +
    2.31 +    # private:
    2.32 +
    2.33 +    def generateUniqueName(self):
    2.34          n = 1
    2.35          while True:
    2.36              name = "%s-%d" % (self.info['name'], n)