[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
[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
[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
[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
Re: [libvirt] [PATCH 10/21] Don't let parent of daemon exit until basic initialization is done
by Laurent Léonard
Hi,
I'm not a C expert, but I see there is a use of an unitialized variable:
default:
{
int got, exitstatus = 0;
int ret;
char status;
close(statuspipe[1]);
/* We wait to make sure the first child forked successfully */
if ((got = waitpid(pid, &exitstatus, 0)) < 0 ||
got != pid ||
status != 0) { <<< here
return -1;
}
That explains the issue described by Guido, because he uses an i386 system. It
was impossible for me to reproduce the issue because I use an amd64 system.
char test;
if (test == 0)
puts("ok");
else
puts("ko");
produces:
- "ok" on amd64 system
- "ko" on i386 system
If I use the exitstatus variable in the test it seems to work great on both
architectures.
--
Laurent Léonard
15 years
[libvirt] [PATCH] network utilities
by Daniel Veillard
Revamping my previous patches to parse IPv4/6 numeric addresses,
adding range computation and netmask checking entries too.
As suggested I used an union for the socket address type:
typedef union {
struct sockaddr_storage stor;
struct sockaddr_in inet4;
struct sockaddr_in6 inet6;
} virSocketAddr;
typedef virSocketAddr *virSocketAddrPtr;
But I wonder if it's not better to make it a struct and add
the lenght of the address as this is usually needed when passing
one of the struct sockaddr_* and that lenght is returned as part
of parsing, keeping both together is probably more useful.
A macro to get the type AF_INET/AF_INET6 out of a virSocketAddr
might be useful instead of having the users manually guess that
->stor.ss_family is teh filed to look at.
Also I wonder how useful the Ipv6 code for netmask and ranges
really is, it seems that IPv6 mostly go with prefix and never use
netmasks, maybe that's just dead code, maybe that's just wrong,
anyway here it is.
I named the header and file network.[ch] as I think other
network related utilities like validation or generation of
MAC addresses could well be moved in that file too.
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
15 years
[libvirt] [PATCH] Fix up a bogus TLS message.
by Chris Lalancette
When working with the TLS transport, I noticed that every single time
a remote stream was closed, I would get a message like:
09:09:40.793: error : remoteIOReadBuffer:7328 : failed to read from TLS socket A TLS packet with unexpected length was received.
libvir: QEMU error : failed to read from TLS socket A TLS packet with unexpected length was received.
in the logs. This happens because of a race in libvirtd; one thread
handles the doRemoteClose(), which calls gnutls_bye() followed by close()
while another thread is poll()'ing on the same fd. Once the close()
happens, the poll returns with revents set to POLLIN, and we would poll
one more time for data from the now-closed fd. Fix this situation by
setting poll->session to NULL when we clean up, and check for that in
remoteIOHandleInput().
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/remote/remote_driver.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index bf001eb..335f44b 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1389,6 +1389,7 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv)
if (priv->uses_tls && priv->session) {
gnutls_bye (priv->session, GNUTLS_SHUT_RDWR);
gnutls_deinit (priv->session);
+ priv->session = NULL;
}
#if HAVE_SASL
if (priv->saslconn)
@@ -7223,6 +7224,12 @@ remoteIOReadBuffer(virConnectPtr conn,
int ret;
if (priv->uses_tls) {
+ if (!priv->session) {
+ /* we may have reached here one more time after gnutls_bye()
+ * was called, so just return here
+ */
+ return 0;
+ }
tls_resend:
ret = gnutls_record_recv (priv->session, bytes, len);
if (ret == GNUTLS_E_INTERRUPTED)
--
1.6.0.6
15 years
[libvirt] Restore after restart libvirtd
by Diego Woitasen
Hi,
I 'm playing with save/restore domains. It's working, but if I
restart libvirtd after 'save domain file' and then try to restore it I
get:
error: Failed to restore domain from /tmp/domain.out
error: operation failed: domain 'domainname' is already defined with
uuid 17c77406-b6e3-621a-1fae-420affce8f48
If I move domainname.xml out of libvirt config. directory it works,
but I think this should not be necessary.
Regards,
Diego
--
Diego Woitasen
15 years