From b20ae99e1df034df244bb95ade6c179cbda8cb31 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 4 Nov 2025 12:23:58 +0100 Subject: [PATCH] domain_capabilities: Rework virDomainCapsCPUFormat() Make the virDomainCapsCPUFormat() function use virXMLFormatElement() family of functions. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/domain_capabilities.c | 77 ++++++++++++++++------------------ 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c index 443e6dcd8e..1c69a05685 100644 --- a/src/conf/domain_capabilities.c +++ b/src/conf/domain_capabilities.c @@ -488,67 +488,64 @@ static void virDomainCapsCPUFormat(virBuffer *buf, const virDomainCapsCPU *cpu) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - - virBufferAsprintf(buf, "hostPassthrough ? "yes" : "no"); if (cpu->hostPassthrough && cpu->hostPassthroughMigratable.report) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - ENUM_PROCESS(cpu, hostPassthroughMigratable, - virTristateSwitchTypeToString); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); + virDomainCapsEnumFormat(&hostPassModeChildBuf, + &cpu->hostPassthroughMigratable, + "hostPassthroughMigratable", + virTristateSwitchTypeToString); } - virBufferAsprintf(buf, "maximum ? "yes" : "no"); if (cpu->maximum && cpu->maximumMigratable.report) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - ENUM_PROCESS(cpu, maximumMigratable, - virTristateSwitchTypeToString); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); + virDomainCapsEnumFormat(&maxModeChildBuf, + &cpu->maximumMigratable, + "maximumMigratable", + virTristateSwitchTypeToString); } - virBufferAsprintf(buf, "hostModel) { - virBufferAddLit(buf, "supported='yes'>\n"); - virBufferAdjustIndent(buf, 2); + virXMLFormatElement(&childBuf, "mode", &maxModeAttrBuf, &maxModeChildBuf); - virCPUDefFormatBuf(buf, cpu->hostModel); + virBufferAsprintf(&hostModeAttrBuf, " name='%s' supported='%s'", + virCPUModeTypeToString(VIR_CPU_MODE_HOST_MODEL), + cpu->hostModel ? "yes" : "no"); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "supported='no'/>\n"); + if (cpu->hostModel) { + virCPUDefFormatBuf(&hostModeChildBuf, cpu->hostModel); } - virBufferAsprintf(buf, "custom && cpu->custom->nmodels) { - virBufferAddLit(buf, "supported='yes'>\n"); - virBufferAdjustIndent(buf, 2); - virDomainCapsCPUCustomFormat(buf, cpu->custom); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virBufferAddLit(&customModeAttrBuf, " supported='yes'"); + virDomainCapsCPUCustomFormat(&customModeChildBuf, cpu->custom); } else { - virBufferAddLit(buf, "supported='no'/>\n"); + virBufferAddLit(&customModeAttrBuf, " supported='no'"); } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virXMLFormatElement(&childBuf, "mode", &customModeAttrBuf, &customModeChildBuf); + + virXMLFormatElement(buf, "cpu", NULL, &childBuf); } static void -- 2.47.3