[libvirt] virStoragePoolDefParseString() fails with the following pool xml

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'/> <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? I ran gdb and I kind of figured out that it fails at if (virStoragePoolDefParseSource(ctxt, &ret->source, ret->type, source_node) < 0) in virStoragePoolDefParseXML() in ~/src/conf/storage_conf.c The reason I need this is to dump Volume XML which takes the poolDefPtr as well as VolDefPtr To return the XML format(virStorageVolDefFormat()). Is there a simpler way of producing the Volume XML just using the VolDefPtr? Regards, Sharadha

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.../>'
<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 Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

-----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: 19 March 2010 10:57 To: Sharadha Prabhakar (3P) Cc: libvir-list@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>

On Fri, Mar 19, 2010 at 11:09:52AM +0000, Sharadha Prabhakar (3P) wrote:
-----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: 19 March 2010 10:57 To: Sharadha Prabhakar (3P) Cc: libvir-list@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
Oh, I take that back. Our example XML is wrong ! Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Hi, I'm still having problems getting a virStoragePoolDefPtr from virStoragePoolDefParseString(xml). I've tried the example xmls in libvirt but still getting NULL. Can someone check if the following xml when passed to virStoragePoolDefParseString(..) returns a pointer to virStoragePoolDefPtr, so that I can confirm that this function really works. If something is wrong with the following XML please point out. <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> <path>/</path> <permissions> <mode>00</mode> <owner>0</owner> <group>0</group> </permissions> </target> </pool> Thanks, Sharadha -----Original Message----- From: Sharadha Prabhakar (3P) Sent: 19 March 2010 11:10 To: 'Daniel P. Berrange' Cc: libvir-list@redhat.com Subject: RE: [libvirt] virStoragePoolDefParseString() fails with the following pool xml -----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: 19 March 2010 10:57 To: Sharadha Prabhakar (3P) Cc: libvir-list@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>

On Mon, Mar 22, 2010 at 06:08:46PM +0000, Sharadha Prabhakar (3P) wrote:
Hi, I'm still having problems getting a virStoragePoolDefPtr from virStoragePoolDefParseString(xml). I've tried the example xmls in libvirt but still getting NULL. Can someone check if the following xml when passed to virStoragePoolDefParseString(..) returns a pointer to virStoragePoolDefPtr, so that I can confirm that this function really works. If something is wrong with the following XML please point out.
The XML looks good & works when I load it via the QEMU driver eg virsh -c qemu:///session pool-define demo.xml This 'pool-define' operation will ultimately call into the virStoragePoolDefParseString() method, so that looks to be working as expected Reegards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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'/> <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? I ran gdb and I kind of figured out that it fails at if (virStoragePoolDefParseSource(ctxt, &ret->source, ret->type, source_node) < 0) in virStoragePoolDefParseXML() in ~/src/conf/storage_conf.c
I think you've got the wrong place here. If I feed your XML to 'virsh pool-define' using the QEMU driver, then I get error: XML description for missing storage pool target path is not well formed or invalid which is from static virStoragePoolDefPtr virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { .... if ((ret->target.path = virXPathString("string(./target/path)", ctxt)) == NULL) { virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool target path")); goto cleanup; } You need to add at least <target>/</target> as we previously discussed Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

I just added target path to pool XML. It doesn't resolve the issue. virStoragePoolDefParseString() returns NULL. -----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: 19 March 2010 11:16 To: Sharadha Prabhakar (3P) Cc: libvir-list@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'/> <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? I ran gdb and I kind of figured out that it fails at if (virStoragePoolDefParseSource(ctxt, &ret->source, ret->type, source_node) < 0) in virStoragePoolDefParseXML() in ~/src/conf/storage_conf.c
I think you've got the wrong place here. If I feed your XML to 'virsh pool-define' using the QEMU driver, then I get error: XML description for missing storage pool target path is not well formed or invalid which is from static virStoragePoolDefPtr virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { .... if ((ret->target.path = virXPathString("string(./target/path)", ctxt)) == NULL) { virStorageReportError(VIR_ERR_XML_ERROR, "%s", _("missing storage pool target path")); goto cleanup; } You need to add at least <target>/</target> as we previously discussed Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (2)
-
Daniel P. Berrange
-
Sharadha Prabhakar (3P)