If using a custom test driver, storage pool file parsing was broken, and storage volume parsing was never implemented. Fix these issues, and add some examples in docs/ Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx> --- docs/testnode.xml | 3 ++ docs/testpool.xml | 15 +++++++++ docs/testvol.xml | 6 +++ src/test.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 0 deletions(-) create mode 100644 docs/testpool.xml create mode 100644 docs/testvol.xml diff --git a/docs/testnode.xml b/docs/testnode.xml index be7121d..1ad7a10 100644 --- a/docs/testnode.xml +++ b/docs/testnode.xml @@ -11,6 +11,9 @@ <domain file="testdomfc4.xml"/> <network file="testnetpriv.xml"/> <network file="testnetdef.xml"/> + <pool file="testpool.xml"> + <volume file="testvol.xml"/> + </pool> <cpu> <mhz>6000</mhz> diff --git a/docs/testpool.xml b/docs/testpool.xml new file mode 100644 index 0000000..c1a8dff --- /dev/null +++ b/docs/testpool.xml @@ -0,0 +1,15 @@ +<pool type='dir'> + <name>default-pool</name> + <uuid>35bb2ad9-388a-cdfe-461a-b8907f6e53fe</uuid> + <capacity>107374182400</capacity> + <allocation>0</allocation> + <available>107374182400</available> + <target> + <path>/default-pool</path> + <permissions> + <mode>0700</mode> + <owner>10736</owner> + <group>10736</group> + </permissions> + </target> +</pool> diff --git a/docs/testvol.xml b/docs/testvol.xml new file mode 100644 index 0000000..00198f8 --- /dev/null +++ b/docs/testvol.xml @@ -0,0 +1,6 @@ +<volume> + <name>default-vol</name> + <capacity>1000000</capacity> + <allocation>50000</allocation> + <target/> +</volume> diff --git a/src/test.c b/src/test.c index 6874d63..1661144 100644 --- a/src/test.c +++ b/src/test.c @@ -341,6 +341,87 @@ static char *testBuildFilename(const char *relativeTo, } } +static int testOpenVolumesForPool(virConnectPtr conn, + xmlDocPtr xml, + xmlXPathContextPtr ctxt, + const char *file, + virStoragePoolObjPtr pool, + int poolidx) { + char *vol_xpath; + int i, ret, func_ret = -1; + xmlNodePtr *vols = NULL; + virStorageVolDefPtr def; + + /* Find storage volumes */ + if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", poolidx) < 0) { + virReportOOMError(NULL); + goto error; + } + + ret = virXPathNodeSet(conn, vol_xpath, ctxt, &vols); + VIR_FREE(vol_xpath); + if (ret < 0) { + testError(NULL, VIR_ERR_XML_ERROR, + _("node vol list for pool '%s'"), pool->def->name); + goto error; + } + + for (i = 0 ; i < ret ; i++) { + char *relFile = virXMLPropString(vols[i], "file"); + if (relFile != NULL) { + char *absFile = testBuildFilename(file, relFile); + VIR_FREE(relFile); + if (!absFile) { + testError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", + _("resolving volume filename")); + goto error; + } + + def = virStorageVolDefParseFile(conn, pool->def, absFile); + VIR_FREE(absFile); + if (!def) + goto error; + } else { + if ((def = virStorageVolDefParseNode(conn, pool->def, xml, + vols[i])) == NULL) { + goto error; + } + } + + if (VIR_REALLOC_N(pool->volumes.objs, + pool->volumes.count+1) < 0) { + virReportOOMError(conn); + goto error; + } + + if (virAsprintf(&def->target.path, "%s/%s", + pool->def->target.path, + def->name) == -1) { + virReportOOMError(conn); + goto error; + } + + def->key = strdup(def->target.path); + if (def->key == NULL) { + virReportOOMError(conn); + goto error; + } + + pool->def->allocation += def->allocation; + pool->def->available = (pool->def->capacity - + pool->def->allocation); + + pool->volumes.objs[pool->volumes.count++] = def; + def = NULL; + } + + func_ret = 0; +error: + virStorageVolDefFree(def); + VIR_FREE(vols); + return func_ret; +} + static int testOpenFromFile(virConnectPtr conn, const char *file) { int fd = -1, i, ret; @@ -586,6 +667,13 @@ static int testOpenFromFile(virConnectPtr conn, goto error; } pool->active = 1; + + /* Find storage volumes */ + if (testOpenVolumesForPool(conn, xml, ctxt, file, pool, i+1) < 0) { + virStoragePoolObjUnlock(pool); + goto error; + } + virStoragePoolObjUnlock(pool); } VIR_FREE(pools); -- 1.6.3.2 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list