From 9c47d2754ca23cac41e993631b4dfdab2eee288b Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 20 May 2020 12:00:23 +0200 Subject: [PATCH] qemuBuildNumaCommandLine: Separate out building of CPU list Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_command.c | 43 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 247ac86e33..402ff44213 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7281,6 +7281,31 @@ qemuBuildNumaHMATCommandLine(virCommand *cmd, } +static int +qemuBuildNumaCPUs(virBuffer *buf, + virBitmap *cpu) +{ + g_autofree char *cpumask = NULL; + char *tmpmask = NULL; + char *next = NULL; + + if (!cpu) + return 0; + + if (!(cpumask = virBitmapFormat(cpu))) + return -1; + + for (tmpmask = cpumask; tmpmask; tmpmask = next) { + if ((next = strchr(tmpmask, ','))) + *(next++) = '\0'; + virBufferAddLit(buf, ",cpus="); + virBufferAdd(buf, tmpmask, -1); + } + + return 0; +} + + static int qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg, virDomainDef *def, @@ -7347,7 +7372,6 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg, } for (i = 0; i < ncells; i++) { - virBitmap *cpumask = virDomainNumaGetNodeCpumask(def->numa, i); ssize_t initiator = virDomainNumaGetNodeInitiator(def->numa, i); if (needBackend) { @@ -7358,21 +7382,8 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg, virCommandAddArg(cmd, "-numa"); virBufferAsprintf(&buf, "node,nodeid=%zu", i); - if (cpumask) { - g_autofree char *cpumaskStr = NULL; - char *next = NULL; - char *tmpmask; - - if (!(cpumaskStr = virBitmapFormat(cpumask))) - goto cleanup; - - for (tmpmask = cpumaskStr; tmpmask; tmpmask = next) { - if ((next = strchr(tmpmask, ','))) - *(next++) = '\0'; - virBufferAddLit(&buf, ",cpus="); - virBufferAdd(&buf, tmpmask, -1); - } - } + if (qemuBuildNumaCPUs(&buf, virDomainNumaGetNodeCpumask(def->numa, i)) < 0) + goto cleanup; if (hmat) { if (initiator < 0)