render / rpms / libvirt

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