Read disk images size from xml description and fill
virStorageVolDef.capacity and allocation (let's consider
that allocation is the same as capacity, calculating real
allocation will be implemented later).
Signed-off-by: Dmitry Guryanov <dguryanov(a)parallels.com>
---
src/parallels/parallels_storage.c | 54 +++++++++++++++++++++++++++++++++++-
1 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c
index 003823e..f3fe3ea 100644
--- a/src/parallels/parallels_storage.c
+++ b/src/parallels/parallels_storage.c
@@ -253,10 +253,57 @@ parallelsPoolAddByDomain(virConnectPtr conn, virDomainObjPtr dom)
return pool;
}
+static int parallelsDiskDescParseNode(xmlDocPtr xml,
+ xmlNodePtr root,
+ virStorageVolDefPtr def)
+{
+ xmlXPathContextPtr ctxt = NULL;
+ int ret;
+
+ if (STRNEQ((const char *)root->name, "Parallels_disk_image")) {
+ virReportError(VIR_ERR_XML_ERROR,
+ "%s", _("unknown root element for storage
pool"));
+ goto cleanup;
+ }
+
+ ctxt = xmlXPathNewContext(xml);
+ if (ctxt == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ ctxt->node = root;
+
+ if (virXPathULongLong("string(./Disk_Parameters/Disk_size)",
+ ctxt, &def->capacity))
+ ret = -1;
+
+ def->capacity <<= 9;
+ def->allocation = def->capacity;
+cleanup:
+ xmlXPathFreeContext(ctxt);
+ return ret;
+
+}
+
+static int parallelsDiskDescParse(const char *path, virStorageVolDefPtr def)
+{
+ xmlDocPtr xml;
+ int ret = -1;
+
+ if (!(xml = virXMLParse(path, NULL, NULL)))
+ return -1;
+
+ ret = parallelsDiskDescParseNode(xml, xmlDocGetRootElement(xml), def);
+ xmlFreeDoc(xml);
+ return ret;
+}
+
static int parallelsAddDiskVolume(virStoragePoolObjPtr pool,
virDomainObjPtr dom,
const char *diskName,
- const char *diskPath)
+ const char *diskPath,
+ const char *diskDescPath)
{
virStorageVolDefPtr def = NULL;
@@ -269,6 +316,8 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool,
def->type = VIR_STORAGE_VOL_FILE;
+ parallelsDiskDescParse(diskDescPath, def);
+
if (!(def->target.path = realpath(diskPath, NULL)))
goto no_memory;
@@ -334,7 +383,8 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
/* here we know, that ent->d_name is a disk image directory */
- if (parallelsAddDiskVolume(pool, dom, ent->d_name, diskPath))
+ if (parallelsAddDiskVolume(pool, dom, ent->d_name,
+ diskPath, diskDescPath))
goto cleanup;
}
--
1.7.1