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