提交 28257dc2 编写于 作者: T Tomas Meszaros 提交者: Michal Privoznik

domain_conf: Introducde virDomainObjListRenameAddNew() & virDomainObjListRenameRemove()

We just need to update the entry in the second hash table. Since commit 8728a565
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: NTomas Meszaros <exo@tty.sk>
上级 ff486e0d
...@@ -2864,6 +2864,41 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, ...@@ -2864,6 +2864,41 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
return ret; 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 * Mark the running VM config as transient. Ensures transient hotplug
* operations do not persist past shutdown. * operations do not persist past shutdown.
......
...@@ -2580,6 +2580,11 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, ...@@ -2580,6 +2580,11 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
unsigned int flags, unsigned int flags,
virDomainDefPtr *oldDef); virDomainDefPtr *oldDef);
int virDomainObjListRenameAddNew(virDomainObjListPtr doms,
virDomainObjPtr vm,
const char *name);
int virDomainObjListRenameRemove(virDomainObjListPtr doms,
const char *name);
void virDomainObjAssignDef(virDomainObjPtr domain, void virDomainObjAssignDef(virDomainObjPtr domain,
virDomainDefPtr def, virDomainDefPtr def,
bool live, bool live,
......
...@@ -410,6 +410,8 @@ virDomainObjListNew; ...@@ -410,6 +410,8 @@ virDomainObjListNew;
virDomainObjListNumOfDomains; virDomainObjListNumOfDomains;
virDomainObjListRemove; virDomainObjListRemove;
virDomainObjListRemoveLocked; virDomainObjListRemoveLocked;
virDomainObjListRenameAddNew;
virDomainObjListRenameRemove;
virDomainObjNew; virDomainObjNew;
virDomainObjParseNode; virDomainObjParseNode;
virDomainObjSetDefTransient; virDomainObjSetDefTransient;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册