2012-07-18 19:06:58 +00:00
|
|
|
/*
|
|
|
|
* storagebackendsheepdogtest.c: storage backend for Sheepdog handling
|
|
|
|
*
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
* Copyright (C) 2014 Red Hat, Inc.
|
2012-07-18 19:06:58 +00:00
|
|
|
* Copyright (C) 2012 Sebastian Wiedenroth
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2012-07-18 19:06:58 +00:00
|
|
|
*
|
|
|
|
* Author: Sebastian Wiedenroth <sebastian.wiedenroth@skylime.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "testutils.h"
|
2017-01-16 12:41:18 +00:00
|
|
|
#include "storage/storage_backend_sheepdog_priv.h"
|
2013-05-02 17:24:02 +00:00
|
|
|
#include "virstring.h"
|
2012-07-18 19:06:58 +00:00
|
|
|
|
2013-05-10 12:52:43 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *output;
|
|
|
|
int expected_return;
|
|
|
|
uint64_t expected_capacity;
|
|
|
|
uint64_t expected_allocation;
|
|
|
|
} collie_test;
|
|
|
|
|
2015-09-29 14:34:38 +00:00
|
|
|
struct testNodeInfoParserData {
|
|
|
|
collie_test data;
|
|
|
|
const char *poolxml;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct testVDIListParserData {
|
|
|
|
collie_test data;
|
|
|
|
const char *poolxml;
|
|
|
|
const char *volxml;
|
|
|
|
};
|
|
|
|
|
2012-07-18 19:06:58 +00:00
|
|
|
|
|
|
|
static int
|
2015-09-29 14:34:38 +00:00
|
|
|
test_node_info_parser(const void *opaque)
|
2012-07-18 19:06:58 +00:00
|
|
|
{
|
2015-09-29 14:34:38 +00:00
|
|
|
const struct testNodeInfoParserData *data = opaque;
|
|
|
|
collie_test test = data->data;
|
2012-07-18 19:06:58 +00:00
|
|
|
int ret = -1;
|
|
|
|
char *output = NULL;
|
|
|
|
virStoragePoolDefPtr pool = NULL;
|
|
|
|
|
2015-09-29 14:34:38 +00:00
|
|
|
if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
|
2012-07-18 19:06:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-03 12:52:21 +00:00
|
|
|
if (VIR_STRDUP(output, test.output) < 0)
|
2012-07-18 19:06:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=
|
|
|
|
test.expected_return)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (test.expected_return) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->capacity == test.expected_capacity &&
|
|
|
|
pool->allocation == test.expected_allocation)
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2012-07-18 19:06:58 +00:00
|
|
|
VIR_FREE(output);
|
|
|
|
virStoragePoolDefFree(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-09-29 14:34:38 +00:00
|
|
|
test_vdi_list_parser(const void *opaque)
|
2012-07-18 19:06:58 +00:00
|
|
|
{
|
2015-09-29 14:34:38 +00:00
|
|
|
const struct testVDIListParserData *data = opaque;
|
|
|
|
collie_test test = data->data;
|
2012-07-18 19:06:58 +00:00
|
|
|
int ret = -1;
|
|
|
|
char *output = NULL;
|
|
|
|
virStoragePoolDefPtr pool = NULL;
|
|
|
|
virStorageVolDefPtr vol = NULL;
|
|
|
|
|
2015-09-29 14:34:38 +00:00
|
|
|
if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
|
2012-07-18 19:06:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-09-29 14:34:38 +00:00
|
|
|
if (!(vol = virStorageVolDefParseFile(pool, data->volxml, 0)))
|
2012-07-18 19:06:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-03 12:52:21 +00:00
|
|
|
if (VIR_STRDUP(output, test.output) < 0)
|
2012-07-18 19:06:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virStorageBackendSheepdogParseVdiList(vol, output) !=
|
|
|
|
test.expected_return)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (test.expected_return) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (vol->target.capacity == test.expected_capacity &&
|
|
|
|
vol->target.allocation == test.expected_allocation)
|
2012-07-18 19:06:58 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2012-07-18 19:06:58 +00:00
|
|
|
VIR_FREE(output);
|
|
|
|
virStoragePoolDefFree(pool);
|
|
|
|
virStorageVolDefFree(vol);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
2015-09-29 14:34:38 +00:00
|
|
|
int ret = 0;
|
2012-07-18 19:06:58 +00:00
|
|
|
char *poolxml = NULL;
|
|
|
|
char *volxml = NULL;
|
|
|
|
|
|
|
|
collie_test node_info_tests[] = {
|
|
|
|
{"", -1, 0, 0},
|
|
|
|
{"Total 15245667872 117571104 0% 20972341\n", 0, 15245667872, 117571104},
|
|
|
|
{"To", -1, 0, 0},
|
|
|
|
{"asdf\nasdf", -1, 0, 0},
|
|
|
|
{"Total ", -1, 0, 0},
|
|
|
|
{"Total 1", -1, 0, 0},
|
|
|
|
{"Total 1\n", -1, 0, 0},
|
|
|
|
{"Total 1 ", -1, 0, 0},
|
|
|
|
{"Total 1 2", -1, 0, 0},
|
|
|
|
{"Total 1 2 ", -1, 0, 0},
|
|
|
|
{"Total 1 2\n", 0, 1, 2},
|
|
|
|
{"Total 1 2 \n", 0, 1, 2},
|
|
|
|
{"Total a 2 \n", -1, 0, 0},
|
|
|
|
{"Total 1 b \n", -1, 0, 0},
|
|
|
|
{"Total a b \n", -1, 0, 0},
|
|
|
|
{"stuff\nTotal 1 2 \n", 0, 1, 2},
|
|
|
|
{"0 1 2 3\nTotal 1 2 \n", 0, 1, 2},
|
|
|
|
{NULL, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
collie_test vdi_list_tests[] = {
|
|
|
|
{"", -1, 0, 0},
|
|
|
|
{"= test 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
|
|
|
|
{"= test\\ with\\ spaces 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
|
|
|
|
{"= backslashattheend\\\\ 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
|
|
|
|
{"s test 1 10 20 0 1336556634 7c2b25\n= test 3 50 60 0 1336557216 7c2b27\n", 0, 50, 60},
|
|
|
|
{"=", -1, 0, 0},
|
|
|
|
{"= test", -1, 0, 0},
|
|
|
|
{"= test ", -1, 0, 0},
|
|
|
|
{"= test 1", -1, 0, 0},
|
|
|
|
{"= test 1 ", -1, 0, 0},
|
|
|
|
{"= test 1 2", -1, 0, 0},
|
|
|
|
{"= test 1 2 ", -1, 0, 0},
|
|
|
|
{"= test 1 2 3", -1, 0, 0},
|
|
|
|
{NULL, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
collie_test *test = node_info_tests;
|
|
|
|
|
|
|
|
if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/pool-sheepdog.xml",
|
|
|
|
abs_srcdir) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&volxml, "%s/storagevolxml2xmlin/vol-sheepdog.xml",
|
|
|
|
abs_srcdir) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define DO_TEST_NODE(collie) \
|
|
|
|
do { \
|
|
|
|
struct testNodeInfoParserData data = { \
|
|
|
|
.data = collie, \
|
|
|
|
.poolxml = poolxml, \
|
|
|
|
}; \
|
|
|
|
if (virTestRun("node_info_parser", test_node_info_parser, \
|
|
|
|
&data) < 0) \
|
|
|
|
ret = -1; \
|
2015-09-29 14:34:38 +00:00
|
|
|
} while (0)
|
|
|
|
|
2012-07-18 19:06:58 +00:00
|
|
|
while (test->output != NULL) {
|
2015-09-29 14:34:38 +00:00
|
|
|
DO_TEST_NODE(*test);
|
2012-07-18 19:06:58 +00:00
|
|
|
++test;
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:34:38 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define DO_TEST_VDI(collie) \
|
|
|
|
do { \
|
|
|
|
struct testVDIListParserData data = { \
|
|
|
|
.data = collie, \
|
|
|
|
.poolxml = poolxml, \
|
|
|
|
.volxml = volxml, \
|
|
|
|
}; \
|
|
|
|
if (virTestRun("vdi_list_parser", test_vdi_list_parser, \
|
|
|
|
&data) < 0) \
|
|
|
|
ret = -1; \
|
2015-09-29 14:34:38 +00:00
|
|
|
} while (0)
|
|
|
|
|
2012-07-18 19:06:58 +00:00
|
|
|
test = vdi_list_tests;
|
|
|
|
|
|
|
|
while (test->output != NULL) {
|
2015-09-29 14:34:38 +00:00
|
|
|
DO_TEST_VDI(*test);
|
2012-07-18 19:06:58 +00:00
|
|
|
++test;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2012-07-18 19:06:58 +00:00
|
|
|
VIR_FREE(poolxml);
|
|
|
|
VIR_FREE(volxml);
|
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN(mymain)
|