提交 6245296f 编写于 作者: P Peter Krempa

conf: capabilities: Modernize virCapabilitiesFormatMemoryBandwidth

Use virXMLFormatElement and the automatic memory handlers to simplfy the
code.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 3ca2bdef
......@@ -1024,7 +1024,6 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf,
virCapsHostMemBWPtr memBW)
{
size_t i = 0;
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
if (!memBW->nnodes)
return 0;
......@@ -1033,17 +1032,18 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf,
virBufferAdjustIndent(buf, 2);
for (i = 0; i < memBW->nnodes; i++) {
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER;
virCapsHostMemBWNodePtr node = memBW->nodes[i];
virResctrlInfoMemBWPerNodePtr control = &node->control;
char *cpus_str = virBitmapFormat(node->cpus);
g_autofree char *cpus_str = virBitmapFormat(node->cpus);
if (!cpus_str)
return -1;
virBufferAsprintf(buf,
"<node id='%u' cpus='%s'",
virBufferAsprintf(&attrBuf,
" id='%u' cpus='%s'",
node->id, cpus_str);
VIR_FREE(cpus_str);
virBufferSetChildIndent(&childrenBuf, buf);
virBufferAsprintf(&childrenBuf,
......@@ -1052,13 +1052,7 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf,
control->granularity, control->min,
control->max_allocation);
if (virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childrenBuf);
virBufferAddLit(buf, "</node>\n");
} else {
virBufferAddLit(buf, "/>\n");
}
virXMLFormatElement(buf, "node", &attrBuf, &childrenBuf);
}
if (virCapabilitiesFormatResctrlMonitor(buf, memBW->monitor) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册