Re: [libvirt] [PATCH 1/3] esx: Wrap libcurl multi handle

2012-07-08 Thread Matthias Bolte
2012/7/3 Doug Goldstein car...@gentoo.org:
 On Tue, Jul 3, 2012 at 3:17 PM, Matthias Bolte
 matthias.bo...@googlemail.com wrote:
 2012/7/3 Doug Goldstein car...@gentoo.org:
 On Mon, Jul 2, 2012 at 4:44 PM, Matthias Bolte
 matthias.bo...@googlemail.com wrote:
 ---
  src/esx/esx_vi.c |  111 
 ++
  src/esx/esx_vi.h |   18 +
  2 files changed, 129 insertions(+), 0 deletions(-)

 +/* esxVI_MultiCURL_Alloc */
 +ESX_VI__TEMPLATE__ALLOC(MultiCURL)
 +
 +/* esxVI_MultiCURL_Free */
 +ESX_VI__TEMPLATE__FREE(MultiCURL,
 +{
 +if (item-count  0) {
 +/* Better leak than crash */
 +VIR_ERROR(_(Trying to free MultiCURL object that is still in 
 use));
 +return;
 +}
 +
 +if (item-handle != NULL) {
 +curl_multi_cleanup(item-handle);
 +}

 Since its a double pointer maybe setting the passed in value to NULL
 to prevent a double free situations?

 Actually that's what already happens here but hidden inside the
 ESX_VI__TEMPLATE__FREE macro. Expanded esxVI_MultiCURL_Free looks like
 this

 void esxVI_MultiCURL_Free(esxVI_MultiCURL **multi)
 {
 esxVI_MultiCURL *item;

 if (multi == NULL || *multi == NULL) {
 return;
 }

 item = *multi;

 if (item-count  0) {
 /* Better leak than crash */
 VIR_ERROR(_(Trying to free MultiCURL object that is still in use));
 return;
 }

 if (item-handle != NULL) {
 curl_multi_cleanup(item-handle);
 }

 VIR_FREE(*multi);
 }

 As VIR_FREE sets its argument to NULL after freeing it a double free
 is not possible here.

 +int
 +esxVI_MultiCURL_Remove(esxVI_MultiCURL *multi, esxVI_CURL *curl)
 +{
 +if (curl-handle == NULL) {
 +ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
 + _(Cannot remove uninitialized CURL handle from a 
 +   multi handle));
 +return -1;
 +}
 +
 +if (curl-multi == NULL) {
 +ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
 + _(Cannot remove CURL handle from a multi handle 
 when it 
 +   wasn't added before));
 +return -1;
 +}
 +
 +if (curl-multi != multi) {
 +ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, %s, _(CURL (multi) 
 mismatch));
 +return -1;
 +}
 +
 +virMutexLock(curl-lock);
 +
 +curl_multi_remove_handle(multi-handle, curl-handle);
 +
 +curl-multi = NULL;
 +--multi-count;
 +
 +virMutexUnlock(curl-lock);

 Maybe add your free code here when count is 0? That way you wouldn't
 have to contend with a potential memory leak case when the free is
 called when its still ref'd.

 count is not meant as a refcount here. It's sole purpose is to avoid
 freeing a multi handle that still has easy handles attached to it.
 Also calling free one count == 0 here would not allow a call sequence
 such as add, remove, add, remove.

 --
 Matthias Bolte
 http://photron.blogspot.com


 Ok good. Just was double checking. Then ACK from me on this patch (its
 not affected by the multi-CONTENT issue mentioned in the other
 e-mail).

Thanks, I pushed this one.

-- 
Matthias Bolte
http://photron.blogspot.com

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2] esx: Extend esxVI_CURL_Download for partial downloads

2012-07-08 Thread Matthias Bolte
Also ensure that the virBuffer used to store the downloaded data
does not overflow.
---

v2:
 - Ensure that the used virBuffer dos not overflow.

 src/esx/esx_driver.c |2 +-
 src/esx/esx_vi.c |   62 +++--
 src/esx/esx_vi.h |3 +-
 3 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index db2144c..95b9286 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2802,7 +2802,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
 
 url = virBufferContentAndReset(buffer);
 
-if (esxVI_CURL_Download(priv-primary-curl, url, vmx)  0) {
+if (esxVI_CURL_Download(priv-primary-curl, url, vmx, 0, NULL)  0) {
 goto cleanup;
 }
 
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 48718b6..0769e8b 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -116,9 +116,9 @@ ESX_VI__TEMPLATE__FREE(CURL,
 })
 
 static size_t
-esxVI_CURL_ReadString(char *data, size_t size, size_t nmemb, void *ptrptr)
+esxVI_CURL_ReadString(char *data, size_t size, size_t nmemb, void *userdata)
 {
-const char *content = *(const char **)ptrptr;
+const char *content = *(const char **)userdata;
 size_t available = 0;
 size_t requested = size * nmemb;
 
@@ -138,16 +138,28 @@ esxVI_CURL_ReadString(char *data, size_t size, size_t 
nmemb, void *ptrptr)
 
 memcpy(data, content, requested);
 
-*(const char **)ptrptr = content + requested;
+*(const char **)userdata = content + requested;
 
 return requested;
 }
 
 static size_t
-esxVI_CURL_WriteBuffer(char *data, size_t size, size_t nmemb, void *buffer)
+esxVI_CURL_WriteBuffer(char *data, size_t size, size_t nmemb, void *userdata)
 {
+virBufferPtr buffer = userdata;
+
 if (buffer != NULL) {
-virBufferAdd((virBufferPtr) buffer, data, size * nmemb);
+/*
+ * Using a virBuffer to store the download data limits the downloadable
+ * size. This is no problem as esxVI_CURL_Download and 
esxVI_CURL_Perform
+ * are meant to download small things such as VMX files, VMDK metadata
+ * files and SOAP responses.
+ */
+if (virBufferUse(buffer)  UINT32_MAX / 2) {
+return 0;
+}
+
+virBufferAdd(buffer, data, size * nmemb);
 
 return size * nmemb;
 }
@@ -160,7 +172,7 @@ esxVI_CURL_WriteBuffer(char *data, size_t size, size_t 
nmemb, void *buffer)
 #if ESX_VI__CURL__ENABLE_DEBUG_OUTPUT
 static int
 esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type,
- char *info, size_t size, void *data ATTRIBUTE_UNUSED)
+ char *info, size_t size, void *userdata ATTRIBUTE_UNUSED)
 {
 char *buffer = NULL;
 
@@ -355,8 +367,10 @@ esxVI_CURL_Connect(esxVI_CURL *curl, esxUtil_ParsedUri 
*parsedUri)
 }
 
 int
-esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content)
+esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content,
+unsigned long long offset, unsigned long long *length)
 {
+char *range = NULL;
 virBuffer buffer = VIR_BUFFER_INITIALIZER;
 int responseCode = 0;
 
@@ -365,9 +379,33 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, 
char **content)
 return -1;
 }
 
+if (length != NULL  *length  0) {
+/*
+ * Using a virBuffer to store the download data limits the downloadable
+ * size. This is no problem as esxVI_CURL_Download is meant to download
+ * small things such as VMX of VMDK metadata files.
+ */
+if (*length  UINT32_MAX / 2) {
+ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
+ _(Download length it too large));
+return -1;
+}
+
+if (virAsprintf(range, %llu-%llu, offset, offset + *length - 1)  
0) {
+virReportOOMError();
+goto cleanup;
+}
+} else if (offset  0) {
+if (virAsprintf(range, %llu-, offset)  0) {
+virReportOOMError();
+goto cleanup;
+}
+}
+
 virMutexLock(curl-lock);
 
 curl_easy_setopt(curl-handle, CURLOPT_URL, url);
+curl_easy_setopt(curl-handle, CURLOPT_RANGE, range);
 curl_easy_setopt(curl-handle, CURLOPT_WRITEDATA, buffer);
 curl_easy_setopt(curl-handle, CURLOPT_UPLOAD, 0);
 curl_easy_setopt(curl-handle, CURLOPT_HTTPGET, 1);
@@ -378,7 +416,7 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char 
**content)
 
 if (responseCode  0) {
 goto cleanup;
-} else if (responseCode != 200) {
+} else if (responseCode != 200  responseCode != 206) {
 ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
  _(HTTP response code %d for download from '%s'),
  responseCode, url);
@@ -390,9 +428,15 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, 
char **content)
 goto cleanup;
 }
 
+if (length != NULL) {
+*length 

[libvirt] dnsmasq SRV/TXT RR and Host xml parsing upgrade and bug fix

2012-07-08 Thread Guannan Ren

The set of patches aims to three kind of jobs.

First, for SRV RR, in order to strictly comform to RFC 2782, the patch
  changed and upgraded codes in following parts.
  The format of SRV RR:
  _Service._Proto.Name TTL Class SRV Priority Weight Port Target

  1,The protocol and service labels are prepended with an underscore.
  e.g: _ldap._tcp.example.com
  2,The range of Port,Priority,Weight is 0-65535.
  3,A Target of . means that the service is decidedly not available at this 
domain.

  Also, trying to invoke dnsmasq command line based on its manpage.
  
--srv-host=_service._prot.[domain],[target[,port[,priority[,weight
  _service and protocol are mandatory options.
  The reset of them are optional.
  When the target is not given in dnsmasq, it comform to the third item above.

  For TXT RR, we changed the text field from mandatory to optional based on
  dnsmasq manpage:
  --txt-record=name[[,text],text]

Second, changed the way of dns element as well as its children elements parsing 
via
  virXPathNodeSet(). It has advantages when multiple children elements there is.

Third, fixed related bug and unexposed bugs
   https://bugzilla.redhat.com/show_bug.cgi?id=836326

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/5] network_conf: refactor the implementation of SRV parsering

2012-07-08 Thread Guannan Ren
Refacor the virNetworkDNSSrvDefParseXML function.
Prefix service and protocol with a underscore during parsing according
to RFC2782.

srv service='kerberos' protocol='tcp'/
before:  --srv-host=kerberos.tcp
after:   --srv-host=_kerberos._tcp

domain is optional which will override the value of --domain options
to dnsmasq if supplied to form the following format

_service._prot.[domain]
--srv-host=_kerberos._tcp.pony.demo.redhat.com,pony
domain has nothing to do with port,priority,weight, so extract it
from if clause.

target is optional. If it is not supplied, it means the SRV RR is
invalid in this DNS zone. Values of port,priority,weight are meaningful
only when target is supplied. These three values have toplimit 65535,
so checking the range of them.

The default for port is 1 and the defaults for weight and priority are 0.
---
 src/conf/network_conf.c |  200 +++
 src/conf/network_conf.h |3 +
 2 files changed, 136 insertions(+), 67 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 012be6a..f6694ed 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -603,92 +603,143 @@ virNetworkDNSSrvDefAlloc(void)
 return srv;
 }
 
-static int
-virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def,
-xmlNodePtr cur,
-xmlXPathContextPtr ctxt)
+static char *
+virNetworkDNSSrvDefParseServiceAndProtocol(xmlNodePtr cur,
+   const char *attr)
 {
-char *domain = NULL;
-char *service = NULL;
-char *protocol = NULL;
-char *target = NULL;
-int port;
-int priority;
-int weight;
-int ret = 0;
-
-virNetworkDNSSrvRecordsDefPtr srv = NULL;
+char *value = NULL;
+char *ret = NULL;
+const char *prefix = _;
+int offset = 1;
+size_t length;
 
-if (!(srv = virNetworkDNSSrvDefAlloc()))
-goto error;
+if (!cur || !attr)
+return NULL;
 
-if (!(service = virXMLPropString(cur, service))) {
+if (!(value = virXMLPropString(cur, attr))) {
 virNetworkReportError(VIR_ERR_XML_DETAIL,
-  %s, _(Missing required service attribute in 
dns srv record));
+  _(Missing required '%s' attribute in dns srv 
record),
+  attr);
 goto error;
 }
 
-if (strlen(service)  DNS_RECORD_LENGTH_SRV) {
-virNetworkReportError(VIR_ERR_XML_DETAIL,
-  _(Service name is too long, limit is %d bytes),
-  DNS_RECORD_LENGTH_SRV);
-goto error;
-}
+length = strlen(value);
 
-if (!(protocol = virXMLPropString(cur, protocol))) {
+if (STREQ(attr, service) 
+   (length == 0 || length  DNS_RECORD_LENGTH_SRV)) {
 virNetworkReportError(VIR_ERR_XML_DETAIL,
-  _(Missing required protocol attribute in dns 
srv record '%s'), service);
+  _(Service name should not be null, limit is %d 
bytes),
+  DNS_RECORD_LENGTH_SRV);
 goto error;
 }
 
 /* Check whether protocol value is the supported one */
-if (STRNEQ(protocol, tcp)  (STRNEQ(protocol, udp))) {
-virNetworkReportError(VIR_ERR_XML_DETAIL,
-  _(Invalid protocol attribute value '%s'), 
protocol);
-goto error;
+if (STREQ(attr, protocol)) {
+if (length == 0 || (STRNEQ(value, tcp)  STRNEQ(value, udp))) {
+virNetworkReportError(VIR_ERR_XML_DETAIL,
+  _(Protocol should not be null, 'tcp' or 
'udp'));
+goto error;
+}
 }
 
-if (VIR_REALLOC_N(def-srvrecords, def-nsrvrecords + 1)  0) {
+/* Prefix the service and protocol with '_'.
+ */
+if (VIR_ALLOC_N(ret, length + offset + 1)  0) {
 virReportOOMError();
 goto error;
 }
+strcpy(ret, prefix);
+strcat(ret + offset, value);
+VIR_FREE(value);
+
+return ret;
+error:
+VIR_FREE(value);
+VIR_FREE(ret);
+return NULL;
+}
+
+static char *
+virNetworkDNSSrvDefParseTarget(xmlNodePtr cur)
+{
+char *target = NULL;
+
+if (!cur)
+return NULL;
+
+/* Target is optional, we ignore null string 
+ * According to RFC 2782, a target of . means that the service
+ * is decidedly not available at this domain. We just ignore .
+ * given by user explicitly because dnsmasq implements it via
+ * not feeding target value in command line.
+ */
+target = virXMLPropString(cur, target);
+
+if (target  (!strlen(target) || *target == '.'))
+VIR_FREE(target);
+
+return target;
+}
+
+static virNetworkDNSSrvRecordsDefPtr
+virNetworkDNSSrvDefParseXML(xmlNodePtr cur,
+xmlXPathContextPtr ctxt)
+{
+virNetworkDNSSrvRecordsDefPtr srv = NULL;
+
+if (!(srv = virNetworkDNSSrvDefAlloc()))
+ 

[libvirt] [PATCH 1/5] network_conf: use pointer to pointer type for srvrecords

2012-07-08 Thread Guannan Ren
Replace virNetworkDNSSrvRecordsDefPtr type with
virNetworkDNSSrvRecordsDefPtr * type for srvrecords field in
struct _virNetworkDNSDef.

Create two new helper functions to allocate and free memory of
type virNetworkDNSSrvRecordsDefPtr.
Fix a bug when any of values of port, priority, weight is not
given in SRV xml description, uninitialized of these three variables
are used  which causes the failure of creating dnsmasq subprocess.

before:
...
  dns
srv service='kerberos' protocol='tcp' target='pony.demo.redhat.com' 
port='88'/
  /dns
...

--srv-host=kerberos.tcp,pony.demo.redhat.com,88,1095468768,32544

after:
--srv-host=kerberos.tcp,pony.demo.redhat.com,88,,
---
 src/conf/network_conf.c |  109 +++---
 src/conf/network_conf.h |5 ++-
 src/network/bridge_driver.c |   22 
 3 files changed, 85 insertions(+), 51 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 515bc36..012be6a 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -140,10 +140,10 @@ static void virNetworkDNSDefFree(virNetworkDNSDefPtr def)
 VIR_FREE(def-hosts);
 if (def-nsrvrecords) {
 while (def-nsrvrecords--) {
-VIR_FREE(def-srvrecords[def-nsrvrecords].domain);
-VIR_FREE(def-srvrecords[def-nsrvrecords].service);
-VIR_FREE(def-srvrecords[def-nsrvrecords].protocol);
-VIR_FREE(def-srvrecords[def-nsrvrecords].target);
+VIR_FREE(def-srvrecords[def-nsrvrecords]-domain);
+VIR_FREE(def-srvrecords[def-nsrvrecords]-service);
+VIR_FREE(def-srvrecords[def-nsrvrecords]-protocol);
+VIR_FREE(def-srvrecords[def-nsrvrecords]-target);
 }
 }
 VIR_FREE(def-srvrecords);
@@ -569,6 +569,40 @@ error:
 return ret;
 }
 
+void
+virNetworkDNSSrvDefFree(virNetworkDNSSrvRecordsDefPtr srv)
+{
+if (!srv)
+return;
+
+VIR_FREE(srv-domain);
+VIR_FREE(srv-service);
+VIR_FREE(srv-protocol);
+VIR_FREE(srv-target);
+
+VIR_FREE(srv);
+}
+
+virNetworkDNSSrvRecordsDefPtr
+virNetworkDNSSrvDefAlloc(void)
+{
+virNetworkDNSSrvRecordsDefPtr srv = NULL;
+
+if (VIR_ALLOC(srv)  0) {
+virReportOOMError();
+return NULL;
+}
+
+/* The default for port is one */
+srv-port = 1;
+
+/* The defaults for weight and priority are zero */
+srv-priority = 0;
+srv-weight = 0;
+
+return srv;
+}
+
 static int
 virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def,
 xmlNodePtr cur,
@@ -583,6 +617,11 @@ virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def,
 int weight;
 int ret = 0;
 
+virNetworkDNSSrvRecordsDefPtr srv = NULL;
+
+if (!(srv = virNetworkDNSSrvDefAlloc()))
+goto error;
+
 if (!(service = virXMLPropString(cur, service))) {
 virNetworkReportError(VIR_ERR_XML_DETAIL,
   %s, _(Missing required service attribute in 
dns srv record));
@@ -614,37 +653,28 @@ virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def,
 goto error;
 }
 
-def-srvrecords[def-nsrvrecords].service = service;
-def-srvrecords[def-nsrvrecords].protocol = protocol;
-def-srvrecords[def-nsrvrecords].domain = NULL;
-def-srvrecords[def-nsrvrecords].target = NULL;
-def-srvrecords[def-nsrvrecords].port = 0;
-def-srvrecords[def-nsrvrecords].priority = 0;
-def-srvrecords[def-nsrvrecords].weight = 0;
+srv-service = service;
+srv-protocol = protocol;
 
 /* Following attributes are optional but we had to make sure they're NULL 
above */
 if ((target = virXMLPropString(cur, target))  (domain = 
virXMLPropString(cur, domain))) {
-xmlNodePtr save_ctxt = ctxt-node;
+srv-target = target;
+srv-domain = domain;
 
+xmlNodePtr save_ctxt = ctxt-node;
 ctxt-node = cur;
-if (virXPathInt(string(./@port), ctxt, port))
-def-srvrecords[def-nsrvrecords].port = port;
+if (virXPathInt(string(./@port), ctxt, port) == 0)
+srv-port = port;
 
-if (virXPathInt(string(./@priority), ctxt, priority))
-def-srvrecords[def-nsrvrecords].priority = priority;
+if (virXPathInt(string(./@priority), ctxt, priority) == 0)
+srv-priority = priority;
 
-if (virXPathInt(string(./@weight), ctxt, weight))
-def-srvrecords[def-nsrvrecords].weight = weight;
+if (virXPathInt(string(./@weight), ctxt, weight) == 0)
+srv-weight = weight;
 ctxt-node = save_ctxt;
-
-def-srvrecords[def-nsrvrecords].domain = domain;
-def-srvrecords[def-nsrvrecords].target = target;
-def-srvrecords[def-nsrvrecords].port = port;
-def-srvrecords[def-nsrvrecords].priority = priority;
-def-srvrecords[def-nsrvrecords].weight = weight;
 }
 
-def-nsrvrecords++;
+

[libvirt] [PATCH 4/5] network_conf: change TXT record to pointer to pointer type

2012-07-08 Thread Guannan Ren
Change the type of txtrecords from virNetworkDNSTxtRecordsDefPtr to
virNetworkDNSTxtRecordsDefPtr *.
Refacotr the virNetworkDNSDefParseXML to create a new TXT xml Parsing
function.
Make value (text field in TXT RR) optional according to dnsmasq
manpage.

--txt-record=name[[,text],text]
---
 src/conf/network_conf.c |  111 +++
 src/conf/network_conf.h |2 +-
 src/network/bridge_driver.c |   16 +-
 3 files changed, 84 insertions(+), 45 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 99c6fc1..b720c9f 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -125,8 +125,8 @@ static void virNetworkDNSDefFree(virNetworkDNSDefPtr def)
 if (def) {
 if (def-txtrecords) {
 while (def-ntxtrecords--) {
-VIR_FREE(def-txtrecords[def-ntxtrecords].name);
-VIR_FREE(def-txtrecords[def-ntxtrecords].value);
+VIR_FREE(def-txtrecords[def-ntxtrecords]-name);
+VIR_FREE(def-txtrecords[def-ntxtrecords]-value);
 }
 }
 VIR_FREE(def-txtrecords);
@@ -512,6 +512,44 @@ virNetworkDHCPRangeDefParseXML(const char *networkName,
 return 0;
 }
 
+static virNetworkDNSTxtRecordsDefPtr
+virNetworkDNSTxtDefParseXML(xmlNodePtr cur)
+
+{
+virNetworkDNSTxtRecordsDefPtr txt = NULL;
+
+if (VIR_ALLOC(txt)  0) {
+virReportOOMError();
+return NULL;
+}
+
+if (!(txt-name = virXMLPropString(cur, name))) {
+virNetworkReportError(VIR_ERR_XML_DETAIL,
+  %s, _(Missing required name attribute in dns 
txt record));
+goto error;
+}
+
+/* The text field for dnsmasq is optional */
+txt-value = virXMLPropString(cur, value);
+if (txt-value  *txt-value == '\0')
+txt-value = NULL;
+
+if (strchr(txt-name, ' ') != NULL) {
+virNetworkReportError(VIR_ERR_XML_DETAIL,
+  _(spaces are not allowed in DNS TXT record 
names (name is '%s')), txt-name);
+goto error;
+}
+
+return txt;
+error:
+if (txt) {
+VIR_FREE(txt-name);
+VIR_FREE(txt-value);
+}
+VIR_FREE(txt);
+return NULL;
+}
+
 static int
 virNetworkDNSHostsDefParseXML(virNetworkDNSDefPtr def,
   xmlNodePtr node)
@@ -751,8 +789,6 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
 xmlNodePtr cur;
 int i, n;
 int ret = -1;
-char *name = NULL;
-char *value = NULL;
 virNetworkDNSDefPtr def = NULL;
 
 if (VIR_ALLOC(def)  0) {
@@ -781,38 +817,31 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
 }
 VIR_FREE(nodes);
 
-cur = node-children;
-while (cur != NULL) {
-if (cur-type == XML_ELEMENT_NODE 
-xmlStrEqual(cur-name, BAD_CAST txt)) {
-if (!(name = virXMLPropString(cur, name))) {
-virNetworkReportError(VIR_ERR_XML_DETAIL,
-  %s, _(Missing required name attribute 
in dns txt record));
-goto error;
-}
-if (!(value = virXMLPropString(cur, value))) {
-virNetworkReportError(VIR_ERR_XML_DETAIL,
-  _(Missing required value attribute in 
dns txt record '%s'), name);
-goto error;
-}
+if ((n = virXPathNodeSet(./dns/txt, ctxt, nodes))  0) {
+virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
+  %s, _(cannot extract txt nodes));
+goto error;
+}
 
-if (strchr(name, ' ') != NULL) {
-virNetworkReportError(VIR_ERR_XML_DETAIL,
-  _(spaces are not allowed in DNS TXT 
record names (name is '%s')), name);
-goto error;
-}
+if (n  VIR_REALLOC_N(def-txtrecords, def-ntxtrecords + n)  0) {
+virReportOOMError();
+goto error;
+}
+for (i = 0; i  n; i++) {
+virNetworkDNSTxtRecordsDefPtr txt;
 
-if (VIR_REALLOC_N(def-txtrecords, def-ntxtrecords + 1)  0) {
-virReportOOMError();
-goto error;
-}
+txt = virNetworkDNSTxtDefParseXML(nodes[i]);
+if (!txt)
+goto error;
 
-def-txtrecords[def-ntxtrecords].name = name;
-def-txtrecords[def-ntxtrecords].value = value;
-def-ntxtrecords++;
-name = NULL;
-value = NULL;
-} else if (cur-type == XML_ELEMENT_NODE 
+def-txtrecords[def-ntxtrecords++] = txt;
+}
+VIR_FREE(nodes);
+
+
+cur = node-children;
+while (cur != NULL) {
+if (cur-type == XML_ELEMENT_NODE 
 xmlStrEqual(cur-name, BAD_CAST host)) {
 ret = virNetworkDNSHostsDefParseXML(def, cur);
 if (ret  0)
@@ -824,13 +853,11 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
 
 ret = 0;
 error:
- 

[libvirt] [PATCH 5/5] network_conf: change host field in _virNetworkDNSDef to pointer to pointer

2012-07-08 Thread Guannan Ren
Change the type of host filed in struct _virNetworkDNSDef from
virNetworkDNSHostsDefPtr to virNetworkDNSHostsDefPtr *.
Create new function virNetworkDNSHostsDefParseXML to parse host
xml defination.
Create virNetworkDNSHostsDefFree to free type data of type
virNetworkDNSHostsDefPtr.
---
 src/conf/network_conf.c |   98 --
 src/conf/network_conf.h |5 +-
 src/network/bridge_driver.c |2 +-
 3 files changed, 60 insertions(+), 45 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index b720c9f..1d0ae50 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -132,9 +132,9 @@ static void virNetworkDNSDefFree(virNetworkDNSDefPtr def)
 VIR_FREE(def-txtrecords);
 if (def-nhosts) {
 while (def-nhosts--) {
-while (def-hosts[def-nhosts].nnames--)
-
VIR_FREE(def-hosts[def-nhosts].names[def-hosts[def-nhosts].nnames]);
-VIR_FREE(def-hosts[def-nhosts].names);
+while (def-hosts[def-nhosts]-nnames--)
+
VIR_FREE(def-hosts[def-nhosts]-names[def-hosts[def-nhosts]-nnames]);
+VIR_FREE(def-hosts[def-nhosts]-names);
 }
 }
 VIR_FREE(def-hosts);
@@ -550,33 +550,42 @@ error:
 return NULL;
 }
 
-static int
-virNetworkDNSHostsDefParseXML(virNetworkDNSDefPtr def,
-  xmlNodePtr node)
+void virNetworkDNSHostsDefFree(virNetworkDNSHostsDefPtr host)
+{
+int i;
+
+if (!host)
+return;
+
+for (i = 0; i  host-nnames; i++)
+VIR_FREE(host-names[i]);
+
+VIR_FREE(host-names);
+VIR_FREE(host);
+}
+
+static virNetworkDNSHostsDefPtr
+virNetworkDNSHostsDefParseXML(xmlNodePtr node)
 {
 xmlNodePtr cur;
-char *ip;
+char *ip = NULL;
 virSocketAddr inaddr;
-int ret = -1;
+virNetworkDNSHostsDefPtr host = NULL;
+
+if (VIR_ALLOC(host)  0) {
+virReportOOMError();
+goto error;
+}
 
 if (!(ip = virXMLPropString(node, ip)) ||
 (virSocketAddrParse(inaddr, ip, AF_UNSPEC)  0)) {
 virNetworkReportError(VIR_ERR_XML_DETAIL,
   _(Missing IP address in DNS host definition));
-VIR_FREE(ip);
 goto error;
 }
-VIR_FREE(ip);
+host-ip = inaddr;
 
-if (VIR_REALLOC_N(def-hosts, def-nhosts + 1)  0) {
-virReportOOMError();
-goto error;
-}
-
-def-hosts[def-nhosts].ip = inaddr;
-def-hosts[def-nhosts].nnames = 0;
-
-if (VIR_ALLOC(def-hosts[def-nhosts].names)  0) {
+if (VIR_ALLOC(host-names)  0) {
 virReportOOMError();
 goto error;
 }
@@ -586,25 +595,24 @@ virNetworkDNSHostsDefParseXML(virNetworkDNSDefPtr def,
 if (cur-type == XML_ELEMENT_NODE 
 xmlStrEqual(cur-name, BAD_CAST hostname)) {
   if (cur-children != NULL) {
-  if (VIR_REALLOC_N(def-hosts[def-nhosts].names, 
def-hosts[def-nhosts].nnames + 1)  0) {
+  if (VIR_REALLOC_N(host-names, host-nnames + 1)  0) {
   virReportOOMError();
   goto error;
   }
 
-  
def-hosts[def-nhosts].names[def-hosts[def-nhosts].nnames] = strdup((char 
*)cur-children-content);
-  def-hosts[def-nhosts].nnames++;
+  host-names[host-nnames] = strdup((char 
*)cur-children-content);
+  host-nnames++;
   }
 }
 
 cur = cur-next;
 }
 
-def-nhosts++;
-
-ret = 0;
-
+return host;
 error:
-return ret;
+VIR_FREE(ip);
+virNetworkDNSHostsDefFree(host);
+return NULL;
 }
 
 void
@@ -782,11 +790,9 @@ error:
 
 static int
 virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
- xmlNodePtr node,
  xmlXPathContextPtr ctxt)
 {
 xmlNodePtr *nodes = NULL;
-xmlNodePtr cur;
 int i, n;
 int ret = -1;
 virNetworkDNSDefPtr def = NULL;
@@ -838,18 +844,26 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
 }
 VIR_FREE(nodes);
 
+if ((n = virXPathNodeSet(./dns/host, ctxt, nodes))  0) {
+virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
+  %s, _(cannot extract host nodes));
+goto error;
+}
 
-cur = node-children;
-while (cur != NULL) {
-if (cur-type == XML_ELEMENT_NODE 
-xmlStrEqual(cur-name, BAD_CAST host)) {
-ret = virNetworkDNSHostsDefParseXML(def, cur);
-if (ret  0)
-goto error;
-}
+if (n  VIR_REALLOC_N(def-hosts, def-nhosts + n)  0) {
+virReportOOMError();
+goto error;
+}
+for (i = 0; i  n; i++) {
+virNetworkDNSHostsDefPtr host;
 
-cur = cur-next;
+host = virNetworkDNSHostsDefParseXML(nodes[i]);
+if (!host)
+goto error;
+
+def-hosts[def-nhosts++] = host;
 }
+   

[libvirt] [PATCH 3/5] bridge_driver: make the dnsmasq comand line more exact

2012-07-08 Thread Guannan Ren
bridge_driver.c: Only the service and potocol are mandatory argument.
If domain or target is not supplied in xml, we should not include the period
and comma in command line, so we don't provide them in dnsmasq
command line and leave the work to dnsmasq.

srv service='kerberos' protocol='tcp'/
before:
 --srv-host=kerberos.tcp..,,,
It will report error in this case

after:
 --srv-host=_kerberos._tcp

network_conf.c: Because we initialized these three values, we should
dumpxml their values anytime.
---
 src/conf/network_conf.c |   31 +++--
 src/network/bridge_driver.c |   44 ++
 2 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index f6694ed..99c6fc1 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -755,8 +755,10 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
 char *value = NULL;
 virNetworkDNSDefPtr def = NULL;
 
-if (VIR_ALLOC(def)  0)
-goto no_memory;
+if (VIR_ALLOC(def)  0) {
+virReportOOMError();
+goto error;
+}
 
 if ((n = virXPathNodeSet(./dns/srv, ctxt, nodes))  0) {
 virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
@@ -764,8 +766,10 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
 goto error;
 }
 
-if (n  VIR_REALLOC_N(def-srvrecords, def-nsrvrecords + n)  0)
-goto no_memory;
+if (n  VIR_REALLOC_N(def-srvrecords, def-nsrvrecords + n)  0) {
+virReportOOMError();
+goto error;
+}
 for (i = 0; i  n; i++) {
 virNetworkDNSSrvRecordsDefPtr srv;
 
@@ -798,8 +802,10 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
 goto error;
 }
 
-if (VIR_REALLOC_N(def-txtrecords, def-ntxtrecords + 1)  0)
-goto no_memory;
+if (VIR_REALLOC_N(def-txtrecords, def-ntxtrecords + 1)  0) {
+virReportOOMError();
+goto error;
+}
 
 def-txtrecords[def-ntxtrecords].name = name;
 def-txtrecords[def-ntxtrecords].value = value;
@@ -817,9 +823,6 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
 }
 
 ret = 0;
-no_memory:
-virReportOOMError();
-
 error:
 if (ret  0) {
 VIR_FREE(name);
@@ -1412,12 +1415,10 @@ virNetworkDNSDefFormat(virBufferPtr buf,
 virBufferAsprintf(buf,  domain='%s', 
def-srvrecords[i]-domain);
 if (def-srvrecords[i]-target)
 virBufferAsprintf(buf,  target='%s', 
def-srvrecords[i]-target);
-if (def-srvrecords[i]-port)
-virBufferAsprintf(buf,  port='%d', def-srvrecords[i]-port);
-if (def-srvrecords[i]-priority)
-virBufferAsprintf(buf,  priority='%d', 
def-srvrecords[i]-priority);
-if (def-srvrecords[i]-weight)
-virBufferAsprintf(buf,  weight='%d', 
def-srvrecords[i]-weight);
+
+virBufferAsprintf(buf,  port='%d', def-srvrecords[i]-port);
+virBufferAsprintf(buf,  priority='%d', 
def-srvrecords[i]-priority);
+virBufferAsprintf(buf,  weight='%d', def-srvrecords[i]-weight);
 
 virBufferAsprintf(buf, /\n);
 }
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index df999b9..95a9b96 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -459,6 +459,8 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
 int r, ret = -1;
 int nbleases = 0;
 int ii;
+char *domain = NULL;
+char *target = NULL;
 char *record = NULL;
 char *recordPort = NULL;
 char *recordWeight = NULL;
@@ -527,38 +529,52 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
 
 for (i = 0; i  dns-nsrvrecords; i++) {
 if (dns-srvrecords[i]-service  dns-srvrecords[i]-protocol) {
-if (dns-srvrecords[i]-port) {
-if (virAsprintf(recordPort, %d, 
dns-srvrecords[i]-port)  0) {
+if (dns-srvrecords[i]-domain) {
+if (virAsprintf(domain, .%s,
+dns-srvrecords[i]-domain)  0) {
 virReportOOMError();
 goto cleanup;
 }
 }
-if (dns-srvrecords[i]-priority) {
-if (virAsprintf(recordPriority, %d, 
dns-srvrecords[i]-priority)  0) {
+
+if (dns-srvrecords[i]-target) {
+if (virAsprintf(target, ,%s,
+dns-srvrecords[i]-target)  0) {
 virReportOOMError();
 goto cleanup;
 }
-}
-if (dns-srvrecords[i]-weight) {
-if (virAsprintf(recordWeight, %d, 
dns-srvrecords[i]-weight)  0) {
+if (virAsprintf(recordPort, ,%d,
+

Re: [libvirt] namespace clean shared libraries

2012-07-08 Thread Bruno Haible
Daniel P. Berrange wrote:
 If its better to just do it in libvirt config.h, then we
 can do that too

Yes, doing '#define foo libvirt_foo' in config.h is the preferred way
of achieving a namespace clean shared library.

There are two ways to generate these #defines:

1) You collect manually, on various systems, the set of symbols that you
   don't want to clash with symbols from other shared libraries. You need
   to do this on various systems, because gnulib may define functions
   'rpl_fflush' or 'dprintf' on some systems and not on others.

2) You collect, from a set of header files, the set of symbols that you
   want to have exported, and process all other symbols with
 '#define foo libvirt_foo'

   This approach is more robust, but requires to compile all *.o files
   twice: Once with the initial settings (no #define), and once for real.

   This approach is implemented in libunistring. Look at the config.h rule
   in this Makefile.am [1]. There are two auxiliary scripts: 'declared.sh' [2]
   extracts the symbols from a .h file (assuming a particular coding style).
   'exported.sh' [3] extracts te symbols of a .o file.

Bruno

[1] 
http://git.savannah.gnu.org/gitweb/?p=libunistring.git;a=blob;f=lib/Makefile.am
[2] 
http://git.savannah.gnu.org/gitweb/?p=libunistring.git;a=blob;f=lib/declared.sh
[3] 
http://git.savannah.gnu.org/gitweb/?p=libunistring.git;a=blob;f=lib/exported.sh.in

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] ESX: Add routines to interface driver

2012-07-08 Thread Ata Bohra
From: Ata E Husain ata.hus...@hotmail.com

Includes most of the dirver routines except DefineXML, I am working on it and 
will update patch for it soon.

diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c
index 5713137..4feadc2 100644
--- a/src/esx/esx_interface_driver.c
+++ b/src/esx/esx_interface_driver.c
@@ -23,6 +23,10 @@
  */

 #include config.h
+#include sys/socket.h
+#include netinet/in.h
+#include arpa/inet.h
+#include libxml/parser.h

 #include internal.h
 #include util.h
@@ -34,10 +38,10 @@
 #include esx_vi.h
 #include esx_vi_methods.h
 #include esx_util.h
+#include interface_conf.h

 #define VIR_FROM_THIS VIR_FROM_ESX
-
-
+#define XML_CAST(const xmlChar*)

 static virDrvOpenStatus
 esxInterfaceOpen(virConnectPtr conn,
@@ -67,10 +71,565 @@ esxInterfaceClose(virConnectPtr conn)



+static int
+esxNumOfInterfaces(virConnectPtr conn)
+{
+esxPrivate *priv = conn-interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+int count = 0;
+
+if (esxVI_EnsureSession(priv-primary)  0 ||
+esxVI_LookupVirtualNicList(priv-primary, virtualNicList)  0) {
+goto cleanup;
+}
+
+if (virtualNicList == NULL) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
+_(Could not retrieve vNic List));
+
+goto cleanup;
+}
+
+for (virtualNic = virtualNicList;
+ virtualNic != NULL;
+ virtualNic = virtualNic-_next) {
+count++;
+}
+
+cleanup:
+esxVI_HostVirtualNic_Free(virtualNicList);
+
+return count;
+}
+
+
+
+static int
+esxNumOfDefinedInterfaces(virConnectPtr conn)
+{
+conn-interfacePrivateData = NULL;
+
+// ESX interfaces are always active
+return 0;
+}
+
+
+
+static int
+esxListInterfaces(virConnectPtr conn, char **names, int maxnames)
+{
+esxPrivate *priv = conn-interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+int result = -1;
+int i = 0;
+
+if (esxVI_EnsureSession(priv-primary)  0 ||
+esxVI_LookupVirtualNicList(priv-primary,
+   virtualNicList)  0) {
+goto cleanup;
+}
+
+if (virtualNicList == NULL) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
+_(Could not retrieve vNIC List));
+goto cleanup;
+}
+
+for (i= 0, virtualNic = virtualNicList;
+ virtualNic != NULL  i  maxnames;
+ ++i, virtualNic = virtualNic-_next) {
+names[i] = strdup(virtualNic-device);
+
+if (names[i] == NULL) {
+for(;i =0;--i) {
+VIR_FREE(names[i]);
+}
+virReportOOMError();
+goto cleanup;
+}
+}
+
+result = i;
+ cleanup:
+esxVI_HostVirtualNic_Free(virtualNicList);
+
+return result;
+}
+
+
+
+static int
+esxListDefinedInterfaces(virConnectPtr conn, char **names, int maxnames)
+{
+conn-interfacePrivateData = NULL;
+*names = NULL;
+
+/* keeps compiler happy */
+VIR_DEBUG(Max Interfaces: %d, maxnames);
+/* ESX interfaces are always active */
+return 0;
+}
+
+
+
+static virInterfacePtr
+esxInterfaceLookupByName(virConnectPtr conn, const char *name)
+{
+esxPrivate *priv = conn-interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+virInterfacePtr ret = NULL;
+
+if (esxVI_EnsureSession(priv-primary)  0 ||
+esxVI_LookupVirtualNicList(priv-primary,
+   virtualNicList)  0) {
+goto cleanup;
+}
+
+if (virtualNicList == 0) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
+_(Could not retrieve vNIC List));
+goto cleanup;
+}
+
+
+for(virtualNic = virtualNicList;
+virtualNic != NULL;
+virtualNic = virtualNic-_next) {
+if (STREQ(virtualNic-device, name)) {
+if (virtualNic-spec == NULL ||
+virtualNic-spec-mac == NULL) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
+  _(Malformed HostVirtualNicSpec));
+goto cleanup;
+}
+
+ret = virGetInterface(conn, virtualNic-device, 
virtualNic-spec-mac);
+break;
+}
+}
+
+ cleanup:
+esxVI_HostVirtualNic_Free(virtualNicList);
+
+return ret;
+}
+
+
+
+static virInterfacePtr
+esxInterfaceLookupByMACString(virConnectPtr conn, const char *mac)
+{
+esxPrivate *priv = conn-interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+virInterfacePtr ret = NULL;
+
+if (esxVI_EnsureSession(priv-primary)  0 ||
+esxVI_LookupVirtualNicList(priv-primary,
+   virtualNicList)  0) {
+goto cleanup;
+}
+
+if (virtualNicList == 0) {
+

Re: [libvirt] [PATCH v2] esx: Extend esxVI_CURL_Download for partial downloads

2012-07-08 Thread Doug Goldstein
On Sun, Jul 8, 2012 at 5:44 AM, Matthias Bolte
matthias.bo...@googlemail.com wrote:
 Also ensure that the virBuffer used to store the downloaded data
 does not overflow.
 ---

 v2:
  - Ensure that the used virBuffer dos not overflow.

  src/esx/esx_driver.c |2 +-
  src/esx/esx_vi.c |   62 +++--
  src/esx/esx_vi.h |3 +-
  3 files changed, 57 insertions(+), 10 deletions(-)

 diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
 index db2144c..95b9286 100644
 --- a/src/esx/esx_driver.c
 +++ b/src/esx/esx_driver.c
 @@ -2802,7 +2802,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int 
 flags)

  url = virBufferContentAndReset(buffer);

 -if (esxVI_CURL_Download(priv-primary-curl, url, vmx)  0) {
 +if (esxVI_CURL_Download(priv-primary-curl, url, vmx, 0, NULL)  0) {
  goto cleanup;
  }

 diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
 index 48718b6..0769e8b 100644
 --- a/src/esx/esx_vi.c
 +++ b/src/esx/esx_vi.c
 @@ -116,9 +116,9 @@ ESX_VI__TEMPLATE__FREE(CURL,
  })

  static size_t
 -esxVI_CURL_ReadString(char *data, size_t size, size_t nmemb, void *ptrptr)
 +esxVI_CURL_ReadString(char *data, size_t size, size_t nmemb, void *userdata)
  {
 -const char *content = *(const char **)ptrptr;
 +const char *content = *(const char **)userdata;
  size_t available = 0;
  size_t requested = size * nmemb;

 @@ -138,16 +138,28 @@ esxVI_CURL_ReadString(char *data, size_t size, size_t 
 nmemb, void *ptrptr)

  memcpy(data, content, requested);

 -*(const char **)ptrptr = content + requested;
 +*(const char **)userdata = content + requested;

  return requested;
  }

  static size_t
 -esxVI_CURL_WriteBuffer(char *data, size_t size, size_t nmemb, void *buffer)
 +esxVI_CURL_WriteBuffer(char *data, size_t size, size_t nmemb, void *userdata)
  {
 +virBufferPtr buffer = userdata;
 +
  if (buffer != NULL) {
 -virBufferAdd((virBufferPtr) buffer, data, size * nmemb);
 +/*
 + * Using a virBuffer to store the download data limits the 
 downloadable
 + * size. This is no problem as esxVI_CURL_Download and 
 esxVI_CURL_Perform
 + * are meant to download small things such as VMX files, VMDK 
 metadata
 + * files and SOAP responses.
 + */
 +if (virBufferUse(buffer)  UINT32_MAX / 2) {
 +return 0;
 +}

This could never be true since the type would have already resulted in
an overflow and therefore would be less than UINT32_MAX / 2 (which is
equivalent to INT32_MAX).  Something like the below would ensure that
you are always within the bounds of your type :

if ((size * nmemb) = (INT32_MAX - virBufferUse(buffer)) {
   virBufferAdd(...)
   return size * nmemb;
}

 +
 +virBufferAdd(buffer, data, size * nmemb);

  return size * nmemb;
  }
 @@ -160,7 +172,7 @@ esxVI_CURL_WriteBuffer(char *data, size_t size, size_t 
 nmemb, void *buffer)
  #if ESX_VI__CURL__ENABLE_DEBUG_OUTPUT
  static int
  esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type,
 - char *info, size_t size, void *data ATTRIBUTE_UNUSED)
 + char *info, size_t size, void *userdata ATTRIBUTE_UNUSED)
  {
  char *buffer = NULL;

 @@ -355,8 +367,10 @@ esxVI_CURL_Connect(esxVI_CURL *curl, esxUtil_ParsedUri 
 *parsedUri)
  }

  int
 -esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content)
 +esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content,
 +unsigned long long offset, unsigned long long *length)
  {
 +char *range = NULL;
  virBuffer buffer = VIR_BUFFER_INITIALIZER;
  int responseCode = 0;

 @@ -365,9 +379,33 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, 
 char **content)
  return -1;
  }

 +if (length != NULL  *length  0) {
 +/*
 + * Using a virBuffer to store the download data limits the 
 downloadable
 + * size. This is no problem as esxVI_CURL_Download is meant to 
 download
 + * small things such as VMX of VMDK metadata files.
 + */
 +if (*length  UINT32_MAX / 2) {

Use INT32_MAX

 +ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
 + _(Download length it too large));
 +return -1;
 +}
 +
 +if (virAsprintf(range, %llu-%llu, offset, offset + *length - 1)  
 0) {
 +virReportOOMError();
 +goto cleanup;
 +}
 +} else if (offset  0) {
 +if (virAsprintf(range, %llu-, offset)  0) {
 +virReportOOMError();
 +goto cleanup;
 +}
 +}
 +
  virMutexLock(curl-lock);

  curl_easy_setopt(curl-handle, CURLOPT_URL, url);
 +curl_easy_setopt(curl-handle, CURLOPT_RANGE, range);
  curl_easy_setopt(curl-handle, CURLOPT_WRITEDATA, buffer);
  curl_easy_setopt(curl-handle, CURLOPT_UPLOAD, 0);
  curl_easy_setopt(curl-handle, 

Re: [libvirt] [PATCH] ESX: Add routines to interface driver

2012-07-08 Thread Daniel Veillard
On Sun, Jul 08, 2012 at 11:36:47AM -0700, Ata Bohra wrote:
 From: Ata E Husain ata.hus...@hotmail.com
 
 Includes most of the dirver routines except DefineXML, I am working on it and 
 will update patch for it soon.

  typo s/dirver/driver/

  I guess you didn't really understand the reason why Doug asked you to
go though git-send-email

That part of the message is what will be recorded permanently in the
git patch database and is supposed to explain why that patch is needed
and how it does it. Comment about future patches are not supposed to
go there, but explanation of why that patch is there, its function.

  I would suggest reading some of the rants from the kernel guys
about why they get grumpy when receiving patches, this can be
educational and even fun at times :-) For example James Bottomley
  https://events.linuxfoundation.org/images/stories/pdf/lcjp2012_bottomley.pdf
around page 17 or one of the presentations from Greg Kroah-Hartman
(but it's better to watch them than read them ;-)

 diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c
 index 5713137..4feadc2 100644
 --- a/src/esx/esx_interface_driver.c
 +++ b/src/esx/esx_interface_driver.c
 @@ -23,6 +23,10 @@
   */
 
  #include config.h
 +#include sys/socket.h
 +#include netinet/in.h
 +#include arpa/inet.h
 +#include libxml/parser.h
 
  #include internal.h
  #include util.h
 @@ -34,10 +38,10 @@
  #include esx_vi.h
  #include esx_vi_methods.h
  #include esx_util.h
 +#include interface_conf.h
 
  #define VIR_FROM_THIS VIR_FROM_ESX
 -
 -
 +#define XML_CAST(const xmlChar*)
 
  static virDrvOpenStatus
  esxInterfaceOpen(virConnectPtr conn,
 @@ -67,10 +71,565 @@ esxInterfaceClose(virConnectPtr conn)
 
 
 
 +static int
 +esxNumOfInterfaces(virConnectPtr conn)
 +{
 +esxPrivate *priv = conn-interfacePrivateData;
 +esxVI_HostVirtualNic *virtualNicList = NULL;
 +const esxVI_HostVirtualNic *virtualNic = NULL;
 +int count = 0;
 +
 +if (esxVI_EnsureSession(priv-primary)  0 ||
 +esxVI_LookupVirtualNicList(priv-primary, virtualNicList)  0) {
 +goto cleanup;
 +}
 +
 +if (virtualNicList == NULL) {
 +ESX_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
 +_(Could not retrieve vNic List));
 +
 +goto cleanup;
 +}
 +
 +for (virtualNic = virtualNicList;
 + virtualNic != NULL;
 + virtualNic = virtualNic-_next) {
 +count++;
 +}
 +
 +cleanup:
 +esxVI_HostVirtualNic_Free(virtualNicList);
 +
 +return count;
 +}
 +
 +
 +
 +static int
 +esxNumOfDefinedInterfaces(virConnectPtr conn)
 +{
 +conn-interfacePrivateData = NULL;
 +
 +// ESX interfaces are always active
 +return 0;
 +}
 +
 +
 +
 +static int
 +esxListInterfaces(virConnectPtr conn, char **names, int maxnames)
 +{
 +esxPrivate *priv = conn-interfacePrivateData;
 +esxVI_HostVirtualNic *virtualNicList = NULL;
 +const esxVI_HostVirtualNic *virtualNic = NULL;
 +int result = -1;
 +int i = 0;
 +
 +if (esxVI_EnsureSession(priv-primary)  0 ||
 +esxVI_LookupVirtualNicList(priv-primary,
 +   virtualNicList)  0) {
 +goto cleanup;
 +}
 +
 +if (virtualNicList == NULL) {
 +ESX_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
 +_(Could not retrieve vNIC List));
 +goto cleanup;
 +}
 +
 +for (i= 0, virtualNic = virtualNicList;
 + virtualNic != NULL  i  maxnames;
 + ++i, virtualNic = virtualNic-_next) {
 +names[i] = strdup(virtualNic-device);
 +
 +if (names[i] == NULL) {
 +for(;i =0;--i) {
 +VIR_FREE(names[i]);
 +}
 +virReportOOMError();
 +goto cleanup;
 +}
 +}
 +
 +result = i;
 + cleanup:
 +esxVI_HostVirtualNic_Free(virtualNicList);
 +
 +return result;
 +}
 +
 +
 +
 +static int
 +esxListDefinedInterfaces(virConnectPtr conn, char **names, int maxnames)
 +{
 +conn-interfacePrivateData = NULL;
 +*names = NULL;
 +
 +/* keeps compiler happy */
 +VIR_DEBUG(Max Interfaces: %d, maxnames);
 +/* ESX interfaces are always active */
 +return 0;
 +}
 +
 +
 +
 +static virInterfacePtr
 +esxInterfaceLookupByName(virConnectPtr conn, const char *name)
 +{
 +esxPrivate *priv = conn-interfacePrivateData;
 +esxVI_HostVirtualNic *virtualNicList = NULL;
 +const esxVI_HostVirtualNic *virtualNic = NULL;
 +virInterfacePtr ret = NULL;
 +
 +if (esxVI_EnsureSession(priv-primary)  0 ||
 +esxVI_LookupVirtualNicList(priv-primary,
 +   virtualNicList)  0) {
 +goto cleanup;
 +}
 +
 +if (virtualNicList == 0) {
 +ESX_ERROR(VIR_ERR_INTERNAL_ERROR, %s,
 +_(Could not retrieve vNIC List));
 +goto cleanup;
 +}
 +
 +
 +for(virtualNic = virtualNicList;
 +virtualNic != NULL;
 +virtualNic = virtualNic-_next) {
 +if 

[libvirt] [PATCH] Add gvir_storage_vol_download() and gvir_sorage_vol_upload()

2012-07-08 Thread Jovanka Gulicoska
From: Jovanka Gulicoska jovanka.gulico...@gmail.com

---
 libvirt-gobject/libvirt-gobject-storage-vol.c |   74 +
 1 file changed, 74 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c 
b/libvirt-gobject/libvirt-gobject-storage-vol.c
index 6f60fcd..5b0647d 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.c
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
@@ -349,3 +349,77 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
 
 return TRUE;
 }
+
+/**
+ * gvir_storage_vol_download:
+ * @vol: the storage volume to download from
+ * @stream: stream to use as output
+ * @offset: position in @vol to start reading from
+ * @length: limit on amount of data to download
+ * @flags: extra flags, not used yet, pass 0
+ *
+ * Returns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_download(GVirStorageVol *vol,
+   GVirStream *stream,
+   unsigned long long offset,
+   unsigned long long length,
+   guint flags,
+   GError **err)
+{
+virStreamPtr st = NULL;
+
+g_object_get(stream, handle, st, NULL);
+
+g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+if(virStorageVolDownload(vol-priv-handle, st, offset, length, 0)  0) {
+   gvir_set_error_literal(err,
+  GVIR_STORAGE_VOL_ERROR,
+  0,
+  Unable to downlaod volume storage);
+
+   return FALSE;
+}
+   
+return TRUE;
+}
+
+/**
+ * gvir_storage_vol_upload:
+ * @vol: the storage volume to upload
+ * @stream: stream to use as input
+ * @offset: position in @vol to start to write to
+ * @length: limit on amount of data to upload
+ * @flags: the flags, not set yet, pass 0
+ *
+ * Retirns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err)
+{
+virStreamPtr st = NULL;
+
+g_object_get(stream, handle, st, NULL);
+
+g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+if(virStorageVolUpload(vol-priv-handle, st, offset, length, 0)  0) {
+   gvir_set_error_literal(err,
+  GVIR_STORAGE_VOL_ERROR,
+  0,
+  Unable to upload to stream);
+  
+   return FALSE;
+}
+
+return TRUE;
+}
-- 
1.7.10.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Add gvir_storage_vol_download and gvir_storgae_vol_upload

2012-07-08 Thread Jovanka Gulicoska
From: Jovanka Gulicoska jovanka.gulico...@gmail.com

---
 libvirt-gobject/libvirt-gobject.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/libvirt-gobject/libvirt-gobject.h 
b/libvirt-gobject/libvirt-gobject.h
index f52cc00..b1158f7 100644
--- a/libvirt-gobject/libvirt-gobject.h
+++ b/libvirt-gobject/libvirt-gobject.h
@@ -44,5 +44,6 @@
 #include libvirt-gobject/libvirt-gobject-storage-pool.h
 #include libvirt-gobject/libvirt-gobject-connection.h
 #include libvirt-gobject/libvirt-gobject-manager.h
+#include libvirt-gobject/libvirt-gobject-stream.h
 
 #endif /* __LIBVIRT_GOBJECT_H__ */
-- 
1.7.10.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Add gvir_storage_vol_download() and gvir_sorage_vol_upload()

2012-07-08 Thread Jovanka Gulicoska
From: Jovanka Gulicoska jovanka.gulico...@gmail.com

---
 libvirt-gobject/libvirt-gobject-storage-vol.c |   74 +
 1 file changed, 74 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c 
b/libvirt-gobject/libvirt-gobject-storage-vol.c
index 6f60fcd..5b0647d 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.c
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
@@ -349,3 +349,77 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
 
 return TRUE;
 }
+
+/**
+ * gvir_storage_vol_download:
+ * @vol: the storage volume to download from
+ * @stream: stream to use as output
+ * @offset: position in @vol to start reading from
+ * @length: limit on amount of data to download
+ * @flags: extra flags, not used yet, pass 0
+ *
+ * Returns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_download(GVirStorageVol *vol,
+   GVirStream *stream,
+   unsigned long long offset,
+   unsigned long long length,
+   guint flags,
+   GError **err)
+{
+virStreamPtr st = NULL;
+
+g_object_get(stream, handle, st, NULL);
+
+g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+if(virStorageVolDownload(vol-priv-handle, st, offset, length, 0)  0) {
+   gvir_set_error_literal(err,
+  GVIR_STORAGE_VOL_ERROR,
+  0,
+  Unable to downlaod volume storage);
+
+   return FALSE;
+}
+   
+return TRUE;
+}
+
+/**
+ * gvir_storage_vol_upload:
+ * @vol: the storage volume to upload
+ * @stream: stream to use as input
+ * @offset: position in @vol to start to write to
+ * @length: limit on amount of data to upload
+ * @flags: the flags, not set yet, pass 0
+ *
+ * Retirns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err)
+{
+virStreamPtr st = NULL;
+
+g_object_get(stream, handle, st, NULL);
+
+g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+if(virStorageVolUpload(vol-priv-handle, st, offset, length, 0)  0) {
+   gvir_set_error_literal(err,
+  GVIR_STORAGE_VOL_ERROR,
+  0,
+  Unable to upload to stream);
+  
+   return FALSE;
+}
+
+return TRUE;
+}
-- 
1.7.10.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Add gvir_storage_vol_download() and gvir_sorage_vol_upload()

2012-07-08 Thread Jovanka Gulicoska
From: Jovanka Gulicoska jovanka.gulico...@gmail.com

---
 libvirt-gobject/libvirt-gobject-storage-vol.c |   74 +
 1 file changed, 74 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c 
b/libvirt-gobject/libvirt-gobject-storage-vol.c
index 6f60fcd..5b0647d 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.c
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
@@ -349,3 +349,77 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
 
 return TRUE;
 }
+
+/**
+ * gvir_storage_vol_download:
+ * @vol: the storage volume to download from
+ * @stream: stream to use as output
+ * @offset: position in @vol to start reading from
+ * @length: limit on amount of data to download
+ * @flags: extra flags, not used yet, pass 0
+ *
+ * Returns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_download(GVirStorageVol *vol,
+   GVirStream *stream,
+   unsigned long long offset,
+   unsigned long long length,
+   guint flags,
+   GError **err)
+{
+virStreamPtr st = NULL;
+
+g_object_get(stream, handle, st, NULL);
+
+g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+if(virStorageVolDownload(vol-priv-handle, st, offset, length, 0)  0) {
+   gvir_set_error_literal(err,
+  GVIR_STORAGE_VOL_ERROR,
+  0,
+  Unable to downlaod volume storage);
+
+   return FALSE;
+}
+   
+return TRUE;
+}
+
+/**
+ * gvir_storage_vol_upload:
+ * @vol: the storage volume to upload
+ * @stream: stream to use as input
+ * @offset: position in @vol to start to write to
+ * @length: limit on amount of data to upload
+ * @flags: the flags, not set yet, pass 0
+ *
+ * Retirns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err)
+{
+virStreamPtr st = NULL;
+
+g_object_get(stream, handle, st, NULL);
+
+g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+if(virStorageVolUpload(vol-priv-handle, st, offset, length, 0)  0) {
+   gvir_set_error_literal(err,
+  GVIR_STORAGE_VOL_ERROR,
+  0,
+  Unable to upload to stream);
+  
+   return FALSE;
+}
+
+return TRUE;
+}
-- 
1.7.10.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Add gvir_storage_vol_download() and gvir_storage_vol_upload() to h file

2012-07-08 Thread Jovanka Gulicoska
From: Jovanka Gulicoska jovanka.gulico...@gmail.com

---
 libvirt-gobject/libvirt-gobject-storage-vol.h |   14 ++
 1 file changed, 14 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h 
b/libvirt-gobject/libvirt-gobject-storage-vol.h
index b425f0a..c6c64c8 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.h
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.h
@@ -110,6 +110,20 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
  guint flags,
  GError **err);
 
+gboolean gvir_storage_vol_download(GVirStorageVol *vol,
+   GVirStream *stream,
+   unsigned long long offset,
+   unsigned long long length,
+   guint flags,
+   GError **err);  
 
+
+gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GOBJECT_STORAGE_VOL_H__ */
-- 
1.7.10.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Release of libvirt-java 0.4.8

2012-07-08 Thread Jason Helfman
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

On Fri, Jul 06, 2012 at 02:20:40PM +0800, Daniel Veillard thus spake:
  I have tagged the git tree and pushed the tarball and rpms at:

 ftp://libvirt.org/libvirt/java/

This release includes the few improvement and fixes made to the java
bindings since the last release last year:

Bug fixes:
Return a byte[] array with secretGetValue (Wido den Hollander)
Fix for the jna parameter passing issue (Daniel Veillard)

Improvements:
Add flags to StoragePoolRefresh (Wido den Hollander)
Allow byte[] arrays to be set as a secretValue (Wido den Hollander)
Added domain flags up to libvirt-0.9.12 (Stefan Majer)
Added error constants up to libvirt-0.9.12 (Stefan Majer)
Add an automated build control script (Daniel P. Berrange)

Documentation:
Fix most of the javadoc reported problems (Daniel Veillard)

Cleanups:
Spaces cleanup and reformating of a few comments (Daniel Veillard)
Cleanup trailing white space issues (Daniel Veillard)


  thanks for the help and contributions :-) !

Daniel


I've committed this new port to FreeBSD this evening. It is available here:

http://www.freshports.org/devel/libvirt-java/

# cd /usr/ports/devel/libvirt-java/  make install clean

Thanks!

- -jgh

- -- 
Jason Helfman
System Administrator
experts-exchange.com
http://www.experts-exchange.com/M_4830110.html
E4AD 7CF1 1396 27F6 79DD  4342 5E92 AD66 8C8C FBA5
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.19 (FreeBSD)

iF4EAREIAAYFAk/6bpMACgkQXpKtZoyM+6VO1QD+L34vHzAww2+sbrjCjZfyzd9S
vQxfIbV7cMlMCQh/XsAA/22RiQPVoDPcTnlDqepAJGENBPuZW48fMSqBU/eujfFT
=LRzu
-END PGP SIGNATURE-

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list