[libvirt] [PATCH] Allow NULL mac address in virGetInterface.
by Laine Stump
There are places where an interface will not have a mac address, and netcf
returns this as a NULL pointer rather than a pointer to an empty string.
Rather than checking for this all over the place in libvirt, just save it
in the virInterface object as an empty string.
---
src/datatypes.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/src/datatypes.c b/src/datatypes.c
index 89ad309..ecefc59 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -588,10 +588,15 @@ virInterfacePtr
virGetInterface(virConnectPtr conn, const char *name, const char *mac) {
virInterfacePtr ret = NULL;
- if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (mac == NULL)) {
+ if ((!VIR_IS_CONNECT(conn)) || (name == NULL)) {
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(NULL);
}
+
+ /* a NULL mac from caller is okay. Treat it as blank */
+ if (mac == NULL)
+ mac = "";
+
virMutexLock(&conn->lock);
ret = (virInterfacePtr) virHashLookup(conn->interfaces, name);
--
1.6.5.15.gc274d
15 years, 1 month
[libvirt] [PATCH] Remove redundant virFileDeletePID() call
by Chris Lalancette
qemudShutdownVMDaemon() calls qemudRemoveDomainStatus(), which
then calls virFileDeletePID(). qemudShutdownVMDaemon() then
unnecessarily calls virFileDeletePID() again. Remove this second
usage of it, and also slightly refactor qemudRemoveDomainStatus()
to VIR_WARN appropriate error messages.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/qemu/qemu_driver.c | 31 +++++++++----------------------
1 files changed, 9 insertions(+), 22 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fd064af..38fe19e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -269,7 +269,7 @@ qemudRemoveDomainStatus(virConnectPtr conn,
struct qemud_driver *driver,
virDomainObjPtr vm)
{
- int rc = -1;
+ char ebuf[1024];
char *file = NULL;
if (virAsprintf(&file, "%s/%s.xml", driver->stateDir, vm->def->name) < 0) {
@@ -277,19 +277,14 @@ qemudRemoveDomainStatus(virConnectPtr conn,
goto cleanup;
}
- if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR) {
- qemudReportError(conn, vm, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Failed to unlink status file %s"), file);
- goto cleanup;
- }
-
- if(virFileDeletePid(driver->stateDir, vm->def->name))
- goto cleanup;
+ if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
+ VIR_WARN(_("Failed to remove domain XML for %s: %s"),
+ vm->def->name, virStrerror(errno, buf, sizeof(ebuf)));
+ if (virFileDeletePid(driver->stateDir, vm->def->name) != 0)
+ VIR_WARN(_("Failed to remove PID file for %s: %s"),
+ vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
- rc = 0;
-cleanup:
- VIR_FREE(file);
- return rc;
+ return 0;
}
@@ -2224,15 +2219,7 @@ retry:
vm->def->name);
}
- if (qemudRemoveDomainStatus(conn, driver, vm) < 0) {
- VIR_WARN(_("Failed to remove domain status for %s"),
- vm->def->name);
- }
- if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
- char ebuf[1024];
- VIR_WARN(_("Failed to remove PID file for %s: %s"),
- vm->def->name, virStrerror(errno, ebuf, sizeof ebuf));
- }
+ qemudRemoveDomainStatus(conn, driver, vm);
vm->pid = -1;
vm->def->id = -1;
--
1.6.0.6
15 years, 1 month
[libvirt] [PATCH 00/21] Rewrite the QEMU monitor handling
by Daniel P. Berrange
This patch series rewrites the QEMU monitor handling almost completely.
The key theme here is to move from a totally synchronous way of
interacting with the monitor, to a totally asynchronous way. This
allows us to handle receipt & dispatch of asychronous events from
QEMU. For example a notification of a disk-full error, or VM state
change. In the process of doing this re-factoring I have also
dropped in basic support/infrastructure for the JSON based monitor.
The basic JSON parsing/formatting is working, but this needs to
wait until QEMU community finalize their monitor syntax for the
new commands & what args they accept.
Daniel
15 years, 1 month
[libvirt] cannot get virt-manager to see VM
by Gerry Reno
I used qemu-img to create a raw image. I then create an xml file with
no uuid but a new name and new mac address. Then I did a 'virsh define
NEW.img'. When I do a 'virsh list --all' the new VM is there but
shut_off. But this new machine does not appear in virt-manager. What
do I need to do to get the new machine to appear in the list of machines
in virt-manager? I want to start this machine using virt-manager. This
is on F11 with libvirt 0.6.2.
-Gerry
15 years, 1 month
[libvirt] [PATCH] ESX: Don't automatically follow redirects.
by Matthias Bolte
The default transport for the VI API is HTTPS. If the server redirects
from HTTPS to HTTP the driver would silently follow that redirection.
The user assumes to communicate with the server over a secure transport
but isn't.
This patch disables automatical redirection following. The driver reports
an error if the server tries to redirect.
* src/esx/esx_vi.c: refactor the call to curl_easy_perform() into a
function and do error handling there, disable automatical redirection
following for curl
* src/esx/esx_vi.h: change the type of responseCode to int
---
src/esx/esx_vi.c | 166 +++++++++++++++++++++++++++---------------------------
src/esx/esx_vi.h | 2 +-
2 files changed, 84 insertions(+), 84 deletions(-)
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index dc51e20..bcf110f 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -216,6 +216,68 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type,
}
#endif
+static int
+esxVI_CURL_Perform(virConnectPtr conn, esxVI_Context *ctx, const char *url)
+{
+ CURLcode errorCode;
+ long responseCode = 0;
+#if LIBCURL_VERSION_NUM >= 0x071202 /* 7.18.2 */
+ const char *redirectUrl = NULL;
+#endif
+
+ errorCode = curl_easy_perform(ctx->curl_handle);
+
+ if (errorCode != CURLE_OK) {
+ ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+ "curl_easy_perform() returned an error: %s (%d)",
+ curl_easy_strerror(errorCode), errorCode);
+ return -1;
+ }
+
+ errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_RESPONSE_CODE,
+ &responseCode);
+
+ if (errorCode != CURLE_OK) {
+ ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+ "curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned an "
+ "error: %s (%d)", curl_easy_strerror(errorCode),
+ errorCode);
+ return -1;
+ }
+
+ if (responseCode < 0) {
+ ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+ "curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned a "
+ "negative response code");
+ return -1;
+ }
+
+ if (responseCode == 301) {
+#if LIBCURL_VERSION_NUM >= 0x071202 /* 7.18.2 */
+ errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_REDIRECT_URL,
+ &redirectUrl);
+
+ if (errorCode != CURLE_OK) {
+ ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+ "curl_easy_getinfo(CURLINFO_REDIRECT_URL) returned "
+ "an error: %s (%d)", curl_easy_strerror(errorCode),
+ errorCode);
+ } else {
+ ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+ "The server redirects from '%s' to '%s'", url,
+ redirectUrl);
+ }
+#else
+ ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+ "The server redirects from '%s'", url);
+#endif
+
+ return -1;
+ }
+
+ return responseCode;
+}
+
int
esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx, const char *url,
const char *ipAddress, const char *username,
@@ -269,7 +331,7 @@ esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx, const char *url,
curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, ctx->url);
curl_easy_setopt(ctx->curl_handle, CURLOPT_USERAGENT, "libvirt-esx");
curl_easy_setopt(ctx->curl_handle, CURLOPT_HEADER, 0);
- curl_easy_setopt(ctx->curl_handle, CURLOPT_FOLLOWLOCATION, 1);
+ curl_easy_setopt(ctx->curl_handle, CURLOPT_FOLLOWLOCATION, 0);
curl_easy_setopt(ctx->curl_handle, CURLOPT_SSL_VERIFYPEER, noVerify ? 0 : 1);
curl_easy_setopt(ctx->curl_handle, CURLOPT_SSL_VERIFYHOST, noVerify ? 0 : 2);
curl_easy_setopt(ctx->curl_handle, CURLOPT_COOKIEFILE, "");
@@ -433,8 +495,7 @@ esxVI_Context_DownloadFile(virConnectPtr conn, esxVI_Context *ctx,
const char *url, char **content)
{
virBuffer buffer = VIR_BUFFER_INITIALIZER;
- CURLcode errorCode;
- long responseCode;
+ int responseCode = 0;
if (content == NULL || *content != NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
@@ -448,27 +509,19 @@ esxVI_Context_DownloadFile(virConnectPtr conn, esxVI_Context *ctx,
curl_easy_setopt(ctx->curl_handle, CURLOPT_UPLOAD, 0);
curl_easy_setopt(ctx->curl_handle, CURLOPT_HTTPGET, 1);
- errorCode = curl_easy_perform(ctx->curl_handle);
-
- if (errorCode != CURLE_OK) {
- ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
- "curl_easy_perform() returned an error: %s (%d)",
- curl_easy_strerror(errorCode), errorCode);
- goto unlock;
- }
+ responseCode = esxVI_CURL_Perform(conn, ctx, url);
- errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_RESPONSE_CODE,
- &responseCode);
+ virMutexUnlock(&ctx->curl_lock);
- if (errorCode != CURLE_OK) {
+ if (responseCode < 0) {
+ goto failure;
+ } else if (responseCode != 200) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
- "curl_easy_getinfo() returned an error: %s (%d)",
- curl_easy_strerror(errorCode), errorCode);
- goto unlock;
+ "HTTP response code %d while trying to download '%s'",
+ responseCode, url);
+ goto failure;
}
- virMutexUnlock(&ctx->curl_lock);
-
if (virBufferError(&buffer)) {
virReportOOMError(conn);
goto failure;
@@ -476,32 +529,19 @@ esxVI_Context_DownloadFile(virConnectPtr conn, esxVI_Context *ctx,
*content = virBufferContentAndReset(&buffer);
- if (responseCode != 200) {
- ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
- "HTTP response code %d while trying to download '%s'",
- (int)responseCode, url);
- goto failure;
- }
-
return 0;
failure:
free(virBufferContentAndReset(&buffer));
return -1;
-
- unlock:
- virMutexUnlock(&ctx->curl_lock);
-
- goto failure;
}
int
esxVI_Context_UploadFile(virConnectPtr conn, esxVI_Context *ctx,
const char *url, const char *content)
{
- CURLcode errorCode;
- long responseCode;
+ int responseCode = 0;
if (content == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
@@ -515,40 +555,20 @@ esxVI_Context_UploadFile(virConnectPtr conn, esxVI_Context *ctx,
curl_easy_setopt(ctx->curl_handle, CURLOPT_UPLOAD, 1);
curl_easy_setopt(ctx->curl_handle, CURLOPT_INFILESIZE, strlen(content));
- errorCode = curl_easy_perform(ctx->curl_handle);
-
- if (errorCode != CURLE_OK) {
- ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
- "curl_easy_perform() returned an error: %s (%d)",
- curl_easy_strerror(errorCode), errorCode);
- goto unlock;
- }
-
- errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_RESPONSE_CODE,
- &responseCode);
-
- if (errorCode != CURLE_OK) {
- ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
- "curl_easy_getinfo() returned an error: %s (%d)",
- curl_easy_strerror(errorCode), errorCode);
- goto unlock;
- }
+ responseCode = esxVI_CURL_Perform(conn, ctx, url);
virMutexUnlock(&ctx->curl_lock);
- if (responseCode != 200 && responseCode != 201) {
+ if (responseCode < 0) {
+ return -1;
+ } else if (responseCode != 200 && responseCode != 201) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"HTTP response code %d while trying to upload to '%s'",
- (int)responseCode, url);
+ responseCode, url);
return -1;
}
return 0;
-
- unlock:
- virMutexUnlock(&ctx->curl_lock);
-
- return -1;
}
int
@@ -558,7 +578,6 @@ esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
{
virBuffer buffer = VIR_BUFFER_INITIALIZER;
esxVI_Fault *fault = NULL;
- CURLcode errorCode;
if (request == NULL || response == NULL || *response != NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
@@ -577,27 +596,14 @@ esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDS, request);
curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDSIZE, strlen(request));
- errorCode = curl_easy_perform(ctx->curl_handle);
-
- if (errorCode != CURLE_OK) {
- ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
- "curl_easy_perform() returned an error: %s (%d)",
- curl_easy_strerror(errorCode), errorCode);
- goto unlock;
- }
+ (*response)->responseCode = esxVI_CURL_Perform(conn, ctx, ctx->url);
- errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_RESPONSE_CODE,
- &(*response)->responseCode);
+ virMutexUnlock(&ctx->curl_lock);
- if (errorCode != CURLE_OK) {
- ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
- "curl_easy_getinfo() returned an error: %s (%d)",
- curl_easy_strerror(errorCode), errorCode);
- goto unlock;
+ if ((*response)->responseCode < 0) {
+ goto failure;
}
- virMutexUnlock(&ctx->curl_lock);
-
if (virBufferError(&buffer)) {
virReportOOMError(conn);
goto failure;
@@ -695,8 +701,7 @@ esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
}
} else if ((*response)->responseCode != 200) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
- "HTTP response code %d", (int)(*response)->responseCode);
-
+ "HTTP response code %d", (*response)->responseCode);
goto failure;
}
@@ -708,11 +713,6 @@ esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
esxVI_Fault_Free(&fault);
return -1;
-
- unlock:
- virMutexUnlock(&ctx->curl_lock);
-
- goto failure;
}
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index 4892fde..4b3005e 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -110,7 +110,7 @@ int esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
*/
struct _esxVI_Response {
- long responseCode; /* required */
+ int responseCode; /* required */
char *content; /* required */
xmlDocPtr document; /* optional */
xmlXPathContextPtr xpathContext; /* optional */
--
1.6.0.4
15 years, 1 month
[libvirt] [patch] Add openvzDomainSetMemoryInternal
by Yuji NISHIDA
Hi all,
This patch is to set KMEMSIZE for OpenVZ.
This function is used for initializing the parameter of KMEMSIZE to
start container.
openvzDomainSetMemory should be left for another purpose so I added
new one.
I think users should specify memory as kbyte ( or bigger ).
---
src/openvz/openvz_driver.c | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index f64ad1e..5c1fefa 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -69,6 +69,7 @@ static int openvzGetMaxVCPUs(virConnectPtr conn,
const char *type);
static int openvzDomainGetMaxVcpus(virDomainPtr dom);
static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int
nvcpus);
static int openvzDomainSetVcpusInternal(virConnectPtr conn,
virDomainObjPtr vm, unsigned int nvcpus);
+static int openvzDomainSetMemoryInternal(virConnectPtr conn,
virDomainObjPtr vm, unsigned long memory);
static void openvzDriverLock(struct openvz_driver *driver)
{
@@ -803,6 +804,14 @@ openvzDomainDefineXML(virConnectPtr conn, const
char *xml)
}
}
+ if (vm->def->memory > 0) {
+ if (openvzDomainSetMemoryInternal(conn, vm, vm->def->memory)
< 0) {
+ openvzError(conn, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("Could not set memory size"));
+ goto cleanup;
+ }
+ }
+
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
if (dom)
dom->id = -1;
@@ -1364,6 +1373,29 @@ static int openvzNumDefinedDomains
(virConnectPtr conn) {
return ninactive;
}
+static int openvzDomainSetMemoryInternal(virConnectPtr conn,
virDomainObjPtr vm,
+ unsigned long mem) {
+ struct openvz_driver *driver = conn->privateData;
+ char str_mem[16];
+ const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,
+ "--kmemsize", str_mem, "--save", NULL };
+
+ /* memory has to be changed its format from kbyte to byte */
+ snprintf( str_mem, sizeof(str_mem), "%lu", mem * 1024 );
+
+ openvzSetProgramSentinal(prog, vm->def->name);
+ if (virRun(conn, prog, NULL) < 0) {
+ openvzError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("Could not exec %s"), VZCTL);
+ goto cleanup;
+ }
+
+ return 0;
+
+cleanup:
+ return -1;
+}
+
static virDriver openvzDriver = {
VIR_DRV_OPENVZ,
"OPENVZ",
--
1.5.3.4
-----
Yuji Nishida
nishidy(a)nict.go.jp
15 years, 1 month
[libvirt] Remaining interface state reporting issue - bond options
by Laine Stump
With the patches I sent to netcf-devel last night, along with lutter's
(or DV's, take your pick ;-) netcf patch to eliminate the segfault, my
patches for reporting interface info now pass make check with no errors.
I believe lutter will be making a netcf release tomorrow or so, after he
gets back on solid ground.
There is one issue left that I'm unsure what to do about - while the xml
returned from netcf for bond interfaces does list all the slave
interfaces of the bond and their types (and any required info for that
type), the parser for bond info in libvirt requires either an miimon or
arpmode node inside the bond, eg:
<interface type="bond" name="bond0">
<bond>
<miimon freq="100" updelay="10" carrier="ioctl"/>
<interface type="ethernet" name="eth1"/>
<interface type="ethernet" name="eth0"/>
</bond>
</interface>
I haven't been able to find a source of this information yet and, while
it may be useful, I don't see it as necessary. Once again I'm proposing
that we make these optional in the XML, such that this would be acceptable:
<interface type="bond" name="bond0">
<bond>
<interface type="ethernet" name="eth1"/>
<interface type="ethernet" name="eth0"/>
</bond>
</interface>
Once we do that, the netcf-reported state of all 4 supported interface
types (ethernet, bridge, vlan, bond) will pass libvirt's parsing test.
15 years, 1 month
[libvirt] Add support for qemu's guestfwd
by Matthew Booth
This series adds support for a vmchannel using qemu's guestfwd. I'll be
following up with support for virtio-serial and RHEL5's vmchannel.
A vmchannel is specified as:
<vmchannel type='pipe'>
<source path='/tmp/vmchannel'/>
<target type='guestfwd' address='10.0.2.1' port='4600'/>
</vmchannel>
There are a couple of minor complications. Firstly, the existing chrdev
structure assumes that all front-ends take only a port. There's a bit of code
churn adding a second union to this struct to allow for different data for
different backends.
Secondly, it turns out that the existing syntax for character devices doesn't
really work for guestfwd. Specifically it won't allow common options to be
added. This is fixed in qemu git with the new -chardev syntax. Consequently,
this patch only adds support for guestfwd using -chardev. We add detection for
-chardev, and a new internal utility function to output -chardev command lines
for all existing character device backends.
Matt
15 years, 1 month