[libvirt PATCH 2/3] conf: pass elementName to virDomainThreadSchedParseHelper

Ján Tomko jtomko at redhat.com
Mon Jul 27 13:15:45 UTC 2020


Pass the scheduler element name instead of trying to reconstructing
it from the attribute name.

This has the benefit of not mixing '%s' with regular text in
translatable strings as well as preventing the confusion when
the 's' marking the plural in the element name ('vcpus') is taken
as a first letter of the 'sched' suffix.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
Fixes: 7ea55a481dd45f09b54425005362533ecc800cd2
Fixes: 99c5fe0e7c26c08103415248ffef1f5acb81ddc7
---
 src/conf/domain_conf.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fd968635fe..0f12b54575 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19965,6 +19965,7 @@ virDomainEmulatorSchedParse(xmlNodePtr node,
 
 static virBitmapPtr
 virDomainSchedulerParse(xmlNodePtr node,
+                        const char *elementName,
                         const char *attributeName,
                         virProcessSchedPolicy *policy,
                         int *priority)
@@ -19974,8 +19975,8 @@ virDomainSchedulerParse(xmlNodePtr node,
 
     if (!(tmp = virXMLPropString(node, attributeName))) {
         virReportError(VIR_ERR_XML_ERROR,
-                       _("Missing attribute '%s' in element '%sched'"),
-                       attributeName, attributeName);
+                       _("Missing attribute '%s' in element '%s'"),
+                       attributeName, elementName);
         goto error;
     }
 
@@ -20002,6 +20003,7 @@ virDomainSchedulerParse(xmlNodePtr node,
 
 static int
 virDomainThreadSchedParseHelper(xmlNodePtr node,
+                                const char *elementName,
                                 const char *attributeName,
                                 virDomainThreadSchedParamPtr (*func)(virDomainDefPtr, unsigned int),
                                 virDomainDefPtr def)
@@ -20012,7 +20014,8 @@ virDomainThreadSchedParseHelper(xmlNodePtr node,
     int priority = 0;
     g_autoptr(virBitmap) map = NULL;
 
-    if (!(map = virDomainSchedulerParse(node, attributeName, &policy, &priority)))
+    if (!(map = virDomainSchedulerParse(node, elementName, attributeName,
+                                        &policy, &priority)))
         return -1;
 
     while ((next = virBitmapNextSetBit(map, next)) > -1) {
@@ -20021,8 +20024,8 @@ virDomainThreadSchedParseHelper(xmlNodePtr node,
 
         if (sched->policy != VIR_PROC_POLICY_NONE) {
             virReportError(VIR_ERR_XML_DETAIL,
-                           _("%ssched attributes 'vcpus' must not overlap"),
-                           STREQ(attributeName, "vcpus") ? "vcpu" : attributeName);
+                           _("'%s' attributes 'vcpus' must not overlap"),
+                           elementName);
             return -1;
         }
 
@@ -20038,7 +20041,9 @@ static int
 virDomainVcpuThreadSchedParse(xmlNodePtr node,
                               virDomainDefPtr def)
 {
-    return virDomainThreadSchedParseHelper(node, "vcpus",
+    return virDomainThreadSchedParseHelper(node,
+                                           "vcpusched",
+                                           "vcpus",
                                            virDomainDefGetVcpuSched,
                                            def);
 }
@@ -20065,7 +20070,9 @@ static int
 virDomainIOThreadSchedParse(xmlNodePtr node,
                             virDomainDefPtr def)
 {
-    return virDomainThreadSchedParseHelper(node, "iothreads",
+    return virDomainThreadSchedParseHelper(node,
+                                           "iothreadsched",
+                                           "iothreads",
                                            virDomainDefGetIOThreadSched,
                                            def);
 }
-- 
2.26.2




More information about the libvir-list mailing list