4372d3
From 0c09e4225c511ce1b0ebe22e45962f83d5145e66 Mon Sep 17 00:00:00 2001
4372d3
Message-Id: <0c09e4225c511ce1b0ebe22e45962f83d5145e66@dist-git>
4372d3
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
4372d3
Date: Fri, 10 Jun 2022 15:10:29 +0200
4372d3
Subject: [PATCH] conf: virtiofs: add thread_pool element
4372d3
MIME-Version: 1.0
4372d3
Content-Type: text/plain; charset=UTF-8
4372d3
Content-Transfer-Encoding: 8bit
4372d3
4372d3
Add an element to configure the thread pool size:
4372d3
4372d3
...
4372d3
<binary>
4372d3
  <thread_pool size='16'/>
4372d3
</binary>
4372d3
...
4372d3
4372d3
https://bugzilla.redhat.com/show_bug.cgi?id=2072905
4372d3
4372d3
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4372d3
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4372d3
(cherry picked from commit 0df2e7df80452f81edbfeb0ee355235b533346a9)
4372d3
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4372d3
4372d3
https://bugzilla.redhat.com/show_bug.cgi?id=2079582
4372d3
---
4372d3
 docs/formatdomain.rst                             |  6 ++++++
4372d3
 docs/schemas/domaincommon.rng                     |  9 +++++++++
4372d3
 src/conf/domain_conf.c                            | 15 +++++++++++++++
4372d3
 src/conf/domain_conf.h                            |  1 +
4372d3
 .../qemuxml2argvdata/vhost-user-fs-fd-memory.xml  |  1 +
4372d3
 5 files changed, 32 insertions(+)
4372d3
4372d3
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
4372d3
index 17e89a0c0d..e6cf2ec083 100644
4372d3
--- a/docs/formatdomain.rst
4372d3
+++ b/docs/formatdomain.rst
4372d3
@@ -3316,6 +3316,7 @@ A directory on the host that can be accessed directly from the guest.
4372d3
             <cache mode='always'/>
4372d3
             <sandbox mode='namespace'/>
4372d3
             <lock posix='on' flock='on'/>
4372d3
+            <thread_pool size='16'/>
4372d3
          </binary>
4372d3
          <source dir='/path'/>
4372d3
          <target dir='mount_tag'/>
4372d3
@@ -3449,6 +3450,11 @@ A directory on the host that can be accessed directly from the guest.
4372d3
    ``chroot``, see the
4372d3
    `virtiofsd documentation <https://qemu.readthedocs.io/en/latest/tools/virtiofsd.html>`__
4372d3
    for more details. ( :since:`Since 7.2.0` )
4372d3
+   Element ``thread_pool`` accepts one attribute ``size`` which defines the
4372d3
+   maximum thread pool size. A value of "0" disables the pool.
4372d3
+   The thread pool helps increase the number of requests in flight when used with
4372d3
+   storage that has a higher latency.  However, it has an overhead, and so for
4372d3
+   fast, low latency filesystems, it may be best to turn it off. ( :since:`Since 8.5.0` )
4372d3
 ``source``
4372d3
    The resource on the host that is being accessed in the guest. The ``name``
4372d3
    attribute must be used with ``type='template'``, and the ``dir`` attribute
4372d3
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
4372d3
index c9c1529979..79c8979410 100644
4372d3
--- a/docs/schemas/domaincommon.rng
4372d3
+++ b/docs/schemas/domaincommon.rng
4372d3
@@ -3064,6 +3064,15 @@
4372d3
             </optional>
4372d3
           </element>
4372d3
         </optional>
4372d3
+        <optional>
4372d3
+          <element name="thread_pool">
4372d3
+            <optional>
4372d3
+              <attribute name="size">
4372d3
+                <data type="integer"/>
4372d3
+              </attribute>
4372d3
+            </optional>
4372d3
+          </element>
4372d3
+        </optional>
4372d3
       </interleave>
4372d3
     </element>
4372d3
   </define>
4372d3
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
4372d3
index 92510973e6..95afd9226e 100644
4372d3
--- a/src/conf/domain_conf.c
4372d3
+++ b/src/conf/domain_conf.c
4372d3
@@ -2447,6 +2447,8 @@ virDomainFSDefNew(virDomainXMLOption *xmlopt)
4372d3
 
4372d3
     ret->src = virStorageSourceNew();
4372d3
 
4372d3
+    ret->thread_pool_size = -1;
4372d3
+
4372d3
     if (xmlopt &&
4372d3
         xmlopt->privateData.fsNew &&
4372d3
         !(ret->privateData = xmlopt->privateData.fsNew()))
4372d3
@@ -9869,6 +9871,7 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt,
4372d3
     if (def->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
4372d3
         g_autofree char *queue_size = virXPathString("string(./driver/@queue)", ctxt);
4372d3
         g_autofree char *binary = virXPathString("string(./binary/@path)", ctxt);
4372d3
+        g_autofree char *thread_pool_size = virXPathString("string(./binary/thread_pool/@size)", ctxt);
4372d3
         g_autofree char *xattr = virXPathString("string(./binary/@xattr)", ctxt);
4372d3
         g_autofree char *cache = virXPathString("string(./binary/cache/@mode)", ctxt);
4372d3
         g_autofree char *sandbox = virXPathString("string(./binary/sandbox/@mode)", ctxt);
4372d3
@@ -9883,6 +9886,14 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt,
4372d3
             goto error;
4372d3
         }
4372d3
 
4372d3
+        if (thread_pool_size &&
4372d3
+            virStrToLong_i(thread_pool_size, NULL, 10, &def->thread_pool_size) < 0) {
4372d3
+            virReportError(VIR_ERR_XML_ERROR,
4372d3
+                           _("cannot parse thread pool size '%s' for virtiofs"),
4372d3
+                           queue_size);
4372d3
+            goto error;
4372d3
+        }
4372d3
+
4372d3
         if (binary)
4372d3
             def->binary = virFileSanitizePath(binary);
4372d3
 
4372d3
@@ -24205,6 +24216,10 @@ virDomainFSDefFormat(virBuffer *buf,
4372d3
         }
4372d3
 
4372d3
         virXMLFormatElement(&binaryBuf, "lock", &lockAttrBuf, NULL);
4372d3
+
4372d3
+        if (def->thread_pool_size >= 0)
4372d3
+            virBufferAsprintf(&binaryBuf, "<thread_pool size='%d'/>\n", def->thread_pool_size);
4372d3
+
4372d3
     }
4372d3
 
4372d3
     virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
4372d3
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
4372d3
index 10af94e2e4..d0d0fdc815 100644
4372d3
--- a/src/conf/domain_conf.h
4372d3
+++ b/src/conf/domain_conf.h
4372d3
@@ -892,6 +892,7 @@ struct _virDomainFSDef {
4372d3
     virTristateSwitch posix_lock;
4372d3
     virTristateSwitch flock;
4372d3
     virDomainFSSandboxMode sandbox;
4372d3
+    int thread_pool_size;
4372d3
     virDomainVirtioOptions *virtio;
4372d3
     virObject *privateData;
4372d3
 };
4372d3
diff --git a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
4372d3
index abddf0870b..81de8c0dd7 100644
4372d3
--- a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
4372d3
+++ b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
4372d3
@@ -32,6 +32,7 @@
4372d3
         <cache mode='always'/>
4372d3
         <sandbox mode='chroot'/>
4372d3
         <lock posix='off' flock='off'/>
4372d3
+        <thread_pool size='16'/>
4372d3
       </binary>
4372d3
       <source dir='/path'/>
4372d3
       <target dir='mount_tag'/>
4372d3
-- 
4372d3
2.35.1
4372d3