
On Tue, Dec 04, 2012 at 05:43:08PM +0400, Dmitry Guryanov wrote:
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 allcoation will be implemented later).
Signed-off-by: Dmitry Guryanov <dguryanov@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 4d71eb1..1448a74 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;
you can drop the ./ in front of the XPath query, it's redundant, but harmless :-)
+ 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;
}
ACK, daniel -- Daniel Veillard | Open Source and Standards, Red Hat veillard@redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/