[libvirt PATCHv3 06/12] conf: add virtiofs-related elements and attributes

Ján Tomko posted 12 patches 6 years ago
There is a newer version of this series
[libvirt PATCHv3 06/12] conf: add virtiofs-related elements and attributes
Posted by Ján Tomko 6 years ago
Add more elements for tuning the virtiofsd daemon
and the vhost-user-fs device:

  <driver type='virtiofs' queue='1024' xattr='on'>
    <binary>/usr/libexec/virtiofsd</binary>
    <cache mode='always' size='2097152' unit='KiB'/>
    <lock posix='off' flock='off'/>
  </driver>

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 docs/formatdomain.html.in                     |  25 +++-
 docs/schemas/domaincommon.rng                 |  48 ++++++++
 src/conf/domain_conf.c                        | 107 +++++++++++++++++-
 src/conf/domain_conf.h                        |  15 +++
 src/libvirt_private.syms                      |   1 +
 .../vhost-user-fs-fd-memory.xml               |   6 +-
 .../vhost-user-fs-hugepages.xml               |   1 +
 7 files changed, 200 insertions(+), 3 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index d5565361ab..58e06d21f5 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3922,10 +3922,15 @@
     &lt;readonly/&gt;
   &lt;/filesystem&gt;
   &lt;filesystem type='mount' accessmode='passthrough'&gt;
-      &lt;driver type='virtiofs'/&gt;
+      &lt;driver type='virtiofs queue='1024'/&gt;
+      &lt;binary path='/usr/libexec/virtiofsd' xattr='on'&gt;
+         &lt;cache mode='always'/&gt;
+         &lt;lock posix='on' flock='on'/&gt;
+      &lt;/binary&gt;
       &lt;source dir='/path'/&gt;
       &lt;target dir='mount_tag'/&gt;
   &lt;/filesystem&gt;
+
   ...
 &lt;/devices&gt;
 ...</pre>
@@ -4049,9 +4054,27 @@
           <a href="#elementsVirtio">Virtio-specific options</a> can also be
           set. (<span class="since">Since 3.5.0</span>)
           </li>
+          <li>
+            For <code>virtiofs</code>, the <code>queue</code> attribute can be used
+            to specify the queue size (i.e. how many requests can the queue fit).
+            (<span class="since">Since 6.1.0</span>)
+          </li>
         </ul>
       </dd>
 
+      <dt><code>binary</code></dt>
+      <dd>
+        The optional <code>binary</code> element can tune the options for virtiofsd.
+        The attribute <code>path</code> can be used to override the path to the daemon.
+        Attribute <code>xattr</code> enables the use of filesystem extended attributes.
+        Caching can be tuned via the <code>cache</code> element, possible <code>mode</code>
+        values being <code>none</code> and <code>always</code>.
+        Locking can be controlled via the <code>lock</code>
+        element - attributes <code>posix</code> and <code>flock</code> both accepting
+        values <code>yes</code> or <code>no</code>.
+        (<span class="since">Since 6.1.0</span>)
+      </dd>
+
       <dt><code>source</code></dt>
       <dd>
         The resource on the host that is being accessed in the guest. The
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index e30b82c57e..db475a43ca 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2480,6 +2480,9 @@
           <optional>
             <ref name="fsDriver"/>
           </optional>
+          <optional>
+            <ref name="fsBinary"/>
+          </optional>
           <interleave>
             <element name="source">
               <attribute name="dir">
@@ -2629,12 +2632,57 @@
           <attribute name="type">
             <value>virtiofs</value>
           </attribute>
+          <optional>
+            <attribute name="queue">
+              <ref name="unsignedInt"/>
+            </attribute>
+          </optional>
           <ref name='virtioOptions'/>
         </group>
         <empty/>
       </choice>
     </element>
   </define>
+  <define name="fsBinary">
+    <element name="binary">
+      <optional>
+        <attribute name="path">
+          <ref name="absFilePath"/>
+        </attribute>
+      </optional>
+      <optional>
+        <attribute name="xattr">
+          <ref name="virOnOff"/>
+        </attribute>
+      </optional>
+      <optional>
+        <element name="cache">
+          <optional>
+            <attribute name="mode">
+              <choice>
+                <value>none</value>
+                <value>always</value>
+              </choice>
+            </attribute>
+          </optional>
+        </element>
+      </optional>
+      <optional>
+        <element name="lock">
+          <optional>
+            <attribute name="posix">
+              <ref name="virOnOff"/>
+            </attribute>
+          </optional>
+          <optional>
+            <attribute name="flock">
+              <ref name="virOnOff"/>
+            </attribute>
+          </optional>
+        </element>
+      </optional>
+    </element>
+  </define>
 
   <define name="interface-network-attributes">
     <attribute name="network">
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d1a6d125d7..5c26e0d06c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -501,6 +501,14 @@ VIR_ENUM_IMPL(virDomainFSModel,
               "virtio-non-transitional",
 );
 
+VIR_ENUM_IMPL(virDomainFSCacheMode,
+              VIR_DOMAIN_FS_CACHE_MODE_LAST,
+              "default",
+              "none",
+              "always",
+);
+
+
 VIR_ENUM_IMPL(virDomainNet,
               VIR_DOMAIN_NET_TYPE_LAST,
               "user",
@@ -2322,6 +2330,7 @@ void virDomainFSDefFree(virDomainFSDefPtr def)
     VIR_FREE(def->dst);
     virDomainDeviceInfoClear(&def->info);
     VIR_FREE(def->virtio);
+    VIR_FREE(def->binary);
 
     VIR_FREE(def);
 }
@@ -11254,6 +11263,64 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
         }
     }
 
+    if (def->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
+        g_autofree char *queue_size = virXPathString("string(./driver/@queue)", ctxt);
+        g_autofree char *binary = virXPathString("string(./binary/@path)", ctxt);
+        g_autofree char *xattr = virXPathString("string(./binary/@xattr)", ctxt);
+        g_autofree char *cache = virXPathString("string(./binary/cache/@mode)", ctxt);
+        g_autofree char *posix_lock = virXPathString("string(./binary/lock/@posix)", ctxt);
+        g_autofree char *flock = virXPathString("string(./binary/lock/@flock)", ctxt);
+        int val;
+
+
+        if (queue_size && virStrToLong_ull(queue_size, NULL, 10, &def->queue_size) < 0) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("cannot parse queue size '%s' for virtiofs"),
+                           queue_size);
+            goto error;
+        }
+
+        if (binary)
+            def->binary = virFileSanitizePath(binary);
+
+        if (xattr) {
+            if ((val = virTristateSwitchTypeFromString(xattr)) <= 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("unknown xattr value '%s'"), xattr);
+                goto error;
+            }
+            def->xattr = val;
+        }
+
+        if (cache) {
+            if ((val = virDomainFSCacheModeTypeFromString(cache)) <= 0) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("cannot parse cache mode '%s' for virtiofs"),
+                               cache);
+                goto error;
+            }
+            def->cache = val;
+        }
+
+        if (posix_lock) {
+            if ((val = virTristateSwitchTypeFromString(posix_lock)) <= 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("unknown posix lock value '%s'"), posix_lock);
+                goto error;
+            }
+            def->posix_lock = val;
+        }
+
+        if (flock) {
+            if ((val = virTristateSwitchTypeFromString(flock)) <= 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("unknown flock value '%s'"), flock);
+                goto error;
+            }
+            def->flock = val;
+        }
+    }
+
     if (format) {
         if ((def->format = virStorageFileFormatTypeFromString(format)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -25053,6 +25120,9 @@ virDomainFSDefFormat(virBufferPtr buf,
     const char *wrpolicy = virDomainFSWrpolicyTypeToString(def->wrpolicy);
     const char *src = def->src->path;
     g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
+    g_auto(virBuffer) driverBuf = VIR_BUFFER_INIT_CHILD(buf);
+    g_auto(virBuffer) binaryAttrBuf = VIR_BUFFER_INITIALIZER;
+    g_auto(virBuffer) binaryBuf = VIR_BUFFER_INIT_CHILD(buf);
 
     if (!type) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -25076,6 +25146,8 @@ virDomainFSDefFormat(virBufferPtr buf,
     virBufferAddLit(buf, ">\n");
 
     virBufferAdjustIndent(buf, 2);
+    virBufferAdjustIndent(&driverBuf, 2);
+    virBufferAdjustIndent(&binaryBuf, 2);
     if (def->fsdriver) {
         virBufferAsprintf(&driverAttrBuf, " type='%s'", fsdriver);
 
@@ -25087,11 +25159,44 @@ virDomainFSDefFormat(virBufferPtr buf,
         if (def->wrpolicy)
             virBufferAsprintf(&driverAttrBuf, " wrpolicy='%s'", wrpolicy);
 
+        if (def->queue_size)
+            virBufferAsprintf(&driverAttrBuf, " queue='%llu'", def->queue_size);
+
+    }
+
+    if (def->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
+        g_auto(virBuffer) lockAttrBuf = VIR_BUFFER_INITIALIZER;
+        virBufferEscapeString(&binaryAttrBuf, " path='%s'", def->binary);
+
+        if (def->xattr != VIR_TRISTATE_SWITCH_ABSENT) {
+            virBufferAsprintf(&binaryAttrBuf, " xattr='%s'",
+                              virTristateSwitchTypeToString(def->xattr));
+        }
+
+        if (def->cache != VIR_DOMAIN_FS_CACHE_MODE_DEFAULT) {
+            virBufferAsprintf(&binaryBuf, "<cache mode='%s'/>\n",
+                              virDomainFSCacheModeTypeToString(def->cache));
+        }
+
+        if (def->posix_lock != VIR_TRISTATE_SWITCH_ABSENT) {
+            virBufferAsprintf(&lockAttrBuf, " posix='%s'",
+                              virTristateSwitchTypeToString(def->posix_lock));
+        }
+
+        if (def->flock != VIR_TRISTATE_SWITCH_ABSENT) {
+            virBufferAsprintf(&lockAttrBuf, " flock='%s'",
+                              virTristateSwitchTypeToString(def->flock));
+        }
+
+        virXMLFormatElement(&binaryBuf, "lock", &lockAttrBuf, NULL);
     }
 
+
     virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
 
-    virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
+    virXMLFormatElement(buf, "driver", &driverAttrBuf, &driverBuf);
+    virXMLFormatElement(buf, "binary", &binaryAttrBuf, &binaryBuf);
+    virXMLFormatElement(buf, "driver", &driverAttrBuf, &driverBuf);
 
     switch (def->type) {
     case VIR_DOMAIN_FS_TYPE_MOUNT:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index de2bd3be93..21a36c34ef 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -804,6 +804,14 @@ typedef enum {
     VIR_DOMAIN_FS_MODEL_LAST
 } virDomainFSModel;
 
+typedef enum {
+    VIR_DOMAIN_FS_CACHE_MODE_DEFAULT = 0,
+    VIR_DOMAIN_FS_CACHE_MODE_NONE,
+    VIR_DOMAIN_FS_CACHE_MODE_ALWAYS,
+
+    VIR_DOMAIN_FS_CACHE_MODE_LAST
+} virDomainFSCacheMode;
+
 struct _virDomainFSDef {
     int type;
     int fsdriver; /* enum virDomainFSDriverType */
@@ -819,6 +827,12 @@ struct _virDomainFSDef {
     unsigned long long space_hard_limit; /* in bytes */
     unsigned long long space_soft_limit; /* in bytes */
     bool symlinksResolved;
+    char *binary;
+    unsigned long long queue_size;
+    virTristateSwitch xattr;
+    virDomainFSCacheMode cache;
+    virTristateSwitch posix_lock;
+    virTristateSwitch flock;
     virDomainVirtioOptionsPtr virtio;
     virObjectPtr privateData;
 };
@@ -3441,6 +3455,7 @@ VIR_ENUM_DECL(virDomainFSDriver);
 VIR_ENUM_DECL(virDomainFSAccessMode);
 VIR_ENUM_DECL(virDomainFSWrpolicy);
 VIR_ENUM_DECL(virDomainFSModel);
+VIR_ENUM_DECL(virDomainFSCacheMode);
 VIR_ENUM_DECL(virDomainNet);
 VIR_ENUM_DECL(virDomainNetBackend);
 VIR_ENUM_DECL(virDomainNetVirtioTxMode);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ebf830791e..30c3b12d79 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -395,6 +395,7 @@ virDomainDiskSourceFormat;
 virDomainDiskTranslateSourcePool;
 virDomainFeatureTypeFromString;
 virDomainFeatureTypeToString;
+virDomainFSCacheModeTypeToString;
 virDomainFSDefFree;
 virDomainFSDefNew;
 virDomainFSDriverTypeToString;
diff --git a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
index a6b6279fb8..f6bb663e97 100644
--- a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
+++ b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
@@ -27,7 +27,11 @@
     <controller type='usb' index='0' model='none'/>
     <controller type='pci' index='0' model='pci-root'/>
     <filesystem type='mount' accessmode='passthrough'>
-      <driver type='virtiofs'/>
+      <driver type='virtiofs' queue='1024'/>
+      <binary path='/usr/libexec/virtiofsd' xattr='on'>
+        <cache mode='always'/>
+        <lock posix='off' flock='off'/>
+      </binary>
       <source dir='/path'/>
       <target dir='mount_tag'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
diff --git a/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml b/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
index 70df7b890d..96b9774704 100644
--- a/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
+++ b/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
@@ -63,6 +63,7 @@
     </controller>
     <filesystem type='mount' accessmode='passthrough'>
       <driver type='virtiofs'/>
+      <binary path='/usr/libexec/virtiofsd'/>
       <source dir='/path'/>
       <target dir='mount_tag'/>
       <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
-- 
2.21.0

Re: [libvirt PATCHv3 06/12] conf: add virtiofs-related elements and attributes
Posted by Daniel P. Berrangé 6 years ago
On Thu, Jan 30, 2020 at 06:06:22PM +0100, Ján Tomko wrote:
> Add more elements for tuning the virtiofsd daemon
> and the vhost-user-fs device:
> 
>   <driver type='virtiofs' queue='1024' xattr='on'>
>     <binary>/usr/libexec/virtiofsd</binary>
>     <cache mode='always' size='2097152' unit='KiB'/>
>     <lock posix='off' flock='off'/>
>   </driver>
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>  docs/formatdomain.html.in                     |  25 +++-
>  docs/schemas/domaincommon.rng                 |  48 ++++++++
>  src/conf/domain_conf.c                        | 107 +++++++++++++++++-
>  src/conf/domain_conf.h                        |  15 +++
>  src/libvirt_private.syms                      |   1 +
>  .../vhost-user-fs-fd-memory.xml               |   6 +-
>  .../vhost-user-fs-hugepages.xml               |   1 +
>  7 files changed, 200 insertions(+), 3 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Re: [libvirt PATCHv3 06/12] conf: add virtiofs-related elements and attributes
Posted by Masayoshi Mizuma 6 years ago
On Thu, Jan 30, 2020 at 06:06:22PM +0100, Ján Tomko wrote:
> Add more elements for tuning the virtiofsd daemon
> and the vhost-user-fs device:
> 

>   <driver type='virtiofs' queue='1024' xattr='on'>
>     <binary>/usr/libexec/virtiofsd</binary>
>     <cache mode='always' size='2097152' unit='KiB'/>
>     <lock posix='off' flock='off'/>
>   </driver>

Above config doesn't work... Following?

      <driver type='virtiofs' queue='1024'/>
      <binary path='/usr/libexec/virtiofsd' xattr='off'>
        <cache mode='always'/>
        <lock posix='off' flock='off'/>
      </binary>

The code looks good to me.

	Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>

Thanks,
Masa

> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>  docs/formatdomain.html.in                     |  25 +++-
>  docs/schemas/domaincommon.rng                 |  48 ++++++++
>  src/conf/domain_conf.c                        | 107 +++++++++++++++++-
>  src/conf/domain_conf.h                        |  15 +++
>  src/libvirt_private.syms                      |   1 +
>  .../vhost-user-fs-fd-memory.xml               |   6 +-
>  .../vhost-user-fs-hugepages.xml               |   1 +
>  7 files changed, 200 insertions(+), 3 deletions(-)
> 
> diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> index d5565361ab..58e06d21f5 100644
> --- a/docs/formatdomain.html.in
> +++ b/docs/formatdomain.html.in
> @@ -3922,10 +3922,15 @@
>      &lt;readonly/&gt;
>    &lt;/filesystem&gt;
>    &lt;filesystem type='mount' accessmode='passthrough'&gt;
> -      &lt;driver type='virtiofs'/&gt;
> +      &lt;driver type='virtiofs queue='1024'/&gt;
> +      &lt;binary path='/usr/libexec/virtiofsd' xattr='on'&gt;
> +         &lt;cache mode='always'/&gt;
> +         &lt;lock posix='on' flock='on'/&gt;
> +      &lt;/binary&gt;
>        &lt;source dir='/path'/&gt;
>        &lt;target dir='mount_tag'/&gt;
>    &lt;/filesystem&gt;
> +
>    ...
>  &lt;/devices&gt;
>  ...</pre>
> @@ -4049,9 +4054,27 @@
>            <a href="#elementsVirtio">Virtio-specific options</a> can also be
>            set. (<span class="since">Since 3.5.0</span>)
>            </li>
> +          <li>
> +            For <code>virtiofs</code>, the <code>queue</code> attribute can be used
> +            to specify the queue size (i.e. how many requests can the queue fit).
> +            (<span class="since">Since 6.1.0</span>)
> +          </li>
>          </ul>
>        </dd>
>  
> +      <dt><code>binary</code></dt>
> +      <dd>
> +        The optional <code>binary</code> element can tune the options for virtiofsd.
> +        The attribute <code>path</code> can be used to override the path to the daemon.
> +        Attribute <code>xattr</code> enables the use of filesystem extended attributes.
> +        Caching can be tuned via the <code>cache</code> element, possible <code>mode</code>
> +        values being <code>none</code> and <code>always</code>.
> +        Locking can be controlled via the <code>lock</code>
> +        element - attributes <code>posix</code> and <code>flock</code> both accepting
> +        values <code>yes</code> or <code>no</code>.
> +        (<span class="since">Since 6.1.0</span>)
> +      </dd>
> +
>        <dt><code>source</code></dt>
>        <dd>
>          The resource on the host that is being accessed in the guest. The
> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
> index e30b82c57e..db475a43ca 100644
> --- a/docs/schemas/domaincommon.rng
> +++ b/docs/schemas/domaincommon.rng
> @@ -2480,6 +2480,9 @@
>            <optional>
>              <ref name="fsDriver"/>
>            </optional>
> +          <optional>
> +            <ref name="fsBinary"/>
> +          </optional>
>            <interleave>
>              <element name="source">
>                <attribute name="dir">
> @@ -2629,12 +2632,57 @@
>            <attribute name="type">
>              <value>virtiofs</value>
>            </attribute>
> +          <optional>
> +            <attribute name="queue">
> +              <ref name="unsignedInt"/>
> +            </attribute>
> +          </optional>
>            <ref name='virtioOptions'/>
>          </group>
>          <empty/>
>        </choice>
>      </element>
>    </define>
> +  <define name="fsBinary">
> +    <element name="binary">
> +      <optional>
> +        <attribute name="path">
> +          <ref name="absFilePath"/>
> +        </attribute>
> +      </optional>
> +      <optional>
> +        <attribute name="xattr">
> +          <ref name="virOnOff"/>
> +        </attribute>
> +      </optional>
> +      <optional>
> +        <element name="cache">
> +          <optional>
> +            <attribute name="mode">
> +              <choice>
> +                <value>none</value>
> +                <value>always</value>
> +              </choice>
> +            </attribute>
> +          </optional>
> +        </element>
> +      </optional>
> +      <optional>
> +        <element name="lock">
> +          <optional>
> +            <attribute name="posix">
> +              <ref name="virOnOff"/>
> +            </attribute>
> +          </optional>
> +          <optional>
> +            <attribute name="flock">
> +              <ref name="virOnOff"/>
> +            </attribute>
> +          </optional>
> +        </element>
> +      </optional>
> +    </element>
> +  </define>
>  
>    <define name="interface-network-attributes">
>      <attribute name="network">
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index d1a6d125d7..5c26e0d06c 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -501,6 +501,14 @@ VIR_ENUM_IMPL(virDomainFSModel,
>                "virtio-non-transitional",
>  );
>  
> +VIR_ENUM_IMPL(virDomainFSCacheMode,
> +              VIR_DOMAIN_FS_CACHE_MODE_LAST,
> +              "default",
> +              "none",
> +              "always",
> +);
> +
> +
>  VIR_ENUM_IMPL(virDomainNet,
>                VIR_DOMAIN_NET_TYPE_LAST,
>                "user",
> @@ -2322,6 +2330,7 @@ void virDomainFSDefFree(virDomainFSDefPtr def)
>      VIR_FREE(def->dst);
>      virDomainDeviceInfoClear(&def->info);
>      VIR_FREE(def->virtio);
> +    VIR_FREE(def->binary);
>  
>      VIR_FREE(def);
>  }
> @@ -11254,6 +11263,64 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
>          }
>      }
>  
> +    if (def->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
> +        g_autofree char *queue_size = virXPathString("string(./driver/@queue)", ctxt);
> +        g_autofree char *binary = virXPathString("string(./binary/@path)", ctxt);
> +        g_autofree char *xattr = virXPathString("string(./binary/@xattr)", ctxt);
> +        g_autofree char *cache = virXPathString("string(./binary/cache/@mode)", ctxt);
> +        g_autofree char *posix_lock = virXPathString("string(./binary/lock/@posix)", ctxt);
> +        g_autofree char *flock = virXPathString("string(./binary/lock/@flock)", ctxt);
> +        int val;
> +
> +
> +        if (queue_size && virStrToLong_ull(queue_size, NULL, 10, &def->queue_size) < 0) {
> +            virReportError(VIR_ERR_XML_ERROR,
> +                           _("cannot parse queue size '%s' for virtiofs"),
> +                           queue_size);
> +            goto error;
> +        }
> +
> +        if (binary)
> +            def->binary = virFileSanitizePath(binary);
> +
> +        if (xattr) {
> +            if ((val = virTristateSwitchTypeFromString(xattr)) <= 0) {
> +                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                               _("unknown xattr value '%s'"), xattr);
> +                goto error;
> +            }
> +            def->xattr = val;
> +        }
> +
> +        if (cache) {
> +            if ((val = virDomainFSCacheModeTypeFromString(cache)) <= 0) {
> +                virReportError(VIR_ERR_XML_ERROR,
> +                               _("cannot parse cache mode '%s' for virtiofs"),
> +                               cache);
> +                goto error;
> +            }
> +            def->cache = val;
> +        }
> +
> +        if (posix_lock) {
> +            if ((val = virTristateSwitchTypeFromString(posix_lock)) <= 0) {
> +                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                               _("unknown posix lock value '%s'"), posix_lock);
> +                goto error;
> +            }
> +            def->posix_lock = val;
> +        }
> +
> +        if (flock) {
> +            if ((val = virTristateSwitchTypeFromString(flock)) <= 0) {
> +                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                               _("unknown flock value '%s'"), flock);
> +                goto error;
> +            }
> +            def->flock = val;
> +        }
> +    }
> +
>      if (format) {
>          if ((def->format = virStorageFileFormatTypeFromString(format)) <= 0) {
>              virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> @@ -25053,6 +25120,9 @@ virDomainFSDefFormat(virBufferPtr buf,
>      const char *wrpolicy = virDomainFSWrpolicyTypeToString(def->wrpolicy);
>      const char *src = def->src->path;
>      g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
> +    g_auto(virBuffer) driverBuf = VIR_BUFFER_INIT_CHILD(buf);
> +    g_auto(virBuffer) binaryAttrBuf = VIR_BUFFER_INITIALIZER;
> +    g_auto(virBuffer) binaryBuf = VIR_BUFFER_INIT_CHILD(buf);
>  
>      if (!type) {
>          virReportError(VIR_ERR_INTERNAL_ERROR,
> @@ -25076,6 +25146,8 @@ virDomainFSDefFormat(virBufferPtr buf,
>      virBufferAddLit(buf, ">\n");
>  
>      virBufferAdjustIndent(buf, 2);
> +    virBufferAdjustIndent(&driverBuf, 2);
> +    virBufferAdjustIndent(&binaryBuf, 2);
>      if (def->fsdriver) {
>          virBufferAsprintf(&driverAttrBuf, " type='%s'", fsdriver);
>  
> @@ -25087,11 +25159,44 @@ virDomainFSDefFormat(virBufferPtr buf,
>          if (def->wrpolicy)
>              virBufferAsprintf(&driverAttrBuf, " wrpolicy='%s'", wrpolicy);
>  
> +        if (def->queue_size)
> +            virBufferAsprintf(&driverAttrBuf, " queue='%llu'", def->queue_size);
> +
> +    }
> +
> +    if (def->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
> +        g_auto(virBuffer) lockAttrBuf = VIR_BUFFER_INITIALIZER;
> +        virBufferEscapeString(&binaryAttrBuf, " path='%s'", def->binary);
> +
> +        if (def->xattr != VIR_TRISTATE_SWITCH_ABSENT) {
> +            virBufferAsprintf(&binaryAttrBuf, " xattr='%s'",
> +                              virTristateSwitchTypeToString(def->xattr));
> +        }
> +
> +        if (def->cache != VIR_DOMAIN_FS_CACHE_MODE_DEFAULT) {
> +            virBufferAsprintf(&binaryBuf, "<cache mode='%s'/>\n",
> +                              virDomainFSCacheModeTypeToString(def->cache));
> +        }
> +
> +        if (def->posix_lock != VIR_TRISTATE_SWITCH_ABSENT) {
> +            virBufferAsprintf(&lockAttrBuf, " posix='%s'",
> +                              virTristateSwitchTypeToString(def->posix_lock));
> +        }
> +
> +        if (def->flock != VIR_TRISTATE_SWITCH_ABSENT) {
> +            virBufferAsprintf(&lockAttrBuf, " flock='%s'",
> +                              virTristateSwitchTypeToString(def->flock));
> +        }
> +
> +        virXMLFormatElement(&binaryBuf, "lock", &lockAttrBuf, NULL);
>      }
>  
> +
>      virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
>  
> -    virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
> +    virXMLFormatElement(buf, "driver", &driverAttrBuf, &driverBuf);
> +    virXMLFormatElement(buf, "binary", &binaryAttrBuf, &binaryBuf);
> +    virXMLFormatElement(buf, "driver", &driverAttrBuf, &driverBuf);
>  
>      switch (def->type) {
>      case VIR_DOMAIN_FS_TYPE_MOUNT:
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index de2bd3be93..21a36c34ef 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -804,6 +804,14 @@ typedef enum {
>      VIR_DOMAIN_FS_MODEL_LAST
>  } virDomainFSModel;
>  
> +typedef enum {
> +    VIR_DOMAIN_FS_CACHE_MODE_DEFAULT = 0,
> +    VIR_DOMAIN_FS_CACHE_MODE_NONE,
> +    VIR_DOMAIN_FS_CACHE_MODE_ALWAYS,
> +
> +    VIR_DOMAIN_FS_CACHE_MODE_LAST
> +} virDomainFSCacheMode;
> +
>  struct _virDomainFSDef {
>      int type;
>      int fsdriver; /* enum virDomainFSDriverType */
> @@ -819,6 +827,12 @@ struct _virDomainFSDef {
>      unsigned long long space_hard_limit; /* in bytes */
>      unsigned long long space_soft_limit; /* in bytes */
>      bool symlinksResolved;
> +    char *binary;
> +    unsigned long long queue_size;
> +    virTristateSwitch xattr;
> +    virDomainFSCacheMode cache;
> +    virTristateSwitch posix_lock;
> +    virTristateSwitch flock;
>      virDomainVirtioOptionsPtr virtio;
>      virObjectPtr privateData;
>  };
> @@ -3441,6 +3455,7 @@ VIR_ENUM_DECL(virDomainFSDriver);
>  VIR_ENUM_DECL(virDomainFSAccessMode);
>  VIR_ENUM_DECL(virDomainFSWrpolicy);
>  VIR_ENUM_DECL(virDomainFSModel);
> +VIR_ENUM_DECL(virDomainFSCacheMode);
>  VIR_ENUM_DECL(virDomainNet);
>  VIR_ENUM_DECL(virDomainNetBackend);
>  VIR_ENUM_DECL(virDomainNetVirtioTxMode);
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index ebf830791e..30c3b12d79 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -395,6 +395,7 @@ virDomainDiskSourceFormat;
>  virDomainDiskTranslateSourcePool;
>  virDomainFeatureTypeFromString;
>  virDomainFeatureTypeToString;
> +virDomainFSCacheModeTypeToString;
>  virDomainFSDefFree;
>  virDomainFSDefNew;
>  virDomainFSDriverTypeToString;
> diff --git a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
> index a6b6279fb8..f6bb663e97 100644
> --- a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
> +++ b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
> @@ -27,7 +27,11 @@
>      <controller type='usb' index='0' model='none'/>
>      <controller type='pci' index='0' model='pci-root'/>
>      <filesystem type='mount' accessmode='passthrough'>
> -      <driver type='virtiofs'/>
> +      <driver type='virtiofs' queue='1024'/>
> +      <binary path='/usr/libexec/virtiofsd' xattr='on'>
> +        <cache mode='always'/>
> +        <lock posix='off' flock='off'/>
> +      </binary>
>        <source dir='/path'/>
>        <target dir='mount_tag'/>
>        <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
> diff --git a/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml b/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
> index 70df7b890d..96b9774704 100644
> --- a/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
> +++ b/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
> @@ -63,6 +63,7 @@
>      </controller>
>      <filesystem type='mount' accessmode='passthrough'>
>        <driver type='virtiofs'/>
> +      <binary path='/usr/libexec/virtiofsd'/>
>        <source dir='/path'/>
>        <target dir='mount_tag'/>
>        <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
> -- 
> 2.21.0
>