mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-30 21:47:18 +00:00
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/
This commit is contained in:
parent
3f305eb1e9
commit
2fa4a8b991
@ -11,6 +11,9 @@
|
|||||||
<domain file="testdomfc4.xml"/>
|
<domain file="testdomfc4.xml"/>
|
||||||
<network file="testnetpriv.xml"/>
|
<network file="testnetpriv.xml"/>
|
||||||
<network file="testnetdef.xml"/>
|
<network file="testnetdef.xml"/>
|
||||||
|
<pool file="testpool.xml">
|
||||||
|
<volume file="testvol.xml"/>
|
||||||
|
</pool>
|
||||||
|
|
||||||
<cpu>
|
<cpu>
|
||||||
<mhz>6000</mhz>
|
<mhz>6000</mhz>
|
||||||
|
15
docs/testpool.xml
Normal file
15
docs/testpool.xml
Normal file
@ -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>
|
6
docs/testvol.xml
Normal file
6
docs/testvol.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<volume>
|
||||||
|
<name>default-vol</name>
|
||||||
|
<capacity>1000000</capacity>
|
||||||
|
<allocation>50000</allocation>
|
||||||
|
<target/>
|
||||||
|
</volume>
|
88
src/test.c
88
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,
|
static int testOpenFromFile(virConnectPtr conn,
|
||||||
const char *file) {
|
const char *file) {
|
||||||
int fd = -1, i, ret;
|
int fd = -1, i, ret;
|
||||||
@ -589,6 +670,13 @@ static int testOpenFromFile(virConnectPtr conn,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
pool->active = 1;
|
pool->active = 1;
|
||||||
|
|
||||||
|
/* Find storage volumes */
|
||||||
|
if (testOpenVolumesForPool(conn, xml, ctxt, file, pool, i+1) < 0) {
|
||||||
|
virStoragePoolObjUnlock(pool);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
virStoragePoolObjUnlock(pool);
|
virStoragePoolObjUnlock(pool);
|
||||||
}
|
}
|
||||||
VIR_FREE(pools);
|
VIR_FREE(pools);
|
||||||
|
Loading…
Reference in New Issue
Block a user