2009-10-09 18:17:21 +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"
|
|
|
|
|
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 *poolxml, const char *inxml,
|
2015-02-05 15:20:17 +00:00
|
|
|
const char *outxml, unsigned int flags)
|
2011-04-24 22:25:10 +00:00
|
|
|
{
|
2019-10-15 13:16:31 +00:00
|
|
|
g_autofree char *actual = NULL;
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virStoragePoolDef) pool = NULL;
|
|
|
|
g_autoptr(virStorageVolDef) dev = NULL;
|
2009-10-09 18:17:21 +00:00
|
|
|
|
2015-04-23 15:10:15 +00:00
|
|
|
if (!(pool = virStoragePoolDefParseFile(poolxml)))
|
2019-02-01 17:03:16 +00:00
|
|
|
return -1;
|
2009-10-09 18:17:21 +00:00
|
|
|
|
2015-04-23 15:10:15 +00:00
|
|
|
if (!(dev = virStorageVolDefParseFile(pool, inxml, flags)))
|
2019-02-01 17:03:16 +00:00
|
|
|
return -1;
|
2009-10-09 18:17:21 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(actual = virStorageVolDefFormat(pool, dev)))
|
2019-02-01 17:03:16 +00:00
|
|
|
return -1;
|
2009-10-09 18:17:21 +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-09 18:17:21 +00:00
|
|
|
|
2019-02-01 17:03:16 +00:00
|
|
|
return 0;
|
2009-10-09 18:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct testInfo {
|
|
|
|
const char *pool;
|
|
|
|
const char *name;
|
2015-02-05 15:20:17 +00:00
|
|
|
unsigned int flags;
|
2009-10-09 18:17:21 +00:00
|
|
|
};
|
|
|
|
|
2011-04-24 22:25:10 +00:00
|
|
|
static int
|
|
|
|
testCompareXMLToXMLHelper(const void *data)
|
|
|
|
{
|
2009-10-09 18:17:21 +00:00
|
|
|
const struct testInfo *info = data;
|
2019-10-15 13:16:31 +00:00
|
|
|
g_autofree char *poolxml = NULL;
|
|
|
|
g_autofree char *inxml = NULL;
|
|
|
|
g_autofree char *outxml = NULL;
|
2011-04-24 22:25:10 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
poolxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s.xml",
|
|
|
|
abs_srcdir, info->pool);
|
|
|
|
inxml = g_strdup_printf("%s/storagevolxml2xmlin/%s.xml",
|
|
|
|
abs_srcdir, info->name);
|
|
|
|
outxml = g_strdup_printf("%s/storagevolxml2xmlout/%s.xml",
|
|
|
|
abs_srcdir, info->name);
|
2009-10-09 18:17:21 +00:00
|
|
|
|
2019-02-01 17:03:16 +00:00
|
|
|
return testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flags);
|
2009-10-09 18:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2011-04-29 16:21:20 +00:00
|
|
|
mymain(void)
|
2009-10-09 18:17:21 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define DO_TEST_FULL(pool, name, flags) \
|
|
|
|
do { \
|
|
|
|
struct testInfo info = { pool, name, flags }; \
|
|
|
|
if (virTestRun("Storage Vol XML-2-XML " name, \
|
|
|
|
testCompareXMLToXMLHelper, &info) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
} \
|
2012-10-17 09:23:12 +00:00
|
|
|
while (0);
|
2009-10-09 18:17:21 +00:00
|
|
|
|
2015-02-05 15:20:17 +00:00
|
|
|
#define DO_TEST(pool, name) DO_TEST_FULL(pool, name, 0)
|
|
|
|
|
2009-10-09 18:17:21 +00:00
|
|
|
DO_TEST("pool-dir", "vol-file");
|
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", "vol-file-naming");
|
2009-10-09 18:17:21 +00:00
|
|
|
DO_TEST("pool-dir", "vol-file-backing");
|
2017-03-07 15:50:59 +00:00
|
|
|
DO_TEST("pool-dir", "vol-file-iso");
|
2009-10-09 18:17:21 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2");
|
2013-05-16 10:38:26 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-1.1");
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-lazy");
|
2013-07-22 13:44:06 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-0.10-lazy");
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nobacking");
|
2018-06-20 20:21:50 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-encryption");
|
2020-09-15 15:30:37 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-luks");
|
2021-05-12 15:43:36 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-clusterSize");
|
2016-06-01 19:01:31 +00:00
|
|
|
DO_TEST("pool-dir", "vol-luks");
|
2016-06-01 23:21:26 +00:00
|
|
|
DO_TEST("pool-dir", "vol-luks-cipher");
|
2009-10-09 18:17:21 +00:00
|
|
|
DO_TEST("pool-disk", "vol-partition");
|
|
|
|
DO_TEST("pool-logical", "vol-logical");
|
|
|
|
DO_TEST("pool-logical", "vol-logical-backing");
|
2012-07-18 19:06:58 +00:00
|
|
|
DO_TEST("pool-sheepdog", "vol-sheepdog");
|
2013-11-20 20:17:55 +00:00
|
|
|
DO_TEST("pool-gluster", "vol-gluster-dir");
|
2014-12-10 12:54:10 +00:00
|
|
|
DO_TEST("pool-gluster", "vol-gluster-dir-neg-uid");
|
2015-02-17 15:54:53 +00:00
|
|
|
DO_TEST_FULL("pool-dir", "vol-qcow2-nocapacity",
|
|
|
|
VIR_VOL_XML_PARSE_NO_CAPACITY);
|
2009-10-09 18:17:21 +00:00
|
|
|
|
2014-03-17 09:38:38 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2009-10-09 18:17:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN(mymain)
|