[libvirt] [PATCH] esx: Also allow virtualHW version 4 for ESX 4.0

2010-01-03 Thread Matthias Bolte
A domain with virtualHW version 4 is allowed on an ESX 4.0 server.
If a domain is migrated from an ESX 3.5 server to an ESX 4.0 server
then the virtualHW version stays the same. So a ESX 4.0 server can
host domains with virtualHW version 4.
---
 src/esx/esx_vmx.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
index 9aad592..d3cad1d 100644
--- a/src/esx/esx_vmx.c
+++ b/src/esx/esx_vmx.c
@@ -780,9 +780,9 @@ esxVMX_ParseConfig(virConnectPtr conn, esxVI_Context *ctx, 
const char *vmx,
 break;
 
   case esxVI_APIVersion_40:
-if (virtualHW_version != 7) {
+if (virtualHW_version != 4  virtualHW_version != 7) {
 ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
-  Expecting VMX entry 'virtualHW.version' to be 7 for 
+  Expecting VMX entry 'virtualHW.version' to be 4 or 7 
for 
   VI API version 4.0 but found %lld, virtualHW_version);
 goto failure;
 }
-- 
1.6.0.4

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


[libvirt] [PATCH] Don't free an uninitalized pointer in update_driver_name()

2010-01-03 Thread Matthias Bolte
This invalid free results in heap corruption. Some symptoms I saw
because of this were libvirtd crashing and virt-manager hanging
while trying to enumerate devices.
---
 src/node_device/node_device_driver.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/node_device/node_device_driver.c 
b/src/node_device/node_device_driver.c
index ecbac0f..fbadfca 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -78,7 +78,7 @@ static int update_driver_name(virConnectPtr conn,
   virNodeDeviceObjPtr dev)
 {
 char *driver_link = NULL;
-char *devpath;
+char *devpath = NULL;
 char *p;
 int ret = -1;
 
@@ -114,7 +114,7 @@ static int update_driver_name(virConnectPtr conn,
 
 cleanup:
 VIR_FREE(driver_link);
-free(devpath);
+VIR_FREE(devpath);
 return ret;
 }
 #else
-- 
1.6.0.4

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


[libvirt] [PATCH] esx: Don't warn about an empty URI path

2010-01-03 Thread Matthias Bolte
---
 src/esx/esx_driver.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 5cdadfd..30e21e0 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -293,7 +293,8 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int 
flags ATTRIBUTE_UNUSED)
 return VIR_DRV_OPEN_DECLINED;
 }
 
-if (conn-uri-path != NULL  STRNEQ(conn-uri-path, /)) {
+if (conn-uri-path != NULL  STRNEQ(conn-uri-path, ) 
+STRNEQ(conn-uri-path, /)) {
 VIR_WARN(Ignoring unexpected path '%s' in URI, conn-uri-path);
 }
 
-- 
1.6.0.4

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


[libvirt] [PATCH] esx: Fix and improve the libcurl debug callback

2010-01-03 Thread Matthias Bolte
The data passed to the callback is not guaranteed to be zero terminated,
take care of that by coping the data and adding a zero terminator.

Also dump the data for other types than CURLINFO_TEXT.

Set CURLOPT_VERBOSE to 1 so the debug callback is called when enabled.
---
 src/esx/esx_vi.c |   43 ++-
 1 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index a7498f0..bad987c 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -181,27 +181,50 @@ static int
 esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type,
  char *info, size_t size, void *data ATTRIBUTE_UNUSED)
 {
+char *buffer = NULL;
+
+/*
+ * The libcurl documentation says:
+ *
+ *The data pointed to by the char * passed to this function WILL NOT
+ *be zero terminated, but will be exactly of the size as told by the
+ *size_t argument.
+ *
+ * To handle this properly in order to pass the info string to VIR_DEBUG
+ * a zero terminated copy of the info string has to be allocated.
+ */
+if (VIR_ALLOC_N(buffer, size + 1)  0) {
+return 0;
+}
+
+if (virStrncpy(buffer, info, size, size + 1) == NULL) {
+VIR_FREE(buffer);
+return 0;
+}
+
 switch (type) {
   case CURLINFO_TEXT:
-VIR_DEBUG0(CURLINFO_TEXT);
-fwrite(info, 1, size, stderr);
-printf(\n\n);
+if (size  0  buffer[size - 1] == '\n') {
+buffer[size - 1] = '\0';
+}
+
+VIR_DEBUG(CURLINFO_TEXT %s, buffer);
 break;
 
   case CURLINFO_HEADER_IN:
-VIR_DEBUG0(CURLINFO_HEADER_IN);
+VIR_DEBUG(CURLINFO_HEADER_IN %s, buffer);
 break;
 
   case CURLINFO_HEADER_OUT:
-VIR_DEBUG0(CURLINFO_HEADER_OUT);
+VIR_DEBUG(CURLINFO_HEADER_OUT %s, buffer);
 break;
 
   case CURLINFO_DATA_IN:
-VIR_DEBUG0(CURLINFO_DATA_IN);
+VIR_DEBUG(CURLINFO_DATA_IN %s, buffer);
 break;
 
   case CURLINFO_DATA_OUT:
-VIR_DEBUG0(CURLINFO_DATA_OUT);
+VIR_DEBUG(CURLINFO_DATA_OUT %s, buffer);
 break;
 
   default:
@@ -209,6 +232,8 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype 
type,
 break;
 }
 
+VIR_FREE(buffer);
+
 return 0;
 }
 #endif
@@ -338,8 +363,8 @@ esxVI_Context_Connect(virConnectPtr conn, esxVI_Context 
*ctx, const char *url,
 curl_easy_setopt(ctx-curl_handle, CURLOPT_WRITEFUNCTION,
  esxVI_CURL_WriteBuffer);
 #if ESX_VI__CURL__ENABLE_DEBUG_OUTPUT
-curl_easy_setopt(ctx-curl_handle, CURLOPT_DEBUGFUNCTION,
- esxVI_CURL_Debug);
+curl_easy_setopt(ctx-curl_handle, CURLOPT_DEBUGFUNCTION, 
esxVI_CURL_Debug);
+curl_easy_setopt(ctx-curl_handle, CURLOPT_VERBOSE, 1);
 #endif
 
 if (virMutexInit(ctx-curl_lock)  0) {
-- 
1.6.0.4

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


[libvirt] [PATCH] esx: Fix deserialization for VI API calls CancelTask and UnregisterVM

2010-01-03 Thread Matthias Bolte
---
 src/esx/esx_vi_methods.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c
index be21112..7925f26 100644
--- a/src/esx/esx_vi_methods.c
+++ b/src/esx/esx_vi_methods.c
@@ -601,7 +601,7 @@ esxVI_CancelTask(virConnectPtr conn, esxVI_Context *ctx,
 
 request = virBufferContentAndReset(buffer);
 
-if (esxVI_Context_Execute(conn, ctx, UnregisterVM, request, response,
+if (esxVI_Context_Execute(conn, ctx, CancelTask, request, response,
   esxVI_Occurrence_None)  0) {
 goto failure;
 }
@@ -652,7 +652,7 @@ esxVI_UnregisterVM(virConnectPtr conn, esxVI_Context *ctx,
 
 request = virBufferContentAndReset(buffer);
 
-if (esxVI_Context_Execute(conn, ctx, AnswerVM, request, response,
+if (esxVI_Context_Execute(conn, ctx, UnregisterVM, request, response,
   esxVI_Occurrence_None)  0) {
 goto failure;
 }
-- 
1.6.0.4

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


[libvirt] [PATCH] esx: Fix 'vpx' MAC address range and allow arbitrary MAC addresses

2010-01-03 Thread Matthias Bolte
The MAC addresses with 00:50:56 prefix are split into several ranges:

  00:50:56:00:00:00 - 00:50:56:3f:ff:ff  'static' range (manually assigned)
  00:50:56:80:00:00 - 00:50:56:bf:ff:ff  'vpx' range (assigned by a VI Client)

Erroneously the 'vpx' range was assumed to be larger and to occupy the
remaining addresses of the 00:50:56 prefix that are not part of the 'static'
range.

00:50:56 was used as prefix for generated MAC addresses, this is not possible
anymore, because there are gaps in the allowed ranges. Therefore, change the
prefix to 00:0c:29 which is the prefix for auto generated MAC addresses anyway.

Allow arbitrary MAC addresses to be used and set the checkMACAddress VMX option
to false in case the MAC address doesn't fall into any predefined range.

* docs/drvesx.html.in: update website accordingly
* src/esx/esx_driver.c: set the auto generation prefix to 00:0c:29
* src/esx/esx_vmx.c: fix MAC address range handling and allow arbitrary MAC
  addresses
* tests/vmx2xml*, tests/xml2vmx*: add some basic MAC address range tests
---
 docs/drvesx.html.in  |   74 --
 src/esx/esx_driver.c |2 +-
 src/esx/esx_vmx.c|   49 +--
 tests/vmx2xmldata/vmx2xml-ethernet-generated.vmx |8 +++
 tests/vmx2xmldata/vmx2xml-ethernet-generated.xml |   19 ++
 tests/vmx2xmldata/vmx2xml-ethernet-other.vmx |8 +++
 tests/vmx2xmldata/vmx2xml-ethernet-other.xml |   19 ++
 tests/vmx2xmldata/vmx2xml-ethernet-static.vmx|7 ++
 tests/vmx2xmldata/vmx2xml-ethernet-static.xml|   19 ++
 tests/vmx2xmldata/vmx2xml-ethernet-vpx.vmx   |7 ++
 tests/vmx2xmldata/vmx2xml-ethernet-vpx.xml   |   19 ++
 tests/vmx2xmltest.c  |5 ++
 tests/xml2vmxdata/xml2vmx-ethernet-generated.vmx |   13 
 tests/xml2vmxdata/xml2vmx-ethernet-generated.xml |   14 
 tests/xml2vmxdata/xml2vmx-ethernet-other.vmx |   13 
 tests/xml2vmxdata/xml2vmx-ethernet-other.xml |   14 
 tests/xml2vmxdata/xml2vmx-ethernet-static.vmx|   12 
 tests/xml2vmxdata/xml2vmx-ethernet-static.xml|   14 
 tests/xml2vmxdata/xml2vmx-ethernet-vpx.vmx   |   12 
 tests/xml2vmxdata/xml2vmx-ethernet-vpx.xml   |   14 
 tests/xml2vmxtest.c  |5 ++
 21 files changed, 320 insertions(+), 27 deletions(-)
 create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-generated.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-generated.xml
 create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-other.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-other.xml
 create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-static.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-static.xml
 create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-vpx.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-vpx.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-generated.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-generated.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-other.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-other.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-static.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-static.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-vpx.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-vpx.xml

diff --git a/docs/drvesx.html.in b/docs/drvesx.html.in
index b7909ff..44a144f 100644
--- a/docs/drvesx.html.in
+++ b/docs/drvesx.html.in
@@ -16,8 +16,8 @@
 SOAP based
 a 
href=http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/;
 VMware Virtual Infrastructure API/a (VI API) to communicate with the
-ESX server, like the VMware Virtual Infrastructure Client does. Since
-version 4.0 this API is called
+ESX server, like the VMware Virtual Infrastructure Client (VI client)
+does. Since version 4.0 this API is called
 a 
href=http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/;
 VMware vSphere API/a.
 /p
@@ -159,7 +159,7 @@ type://[usern...@]hostname[:port]/[?extraparameters]
 There are several specialties in the domain XML config for ESX domains.
 /p
 
-h3Restrictions/h3
+h3a name=restrictionsRestrictions/h3
 p
 There are some restrictions for some values of the domain XML config.
 The driver will complain if this restrictions are violated.
@@ -173,12 +173,13 @@ type://[usern...@]hostname[:port]/[?extraparameters]
 /li
 li
 Valid MAC address prefixes are code00:0c:29/code and
-code00:50:56/code
+code00:50:56/code. span class=sinceSince 0.7.6/span
+arbitrary a href=#macaddressesMAC addresses/a are supported.
 /li
 /ul
 
 
-h3Datastore references/h3
+   

[libvirt] [PATCH] virsh: Use VIR_FREE instead of free

2010-01-03 Thread Matthias Bolte
virsh uses other parts of the internal API already, so use VIR_FREE also.
---
 tools/virsh.c |  297 -
 1 files changed, 146 insertions(+), 151 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index e2a32b4..2844927 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -46,6 +46,7 @@
 #include buf.h
 #include console.h
 #include util.h
+#include memory.h
 
 static char *progname;
 
@@ -481,7 +482,7 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
 ctl-conn = NULL;
 }
 
-free(ctl-name);
+VIR_FREE(ctl-name);
 ctl-name = vshStrdup(ctl, vshCommandOptString(cmd, name, NULL));
 
 if (!ro) {
@@ -560,7 +561,7 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom)
 xml = xmlReadDoc((const xmlChar *) doc, domain.xml, NULL,
  XML_PARSE_NOENT | XML_PARSE_NONET |
  XML_PARSE_NOWARNING);
-free(doc);
+VIR_FREE(doc);
 if (!xml)
 goto cleanup;
 ctxt = xmlXPathNewContext(xml);
@@ -583,8 +584,8 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom)
 xmlXPathFreeContext(ctxt);
 if (xml)
 xmlFreeDoc(xml);
-free(thisHost);
-free(thatHost);
+VIR_FREE(thisHost);
+VIR_FREE(thatHost);
 
 return ret;
 }
@@ -651,7 +652,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
 if ((maxid = virConnectListDomains(ctl-conn, ids[0], maxid))  
0) {
 vshError(ctl, %s, _(Failed to list active domains));
-free(ids);
+VIR_FREE(ids);
 return FALSE;
 }
 
@@ -662,7 +663,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 maxname = virConnectNumOfDefinedDomains(ctl-conn);
 if (maxname  0) {
 vshError(ctl, %s, _(Failed to list inactive domains));
-free(ids);
+VIR_FREE(ids);
 return FALSE;
 }
 if (maxname) {
@@ -670,8 +671,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
 if ((maxname = virConnectListDefinedDomains(ctl-conn, names, 
maxname))  0) {
 vshError(ctl, %s, _(Failed to list inactive domains));
-free(ids);
-free(names);
+VIR_FREE(ids);
+VIR_FREE(names);
 return FALSE;
 }
 
@@ -708,7 +709,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
 /* this kind of work with domains is not atomic operation */
 if (!dom) {
-free(names[i]);
+VIR_FREE(names[i]);
 continue;
 }
 
@@ -720,10 +721,10 @@ cmdList(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 vshPrint(ctl, %3s %-20s %s\n, -, names[i], state);
 
 virDomainFree(dom);
-free(names[i]);
+VIR_FREE(names[i]);
 }
-free(ids);
-free(names);
+VIR_FREE(ids);
+VIR_FREE(names);
 return TRUE;
 }
 
@@ -1019,7 +1020,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
 return FALSE;
 
 dom = virDomainCreateXML(ctl-conn, buffer, 0);
-free (buffer);
+VIR_FREE(buffer);
 
 if (dom != NULL) {
 vshPrint(ctl, _(Domain %s created from %s\n),
@@ -1070,7 +1071,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd)
 return FALSE;
 
 dom = virDomainDefineXML(ctl-conn, buffer);
-free (buffer);
+VIR_FREE(buffer);
 
 if (dom != NULL) {
 vshPrint(ctl, _(Domain %s defined from %s\n),
@@ -1371,7 +1372,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
 if (schedulertype!= NULL){
 vshPrint(ctl, %-15s: %s\n, _(Scheduler),
  schedulertype);
-free(schedulertype);
+VIR_FREE(schedulertype);
 } else {
 vshPrint(ctl, %-15s: %s\n, _(Scheduler), _(Unknown));
 goto cleanup;
@@ -1436,7 +1437,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
 }
 
  cleanup:
-free(params);
+VIR_FREE(params);
 virDomainFree(dom);
 return ret_val;
 }
@@ -1724,7 +1725,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
 
 if ((str = virDomainGetOSType(dom))) {
 vshPrint(ctl, %-15s %s\n, _(OS Type:), str);
-free(str);
+VIR_FREE(str);
 }
 
 if (virDomainGetInfo(dom, info) == 0) {
@@ -1912,8 +1913,8 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
 ret = FALSE;
 }
 
-free(cpumap);
-free(cpuinfo);
+VIR_FREE(cpumap);
+VIR_FREE(cpuinfo);
 virDomainFree(dom);
 return ret;
 }
@@ -2037,7 +2038,7 @@ cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
 VIR_USE_CPU(cpumap, cpu);
 } else {
 vshError(ctl, _(Physical CPU %d doesn't exist.), cpu);
-free(cpumap);
+VIR_FREE(cpumap);
 virDomainFree(dom);
 return FALSE;
 }
@@ -2050,7 +2051,7 @@ cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
 ret = FALSE;
 }
 
-

Re: [libvirt] [PATCH] virsh: Add persistent history using libreadline

2010-01-03 Thread Laine Stump

On 01/03/2010 02:42 PM, Matthias Bolte wrote:

+if (virAsprintf(ctl-historyfile, %s/histroy, ctl-historydir)  0) {
   


A minor typo in the format string ;-)

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


Re: [libvirt] [PATCH] virsh: Add persistent history using libreadline

2010-01-03 Thread Matthias Bolte
2010/1/3 Laine Stump la...@laine.org:
 On 01/03/2010 02:42 PM, Matthias Bolte wrote:

 +    if (virAsprintf(ctl-historyfile, %s/histroy, ctl-historydir)
  0) {


 A minor typo in the format string ;-)


Fixed, thanks.

Matthias

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

[libvirt] FIrst approximation of creating volumes directly with desired uid

2010-01-03 Thread Laine Stump
|I've made an attempt to create storage volumes directly with the 
desired uid/gid (by forking a new process, calling setuid/setgid in that 
process, and then creating the file). Since it's sure to get ripped 
apart, I've put it up on gitorious rather than sending patches to the list.


The repository is:

git://gitorious.org/~laine/libvirt/laine-staging.git 
git://gitorious.org/%7Elaine/libvirt/laine-staging.git


and the branch is (in a quite non-sequiter fashion) xml2xmltest

Only the last 3 commits on the branch are related to this topic.

The first adds uid and gid args to virRun (and all related functions) so 
that new processes can be run as a different user. This is necessary for 
the cases where we call an external program to create the image 
(qemu-img, for example).


The second commit adds two new functions to util.c: virFileCreate and 
virDirCreate. In the case that the current process is running as root, 
and the caller has requested a different uid or gid for the new 
file/directory, these functions do the proper fork dance to get this 
done and return proper status to the caller.


The third commit uses the enhanced virRun, and the two new functions to 
change the way that storage volumes are created.


I've noted some of my concerns about doing things this way in a bugzilla 
report about the problem I'm trying to fix:


https://bugzilla.redhat.com/show_bug.cgi?id=547543


|

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