2009-10-08 21:26:30 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.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
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
char *inXmlData = NULL;
|
|
|
|
char *outXmlData = NULL;
|
2009-10-08 21:26:30 +00:00
|
|
|
char *actual = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virStoragePoolDefPtr dev = NULL;
|
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
if (virtTestLoadFile(inxml, &inXmlData) < 0)
|
2009-10-08 21:26:30 +00:00
|
|
|
goto fail;
|
2011-04-24 22:25:10 +00:00
|
|
|
if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
2009-10-08 21:26:30 +00:00
|
|
|
goto fail;
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(dev = virStoragePoolDefParseString(inXmlData)))
|
2009-10-08 21:26:30 +00:00
|
|
|
goto fail;
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(actual = virStoragePoolDefFormat(dev)))
|
2009-10-08 21:26:30 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (STRNEQ(outXmlData, actual)) {
|
|
|
|
virtTestDifference(stderr, outXmlData, actual);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(inXmlData);
|
|
|
|
VIR_FREE(outXmlData);
|
|
|
|
VIR_FREE(actual);
|
2009-10-08 21:26:30 +00:00
|
|
|
virStoragePoolDefFree(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
static int
|
|
|
|
testCompareXMLToXMLHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
char *inxml = NULL;
|
|
|
|
char *outxml = NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml",
|
|
|
|
abs_srcdir, (const char*)data) < 0 ||
|
|
|
|
virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml",
|
|
|
|
abs_srcdir, (const char*)data) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = testCompareXMLToXMLFiles(inxml, outxml);
|
2009-10-08 21:26:30 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(inxml);
|
|
|
|
VIR_FREE(outxml);
|
2011-04-24 22:25:10 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
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;
|
|
|
|
|
2013-09-20 18:13:35 +00:00
|
|
|
#define DO_TEST(name) \
|
|
|
|
if (virtTestRun("Storage Pool XML-2-XML " name, \
|
|
|
|
testCompareXMLToXMLHelper, (name)) < 0) \
|
2009-10-08 21:26:30 +00:00
|
|
|
ret = -1
|
|
|
|
|
|
|
|
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");
|
|
|
|
DO_TEST("pool-disk");
|
|
|
|
DO_TEST("pool-iscsi");
|
|
|
|
DO_TEST("pool-iscsi-auth");
|
|
|
|
DO_TEST("pool-netfs");
|
2013-11-12 23:35:36 +00:00
|
|
|
DO_TEST("pool-netfs-gluster");
|
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");
|
2015-01-16 17:38:32 +00:00
|
|
|
#ifdef WITH_STORAGE_ZFS
|
2014-09-07 14:01:34 +00:00
|
|
|
DO_TEST("pool-zfs");
|
|
|
|
DO_TEST("pool-zfs-sourcedev");
|
2015-01-16 17:38:32 +00:00
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|