[libvirt] [PATCH 1/2] Implementation deficiency in virInitctlSetRunLevel v4
by Reco
Implement virProcessRunInMountNamespace, which runs callback of type
virProcessNamespaceCallback in a container namespace.
Hope it'll nail it this time.
---
src/libvirt_private.syms | 1 +
src/util/virprocess.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++
src/util/virprocess.h | 6 +++++
3 files changed, 70 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2dbb8f8..e210fd0 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1646,6 +1646,7 @@ virProcessGetNamespaces;
virProcessGetStartTime;
virProcessKill;
virProcessKillPainfully;
+virProcessRunInMountNamespace;
virProcessSetAffinity;
virProcessSetMaxFiles;
virProcessSetMaxMemLock;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 9fc3207..7bb494e 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -31,6 +31,7 @@
# include <sys/resource.h>
#endif
#include <sched.h>
+#include <stdlib.h>
#ifdef __FreeBSD__
# include <sys/param.h>
@@ -847,3 +848,65 @@ int virProcessGetStartTime(pid_t pid,
return 0;
}
#endif
+
+#ifdef HAVE_SETNS
+int virProcessRunInMountNamespace(pid_t pid,
+ virProcessNamespaceCallback cb,
+ void *opaque)
+{
+ char* path = NULL;
+ int ret = -1;
+ int cpid = -1;
+ int status = -1;
+ int fd = -1;
+
+ if (virAsprintf(&path, "/proc/%llu/ns/mnt",
+ (unsigned long long)pid) < 0) {
+ goto cleanup;
+ }
+
+ if ((fd = open(path, O_RDONLY)) < 0) {
+ virReportSystemError(errno, "%s",
+ _("Kernel does not provide mount namespace"));
+ goto cleanup;
+ }
+
+ switch (cpid = fork()) {
+ case 0:
+ if (setns(fd, 0) == -1) {
+ _exit(-1);
+ }
+
+ ret = cb(pid, opaque);
+ _exit(ret);
+ break;
+ case -1:
+ virReportSystemError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Fork failed"));
+ goto cleanup;
+ default:
+ if (virProcessWait(cpid, &status) < 0 || status < 0) {
+ virReportSystemError(errno,
+ _("Callback failed with status %i"),
+ status);
+ ret = 1;
+ } else {
+ ret = 0;
+ }
+ }
+
+cleanup:
+ VIR_FREE(path);
+ VIR_FORCE_CLOSE(fd);
+ return ret;
+}
+#else
+int virProcessRunInMountNamespace(pid_t pid ATTRIBUTE_UNUSED,
+ virProcessNamespaceCallback cb ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Mount namespaces are not available on this platform"));
+ return -1;
+}
+#endif
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
index 9f77bc5..205abf7 100644
--- a/src/util/virprocess.h
+++ b/src/util/virprocess.h
@@ -60,4 +60,10 @@ int virProcessSetNamespaces(size_t nfdlist,
int virProcessSetMaxMemLock(pid_t pid, unsigned long long bytes);
int virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
int virProcessSetMaxFiles(pid_t pid, unsigned int files);
+
+typedef int (*virProcessNamespaceCallback)(pid_t pid, void *opaque);
+
+int virProcessRunInMountNamespace(pid_t pid,
+ virProcessNamespaceCallback cb,
+ void *opaque);
#endif /* __VIR_PROCESS_H__ */
--
1.7.10.4
10 years, 11 months
[libvirt] [PATCHv6 0/3] Implement RBD storage pool support
by Adam Walters
Here is a re-based re-submission of my patches to implement RBD storage pool support for QEMU domains. Nothing in it has changed other than it has been rebased against the latest. The race condition I located still exists, but I have some patches forthcoming to address that issue. The code here still works well for me, but I only have the one host to test this on.
If possible, I would like to try and get this merged for the 1.2.1 release cycle, so that other users can benefit from the addition of added storage pool support. As always, if you find any problems with my patches, please let me know, and I will fix them as soon as I can.
Adam Walters (3):
qemu: conf: Implement qemuAddRBDPoolSourceHost function
qemu: conf: Implement RBD storage pool support
domain: conf: Fix secret type checking
src/conf/domain_conf.c | 6 +++--
src/qemu/qemu_conf.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 65 insertions(+), 3 deletions(-)
--
1.8.5.2
10 years, 11 months
[libvirt] [PATCH 2/2] Implementation deficiency in virInitctlSetRunLevel v4
by Reco
Use helper virProcessRunInMountNamespace in lxcDomainShutdownFlags and
lxcDomainReboot.
---
src/lxc/lxc_driver.c | 44 ++++++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 16 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index e5298d1..2385f5b 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2694,12 +2694,21 @@ lxcConnectListAllDomains(virConnectPtr conn,
static int
+virDomainShutdownCallback(pid_t pid ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ int rc;
+ rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_POWEROFF, NULL);
+ return rc;
+}
+
+
+static int
lxcDomainShutdownFlags(virDomainPtr dom,
unsigned int flags)
{
virLXCDomainObjPrivatePtr priv;
virDomainObjPtr vm;
- char *vroot = NULL;
int ret = -1;
int rc;
@@ -2726,14 +2735,12 @@ lxcDomainShutdownFlags(virDomainPtr dom,
goto cleanup;
}
- if (virAsprintf(&vroot, "/proc/%llu/root",
- (unsigned long long)priv->initpid) < 0)
- goto cleanup;
-
if (flags == 0 ||
(flags & VIR_DOMAIN_SHUTDOWN_INITCTL)) {
- if ((rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_POWEROFF,
- vroot)) < 0) {
+ rc = virProcessRunInMountNamespace(priv->initpid,
+ virDomainShutdownCallback,
+ NULL);
+ if (rc < 0) {
goto cleanup;
}
if (rc == 0 && flags != 0 &&
@@ -2761,7 +2768,6 @@ lxcDomainShutdownFlags(virDomainPtr dom,
ret = 0;
cleanup:
- VIR_FREE(vroot);
if (vm)
virObjectUnlock(vm);
return ret;
@@ -2773,13 +2779,22 @@ lxcDomainShutdown(virDomainPtr dom)
return lxcDomainShutdownFlags(dom, 0);
}
+
+virDomainRebootCallback(pid_t pid ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ int rc;
+ rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_REBOOT, NULL);
+ return rc;
+}
+
+
static int
lxcDomainReboot(virDomainPtr dom,
unsigned int flags)
{
virLXCDomainObjPrivatePtr priv;
virDomainObjPtr vm;
- char *vroot = NULL;
int ret = -1;
int rc;
@@ -2806,14 +2821,12 @@ lxcDomainReboot(virDomainPtr dom,
goto cleanup;
}
- if (virAsprintf(&vroot, "/proc/%llu/root",
- (unsigned long long)priv->initpid) < 0)
- goto cleanup;
-
if (flags == 0 ||
(flags & VIR_DOMAIN_REBOOT_INITCTL)) {
- if ((rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_REBOOT,
- vroot)) < 0) {
+ rc = virProcessRunInMountNamespace(priv->initpid,
+ virDomainRebootCallback,
+ NULL);
+ if (rc < 0) {
goto cleanup;
}
if (rc == 0 && flags != 0 &&
@@ -2841,7 +2854,6 @@ lxcDomainReboot(virDomainPtr dom,
ret = 0;
cleanup:
- VIR_FREE(vroot);
if (vm)
virObjectUnlock(vm);
return ret;
--
1.7.10.4
10 years, 11 months
[libvirt] [PATCH] libxl: fix segfault when domain create fail
by Bamvor Jian Zhang
there is a segfault in libxl logging in libxl_ctx_free when domain
create fail. because the log output handler vmessage is freed by
xtl_logger_destroy before libxl_ctx_free in virDomainObjListRemove.
move xtl_logger_destroy after libxl_ctx_free could fix this bug.
Signed-off-by: Bamvor Jian Zhang <bjzhang(a)suse.com>
---
src/libxl/libxl_domain.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 68009db..e72c483 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -354,12 +354,11 @@ libxlDomainObjPrivateDispose(void *obj)
libxl_evdisable_domain_death(priv->ctx, priv->deathW);
virChrdevFree(priv->devs);
-
- xtl_logger_destroy(priv->logger);
+ libxl_ctx_free(priv->ctx);
if (priv->logger_file)
VIR_FORCE_FCLOSE(priv->logger_file);
- libxl_ctx_free(priv->ctx);
+ xtl_logger_destroy(priv->logger);
}
static void
--
1.8.1.4
10 years, 11 months
[libvirt] [PATCH] PanicCheckABIStability: Need to check for existence
by John Ferlan
Commit id '4313fead' added a call to virDomainPanicCheckABIStability()
which did not check whether the panic device existed before making a call
to virDomainDeviceInfoCheckABIStability() which ended up segfaulting:
Thread 1 (Thread 0x7f5332837700 (LWP 10964)):
(src=<optimized out>, dst=<optimized out>)
at conf/domain_conf.c:13007
(dst=<optimized out>, src=<optimized out>)
at conf/domain_conf.c:13712
(src=<optimized out>, dst=<optimized out>)
at conf/domain_conf.c:14056
(domain=domain@entry=0x7f53000057c0, vm=vm@entry=0x7f53000036d0,
defptr=defptr@entry=0x7f5332836978, snap=snap@entry=0x7f5332836970,
update_current=update_current@entry=0x7f5332836962, flags=flags@entry=1)
at conf/snapshot_conf.c:1230
(domain=0x7f53000057c0, xmlDesc=<optimized out>, flags=1)
at qemu/qemu_driver.c:12719
(domain=domain@entry=0x7f53000057c0, xmlDesc=0x7f53000081d0
"<domainsnapshot>\n <name>snap2</name>\n
<description>new-desc</description>\n <state>running</state>\n
<parent>\n <name>snap1</name>\n </parent>\n
<creationTime>1387487268</creationTime>\n <memory s"..., flags=1)
at libvirt.c:19695
...
(gdb) up 3
(gdb) print *other->def->dom
$2 = {virtType = 2, id = -1, ..
...
rng = 0x0, panic = 0x0, namespaceData = 0x0,...
...
(gdb) print *def->dom
$3 = {virtType = 2, id = -1, ...
...
rng = 0x0, panic = 0x0, namespaceData = 0x0,...
...
(gdb)
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
NOTE: Optionally the call could be changed to:
"if (src->panic && !virDomainPanicCheckABIStability(...)"
I went with what I did following the RNGDefCheckABIStability.
src/conf/domain_conf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0079234..c86af9a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13709,6 +13709,9 @@ static bool
virDomainPanicCheckABIStability(virDomainPanicDefPtr src,
virDomainPanicDefPtr dst)
{
+ if (!src && !dst)
+ return true;
+
return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info);
}
--
1.8.3.1
10 years, 11 months
[libvirt] [RFC PATCH] qemu: new API for tracking arbitrary monitor events
by Eric Blake
Several times in the past, qemu has implemented a new event,
but libvirt has not yet caught up to reporting that event to
the user applications. While it is possible to track libvirt
logs to see that an unknown event was received and ignored,
it would be nicer to copy what 'virsh qemu-monitor-command'
does, and expose this information to the end developer as
one of our unsupported qemu-specific commands.
If you find yourself needing to use this API for more than
just development purposes, please ask on the libvirt list
for a supported counterpart event to be added in libvirt.so.
While the supported virConnectDomainEventRegisterAny() API
takes an id which determines the signature of the callback,
this version takes a string filter and always uses the same
signature. Furthermore, I chose to expose this as a new API
instead of trying to add a new eventID at the top level, in
part because the generic option lacks event name filtering,
and in part because the normal domain event namespace should
not be polluted by a qemu-only event. I also added a flags
argument; unused for now, but we might decide to use it to
allow a user to request event names by glob or regex instead
of literal match.
* include/libvirt/libvirt-qemu.h
(virConnectDomainQemuMonitorEventCallback)
(virConnectDomainQemuMonitorEventRegister)
(virConnectDomainQemuMonitorEventDeregister): New prototypes.
* src/libvirt-qemu.c (virConnectDomainQemuMonitorEventRegister)
(virConnectDomainQemuMonitorEventDeregister): New functions.
* src/libvirt_qemu.syms (LIBVIRT_QEMU_1.2.1): Export them.
* src/driver.h (virDrvConnectDomainQemuMonitorEventRegister)
(virDrvConnectDomainQemuMonitorEventDeregister): New callbacks.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
Before I go and implement the guts of this new API, I first
wanted to get approval from the list that I'm on the right track.
include/libvirt/libvirt-qemu.h | 31 ++++++++++-
src/driver.h | 15 +++++
src/libvirt-qemu.c | 123 +++++++++++++++++++++++++++++++++++++++++
src/libvirt_qemu.syms | 6 ++
4 files changed, 174 insertions(+), 1 deletion(-)
diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h
index 3e79a8c..5403093 100644
--- a/include/libvirt/libvirt-qemu.h
+++ b/include/libvirt/libvirt-qemu.h
@@ -4,7 +4,7 @@
* Description: Provides the interfaces of the libvirt library to handle
* qemu specific methods
*
- * Copyright (C) 2010, 2012 Red Hat, Inc.
+ * Copyright (C) 2010, 2012-2013 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -54,6 +54,35 @@ typedef enum {
char *virDomainQemuAgentCommand(virDomainPtr domain, const char *cmd,
int timeout, unsigned int flags);
+/**
+ * virConnectDomainQemuMonitorEventCallback:
+ * @conn: the connection pointer
+ * @dom: the domain pointer
+ * @event: the name of the event
+ * @details: the JSON details of the event
+ * @opaque: application specified data
+ *
+ * The callback signature to use when registering for a qemu monitor
+ * event with virConnectDomainQemuMonitorEventRegister().
+ */
+typedef void (*virConnectDomainQemuMonitorEventCallback)(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *event,
+ const char *details,
+ void *opaque);
+
+int virConnectDomainQemuMonitorEventRegister(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *event,
+ virConnectDomainQemuMonitorEventCallback cb,
+ void *opaque,
+ virFreeCallback freecb,
+ unsigned int flags);
+
+int virConnectDomainQemuMonitorEventDeregister(virConnectPtr conn,
+ int callbackID);
+
+
# ifdef __cplusplus
}
# endif
diff --git a/src/driver.h b/src/driver.h
index b6927ea..e9bf5cb 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -841,6 +841,19 @@ typedef virDomainPtr
unsigned int flags);
typedef int
+(*virDrvConnectDomainQemuMonitorEventRegister)(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *event,
+ virConnectDomainQemuMonitorEventCallback cb,
+ void *opaque,
+ virFreeCallback freecb,
+ unsigned int flags);
+
+typedef int
+(*virDrvConnectDomainQemuMonitorEventDeregister)(virConnectPtr conn,
+ int callbackID);
+
+typedef int
(*virDrvDomainOpenConsole)(virDomainPtr dom,
const char *dev_name,
virStreamPtr st,
@@ -1300,6 +1313,8 @@ struct _virDriver {
virDrvDomainQemuMonitorCommand domainQemuMonitorCommand;
virDrvDomainQemuAttach domainQemuAttach;
virDrvDomainQemuAgentCommand domainQemuAgentCommand;
+ virDrvConnectDomainQemuMonitorEventRegister connectDomainQemuMonitorEventRegister;
+ virDrvConnectDomainQemuMonitorEventDeregister connectDomainQemuMonitorEventDeregister;
virDrvDomainOpenConsole domainOpenConsole;
virDrvDomainOpenChannel domainOpenChannel;
virDrvDomainOpenGraphics domainOpenGraphics;
diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
index db52c65..849932d 100644
--- a/src/libvirt-qemu.c
+++ b/src/libvirt-qemu.c
@@ -237,3 +237,126 @@ error:
virDispatchError(conn);
return NULL;
}
+
+
+/**
+ * virConnectDomainQemuMonitorEventRegister:
+ * @conn: pointer to the connection
+ * @dom: pointer to the domain, or NULL
+ * @event: name of the event, or NULL
+ * @cb: callback to the function handling monitor events
+ * @opaque: opaque data to pass on to the callback
+ * @freecb: optional function to deallocate opaque when not used anymore
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * This API is QEMU specific, so it will only work with hypervisor
+ * connections to the QEMU driver.
+ *
+ * Adds a callback to receive notifications of arbitrary qemu monitor events
+ * occurring on a domain. Many qemu monitor events also result in a libvirt
+ * event which can be delivered via virConnectDomainEventRegisterAny(); this
+ * command is primarily for testing new qemu events that have not yet been
+ * given a libvirt counterpart event.
+ *
+ * If @dom is NULL, then events will be monitored for any domain. If @dom
+ * is non-NULL, then only the specific domain will be monitored.
+ *
+ * If @event is NULL, then all monitor events will be reported. If @event is
+ * non-NULL, then only the specific monitor event will be reported. @flags
+ * is currently unused, but in the future may support a flag for passing
+ * @event as a glob instead of a literal name to match a category of events.
+ *
+ * The virDomainPtr object handle passed into the callback upon delivery
+ * of an event is only valid for the duration of execution of the callback.
+ * If the callback wishes to keep the domain object after the callback returns,
+ * it shall take a reference to it, by calling virDomainRef().
+ * The reference can be released once the object is no longer required
+ * by calling virDomainFree().
+ *
+ * The return value from this method is a positive integer identifier
+ * for the callback. To unregister a callback, this callback ID should
+ * be passed to the virConnectDomainQemuMonitorEventDeregister() method.
+ *
+ * Returns a callback identifier on success, -1 on failure
+ */
+int
+virConnectDomainQemuMonitorEventRegister(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *event,
+ virConnectDomainQemuMonitorEventCallback cb,
+ void *opaque,
+ virFreeCallback freecb,
+ unsigned int flags)
+{
+ VIR_DOMAIN_DEBUG(dom,
+ "conn=%p, event=%s, cb=%p, opaque=%p, freecb=%p, flags=%x",
+ conn, NULLSTR(event), cb, opaque, freecb, flags);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+ virDispatchError(NULL);
+ return -1;
+ }
+ if (dom &&
+ !(VIR_IS_CONNECTED_DOMAIN(dom) && dom->conn == conn)) {
+ virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+ virDispatchError(conn);
+ return -1;
+ }
+ virCheckNonNullArgGoto(cb, error);
+
+ if ((conn->driver) && (conn->driver->connectDomainQemuMonitorEventRegister)) {
+ int ret;
+ ret = conn->driver->connectDomainQemuMonitorEventRegister(conn, dom, event, cb, opaque, freecb, flags);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+error:
+ virDispatchError(conn);
+ return -1;
+}
+
+/**
+ * virConnectDomainQemuMonitorEventDeregister:
+ * @conn: pointer to the connection
+ * @callbackID: the callback identifier
+ *
+ * Removes an event callback. The callbackID parameter should be the
+ * value obtained from a previous virConnectDomainQemuMonitorEventRegister()
+ * method.
+ *
+ * Returns 0 on success, -1 on failure
+ */
+int
+virConnectDomainQemuMonitorEventDeregister(virConnectPtr conn,
+ int callbackID)
+{
+ VIR_DEBUG("conn=%p, callbackID=%d", conn, callbackID);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+ virDispatchError(NULL);
+ return -1;
+ }
+ virCheckNonNegativeArgGoto(callbackID, error);
+
+ if ((conn->driver) && (conn->driver->connectDomainQemuMonitorEventDeregister)) {
+ int ret;
+ ret = conn->driver->connectDomainQemuMonitorEventDeregister(conn, callbackID);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+error:
+ virDispatchError(conn);
+ return -1;
+}
diff --git a/src/libvirt_qemu.syms b/src/libvirt_qemu.syms
index f968d91..7698c5c 100644
--- a/src/libvirt_qemu.syms
+++ b/src/libvirt_qemu.syms
@@ -24,3 +24,9 @@ LIBVIRT_QEMU_0.10.0 {
global:
virDomainQemuAgentCommand;
} LIBVIRT_QEMU_0.9.4;
+
+LIBVIRT_QEMU_1.2.1 {
+ global:
+ virConnectDomainQemuMonitorEventDeregister;
+ virConnectDomainQemuMonitorEventRegister;
+} LIBVIRT_QEMU_0.10.0;
--
1.8.4.2
10 years, 11 months
[libvirt] [PATCH 1/2] Implementation deficiency in virInitctlSetRunLevel v3
by Reco
Implement virProcessRunInMountNamespace, which runs callback of type
virProcessNamespaceCallback in a container namespace.
---
src/libvirt_private.syms | 1 +
src/util/virprocess.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++
src/util/virprocess.h | 6 +++++
3 files changed, 70 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2dbb8f8..3f4b350 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1646,6 +1646,7 @@ virProcessGetNamespaces;
virProcessGetStartTime;
virProcessKill;
virProcessKillPainfully;
+virProcessRunInMountNamespace
virProcessSetAffinity;
virProcessSetMaxFiles;
virProcessSetMaxMemLock;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 9fc3207..2e8535e 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -31,6 +31,7 @@
# include <sys/resource.h>
#endif
#include <sched.h>
+#include <stdlib.h>
#ifdef __FreeBSD__
# include <sys/param.h>
@@ -847,3 +848,65 @@ int virProcessGetStartTime(pid_t pid,
return 0;
}
#endif
+
+#ifdef HAVE_SETNS
+int virProcessRunInMountNamespace(pid_t pid,
+ virProcessNamespaceCallback cb,
+ void *opaque)
+{
+ char* path = NULL;
+ int ret = -1;
+ int cpid = -1;
+ int status = -1;
+ int fd = -1;
+
+ if (virAsprintf(&path, "/proc/%llu/ns/mnt",
+ (unsigned long long)pid) < 0) {
+ goto cleanup;
+ }
+
+ if ((fd = open(path, O_RDONLY)) < 0) {
+ virReportSystemError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("Kernel does not provide mount namespace"));
+ goto cleanup;
+ }
+
+ switch (cpid = fork()) {
+ case 0:
+ if (setns(fd, 0) == -1) {
+ exit(-1);
+ }
+
+ ret = cb(pid, opaque);
+ exit(ret);
+ break;
+ case -1:
+ virReportSystemError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Fork failed"));
+ goto cleanup;
+ default:
+ if (waitpid(cpid, &status, 0) < 0 || status < 0) {
+ virReportSystemError(errno,
+ _("Callback failed with status %i"),
+ status);
+ ret = 1;
+ } else {
+ ret = 0;
+ }
+ }
+
+cleanup:
+ VIR_FREE(path);
+ VIR_FORCE_CLOSE(fd);
+ return ret;
+}
+#else
+int virProcessRunInMountNamespace(pid_t pid ATTRIBUTE_UNUSED,
+ virProcessNamespaceCallback cb ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Mount namespaces are not available on this platform"));
+ return -1;
+}
+#endif
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
index 9f77bc5..205abf7 100644
--- a/src/util/virprocess.h
+++ b/src/util/virprocess.h
@@ -60,4 +60,10 @@ int virProcessSetNamespaces(size_t nfdlist,
int virProcessSetMaxMemLock(pid_t pid, unsigned long long bytes);
int virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
int virProcessSetMaxFiles(pid_t pid, unsigned int files);
+
+typedef int (*virProcessNamespaceCallback)(pid_t pid, void *opaque);
+
+int virProcessRunInMountNamespace(pid_t pid,
+ virProcessNamespaceCallback cb,
+ void *opaque);
#endif /* __VIR_PROCESS_H__ */
--
1.7.10.4
10 years, 11 months
[libvirt] [PATCH v3 0/4] add support for panic device
by Hu Tao
panic device is a device that enables libvirt to receive notification of
guest panic event. qemu implements it by pvpanic. This series adds support
for panic device. It is implemented in qemu driver only.
changes in v3:
- introduce generic ISA address
- rename pvpanic to panic.
- add RNG schemas for new elements
- add tests for panic device
- error out if panic device is requested but qemu is too old
Hu Tao (4):
conf: introduce generic ISA address
conf: add support for panic device
qemu: add support for -device pvpanic
test: add test for panic device
docs/formatdomain.html.in | 33 ++++++
docs/schemas/basictypes.rng | 17 ++++
docs/schemas/domaincommon.rng | 16 +++
src/conf/domain_conf.c | 135 ++++++++++++++++++++++++-
src/conf/domain_conf.h | 18 ++++
src/qemu/qemu_capabilities.c | 3 +
src/qemu/qemu_capabilities.h | 2 +
src/qemu/qemu_command.c | 16 +++
tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 1 +
tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 1 +
tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 +
tests/qemuxml2argvdata/qemuxml2argv-panic.args | 6 ++
tests/qemuxml2argvdata/qemuxml2argv-panic.xml | 31 ++++++
tests/qemuxml2argvtest.c | 3 +
tests/qemuxml2xmltest.c | 2 +
15 files changed, 284 insertions(+), 1 deletion(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic.xml
--
1.7.11.7
10 years, 11 months
[libvirt] SECURITY: CVE-2013-6436: libvirtd daemon crash when reading memory tunables for LXC guest in shutoff status
by Daniel P. Berrange
Libvirt Security Notice
=======================
Summary: libvirtd daemon crash when reading memory tunables
for LXC guest in shutoff status
Reported on: 20131209
Published on: 20131220
Fixed on: 20131220
Reported by: Martin Kletzander <mkletzan(a)redhat.com>
Patched by: Martin Kletzander <mkletzan(a)redhat.com>
See also: CVE-2013-6436
Description
-----------
The lxcDomainGetMemoryParameters method in the LXC driver did not
check whether the guest being accessed was running or not. When
shutoff there will be no virCgroupPtr instance associated with the
guest. Reading memory tunables involves calling methods with the
virCgroupPtr object as a parameter. This will lead to a crash
accessing a NULL pointer.
Impact
------
A user who has permission to invoke the virDomainGetMemoryParameters
API against the LXC driver will be able to crash the libvirtd
daemon. Access to this API is granted to any user who connects to
the read-only libvirtd UNIX domain socket. If ACLs are active,
access is granted to any user with the 'read' permission on the
'domain' object, which is granted by default to all users. As a
result an unprivileged user will be able to inflict a denial of
service attack on other users of the libvirtd daemon with higher
privilege.
Workaround
----------
The impact can be mitigated by blocking access to the read-only
libvirtd UNIX domain socket, with policykit or the 'auth_unix_ro'
parameter in '/etc/libvirt/libvirtd.conf'. If ACLs are active, the
'read' permission should be removed from any untrusted users. This
will not prevent the crash, but will stop unprivileged users from
inflicting the denial of service on higher privileged users.
Affected product
----------------
Name: libvirt
Repository: git://libvirt.org/git/libvirt.git
Branch: master
Broken by: cfed9ad4fb28e268e1467a0071c2fbc0c0873969
Fixed by: f8c1cb90213508c4f32549023b0572ed774e48aa
Branch: v1.0.5-maint
Broken in: v1.0.5
Broken in: v1.0.5.1
Broken in: v1.0.5.2
Broken in: v1.0.5.3
Broken in: v1.0.5.4
Broken in: v1.0.5.5
Broken in: v1.0.5.6
Broken in: v1.0.5.7
Broken by: cfed9ad4fb28e268e1467a0071c2fbc0c0873969
Fixed by: 218bd2e8716bcb4c90acf6ecaf879d606b46606b
Branch: v1.0.6-maint
Broken in: v1.0.6
Broken by: cfed9ad4fb28e268e1467a0071c2fbc0c0873969
Fixed by: 80d682fd90bb7e97d8670be4cba1fe153438d7a0
Branch: v1.1.0-maint
Broken in: v1.1.0
Broken by: cfed9ad4fb28e268e1467a0071c2fbc0c0873969
Fixed by: 30a589bc4731488ca3428515ed57ce5446a83bbd
Branch: v1.1.1-maint
Broken in: v1.1.1
Broken by: cfed9ad4fb28e268e1467a0071c2fbc0c0873969
Fixed by: 9a68d1354233f4cfca686655f8021e9477977e6e
Branch: v1.1.2-maint
Broken in: v1.1.2
Broken by: cfed9ad4fb28e268e1467a0071c2fbc0c0873969
Fixed by: 79384018480f11ec6f2c2196039e67a9196d3e3a
Branch: v1.1.3-maint
Broken in: v1.1.3
Broken in: v1.1.3.1
Broken by: cfed9ad4fb28e268e1467a0071c2fbc0c0873969
Fixed by: 66247dc5fffe5b9447f4db377c5adf02e6db97c4
Branch: v1.1.4-maint
Broken in: v1.1.4
Broken by: cfed9ad4fb28e268e1467a0071c2fbc0c0873969
Fixed by: 09956c7db764a0958034de6fac58aaaaf8e878bf
Branch: v1.2.0-maint
Broken in: v1.2.0
Broken by: cfed9ad4fb28e268e1467a0071c2fbc0c0873969
Fixed by: 705f388bceb4fce21b7c5ebc6310cb467c362239
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
10 years, 11 months
[libvirt] [PATCH 0/3] libxl: improve vcpu pinning
by Dario Faggioli
Basically, by making it possible to both query and change the vcpu to pcpu
pinning of a (persistent) domain, even when it is not running.
That happens by providing the implementation of virDomainGetVcpuPinInfo() and
virDomainPinVcpuFlags() within he libxl driver, which is what happens in the
first two patches. The third patch is something that can also be seen as a
bugfix, and that's why I kept it separated from the second one, for easier
review (although, the 'bug' does not really manifests, until
virDomainPinVcpuFlags is implemented in patch 2).
The logic is a lot similar to what happens in the QEMU driver.
The patches are available in the following git branch:
git://xenbits.xen.org/people/dariof/libvirt.git libxl/VcpuPinX
Thanks and Regards,
Dario
---
Dario Faggioli (3):
libxl: implement virDomainGetVcpuPinInfo
libxl: implement virDomainPinVcpuFlags
libxl: correctly handle affinity reset in virDomainPinVcpu[Flags]
src/libxl/libxl_driver.c | 171 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 150 insertions(+), 21 deletions(-)
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
10 years, 11 months