From 2fa4a8b9915feaf40b8bc54e797d20b48f01600a Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 22 Jun 2009 17:19:30 +0000 Subject: [PATCH] Fix storage handling for custom test driver. 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/ --- docs/testnode.xml | 3 ++ docs/testpool.xml | 15 ++++++++ docs/testvol.xml | 6 ++++ src/test.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 docs/testpool.xml create mode 100644 docs/testvol.xml diff --git a/docs/testnode.xml b/docs/testnode.xml index be7121d81e..1ad7a1083a 100644 --- a/docs/testnode.xml +++ b/docs/testnode.xml @@ -11,6 +11,9 @@ + + + 6000 diff --git a/docs/testpool.xml b/docs/testpool.xml new file mode 100644 index 0000000000..c1a8dff779 --- /dev/null +++ b/docs/testpool.xml @@ -0,0 +1,15 @@ + + default-pool + 35bb2ad9-388a-cdfe-461a-b8907f6e53fe + 107374182400 + 0 + 107374182400 + + /default-pool + + 0700 + 10736 + 10736 + + + diff --git a/docs/testvol.xml b/docs/testvol.xml new file mode 100644 index 0000000000..00198f8de4 --- /dev/null +++ b/docs/testvol.xml @@ -0,0 +1,6 @@ + + default-vol + 1000000 + 50000 + + diff --git a/src/test.c b/src/test.c index a74e874bca..6f07462862 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; @@ -589,6 +670,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);