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