render / rpms / libvirt

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