Add support for the iothread poll-weight XML attribute.

Store the value in the internal iothread definition, parse it from
the <poll/> element, and format it back into domain XML. Also extend
the schema to accept the new attribute and enforce the accepted
range of [0, 63] in the domain validator.

Signed-off-by: Jaehoon Kim <[email protected]>
---
 src/conf/domain_conf.c                     | 14 +++++++++++++-
 src/conf/domain_conf.h                     |  2 ++
 src/conf/domain_validate.c                 |  7 +++++++
 src/conf/schemas/domaincommon.rng          |  5 +++++
 tests/genericxml2xmlindata/iothreadids.xml |  2 +-
 5 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 45235d74bc..0cd0a22708 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16988,7 +16988,9 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
  *
  *     <iothreads>4</iothreads>
  *     <iothreadids>
- *       <iothread id='1' thread_pool_min="0" thread_pool_max="60"/>
+ *       <iothread id='1' thread_pool_min="0" thread_pool_max="60">
+ *         <poll max='32000' grow='2' shrink='2' weight='3'/>
+ *       </iothread>
  *       <iothread id='3'/>
  *       <iothread id='5'/>
  *       <iothread id='7'/>
@@ -17036,6 +17038,12 @@ virDomainIOThreadIDDefParseXML(xmlNodePtr node)
             return NULL;
 
         iothrid->set_poll_shrink = rc == 1;
+
+        if ((rc = virXMLPropUInt(pollNode, "weight", 10, VIR_XML_PROP_NONE,
+                                 &iothrid->poll_weight)) < 0)
+            return NULL;
+
+        iothrid->set_poll_weight = rc == 1;
     }
 
     return g_steal_pointer(&iothrid);
@@ -29015,6 +29023,7 @@ virDomainDefIothreadShouldFormat(const virDomainDef 
*def)
             def->iothreadids[i]->set_poll_max_ns ||
             def->iothreadids[i]->set_poll_grow ||
             def->iothreadids[i]->set_poll_shrink ||
+            def->iothreadids[i]->set_poll_weight ||
             def->iothreadids[i]->thread_pool_min >= 0 ||
             def->iothreadids[i]->thread_pool_max >= 0)
             return true;
@@ -29088,6 +29097,9 @@ virDomainDefIOThreadsFormat(virBuffer *buf,
             if (iothread->set_poll_shrink)
                 virBufferAsprintf(&pollAttrBuf, " shrink='%llu'", 
iothread->poll_shrink);
 
+            if (iothread->set_poll_weight)
+                virBufferAsprintf(&pollAttrBuf, " weight='%u'", 
iothread->poll_weight);
+
             virXMLFormatElement(&iothreadChildBuf, "poll", &pollAttrBuf, NULL);
 
             virXMLFormatElement(&childrenBuf, "iothread", &attrBuf, 
&iothreadChildBuf);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 91f57de0f1..57c26d4070 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2902,6 +2902,8 @@ struct _virDomainIOThreadIDDef {
     bool set_poll_grow;
     unsigned long long poll_shrink;
     bool set_poll_shrink;
+    unsigned int poll_weight;
+    bool set_poll_weight;
 
     int thread_pool_min;
     int thread_pool_max;
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 3946f92182..ab998de716 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -1931,6 +1931,13 @@ virDomainDefValidateIOThreads(const virDomainDef *def)
         if (virDomainDefValidateIOThreadsThreadPool(iothread->thread_pool_min,
                                                     iothread->thread_pool_max) 
< 0)
             return -1;
+
+        if (iothread->set_poll_weight && iothread->poll_weight > 63) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("poll weight %1$u is out of range [0, 63]"),
+                           iothread->poll_weight);
+            return -1;
+        }
     }
 
     if (def->defaultIOThread &&
diff --git a/src/conf/schemas/domaincommon.rng 
b/src/conf/schemas/domaincommon.rng
index 81ffbfc2fa..1b6f972cec 100644
--- a/src/conf/schemas/domaincommon.rng
+++ b/src/conf/schemas/domaincommon.rng
@@ -990,6 +990,11 @@
                       <ref name="unsignedLong"/>
                     </attribute>
                   </optional>
+                  <optional>
+                    <attribute name="weight">
+                      <ref name="unsignedInt"/>
+                    </attribute>
+                  </optional>
                 </element>
               </optional>
             </element>
diff --git a/tests/genericxml2xmlindata/iothreadids.xml 
b/tests/genericxml2xmlindata/iothreadids.xml
index 671a467295..e9814854eb 100644
--- a/tests/genericxml2xmlindata/iothreadids.xml
+++ b/tests/genericxml2xmlindata/iothreadids.xml
@@ -7,7 +7,7 @@
   <iothreads>1</iothreads>
   <iothreadids>
     <iothread id='8' thread_pool_min='2147483647' thread_pool_max='2147483647'>
-      <poll max='9223372036854775807' grow='456' shrink='789'/>
+      <poll max='9223372036854775807' grow='456' shrink='789' weight='3'/>
     </iothread>
   </iothreadids>
   <os>
-- 
2.54.0

Reply via email to