[libvirt] [PATCH] conf: Do not load domain if the domain with same already exists

We don't allow to define domain with same name and different UUID, or with same UUID, so it's reasonable to not load the domain config if there is domain with same name already exists. Otherwise it can cause problem like: 1) % cp /etc/libvirt/qemu/dom.xml /etc/libvirt/qemu/dom_diffuuid.xml 2) remove the line with "uuid" in the "dom_diffuuid.xml" 3) % for i in {1..10}; do kill -SIGHUP $(pidof libvirtd); done 4) % virsh list --all There will be 11 domains listed with the same name, as if there is no UUID specified in domain XML, libvirt will generate one for it, which will be definitely different with the original one. --- src/conf/domain_conf.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ce1f3c5..0bed929 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10535,7 +10535,8 @@ static virDomainObjPtr virDomainLoadConfig(virCapsPtr caps, /* if the domain is already in our hashtable, we only need to * update the autostart flag */ - if ((dom = virDomainFindByUUID(doms, def->uuid))) { + if ((dom = virDomainFindByUUID(doms, def->uuid)) || + (dom = virDomainFindByName(doms, def->name))) { dom->autostart = autostart; VIR_FREE(configFile); -- 1.7.6

On 08/16/2011 09:05 AM, Osier Yang wrote:
We don't allow to define domain with same name and different UUID, or with same UUID, so it's reasonable to not load the domain config if there is domain with same name already exists.
Otherwise it can cause problem like:
1) % cp /etc/libvirt/qemu/dom.xml /etc/libvirt/qemu/dom_diffuuid.xml 2) remove the line with "uuid" in the "dom_diffuuid.xml"
This is invalid. Users should not be mucking with /etc/libvirt, but rather going through libvirt APIs. Is there any way, using only libvirt APIs, where /etc/libvirt can end up with a domain without a uuid? If not, then NACK to this patch, and instead fix the test scenario that was driving this patch to quit going behind libvirt's back.
There will be 11 domains listed with the same name, as if there is no UUID specified in domain XML, libvirt will generate one for it, which will be definitely different with the original one.
Libvirt should have already generated a uuid for all domains already in /etc/libvirt; if there is no way for /etc/libvirt to have a domain without a uuid in /etc/libvirt short of going behind libvirt's back, then doing a name lookup won't buy us any safety. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

于 2011年08月16日 22:58, Eric Blake 写道:
On 08/16/2011 09:05 AM, Osier Yang wrote:
We don't allow to define domain with same name and different UUID, or with same UUID, so it's reasonable to not load the domain config if there is domain with same name already exists.
Otherwise it can cause problem like:
1) % cp /etc/libvirt/qemu/dom.xml /etc/libvirt/qemu/dom_diffuuid.xml 2) remove the line with "uuid" in the "dom_diffuuid.xml"
This is invalid. Users should not be mucking with /etc/libvirt, but rather going through libvirt APIs. Is there any way, using only libvirt APIs, where /etc/libvirt can end up with a domain without a uuid? If not, then NACK to this patch, and instead fix the test scenario that was driving this patch to quit going behind libvirt's back.
There will be 11 domains listed with the same name, as if there is no UUID specified in domain XML, libvirt will generate one for it, which will be definitely different with the original one.
Libvirt should have already generated a uuid for all domains already in /etc/libvirt; if there is no way for /etc/libvirt to have a domain without a uuid in /etc/libvirt short of going behind libvirt's back, then doing a name lookup won't buy us any safety.
I don't see a way to cause a domain has no UUID though libvirt APIs, so self NACK this. Thanks Osier
participants (2)
-
Eric Blake
-
Osier Yang