Skip to contentSkip to conversation

Prevent xend from starting duplicate domains

PATCH In review Dan Smith 4 participants 7 messages Sep 13, 2005 – Sep 16, 2005

lore
Share & tools
lore

Dan Smith

author
#0 lore raw

PATCH 1/1 Prevent xend from starting duplicate domains

The attached patch puts a simple check in domain_create() which prevents starting a domain if there is already one of the same name in the domain list.

This fixes the problem of getting the following error message from xm while creating a domain soon after destroying one with the same name:

xen.xend.XendProtocol.XendError: (3, 'No such process')

tools/python/xen/xend/XendDomain.py +7 -0
diff -r 3a34bcb7c28b tools/python/xen/xend/XendDomain.py
@@ -296,6 +296,13 @@
         @param config: configuration
         @return: domain
         """
+
+        existing = self.domains.get_by_name(sxp.child_value(config, "name"))
+        if existing:
+            log.debug("Attempt to create duplicate domain %s" % existing.name)
+            raise XendError("Domain %s already exists as %i!" %
+                            (existing.name, existing.id))
+        
         dominfo = XendDomainInfo.create(self.dbmap, config)
         return dominfo
 
Signature · 5 lines
-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: [email protected]

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 10 lines · Dan Smith

The attached patch puts a simple check in domain_create() which prevents starting a domain if there is already one of the same name in the domain list.

This fixes the problem of getting the following error message from xm while creating a domain soon after destroying one with the same name:

xen.xend.XendProtocol.XendError: (3, 'No such process')

Surely there's a race condition here? The hypervisor op that creates a domain has to fail if it would result in two domains with the same name; this can't be reliably enforced by a separate check in the Python tools.

Signature · 1 line
David Hopwood <[email protected]>
author
#2 lore raw

DH> Surely there's a race condition here? The hypervisor op that DH> creates a domain has to fail if it would result in two domains DH> with the same name;

With the same domid? Yes. Unless I'm completely missing something, the hypervisor knows nothing of the *names* of the domains.

Am I wrong?

DH> this can't be reliably enforced by a separate check in the Python DH> tools.

Going on the assumption that the names are known only to the tools, I think the tools are the best place to perform the check.

Signature · 4 lines
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: [email protected]
#3 lore raw
Quoted 8 lines · Dan Smith

DH> Surely there's a race condition here? The hypervisor op that DH> creates a domain has to fail if it would result in two domains DH> with the same name;

With the same domid? Yes. Unless I'm completely missing something, the hypervisor knows nothing of the *names* of the domains.

The hypervisor has no concept of domain names. That's entirely a Xend construct. The same applies to UUIDs.

Even if there are two domains with the same name, they have different domain IDs which is okay from the hypervisor's perspective.

Quoted 10 lines

Am I wrong?

DH> this can't be reliably enforced by a separate check in the Python DH> tools.

Going on the assumption that the names are known only to the tools, I think the tools are the best place to perform the check.

Regards,

Anthony Liguori

#4 lore raw
In reply to Dan Smith
Quoted 8 lines · Dan Smith

The attached patch puts a simple check in domain_create() which prevents starting a domain if there is already one of the same name in the domain list.

This fixes the problem of getting the following error message from xm while creating a domain soon after destroying one with the same name:

xen.xend.XendProtocol.XendError: (3, 'No such process')

There is already a check for domains with the same name in XendDomainInfo.check_name. We should fix that check instead of adding another check. Could you try the attached patch which removes the check if a domain "is terminated" and thus allows creation of a domain with the same name?

It's arguable if this should be allowed or not, but if we allow it, then we need to find the root cause of the error you're seeing...

christian

tools/python/xen/xend/XendDomainInfo.py +0 -2
diff -r 4490e39fc322 tools/python/xen/xend/XendDomainInfo.py
@@ -635,8 +635,6 @@
         # my domain id.
         if not dominfo:
             return
-        if dominfo.is_terminated():
-            return
         if not self.domid or (dominfo.domid != self.domid):
             raise VmError('vm name clash: ' + name)
         

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#5 lore raw

CL> There is already a check for domains with the same name in CL> XendDomainInfo.check_name.

Ah, yes, I see that now.

CL> We should fix that check instead of adding another check.

I agree that there should be one check, but it seems counter-intuitive (to me) to have that check where it is. That's the reason I hadn't noticed it before.

It seems strange to have a container class (XendDomain) that instantiates an item object which then gets an instance of the container to check for another domain with the same name. Why not have the container itself do the duplicate check? I would argue that the existing model is bad because the item class could not be placed in another container. Further, the container is enforced as a set by the items that go in it, instead of the container itself.

If others agree, I'd be happy to submit a patch that moves the check out of the item class and into the container class.

CL> Could you try the attached patch which removes the check if a CL> domain "is terminated" and thus allows creation of a domain with CL> the same name?

I did test the patch and it does prevent corruption of the list.

Signature · 4 lines
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: [email protected]
#6 lore raw
Quoted 14 lines · Dan Smith

CL> We should fix that check instead of adding another check.

I agree that there should be one check, but it seems counter-intuitive (to me) to have that check where it is. That's the reason I hadn't noticed it before.

It seems strange to have a container class (XendDomain) that instantiates an item object which then gets an instance of the container to check for another domain with the same name. Why not have the container itself do the duplicate check? I would argue that the existing model is bad because the item class could not be placed in another container. Further, the container is enforced as a set by the items that go in it, instead of the container itself.

Quoted 2 lines

If others agree, I'd be happy to submit a patch that moves the check out of the item class and into the container class.

I agree, go for it. You'll have to check both in the create and restore cases. I don't think we need to check on recreate, we can assume a consistent store...

Quoted 5 lines

CL> Could you try the attached patch which removes the check if a CL> domain "is terminated" and thus allows creation of a domain with CL> the same name?

I did test the patch and it does prevent corruption of the list.

I'm happy with removing the check, but I wonder if we're not masking the fact that we set the domain to terminated state when it's not yet in that state. Yeah, looks like we should only set the state to terminated once we've completed device cleanup.
Of course we must have some other bug which you hit when we have domains in terminated state and you want to create a new domain of the same name. Maybe renaming the domain when we set the terminated state is the solution for that...

christian