2009-10-09 05:26:30 +08:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "storage_conf.h"
|
|
|
|
|
2019-01-08 06:14:57 +08:00
|
|
|
#include "storage/storage_util.h"
|
|
|
|
|
2013-06-07 23:10:28 +08:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
static int
|
|
|
|
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
|
|
|
|
{
|
2019-10-15 21:16:31 +08:00
|
|
|
g_autofree char *actual = NULL;
|
2019-10-15 20:47:50 +08:00
|
|
|
g_autoptr(virStoragePoolDef) dev = NULL;
|
2009-10-09 05:26:30 +08:00
|
|
|
|
2015-04-23 23:10:15 +08:00
|
|
|
if (!(dev = virStoragePoolDefParseFile(inxml)))
|
2019-02-02 01:03:16 +08:00
|
|
|
return -1;
|
2009-10-09 05:26:30 +08:00
|
|
|
|
2010-02-10 19:42:56 +08:00
|
|
|
if (!(actual = virStoragePoolDefFormat(dev)))
|
2019-02-02 01:03:16 +08:00
|
|
|
return -1;
|
2009-10-09 05:26:30 +08:00
|
|
|
|
2016-05-26 23:01:53 +08:00
|
|
|
if (virTestCompareToFile(actual, outxml) < 0)
|
2019-02-02 01:03:16 +08:00
|
|
|
return -1;
|
2009-10-09 05:26:30 +08:00
|
|
|
|
2019-02-02 01:03:16 +08:00
|
|
|
return 0;
|
2009-10-09 05:26:30 +08:00
|
|
|
}
|
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
static int
|
|
|
|
testCompareXMLToXMLHelper(const void *data)
|
|
|
|
{
|
2019-10-15 21:16:31 +08:00
|
|
|
g_autofree char *inxml = NULL;
|
|
|
|
g_autofree char *outxml = NULL;
|
2011-04-25 06:25:10 +08:00
|
|
|
|
2019-10-22 21:26:14 +08:00
|
|
|
inxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s.xml",
|
|
|
|
abs_srcdir, (const char*)data);
|
|
|
|
outxml = g_strdup_printf("%s/storagepoolxml2xmlout/%s.xml",
|
|
|
|
abs_srcdir, (const char*)data);
|
2011-04-25 06:25:10 +08:00
|
|
|
|
2019-02-02 01:03:16 +08:00
|
|
|
return testCompareXMLToXMLFiles(inxml, outxml);
|
2011-04-25 06:25:10 +08:00
|
|
|
}
|
2009-10-09 05:26:30 +08:00
|
|
|
|
|
|
|
static int
|
2011-04-30 00:21:20 +08:00
|
|
|
mymain(void)
|
2009-10-09 05:26:30 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2017-11-03 20:09:47 +08:00
|
|
|
#define DO_TEST(name) \
|
|
|
|
if (virTestRun("Storage Pool XML-2-XML " name, \
|
|
|
|
testCompareXMLToXMLHelper, (name)) < 0) \
|
2009-10-09 05:26:30 +08:00
|
|
|
ret = -1
|
|
|
|
|
2019-01-08 06:14:57 +08:00
|
|
|
if (storageRegisterAll() < 0)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2009-10-09 05:26:30 +08:00
|
|
|
DO_TEST("pool-dir");
|
storage: use valid XML for awkward volume names
$ touch /var/lib/libvirt/images/'a<b>c'
$ virsh pool-refresh default
$ virsh vol-dumpxml 'a<b>c' default | head -n2
<volume>
<name>a<b>c</name>
Oops. That's not valid XML. And when we fix the XML
generation, it fails RelaxNG validation.
I'm also tired of seeing <key>(null)</key> in the example
output for volume xml; while we used NULLSTR() to avoid
a NULL deref rather than relying on glibc's printf
extension behavior, it's even better if we avoid the issue
in the first place. But this requires being careful that
we don't invalidate any storage backends that were relying
on key being unassigned during virStoragVolCreateXML[From].
I would have split this into two patches (one for escaping,
one for avoiding <key>(null)</key>), but since they both
end up touching a lot of the same test files, I ended up
merging it into one.
Note that this patch allows pretty much any volume name
that can appear in a directory (excluding . and .. because
those are special), but does nothing to change the current
(unenforced) RelaxNG claim that pool names will consist
only of letters, numbers, _, -, and +. Tightening the C
code to match RelaxNG patterns and/or relaxing the grammar
to match the C code for pool names is a task for another
day (but remember, we DID recently tighten C code for
domain names to exclude a leading '.').
* src/conf/storage_conf.c (virStoragePoolSourceFormat)
(virStoragePoolDefFormat, virStorageVolTargetDefFormat)
(virStorageVolDefFormat): Escape user-controlled strings.
(virStorageVolDefParseXML): Parse key, for use in unit tests.
* src/storage/storage_driver.c (storageVolCreateXML)
(storageVolCreateXMLFrom): Ensure parsed key doesn't confuse
volume creation.
* docs/schemas/basictypes.rng (volName): Relax definition.
* tests/storagepoolxml2xmltest.c (mymain): Test it.
* tests/storagevolxml2xmltest.c (mymain): Likewise.
* tests/storagepoolxml2xmlin/pool-dir-naming.xml: New file.
* tests/storagepoolxml2xmlout/pool-dir-naming.xml: Likewise.
* tests/storagevolxml2xmlin/vol-file-naming.xml: Likewise.
* tests/storagevolxml2xmlout/vol-file-naming.xml: Likewise.
* tests/storagevolxml2xmlout/vol-*.xml: Fix fallout.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-11-21 08:04:05 +08:00
|
|
|
DO_TEST("pool-dir-naming");
|
2020-07-18 02:32:18 +08:00
|
|
|
DO_TEST("pool-dir-cow");
|
2009-10-09 05:26:30 +08:00
|
|
|
DO_TEST("pool-fs");
|
|
|
|
DO_TEST("pool-logical");
|
2013-04-30 19:48:46 +08:00
|
|
|
DO_TEST("pool-logical-nopath");
|
2009-10-09 05:26:30 +08:00
|
|
|
DO_TEST("pool-logical-create");
|
2017-03-28 21:11:52 +08:00
|
|
|
DO_TEST("pool-logical-noname");
|
2009-10-09 05:26:30 +08:00
|
|
|
DO_TEST("pool-disk");
|
2016-01-07 19:57:28 +08:00
|
|
|
DO_TEST("pool-disk-device-nopartsep");
|
2009-10-09 05:26:30 +08:00
|
|
|
DO_TEST("pool-iscsi");
|
|
|
|
DO_TEST("pool-iscsi-auth");
|
|
|
|
DO_TEST("pool-netfs");
|
2019-06-25 19:37:16 +08:00
|
|
|
DO_TEST("pool-netfs-slash");
|
2018-12-04 23:20:59 +08:00
|
|
|
DO_TEST("pool-netfs-auto");
|
2019-01-11 08:23:27 +08:00
|
|
|
DO_TEST("pool-netfs-protocol-ver");
|
2013-11-13 07:35:36 +08:00
|
|
|
DO_TEST("pool-netfs-gluster");
|
2015-06-03 23:43:00 +08:00
|
|
|
DO_TEST("pool-netfs-cifs");
|
2019-01-30 23:26:48 +08:00
|
|
|
#ifdef WITH_STORAGE_FS
|
2019-01-08 06:14:57 +08:00
|
|
|
DO_TEST("pool-netfs-ns-mountopts");
|
2019-01-30 23:26:48 +08:00
|
|
|
#endif
|
2009-10-09 05:26:30 +08:00
|
|
|
DO_TEST("pool-scsi");
|
2013-03-26 00:43:36 +08:00
|
|
|
DO_TEST("pool-scsi-type-scsi-host");
|
|
|
|
DO_TEST("pool-scsi-type-fc-host");
|
storage: Introduce 'managed' for the fchost parent
https://bugzilla.redhat.com/show_bug.cgi?id=1160926
Introduce a 'managed' attribute to allow libvirt to decide whether to
delete a vHBA vport created via external means such as nodedev-create.
The code currently decides whether to delete the vHBA based solely on
whether the parent was provided at creation time. However, that may not
be the desired action, so rather than delete and force someone to create
another vHBA via an additional nodedev-create allow the configuration of
the storage pool to decide the desired action.
During createVport when libvirt does the VPORT_CREATE, set the managed
value to YES if not already set to indicate to the deleteVport code that
it should delete the vHBA when the pool is destroyed.
If libvirtd is restarted all the memory only state was lost, so for a
persistent storage pool, use the virStoragePoolSaveConfig in order to
write out the managed value.
Because we're now saving the current configuration, we need to be sure
to not save the parent in the output XML if it was undefined at start.
Saving the name would cause future starts to always use the same parent
which is not the expected result when not providing a parent. By not
providing a parent, libvirt is expected to find the best available
vHBA port for each subsequent (re)start.
At deleteVport, use the new managed value to decide whether to execute
the VPORT_DELETE. Since we no longer save the parent in memory or in
XML when provided, if it was not provided, then we have to look it up.
2014-11-11 00:19:51 +08:00
|
|
|
DO_TEST("pool-scsi-type-fc-host-managed");
|
2009-10-09 05:26:30 +08:00
|
|
|
DO_TEST("pool-mpath");
|
2010-06-08 04:47:37 +08:00
|
|
|
DO_TEST("pool-iscsi-multiiqn");
|
2010-08-18 01:44:27 +08:00
|
|
|
DO_TEST("pool-iscsi-vendor-product");
|
2013-10-16 07:06:18 +08:00
|
|
|
DO_TEST("pool-gluster");
|
|
|
|
DO_TEST("pool-gluster-sub");
|
2014-03-04 11:15:13 +08:00
|
|
|
DO_TEST("pool-scsi-type-scsi-host-stable");
|
2014-09-07 22:01:34 +08:00
|
|
|
DO_TEST("pool-zfs");
|
|
|
|
DO_TEST("pool-zfs-sourcedev");
|
2016-03-12 00:50:54 +08:00
|
|
|
DO_TEST("pool-rbd");
|
2019-01-30 23:26:48 +08:00
|
|
|
#ifdef WITH_STORAGE_RBD
|
2019-04-28 10:29:53 +08:00
|
|
|
DO_TEST("pool-rbd-ipv6");
|
2019-03-19 21:42:17 +08:00
|
|
|
DO_TEST("pool-rbd-refresh-volume-allocation");
|
2019-01-08 22:28:03 +08:00
|
|
|
DO_TEST("pool-rbd-ns-configopts");
|
2019-01-30 23:26:48 +08:00
|
|
|
#endif
|
2017-01-17 22:10:59 +08:00
|
|
|
DO_TEST("pool-vstorage");
|
2018-07-31 16:44:21 +08:00
|
|
|
DO_TEST("pool-iscsi-direct-auth");
|
|
|
|
DO_TEST("pool-iscsi-direct");
|
2009-10-09 05:26:30 +08:00
|
|
|
|
2014-03-17 17:38:38 +08:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2009-10-09 05:26:30 +08:00
|
|
|
}
|
|
|
|
|
2017-03-29 22:45:42 +08:00
|
|
|
VIR_TEST_MAIN(mymain)
|