Add uuid check to domain creation
PATCH 1/1 Add uuid check to domain creation
Hi,
This patch prevents 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.
Best regards,
Kan
---------
When I found the problem of uuid, operations were as follows.
I created VM with the following VM configuration definitions. (I specified the same uuid.)
uuid1.conf:
kernel = "/boot/vmlinuz-2.6-xenU"
memory = 256
name = "vm1"
disk = [ 'file:/xen/xen-test/image/rhel4_1.img,sda1,w' ] vif = [ '' ]
root = "/dev/sda1 ro"
uuid = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
uuid2.conf:
kernel = "/boot/vmlinuz-2.6-xenU"
memory = 256
name = "vm2"
disk = [ 'file:/xen/xen-test/image/rhel4_2.img,sda1,w' ] vif = [ '' ]
root = "/dev/sda1 ro"
uuid = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
The result was as follows.
- The same uuid is used in domain 1 and domain 2.
- The domain name of domain 1 was changed from vm1 to vm2.
# xm create /home/kanno/uuid1.conf
Using config file "/home/kanno/uuid1.conf".
Started domain vm1
# xm create /home/kanno/uuid2.conf
Using config file "/home/kanno/uuid2.conf".
Error: an integer is required
# xm list -l
(domain
(domid 0)
(uuid 00000000-0000-0000-0000-000000000000)
(vcpus 2)
(cpu_weight 1.0)
(memory 1024)
(maxmem 1024)
(features )
(name Domain-0)
(on_poweroff destroy)
(on_reboot restart)
(on_crash restart)
(state r-----)
(shutdown_reason poweroff)
(cpu_time 34.941371157)
(online_vcpus 2)
)
(domain
(domid 1)
(uuid aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
(vcpus 1)
(cpu_weight 1.0)
(memory 256)
(maxmem 256)
(features )
(name vm2)
(on_poweroff destroy)
(on_reboot restart)
(on_crash restart)
(image (linux (kernel /boot/vmlinuz-2.6-xenU) (root '/dev/sda1 ro')))
(device (vif (backend 0) (script vif-bridge) (mac 00:16:3e:17:14:cb)))
(device
(vbd
(backend 0)
(dev sda1)
(uname file:/xen/xen-test/image/rhel4_1.img)
(mode w)
)
)
(state -b----)
(shutdown_reason poweroff)
(cpu_time 3.610959097)
(online_vcpus 1)
(up_time 78.2889318466)
(start_time 1151666985.97)
(store_mfn 1048657)
(console_mfn 1048656)
)
(domain
(domid 2)
(uuid aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
(vcpus 1)
(cpu_weight 1.0)
(memory 256)
(maxmem 256)
(features )
(name vm2)
(on_poweroff destroy)
(on_reboot restart)
(on_crash restart)
(image (linux (kernel /boot/vmlinuz-2.6-xenU) (root '/dev/sda1 ro')))
(device (vif (backend 0) (script vif-bridge) (mac 00:16:3e:7e:ee:5c)))
(device
(vbd
(backend 0)
(dev sda1)
(uname file:/xen/xen-test/image/rhel4_2.img)
(mode w)
)
)
(state --p---)
(shutdown_reason poweroff)
(cpu_time 0.0)
(online_vcpus 1)
(up_time 14.7986199856)
(start_time 1151667049.47)
(store_mfn 737361)
(console_mfn 737360)
)tools/python/xen/xend/XendDomain.py +13 -0
@@ -347,6 +347,19 @@ class XendDomain: self.domains_lock.release() + def domain_lookup_by_uuid_nr(self, uuid): + self.domains_lock.acquire() + try: + matching = filter(lambda d: d.getUuid() == uuid, + self.domains.values()) + n = len(matching) + if n == 1: + return matching[0] + return None + finally: + self.domains_lock.release() + + def privilegedDomain(self): self.domains_lock.acquire() try:
tools/python/xen/xend/XendDomainInfo.py +25 -0
@@ -396,6 +396,10 @@ def domain_by_name(name): return XendDomain.instance().domain_lookup_by_name_nr(name) +def domain_by_uuid(uuid): + return XendDomain.instance().domain_lookup_by_uuid_nr(uuid) + + def shutdown_reason(code): """Get a shutdown reason from a code.
@@ -581,6 +585,7 @@ class XendDomainInfo: defaultInfo('security', lambda: None) self.check_name(self.info['name']) + self.check_uuid(self.info['uuid']) if isinstance(self.info['image'], str): self.info['image'] = sxp.from_string(self.info['image'])
@@ -777,6 +782,9 @@ class XendDomainInfo: def getName(self): return self.info['name'] + + def getUuid(self): + return self.info['uuid'] def getDomainPath(self): return self.dompath
@@ -1205,6 +1213,23 @@ class XendDomainInfo: if dominfo.domid != self.domid: raise VmError("VM name '%s' is used in both domains %d and %d" % (name, self.domid, dominfo.domid)) + + + def check_uuid(self, uuid): + """The same uuid cannot be used for more than one vm at the same time. + + @param uuid: uuid + @raise: VmError if same uuid is used + """ + dominfo = domain_by_uuid(uuid) + if not dominfo: + return + if self.domid is None: + raise VmError("uuid '%s' already in use by domain %d" % + (uuid, dominfo.domid)) + if dominfo.domid != self.domid: + raise VmError("uuid '%s' is used in both domains %d and %d" % + (uuid, self.domid, dominfo.domid)) def construct(self):
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel