[libvirt] [PATCH v4 00/10] Allow adding mountOpts to the storage pool mount command

v3: https://www.redhat.com/archives/libvir-list/2019-January/msg00467.html NB: Kept same subject for cover to keep the same context; however, it's now more of a series of a few things... Add default NFS Server options, add nfsvers, and add support for XML namespaces in storage pools which are used by NFS and RBD storage pools. Changes since v3: Remove patch 1 and 3. Rework patch 2 to make the nodev, nosuid, and noexec be the "default options" for the NFS Storage Pool. Created a virStorageBackendFileSystemMountNFSAddOptions in order to add those options for NFS pools using format NFS (and not 'cifs' or 'gluster'). Everything else just gets adjusted/merged based on how the first patch works. John Ferlan (10): storage: Add default mount options for NFS Storage Pools docs: Add news mention of NFS Storage Pool mount options conf: Add optional NFS Source Pool <protocol ver='n'/> option storage: Add the nfsvers to the command line virsh: Add source-protocol-ver for pool commands conf: Introduce virStoragePoolXMLNamespace nfs: Add infrastructure to manage XML namespace options docs,tests: Add schema, description, and tests for NFS namespace storage: Add NFS storage pool namespace options to command line rbd: Utilize storage pool namespace to manage config options docs/formatstorage.html.in | 123 +++++++++++++ docs/news.xml | 11 ++ docs/schemas/storagepool.rng | 50 ++++++ src/conf/storage_conf.c | 73 +++++++- src/conf/storage_conf.h | 27 +++ src/libvirt_private.syms | 1 + src/storage/storage_backend_fs.c | 128 ++++++++++++++ src/storage/storage_backend_rbd.c | 166 +++++++++++++++++- src/storage/storage_util.c | 52 ++++++ src/storage/storage_util.h | 14 ++ tests/Makefile.am | 4 +- .../pool-netfs-auto-freebsd.argv | 1 + .../pool-netfs-auto-linux.argv | 1 + .../pool-netfs-freebsd.argv | 1 + .../pool-netfs-linux.argv | 1 + .../pool-netfs-ns-mountopts-freebsd.argv | 2 + .../pool-netfs-ns-mountopts-linux.argv | 2 + .../pool-netfs-ns-mountopts.argv | 1 + .../pool-netfs-protocol-ver-freebsd.argv | 1 + .../pool-netfs-protocol-ver-linux.argv | 2 + .../pool-netfs-protocol-ver.argv | 1 + tests/storagepoolxml2argvtest.c | 49 +++++- .../pool-netfs-ns-mountopts.xml | 25 +++ .../pool-netfs-protocol-ver.xml | 21 +++ .../pool-rbd-ns-configopts.xml | 17 ++ .../pool-netfs-ns-mountopts.xml | 25 +++ .../pool-netfs-protocol-ver.xml | 21 +++ .../pool-rbd-ns-configopts.xml | 20 +++ tests/storagepoolxml2xmltest.c | 8 + tools/virsh-pool.c | 12 +- tools/virsh.pod | 5 + 31 files changed, 851 insertions(+), 14 deletions(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-ns-mountopts.xml create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-ns-configopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-ns-mountopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-ns-configopts.xml -- 2.20.1

https://bugzilla.redhat.com/show_bug.cgi?id=1584663 Modify the command generation to add some default options to an NFS Storage Pool based on the OS type. For Linux, it'll be the "nodev, nosuid, noexec". For FreeBSD, it'll be "nosuid, noexec". For others, just leave the options alone. Modify the storagepoolxml2argvtest to handle the fact that the same input XML could generate different output XML based on whether Linux, FreeBSD, or other was being built. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 16 ++++++++ .../pool-netfs-auto-freebsd.argv | 1 + .../pool-netfs-auto-linux.argv | 1 + .../pool-netfs-freebsd.argv | 1 + .../pool-netfs-linux.argv | 1 + tests/storagepoolxml2argvtest.c | 40 +++++++++++++++---- 6 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-linux.argv diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index a84ee5b600..44a95d9fab 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -34,6 +34,11 @@ # ifndef FS_NOCOW_FL # define FS_NOCOW_FL 0x00800000 /* Do not cow file */ # endif +# define default_nfs_mount_opts "nodev,nosuid,noexec" +#elif defined(__FreeBSD__) +# define default_nfs_mount_opts "nosuid,noexec" +#else +# define default_nfs_mount_opts "" #endif #if WITH_BLKID @@ -4261,12 +4266,21 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool) } +static void +virStorageBackendFileSystemMountNFSAddOptions(virCommandPtr cmd) +{ + if (*default_nfs_mount_opts != '\0') + virCommandAddArgList(cmd, "-o", default_nfs_mount_opts, NULL); +} + + static void virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd, const char *src, virStoragePoolDefPtr def) { virCommandAddArgList(cmd, src, def->target.path, NULL); + virStorageBackendFileSystemMountNFSAddOptions(cmd); } @@ -4308,6 +4322,8 @@ virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd, else fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format); virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); + if (def->type == VIR_STORAGE_POOL_NETFS) + virStorageBackendFileSystemMountNFSAddOptions(cmd); } diff --git a/tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv b/tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv new file mode 100644 index 0000000000..39e5c97aed --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv @@ -0,0 +1 @@ +mount localhost:/var/lib/libvirt/images /mnt -o nosuid,noexec diff --git a/tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv b/tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv new file mode 100644 index 0000000000..1f82d3d29c --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv @@ -0,0 +1 @@ +mount localhost:/var/lib/libvirt/images /mnt -o nodev,nosuid,noexec diff --git a/tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv b/tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv new file mode 100644 index 0000000000..05c1951f32 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv @@ -0,0 +1 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nosuid,noexec diff --git a/tests/storagepoolxml2argvdata/pool-netfs-linux.argv b/tests/storagepoolxml2argvdata/pool-netfs-linux.argv new file mode 100644 index 0000000000..22fafd7b32 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-linux.argv @@ -0,0 +1 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nodev,nosuid,noexec diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c index 2f2d40e027..c114fecbcf 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -96,6 +96,8 @@ testCompareXMLToArgvFiles(bool shouldFail, struct testInfo { bool shouldFail; const char *pool; + bool linuxOut; + bool freebsdOut; }; static int @@ -110,9 +112,19 @@ testCompareXMLToArgvHelper(const void *data) abs_srcdir, info->pool) < 0) goto cleanup; - if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s.argv", - abs_srcdir, info->pool) < 0 && !info->shouldFail) - goto cleanup; + if (info->linuxOut) { + if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s-linux.argv", + abs_srcdir, info->pool) < 0 && !info->shouldFail) + goto cleanup; + } else if (info->freebsdOut) { + if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s-freebsd.argv", + abs_srcdir, info->pool) < 0 && !info->shouldFail) + goto cleanup; + } else { + if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s.argv", + abs_srcdir, info->pool) < 0 && !info->shouldFail) + goto cleanup; + } result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline); @@ -129,9 +141,9 @@ mymain(void) { int ret = 0; -#define DO_TEST_FULL(shouldFail, pool) \ +#define DO_TEST_FULL(shouldFail, pool, linuxOut, freebsdOut) \ do { \ - struct testInfo info = { shouldFail, pool }; \ + struct testInfo info = { shouldFail, pool, linuxOut, freebsdOut }; \ if (virTestRun("Storage Pool XML-2-argv " pool, \ testCompareXMLToArgvHelper, &info) < 0) \ ret = -1; \ @@ -139,10 +151,16 @@ mymain(void) while (0); #define DO_TEST(pool, ...) \ - DO_TEST_FULL(false, pool) + DO_TEST_FULL(false, pool, false, false) #define DO_TEST_FAIL(pool, ...) \ - DO_TEST_FULL(true, pool) + DO_TEST_FULL(true, pool, false, false) + +#define DO_TEST_LINUX(pool, ...) \ + DO_TEST_FULL(false, pool, true, false) + +#define DO_TEST_FREEBSD(pool, ...) \ + DO_TEST_FULL(false, pool, false, true) DO_TEST_FAIL("pool-dir"); DO_TEST_FAIL("pool-dir-naming"); @@ -155,8 +173,16 @@ mymain(void) DO_TEST_FAIL("pool-disk-device-nopartsep"); DO_TEST_FAIL("pool-iscsi"); DO_TEST_FAIL("pool-iscsi-auth"); +#ifdef __linux__ + DO_TEST_LINUX("pool-netfs"); + DO_TEST_LINUX("pool-netfs-auto"); +#elif defined(__FreeBSD__) + DO_TEST_FREEBSD("pool-netfs"); + DO_TEST_FREEBSD("pool-netfs-auto"); +#else DO_TEST("pool-netfs"); DO_TEST("pool-netfs-auto"); +#endif DO_TEST("pool-netfs-gluster"); DO_TEST("pool-netfs-cifs"); DO_TEST_FAIL("pool-scsi"); -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:07PM -0500, John Ferlan wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1584663
Modify the command generation to add some default options to an NFS Storage Pool based on the OS type. For Linux, it'll be the "nodev, nosuid, noexec". For FreeBSD, it'll be "nosuid, noexec". For others, just leave the options alone.
Modify the storagepoolxml2argvtest to handle the fact that the same input XML could generate different output XML based on whether Linux, FreeBSD, or other was being built.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 16 ++++++++ .../pool-netfs-auto-freebsd.argv | 1 + .../pool-netfs-auto-linux.argv | 1 + .../pool-netfs-freebsd.argv | 1 + .../pool-netfs-linux.argv | 1 + tests/storagepoolxml2argvtest.c | 40 +++++++++++++++---- 6 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-linux.argv
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index a84ee5b600..44a95d9fab 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -34,6 +34,11 @@ # ifndef FS_NOCOW_FL # define FS_NOCOW_FL 0x00800000 /* Do not cow file */ # endif +# define default_nfs_mount_opts "nodev,nosuid,noexec" +#elif defined(__FreeBSD__) +# define default_nfs_mount_opts "nosuid,noexec" +#else +# define default_nfs_mount_opts "" #endif
#if WITH_BLKID @@ -4261,12 +4266,21 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool) }
+static void +virStorageBackendFileSystemMountNFSAddOptions(virCommandPtr cmd) +{ + if (*default_nfs_mount_opts != '\0') + virCommandAddArgList(cmd, "-o", default_nfs_mount_opts, NULL); +} + + static void virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd, const char *src, virStoragePoolDefPtr def) { virCommandAddArgList(cmd, src, def->target.path, NULL); + virStorageBackendFileSystemMountNFSAddOptions(cmd); }
@@ -4308,6 +4322,8 @@ virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd, else fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format); virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); + if (def->type == VIR_STORAGE_POOL_NETFS) + virStorageBackendFileSystemMountNFSAddOptions(cmd);
This doesn't need to be restricted to just NFS. A kind of filesystem we mount as a storage pool should use these extra options, as they are general purpose mount options, not FS specific. Just s/nfs//i in all the method names / constants. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On 1/29/19 6:44 AM, Daniel P. Berrangé wrote:
On Thu, Jan 17, 2019 at 04:22:07PM -0500, John Ferlan wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1584663
Modify the command generation to add some default options to an NFS Storage Pool based on the OS type. For Linux, it'll be the "nodev, nosuid, noexec". For FreeBSD, it'll be "nosuid, noexec". For others, just leave the options alone.
Modify the storagepoolxml2argvtest to handle the fact that the same input XML could generate different output XML based on whether Linux, FreeBSD, or other was being built.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 16 ++++++++ .../pool-netfs-auto-freebsd.argv | 1 + .../pool-netfs-auto-linux.argv | 1 + .../pool-netfs-freebsd.argv | 1 + .../pool-netfs-linux.argv | 1 + tests/storagepoolxml2argvtest.c | 40 +++++++++++++++---- 6 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-linux.argv
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index a84ee5b600..44a95d9fab 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -34,6 +34,11 @@ # ifndef FS_NOCOW_FL # define FS_NOCOW_FL 0x00800000 /* Do not cow file */ # endif +# define default_nfs_mount_opts "nodev,nosuid,noexec" +#elif defined(__FreeBSD__) +# define default_nfs_mount_opts "nosuid,noexec" +#else +# define default_nfs_mount_opts "" #endif
#if WITH_BLKID @@ -4261,12 +4266,21 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool) }
+static void +virStorageBackendFileSystemMountNFSAddOptions(virCommandPtr cmd) +{ + if (*default_nfs_mount_opts != '\0') + virCommandAddArgList(cmd, "-o", default_nfs_mount_opts, NULL); +} + + static void virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd, const char *src, virStoragePoolDefPtr def) { virCommandAddArgList(cmd, src, def->target.path, NULL); + virStorageBackendFileSystemMountNFSAddOptions(cmd); }
@@ -4308,6 +4322,8 @@ virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd, else fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format); virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); + if (def->type == VIR_STORAGE_POOL_NETFS) + virStorageBackendFileSystemMountNFSAddOptions(cmd);
This doesn't need to be restricted to just NFS. A kind of filesystem we mount as a storage pool should use these extra options, as they are general purpose mount options, not FS specific.
Just s/nfs//i in all the method names / constants.
I can modify default_nfs_mount_opts to be just default_mount_opts; however, as you see going forward the new method ends up being used by patch4 for "nfsvers=%u," and patch9 for Namespace options, so I thinking keeping the name virStorageBackendFileSystemMountNFSAddOptions is better. Fair enough? John With diffs squashed in: diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 44a95d9fab..8d78162a5a 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -34,11 +34,11 @@ # ifndef FS_NOCOW_FL # define FS_NOCOW_FL 0x00800000 /* Do not cow file */ # endif -# define default_nfs_mount_opts "nodev,nosuid,noexec" +# define default_mount_opts "nodev,nosuid,noexec" #elif defined(__FreeBSD__) -# define default_nfs_mount_opts "nosuid,noexec" +# define default_mount_opts "nosuid,noexec" #else -# define default_nfs_mount_opts "" +# define default_mount_opts "" #endif #if WITH_BLKID @@ -4269,8 +4269,8 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool) static void virStorageBackendFileSystemMountNFSAddOptions(virCommandPtr cmd) { - if (*default_nfs_mount_opts != '\0') - virCommandAddArgList(cmd, "-o", default_nfs_mount_opts, NULL); + if (*default_mount_opts != '\0') + virCommandAddArgList(cmd, "-o", default_mount_opts, NULL); }

On Tue, Jan 29, 2019 at 08:43:31AM -0500, John Ferlan wrote:
On 1/29/19 6:44 AM, Daniel P. Berrangé wrote:
On Thu, Jan 17, 2019 at 04:22:07PM -0500, John Ferlan wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1584663
Modify the command generation to add some default options to an NFS Storage Pool based on the OS type. For Linux, it'll be the "nodev, nosuid, noexec". For FreeBSD, it'll be "nosuid, noexec". For others, just leave the options alone.
Modify the storagepoolxml2argvtest to handle the fact that the same input XML could generate different output XML based on whether Linux, FreeBSD, or other was being built.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 16 ++++++++ .../pool-netfs-auto-freebsd.argv | 1 + .../pool-netfs-auto-linux.argv | 1 + .../pool-netfs-freebsd.argv | 1 + .../pool-netfs-linux.argv | 1 + tests/storagepoolxml2argvtest.c | 40 +++++++++++++++---- 6 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-linux.argv
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index a84ee5b600..44a95d9fab 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -34,6 +34,11 @@ # ifndef FS_NOCOW_FL # define FS_NOCOW_FL 0x00800000 /* Do not cow file */ # endif +# define default_nfs_mount_opts "nodev,nosuid,noexec" +#elif defined(__FreeBSD__) +# define default_nfs_mount_opts "nosuid,noexec" +#else +# define default_nfs_mount_opts "" #endif
#if WITH_BLKID @@ -4261,12 +4266,21 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool) }
+static void +virStorageBackendFileSystemMountNFSAddOptions(virCommandPtr cmd) +{ + if (*default_nfs_mount_opts != '\0') + virCommandAddArgList(cmd, "-o", default_nfs_mount_opts, NULL); +} + + static void virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd, const char *src, virStoragePoolDefPtr def) { virCommandAddArgList(cmd, src, def->target.path, NULL); + virStorageBackendFileSystemMountNFSAddOptions(cmd); }
@@ -4308,6 +4322,8 @@ virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd, else fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format); virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); + if (def->type == VIR_STORAGE_POOL_NETFS) + virStorageBackendFileSystemMountNFSAddOptions(cmd);
This doesn't need to be restricted to just NFS. A kind of filesystem we mount as a storage pool should use these extra options, as they are general purpose mount options, not FS specific.
Just s/nfs//i in all the method names / constants.
I can modify default_nfs_mount_opts to be just default_mount_opts; however, as you see going forward the new method ends up being used by patch4 for "nfsvers=%u," and patch9 for Namespace options, so I thinking keeping the name virStorageBackendFileSystemMountNFSAddOptions is better.
I mentioned later for patch 9 that the namespace options should apply for any filesystem mounts we do IOW, both pool type=fs and type=netfs. In fact even for type=netfs, we can't assume it is NFS - it could be a CIFS or GlusterFS pool, rather than NFS so the name is a bit misleading in that respect anyway. For patch 4, we just need to push the check for whether it is NFS down into the virStorageBackendFileSystemMountAddOptions method, so it only formats the nfsvers for that specific pool config. Presumably the XML parser stops us even parsing the protocol out of the XML unless type == netfs + format==nfs, so we'd be ok even without the check, but its less suprising to have the explicit check anyway. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Signed-off-by: John Ferlan <jferlan@redhat.com> --- docs/news.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index bc11791d03..12bff206c1 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -39,6 +39,17 @@ <section title="Improvements"> </section> <section title="Bug fixes"> + <change> + <summary> + storage: Add default mount options for NFS Storage Pools + </summary> + <description> + Altered the command line generation for NFS Storage Pools to + add some default options. For Linux based systems, the options + added are "nodev, nosuid, noexec". For FreeBSD based systems, + the options added are "nosuid, noexec". + </description> + </change> </section> </release> <release version="v5.0.0" date="2019-01-15"> -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:08PM -0500, John Ferlan wrote:
Signed-off-by: John Ferlan <jferlan@redhat.com> --- docs/news.xml | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/docs/news.xml b/docs/news.xml index bc11791d03..12bff206c1 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -39,6 +39,17 @@ <section title="Improvements"> </section> <section title="Bug fixes"> + <change> + <summary> + storage: Add default mount options for NFS Storage Pools + </summary> + <description> + Altered the command line generation for NFS Storage Pools to + add some default options. For Linux based systems, the options + added are "nodev, nosuid, noexec". For FreeBSD based systems, + the options added are "nosuid, noexec". + </description> + </change> </section> </release> <release version="v5.0.0" date="2019-01-15">
If you generalize the text so its not just NFS per previous patch comments Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Add an optional way to define which NFS Server version will be used to content the target NFS server. Signed-off-by: John Ferlan <jferlan@redhat.com> --- docs/formatstorage.html.in | 16 ++++++++++++++ docs/schemas/storagepool.rng | 7 ++++++ src/conf/storage_conf.c | 22 +++++++++++++++++++ src/conf/storage_conf.h | 3 +++ .../pool-netfs-protocol-ver.xml | 21 ++++++++++++++++++ .../pool-netfs-protocol-ver.xml | 21 ++++++++++++++++++ tests/storagepoolxml2xmltest.c | 1 + 7 files changed, 91 insertions(+) create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in index b6bf3edbd2..b1b76a1dda 100644 --- a/docs/formatstorage.html.in +++ b/docs/formatstorage.html.in @@ -121,6 +121,16 @@ </source> ...</pre> + <pre> +... + <source> + <host name='localhost'/> + <dir path='/var/lib/libvirt/images'/> + <format type='nfs'/> + <protocol ver='3'/> + </source> +...</pre> + <dl> <dt><code>device</code></dt> <dd>Provides the source for pools backed by physical devices @@ -386,6 +396,12 @@ 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>protocol</code></dt> + <dd>For a <code>netfs</code> Storage Pool provide a mechanism to + define which NFS protocol version number will be used to contact + the server's NFS service. The attribute <code>ver</code> accepts + an unsigned integer as the version number to use. + <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..f9a16422cc 100644 --- a/docs/schemas/storagepool.rng +++ b/docs/schemas/storagepool.rng @@ -531,6 +531,13 @@ <ref name='sourceinfohost'/> <ref name='sourceinfodir'/> <ref name='sourcefmtnetfs'/> + <optional> + <element name='protocol'> + <attribute name='ver'> + <ref name='unsignedInt'/> + </attribute> + </element> + </optional> <optional> <ref name='sourceinfovendor'/> </optional> diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 55db7a96f5..76e0bb987b 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -420,6 +420,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, virStorageAuthDefPtr authdef = NULL; char *name = NULL; char *port = NULL; + char *ver = NULL; int n; relnode = ctxt->node; @@ -546,6 +547,24 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, authdef = NULL; } + /* Option protocol version string (NFSvN) */ + if ((ver = virXPathString("string(./protocol/@ver)", ctxt))) { + if ((source->format != VIR_STORAGE_POOL_NETFS_NFS) && + (source->format != VIR_STORAGE_POOL_NETFS_AUTO)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("storage pool protocol ver unsupported for " + "pool type '%s'"), + virStoragePoolFormatFileSystemNetTypeToString(source->format)); + goto cleanup; + } + if (virStrToLong_uip(ver, NULL, 0, &source->protocolVer) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("storage pool protocol ver '%s' is malformaed"), + ver); + goto cleanup; + } + } + source->vendor = virXPathString("string(./vendor/@name)", ctxt); source->product = virXPathString("string(./product/@name)", ctxt); @@ -962,6 +981,9 @@ virStoragePoolSourceFormat(virBufferPtr buf, if (src->auth) virStorageAuthDefFormat(buf, src->auth); + if (src->protocolVer) + virBufferAsprintf(buf, "<protocol ver='%u'/>\n", src->protocolVer); + 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..a6763447a7 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -197,6 +197,9 @@ struct _virStoragePoolSource { * or lvm version, etc. */ int format; + + /* Protocol version value for netfs */ + unsigned int protocolVer; }; typedef struct _virStoragePoolTarget virStoragePoolTarget; diff --git a/tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml b/tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml new file mode 100644 index 0000000000..40f3f94e41 --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml @@ -0,0 +1,21 @@ +<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'/> + <protocol ver='3'/> + </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-protocol-ver.xml b/tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml new file mode 100644 index 0000000000..5fcad1305b --- /dev/null +++ b/tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml @@ -0,0 +1,21 @@ +<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'/> + <protocol ver='3'/> + </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..d18390034f 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -83,6 +83,7 @@ mymain(void) DO_TEST("pool-iscsi-auth"); DO_TEST("pool-netfs"); DO_TEST("pool-netfs-auto"); + DO_TEST("pool-netfs-protocol-ver"); DO_TEST("pool-netfs-gluster"); DO_TEST("pool-netfs-cifs"); DO_TEST("pool-scsi"); -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:09PM -0500, John Ferlan wrote:
Add an optional way to define which NFS Server version will be used to content the target NFS server.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- docs/formatstorage.html.in | 16 ++++++++++++++ docs/schemas/storagepool.rng | 7 ++++++ src/conf/storage_conf.c | 22 +++++++++++++++++++ src/conf/storage_conf.h | 3 +++ .../pool-netfs-protocol-ver.xml | 21 ++++++++++++++++++ .../pool-netfs-protocol-ver.xml | 21 ++++++++++++++++++ tests/storagepoolxml2xmltest.c | 1 + 7 files changed, 91 insertions(+) create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

If protocolVer present, add the -o nfsvers=# to the command line for the NFS Storage Pool Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 20 +++++++++++++++---- .../pool-netfs-protocol-ver-freebsd.argv | 1 + .../pool-netfs-protocol-ver-linux.argv | 2 ++ .../pool-netfs-protocol-ver.argv | 1 + tests/storagepoolxml2argvtest.c | 3 +++ 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 44a95d9fab..b82bef2904 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -4267,10 +4267,22 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool) static void -virStorageBackendFileSystemMountNFSAddOptions(virCommandPtr cmd) +virStorageBackendFileSystemMountNFSAddOptions(virCommandPtr cmd, + virStoragePoolDefPtr def) { + VIR_AUTOFREE(char *) mountOpts = NULL; + virBuffer buf = VIR_BUFFER_INITIALIZER; + + if (def->source.protocolVer > 0) + virBufferAsprintf(&buf, "nfsvers=%u,", def->source.protocolVer); + if (*default_nfs_mount_opts != '\0') - virCommandAddArgList(cmd, "-o", default_nfs_mount_opts, NULL); + virBufferAddLit(&buf, default_nfs_mount_opts); + + virBufferTrim(&buf, ",", -1); + mountOpts = virBufferContentAndReset(&buf); + if (mountOpts) + virCommandAddArgList(cmd, "-o", mountOpts, NULL); } @@ -4280,7 +4292,7 @@ virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd, virStoragePoolDefPtr def) { virCommandAddArgList(cmd, src, def->target.path, NULL); - virStorageBackendFileSystemMountNFSAddOptions(cmd); + virStorageBackendFileSystemMountNFSAddOptions(cmd, def); } @@ -4323,7 +4335,7 @@ virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd, fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format); virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); if (def->type == VIR_STORAGE_POOL_NETFS) - virStorageBackendFileSystemMountNFSAddOptions(cmd); + virStorageBackendFileSystemMountNFSAddOptions(cmd, def); } diff --git a/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv new file mode 100644 index 0000000000..3384a8a8dd --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv @@ -0,0 +1 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3,nosuid,noexec diff --git a/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv new file mode 100644 index 0000000000..7508046340 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv @@ -0,0 +1,2 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3,nodev,nosuid,\ +noexec diff --git a/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv new file mode 100644 index 0000000000..f26656d5b8 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv @@ -0,0 +1 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3 diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c index c114fecbcf..b6a46280cd 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -176,12 +176,15 @@ mymain(void) #ifdef __linux__ DO_TEST_LINUX("pool-netfs"); DO_TEST_LINUX("pool-netfs-auto"); + DO_TEST_LINUX("pool-netfs-protocol-ver"); #elif defined(__FreeBSD__) DO_TEST_FREEBSD("pool-netfs"); DO_TEST_FREEBSD("pool-netfs-auto"); + DO_TEST_FREEBSD("pool-netfs-protocol-ver"); #else DO_TEST("pool-netfs"); DO_TEST("pool-netfs-auto"); + DO_TEST("pool-netfs-protocol-ver"); #endif DO_TEST("pool-netfs-gluster"); DO_TEST("pool-netfs-cifs"); -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:10PM -0500, John Ferlan wrote:
If protocolVer present, add the -o nfsvers=# to the command line for the NFS Storage Pool
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 20 +++++++++++++++---- .../pool-netfs-protocol-ver-freebsd.argv | 1 + .../pool-netfs-protocol-ver-linux.argv | 2 ++ .../pool-netfs-protocol-ver.argv | 1 + tests/storagepoolxml2argvtest.c | 3 +++ 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Allow the addition of the <protocol ver='n'/> to the provided XML. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-pool.c | 12 ++++++++++-- tools/virsh.pod | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 70ca39bd3d..9514570468 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -136,6 +136,10 @@ {.name = "adapter-parent-fabric-wwn", \ .type = VSH_OT_STRING, \ .help = N_("adapter parent scsi_hostN fabric_wwn to be used for underlying vHBA storage") \ + }, \ + {.name = "source-protocol-ver", \ + .type = VSH_OT_STRING, \ + .help = N_("nfsvers value for NFS pool mount option") \ } virStoragePoolPtr @@ -319,7 +323,7 @@ virshBuildPoolXML(vshControl *ctl, *secretUsage = NULL, *adapterName = NULL, *adapterParent = NULL, *adapterWwnn = NULL, *adapterWwpn = NULL, *secretUUID = NULL, *adapterParentWwnn = NULL, *adapterParentWwpn = NULL, - *adapterParentFabricWwn = NULL; + *adapterParentFabricWwn = NULL, *protoVer = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; VSH_EXCLUSIVE_OPTIONS("secret-usage", "secret-uuid"); @@ -345,7 +349,8 @@ virshBuildPoolXML(vshControl *ctl, vshCommandOptStringReq(ctl, cmd, "adapter-parent", &adapterParent) < 0 || vshCommandOptStringReq(ctl, cmd, "adapter-parent-wwnn", &adapterParentWwnn) < 0 || vshCommandOptStringReq(ctl, cmd, "adapter-parent-wwpn", &adapterParentWwpn) < 0 || - vshCommandOptStringReq(ctl, cmd, "adapter-parent-fabric-wwn", &adapterParentFabricWwn) < 0) + vshCommandOptStringReq(ctl, cmd, "adapter-parent-fabric-wwn", &adapterParentFabricWwn) < 0 || + vshCommandOptStringReq(ctl, cmd, "source-protocol-ver", &protoVer) < 0) goto cleanup; virBufferAsprintf(&buf, "<pool type='%s'>\n", type); @@ -394,6 +399,9 @@ virshBuildPoolXML(vshControl *ctl, if (srcName) virBufferAsprintf(&buf, "<name>%s</name>\n", srcName); + if (protoVer) + virBufferAsprintf(&buf, "<protocol ver='%s'/>\n", protoVer); + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</source>\n"); } diff --git a/tools/virsh.pod b/tools/virsh.pod index 86a4996cae..59a5900162 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3887,6 +3887,7 @@ just I<--build> is provided, then B<pool-build> is called with no flags. [I<--source-name name>] [I<--target path>] [I<--source-format format>] [I<--auth-type authtype> I<--auth-username username> [I<--secret-usage usage> | I<--secret-uuid uuid>]] +[I<--source-protocol-ver ver>] [[I<--adapter-name name>] | [I<--adapter-wwnn> wwnn I<--adapter-wwpn> wwpn] [I<--adapter-parent parent> | I<--adapter-parent-wwnn parent_wwnn> I<adapter-parent-wwpn parent_wwpn> | @@ -3929,6 +3930,10 @@ the storage pool. The I<authtype> is either chap for iscsi I<type> pools or ceph for rbd I<type> pools. Either the secret I<usage> or I<uuid> value may be provided, but not both. +[I<--source-protocol-ver ver>] provides the NFS protocol version number used +to contact the server's NFS service via nfs mount option 'nfsvers=n'. It is +expect the I<ver> value is an unsigned integer. + [I<--adapter-name name>] defines the scsi_hostN adapter name to be used for the scsi_host adapter type pool. -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:11PM -0500, John Ferlan wrote:
Allow the addition of the <protocol ver='n'/> to the provided XML.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-pool.c | 12 ++++++++++-- tools/virsh.pod | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Introduce the infrastructure necessary to manage a Storage Pool XML Namespace. The general concept is similar to virDomainXMLNamespace, except that for Storage Pools the storage backend specific details can be stored within the _virStoragePoolOptions unlike the domain processing code which manages its xmlopt's via the virDomainXMLOption which is allocated/passed around for each domain. This patch defines the add the parse, format, free, and href methods required to process the XML and callout from the Storage Pool Def parse, format, and free API's to perform the action on the XML data for/from the backend. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/storage_conf.c | 51 +++++++++++++++++++++++++++++++++++++++- src/conf/storage_conf.h | 24 +++++++++++++++++++ src/libvirt_private.syms | 1 + 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 76e0bb987b..a7298381ef 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -124,6 +124,9 @@ typedef virStoragePoolOptions *virStoragePoolOptionsPtr; struct _virStoragePoolOptions { unsigned int flags; int defaultFormat; + + virStoragePoolXMLNamespace ns; + virStoragePoolFormatToString formatToString; virStoragePoolFormatFromString formatFromString; }; @@ -318,6 +321,34 @@ virStoragePoolOptionsForPoolType(int type) } +/* virStoragePoolOptionsPoolTypeSetXMLNamespace: + * @type: virStoragePoolType + * @ns: xmlopt namespace pointer + * + * Store the @ns in the pool options for the particular backend. + * This allows the parse/format code to then directly call the Namespace + * method space (parse, format, href, free) as needed during processing. + * + * Returns: 0 on success, -1 on failure. + */ +int +virStoragePoolOptionsPoolTypeSetXMLNamespace(int type, + virStoragePoolXMLNamespacePtr ns) +{ + int ret = -1; + virStoragePoolTypeInfoPtr backend = virStoragePoolTypeInfoLookup(type); + + if (!backend) + goto cleanup; + + backend->poolOptions.ns = *ns; + ret = 0; + + cleanup: + return ret; +} + + static virStorageVolOptionsPtr virStorageVolOptionsForPoolType(int type) { @@ -401,6 +432,8 @@ virStoragePoolDefFree(virStoragePoolDefPtr def) VIR_FREE(def->target.path); VIR_FREE(def->target.perms.label); + if (def->namespaceData && def->ns.free) + (def->ns.free)(def->namespaceData); VIR_FREE(def); } @@ -835,6 +868,13 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) goto error; } + /* Make a copy of all the callback pointers here for easier use, + * especially during the virStoragePoolSourceClear method */ + ret->ns = options->ns; + if (ret->ns.parse && + (ret->ns.parse)(ctxt, &ret->namespaceData) < 0) + goto error; + cleanup: VIR_FREE(uuid); VIR_FREE(type); @@ -1011,7 +1051,10 @@ virStoragePoolDefFormatBuf(virBufferPtr buf, _("unexpected pool type")); return -1; } - virBufferAsprintf(buf, "<pool type='%s'>\n", type); + virBufferAsprintf(buf, "<pool type='%s'", type); + if (def->namespaceData && def->ns.href) + virBufferAsprintf(buf, " %s", (def->ns.href)()); + virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); virBufferEscapeString(buf, "<name>%s</name>\n", def->name); @@ -1064,6 +1107,12 @@ virStoragePoolDefFormatBuf(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</target>\n"); } + + if (def->namespaceData && def->ns.format) { + if ((def->ns.format)(buf, def->namespaceData) < 0) + return -1; + } + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</pool>\n"); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index a6763447a7..24217eb401 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -33,6 +33,26 @@ # include <libxml/tree.h> +/* Various callbacks needed to parse/create Storage Pool XML's using + * a private namespace */ +typedef int (*virStoragePoolDefNamespaceParse)(xmlXPathContextPtr, void **); +typedef void (*virStoragePoolDefNamespaceFree)(void *); +typedef int (*virStoragePoolDefNamespaceXMLFormat)(virBufferPtr, void *); +typedef const char *(*virStoragePoolDefNamespaceHref)(void); + +typedef struct _virStoragePoolXMLNamespace virStoragePoolXMLNamespace; +typedef virStoragePoolXMLNamespace *virStoragePoolXMLNamespacePtr; +struct _virStoragePoolXMLNamespace { + virStoragePoolDefNamespaceParse parse; + virStoragePoolDefNamespaceFree free; + virStoragePoolDefNamespaceXMLFormat format; + virStoragePoolDefNamespaceHref href; +}; + +int +virStoragePoolOptionsPoolTypeSetXMLNamespace(int type, + virStoragePoolXMLNamespacePtr ns); + /* * How the volume's data is stored on underlying * physical devices - can potentially span many @@ -222,6 +242,10 @@ struct _virStoragePoolDef { virStoragePoolSource source; virStoragePoolTarget target; + + /* Pool backend specific XML namespace data */ + void *namespaceData; + virStoragePoolXMLNamespace ns; }; typedef struct _virStoragePoolSourceList virStoragePoolSourceList; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c3d6306809..4d82797ee1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -919,6 +919,7 @@ virStoragePoolFormatDiskTypeToString; virStoragePoolFormatFileSystemNetTypeToString; virStoragePoolFormatFileSystemTypeToString; virStoragePoolFormatLogicalTypeToString; +virStoragePoolOptionsPoolTypeSetXMLNamespace; virStoragePoolSaveConfig; virStoragePoolSaveState; virStoragePoolSourceClear; -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:12PM -0500, John Ferlan wrote:
Introduce the infrastructure necessary to manage a Storage Pool XML Namespace. The general concept is similar to virDomainXMLNamespace, except that for Storage Pools the storage backend specific details can be stored within the _virStoragePoolOptions unlike the domain processing code which manages its xmlopt's via the virDomainXMLOption which is allocated/passed around for each domain.
This patch defines the add the parse, format, free, and href methods required to process the XML and callout from the Storage Pool Def parse, format, and free API's to perform the action on the XML data for/from the backend.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/storage_conf.c | 51 +++++++++++++++++++++++++++++++++++++++- src/conf/storage_conf.h | 24 +++++++++++++++++++ src/libvirt_private.syms | 1 + 3 files changed, 75 insertions(+), 1 deletion(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Introduce the virStoragePoolNetFSMountOptionsDef to be used to manage the NFS Storage Pool XML Namespace for mount options. Using a new virStorageBackendNamespaceInit function, set the virStoragePoolXMLNamespace into the _virStoragePoolOptions when the storage backend is loaded. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_backend_fs.c | 128 +++++++++++++++++++++++++++++++ src/storage/storage_util.c | 16 ++++ src/storage/storage_util.h | 14 ++++ 3 files changed, 158 insertions(+) diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index dc9869417e..b82215fcdb 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -41,6 +41,7 @@ VIR_LOG_INIT("storage.storage_backend_fs"); #if WITH_STORAGE_FS +# include <libxml/xpathInternals.h> # include <mntent.h> struct _virNetfsDiscoverState { @@ -559,6 +560,122 @@ virStorageBackendFileSystemBuild(virStoragePoolObjPtr pool, } +#if WITH_STORAGE_FS + +# define STORAGE_POOL_NETFS_NAMESPACE_HREF "http://libvirt.org/schemas/storagepool/source/netfs/1.0" + +/* NetFS backend XML Namespace handling for nfs specific mount options to + * be added to the mount -o {options_list} command line. The XML will use + * the format, such as: + * + * <netfs:mount_opts> + * <netfs:option name='nodev'/> + * <netfs:option name='nosuid'/> + * </netfs:mount_opts> + * + * and the <pool type='netfs'> is required to have a "xmlns:netfs='%s'" + * attribute using the STORAGE_POOL_NETFS_NAMESPACE_HREF + */ + +static void +virStoragePoolDefNetFSNamespaceFree(void *nsdata) +{ + virStoragePoolNetFSMountOptionsDefPtr cmdopts = nsdata; + size_t i; + + if (!cmdopts) + return; + + for (i = 0; i < cmdopts->noptions; i++) + VIR_FREE(cmdopts->options[i]); + VIR_FREE(cmdopts->options); + + VIR_FREE(cmdopts); +} + + +static int +virStoragePoolDefNetFSNamespaceParse(xmlXPathContextPtr ctxt, + void **data) +{ + virStoragePoolNetFSMountOptionsDefPtr cmdopts = NULL; + xmlNodePtr *nodes = NULL; + int nnodes; + size_t i; + int ret = -1; + + if (xmlXPathRegisterNs(ctxt, BAD_CAST "netfs", + BAD_CAST STORAGE_POOL_NETFS_NAMESPACE_HREF) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to register xml namespace '%s'"), + STORAGE_POOL_NETFS_NAMESPACE_HREF); + return -1; + } + + nnodes = virXPathNodeSet("./netfs:mount_opts/netfs:option", ctxt, &nodes); + if (nnodes < 0) + return -1; + + if (nnodes == 0) + return 0; + + if (VIR_ALLOC(cmdopts) < 0 || + VIR_ALLOC_N(cmdopts->options, nnodes) < 0) + goto cleanup; + + for (i = 0; i < nnodes; i++) { + if (!(cmdopts->options[cmdopts->noptions] = + virXMLPropString(nodes[i], "name"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("no netfs mount option name specified")); + goto cleanup; + } + cmdopts->noptions++; + } + + VIR_STEAL_PTR(*data, cmdopts); + ret = 0; + + cleanup: + VIR_FREE(nodes); + virStoragePoolDefNetFSNamespaceFree(cmdopts); + return ret; +} + + +static int +virStoragePoolDefNetFSNamespaceFormatXML(virBufferPtr buf, + void *nsdata) +{ + size_t i; + virStoragePoolNetFSMountOptionsDefPtr def = nsdata; + + if (!def) + return 0; + + virBufferAddLit(buf, "<netfs:mount_opts>\n"); + virBufferAdjustIndent(buf, 2); + + for (i = 0; i < def->noptions; i++) + virBufferEscapeString(buf, "<netfs:option name='%s'/>\n", + def->options[i]); + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "</netfs:mount_opts>\n"); + + return 0; +} + + +static const char * +virStoragePoolDefNetFSNamespaceHref(void) +{ + return "xmlns:netfs='" STORAGE_POOL_NETFS_NAMESPACE_HREF "'"; +} + +#endif /* WITH_STORAGE_FS */ + + virStorageBackend virStorageBackendDirectory = { .type = VIR_STORAGE_POOL_DIR, @@ -617,6 +734,13 @@ virStorageBackend virStorageBackendNetFileSystem = { .downloadVol = virStorageBackendVolDownloadLocal, .wipeVol = virStorageBackendVolWipeLocal, }; + +static virStoragePoolXMLNamespace virStoragePoolNetFSXMLNamespace = { + .parse = virStoragePoolDefNetFSNamespaceParse, + .free = virStoragePoolDefNetFSNamespaceFree, + .format = virStoragePoolDefNetFSNamespaceFormatXML, + .href = virStoragePoolDefNetFSNamespaceHref, +}; #endif /* WITH_STORAGE_FS */ @@ -632,6 +756,10 @@ virStorageBackendFsRegister(void) if (virStorageBackendRegister(&virStorageBackendNetFileSystem) < 0) return -1; + + if (virStorageBackendNamespaceInit(VIR_STORAGE_POOL_NETFS, + &virStoragePoolNetFSXMLNamespace) < 0) + return -1; #endif /* WITH_STORAGE_FS */ return 0; diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index b82bef2904..2e753f4501 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -82,6 +82,22 @@ VIR_LOG_INIT("storage.storage_util"); + +/* virStorageBackendNamespaceInit: + * @poolType: virStoragePoolType + * @xmlns: Storage Pool specific namespace callback methods + * + * To be called during storage backend registration to configure the + * Storage Pool XML Namespace based on the backend's needs. + */ +int +virStorageBackendNamespaceInit(int poolType, + virStoragePoolXMLNamespacePtr xmlns) +{ + return virStoragePoolOptionsPoolTypeSetXMLNamespace(poolType, xmlns); +} + + #define READ_BLOCK_SIZE_DEFAULT (1024 * 1024) #define WRITE_BLOCK_SIZE_DEFAULT (4 * 1024) diff --git a/src/storage/storage_util.h b/src/storage/storage_util.h index c872468135..b11b1b23f7 100644 --- a/src/storage/storage_util.h +++ b/src/storage/storage_util.h @@ -26,6 +26,20 @@ # include "storage_driver.h" # include "storage_backend.h" +/* NetFS Storage Pool Namespace options to share w/ storage_backend_fs.c and + * the virStorageBackendFileSystemMountCmd method */ +typedef struct _virStoragePoolNetFSMountOptionsDef virStoragePoolNetFSMountOptionsDef; +typedef virStoragePoolNetFSMountOptionsDef *virStoragePoolNetFSMountOptionsDefPtr; +struct _virStoragePoolNetFSMountOptionsDef { + size_t noptions; + char **options; +}; + +int +virStorageBackendNamespaceInit(int poolType, + virStoragePoolXMLNamespacePtr xmlns); + + /* File creation/cloning functions used for cloning between backends */ int -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:13PM -0500, John Ferlan wrote:
Introduce the virStoragePoolNetFSMountOptionsDef to be used to manage the NFS Storage Pool XML Namespace for mount options.
Using a new virStorageBackendNamespaceInit function, set the virStoragePoolXMLNamespace into the _virStoragePoolOptions when the storage backend is loaded.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_backend_fs.c | 128 +++++++++++++++++++++++++++++++ src/storage/storage_util.c | 16 ++++ src/storage/storage_util.h | 14 ++++ 3 files changed, 158 insertions(+)
With one small nitpick below... Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index dc9869417e..b82215fcdb 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -41,6 +41,7 @@ VIR_LOG_INIT("storage.storage_backend_fs");
#if WITH_STORAGE_FS
+# include <libxml/xpathInternals.h> # include <mntent.h>
struct _virNetfsDiscoverState { @@ -559,6 +560,122 @@ virStorageBackendFileSystemBuild(virStoragePoolObjPtr pool, }
+#if WITH_STORAGE_FS + +# define STORAGE_POOL_NETFS_NAMESPACE_HREF "http://libvirt.org/schemas/storagepool/source/netfs/1.0" + +/* NetFS backend XML Namespace handling for nfs specific mount options to + * be added to the mount -o {options_list} command line. The XML will use + * the format, such as: + * + * <netfs:mount_opts> + * <netfs:option name='nodev'/> + * <netfs:option name='nosuid'/>
I'd probably illustrate with different examples, given that those flags are added by default
+ * </netfs:mount_opts> + * + * and the <pool type='netfs'> is required to have a "xmlns:netfs='%s'" + * attribute using the STORAGE_POOL_NETFS_NAMESPACE_HREF + */
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Modify the storagepool.rng to allow for the usage of a different XML namespace to parse the netfs_mount_opts to be included with the netfs storage pool definition. Modify the storagepoolxml2xmltest to utilize a properly modified XML file to parse and format the namespace for a netfs storage pool. Signed-off-by: John Ferlan <jferlan@redhat.com> --- docs/formatstorage.html.in | 57 +++++++++++++++++++ docs/schemas/storagepool.rng | 20 +++++++ tests/Makefile.am | 4 +- .../pool-netfs-ns-mountopts.xml | 25 ++++++++ .../pool-netfs-ns-mountopts.xml | 25 ++++++++ tests/storagepoolxml2xmltest.c | 6 ++ 6 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-ns-mountopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-ns-mountopts.xml diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in index b1b76a1dda..7a5a38de9e 100644 --- a/docs/formatstorage.html.in +++ b/docs/formatstorage.html.in @@ -497,6 +497,63 @@ device, measured in bytes. <span class="since">Since 0.4.1</span> </p> + <h3><a id="StoragePoolNamespaces">Storage Pool Namespaces</a></h3> + + <p> + Usage of Storage Pool Namespaces provides a mechanism to provide + pool type specific data in a free form or abitrary manner via + XML syntax targeted solely for the needs of the specific pool type + which is not otherwise supportable via XML. For the "netfs" pool + this provides a mechanism to provide additional mount options on the + command line. + </p> + <dl> + <dt><code>netfs:mount_opts</code></dt> + <dd>Provides an XML namespace mechanism to optionally utilize + specifically named options for the mount command via the "-o" + option for the <code>netfs</code> type storage pools. In order + to designate that the Storage Pool will be using the mechanism, + the <code>pool</code> element must be modified to provide the + XML namespace attribute syntax as follows: + + <p> + xmlns:netfs='http://libvirt.org/schemas/storagepool/source/netfs/1.0' + </p> + + <p> + The <code>netfs:mount_opts</code> defines the mount options by + specifying multiple <code>netfs:option</code> subelements with + the attribute <code>name</code> specifying the mount option to + be added. The value of the named option is not checked since + it's possible options don't exist on all distributions. It is + expected that proper and valid options will be supplied for the + target host. + </p> + + The following XML snippet shows the syntax required in order to + utilize + <pre> +<pool type="netfs" xmlns:netfs='http://libvirt.org/schemas/storagepool/source/netfs/1.0'> + <name>nfsimages</name> +... + <source> +... + </source> +... + <target> +... + </target> + <netfs:mount_opts> + <netfs:option name='sync'/> + <netfs:option name='lazytime'/> + </netfs:mount_opts> +</pool> +...</pre> + + <span class="since">Since 5.1.0.</span></dd> + + </dl> + <h2><a id="StorageVol">Storage volume XML</a></h2> <p> A storage volume will generally be either a file or a device diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng index f9a16422cc..cea4bb474a 100644 --- a/docs/schemas/storagepool.rng +++ b/docs/schemas/storagepool.rng @@ -64,6 +64,9 @@ <ref name='sourcenetfs'/> <ref name='target'/> </interleave> + <optional> + <ref name='netfs_mount_opts'/> + </optional> </define> <define name='poollogical'> @@ -682,4 +685,21 @@ </data> </define> + <!-- + Optional storage pool extensions in their own namespace: + NetFS + --> + + <define name="netfs_mount_opts"> + <element name="mount_opts" ns="http://libvirt.org/schemas/storagepool/source/netfs/1.0"> + <zeroOrMore> + <element name="option"> + <attribute name='name'> + <text/> + </attribute> + </element> + </zeroOrMore> + </element> + </define> + </grammar> diff --git a/tests/Makefile.am b/tests/Makefile.am index f74d8463b6..ab4c716529 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -937,7 +937,9 @@ storagevolxml2xmltest_LDADD = $(LDADDS) storagepoolxml2xmltest_SOURCES = \ storagepoolxml2xmltest.c \ testutils.c testutils.h -storagepoolxml2xmltest_LDADD = $(LDADDS) +storagepoolxml2xmltest_LDADD = $(LDADDS) \ + ../src/libvirt_driver_storage_impl.la \ + $(GNULIB_LIBS) nodedevxml2xmltest_SOURCES = \ nodedevxml2xmltest.c \ diff --git a/tests/storagepoolxml2xmlin/pool-netfs-ns-mountopts.xml b/tests/storagepoolxml2xmlin/pool-netfs-ns-mountopts.xml new file mode 100644 index 0000000000..6295edd6ee --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-netfs-ns-mountopts.xml @@ -0,0 +1,25 @@ +<pool type='netfs' xmlns:netfs='http://libvirt.org/schemas/storagepool/source/netfs/1.0'> + <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'/> + <protocol ver='3'/> + </source> + <target> + <path>/mnt</path> + <permissions> + <mode>0700</mode> + <owner>0</owner> + <group>0</group> + </permissions> + </target> + <netfs:mount_opts> + <netfs:option name='sync'/> + <netfs:option name='lazytime'/> + </netfs:mount_opts> +</pool> diff --git a/tests/storagepoolxml2xmlout/pool-netfs-ns-mountopts.xml b/tests/storagepoolxml2xmlout/pool-netfs-ns-mountopts.xml new file mode 100644 index 0000000000..efa7b07f31 --- /dev/null +++ b/tests/storagepoolxml2xmlout/pool-netfs-ns-mountopts.xml @@ -0,0 +1,25 @@ +<pool type='netfs' xmlns:netfs='http://libvirt.org/schemas/storagepool/source/netfs/1.0'> + <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'/> + <protocol ver='3'/> + </source> + <target> + <path>/mnt</path> + <permissions> + <mode>0700</mode> + <owner>0</owner> + <group>0</group> + </permissions> + </target> + <netfs:mount_opts> + <netfs:option name='sync'/> + <netfs:option name='lazytime'/> + </netfs:mount_opts> +</pool> diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index d18390034f..aff9ff160c 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -11,6 +11,8 @@ #include "testutilsqemu.h" #include "virstring.h" +#include "storage/storage_util.h" + #define VIR_FROM_THIS VIR_FROM_NONE static int @@ -70,6 +72,9 @@ mymain(void) testCompareXMLToXMLHelper, (name)) < 0) \ ret = -1 + if (storageRegisterAll() < 0) + return EXIT_FAILURE; + DO_TEST("pool-dir"); DO_TEST("pool-dir-naming"); DO_TEST("pool-fs"); @@ -86,6 +91,7 @@ mymain(void) DO_TEST("pool-netfs-protocol-ver"); DO_TEST("pool-netfs-gluster"); DO_TEST("pool-netfs-cifs"); + DO_TEST("pool-netfs-ns-mountopts"); DO_TEST("pool-scsi"); DO_TEST("pool-scsi-type-scsi-host"); DO_TEST("pool-scsi-type-fc-host"); -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:14PM -0500, John Ferlan wrote:
Modify the storagepool.rng to allow for the usage of a different XML namespace to parse the netfs_mount_opts to be included with the netfs storage pool definition.
Modify the storagepoolxml2xmltest to utilize a properly modified XML file to parse and format the namespace for a netfs storage pool.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- docs/formatstorage.html.in | 57 +++++++++++++++++++ docs/schemas/storagepool.rng | 20 +++++++ tests/Makefile.am | 4 +- .../pool-netfs-ns-mountopts.xml | 25 ++++++++ .../pool-netfs-ns-mountopts.xml | 25 ++++++++ tests/storagepoolxml2xmltest.c | 6 ++ 6 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-ns-mountopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-ns-mountopts.xml
I would have expected all this stuff to be introduced in the previous patch really, since its exercising the parser code the previous patch added
+ <h3><a id="StoragePoolNamespaces">Storage Pool Namespaces</a></h3> + + <p> + Usage of Storage Pool Namespaces provides a mechanism to provide + pool type specific data in a free form or abitrary manner via + XML syntax targeted solely for the needs of the specific pool type + which is not otherwise supportable via XML. For the "netfs" pool + this provides a mechanism to provide additional mount options on the + command line. + </p>
This needs to have text to make it clear that using this feature comes with *no* support guarantees. It should say it is only intended for developers testing out a concept prior to requesting an explicitly supported XML option in libvirt, and thus should never be used in production.
+ <dl> + <dt><code>netfs:mount_opts</code></dt> + <dd>Provides an XML namespace mechanism to optionally utilize + specifically named options for the mount command via the "-o" + option for the <code>netfs</code> type storage pools. In order + to designate that the Storage Pool will be using the mechanism, + the <code>pool</code> element must be modified to provide the + XML namespace attribute syntax as follows: + + <p> + xmlns:netfs='http://libvirt.org/schemas/storagepool/source/netfs/1.0' + </p> + + <p> + The <code>netfs:mount_opts</code> defines the mount options by + specifying multiple <code>netfs:option</code> subelements with + the attribute <code>name</code> specifying the mount option to + be added. The value of the named option is not checked since + it's possible options don't exist on all distributions. It is + expected that proper and valid options will be supplied for the + target host. + </p> + + The following XML snippet shows the syntax required in order to + utilize + <pre>
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Thu, Jan 17, 2019 at 04:22:14PM -0500, John Ferlan wrote:
Modify the storagepool.rng to allow for the usage of a different XML namespace to parse the netfs_mount_opts to be included with the netfs storage pool definition.
Modify the storagepoolxml2xmltest to utilize a properly modified XML file to parse and format the namespace for a netfs storage pool.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- docs/formatstorage.html.in | 57 +++++++++++++++++++ docs/schemas/storagepool.rng | 20 +++++++ tests/Makefile.am | 4 +- .../pool-netfs-ns-mountopts.xml | 25 ++++++++ .../pool-netfs-ns-mountopts.xml | 25 ++++++++ tests/storagepoolxml2xmltest.c | 6 ++ 6 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-ns-mountopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-ns-mountopts.xml
+ <dl> + <dt><code>netfs:mount_opts</code></dt> + <dd>Provides an XML namespace mechanism to optionally utilize + specifically named options for the mount command via the "-o" + option for the <code>netfs</code> type storage pools. In order + to designate that the Storage Pool will be using the mechanism, + the <code>pool</code> element must be modified to provide the + XML namespace attribute syntax as follows: + + <p> + xmlns:netfs='http://libvirt.org/schemas/storagepool/source/netfs/1.0' + </p> + + <p> + The <code>netfs:mount_opts</code> defines the mount options by + specifying multiple <code>netfs:option</code> subelements with + the attribute <code>name</code> specifying the mount option to + be added. The value of the named option is not checked since + it's possible options don't exist on all distributions. It is + expected that proper and valid options will be supplied for the + target host. + </p> + + The following XML snippet shows the syntax required in order to + utilize + <pre> +<pool type="netfs" xmlns:netfs='http://libvirt.org/schemas/storagepool/source/netfs/1.0'> + <name>nfsimages</name> +... + <source> +... + </source> +... + <target> +... + </target> + <netfs:mount_opts> + <netfs:option name='sync'/> + <netfs:option name='lazytime'/> + </netfs:mount_opts> +</pool> +...</pre> +
Based on my comments in the first patch, we should acutally just call this 'fs' not 'netfs' and allow it for any filesystem mount pool, as this is valid for cifs, glusterfs, and local filesystems too. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

If the NetFS Storage Pool Namespace XML data exists, format the mount options on the MOUNT command line. When the pool is started, the options will be generated on the command line along with the options already defined. To view the options of the running pool, use either 'nfsstat -m' or 'grep $POOLNAME /proc/mounts' for the added Flags/options. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 10 +++++++++- .../pool-netfs-ns-mountopts-freebsd.argv | 2 ++ .../pool-netfs-ns-mountopts-linux.argv | 2 ++ .../pool-netfs-ns-mountopts.argv | 1 + tests/storagepoolxml2argvtest.c | 6 ++++++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 2e753f4501..1fdaf54059 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -4293,7 +4293,15 @@ virStorageBackendFileSystemMountNFSAddOptions(virCommandPtr cmd, virBufferAsprintf(&buf, "nfsvers=%u,", def->source.protocolVer); if (*default_nfs_mount_opts != '\0') - virBufferAddLit(&buf, default_nfs_mount_opts); + virBufferAsprintf(&buf, "%s,", default_nfs_mount_opts); + + if (def->namespaceData) { + size_t i; + virStoragePoolNetFSMountOptionsDefPtr opts = def->namespaceData; + + for (i = 0; i < opts->noptions; i++) + virBufferAsprintf(&buf, "%s,", opts->options[i]); + } virBufferTrim(&buf, ",", -1); mountOpts = virBufferContentAndReset(&buf); diff --git a/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv new file mode 100644 index 0000000000..d8bd7e378e --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv @@ -0,0 +1,2 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3,nosuid,noexec,\ +sync,lazytime diff --git a/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv new file mode 100644 index 0000000000..486b2183b7 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv @@ -0,0 +1,2 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3,nodev,nosuid,\ +noexec,sync,lazytime diff --git a/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv new file mode 100644 index 0000000000..a63d6da456 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv @@ -0,0 +1 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3,sync,lazytime diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c index b6a46280cd..b6bc838f7b 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -162,6 +162,9 @@ mymain(void) #define DO_TEST_FREEBSD(pool, ...) \ DO_TEST_FULL(false, pool, false, true) + if (storageRegisterAll() < 0) + return EXIT_FAILURE; + DO_TEST_FAIL("pool-dir"); DO_TEST_FAIL("pool-dir-naming"); DO_TEST("pool-fs"); @@ -177,14 +180,17 @@ mymain(void) DO_TEST_LINUX("pool-netfs"); DO_TEST_LINUX("pool-netfs-auto"); DO_TEST_LINUX("pool-netfs-protocol-ver"); + DO_TEST_LINUX("pool-netfs-ns-mountopts"); #elif defined(__FreeBSD__) DO_TEST_FREEBSD("pool-netfs"); DO_TEST_FREEBSD("pool-netfs-auto"); DO_TEST_FREEBSD("pool-netfs-protocol-ver"); + DO_TEST_FREEBSD("pool-netfs-ns-mountopts"); #else DO_TEST("pool-netfs"); DO_TEST("pool-netfs-auto"); DO_TEST("pool-netfs-protocol-ver"); + DO_TEST("pool-netfs-ns-mountopts"); #endif DO_TEST("pool-netfs-gluster"); DO_TEST("pool-netfs-cifs"); -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:15PM -0500, John Ferlan wrote:
If the NetFS Storage Pool Namespace XML data exists, format the mount options on the MOUNT command line.
When the pool is started, the options will be generated on the command line along with the options already defined.
To view the options of the running pool, use either 'nfsstat -m' or 'grep $POOLNAME /proc/mounts' for the added Flags/options.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 10 +++++++++- .../pool-netfs-ns-mountopts-freebsd.argv | 2 ++ .../pool-netfs-ns-mountopts-linux.argv | 2 ++ .../pool-netfs-ns-mountopts.argv | 1 + tests/storagepoolxml2argvtest.c | 6 ++++++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Thu, Jan 17, 2019 at 04:22:15PM -0500, John Ferlan wrote:
If the NetFS Storage Pool Namespace XML data exists, format the mount options on the MOUNT command line.
When the pool is started, the options will be generated on the command line along with the options already defined.
To view the options of the running pool, use either 'nfsstat -m' or 'grep $POOLNAME /proc/mounts' for the added Flags/options.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/storage/storage_util.c | 10 +++++++++- .../pool-netfs-ns-mountopts-freebsd.argv | 2 ++ .../pool-netfs-ns-mountopts-linux.argv | 2 ++ .../pool-netfs-ns-mountopts.argv | 1 + tests/storagepoolxml2argvtest.c | 6 ++++++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 2e753f4501..1fdaf54059 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -4293,7 +4293,15 @@ virStorageBackendFileSystemMountNFSAddOptions(virCommandPtr cmd, virBufferAsprintf(&buf, "nfsvers=%u,", def->source.protocolVer);
if (*default_nfs_mount_opts != '\0') - virBufferAddLit(&buf, default_nfs_mount_opts); + virBufferAsprintf(&buf, "%s,", default_nfs_mount_opts); + + if (def->namespaceData) { + size_t i; + virStoragePoolNetFSMountOptionsDefPtr opts = def->namespaceData; + + for (i = 0; i < opts->noptions; i++) + virBufferAsprintf(&buf, "%s,", opts->options[i]); + }
For QEMU guests, we mark the guest as tainted when using custom arg passthrough, and log a message at warning level. So we should emit a VIR_WARN here about the storage pool being tainted.
virBufferTrim(&buf, ",", -1); mountOpts = virBufferContentAndReset(&buf); diff --git a/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv new file mode 100644 index 0000000000..d8bd7e378e --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv @@ -0,0 +1,2 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3,nosuid,noexec,\ +sync,lazytime diff --git a/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv new file mode 100644 index 0000000000..486b2183b7 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv @@ -0,0 +1,2 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3,nodev,nosuid,\ +noexec,sync,lazytime diff --git a/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv new file mode 100644 index 0000000000..a63d6da456 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv @@ -0,0 +1 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3,sync,lazytime diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c index b6a46280cd..b6bc838f7b 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -162,6 +162,9 @@ mymain(void) #define DO_TEST_FREEBSD(pool, ...) \ DO_TEST_FULL(false, pool, false, true)
+ if (storageRegisterAll() < 0) + return EXIT_FAILURE; + DO_TEST_FAIL("pool-dir"); DO_TEST_FAIL("pool-dir-naming"); DO_TEST("pool-fs"); @@ -177,14 +180,17 @@ mymain(void) DO_TEST_LINUX("pool-netfs"); DO_TEST_LINUX("pool-netfs-auto"); DO_TEST_LINUX("pool-netfs-protocol-ver"); + DO_TEST_LINUX("pool-netfs-ns-mountopts"); #elif defined(__FreeBSD__) DO_TEST_FREEBSD("pool-netfs"); DO_TEST_FREEBSD("pool-netfs-auto"); DO_TEST_FREEBSD("pool-netfs-protocol-ver"); + DO_TEST_FREEBSD("pool-netfs-ns-mountopts"); #else DO_TEST("pool-netfs"); DO_TEST("pool-netfs-auto"); DO_TEST("pool-netfs-protocol-ver"); + DO_TEST("pool-netfs-ns-mountopts"); #endif DO_TEST("pool-netfs-gluster"); DO_TEST("pool-netfs-cifs"); -- 2.20.1
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Allow for adjustment of RBD configuration options via Storage Pool XML Namespace adjustments. Based off original patch/concept: https://www.redhat.com/archives/libvir-list/2014-May/msg00940.html Signed-off-by: John Ferlan <jferlan@redhat.com> --- docs/formatstorage.html.in | 52 +++++- docs/schemas/storagepool.rng | 23 +++ src/storage/storage_backend_rbd.c | 166 +++++++++++++++++- .../pool-rbd-ns-configopts.xml | 17 ++ .../pool-rbd-ns-configopts.xml | 20 +++ tests/storagepoolxml2xmltest.c | 1 + 6 files changed, 275 insertions(+), 4 deletions(-) create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-ns-configopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-ns-configopts.xml diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in index 7a5a38de9e..0e2cfae247 100644 --- a/docs/formatstorage.html.in +++ b/docs/formatstorage.html.in @@ -505,7 +505,8 @@ XML syntax targeted solely for the needs of the specific pool type which is not otherwise supportable via XML. For the "netfs" pool this provides a mechanism to provide additional mount options on the - command line. + command line. For the "rbd" pool this provides a mechanism to override + default settings for RBD configuration options. </p> <dl> <dt><code>netfs:mount_opts</code></dt> @@ -552,6 +553,55 @@ <span class="since">Since 5.1.0.</span></dd> + <dt><code>rbd:config_opts</code></dt> + <dd>Provides an XML namespace mechanism to optionally utilize + specifically named options for the RBD configuration options + via the rados_conf_set API for the <code>rbd</code> type + storage pools. In order to designate that the Storage Pool + will be using the mechanism, the <code>pool</code> element + must be modified to provide the XML namespace attribute + syntax as follows: + + <p> + xmlns:rbd='http://libvirt.org/schemas/storagepool/source/rbd/1.0' + </p> + + <p> + The <code>rbd:config_opts</code> defines the configuration options + by specifying multiple <code>rbd:option</code> subelements with + the attribute <code>name</code> specifying the configuration option + to be added and <code>value</code> specifying the configuration + option value. The name and value for each option is only checked + to be not empty. The name and value provided are not checked since + it's possible options don't exist on all distributions. It is + expected that proper and valid options will be supplied for the + target host. + </p> + + The following XML snippet shows the syntax required in order to + utilize + <pre> +<pool type="rbd" xmlns:rbd='http://libvirt.org/schemas/storagepool/source/rbd/1.0'> + <name>myrbdpool</name> +... + <source> +... + </source> +... + <target> +... + </target> +... + <rbd:config_opts> + <rbd:option name='client_mount_timeout' value='45'/> + <rbd:option name='rados_mon_op_timeout' value='20'/> + <rbd:option name='rados_osd_op_timeout' value='10'/> + </rbd:config_opts> +</pool> +</pre> + + <span class="since">Since 5.1.0.</span></dd> + </dl> <h2><a id="StorageVol">Storage volume XML</a></h2> diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng index cea4bb474a..8ad95246f4 100644 --- a/docs/schemas/storagepool.rng +++ b/docs/schemas/storagepool.rng @@ -153,6 +153,9 @@ <ref name='sizing'/> <ref name='sourcerbd'/> </interleave> + <optional> + <ref name='rbd_config_opts'/> + </optional> </define> <define name='poolsheepdog'> @@ -702,4 +705,24 @@ </element> </define> + <!-- + Optional storage pool extensions in their own namespace: + RBD + --> + + <define name="rbd_config_opts"> + <element name="config_opts" ns="http://libvirt.org/schemas/storagepool/source/rbd/1.0"> + <zeroOrMore> + <element name="option"> + <attribute name='name'> + <text/> + </attribute> + <attribute name='value'> + <text/> + </attribute> + </element> + </zeroOrMore> + </element> + </define> + </grammar> diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index 24dd1349ae..cc38b76ff2 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -36,6 +36,7 @@ #include "rbd/librbd.h" #include "secret_util.h" #include "storage_util.h" +#include <libxml/xpathInternals.h> #define VIR_FROM_THIS VIR_FROM_STORAGE @@ -50,6 +51,140 @@ struct _virStorageBackendRBDState { typedef struct _virStorageBackendRBDState virStorageBackendRBDState; typedef virStorageBackendRBDState *virStorageBackendRBDStatePtr; +/* NetFS Storage Pool Namespace options to share w/ storage_backend_fs.c and + * the virStorageBackendFileSystemMountCmd method */ +typedef struct _virStoragePoolRBDMountOptionsDef virStoragePoolRBDMountOptionsDef; +typedef virStoragePoolRBDMountOptionsDef *virStoragePoolRBDMountOptionsDefPtr; +struct _virStoragePoolRBDMountOptionsDef { + size_t noptions; + char **names; + char **values; +}; + +#define STORAGE_POOL_RBD_NAMESPACE_HREF "http://libvirt.org/schemas/storagepool/source/rbd/1.0" + +static void +virStoragePoolDefRBDNamespaceFree(void *nsdata) +{ + virStoragePoolRBDMountOptionsDefPtr cmdopts = nsdata; + size_t i; + + if (!cmdopts) + return; + + for (i = 0; i < cmdopts->noptions; i++) { + VIR_FREE(cmdopts->names[i]); + VIR_FREE(cmdopts->values[i]); + } + VIR_FREE(cmdopts->names); + VIR_FREE(cmdopts->values); + + VIR_FREE(cmdopts); +} + + +static int +virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr ctxt, + void **data) +{ + virStoragePoolRBDMountOptionsDefPtr cmdopts = NULL; + xmlNodePtr *nodes = NULL; + int nnodes; + size_t i; + int ret = -1; + + if (xmlXPathRegisterNs(ctxt, BAD_CAST "rbd", + BAD_CAST STORAGE_POOL_RBD_NAMESPACE_HREF) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to register xml namespace '%s'"), + STORAGE_POOL_RBD_NAMESPACE_HREF); + return -1; + } + + nnodes = virXPathNodeSet("./rbd:config_opts/rbd:option", ctxt, &nodes); + if (nnodes < 0) + return -1; + + if (nnodes == 0) + return 0; + + if (VIR_ALLOC(cmdopts) < 0) + goto cleanup; + + if (VIR_ALLOC_N(cmdopts->names, nnodes) < 0 || + VIR_ALLOC_N(cmdopts->values, nnodes) < 0) + goto cleanup; + + for (i = 0; i < nnodes; i++) { + if (!(cmdopts->names[cmdopts->noptions] = + virXMLPropString(nodes[i], "name"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("no rbd option name specified")); + goto cleanup; + } + if (*cmdopts->names[cmdopts->noptions] == '\0') { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("empty rbd option name specified")); + goto cleanup; + } + if (!(cmdopts->values[cmdopts->noptions] = + virXMLPropString(nodes[i], "value"))) { + virReportError(VIR_ERR_XML_ERROR, + _("no rbd option value specified for name '%s'"), + cmdopts->names[cmdopts->noptions]); + goto cleanup; + } + if (*cmdopts->values[cmdopts->noptions] == '\0') { + virReportError(VIR_ERR_XML_ERROR, + _("empty rbd option value specified for name '%s'"), + cmdopts->names[cmdopts->noptions]); + goto cleanup; + } + cmdopts->noptions++; + } + + VIR_STEAL_PTR(*data, cmdopts); + ret = 0; + + cleanup: + VIR_FREE(nodes); + virStoragePoolDefRBDNamespaceFree(cmdopts); + return ret; +} + + +static int +virStoragePoolDefRBDNamespaceFormatXML(virBufferPtr buf, + void *nsdata) +{ + size_t i; + virStoragePoolRBDMountOptionsDefPtr def = nsdata; + + if (!def) + return 0; + + virBufferAddLit(buf, "<rbd:config_opts>\n"); + virBufferAdjustIndent(buf, 2); + + for (i = 0; i < def->noptions; i++) { + virBufferEscapeString(buf, "<rbd:option name='%s' ", def->names[i]); + virBufferEscapeString(buf, "value='%s'/>\n", def->values[i]); + } + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "</rbd:config_opts>\n"); + + return 0; +} + + +static const char * +virStoragePoolDefRBDNamespaceHref(void) +{ + return "xmlns:rbd='" STORAGE_POOL_RBD_NAMESPACE_HREF "'"; +} + + static int virStorageBackendRBDRADOSConfSet(rados_t cluster, const char *option, @@ -69,10 +204,11 @@ virStorageBackendRBDRADOSConfSet(rados_t cluster, static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, - virStoragePoolSourcePtr source) + virStoragePoolDefPtr def) { int ret = -1; int r = 0; + virStoragePoolSourcePtr source = &def->source; virStorageAuthDefPtr authdef = source->auth; unsigned char *secret_value = NULL; size_t secret_value_size = 0; @@ -183,6 +319,17 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, rbd_default_format) < 0) goto cleanup; + if (def->namespaceData) { + virStoragePoolRBDMountOptionsDefPtr cmdopts = def->namespaceData; + + for (i = 0; i < cmdopts->noptions; i++) { + if (virStorageBackendRBDRADOSConfSet(ptr->cluster, + cmdopts->names[i], + cmdopts->values[i]) < 0) + goto cleanup; + } + } + ptr->starttime = time(0); if ((r = rados_connect(ptr->cluster)) < 0) { virReportSystemError(-r, _("failed to connect to the RADOS monitor on: %s"), @@ -256,7 +403,7 @@ virStorageBackendRBDNewState(virStoragePoolObjPtr pool) if (VIR_ALLOC(ptr) < 0) return NULL; - if (virStorageBackendRBDOpenRADOSConn(ptr, &def->source) < 0) + if (virStorageBackendRBDOpenRADOSConn(ptr, def) < 0) goto error; if (virStorageBackendRBDOpenIoCTX(ptr, pool) < 0) @@ -1277,6 +1424,7 @@ virStorageBackendRBDVolWipe(virStoragePoolObjPtr pool, return ret; } + virStorageBackend virStorageBackendRBD = { .type = VIR_STORAGE_POOL_RBD, @@ -1291,8 +1439,20 @@ virStorageBackend virStorageBackendRBD = { }; +static virStoragePoolXMLNamespace virStoragePoolRBDXMLNamespace = { + .parse = virStoragePoolDefRBDNamespaceParse, + .free = virStoragePoolDefRBDNamespaceFree, + .format = virStoragePoolDefRBDNamespaceFormatXML, + .href = virStoragePoolDefRBDNamespaceHref, +}; + + int virStorageBackendRBDRegister(void) { - return virStorageBackendRegister(&virStorageBackendRBD); + if (virStorageBackendRegister(&virStorageBackendRBD) < 0) + return -1; + + return virStorageBackendNamespaceInit(VIR_STORAGE_POOL_RBD, + &virStoragePoolRBDXMLNamespace); } diff --git a/tests/storagepoolxml2xmlin/pool-rbd-ns-configopts.xml b/tests/storagepoolxml2xmlin/pool-rbd-ns-configopts.xml new file mode 100644 index 0000000000..6b62aa6f7e --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-rbd-ns-configopts.xml @@ -0,0 +1,17 @@ +<pool type='rbd' xmlns:rbd='http://libvirt.org/schemas/storagepool/source/rbd/1.0'> + <name>ceph</name> + <uuid>47c1faee-0207-e741-f5ae-d9b019b98fe2</uuid> + <source> + <name>rbd</name> + <host name='localhost' port='6789'/> + <host name='localhost' port='6790'/> + <auth username='admin' type='ceph'> + <secret uuid='2ec115d7-3a88-3ceb-bc12-0ac909a6fd87'/> + </auth> + </source> + <rbd:config_opts> + <rbd:option name='client_mount_timeout' value='45'/> + <rbd:option name='rados_mon_op_timeout' value='10'/> + <rbd:option name='rados_osd_op_timeout' value='20'/> + </rbd:config_opts> +</pool> diff --git a/tests/storagepoolxml2xmlout/pool-rbd-ns-configopts.xml b/tests/storagepoolxml2xmlout/pool-rbd-ns-configopts.xml new file mode 100644 index 0000000000..342a0ff74a --- /dev/null +++ b/tests/storagepoolxml2xmlout/pool-rbd-ns-configopts.xml @@ -0,0 +1,20 @@ +<pool type='rbd' xmlns:rbd='http://libvirt.org/schemas/storagepool/source/rbd/1.0'> + <name>ceph</name> + <uuid>47c1faee-0207-e741-f5ae-d9b019b98fe2</uuid> + <capacity unit='bytes'>0</capacity> + <allocation unit='bytes'>0</allocation> + <available unit='bytes'>0</available> + <source> + <host name='localhost' port='6789'/> + <host name='localhost' port='6790'/> + <name>rbd</name> + <auth type='ceph' username='admin'> + <secret uuid='2ec115d7-3a88-3ceb-bc12-0ac909a6fd87'/> + </auth> + </source> + <rbd:config_opts> + <rbd:option name='client_mount_timeout' value='45'/> + <rbd:option name='rados_mon_op_timeout' value='10'/> + <rbd:option name='rados_osd_op_timeout' value='20'/> + </rbd:config_opts> +</pool> diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index aff9ff160c..90d00a8d9e 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -106,6 +106,7 @@ mymain(void) DO_TEST("pool-zfs"); DO_TEST("pool-zfs-sourcedev"); DO_TEST("pool-rbd"); + DO_TEST("pool-rbd-ns-configopts"); DO_TEST("pool-vstorage"); DO_TEST("pool-iscsi-direct-auth"); DO_TEST("pool-iscsi-direct"); -- 2.20.1

On Thu, Jan 17, 2019 at 04:22:16PM -0500, John Ferlan wrote:
Allow for adjustment of RBD configuration options via Storage Pool XML Namespace adjustments.
Based off original patch/concept:
https://www.redhat.com/archives/libvir-list/2014-May/msg00940.html
Signed-off-by: John Ferlan <jferlan@redhat.com> --- docs/formatstorage.html.in | 52 +++++- docs/schemas/storagepool.rng | 23 +++ src/storage/storage_backend_rbd.c | 166 +++++++++++++++++- .../pool-rbd-ns-configopts.xml | 17 ++ .../pool-rbd-ns-configopts.xml | 20 +++ tests/storagepoolxml2xmltest.c | 1 + 6 files changed, 275 insertions(+), 4 deletions(-) create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-ns-configopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-ns-configopts.xml
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

ping? Tks - John On 1/17/19 4:22 PM, John Ferlan wrote:
v3: https://www.redhat.com/archives/libvir-list/2019-January/msg00467.html
NB: Kept same subject for cover to keep the same context; however, it's now more of a series of a few things... Add default NFS Server options, add nfsvers, and add support for XML namespaces in storage pools which are used by NFS and RBD storage pools.
Changes since v3:
Remove patch 1 and 3. Rework patch 2 to make the nodev, nosuid, and noexec be the "default options" for the NFS Storage Pool. Created a virStorageBackendFileSystemMountNFSAddOptions in order to add those options for NFS pools using format NFS (and not 'cifs' or 'gluster').
Everything else just gets adjusted/merged based on how the first patch works.
John Ferlan (10): storage: Add default mount options for NFS Storage Pools docs: Add news mention of NFS Storage Pool mount options conf: Add optional NFS Source Pool <protocol ver='n'/> option storage: Add the nfsvers to the command line virsh: Add source-protocol-ver for pool commands conf: Introduce virStoragePoolXMLNamespace nfs: Add infrastructure to manage XML namespace options docs,tests: Add schema, description, and tests for NFS namespace storage: Add NFS storage pool namespace options to command line rbd: Utilize storage pool namespace to manage config options
docs/formatstorage.html.in | 123 +++++++++++++ docs/news.xml | 11 ++ docs/schemas/storagepool.rng | 50 ++++++ src/conf/storage_conf.c | 73 +++++++- src/conf/storage_conf.h | 27 +++ src/libvirt_private.syms | 1 + src/storage/storage_backend_fs.c | 128 ++++++++++++++ src/storage/storage_backend_rbd.c | 166 +++++++++++++++++- src/storage/storage_util.c | 52 ++++++ src/storage/storage_util.h | 14 ++ tests/Makefile.am | 4 +- .../pool-netfs-auto-freebsd.argv | 1 + .../pool-netfs-auto-linux.argv | 1 + .../pool-netfs-freebsd.argv | 1 + .../pool-netfs-linux.argv | 1 + .../pool-netfs-ns-mountopts-freebsd.argv | 2 + .../pool-netfs-ns-mountopts-linux.argv | 2 + .../pool-netfs-ns-mountopts.argv | 1 + .../pool-netfs-protocol-ver-freebsd.argv | 1 + .../pool-netfs-protocol-ver-linux.argv | 2 + .../pool-netfs-protocol-ver.argv | 1 + tests/storagepoolxml2argvtest.c | 49 +++++- .../pool-netfs-ns-mountopts.xml | 25 +++ .../pool-netfs-protocol-ver.xml | 21 +++ .../pool-rbd-ns-configopts.xml | 17 ++ .../pool-netfs-ns-mountopts.xml | 25 +++ .../pool-netfs-protocol-ver.xml | 21 +++ .../pool-rbd-ns-configopts.xml | 20 +++ tests/storagepoolxml2xmltest.c | 8 + tools/virsh-pool.c | 12 +- tools/virsh.pod | 5 + 31 files changed, 851 insertions(+), 14 deletions(-) create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-ns-mountopts.xml create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-ns-configopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-ns-mountopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-ns-configopts.xml
participants (2)
-
Daniel P. Berrangé
-
John Ferlan