]> xenbits.xensource.com Git - libvirt.git/commitdiff
domain_conf: Introducde virDomainObjListRenameAddNew() & virDomainObjListRenameRemove()
authorTomas Meszaros <exo@tty.sk>
Mon, 10 Aug 2015 19:59:16 +0000 (21:59 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 14 Aug 2015 08:50:20 +0000 (10:50 +0200)
We just need to update the entry in the second hash table. Since commit 8728a56
we have two hash tables for the domain list so that we can do O(1) lookup
regardless of looking up by UUID or name. Since with renaming a domain UUID does
not change, we only need to update the second hash table, where domains are
referenced by their name.

We will call both functions from the qemuDomainRename().

Signed-off-by: Tomas Meszaros <exo@tty.sk>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms

index f4469988127ecd9808019f2413f7c767b41e1c57..d440eb31f70dbe69fae5940202b44a1e47667815 100644 (file)
@@ -2864,6 +2864,41 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
     return ret;
 }
 
+
+int
+virDomainObjListRenameAddNew(virDomainObjListPtr doms,
+                             virDomainObjPtr vm,
+                             const char *name)
+{
+    int ret = -1;
+    virObjectLock(doms);
+
+    /* Add new name into the hash table of domain names. */
+    if (virHashAddEntry(doms->objsName, name, vm) < 0)
+        goto cleanup;
+
+    /* Okay, this is crazy. virHashAddEntry() does not increment
+     * the refcounter of @vm, but virHashRemoveEntry() does
+     * decrement it. We need to work around it. */
+    virObjectRef(vm);
+
+    ret = 0;
+ cleanup:
+    virObjectUnlock(doms);
+    return ret;
+}
+
+
+int
+virDomainObjListRenameRemove(virDomainObjListPtr doms, const char *name)
+{
+    virObjectLock(doms);
+    virHashRemoveEntry(doms->objsName, name);
+    virObjectUnlock(doms);
+    return 0;
+}
+
+
 /*
  * Mark the running VM config as transient. Ensures transient hotplug
  * operations do not persist past shutdown.
index e1872bca002c3a602fd9c464be67ad555ff56f7c..961e4ed6b47eb0ce4ef79e27181190f7073d8a84 100644 (file)
@@ -2580,6 +2580,11 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
                                     virDomainXMLOptionPtr xmlopt,
                                     unsigned int flags,
                                     virDomainDefPtr *oldDef);
+int virDomainObjListRenameAddNew(virDomainObjListPtr doms,
+                                 virDomainObjPtr vm,
+                                 const char *name);
+int virDomainObjListRenameRemove(virDomainObjListPtr doms,
+                                 const char *name);
 void virDomainObjAssignDef(virDomainObjPtr domain,
                            virDomainDefPtr def,
                            bool live,
index 45f42f5020350cf2e0fc90969c300d43af01faa1..9042330f99749767120abfa8585ab4c47f375f07 100644 (file)
@@ -410,6 +410,8 @@ virDomainObjListNew;
 virDomainObjListNumOfDomains;
 virDomainObjListRemove;
 virDomainObjListRemoveLocked;
+virDomainObjListRenameAddNew;
+virDomainObjListRenameRemove;
 virDomainObjNew;
 virDomainObjParseNode;
 virDomainObjSetDefTransient;