mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
conf: Remove virDomainResctrlAppend and introduce virDomainResctrlNew
Introduced virDomainResctrlNew to do the most part of virDomainResctrlAppend and move the operation of appending resctrl to @def->resctrls out of function. Rather than rely on virDomainResctrlAppend to perform the allocation, move the onus to the caller and make use of virBitmapNewCopy for @vcpus and virObjectRef for @alloc, thus removing the need to set each to NULL after the call. Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
3f2214c2cd
commit
a54824e7d0
@ -18921,26 +18921,22 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static virDomainResctrlDefPtr
|
||||||
virDomainResctrlAppend(virDomainDefPtr def,
|
virDomainResctrlNew(xmlNodePtr node,
|
||||||
xmlNodePtr node,
|
virResctrlAllocPtr alloc,
|
||||||
virResctrlAllocPtr alloc,
|
virBitmapPtr vcpus,
|
||||||
virBitmapPtr vcpus,
|
unsigned int flags)
|
||||||
unsigned int flags)
|
|
||||||
{
|
{
|
||||||
char *vcpus_str = NULL;
|
char *vcpus_str = NULL;
|
||||||
char *alloc_id = NULL;
|
char *alloc_id = NULL;
|
||||||
virDomainResctrlDefPtr tmp_resctrl = NULL;
|
virDomainResctrlDefPtr resctrl = NULL;
|
||||||
int ret = -1;
|
virDomainResctrlDefPtr ret = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(tmp_resctrl) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
/* We need to format it back because we need to be consistent in the naming
|
/* We need to format it back because we need to be consistent in the naming
|
||||||
* even when users specify some "sub-optimal" string there. */
|
* even when users specify some "sub-optimal" string there. */
|
||||||
vcpus_str = virBitmapFormat(vcpus);
|
vcpus_str = virBitmapFormat(vcpus);
|
||||||
if (!vcpus_str)
|
if (!vcpus_str)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
|
if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
|
||||||
alloc_id = virXMLPropString(node, "id");
|
alloc_id = virXMLPropString(node, "id");
|
||||||
@ -18958,15 +18954,20 @@ virDomainResctrlAppend(virDomainDefPtr def,
|
|||||||
if (virResctrlAllocSetID(alloc, alloc_id) < 0)
|
if (virResctrlAllocSetID(alloc, alloc_id) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
tmp_resctrl->vcpus = vcpus;
|
if (VIR_ALLOC(resctrl) < 0)
|
||||||
tmp_resctrl->alloc = alloc;
|
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, tmp_resctrl) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
if (!(resctrl->vcpus = virBitmapNewCopy(vcpus))) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("failed to copy 'vcpus'"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
resctrl->alloc = virObjectRef(alloc);
|
||||||
|
|
||||||
|
VIR_STEAL_PTR(ret, resctrl);
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainResctrlDefFree(tmp_resctrl);
|
virDomainResctrlDefFree(resctrl);
|
||||||
VIR_FREE(alloc_id);
|
VIR_FREE(alloc_id);
|
||||||
VIR_FREE(vcpus_str);
|
VIR_FREE(vcpus_str);
|
||||||
return ret;
|
return ret;
|
||||||
@ -18983,6 +18984,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
|
|||||||
xmlNodePtr *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
virBitmapPtr vcpus = NULL;
|
virBitmapPtr vcpus = NULL;
|
||||||
virResctrlAllocPtr alloc = NULL;
|
virResctrlAllocPtr alloc = NULL;
|
||||||
|
virDomainResctrlDefPtr resctrl = NULL;
|
||||||
ssize_t i = 0;
|
ssize_t i = 0;
|
||||||
int n;
|
int n;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -19021,19 +19023,22 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resctrl = virDomainResctrlNew(node, alloc, vcpus, flags);
|
||||||
|
if (!resctrl)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (virResctrlAllocIsEmpty(alloc)) {
|
if (virResctrlAllocIsEmpty(alloc)) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainResctrlAppend(def, node, alloc, vcpus, flags) < 0)
|
if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, resctrl) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
vcpus = NULL;
|
|
||||||
alloc = NULL;
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
ctxt->node = oldnode;
|
ctxt->node = oldnode;
|
||||||
|
virDomainResctrlDefFree(resctrl);
|
||||||
virObjectUnref(alloc);
|
virObjectUnref(alloc);
|
||||||
virBitmapFree(vcpus);
|
virBitmapFree(vcpus);
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
@ -19191,6 +19196,8 @@ virDomainMemorytuneDefParse(virDomainDefPtr def,
|
|||||||
xmlNodePtr *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
virBitmapPtr vcpus = NULL;
|
virBitmapPtr vcpus = NULL;
|
||||||
virResctrlAllocPtr alloc = NULL;
|
virResctrlAllocPtr alloc = NULL;
|
||||||
|
virDomainResctrlDefPtr resctrl = NULL;
|
||||||
|
|
||||||
ssize_t i = 0;
|
ssize_t i = 0;
|
||||||
int n;
|
int n;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -19235,15 +19242,18 @@ virDomainMemorytuneDefParse(virDomainDefPtr def,
|
|||||||
* just update the existing alloc information, which is done in above
|
* just update the existing alloc information, which is done in above
|
||||||
* virDomainMemorytuneDefParseMemory */
|
* virDomainMemorytuneDefParseMemory */
|
||||||
if (new_alloc) {
|
if (new_alloc) {
|
||||||
if (virDomainResctrlAppend(def, node, alloc, vcpus, flags) < 0)
|
resctrl = virDomainResctrlNew(node, alloc, vcpus, flags);
|
||||||
|
if (!resctrl)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, resctrl) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
vcpus = NULL;
|
|
||||||
alloc = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
ctxt->node = oldnode;
|
ctxt->node = oldnode;
|
||||||
|
virDomainResctrlDefFree(resctrl);
|
||||||
virObjectUnref(alloc);
|
virObjectUnref(alloc);
|
||||||
virBitmapFree(vcpus);
|
virBitmapFree(vcpus);
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
|
Loading…
Reference in New Issue
Block a user