2013-02-18 12:43:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "datatypes.h"
|
2017-01-11 17:04:15 +00:00
|
|
|
#include "storage/storage_util.h"
|
2013-02-18 12:43:28 +00:00
|
|
|
#include "testutilsqemu.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2013-02-18 12:43:28 +00:00
|
|
|
|
2013-06-07 15:10:28 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2013-02-18 12:43:28 +00:00
|
|
|
const char create_tool[] = "qemu-img";
|
|
|
|
|
2013-07-22 13:55:40 +00:00
|
|
|
/* createVol sets this on volume creation */
|
|
|
|
static void
|
|
|
|
testSetVolumeType(virStorageVolDefPtr vol,
|
|
|
|
virStoragePoolDefPtr pool)
|
|
|
|
{
|
2013-07-26 11:10:12 +00:00
|
|
|
if (!vol || !pool)
|
2013-07-22 13:55:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch (pool->type) {
|
|
|
|
case VIR_STORAGE_POOL_DIR:
|
|
|
|
case VIR_STORAGE_POOL_FS:
|
|
|
|
case VIR_STORAGE_POOL_NETFS:
|
|
|
|
vol->type = VIR_STORAGE_VOL_FILE;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL:
|
|
|
|
vol->type = VIR_STORAGE_VOL_BLOCK;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 12:43:28 +00:00
|
|
|
static int
|
|
|
|
testCompareXMLToArgvFiles(bool shouldFail,
|
|
|
|
const char *poolxml,
|
|
|
|
const char *volxml,
|
2013-07-22 13:55:40 +00:00
|
|
|
const char *inputpoolxml,
|
2013-02-18 12:43:28 +00:00
|
|
|
const char *inputvolxml,
|
|
|
|
const char *cmdline,
|
|
|
|
unsigned int flags,
|
2015-02-17 15:57:02 +00:00
|
|
|
int imgformat,
|
|
|
|
unsigned long parse_flags)
|
2013-02-18 12:43:28 +00:00
|
|
|
{
|
|
|
|
char *actualCmdline = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCommandPtr cmd = NULL;
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
virStorageVolDefPtr vol = NULL, inputvol = NULL;
|
|
|
|
virStoragePoolDefPtr pool = NULL;
|
2013-07-22 13:55:40 +00:00
|
|
|
virStoragePoolDefPtr inputpool = NULL;
|
2013-02-18 12:43:28 +00:00
|
|
|
virStoragePoolObj poolobj = {.def = NULL };
|
|
|
|
|
|
|
|
|
|
|
|
if (!(conn = virGetConnect()))
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-04-23 15:10:15 +00:00
|
|
|
if (!(pool = virStoragePoolDefParseFile(poolxml)))
|
2013-02-18 12:43:28 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
poolobj.def = pool;
|
|
|
|
|
2013-07-22 13:55:40 +00:00
|
|
|
if (inputpoolxml) {
|
2015-04-23 15:10:15 +00:00
|
|
|
if (!(inputpool = virStoragePoolDefParseFile(inputpoolxml)))
|
2013-07-22 13:55:40 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:54:53 +00:00
|
|
|
if (inputvolxml)
|
|
|
|
parse_flags |= VIR_VOL_XML_PARSE_NO_CAPACITY;
|
|
|
|
|
2015-04-23 15:10:15 +00:00
|
|
|
if (!(vol = virStorageVolDefParseFile(pool, volxml, parse_flags)))
|
2013-02-18 12:43:28 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (inputvolxml &&
|
2015-04-23 15:10:15 +00:00
|
|
|
!(inputvol = virStorageVolDefParseFile(inputpool, inputvolxml, 0)))
|
2013-02-18 12:43:28 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-22 13:55:40 +00:00
|
|
|
testSetVolumeType(vol, pool);
|
|
|
|
testSetVolumeType(inputvol, inputpool);
|
|
|
|
|
2014-07-31 16:08:33 +00:00
|
|
|
cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, &poolobj, vol,
|
|
|
|
inputvol, flags,
|
2016-06-02 15:33:47 +00:00
|
|
|
create_tool, imgformat,
|
|
|
|
NULL);
|
2013-06-05 08:49:15 +00:00
|
|
|
if (!cmd) {
|
2013-02-18 12:43:28 +00:00
|
|
|
if (shouldFail) {
|
|
|
|
virResetLastError();
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-06-05 08:49:15 +00:00
|
|
|
if (!(actualCmdline = virCommandToString(cmd)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(actualCmdline, cmdline) < 0)
|
2013-02-18 12:43:28 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-02-18 12:43:28 +00:00
|
|
|
virStoragePoolDefFree(pool);
|
2013-07-22 13:55:40 +00:00
|
|
|
virStoragePoolDefFree(inputpool);
|
2013-02-18 12:43:28 +00:00
|
|
|
virStorageVolDefFree(vol);
|
|
|
|
virStorageVolDefFree(inputvol);
|
|
|
|
virCommandFree(cmd);
|
|
|
|
VIR_FREE(actualCmdline);
|
2013-02-27 09:11:52 +00:00
|
|
|
virObjectUnref(conn);
|
2013-02-18 12:43:28 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct testInfo {
|
|
|
|
bool shouldFail;
|
|
|
|
const char *pool;
|
|
|
|
const char *vol;
|
2013-07-22 13:55:40 +00:00
|
|
|
const char *inputpool;
|
2013-02-18 12:43:28 +00:00
|
|
|
const char *inputvol;
|
|
|
|
const char *cmdline;
|
|
|
|
unsigned int flags;
|
|
|
|
int imgformat;
|
2015-02-17 15:57:02 +00:00
|
|
|
unsigned long parseflags;
|
2013-02-18 12:43:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLToArgvHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
const struct testInfo *info = data;
|
|
|
|
char *poolxml = NULL;
|
2013-07-22 13:55:40 +00:00
|
|
|
char *inputpoolxml = NULL;
|
2013-02-18 12:43:28 +00:00
|
|
|
char *volxml = NULL;
|
|
|
|
char *inputvolxml = NULL;
|
|
|
|
char *cmdline = NULL;
|
|
|
|
|
|
|
|
if (info->inputvol &&
|
2013-07-22 13:44:06 +00:00
|
|
|
virAsprintf(&inputvolxml, "%s/storagevolxml2xmlin/%s.xml",
|
2013-02-18 12:43:28 +00:00
|
|
|
abs_srcdir, info->inputvol) < 0)
|
|
|
|
goto cleanup;
|
2013-07-22 13:55:40 +00:00
|
|
|
if (info->inputpool &&
|
|
|
|
virAsprintf(&inputpoolxml, "%s/storagepoolxml2xmlin/%s.xml",
|
|
|
|
abs_srcdir, info->inputpool) < 0)
|
|
|
|
goto cleanup;
|
2013-07-22 12:56:26 +00:00
|
|
|
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
|
2013-02-18 12:43:28 +00:00
|
|
|
abs_srcdir, info->pool) < 0 ||
|
2013-07-22 13:44:06 +00:00
|
|
|
virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml",
|
2013-02-18 12:43:28 +00:00
|
|
|
abs_srcdir, info->vol) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv",
|
|
|
|
abs_srcdir, info->cmdline) < 0 && !info->shouldFail)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
|
2013-07-22 13:55:40 +00:00
|
|
|
inputpoolxml, inputvolxml,
|
|
|
|
cmdline, info->flags,
|
2015-02-17 15:57:02 +00:00
|
|
|
info->imgformat, info->parseflags);
|
2013-02-18 12:43:28 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-02-18 12:43:28 +00:00
|
|
|
VIR_FREE(poolxml);
|
|
|
|
VIR_FREE(volxml);
|
|
|
|
VIR_FREE(inputvolxml);
|
2013-07-22 13:55:40 +00:00
|
|
|
VIR_FREE(inputpoolxml);
|
2013-02-18 12:43:28 +00:00
|
|
|
VIR_FREE(cmdline);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
2016-05-31 14:53:18 +00:00
|
|
|
FMT_OPTIONS = 0,
|
2013-08-20 15:37:08 +00:00
|
|
|
FMT_COMPAT,
|
2013-02-18 12:43:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
unsigned int flags = VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
|
|
|
|
|
2015-02-17 15:57:02 +00:00
|
|
|
#define DO_TEST_FULL(shouldFail, parseflags, pool, vol, inputpool, inputvol, \
|
|
|
|
cmdline, flags, imgformat) \
|
2013-07-22 07:11:50 +00:00
|
|
|
do { \
|
2013-07-22 13:55:40 +00:00
|
|
|
struct testInfo info = { shouldFail, pool, vol, inputpool, inputvol, \
|
2015-02-17 15:57:02 +00:00
|
|
|
cmdline, flags, imgformat, parseflags }; \
|
2016-05-26 15:01:50 +00:00
|
|
|
if (virTestRun("Storage Vol XML-2-argv " cmdline, \
|
|
|
|
testCompareXMLToArgvHelper, &info) < 0) \
|
2013-07-22 07:11:50 +00:00
|
|
|
ret = -1; \
|
|
|
|
} \
|
2013-02-18 12:43:28 +00:00
|
|
|
while (0);
|
|
|
|
|
2013-07-22 07:11:50 +00:00
|
|
|
#define DO_TEST(pool, ...) \
|
2015-02-17 15:57:02 +00:00
|
|
|
DO_TEST_FULL(false, 0, pool, __VA_ARGS__)
|
2013-07-22 07:11:50 +00:00
|
|
|
|
|
|
|
#define DO_TEST_FAIL(pool, ...) \
|
2015-02-17 15:57:02 +00:00
|
|
|
DO_TEST_FULL(true, 0, pool, __VA_ARGS__)
|
2013-07-22 07:11:50 +00:00
|
|
|
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2",
|
2013-07-22 13:55:40 +00:00
|
|
|
NULL, NULL,
|
2013-07-22 07:11:50 +00:00
|
|
|
"qcow2", 0, FMT_OPTIONS);
|
|
|
|
DO_TEST_FAIL("pool-dir", "vol-qcow2",
|
2013-07-22 13:55:40 +00:00
|
|
|
NULL, NULL,
|
2013-07-22 07:11:50 +00:00
|
|
|
"qcow2-prealloc", flags, FMT_OPTIONS);
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
2013-07-22 13:55:40 +00:00
|
|
|
NULL, NULL,
|
2013-02-18 12:43:28 +00:00
|
|
|
"qcow2-nobacking-prealloc", flags, FMT_OPTIONS);
|
2013-07-22 07:11:50 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
2013-07-22 13:55:40 +00:00
|
|
|
"pool-dir", "vol-file",
|
2013-02-18 12:43:28 +00:00
|
|
|
"qcow2-nobacking-convert-prealloc", flags, FMT_OPTIONS);
|
2014-08-01 13:24:20 +00:00
|
|
|
DO_TEST_FAIL("pool-dir", "vol-qcow2",
|
|
|
|
"pool-dir", "vol-file",
|
|
|
|
"qcow2-convert-nobacking", 0, FMT_OPTIONS);
|
2013-07-22 07:11:50 +00:00
|
|
|
DO_TEST_FAIL("pool-dir", "vol-qcow2",
|
2013-07-22 13:55:40 +00:00
|
|
|
"pool-dir", "vol-file",
|
2013-07-22 07:11:50 +00:00
|
|
|
"qcow2-convert-prealloc", flags, FMT_OPTIONS);
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-lazy",
|
2013-07-22 13:55:40 +00:00
|
|
|
NULL, NULL,
|
2013-07-22 07:11:50 +00:00
|
|
|
"qcow2-lazy", 0, FMT_OPTIONS);
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-1.1",
|
2013-07-22 13:55:40 +00:00
|
|
|
NULL, NULL,
|
2013-07-22 07:11:50 +00:00
|
|
|
"qcow2-1.1", 0, FMT_OPTIONS);
|
|
|
|
DO_TEST_FAIL("pool-dir", "vol-qcow2-0.10-lazy",
|
2013-07-22 13:55:40 +00:00
|
|
|
NULL, NULL,
|
2013-07-22 07:11:50 +00:00
|
|
|
"qcow2-0.10-lazy", 0, FMT_OPTIONS);
|
2013-07-22 13:55:40 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
|
|
|
"pool-logical", "vol-logical",
|
|
|
|
"qcow2-from-logical", 0, FMT_OPTIONS);
|
|
|
|
DO_TEST("pool-logical", "vol-logical",
|
|
|
|
"pool-dir", "vol-qcow2-nobacking",
|
|
|
|
"logical-from-qcow2", 0, FMT_OPTIONS);
|
2013-02-18 12:43:28 +00:00
|
|
|
|
2013-08-20 15:37:08 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2",
|
|
|
|
NULL, NULL,
|
|
|
|
"qcow2-compat", 0, FMT_COMPAT);
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
|
|
|
NULL, NULL,
|
|
|
|
"qcow2-nobacking-prealloc-compat", flags, FMT_COMPAT);
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
|
|
|
"pool-dir", "vol-file",
|
|
|
|
"qcow2-nobacking-convert-prealloc-compat", flags, FMT_COMPAT);
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-lazy",
|
|
|
|
NULL, NULL,
|
|
|
|
"qcow2-lazy", 0, FMT_COMPAT);
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-1.1",
|
|
|
|
NULL, NULL,
|
|
|
|
"qcow2-1.1", 0, FMT_COMPAT);
|
|
|
|
DO_TEST_FAIL("pool-dir", "vol-qcow2-0.10-lazy",
|
|
|
|
NULL, NULL,
|
|
|
|
"qcow2-0.10-lazy", 0, FMT_COMPAT);
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nobacking",
|
|
|
|
"pool-logical", "vol-logical",
|
|
|
|
"qcow2-from-logical-compat", 0, FMT_COMPAT);
|
|
|
|
DO_TEST("pool-logical", "vol-logical",
|
|
|
|
"pool-dir", "vol-qcow2-nobacking",
|
|
|
|
"logical-from-qcow2", 0, FMT_COMPAT);
|
2014-07-15 08:49:47 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nocow",
|
|
|
|
NULL, NULL,
|
|
|
|
"qcow2-nocow", 0, FMT_OPTIONS);
|
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nocow",
|
|
|
|
NULL, NULL,
|
|
|
|
"qcow2-nocow-compat", 0, FMT_COMPAT);
|
2015-02-17 15:54:53 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-nocapacity",
|
|
|
|
"pool-dir", "vol-file",
|
|
|
|
"qcow2-nocapacity-convert-prealloc", flags, FMT_OPTIONS);
|
2015-06-30 20:19:04 +00:00
|
|
|
DO_TEST("pool-dir", "vol-qcow2-zerocapacity",
|
|
|
|
NULL, NULL,
|
|
|
|
"qcow2-zerocapacity", 0, FMT_COMPAT);
|
2015-02-17 15:57:02 +00:00
|
|
|
DO_TEST_FULL(false, VIR_VOL_XML_PARSE_OPT_CAPACITY,
|
|
|
|
"pool-dir", "vol-qcow2-nocapacity-backing", NULL, NULL,
|
|
|
|
"qcow2-nocapacity", 0, FMT_OPTIONS);
|
2013-08-20 15:37:08 +00:00
|
|
|
|
2017-03-07 15:50:59 +00:00
|
|
|
DO_TEST("pool-dir", "vol-file-iso",
|
|
|
|
NULL, NULL,
|
|
|
|
"iso", 0, FMT_OPTIONS);
|
|
|
|
DO_TEST("pool-dir", "vol-file",
|
|
|
|
"pool-dir", "vol-file-iso",
|
|
|
|
"iso-input", 0, FMT_OPTIONS);
|
|
|
|
|
2014-03-17 09:38:38 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2013-02-18 12:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|