[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/3] storage: Add mount options attribute for pool source dir element



If libvirt creates the command to mount the storage pool, it should
be able to provide a list of mount options per the policy of the
consumer. Add the "mount_opts" RNG/XML variable and the corresponding
_virStoragePoolSource field to take whatever is provided in the XML
to use in order to create the command.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 docs/formatstorage.html.in                    |  8 ++++++++
 docs/schemas/storagepool.rng                  |  5 +++++
 src/conf/storage_conf.c                       | 12 +++++++++--
 src/conf/storage_conf.h                       |  3 +++
 .../pool-netfs-mountopts.xml                  | 20 +++++++++++++++++++
 .../pool-netfs-mountopts.xml                  | 20 +++++++++++++++++++
 tests/storagepoolxml2xmltest.c                |  1 +
 7 files changed, 67 insertions(+), 2 deletions(-)
 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..491d75c2b1 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -155,6 +155,14 @@
         for a <code>netfs</code> pool type using <code>format</code>
         type "cifs", the path to the Samba share without the leading slash.
         <span class="since">Since 0.4.1</span></dd>
+
+        <p>An optional <code>mount_opts</code> may be provided to add
+        mount options for pools such as <code>netfs</code> in order to
+        provide a list of mount options to be provided to the mount command
+        via the "-o" option during pool startup or creation. The options
+        are passed directly via a string to the command.
+        <span class="since">Since 5.0.0.</span>
+        </p>
       <dt><code>adapter</code></dt>
       <dd>Provides the source for pools backed by SCSI adapters (pool
         type <code>scsi</code>). May only occur once.
diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index 74f4363106..7252d8d44b 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -354,6 +354,11 @@
       <attribute name='path'>
         <ref name='absDirPath'/>
       </attribute>
+      <optional>
+        <attribute name='mount_opts'>
+          <text/>
+        </attribute>
+      </optional>
       <empty/>
     </element>
   </define>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 55db7a96f5..56710395be 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -372,6 +372,7 @@ virStoragePoolSourceClear(virStoragePoolSourcePtr source)
         virStoragePoolSourceDeviceClear(&source->devices[i]);
     VIR_FREE(source->devices);
     VIR_FREE(source->dir);
+    VIR_FREE(source->mountOpts);
     VIR_FREE(source->name);
     virStorageAdapterClear(&source->adapter);
     virStorageSourceInitiatorClear(&source->initiator);
@@ -527,6 +528,9 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
         VIR_STRDUP(source->dir, "/") < 0)
         goto cleanup;
 
+    /* Optional mount options for the directory */
+    source->mountOpts = virXPathString("string(./dir/@mount_opts)", ctxt);
+
     if ((adapternode = virXPathNode("./adapter", ctxt))) {
         if (virStorageAdapterParseXML(&source->adapter, adapternode, ctxt) < 0)
             goto cleanup;
@@ -934,8 +938,12 @@ virStoragePoolSourceFormat(virBufferPtr buf,
         }
     }
 
-    if (options->flags & VIR_STORAGE_POOL_SOURCE_DIR)
-        virBufferEscapeString(buf, "<dir path='%s'/>\n", src->dir);
+    if (options->flags & VIR_STORAGE_POOL_SOURCE_DIR) {
+        virBufferEscapeString(buf, "<dir path='%s'", src->dir);
+        if (src->mountOpts)
+            virBufferEscapeString(buf, " mount_opts='%s'", src->mountOpts);
+        virBufferAddLit(buf, "/>\n");
+    }
 
     if ((options->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER) &&
         (src->adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST ||
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index dc0aa2ab29..780a219d3f 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -175,6 +175,9 @@ struct _virStoragePoolSource {
     /* Or a directory */
     char *dir;
 
+    /* If provided, a list of mount(8) options for mounting the pool's dir */
+    char *mountOpts;
+
     /* Or an adapter */
     virStorageAdapter adapter;
 
diff --git a/tests/storagepoolxml2xmlin/pool-netfs-mountopts.xml b/tests/storagepoolxml2xmlin/pool-netfs-mountopts.xml
new file mode 100644
index 0000000000..ae312f6e5c
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-netfs-mountopts.xml
@@ -0,0 +1,20 @@
+<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' mount_opts="nodev,nosuid"/>
+    <format type='nfs'/>
+  </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..3c6913d370
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-netfs-mountopts.xml
@@ -0,0 +1,20 @@
+<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' mount_opts='nodev,nosuid'/>
+    <format type='nfs'/>
+  </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.17.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]