2009-10-08 21:26:30 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "storage_conf.h"
|
|
|
|
#include "testutilsqemu.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2009-10-08 21:26:30 +00:00
|
|
|
|
2019-01-07 22:14:57 +00:00
|
|
|
#include "storage/storage_util.h"
|
|
|
|
|
2013-06-07 15:10:28 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
static int
|
|
|
|
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
|
|
|
|
{
|
2019-02-01 17:03:16 +00:00
|
|
|
VIR_AUTOFREE(char *) actual = NULL;
|
2019-01-31 15:21:47 +00:00
|
|
|
VIR_AUTOPTR(virStoragePoolDef) dev = NULL;
|
2009-10-08 21:26:30 +00:00
|
|
|
|
2015-04-23 15:10:15 +00:00
|
|
|
if (!(dev = virStoragePoolDefParseFile(inxml)))
|
2019-02-01 17:03:16 +00:00
|
|
|
return -1;
|
2009-10-08 21:26:30 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(actual = virStoragePoolDefFormat(dev)))
|
2019-02-01 17:03:16 +00:00
|
|
|
return -1;
|
2009-10-08 21:26:30 +00:00
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(actual, outxml) < 0)
|
2019-02-01 17:03:16 +00:00
|
|
|
return -1;
|
2009-10-08 21:26:30 +00:00
|
|
|
|
2019-02-01 17:03:16 +00:00
|
|
|
return 0;
|
2009-10-08 21:26:30 +00:00
|
|
|
}
|
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
static int
|
|
|
|
testCompareXMLToXMLHelper(const void *data)
|
|
|
|
{
|
2019-02-01 17:03:16 +00:00
|
|
|
VIR_AUTOFREE(char *) inxml = NULL;
|
|
|
|
VIR_AUTOFREE(char *) outxml = NULL;
|
2011-04-24 22:25:10 +00:00
|
|
|
|
|
|
|
if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml",
|
|
|
|
abs_srcdir, (const char*)data) < 0 ||
|
|
|
|
virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml",
|
2019-02-01 17:03:16 +00:00
|
|
|
abs_srcdir, (const char*)data) < 0)
|
|
|
|
return -1;
|
2011-04-24 22:25:10 +00:00
|
|
|
|
2019-02-01 17:03:16 +00:00
|
|
|
return testCompareXMLToXMLFiles(inxml, outxml);
|
2011-04-24 22:25:10 +00:00
|
|
|
}
|
2009-10-08 21:26:30 +00:00
|
|
|
|
|
|
|
static int
|
2011-04-29 16:21:20 +00:00
|
|
|
mymain(void)
|
2009-10-08 21:26:30 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define DO_TEST(name) \
|
|
|
|
if (virTestRun("Storage Pool XML-2-XML " name, \
|
|
|
|
testCompareXMLToXMLHelper, (name)) < 0) \
|
2009-10-08 21:26:30 +00:00
|
|
|
ret = -1
|
|
|
|
|
2019-01-07 22:14:57 +00:00
|
|
|
if (storageRegisterAll() < 0)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2009-10-08 21:26:30 +00: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 00:04:05 +00:00
|
|
|
DO_TEST("pool-dir-naming");
|
2009-10-08 21:26:30 +00:00
|
|
|
DO_TEST("pool-fs");
|
|
|
|
DO_TEST("pool-logical");
|
2013-04-30 11:48:46 +00:00
|
|
|
DO_TEST("pool-logical-nopath");
|
2009-10-08 21:26:30 +00:00
|
|
|
DO_TEST("pool-logical-create");
|
2017-03-28 13:11:52 +00:00
|
|
|
DO_TEST("pool-logical-noname");
|
2009-10-08 21:26:30 +00:00
|
|
|
DO_TEST("pool-disk");
|
2016-01-07 11:57:28 +00:00
|
|
|
DO_TEST("pool-disk-device-nopartsep");
|
2009-10-08 21:26:30 +00:00
|
|
|
DO_TEST("pool-iscsi");
|
|
|
|
DO_TEST("pool-iscsi-auth");
|
|
|
|
DO_TEST("pool-netfs");
|
2018-12-04 15:20:59 +00:00
|
|
|
DO_TEST("pool-netfs-auto");
|
2019-01-11 00:23:27 +00:00
|
|
|
DO_TEST("pool-netfs-protocol-ver");
|
2013-11-12 23:35:36 +00:00
|
|
|
DO_TEST("pool-netfs-gluster");
|
2015-06-03 15:43:00 +00:00
|
|
|
DO_TEST("pool-netfs-cifs");
|
2019-01-30 15:26:48 +00:00
|
|
|
#ifdef WITH_STORAGE_FS
|
2019-01-07 22:14:57 +00:00
|
|
|
DO_TEST("pool-netfs-ns-mountopts");
|
2019-01-30 15:26:48 +00:00
|
|
|
#endif
|
2009-10-08 21:26:30 +00:00
|
|
|
DO_TEST("pool-scsi");
|
2013-03-25 16:43:36 +00: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-10 16:19:51 +00:00
|
|
|
DO_TEST("pool-scsi-type-fc-host-managed");
|
2009-10-08 21:26:30 +00:00
|
|
|
DO_TEST("pool-mpath");
|
2010-06-07 20:47:37 +00:00
|
|
|
DO_TEST("pool-iscsi-multiiqn");
|
2010-08-17 17:44:27 +00:00
|
|
|
DO_TEST("pool-iscsi-vendor-product");
|
2012-07-18 19:06:58 +00:00
|
|
|
DO_TEST("pool-sheepdog");
|
2013-10-15 23:06:18 +00:00
|
|
|
DO_TEST("pool-gluster");
|
|
|
|
DO_TEST("pool-gluster-sub");
|
2014-03-04 03:15:13 +00:00
|
|
|
DO_TEST("pool-scsi-type-scsi-host-stable");
|
2014-09-07 14:01:34 +00:00
|
|
|
DO_TEST("pool-zfs");
|
|
|
|
DO_TEST("pool-zfs-sourcedev");
|
2016-03-11 16:50:54 +00:00
|
|
|
DO_TEST("pool-rbd");
|
2019-01-30 15:26:48 +00:00
|
|
|
#ifdef WITH_STORAGE_RBD
|
2019-03-19 13:42:17 +00:00
|
|
|
DO_TEST("pool-rbd-refresh-volume-allocation");
|
2019-01-08 14:28:03 +00:00
|
|
|
DO_TEST("pool-rbd-ns-configopts");
|
2019-01-30 15:26:48 +00:00
|
|
|
#endif
|
2017-01-17 14:10:59 +00:00
|
|
|
DO_TEST("pool-vstorage");
|
2018-07-31 08:44:21 +00:00
|
|
|
DO_TEST("pool-iscsi-direct-auth");
|
|
|
|
DO_TEST("pool-iscsi-direct");
|
2009-10-08 21:26:30 +00:00
|
|
|
|
2014-03-17 09:38:38 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2009-10-08 21:26:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN(mymain)
|