[libvirt] [PATCH 0/2] refactor virDomainSchedulerFormat

*** BLURB HERE *** Ján Tomko (2): conf: pass the element/attribute names to virSchedulerFormat conf: switch virDomainSchedulerFormat to use virXMLFormatElement src/conf/domain_conf.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) -- 2.19.2

Instead of constructing them dynamically from a base name, pass the two different static strings. While adjusting the callers, also expect a negative return value. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/conf/domain_conf.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b969a9f6e5..93d32c9df1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27189,26 +27189,27 @@ virDomainPerfDefFormat(virBufferPtr buf, virDomainPerfDefPtr perf) } -static void +static int virDomainSchedulerFormat(virBufferPtr buf, - const char *name, + const char *elementName, + const char *idAttributeName, virDomainThreadSchedParamPtr sched, size_t id) { switch (sched->policy) { case VIR_PROC_POLICY_BATCH: case VIR_PROC_POLICY_IDLE: - virBufferAsprintf(buf, "<%ssched " - "%ss='%zu' scheduler='%s'/>\n", - name, name, id, + virBufferAsprintf(buf, "<%s " + "%s='%zu' scheduler='%s'/>\n", + elementName, idAttributeName, id, virProcessSchedPolicyTypeToString(sched->policy)); break; case VIR_PROC_POLICY_RR: case VIR_PROC_POLICY_FIFO: - virBufferAsprintf(buf, "<%ssched " - "%ss='%zu' scheduler='%s' priority='%d'/>\n", - name, name, id, + virBufferAsprintf(buf, "<%s " + "%s='%zu' scheduler='%s' priority='%d'/>\n", + elementName, idAttributeName, id, virProcessSchedPolicyTypeToString(sched->policy), sched->priority); break; @@ -27218,6 +27219,7 @@ virDomainSchedulerFormat(virBufferPtr buf, break; } + return 0; } @@ -27476,14 +27478,16 @@ virDomainCputuneDefFormat(virBufferPtr buf, } for (i = 0; i < def->maxvcpus; i++) { - virDomainSchedulerFormat(&childrenBuf, "vcpu", - &def->vcpus[i]->sched, i); + if (virDomainSchedulerFormat(&childrenBuf, "vcpusched", "vcpus", + &def->vcpus[i]->sched, i) < 0) + goto cleanup; } for (i = 0; i < def->niothreadids; i++) { - virDomainSchedulerFormat(&childrenBuf, "iothread", - &def->iothreadids[i]->sched, - def->iothreadids[i]->iothread_id); + if (virDomainSchedulerFormat(&childrenBuf, "iothreadsched", "iothreads", + &def->iothreadids[i]->sched, + def->iothreadids[i]->iothread_id) < 0) + goto cleanup; } for (i = 0; i < def->nresctrls; i++) -- 2.19.2

On Mon, 2019-04-15 at 16:55 +0200, Ján Tomko wrote:
Instead of constructing them dynamically from a base name, pass the two different static strings.
While adjusting the callers, also expect a negative return value.
Changing the arguments and changing the return value should happen in separate commits. Commit looks good otherwise. -- Andrea Bolognani / Red Hat / Virtualization

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/conf/domain_conf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 93d32c9df1..1f44237b11 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27196,30 +27196,30 @@ virDomainSchedulerFormat(virBufferPtr buf, virDomainThreadSchedParamPtr sched, size_t id) { + VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + switch (sched->policy) { case VIR_PROC_POLICY_BATCH: case VIR_PROC_POLICY_IDLE: - virBufferAsprintf(buf, "<%s " - "%s='%zu' scheduler='%s'/>\n", - elementName, idAttributeName, id, + virBufferAsprintf(&attrBuf, " %s='%zu'", idAttributeName, id); + virBufferAsprintf(&attrBuf, " scheduler='%s'", virProcessSchedPolicyTypeToString(sched->policy)); break; case VIR_PROC_POLICY_RR: case VIR_PROC_POLICY_FIFO: - virBufferAsprintf(buf, "<%s " - "%s='%zu' scheduler='%s' priority='%d'/>\n", - elementName, idAttributeName, id, - virProcessSchedPolicyTypeToString(sched->policy), - sched->priority); + virBufferAsprintf(&attrBuf, " %s='%zu'", idAttributeName, id); + virBufferAsprintf(&attrBuf, " scheduler='%s'", + virProcessSchedPolicyTypeToString(sched->policy)); + virBufferAsprintf(&attrBuf, " priority='%d'", sched->priority); break; case VIR_PROC_POLICY_NONE: case VIR_PROC_POLICY_LAST: - break; + return 0; } - return 0; + return virXMLFormatElement(buf, elementName, &attrBuf, NULL); } -- 2.19.2

On Mon, 2019-04-15 at 16:55 +0200, Ján Tomko wrote: [...]
switch (sched->policy) { case VIR_PROC_POLICY_BATCH: case VIR_PROC_POLICY_IDLE: - virBufferAsprintf(buf, "<%s " - "%s='%zu' scheduler='%s'/>\n", - elementName, idAttributeName, id, + virBufferAsprintf(&attrBuf, " %s='%zu'", idAttributeName, id); + virBufferAsprintf(&attrBuf, " scheduler='%s'", virProcessSchedPolicyTypeToString(sched->policy));
Since these two attributes (idAttributeName and 'scheduler') are formatted the same way for the two cases below, how about replacing the 'break' with 'ATTRIBUTE_FALLTHROUGH' to avoid repetition? I'm also not sure why you turned a single call to virBufferAsprintf() into two or three separate calls to it. Looks good otherwise. -- Andrea Bolognani / Red Hat / Virtualization
participants (2)
-
Andrea Bolognani
-
Ján Tomko