-----Original Message-----
From: Daniel P. Berrange [mailto:berrange@redhat.com]
Sent: 19 March 2010 10:57
To: Sharadha Prabhakar (3P)
Cc: libvir-list(a)redhat.com
Subject: Re: [libvirt] virStoragePoolDefParseString() fails with the following pool xml
On Fri, Mar 19, 2010 at 10:37:15AM +0000, Sharadha Prabhakar (3P) wrote:
Hi,
I have the following Pool XML
<pool type='netfs'>
<name>NFS ISO library</name>
<uuid>6142b786-378d-9def-bc96-2d0dc0466c13</uuid>
<capacity>838729728</capacity>
<allocation>838729728</allocation>
<available>148315040</available>
<source>
<host name='telos'/>
<dir path='/images/autoinstall'/>
That needs to be '<directory.../>' instead of just
<dir.../>'
I only filled the virStoragePoolDefPtr and passed it to virStoragePoolDefFormat(..) which
Returned the XML string that you see now. I've attached the function I used to fill
pdef and
The call to virStoragePoolDefFormat at the end of this mail. I'm using libvirt version
0.7.6
<format type='auto'/>
</source>
<target>
<permissions>
<mode>00</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>
I'm passing this string to virStoragePoolDefParseString() to get a
virStoragePoolDefPtr
But it returns NULL. Can anyone explain if there's something wrong with the XML
format?
FYI, there are example XML files in examples/xml/storage/ too
static char *
xenapiStoragePoolGetXMLDesc (virStoragePoolPtr pool,
unsigned int flags ATTRIBUTE_UNUSED)
{
xen_sr_record *record=NULL;
xen_sr sr=NULL;
xen_pbd_set *pbd_set=NULL;
xen_pbd pbd=NULL;
char *pathDetails = NULL, *host=NULL, *path=NULL,*xml=NULL;
virConnectPtr conn = pool->conn;
virStoragePoolDefPtr pdef=NULL;
char uuidStr[VIR_UUID_STRING_BUFLEN];
int i;
xen_session *session = ((struct _xenapiStoragePrivate
*)(conn->storagePrivateData))->session;
virUUIDFormat(pool->uuid,uuidStr);
if (xen_sr_get_by_uuid(session, &sr, uuidStr)) {
if (!xen_sr_get_record(session, &record, sr)) {
xen_sr_free(sr);
xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, "Couldn't get
SR information");
return NULL;
}
if (VIR_ALLOC(pdef)<0) {
virReportOOMError();
xen_sr_record_free(record);
return NULL;
}
if (STREQ(record->type,"nfs") ||
STREQ(record->type,"iso"))
pdef->type = VIR_STORAGE_POOL_NETFS;
else if(STREQ(record->type,"iscsi"))
pdef->type = VIR_STORAGE_POOL_ISCSI;
else if(STREQ(record->type,"file"))
pdef->type = VIR_STORAGE_POOL_DIR;
else if(STREQ(record->type,"lvm"))
pdef->type = VIR_STORAGE_POOL_LOGICAL;
else if(STREQ(record->type,"ext"))
pdef->type = VIR_STORAGE_POOL_FS;
else if(STREQ(record->type,"hba"))
pdef->type = VIR_STORAGE_POOL_SCSI;
fprintf(stderr,"\ntype:%s",virStoragePoolTypeToString(pdef->type));
if (!(pdef->name = strdup(record->name_label))) {
virReportOOMError();
xen_sr_record_free(record);
virStoragePoolDefFree(pdef);
return NULL; //goto cleanup;
}
virUUIDParse(record->uuid,pdef->uuid);
pdef->allocation = (record->virtual_allocation)/1024;
pdef->capacity = (record->physical_size)/1024;
pdef->available = (record->physical_size -
record->physical_utilisation)/1024;
if (STREQ(record->type,"ext")) {
pdef->source.format = VIR_STORAGE_POOL_FS_EXT3;
} else if (STREQ(record->type,"nfs")) {
pdef->source.format = VIR_STORAGE_POOL_NETFS_NFS;
}
xen_sr_get_pbds (session, &pbd_set, sr);
pbd = pbd_set->contents[0];
xen_string_string_map *deviceConfig=NULL;
xen_pbd_get_device_config(session, &deviceConfig, pbd);
if (deviceConfig) {
for (i=0;i<deviceConfig->size;i++) {
if(STREQ(deviceConfig->contents[i].key,"location")) {
fprintf(stderr,"\nfound location");
pathDetails = strdup(deviceConfig->contents[i].val);
break;
}
}
xen_string_string_map_free(deviceConfig);
}
if (pathDetails) {
VIR_ALLOC_N(host,strlen(pathDetails));
VIR_ALLOC_N(path,strlen(pathDetails));
if(pathDetails[0]!='/') {
sscanf(pathDetails,"%[^:]:%s",host,path);
} else {
if(pathDetails[1]=='/') {
sscanf(pathDetails,"//%[^/]%s",host,path);
} else {
strcpy(path,pathDetails);
}
}
fprintf(stderr,"\nhost:%s,path:%s",host,path);
if (host)
pdef->source.host.name = strdup(host);
if (path)
pdef->source.dir = strdup(path);
VIR_FREE(host);
VIR_FREE(path);
VIR_FREE(pathDetails);
}
xen_sr_free(sr);
xen_sr_record_free(record);
xml = virStoragePoolDefFormat(pdef);
virStoragePoolDefFree(pdef);
if (!xml)
xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, "Couldn't
convert to XML format");
return xml;
} else {
xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL);
return NULL;
}
}
The XML output produced was
<pool type='netfs'>
<name>NFS ISO library</name>
<uuid>6142b786-378d-9def-bc96-2d0dc0466c13</uuid>
<capacity>838729728</capacity>
<allocation>838729728</allocation>
<available>148315040</available>
<source>
<host name='telos'/>
<dir path='/images/autoinstall'/>
<format type='auto'/>
</source>
<target>
<permissions>
<mode>00</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>