ia64/xen-unstable

changeset 10710:800261a88275

[XEND] Prevent uuid double use.

A check_uuid() in this patch checks on uuid of the
VM configuration definition. If specified uuid is
already used with the others VM, the xm create command
does not create the VM. The xm create command error occurs.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author kfraser@localhost.localdomain
date Mon Jul 10 15:10:00 2006 +0100 (2006-07-10)
parents a1c2cede77c7
children 9ddc5be227c1
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Mon Jul 10 15:01:49 2006 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Mon Jul 10 15:10:00 2006 +0100
     1.3 @@ -347,6 +347,19 @@ class XendDomain:
     1.4              self.domains_lock.release()
     1.5  
     1.6  
     1.7 +    def domain_lookup_by_uuid_nr(self, uuid):
     1.8 +        self.domains_lock.acquire()
     1.9 +        try:
    1.10 +            matching = filter(lambda d: d.getUuid() == uuid,
    1.11 +                              self.domains.values())
    1.12 +            n = len(matching)
    1.13 +            if n == 1:
    1.14 +                return matching[0]
    1.15 +            return None
    1.16 +        finally:
    1.17 +            self.domains_lock.release()
    1.18 +
    1.19 +
    1.20      def privilegedDomain(self):
    1.21          self.domains_lock.acquire()
    1.22          try:
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Jul 10 15:01:49 2006 +0100
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Jul 10 15:10:00 2006 +0100
     2.3 @@ -396,6 +396,10 @@ def domain_by_name(name):
     2.4      return XendDomain.instance().domain_lookup_by_name_nr(name)
     2.5  
     2.6  
     2.7 +def domain_by_uuid(uuid):
     2.8 +    return XendDomain.instance().domain_lookup_by_uuid_nr(uuid)
     2.9 +
    2.10 +
    2.11  def shutdown_reason(code):
    2.12      """Get a shutdown reason from a code.
    2.13  
    2.14 @@ -581,6 +585,7 @@ class XendDomainInfo:
    2.15              defaultInfo('security',     lambda: None)
    2.16  
    2.17              self.check_name(self.info['name'])
    2.18 +            self.check_uuid(self.info['uuid'])
    2.19  
    2.20              if isinstance(self.info['image'], str):
    2.21                  self.info['image'] = sxp.from_string(self.info['image'])
    2.22 @@ -778,6 +783,9 @@ class XendDomainInfo:
    2.23      def getName(self):
    2.24          return self.info['name']
    2.25  
    2.26 +    def getUuid(self):
    2.27 +        return self.info['uuid']
    2.28 +
    2.29      def getDomainPath(self):
    2.30          return self.dompath
    2.31  
    2.32 @@ -1207,6 +1215,23 @@ class XendDomainInfo:
    2.33                            (name, self.domid, dominfo.domid))
    2.34  
    2.35  
    2.36 +    def check_uuid(self, uuid):
    2.37 +        """The same uuid cannot be used for more than one vm at the same time.
    2.38 +
    2.39 +        @param uuid: uuid
    2.40 +        @raise: VmError if same uuid is used
    2.41 +        """
    2.42 +        dominfo = domain_by_uuid(uuid)
    2.43 +        if not dominfo:
    2.44 +            return
    2.45 +        if self.domid is None:
    2.46 +            raise VmError("uuid '%s' already in use by domain %d" %
    2.47 +                          (uuid, dominfo.domid))
    2.48 +        if dominfo.domid != self.domid:
    2.49 +            raise VmError("uuid '%s' is used in both domains %d and %d" %
    2.50 +                          (uuid, self.domid, dominfo.domid))
    2.51 +
    2.52 +
    2.53      def construct(self):
    2.54          """Construct the domain.
    2.55