[libvirt] [PATCH v3 01/11] conf: Add some defined NFS Storage Pool mount options

John Ferlan jferlan at redhat.com
Wed Jan 16 01:09:12 UTC 2019


https://bugzilla.redhat.com/show_bug.cgi?id=1584663

Add the ability to parse/manage some defined NFS Storage Pool mount
options. Keep the set of defined options limited to noexec, nosuid,
nodev, and ro. Subsequent patches will add the ability to provide the
NFS nfsvers value and eventally any option via storage pool namespaces.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 docs/formatstorage.html.in                    | 21 +++++++++
 docs/schemas/storagepool.rng                  | 20 ++++++++
 src/conf/storage_conf.c                       | 47 +++++++++++++++++++
 src/conf/storage_conf.h                       | 13 +++++
 .../pool-netfs-mountopts.xml                  | 24 ++++++++++
 .../pool-netfs-mountopts.xml                  | 24 ++++++++++
 tests/storagepoolxml2xmltest.c                |  1 +
 7 files changed, 150 insertions(+)
 create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-mountopts.xml
 create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-mountopts.xml

diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index b6bf3edbd2..97c90f0797 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -121,6 +121,19 @@
 </source>
 ...</pre>
 
+    <pre>
+...
+  <source>
+    <host name='localhost'/>
+    <dir path='/var/lib/libvirt/images'/>
+    <format type='nfs'/>
+    <mount_opts>
+      <option name='nodev'/>
+      <option name='nosuid'/>
+    </mount_opts>
+  </source>
+...</pre>
+
     <dl>
       <dt><code>device</code></dt>
       <dd>Provides the source for pools backed by physical devices
@@ -386,6 +399,14 @@
         LVM metadata type. All drivers are required to have a default
         value for this, so it is optional. <span class="since">Since 0.4.1</span></dd>
 
+      <dt><code>mount_opts</code></dt>
+      <dd>Provide an optional set of mount options for the <code>netfs</code>
+        pool startup or creation to be provided via the "-o" option.
+        The desired options are specified by using the subelement
+        <code>option</code> with the attribute <code>name</code> to
+        provide the option. Supported option names are "noexec", "nosuid",
+        "nodev", and "ro".
+        <span class="since">Since 5.1.0</span></dd>
       <dt><code>vendor</code></dt>
       <dd>Provides optional information about the vendor of the
         storage device. This contains a single
diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index 74f4363106..d52856b556 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -531,6 +531,9 @@
             <ref name='sourceinfohost'/>
             <ref name='sourceinfodir'/>
             <ref name='sourcefmtnetfs'/>
+            <optional>
+              <ref name='sourcemountopts'/>
+            </optional>
             <optional>
               <ref name='sourceinfovendor'/>
             </optional>
@@ -576,6 +579,23 @@
     </element>
   </define>
 
+  <define name='sourcemountopts'>
+    <element name='mount_opts'>
+      <zeroOrMore>
+        <element name='option'>
+          <attribute name='name'>
+            <choice>
+              <value>noexec</value>
+              <value>nosuid</value>
+              <value>nodev</value>
+              <value>ro</value>
+            </choice>
+          </attribute>
+        </element>
+      </zeroOrMore>
+    </element>
+  </define>
+
   <define name='sourcedisk'>
     <element name='source'>
       <interleave>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 55db7a96f5..aafb7980e7 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -70,6 +70,10 @@ VIR_ENUM_IMPL(virStoragePoolFormatFileSystemNet,
               VIR_STORAGE_POOL_NETFS_LAST,
               "auto", "nfs", "glusterfs", "cifs")
 
+VIR_ENUM_IMPL(virStoragePoolSourceMountOpts,
+              VIR_STORAGE_POOL_SOURCE_MOUNT_OPTS_LAST,
+              "noexec", "nosuid", "nodev", "ro")
+
 VIR_ENUM_IMPL(virStoragePoolFormatDisk,
               VIR_STORAGE_POOL_DISK_LAST,
               "unknown", "dos", "dvh", "gpt",
@@ -378,6 +382,10 @@ virStoragePoolSourceClear(virStoragePoolSourcePtr source)
     virStorageAuthDefFree(source->auth);
     VIR_FREE(source->vendor);
     VIR_FREE(source->product);
+    for (i = 0; i < source->nmountOpts; i++)
+        VIR_FREE(source->mountOpts[i]);
+    VIR_FREE(source->mountOpts);
+    source->nmountOpts = 0;
 }
 
 
@@ -546,6 +554,33 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
         authdef = NULL;
     }
 
+    /* Optional, but defined mount ops */
+    VIR_FREE(nodeset);
+    n = virXPathNodeSet("./mount_opts/option", ctxt, &nodeset);
+    if (n < 0)
+        goto cleanup;
+
+    if (n > 0) {
+        if (VIR_ALLOC_N(source->mountOpts, n) < 0)
+            goto cleanup;
+        for (i = 0; i < n; i++) {
+            if (!(source->mountOpts[i] = virXMLPropString(nodeset[i],
+                                                          "name"))) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("no mount option name specified"));
+                goto cleanup;
+            }
+            source->nmountOpts++;
+            /* Do we recognize the string? */
+            if (virStoragePoolSourceMountOptsTypeFromString(source->mountOpts[i]) < 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("unknown mount option name '%s' specified"),
+                               source->mountOpts[i]);
+                goto cleanup;
+            }
+        }
+    }
+
     source->vendor = virXPathString("string(./vendor/@name)", ctxt);
     source->product = virXPathString("string(./product/@name)", ctxt);
 
@@ -962,6 +997,18 @@ virStoragePoolSourceFormat(virBufferPtr buf,
     if (src->auth)
         virStorageAuthDefFormat(buf, src->auth);
 
+    if (src->mountOpts) {
+        virBufferAddLit(buf, "<mount_opts>\n");
+        virBufferAdjustIndent(buf, 2);
+
+        for (i = 0; i < src->nmountOpts; i++)
+            virBufferEscapeString(buf, "<option name='%s'/>\n",
+                                  src->mountOpts[i]);
+
+        virBufferAdjustIndent(buf, -2);
+        virBufferAddLit(buf, "</mount_opts>\n");
+    }
+
     virBufferEscapeString(buf, "<vendor name='%s'/>\n", src->vendor);
     virBufferEscapeString(buf, "<product name='%s'/>\n", src->product);
 
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index dc0aa2ab29..c23e6720ac 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -193,6 +193,10 @@ struct _virStoragePoolSource {
     /* Product name of the source*/
     char *product;
 
+    /* Defined mount options to be added to mount command line */
+    char **mountOpts;
+    size_t nmountOpts;
+
     /* Pool type specific format such as filesystem type,
      * or lvm version, etc.
      */
@@ -332,6 +336,15 @@ typedef enum {
 } virStoragePoolFormatFileSystemNet;
 VIR_ENUM_DECL(virStoragePoolFormatFileSystemNet)
 
+typedef enum {
+    VIR_STORAGE_POOL_SOURCE_MOUNT_OPTS_NOEXEC = 0,
+    VIR_STORAGE_POOL_SOURCE_MOUNT_OPTS_NOSUID,
+    VIR_STORAGE_POOL_SOURCE_MOUNT_OPTS_NODEV,
+    VIR_STORAGE_POOL_SOURCE_MOUNT_OPTS_RO,
+    VIR_STORAGE_POOL_SOURCE_MOUNT_OPTS_LAST,
+} virStoragePoolSourceMountOpts;
+VIR_ENUM_DECL(virStoragePoolSourceMountOpts)
+
 typedef enum {
     VIR_STORAGE_POOL_DISK_UNKNOWN = 0,
     VIR_STORAGE_POOL_DISK_DOS = 1,
diff --git a/tests/storagepoolxml2xmlin/pool-netfs-mountopts.xml b/tests/storagepoolxml2xmlin/pool-netfs-mountopts.xml
new file mode 100644
index 0000000000..c2bb3bf4ed
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-netfs-mountopts.xml
@@ -0,0 +1,24 @@
+<pool type='netfs'>
+  <name>nfsimages</name>
+  <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <host name='localhost'/>
+    <dir path='/var/lib/libvirt/images'/>
+    <format type='nfs'/>
+    <mount_opts>
+      <option name='nodev'/>
+      <option name='nosuid'/>
+    </mount_opts>
+  </source>
+  <target>
+    <path>/mnt</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-netfs-mountopts.xml b/tests/storagepoolxml2xmlout/pool-netfs-mountopts.xml
new file mode 100644
index 0000000000..786acf8887
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-netfs-mountopts.xml
@@ -0,0 +1,24 @@
+<pool type='netfs'>
+  <name>nfsimages</name>
+  <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
+  <capacity unit='bytes'>0</capacity>
+  <allocation unit='bytes'>0</allocation>
+  <available unit='bytes'>0</available>
+  <source>
+    <host name='localhost'/>
+    <dir path='/var/lib/libvirt/images'/>
+    <format type='nfs'/>
+    <mount_opts>
+      <option name='nodev'/>
+      <option name='nosuid'/>
+    </mount_opts>
+  </source>
+  <target>
+    <path>/mnt</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index 707d09f5c2..08d9a08020 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -85,6 +85,7 @@ mymain(void)
     DO_TEST("pool-netfs-auto");
     DO_TEST("pool-netfs-gluster");
     DO_TEST("pool-netfs-cifs");
+    DO_TEST("pool-netfs-mountopts");
     DO_TEST("pool-scsi");
     DO_TEST("pool-scsi-type-scsi-host");
     DO_TEST("pool-scsi-type-fc-host");
-- 
2.20.1




More information about the libvir-list mailing list