d76c62
From c811bd72130364673dd4a0d2a997a1d8f675eb71 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <c811bd72130364673dd4a0d2a997a1d8f675eb71@dist-git>
d76c62
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
d76c62
Date: Wed, 4 Mar 2020 12:42:42 +0100
d76c62
Subject: [PATCH] conf: add virtiofs-related elements and attributes
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Add more elements for tuning the virtiofsd daemon
d76c62
and the vhost-user-fs device:
d76c62
d76c62
  <driver type='virtiofs' queue='1024' xattr='on'>
d76c62
    <binary path='/usr/libexec/virtiofsd'>
d76c62
      <cache mode='always'/>
d76c62
      <lock posix='off' flock='off'/>
d76c62
    </binary>
d76c62
  </driver>
d76c62
d76c62
Signed-off-by: Ján Tomko <jtomko@redhat.com>
d76c62
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
d76c62
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
d76c62
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Tested-by: Andrea Bolognani <abologna@redhat.com>
d76c62
(cherry picked from commit 66079339847dc942b9b673e3040b56b055a8d8f5)
d76c62
Signed-off-by: Ján Tomko <jtomko@redhat.com>
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1694166
d76c62
Message-Id: <506d0532c6043a9b8c946bdc42c3d9c5529f6fb8.1583322090.git.jtomko@redhat.com>
d76c62
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
d76c62
---
d76c62
 docs/formatdomain.html.in                     |  25 ++++-
d76c62
 docs/schemas/domaincommon.rng                 |  48 ++++++++
d76c62
 src/conf/domain_conf.c                        | 104 +++++++++++++++++-
d76c62
 src/conf/domain_conf.h                        |  15 +++
d76c62
 src/libvirt_private.syms                      |   1 +
d76c62
 .../vhost-user-fs-fd-memory.xml               |   6 +-
d76c62
 .../vhost-user-fs-hugepages.xml               |   1 +
d76c62
 7 files changed, 197 insertions(+), 3 deletions(-)
d76c62
d76c62
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
d76c62
index 337ab01316..e9830ab231 100644
d76c62
--- a/docs/formatdomain.html.in
d76c62
+++ b/docs/formatdomain.html.in
d76c62
@@ -3936,7 +3936,11 @@
d76c62
     <readonly/>
d76c62
   </filesystem>
d76c62
   <filesystem type='mount' accessmode='passthrough'>
d76c62
-      <driver type='virtiofs'/>
d76c62
+      <driver type='virtiofs queue='1024'/>
d76c62
+      <binary path='/usr/libexec/virtiofsd' xattr='on'>
d76c62
+         <cache mode='always'/>
d76c62
+         <lock posix='on' flock='on'/>
d76c62
+      </binary>
d76c62
       <source dir='/path'/>
d76c62
       <target dir='mount_tag'/>
d76c62
   </filesystem>
d76c62
@@ -4063,9 +4067,28 @@
d76c62
           Virtio-specific options can also be
d76c62
           set. (Since 3.5.0)
d76c62
           
d76c62
+          
  • d76c62
    +            For virtiofs, the queue attribute can be used
    d76c62
    +            to specify the queue size (i.e. how many requests can the queue fit).
    d76c62
    +            (Since 6.2.0)
    d76c62
    +          
    d76c62
             
    d76c62
           
    d76c62
     
    d76c62
    +      
    binary
    d76c62
    +      
    d76c62
    +        The optional binary element can tune the options for virtiofsd.
    d76c62
    +        All of the following attributes and elements are optional.
    d76c62
    +        The attribute path can be used to override the path to the daemon.
    d76c62
    +        Attribute xattr enables the use of filesystem extended attributes.
    d76c62
    +        Caching can be tuned via the cache element, possible mode
    d76c62
    +        values being none and always.
    d76c62
    +        Locking can be controlled via the lock
    d76c62
    +        element - attributes posix and flock both accepting
    d76c62
    +        values on or off.
    d76c62
    +        (Since 6.2.0)
    d76c62
    +      
    d76c62
    +
    d76c62
           
    source
    d76c62
           
    d76c62
             The resource on the host that is being accessed in the guest. The
    d76c62
    diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
    d76c62
    index 5a9291b443..aa70e340b9 100644
    d76c62
    --- a/docs/schemas/domaincommon.rng
    d76c62
    +++ b/docs/schemas/domaincommon.rng
    d76c62
    @@ -2500,6 +2500,9 @@
    d76c62
               <optional>
    d76c62
                 <ref name="fsDriver"/>
    d76c62
               </optional>
    d76c62
    +          <optional>
    d76c62
    +            <ref name="fsBinary"/>
    d76c62
    +          </optional>
    d76c62
               <interleave>
    d76c62
                 <element name="source">
    d76c62
                   <attribute name="dir">
    d76c62
    @@ -2649,12 +2652,57 @@
    d76c62
               <attribute name="type">
    d76c62
                 <value>virtiofs</value>
    d76c62
               </attribute>
    d76c62
    +          <optional>
    d76c62
    +            <attribute name="queue">
    d76c62
    +              <ref name="unsignedInt"/>
    d76c62
    +            </attribute>
    d76c62
    +          </optional>
    d76c62
               <ref name='virtioOptions'/>
    d76c62
             </group>
    d76c62
             <empty/>
    d76c62
           </choice>
    d76c62
         </element>
    d76c62
       </define>
    d76c62
    +  <define name="fsBinary">
    d76c62
    +    <element name="binary">
    d76c62
    +      <optional>
    d76c62
    +        <attribute name="path">
    d76c62
    +          <ref name="absFilePath"/>
    d76c62
    +        </attribute>
    d76c62
    +      </optional>
    d76c62
    +      <optional>
    d76c62
    +        <attribute name="xattr">
    d76c62
    +          <ref name="virOnOff"/>
    d76c62
    +        </attribute>
    d76c62
    +      </optional>
    d76c62
    +      <optional>
    d76c62
    +        <element name="cache">
    d76c62
    +          <optional>
    d76c62
    +            <attribute name="mode">
    d76c62
    +              <choice>
    d76c62
    +                <value>none</value>
    d76c62
    +                <value>always</value>
    d76c62
    +              </choice>
    d76c62
    +            </attribute>
    d76c62
    +          </optional>
    d76c62
    +        </element>
    d76c62
    +      </optional>
    d76c62
    +      <optional>
    d76c62
    +        <element name="lock">
    d76c62
    +          <optional>
    d76c62
    +            <attribute name="posix">
    d76c62
    +              <ref name="virOnOff"/>
    d76c62
    +            </attribute>
    d76c62
    +          </optional>
    d76c62
    +          <optional>
    d76c62
    +            <attribute name="flock">
    d76c62
    +              <ref name="virOnOff"/>
    d76c62
    +            </attribute>
    d76c62
    +          </optional>
    d76c62
    +        </element>
    d76c62
    +      </optional>
    d76c62
    +    </element>
    d76c62
    +  </define>
    d76c62
     
    d76c62
       <define name="interface-network-attributes">
    d76c62
         <attribute name="network">
    d76c62
    diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
    d76c62
    index 31d4828802..3a370e6b90 100644
    d76c62
    --- a/src/conf/domain_conf.c
    d76c62
    +++ b/src/conf/domain_conf.c
    d76c62
    @@ -500,6 +500,14 @@ VIR_ENUM_IMPL(virDomainFSModel,
    d76c62
                   "virtio-non-transitional",
    d76c62
     );
    d76c62
     
    d76c62
    +VIR_ENUM_IMPL(virDomainFSCacheMode,
    d76c62
    +              VIR_DOMAIN_FS_CACHE_MODE_LAST,
    d76c62
    +              "default",
    d76c62
    +              "none",
    d76c62
    +              "always",
    d76c62
    +);
    d76c62
    +
    d76c62
    +
    d76c62
     VIR_ENUM_IMPL(virDomainNet,
    d76c62
                   VIR_DOMAIN_NET_TYPE_LAST,
    d76c62
                   "user",
    d76c62
    @@ -2322,6 +2330,7 @@ void virDomainFSDefFree(virDomainFSDefPtr def)
    d76c62
         virDomainDeviceInfoClear(&def->info);
    d76c62
         VIR_FREE(def->virtio);
    d76c62
         virObjectUnref(def->privateData);
    d76c62
    +    VIR_FREE(def->binary);
    d76c62
     
    d76c62
         VIR_FREE(def);
    d76c62
     }
    d76c62
    @@ -11293,6 +11302,63 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
    d76c62
             }
    d76c62
         }
    d76c62
     
    d76c62
    +    if (def->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
    d76c62
    +        g_autofree char *queue_size = virXPathString("string(./driver/@queue)", ctxt);
    d76c62
    +        g_autofree char *binary = virXPathString("string(./binary/@path)", ctxt);
    d76c62
    +        g_autofree char *xattr = virXPathString("string(./binary/@xattr)", ctxt);
    d76c62
    +        g_autofree char *cache = virXPathString("string(./binary/cache/@mode)", ctxt);
    d76c62
    +        g_autofree char *posix_lock = virXPathString("string(./binary/lock/@posix)", ctxt);
    d76c62
    +        g_autofree char *flock = virXPathString("string(./binary/lock/@flock)", ctxt);
    d76c62
    +        int val;
    d76c62
    +
    d76c62
    +        if (queue_size && virStrToLong_ull(queue_size, NULL, 10, &def->queue_size) < 0) {
    d76c62
    +            virReportError(VIR_ERR_XML_ERROR,
    d76c62
    +                           _("cannot parse queue size '%s' for virtiofs"),
    d76c62
    +                           queue_size);
    d76c62
    +            goto error;
    d76c62
    +        }
    d76c62
    +
    d76c62
    +        if (binary)
    d76c62
    +            def->binary = virFileSanitizePath(binary);
    d76c62
    +
    d76c62
    +        if (xattr) {
    d76c62
    +            if ((val = virTristateSwitchTypeFromString(xattr)) <= 0) {
    d76c62
    +                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
    d76c62
    +                               _("unknown xattr value '%s'"), xattr);
    d76c62
    +                goto error;
    d76c62
    +            }
    d76c62
    +            def->xattr = val;
    d76c62
    +        }
    d76c62
    +
    d76c62
    +        if (cache) {
    d76c62
    +            if ((val = virDomainFSCacheModeTypeFromString(cache)) <= 0) {
    d76c62
    +                virReportError(VIR_ERR_XML_ERROR,
    d76c62
    +                               _("cannot parse cache mode '%s' for virtiofs"),
    d76c62
    +                               cache);
    d76c62
    +                goto error;
    d76c62
    +            }
    d76c62
    +            def->cache = val;
    d76c62
    +        }
    d76c62
    +
    d76c62
    +        if (posix_lock) {
    d76c62
    +            if ((val = virTristateSwitchTypeFromString(posix_lock)) <= 0) {
    d76c62
    +                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
    d76c62
    +                               _("unknown posix lock value '%s'"), posix_lock);
    d76c62
    +                goto error;
    d76c62
    +            }
    d76c62
    +            def->posix_lock = val;
    d76c62
    +        }
    d76c62
    +
    d76c62
    +        if (flock) {
    d76c62
    +            if ((val = virTristateSwitchTypeFromString(flock)) <= 0) {
    d76c62
    +                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
    d76c62
    +                               _("unknown flock value '%s'"), flock);
    d76c62
    +                goto error;
    d76c62
    +            }
    d76c62
    +            def->flock = val;
    d76c62
    +        }
    d76c62
    +    }
    d76c62
    +
    d76c62
         if (format) {
    d76c62
             if ((def->format = virStorageFileFormatTypeFromString(format)) <= 0) {
    d76c62
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
    d76c62
    @@ -24994,6 +25060,9 @@ virDomainFSDefFormat(virBufferPtr buf,
    d76c62
         const char *wrpolicy = virDomainFSWrpolicyTypeToString(def->wrpolicy);
    d76c62
         const char *src = def->src->path;
    d76c62
         g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
    d76c62
    +    g_auto(virBuffer) driverBuf = VIR_BUFFER_INIT_CHILD(buf);
    d76c62
    +    g_auto(virBuffer) binaryAttrBuf = VIR_BUFFER_INITIALIZER;
    d76c62
    +    g_auto(virBuffer) binaryBuf = VIR_BUFFER_INIT_CHILD(buf);
    d76c62
     
    d76c62
         if (!type) {
    d76c62
             virReportError(VIR_ERR_INTERNAL_ERROR,
    d76c62
    @@ -25017,6 +25086,8 @@ virDomainFSDefFormat(virBufferPtr buf,
    d76c62
         virBufferAddLit(buf, ">\n");
    d76c62
     
    d76c62
         virBufferAdjustIndent(buf, 2);
    d76c62
    +    virBufferAdjustIndent(&driverBuf, 2);
    d76c62
    +    virBufferAdjustIndent(&binaryBuf, 2);
    d76c62
         if (def->fsdriver) {
    d76c62
             virBufferAsprintf(&driverAttrBuf, " type='%s'", fsdriver);
    d76c62
     
    d76c62
    @@ -25028,11 +25099,42 @@ virDomainFSDefFormat(virBufferPtr buf,
    d76c62
             if (def->wrpolicy)
    d76c62
                 virBufferAsprintf(&driverAttrBuf, " wrpolicy='%s'", wrpolicy);
    d76c62
     
    d76c62
    +        if (def->queue_size)
    d76c62
    +            virBufferAsprintf(&driverAttrBuf, " queue='%llu'", def->queue_size);
    d76c62
    +
    d76c62
    +    }
    d76c62
    +
    d76c62
    +    if (def->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
    d76c62
    +        g_auto(virBuffer) lockAttrBuf = VIR_BUFFER_INITIALIZER;
    d76c62
    +        virBufferEscapeString(&binaryAttrBuf, " path='%s'", def->binary);
    d76c62
    +
    d76c62
    +        if (def->xattr != VIR_TRISTATE_SWITCH_ABSENT) {
    d76c62
    +            virBufferAsprintf(&binaryAttrBuf, " xattr='%s'",
    d76c62
    +                              virTristateSwitchTypeToString(def->xattr));
    d76c62
    +        }
    d76c62
    +
    d76c62
    +        if (def->cache != VIR_DOMAIN_FS_CACHE_MODE_DEFAULT) {
    d76c62
    +            virBufferAsprintf(&binaryBuf, "<cache mode='%s'/>\n",
    d76c62
    +                              virDomainFSCacheModeTypeToString(def->cache));
    d76c62
    +        }
    d76c62
    +
    d76c62
    +        if (def->posix_lock != VIR_TRISTATE_SWITCH_ABSENT) {
    d76c62
    +            virBufferAsprintf(&lockAttrBuf, " posix='%s'",
    d76c62
    +                              virTristateSwitchTypeToString(def->posix_lock));
    d76c62
    +        }
    d76c62
    +
    d76c62
    +        if (def->flock != VIR_TRISTATE_SWITCH_ABSENT) {
    d76c62
    +            virBufferAsprintf(&lockAttrBuf, " flock='%s'",
    d76c62
    +                              virTristateSwitchTypeToString(def->flock));
    d76c62
    +        }
    d76c62
    +
    d76c62
    +        virXMLFormatElement(&binaryBuf, "lock", &lockAttrBuf, NULL);
    d76c62
         }
    d76c62
     
    d76c62
         virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
    d76c62
     
    d76c62
    -    virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
    d76c62
    +    virXMLFormatElement(buf, "driver", &driverAttrBuf, &driverBuf);
    d76c62
    +    virXMLFormatElement(buf, "binary", &binaryAttrBuf, &binaryBuf);
    d76c62
     
    d76c62
         switch (def->type) {
    d76c62
         case VIR_DOMAIN_FS_TYPE_MOUNT:
    d76c62
    diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
    d76c62
    index 921cc42a57..2a382ede72 100644
    d76c62
    --- a/src/conf/domain_conf.h
    d76c62
    +++ b/src/conf/domain_conf.h
    d76c62
    @@ -802,6 +802,14 @@ typedef enum {
    d76c62
         VIR_DOMAIN_FS_MODEL_LAST
    d76c62
     } virDomainFSModel;
    d76c62
     
    d76c62
    +typedef enum {
    d76c62
    +    VIR_DOMAIN_FS_CACHE_MODE_DEFAULT = 0,
    d76c62
    +    VIR_DOMAIN_FS_CACHE_MODE_NONE,
    d76c62
    +    VIR_DOMAIN_FS_CACHE_MODE_ALWAYS,
    d76c62
    +
    d76c62
    +    VIR_DOMAIN_FS_CACHE_MODE_LAST
    d76c62
    +} virDomainFSCacheMode;
    d76c62
    +
    d76c62
     struct _virDomainFSDef {
    d76c62
         int type;
    d76c62
         int fsdriver; /* enum virDomainFSDriverType */
    d76c62
    @@ -817,6 +825,12 @@ struct _virDomainFSDef {
    d76c62
         unsigned long long space_hard_limit; /* in bytes */
    d76c62
         unsigned long long space_soft_limit; /* in bytes */
    d76c62
         bool symlinksResolved;
    d76c62
    +    char *binary;
    d76c62
    +    unsigned long long queue_size;
    d76c62
    +    virTristateSwitch xattr;
    d76c62
    +    virDomainFSCacheMode cache;
    d76c62
    +    virTristateSwitch posix_lock;
    d76c62
    +    virTristateSwitch flock;
    d76c62
         virDomainVirtioOptionsPtr virtio;
    d76c62
         virObjectPtr privateData;
    d76c62
     };
    d76c62
    @@ -3437,6 +3451,7 @@ VIR_ENUM_DECL(virDomainFSDriver);
    d76c62
     VIR_ENUM_DECL(virDomainFSAccessMode);
    d76c62
     VIR_ENUM_DECL(virDomainFSWrpolicy);
    d76c62
     VIR_ENUM_DECL(virDomainFSModel);
    d76c62
    +VIR_ENUM_DECL(virDomainFSCacheMode);
    d76c62
     VIR_ENUM_DECL(virDomainNet);
    d76c62
     VIR_ENUM_DECL(virDomainNetBackend);
    d76c62
     VIR_ENUM_DECL(virDomainNetVirtioTxMode);
    d76c62
    diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
    d76c62
    index bc2858fc00..5dc99e03cf 100644
    d76c62
    --- a/src/libvirt_private.syms
    d76c62
    +++ b/src/libvirt_private.syms
    d76c62
    @@ -389,6 +389,7 @@ virDomainDiskSourceFormat;
    d76c62
     virDomainDiskTranslateSourcePool;
    d76c62
     virDomainFeatureTypeFromString;
    d76c62
     virDomainFeatureTypeToString;
    d76c62
    +virDomainFSCacheModeTypeToString;
    d76c62
     virDomainFSDefFree;
    d76c62
     virDomainFSDefNew;
    d76c62
     virDomainFSDriverTypeToString;
    d76c62
    diff --git a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
    d76c62
    index a6b6279fb8..f6bb663e97 100644
    d76c62
    --- a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
    d76c62
    +++ b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
    d76c62
    @@ -27,7 +27,11 @@
    d76c62
         <controller type='usb' index='0' model='none'/>
    d76c62
         <controller type='pci' index='0' model='pci-root'/>
    d76c62
         <filesystem type='mount' accessmode='passthrough'>
    d76c62
    -      <driver type='virtiofs'/>
    d76c62
    +      <driver type='virtiofs' queue='1024'/>
    d76c62
    +      <binary path='/usr/libexec/virtiofsd' xattr='on'>
    d76c62
    +        <cache mode='always'/>
    d76c62
    +        <lock posix='off' flock='off'/>
    d76c62
    +      </binary>
    d76c62
           <source dir='/path'/>
    d76c62
           <target dir='mount_tag'/>
    d76c62
           <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    d76c62
    diff --git a/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml b/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
    d76c62
    index 70df7b890d..96b9774704 100644
    d76c62
    --- a/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
    d76c62
    +++ b/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
    d76c62
    @@ -63,6 +63,7 @@
    d76c62
         </controller>
    d76c62
         <filesystem type='mount' accessmode='passthrough'>
    d76c62
           <driver type='virtiofs'/>
    d76c62
    +      <binary path='/usr/libexec/virtiofsd'/>
    d76c62
           <source dir='/path'/>
    d76c62
           <target dir='mount_tag'/>
    d76c62
           <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    d76c62
    -- 
    d76c62
    2.25.1
    d76c62