[libvirt] [libvirt-glib] Getter/setter for disk source's startupPolicy attribute
by Zeeshan Ali (Khattak)
From: "Zeeshan Ali (Khattak)" <zeeshanak(a)gnome.org>
---
libvirt-gconfig/libvirt-gconfig-domain-disk.c | 26 +++++++++++++++++++++++++
libvirt-gconfig/libvirt-gconfig-domain-disk.h | 9 ++++++++
libvirt-gconfig/libvirt-gconfig.sym | 3 ++
3 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
index 5d0acb5..a29ea47 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
@@ -127,6 +127,18 @@ void gvir_config_domain_disk_set_snapshot_type(GVirConfigDomainDisk *disk,
type, NULL);
}
+void gvir_config_domain_disk_set_startup_policy(GVirConfigDomainDisk *disk,
+ GVirConfigDomainDiskStartupPolicy policy)
+{
+ const char *str;
+
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk));
+ str = gvir_config_genum_get_nick(GVIR_CONFIG_TYPE_DOMAIN_DISK_STARTUP_POLICY, policy);
+ g_return_if_fail(str != NULL);
+ gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk),
+ "source", "startupPolicy", str);
+}
+
void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk,
const char *source)
{
@@ -235,6 +247,19 @@ gvir_config_domain_disk_get_snapshot_type(GVirConfigDomainDisk *disk)
GVIR_CONFIG_DOMAIN_DISK_SNAPSHOT_NO);
}
+GVirConfigDomainDiskStartupPolicy
+gvir_config_domain_disk_get_startup_policy(GVirConfigDomainDisk *disk)
+{
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk),
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_MANDATORY);
+
+ return gvir_config_object_get_attribute_genum
+ (GVIR_CONFIG_OBJECT(disk),
+ "source", "startupPolicy",
+ GVIR_CONFIG_TYPE_DOMAIN_DISK_STARTUP_POLICY,
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_MANDATORY);
+}
+
const char *
gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk)
{
@@ -291,6 +316,7 @@ gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk)
GVIR_CONFIG_TYPE_DOMAIN_DISK_CACHE_TYPE,
GVIR_CONFIG_DOMAIN_DISK_CACHE_DEFAULT);
}
+
GVirConfigDomainDiskBus
gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk *disk)
{
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
index 916421d..7e85d75 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
@@ -95,6 +95,12 @@ typedef enum {
GVIR_CONFIG_DOMAIN_DISK_SNAPSHOT_EXTERNAL
} GVirConfigDomainDiskSnapshotType;
+typedef enum {
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_MANDATORY,
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_REQUISITE,
+ GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_OPTIONAL
+} GVirConfigDomainDiskStartupPolicy;
+
GType gvir_config_domain_disk_get_type(void);
GVirConfigDomainDisk *gvir_config_domain_disk_new(void);
@@ -107,6 +113,8 @@ void gvir_config_domain_disk_set_guest_device_type(GVirConfigDomainDisk *disk,
GVirConfigDomainDiskGuestDeviceType type);
void gvir_config_domain_disk_set_snapshot_type(GVirConfigDomainDisk *disk,
GVirConfigDomainDiskSnapshotType type);
+void gvir_config_domain_disk_set_startup_policy(GVirConfigDomainDisk *disk,
+ GVirConfigDomainDiskStartupPolicy policy);
void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk,
const char *source);
void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk,
@@ -123,6 +131,7 @@ void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk,
GVirConfigDomainDiskType gvir_config_domain_disk_get_disk_type(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskGuestDeviceType gvir_config_domain_disk_get_guest_device_type(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskSnapshotType gvir_config_domain_disk_get_snapshot_type(GVirConfigDomainDisk *disk);
+GVirConfigDomainDiskStartupPolicy gvir_config_domain_disk_get_startup_policy(GVirConfigDomainDisk *disk);
const char *gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskCacheType gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk);
const char *gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk);
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 2378a3c..f4e5fa3 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -76,6 +76,7 @@ LIBVIRT_GCONFIG_0.0.7 {
gvir_config_domain_disk_cache_type_get_type;
gvir_config_domain_disk_guest_device_type_get_type;
gvir_config_domain_disk_snapshot_type_get_type;
+ gvir_config_domain_disk_startup_policy_get_type;
gvir_config_domain_disk_type_get_type;
gvir_config_domain_disk_new;
gvir_config_domain_disk_new_from_xml;
@@ -91,6 +92,8 @@ LIBVIRT_GCONFIG_0.0.7 {
gvir_config_domain_disk_set_snapshot_type;
gvir_config_domain_disk_get_source;
gvir_config_domain_disk_set_source;
+ gvir_config_domain_disk_get_startup_policy;
+ gvir_config_domain_disk_set_startup_policy;
gvir_config_domain_disk_get_target_bus;
gvir_config_domain_disk_set_target_bus;
gvir_config_domain_disk_get_target_dev;
--
1.7.7.6
12 years, 10 months
Re: [libvirt] [Guidelines Change] Changes to the Packaging Guidelines
by Eric Blake
things we should be thinking about:
On 04/12/2012 02:57 PM, Tom Callaway wrote:
> Here is the latest set of changes to the Fedora Packaging Guidelines:
>
> ---
>
> Packages which have SysV initscripts that contain 'non-standard service
> commands' (commands besides start, stop, reload, restart, or
> try-restart) must convert those commands into standalone helper scripts.
> Systemd does not support non-standard unit commands.
>
> https://fedoraproject.org/wiki/Packaging:Systemd#Unit_Files
I think libvirt-guests falls into this category.
>
> ---
>
> The guidelines relating to PIE and Hardened Packages were updated. Now,
> if your package meets the following critera you MUST enable the PIE
> compiler flags:
>
> * Your package is long running. This means it's likely to be started and
> keep running until the machine is rebooted, not start on demand and quit
> on idle.
>
> * Your package has suid binaries, or binaries with capabilities.
>
> * Your package runs as root.
>
> https://fedoraproject.org/wiki/Packaging:Guidelines#PIE
libvirtd definitely qualifies as one of these packages needing PIE
compilation in our libvirt.spec file.
>
> ---
>
> Rules involving appropriate scripting within Fedora Package spec files
> were added to the Guidelines:
>
> https://fedoraproject.org/wiki/Packaging:Guidelines#Scripting_inside_of_s...
Don't know if any of these changes impact us, but can't hurt to audit it.
Plus, we still haven't converted our mingw specfile over to the mingw64
toolchain. Anyone up for some specfile maintenance?
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
12 years, 10 months
[libvirt] [PATCH v2] Pull DBus event code out into common area
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The policy kit and HAL node device drivers both require a
DBus connection. The HAL device code further requires that
the DBus connection is integrated with the event loop and
provides such glue logic itself.
The forthcoming FirewallD integration also requires a
dbus connection with event loop integration. Thus we need
to pull the current event loop glue out of the HAL driver.
Thus we create src/util/virdbus.{c,h} files. This contains
just one method virDBusGetSystemBus() which obtains a handle
to the single shared system bus instance, with event glue
automagically setup.
---
.gitignore | 6 +-
configure.ac | 37 ++++++-
daemon/Makefile.am | 3 +-
daemon/libvirtd.c | 4 -
daemon/remote.c | 8 +-
include/libvirt/virterror.h | 1 +
src/Makefile.am | 13 +--
src/libvirt_dbus.syms | 2 -
src/node_device/node_device_hal.c | 143 ++------------------------
src/rpc/virnetserver.c | 40 --------
src/rpc/virnetserver.h | 8 --
src/util/virdbus.c | 201 +++++++++++++++++++++++++++++++++++++
src/util/virdbus.h | 34 ++++++
src/util/virterror.c | 3 +
14 files changed, 296 insertions(+), 207 deletions(-)
delete mode 100644 src/libvirt_dbus.syms
create mode 100644 src/util/virdbus.c
create mode 100644 src/util/virdbus.h
diff --git a/.gitignore b/.gitignore
index 5aa9c9b..14a21d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,12 +48,12 @@
/daemon/*_dispatch.h
/daemon/libvirt_qemud
/daemon/libvirtd
-/daemon/libvirtd.init
-/daemon/libvirtd.service
/daemon/libvirtd*.logrotate
/daemon/libvirtd.8
/daemon/libvirtd.8.in
+/daemon/libvirtd.init
/daemon/libvirtd.pod
+/daemon/libvirtd.service
/docs/devhelp/libvirt.devhelp
/docs/hvsupport.html.in
/docs/libvirt-api.xml
@@ -118,6 +118,7 @@
/tests/eventtest
/tests/hashtest
/tests/jsontest
+/tests/libvirtdconftest
/tests/networkxml2argvtest
/tests/nodeinfotest
/tests/nwfilterxml2xmltest
@@ -150,7 +151,6 @@
/tests/vmx2xmltest
/tests/xencapstest
/tests/xmconfigtest
-/tests/libvirtdconftest
/tools/*.[18]
/tools/libvirt-guests.init
/tools/virsh
diff --git a/configure.ac b/configure.ac
index 3f5b3ff..f49b620 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,6 +74,7 @@ LIBPCAP_REQUIRED="1.0.0"
LIBNL_REQUIRED="1.1"
LIBSSH2_REQUIRED="1.0"
LIBBLKID_REQUIRED="2.17"
+DBUS_REQUIRED="1.0.0"
dnl Checks for C compiler.
AC_PROG_CC
@@ -1099,6 +1100,36 @@ AC_SUBST([SANLOCK_CFLAGS])
AC_SUBST([SANLOCK_LIBS])
+dnl DBus library
+DBUS_CFLAGS=
+DBUS_LIBS=
+AC_ARG_WITH([dbus],
+ AC_HELP_STRING([--with-dbus], [enable communication with DBus @<:@default=check@:>@]),
+ [],
+ [with_dbus=check])
+if test "$with_dbus" = "yes" || test "$with_dbus" = "check" ; then
+ PKG_CHECK_MODULES(DBUS, dbus-1 >= $DBUS_REQUIRED,
+ [with_dbus=yes], [
+ if test "$with_dbus" = "check" ; then
+ with_dbus=no
+ else
+ AC_MSG_ERROR([You must install DBus >= $DBUS_REQUIRED to compile libvirt])
+ fi])
+fi
+
+if test "$with_dbus" = "yes" ; then
+ AC_DEFINE_UNQUOTED([HAVE_DBUS], 1, [enable communication with DBus])
+
+ save_LIBS="$LIBS"
+ save_CFLAGS="$CFLAGS"
+ LIBS="$LIBS $DBUS_LIBS"
+ CFLAGS="$CFLAGS $DBUS_CFLAGS"
+ AC_CHECK_FUNCS([dbus_watch_get_unix_fd])
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+fi
+
+
dnl PolicyKit library
POLKIT_CFLAGS=
POLKIT_LIBS=
@@ -1109,7 +1140,6 @@ AC_ARG_WITH([polkit],
[with_polkit=check])
with_polkit0=no
-with_dbus=no
with_polkit1=no
if test "x$with_polkit" = "xyes" || test "x$with_polkit" = "xcheck"; then
dnl Check for new polkit first - just a binary
@@ -1138,8 +1168,6 @@ if test "x$with_polkit" = "xyes" || test "x$with_polkit" = "xcheck"; then
[use PolicyKit for UNIX socket access checks])
AC_DEFINE_UNQUOTED([HAVE_POLKIT0], 1,
[use PolicyKit for UNIX socket access checks])
- AC_DEFINE_UNQUOTED([HAVE_DBUS], 1,
- [use DBus for PolicyKit])
old_CFLAGS=$CFLAGS
old_LIBS=$LIBS
@@ -1154,13 +1182,11 @@ if test "x$with_polkit" = "xyes" || test "x$with_polkit" = "xcheck"; then
AC_DEFINE_UNQUOTED([POLKIT_AUTH],["$POLKIT_AUTH"],[Location of polkit-auth program])
fi
with_polkit0="yes"
- with_dbus="yes"
fi
fi
fi
AM_CONDITIONAL([HAVE_POLKIT], [test "x$with_polkit" = "xyes"])
AM_CONDITIONAL([HAVE_POLKIT0], [test "x$with_polkit0" = "xyes"])
-AM_CONDITIONAL([HAVE_DBUS], [test "x$with_dbus" = "xyes"])
AM_CONDITIONAL([HAVE_POLKIT1], [test "x$with_polkit1" = "xyes"])
AC_SUBST([POLKIT_CFLAGS])
AC_SUBST([POLKIT_LIBS])
@@ -2413,7 +2439,6 @@ if test "x$with_hal" = "xyes" || test "x$with_hal" = "xcheck"; then
CFLAGS="$CFLAGS $HAL_CFLAGS"
LIBS="$LIBS $HAL_LIBS"
AC_CHECK_FUNCS([libhal_get_all_devices],,[with_hal=no])
- AC_CHECK_FUNCS([dbus_watch_get_unix_fd])
CFLAGS="$old_CFLAGS"
LIBS="$old_LIBS"
fi
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 5d9f5d7..24cce8f 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -94,7 +94,7 @@ libvirtd_SOURCES = $(DAEMON_SOURCES)
#-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L
libvirtd_CFLAGS = \
$(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) $(SASL_CFLAGS) \
- $(XDR_CFLAGS) $(POLKIT_CFLAGS) \
+ $(XDR_CFLAGS) $(POLKIT_CFLAGS) $(DBUS_CFLAGS) \
$(WARN_CFLAGS) \
$(COVERAGE_CFLAGS) \
-DQEMUD_PID_FILE="\"$(QEMUD_PID_FILE)\"" \
@@ -108,6 +108,7 @@ libvirtd_LDADD = \
$(LIBXML_LIBS) \
$(GNUTLS_LIBS) \
$(SASL_LIBS) \
+ $(DBUS_LIBS) \
$(POLKIT_LIBS)
if WITH_DTRACE_PROBES
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index ce931d4..b098f6a 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -812,7 +812,6 @@ int main(int argc, char **argv) {
struct daemonConfig *config;
bool privileged = geteuid() == 0 ? true : false;
bool implicit_conf = false;
- bool use_polkit_dbus;
char *run_dir = NULL;
mode_t old_umask;
@@ -1008,8 +1007,6 @@ int main(int argc, char **argv) {
goto cleanup;
}
- use_polkit_dbus = config->auth_unix_rw == REMOTE_AUTH_POLKIT ||
- config->auth_unix_ro == REMOTE_AUTH_POLKIT;
if (!(srv = virNetServerNew(config->min_workers,
config->max_workers,
config->prio_workers,
@@ -1018,7 +1015,6 @@ int main(int argc, char **argv) {
config->keepalive_count,
!!config->keepalive_required,
config->mdns_adv ? config->mdns_name : NULL,
- use_polkit_dbus,
remoteClientInitHook))) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
diff --git a/daemon/remote.c b/daemon/remote.c
index b71ffa2..16a8a05 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -45,7 +45,7 @@
#include "virnetserver.h"
#include "virfile.h"
#include "virtypedparam.h"
-
+#include "virdbus.h"
#include "remote_protocol.h"
#include "qemu_protocol.h"
@@ -2672,6 +2672,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server,
char *ident = NULL;
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
+ DBusConnection *sysbus;
virMutexLock(&priv->lock);
@@ -2697,10 +2698,13 @@ remoteDispatchAuthPolkit(virNetServerPtr server,
goto authfail;
}
+ if (!(sysbus = virDBusGetSystemBus()))
+ goto authfail;
+
VIR_INFO("Checking PID %lld running as %d",
(long long) callerPid, callerUid);
dbus_error_init(&err);
- if (!(pkcaller = polkit_caller_new_from_pid(virNetServerGetDBusConn(server),
+ if (!(pkcaller = polkit_caller_new_from_pid(sysbus,
callerPid, &err))) {
VIR_ERROR(_("Failed to lookup policy kit caller: %s"), err.message);
dbus_error_free(&err);
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index e04d29e..cda15ff 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -87,6 +87,7 @@ typedef enum {
VIR_FROM_CAPABILITIES = 44, /* Error from capabilities */
VIR_FROM_URI = 45, /* Error from URI handling */
VIR_FROM_AUTH = 46, /* Error from auth handling */
+ VIR_FROM_DBUS = 47, /* Error from DBus */
} virErrorDomain;
diff --git a/src/Makefile.am b/src/Makefile.am
index a2aae9d..b8a19b4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -88,6 +88,7 @@ UTIL_SOURCES = \
util/virtypedparam.c util/virtypedparam.h \
util/xml.c util/xml.h \
util/virterror.c util/virterror_internal.h \
+ util/virdbus.c util/virdbus.h \
util/virhash.c util/virhash.h \
util/virhashcode.c util/virhashcode.h \
util/virkeycode.c util/virkeycode.h \
@@ -574,10 +575,11 @@ libvirt_la_BUILT_LIBADD = libvirt_util.la
libvirt_util_la_SOURCES = \
$(UTIL_SOURCES)
libvirt_util_la_CFLAGS = $(CAPNG_CFLAGS) $(YAJL_CFLAGS) $(LIBNL_CFLAGS) \
- $(AM_CFLAGS) $(AUDIT_CFLAGS) $(DEVMAPPER_CFLAGS)
+ $(AM_CFLAGS) $(AUDIT_CFLAGS) $(DEVMAPPER_CFLAGS) \
+ $(DBUS_CFLAGS)
libvirt_util_la_LIBADD = $(CAPNG_LIBS) $(YAJL_LIBS) $(LIBNL_LIBS) \
$(THREAD_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \
- $(RT_LIBS)
+ $(RT_LIBS) $(DBUS_LIBS)
noinst_LTLIBRARIES += libvirt_conf.la
@@ -1198,10 +1200,6 @@ if WITH_LINUX
USED_SYM_FILES += libvirt_linux.syms
endif
-if HAVE_DBUS
-USED_SYM_FILES += libvirt_dbus.syms
-endif
-
if WITH_LIBVIRTD
USED_SYM_FILES += libvirt_daemon.syms
endif
@@ -1525,7 +1523,7 @@ libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(AM_LDFLAGS)
libvirt_lxc_LDADD = $(CAPNG_LIBS) $(YAJL_LIBS) \
$(LIBXML_LIBS) $(NUMACTL_LIBS) $(THREAD_LIBS) \
$(LIBNL_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \
- $(RT_LIBS) \
+ $(RT_LIBS) $(DBUS_LIBS) \
../gnulib/lib/libgnu.la
if WITH_DTRACE_PROBES
libvirt_lxc_LDADD += probes.o
@@ -1542,6 +1540,7 @@ libvirt_lxc_CFLAGS = \
$(CAPNG_CFLAGS) \
$(YAJL_CFLAGS) \
$(AUDIT_CFLAGS) \
+ $(DBUS_CFLAGS) \
-I$(top_srcdir)/src/conf \
$(AM_CFLAGS)
if HAVE_LIBBLKID
diff --git a/src/libvirt_dbus.syms b/src/libvirt_dbus.syms
deleted file mode 100644
index a460ec5..0000000
--- a/src/libvirt_dbus.syms
+++ /dev/null
@@ -1,2 +0,0 @@
-# virnetserver.h
-virNetServerGetDBusConn;
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index a028886..dd14271 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -39,6 +39,7 @@
#include "logging.h"
#include "node_device_driver.h"
#include "ignore-value.h"
+#include "virdbus.h"
#define VIR_FROM_THIS VIR_FROM_NODEDEV
@@ -586,124 +587,15 @@ static void device_prop_modified(LibHalContext *ctx ATTRIBUTE_UNUSED,
}
-static void dbus_watch_callback(int fdatch ATTRIBUTE_UNUSED,
- int fd ATTRIBUTE_UNUSED,
- int events, void *opaque)
-{
- DBusWatch *watch = opaque;
- LibHalContext *hal_ctx;
- DBusConnection *dbus_conn;
- int dbus_flags = 0;
-
- if (events & VIR_EVENT_HANDLE_READABLE)
- dbus_flags |= DBUS_WATCH_READABLE;
- if (events & VIR_EVENT_HANDLE_WRITABLE)
- dbus_flags |= DBUS_WATCH_WRITABLE;
- if (events & VIR_EVENT_HANDLE_ERROR)
- dbus_flags |= DBUS_WATCH_ERROR;
- if (events & VIR_EVENT_HANDLE_HANGUP)
- dbus_flags |= DBUS_WATCH_HANGUP;
-
- (void)dbus_watch_handle(watch, dbus_flags);
-
- nodeDeviceLock(driverState);
- hal_ctx = DRV_STATE_HAL_CTX(driverState);
- dbus_conn = libhal_ctx_get_dbus_connection(hal_ctx);
- nodeDeviceUnlock(driverState);
- while (dbus_connection_dispatch(dbus_conn) == DBUS_DISPATCH_DATA_REMAINS)
- /* keep dispatching while data remains */;
-}
-
-
-static int xlate_dbus_watch_flags(int dbus_flags)
-{
- unsigned int flags = 0;
- if (dbus_flags & DBUS_WATCH_READABLE)
- flags |= VIR_EVENT_HANDLE_READABLE;
- if (dbus_flags & DBUS_WATCH_WRITABLE)
- flags |= VIR_EVENT_HANDLE_WRITABLE;
- if (dbus_flags & DBUS_WATCH_ERROR)
- flags |= VIR_EVENT_HANDLE_ERROR;
- if (dbus_flags & DBUS_WATCH_HANGUP)
- flags |= VIR_EVENT_HANDLE_HANGUP;
- return flags;
-}
-
-
-struct nodeDeviceWatchInfo
-{
- int watch;
-};
-
-static void nodeDeviceWatchFree(void *data) {
- struct nodeDeviceWatchInfo *info = data;
- VIR_FREE(info);
-}
-
-static dbus_bool_t add_dbus_watch(DBusWatch *watch,
- void *data ATTRIBUTE_UNUSED)
-{
- int flags = 0;
- int fd;
- struct nodeDeviceWatchInfo *info;
-
- if (VIR_ALLOC(info) < 0)
- return 0;
-
- if (dbus_watch_get_enabled(watch))
- flags = xlate_dbus_watch_flags(dbus_watch_get_flags(watch));
-
-#if HAVE_DBUS_WATCH_GET_UNIX_FD
- fd = dbus_watch_get_unix_fd(watch);
-#else
- fd = dbus_watch_get_fd(watch);
-#endif
- info->watch = virEventAddHandle(fd, flags, dbus_watch_callback,
- watch, NULL);
- if (info->watch < 0) {
- VIR_FREE(info);
- return 0;
- }
- dbus_watch_set_data(watch, info, nodeDeviceWatchFree);
-
- return 1;
-}
-
-
-static void remove_dbus_watch(DBusWatch *watch,
- void *data ATTRIBUTE_UNUSED)
-{
- struct nodeDeviceWatchInfo *info;
-
- info = dbus_watch_get_data(watch);
-
- (void)virEventRemoveHandle(info->watch);
-}
-
-
-static void toggle_dbus_watch(DBusWatch *watch,
- void *data ATTRIBUTE_UNUSED)
-{
- int flags = 0;
- struct nodeDeviceWatchInfo *info;
-
- if (dbus_watch_get_enabled(watch))
- flags = xlate_dbus_watch_flags(dbus_watch_get_flags(watch));
-
- info = dbus_watch_get_data(watch);
-
- (void)virEventUpdateHandle(info->watch, flags);
-}
static int halDeviceMonitorStartup(int privileged ATTRIBUTE_UNUSED)
{
LibHalContext *hal_ctx = NULL;
- DBusConnection *dbus_conn = NULL;
- DBusError err;
char **udi = NULL;
int num_devs, i;
int ret = -1;
+ DBusConnection *sysbus;
/* Ensure caps_tbl is sorted by capability name */
qsort(caps_tbl, ARRAY_CARDINALITY(caps_tbl), sizeof(caps_tbl[0]),
@@ -718,26 +610,19 @@ static int halDeviceMonitorStartup(int privileged ATTRIBUTE_UNUSED)
}
nodeDeviceLock(driverState);
- /* Allocate and initialize a new HAL context */
- dbus_connection_set_change_sigpipe(FALSE);
- dbus_threads_init_default();
+ if (!(sysbus == virDBusGetSystemBus())) {
+ virErrorPtr err = virGetLastError();
+ VIR_ERROR(_("DBus not available, disabling HAL driver: %s",
+ err->message));
+ ret = 0;
+ goto failure;
+ }
- dbus_error_init(&err);
hal_ctx = libhal_ctx_new();
if (hal_ctx == NULL) {
VIR_ERROR(_("libhal_ctx_new returned NULL"));
goto failure;
}
- dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
- if (dbus_conn == NULL) {
- VIR_ERROR(_("dbus_bus_get failed"));
- /* We don't want to show a fatal error here,
- otherwise entire libvirtd shuts down when
- D-Bus isn't running */
- ret = 0;
- goto failure;
- }
- dbus_connection_set_exit_on_disconnect(dbus_conn, FALSE);
if (!libhal_ctx_set_dbus_connection(hal_ctx, dbus_conn)) {
VIR_ERROR(_("libhal_ctx_set_dbus_connection failed"));
@@ -752,16 +637,6 @@ static int halDeviceMonitorStartup(int privileged ATTRIBUTE_UNUSED)
goto failure;
}
- /* Register dbus watch callbacks */
- if (!dbus_connection_set_watch_functions(dbus_conn,
- add_dbus_watch,
- remove_dbus_watch,
- toggle_dbus_watch,
- NULL, NULL)) {
- VIR_ERROR(_("dbus_connection_set_watch_functions failed"));
- goto failure;
- }
-
/* Populate with known devices */
driverState->privateData = hal_ctx;
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index f761e6b..3965fc2 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -39,9 +39,6 @@
#if HAVE_AVAHI
# include "virnetservermdns.h"
#endif
-#if HAVE_DBUS
-# include <dbus/dbus.h>
-#endif
#define VIR_FROM_THIS VIR_FROM_RPC
#define virNetError(code, ...) \
@@ -88,10 +85,6 @@ struct _virNetServer {
virNetServerMDNSGroupPtr mdnsGroup;
#endif
-#if HAVE_DBUS
- DBusConnection *sysbus;
-#endif
-
size_t nservices;
virNetServerServicePtr *services;
@@ -311,7 +304,6 @@ virNetServerPtr virNetServerNew(size_t min_workers,
unsigned int keepaliveCount,
bool keepaliveRequired,
const char *mdnsGroupName,
- bool connectDBus ATTRIBUTE_UNUSED,
virNetServerClientInitHook clientInitHook)
{
virNetServerPtr srv;
@@ -353,25 +345,6 @@ virNetServerPtr virNetServerNew(size_t min_workers,
}
#endif
-#if HAVE_DBUS
- if (connectDBus) {
- DBusError derr;
-
- dbus_connection_set_change_sigpipe(FALSE);
- dbus_threads_init_default();
-
- dbus_error_init(&derr);
- srv->sysbus = dbus_bus_get(DBUS_BUS_SYSTEM, &derr);
- if (!(srv->sysbus)) {
- VIR_ERROR(_("Failed to connect to system bus for PolicyKit auth: %s"),
- derr.message);
- dbus_error_free(&derr);
- goto error;
- }
- dbus_connection_set_exit_on_disconnect(srv->sysbus, FALSE);
- }
-#endif
-
if (virMutexInit(&srv->lock) < 0) {
virNetError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot initialize mutex"));
@@ -429,14 +402,6 @@ bool virNetServerIsPrivileged(virNetServerPtr srv)
}
-#if HAVE_DBUS
-DBusConnection* virNetServerGetDBusConn(virNetServerPtr srv)
-{
- return srv->sysbus;
-}
-#endif
-
-
void virNetServerAutoShutdown(virNetServerPtr srv,
unsigned int timeout,
virNetServerAutoShutdownFunc func,
@@ -828,11 +793,6 @@ void virNetServerFree(virNetServerPtr srv)
virNetServerMDNSFree(srv->mdns);
#endif
-#if HAVE_DBUS
- if (srv->sysbus)
- dbus_connection_unref(srv->sysbus);
-#endif
-
virNetServerUnlock(srv);
virMutexDestroy(&srv->lock);
VIR_FREE(srv);
diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h
index a04ffdd..0ebe00e 100644
--- a/src/rpc/virnetserver.h
+++ b/src/rpc/virnetserver.h
@@ -25,9 +25,6 @@
# define __VIR_NET_SERVER_H__
# include <signal.h>
-# if HAVE_DBUS
-# include <dbus/dbus.h>
-# endif
# include "virnettlscontext.h"
# include "virnetserverprogram.h"
@@ -45,7 +42,6 @@ virNetServerPtr virNetServerNew(size_t min_workers,
unsigned int keepaliveCount,
bool keepaliveRequired,
const char *mdnsGroupName,
- bool connectDBus,
virNetServerClientInitHook clientInitHook);
typedef int (*virNetServerAutoShutdownFunc)(virNetServerPtr srv, void *opaque);
@@ -54,10 +50,6 @@ void virNetServerRef(virNetServerPtr srv);
bool virNetServerIsPrivileged(virNetServerPtr srv);
-# if HAVE_DBUS
-DBusConnection* virNetServerGetDBusConn(virNetServerPtr srv);
-# endif
-
void virNetServerAutoShutdown(virNetServerPtr srv,
unsigned int timeout,
virNetServerAutoShutdownFunc func,
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
new file mode 100644
index 0000000..badfe8c
--- /dev/null
+++ b/src/util/virdbus.c
@@ -0,0 +1,201 @@
+/*
+ * virdbus.c: helper for using DBus
+ *
+ * Copyright (C) 2012 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <config.h>
+
+#include "virdbus.h"
+#include "memory.h"
+#include "virterror_internal.h"
+#include "logging.h"
+#include "threads.h"
+
+#define VIR_FROM_THIS VIR_FROM_DBUS
+
+#define virDBusReportError(code, ...) \
+ virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
+ __FUNCTION__, __LINE__, __VA_ARGS__)
+
+#ifdef HAVE_DBUS
+
+static DBusConnection *systembus = NULL;
+static virOnceControl once = VIR_ONCE_CONTROL_INITIALIZER;
+static DBusError dbuserr;
+
+static dbus_bool_t virDBusAddWatch(DBusWatch *watch, void *data);
+static void virDBusRemoveWatch(DBusWatch *watch, void *data);
+static void virDBusToggleWatch(DBusWatch *watch, void *data);
+
+static void virDBusSystemBusInit(void)
+{
+ /* Allocate and initialize a new HAL context */
+ dbus_connection_set_change_sigpipe(FALSE);
+ dbus_threads_init_default();
+
+ dbus_error_init(&dbuserr);
+ if (!(systembus = dbus_bus_get(DBUS_BUS_SYSTEM, &dbuserr)))
+ return;
+
+ dbus_connection_set_exit_on_disconnect(systembus, FALSE);
+
+ /* Register dbus watch callbacks */
+ if (!dbus_connection_set_watch_functions(systembus,
+ virDBusAddWatch,
+ virDBusRemoveWatch,
+ virDBusToggleWatch,
+ NULL, NULL)) {
+ systembus = NULL;
+ return;
+ }
+}
+
+
+DBusConnection *virDBusGetSystemBus(void)
+{
+ if (virOnce(&once, virDBusSystemBusInit) < 0) {
+ virDBusReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Unable to run one time DBus initializer"));
+ return NULL;
+ }
+
+ if (!systembus) {
+ virDBusReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to get DBus system bus connection: %s"),
+ dbuserr.message ? dbuserr.message : "watch setup failed");
+ return NULL;
+ }
+
+ return systembus;
+}
+
+
+static void virDBusWatchCallback(int fdatch ATTRIBUTE_UNUSED,
+ int fd ATTRIBUTE_UNUSED,
+ int events, void *opaque)
+{
+ DBusWatch *watch = opaque;
+ int dbus_flags = 0;
+
+ if (events & VIR_EVENT_HANDLE_READABLE)
+ dbus_flags |= DBUS_WATCH_READABLE;
+ if (events & VIR_EVENT_HANDLE_WRITABLE)
+ dbus_flags |= DBUS_WATCH_WRITABLE;
+ if (events & VIR_EVENT_HANDLE_ERROR)
+ dbus_flags |= DBUS_WATCH_ERROR;
+ if (events & VIR_EVENT_HANDLE_HANGUP)
+ dbus_flags |= DBUS_WATCH_HANGUP;
+
+ (void)dbus_watch_handle(watch, dbus_flags);
+
+ while (dbus_connection_dispatch(systembus) == DBUS_DISPATCH_DATA_REMAINS)
+ /* keep dispatching while data remains */;
+}
+
+
+static int virDBusTranslateWatchFlags(int dbus_flags)
+{
+ unsigned int flags = 0;
+ if (dbus_flags & DBUS_WATCH_READABLE)
+ flags |= VIR_EVENT_HANDLE_READABLE;
+ if (dbus_flags & DBUS_WATCH_WRITABLE)
+ flags |= VIR_EVENT_HANDLE_WRITABLE;
+ if (dbus_flags & DBUS_WATCH_ERROR)
+ flags |= VIR_EVENT_HANDLE_ERROR;
+ if (dbus_flags & DBUS_WATCH_HANGUP)
+ flags |= VIR_EVENT_HANDLE_HANGUP;
+ return flags;
+}
+
+
+struct virDBusWatch
+{
+ int watch;
+};
+
+static void virDBusWatchFree(void *data) {
+ struct virDBusWatch *info = data;
+ VIR_FREE(info);
+}
+
+static dbus_bool_t virDBusAddWatch(DBusWatch *watch,
+ void *data ATTRIBUTE_UNUSED)
+{
+ int flags = 0;
+ int fd;
+ struct virDBusWatch *info;
+
+ if (VIR_ALLOC(info) < 0)
+ return 0;
+
+ if (dbus_watch_get_enabled(watch))
+ flags = virDBusTranslateWatchFlags(dbus_watch_get_flags(watch));
+
+# if HAVE_DBUS_WATCH_GET_UNIX_FD
+ fd = dbus_watch_get_unix_fd(watch);
+# else
+ fd = dbus_watch_get_fd(watch);
+# endif
+ info->watch = virEventAddHandle(fd, flags,
+ virDBusWatchCallback,
+ watch, NULL);
+ if (info->watch < 0) {
+ VIR_FREE(info);
+ return 0;
+ }
+ dbus_watch_set_data(watch, info, virDBusWatchFree);
+
+ return 1;
+}
+
+
+static void virDBusRemoveWatch(DBusWatch *watch,
+ void *data ATTRIBUTE_UNUSED)
+{
+ struct virDBusWatch *info;
+
+ info = dbus_watch_get_data(watch);
+
+ (void)virEventRemoveHandle(info->watch);
+}
+
+
+static void virDBusToggleWatch(DBusWatch *watch,
+ void *data ATTRIBUTE_UNUSED)
+{
+ int flags = 0;
+ struct virDBusWatch *info;
+
+ if (dbus_watch_get_enabled(watch))
+ flags = virDBusTranslateWatchFlags(dbus_watch_get_flags(watch));
+
+ info = dbus_watch_get_data(watch);
+
+ (void)virEventUpdateHandle(info->watch, flags);
+}
+
+#else /* ! HAVE_DBUS */
+DBusConnection *virDBusGetSystemBus(void)
+{
+ virDBusReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("DBus support not compiled into this binary"));
+ return NULL;
+}
+
+#endif /* ! HAVE_DBUS */
diff --git a/src/util/virdbus.h b/src/util/virdbus.h
new file mode 100644
index 0000000..7d9ec8f
--- /dev/null
+++ b/src/util/virdbus.h
@@ -0,0 +1,34 @@
+/*
+ * virdbus.h: helper for using DBus
+ *
+ * Copyright (C) 2012 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef __VIR_DBUS_H__
+# define __VIR_DBUS_H__
+
+# ifdef HAVE_DBUS
+# include <dbus/dbus.h>
+# else
+# define DBusConnection void
+# endif
+# include "internal.h"
+
+DBusConnection *virDBusGetSystemBus(void);
+
+#endif /* __VIR_DBUS_H__ */
diff --git a/src/util/virterror.c b/src/util/virterror.c
index ff9a36f..de45bb0 100644
--- a/src/util/virterror.c
+++ b/src/util/virterror.c
@@ -184,6 +184,9 @@ static const char *virErrorDomainName(virErrorDomain domain) {
case VIR_FROM_AUTH:
dom = "Auth ";
break;
+ case VIR_FROM_DBUS:
+ dom = "DBus ";
+ break;
}
return dom;
}
--
1.7.7.6
12 years, 10 months
[libvirt] [PATCH] xend_internal: Use domain/status for shutdown check
by Stefan Bader
As promised this version does keep the domid < 0 check in
order to be clearly keeping the old behavior.
-Stefan
>From 18d398d98dc0dc2d9148ffb8673c651248d1bca5 Mon Sep 17 00:00:00 2001
From: Stefan Bader <stefan.bader(a)canonical.com>
Date: Thu, 12 Apr 2012 09:59:56 +0000
Subject: [PATCH] xend_internal: Use domain/status for shutdown check
On newer xend (v3.x and after) there is no state and domid reported
for inactive domains. When initially creating connections this is
handled in various places by assigning domain->id = -1.
But once an instance has been running, the id is set to the current
domain id. And it does not change when the instance is shut down.
So when querying the domain info, the hypervisor driver, which gets
asked first will indicate it cannot find information, then the
xend driver is asked and will set the status to NOSTATE because it
checks for the -1 domain id.
Checking domain/status for 0 seems to be more reliable for that.
One note: I am not sure whether the domain->id also should get set
back to -1 whenever any sub-driver thinks the instance is no longer
running.
BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=746007
BugLink: http://bugs.launchpad.net/bugs/929626
[v2: Keep old id check just in case]
Signed-off-by: Stefan Bader <stefan.bader(a)canonical.com>
---
src/xen/xend_internal.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 6526af4..f1aa9b6 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -989,9 +989,14 @@ sexpr_to_xend_domain_state(virDomainPtr domain, const struct sexpr *root)
state = VIR_DOMAIN_BLOCKED;
else if (strchr(flags, 'r'))
state = VIR_DOMAIN_RUNNING;
- } else if (domain->id < 0) {
- /* Inactive domains don't have a state reported, so
- mark them SHUTOFF, rather than NOSTATE */
+ } else if (domain->id < 0 || sexpr_int(root, "domain/status") == 0) {
+ /* As far as I can see the domain->id is a bad sign for checking
+ * inactive domains as this is inaccurate after the domain has
+ * been running once. However domain/status from xend seems to
+ * be always present and 0 for inactive domains.
+ * (keeping the check for id < 0 to be extra safe about backward
+ * compatibility)
+ */
state = VIR_DOMAIN_SHUTOFF;
}
--
1.7.9.5
12 years, 10 months
[libvirt] [PATCH] Pull DBus event code out into common area
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The policy kit and HAL node device drivers both require a
DBus connection. The HAL device code further requires that
the DBus connection is integrated with the event loop and
provides such glue logic itself.
The forthcoming FirewallD integration also requires a
dbus connection with event loop integration. Thus we need
to pull the current event loop glue out of the HAL driver.
Thus we create src/util/virdbus.{c,h} files. This contains
just one method virDBusGetSystemBus() which obtains a handle
to the single shared system bus instance, with event glue
automagically setup.
NB, I have not actually tested this on a system with HAL or
PolicyKit-0 installed, so it may well not compile. Hopefully
someone on list has a suitable system where they can test
those two. If not, I'll install a VM next week to test it in.
---
.gitignore | 6 ++--
configure.ac | 3 +-
daemon/Makefile.am | 3 +-
daemon/libvirtd.c | 4 ---
src/Makefile.am | 3 +-
src/rpc/virnetserver.c | 6 ----
src/rpc/virnetserver.h | 4 ---
src/util/virdbus.c | 68 ++++++++++++++++++++++-------------------------
8 files changed, 40 insertions(+), 57 deletions(-)
diff --git a/.gitignore b/.gitignore
index 5aa9c9b..14a21d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,12 +48,12 @@
/daemon/*_dispatch.h
/daemon/libvirt_qemud
/daemon/libvirtd
-/daemon/libvirtd.init
-/daemon/libvirtd.service
/daemon/libvirtd*.logrotate
/daemon/libvirtd.8
/daemon/libvirtd.8.in
+/daemon/libvirtd.init
/daemon/libvirtd.pod
+/daemon/libvirtd.service
/docs/devhelp/libvirt.devhelp
/docs/hvsupport.html.in
/docs/libvirt-api.xml
@@ -118,6 +118,7 @@
/tests/eventtest
/tests/hashtest
/tests/jsontest
+/tests/libvirtdconftest
/tests/networkxml2argvtest
/tests/nodeinfotest
/tests/nwfilterxml2xmltest
@@ -150,7 +151,6 @@
/tests/vmx2xmltest
/tests/xencapstest
/tests/xmconfigtest
-/tests/libvirtdconftest
/tools/*.[18]
/tools/libvirt-guests.init
/tools/virsh
diff --git a/configure.ac b/configure.ac
index 3863119..f49b620 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1116,9 +1116,8 @@ if test "$with_dbus" = "yes" || test "$with_dbus" = "check" ; then
AC_MSG_ERROR([You must install DBus >= $DBUS_REQUIRED to compile libvirt])
fi])
fi
-echo ">>>>>>>>>> $with_dbus <<<<<<<<<<<<<<<<<"
+
if test "$with_dbus" = "yes" ; then
-echo ">>>>>>>>>> $with_dbus <<<<<<<<<<<<<<<<<"
AC_DEFINE_UNQUOTED([HAVE_DBUS], 1, [enable communication with DBus])
save_LIBS="$LIBS"
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 5d9f5d7..24cce8f 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -94,7 +94,7 @@ libvirtd_SOURCES = $(DAEMON_SOURCES)
#-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L
libvirtd_CFLAGS = \
$(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) $(SASL_CFLAGS) \
- $(XDR_CFLAGS) $(POLKIT_CFLAGS) \
+ $(XDR_CFLAGS) $(POLKIT_CFLAGS) $(DBUS_CFLAGS) \
$(WARN_CFLAGS) \
$(COVERAGE_CFLAGS) \
-DQEMUD_PID_FILE="\"$(QEMUD_PID_FILE)\"" \
@@ -108,6 +108,7 @@ libvirtd_LDADD = \
$(LIBXML_LIBS) \
$(GNUTLS_LIBS) \
$(SASL_LIBS) \
+ $(DBUS_LIBS) \
$(POLKIT_LIBS)
if WITH_DTRACE_PROBES
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index ce931d4..b098f6a 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -812,7 +812,6 @@ int main(int argc, char **argv) {
struct daemonConfig *config;
bool privileged = geteuid() == 0 ? true : false;
bool implicit_conf = false;
- bool use_polkit_dbus;
char *run_dir = NULL;
mode_t old_umask;
@@ -1008,8 +1007,6 @@ int main(int argc, char **argv) {
goto cleanup;
}
- use_polkit_dbus = config->auth_unix_rw == REMOTE_AUTH_POLKIT ||
- config->auth_unix_ro == REMOTE_AUTH_POLKIT;
if (!(srv = virNetServerNew(config->min_workers,
config->max_workers,
config->prio_workers,
@@ -1018,7 +1015,6 @@ int main(int argc, char **argv) {
config->keepalive_count,
!!config->keepalive_required,
config->mdns_adv ? config->mdns_name : NULL,
- use_polkit_dbus,
remoteClientInitHook))) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
diff --git a/src/Makefile.am b/src/Makefile.am
index c6b7033..b8a19b4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1523,7 +1523,7 @@ libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(AM_LDFLAGS)
libvirt_lxc_LDADD = $(CAPNG_LIBS) $(YAJL_LIBS) \
$(LIBXML_LIBS) $(NUMACTL_LIBS) $(THREAD_LIBS) \
$(LIBNL_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \
- $(RT_LIBS) \
+ $(RT_LIBS) $(DBUS_LIBS) \
../gnulib/lib/libgnu.la
if WITH_DTRACE_PROBES
libvirt_lxc_LDADD += probes.o
@@ -1540,6 +1540,7 @@ libvirt_lxc_CFLAGS = \
$(CAPNG_CFLAGS) \
$(YAJL_CFLAGS) \
$(AUDIT_CFLAGS) \
+ $(DBUS_CFLAGS) \
-I$(top_srcdir)/src/conf \
$(AM_CFLAGS)
if HAVE_LIBBLKID
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index 0e0edd3..3965fc2 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -304,7 +304,6 @@ virNetServerPtr virNetServerNew(size_t min_workers,
unsigned int keepaliveCount,
bool keepaliveRequired,
const char *mdnsGroupName,
- bool connectDBus ATTRIBUTE_UNUSED,
virNetServerClientInitHook clientInitHook)
{
virNetServerPtr srv;
@@ -794,11 +793,6 @@ void virNetServerFree(virNetServerPtr srv)
virNetServerMDNSFree(srv->mdns);
#endif
-#if HAVE_DBUS
- if (srv->sysbus)
- dbus_connection_unref(srv->sysbus);
-#endif
-
virNetServerUnlock(srv);
virMutexDestroy(&srv->lock);
VIR_FREE(srv);
diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h
index a9dec18..0ebe00e 100644
--- a/src/rpc/virnetserver.h
+++ b/src/rpc/virnetserver.h
@@ -25,9 +25,6 @@
# define __VIR_NET_SERVER_H__
# include <signal.h>
-# if HAVE_DBUS
-# include <dbus/dbus.h>
-# endif
# include "virnettlscontext.h"
# include "virnetserverprogram.h"
@@ -45,7 +42,6 @@ virNetServerPtr virNetServerNew(size_t min_workers,
unsigned int keepaliveCount,
bool keepaliveRequired,
const char *mdnsGroupName,
- bool connectDBus,
virNetServerClientInitHook clientInitHook);
typedef int (*virNetServerAutoShutdownFunc)(virNetServerPtr srv, void *opaque);
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
index 636cd45..badfe8c 100644
--- a/src/util/virdbus.c
+++ b/src/util/virdbus.c
@@ -22,6 +22,10 @@
#include <config.h>
#include "virdbus.h"
+#include "memory.h"
+#include "virterror_internal.h"
+#include "logging.h"
+#include "threads.h"
#define VIR_FROM_THIS VIR_FROM_DBUS
@@ -33,7 +37,7 @@
static DBusConnection *systembus = NULL;
static virOnceControl once = VIR_ONCE_CONTROL_INITIALIZER;
-static DBusError err;
+static DBusError dbuserr;
static dbus_bool_t virDBusAddWatch(DBusWatch *watch, void *data);
static void virDBusRemoveWatch(DBusWatch *watch, void *data);
@@ -41,24 +45,21 @@ static void virDBusToggleWatch(DBusWatch *watch, void *data);
static void virDBusSystemBusInit(void)
{
- DBusConnection *dbus_conn = NULL;
- DBusError err;
-
/* Allocate and initialize a new HAL context */
dbus_connection_set_change_sigpipe(FALSE);
dbus_threads_init_default();
- dbus_error_init(&err);
- if (!(systembus = dbus_bus_get(DBUS_BUS_SYSTEM, &err)))
+ dbus_error_init(&dbuserr);
+ if (!(systembus = dbus_bus_get(DBUS_BUS_SYSTEM, &dbuserr)))
return;
dbus_connection_set_exit_on_disconnect(systembus, FALSE);
/* Register dbus watch callbacks */
if (!dbus_connection_set_watch_functions(systembus,
- add_dbus_watch,
- remove_dbus_watch,
- toggle_dbus_watch,
+ virDBusAddWatch,
+ virDBusRemoveWatch,
+ virDBusToggleWatch,
NULL, NULL)) {
systembus = NULL;
return;
@@ -77,7 +78,7 @@ DBusConnection *virDBusGetSystemBus(void)
if (!systembus) {
virDBusReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to get DBus system bus connection: %s"),
- err->message ? err->message : "watch setup failed");
+ dbuserr.message ? dbuserr.message : "watch setup failed");
return NULL;
}
@@ -85,13 +86,11 @@ DBusConnection *virDBusGetSystemBus(void)
}
-static void dbus_watch_callback(int fdatch ATTRIBUTE_UNUSED,
- int fd ATTRIBUTE_UNUSED,
- int events, void *opaque)
+static void virDBusWatchCallback(int fdatch ATTRIBUTE_UNUSED,
+ int fd ATTRIBUTE_UNUSED,
+ int events, void *opaque)
{
DBusWatch *watch = opaque;
- LibHalContext *hal_ctx;
- DBusConnection *dbus_conn;
int dbus_flags = 0;
if (events & VIR_EVENT_HANDLE_READABLE)
@@ -105,16 +104,12 @@ static void dbus_watch_callback(int fdatch ATTRIBUTE_UNUSED,
(void)dbus_watch_handle(watch, dbus_flags);
- nodeDeviceLock(driverState);
- hal_ctx = DRV_STATE_HAL_CTX(driverState);
- dbus_conn = libhal_ctx_get_dbus_connection(hal_ctx);
- nodeDeviceUnlock(driverState);
- while (dbus_connection_dispatch(dbus_conn) == DBUS_DISPATCH_DATA_REMAINS)
+ while (dbus_connection_dispatch(systembus) == DBUS_DISPATCH_DATA_REMAINS)
/* keep dispatching while data remains */;
}
-static int xlate_dbus_watch_flags(int dbus_flags)
+static int virDBusTranslateWatchFlags(int dbus_flags)
{
unsigned int flags = 0;
if (dbus_flags & DBUS_WATCH_READABLE)
@@ -129,50 +124,51 @@ static int xlate_dbus_watch_flags(int dbus_flags)
}
-struct nodeDeviceWatchInfo
+struct virDBusWatch
{
int watch;
};
-static void nodeDeviceWatchFree(void *data) {
- struct nodeDeviceWatchInfo *info = data;
+static void virDBusWatchFree(void *data) {
+ struct virDBusWatch *info = data;
VIR_FREE(info);
}
-static dbus_bool_t add_dbus_watch(DBusWatch *watch,
+static dbus_bool_t virDBusAddWatch(DBusWatch *watch,
void *data ATTRIBUTE_UNUSED)
{
int flags = 0;
int fd;
- struct nodeDeviceWatchInfo *info;
+ struct virDBusWatch *info;
if (VIR_ALLOC(info) < 0)
return 0;
if (dbus_watch_get_enabled(watch))
- flags = xlate_dbus_watch_flags(dbus_watch_get_flags(watch));
+ flags = virDBusTranslateWatchFlags(dbus_watch_get_flags(watch));
# if HAVE_DBUS_WATCH_GET_UNIX_FD
fd = dbus_watch_get_unix_fd(watch);
# else
fd = dbus_watch_get_fd(watch);
# endif
- info->watch = virEventAddHandle(fd, flags, dbus_watch_callback,
+ info->watch = virEventAddHandle(fd, flags,
+ virDBusWatchCallback,
watch, NULL);
if (info->watch < 0) {
VIR_FREE(info);
return 0;
}
- dbus_watch_set_data(watch, info, nodeDeviceWatchFree);
+ dbus_watch_set_data(watch, info, virDBusWatchFree);
return 1;
}
-static void remove_dbus_watch(DBusWatch *watch,
- void *data ATTRIBUTE_UNUSED)
+static void virDBusRemoveWatch(DBusWatch *watch,
+ void *data ATTRIBUTE_UNUSED)
{
- struct nodeDeviceWatchInfo *info;
+ struct virDBusWatch *info;
info = dbus_watch_get_data(watch);
@@ -180,14 +176,14 @@ static void remove_dbus_watch(DBusWatch *watch,
}
-static void toggle_dbus_watch(DBusWatch *watch,
- void *data ATTRIBUTE_UNUSED)
+static void virDBusToggleWatch(DBusWatch *watch,
+ void *data ATTRIBUTE_UNUSED)
{
int flags = 0;
- struct nodeDeviceWatchInfo *info;
+ struct virDBusWatch *info;
if (dbus_watch_get_enabled(watch))
- flags = xlate_dbus_watch_flags(dbus_watch_get_flags(watch));
+ flags = virDBusTranslateWatchFlags(dbus_watch_get_flags(watch));
info = dbus_watch_get_data(watch);
--
1.7.7.6
12 years, 10 months
[libvirt] [PATCH] qemu, util fix netlink callback registration for migration
by D. Herrendoerfer
From: "D. Herrendoerfer" <d.herrendoerfer(a)herrendoerfer.name>
This patch adds a netlink callback when migrating a VEPA enabled
virtual machine.
It fixes a Bug where a VM would not request a port association when
it was cleared by lldpad.
This patch requires the latest git version of lldpad to work.
Signed-off-by: D. Herrendoerfer <d.herrendoerfer(a)herrendoerfer.name>
---
src/qemu/qemu_migration.c | 6 ++++++
src/util/virnetdevmacvlan.c | 14 +++++++++++++-
src/util/virnetdevmacvlan.h | 8 ++++++++
3 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 77d40c0..7a8a7c4 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2654,6 +2654,12 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def) {
def->uuid,
VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_FINISH, false) < 0)
goto err_exit;
+
+ if (virNetDevMacVLanVPortProfileRegisterCallback(net->ifname, net->mac,
+ virDomainNetGetActualDirectDev(net), def->uuid,
+ virDomainNetGetActualVirtPortProfile(net),
+ VIR_NETDEV_VPORT_PROFILE_OP_CREATE))
+ goto err_exit;
}
last_good_net = i;
}
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 90888b0..b259e00 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -769,7 +769,7 @@ virNetDevMacVLanVPortProfileDestroyCallback(int watch ATTRIBUTE_UNUSED,
virNetlinkCallbackDataFree((virNetlinkCallbackDataPtr)opaque);
}
-static int
+int
virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
const unsigned char *macaddress,
const char *linkdev,
@@ -1125,4 +1125,16 @@ int virNetDevMacVLanRestartWithVPortProfile(const char *cr_ifname ATTRIBUTE_UNUS
_("Cannot create macvlan devices on this platform"));
return -1;
}
+
+int virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname ATTRIBUTE_UNUSED,
+ const unsigned char *macaddress ATTRIBUTE_UNUSED,
+ const char *linkdev ATTRIBUTE_UNUSED,
+ const unsigned char *vmuuid ATTRIBUTE_UNUSED,
+ virNetDevVPortProfilePtr virtPortProfile ATTRIBUTE_UNUSED,
+ enum virNetDevVPortProfileOp vmOp ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Cannot create macvlan devices on this platform"));
+ return -1;
+}
#endif /* ! WITH_MACVTAP */
diff --git a/src/util/virnetdevmacvlan.h b/src/util/virnetdevmacvlan.h
index 14640cf..2299f1d 100644
--- a/src/util/virnetdevmacvlan.h
+++ b/src/util/virnetdevmacvlan.h
@@ -84,4 +84,12 @@ int virNetDevMacVLanRestartWithVPortProfile(const char *cr_ifname,
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK;
+int virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
+ const unsigned char *macaddress ,
+ const char *linkdev,
+ const unsigned char *vmuuid,
+ virNetDevVPortProfilePtr virtPortProfile,
+ enum virNetDevVPortProfileOp vmOp)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
+ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK;
#endif /* __UTIL_MACVTAP_H__ */
--
1.7.7.6
12 years, 10 months
[libvirt] [PATCH] qemu_agent: Report error class at least
by Michal Privoznik
Currently, qemu GA is not providing 'desc' field for errors like
we are used to from qemu monitor. Therefore, we fall back to this
general 'unknown error' string. However, GA is reporting 'class' which
is not perfect, but much more helpful than generic error string.
Thus we should fall back to class firstly and if even no class
is presented, then we can fall back to that generic string.
Before this patch:
virsh # dompmsuspend --target mem f16
error: Domain f16 could not be suspended
error: internal error unable to execute QEMU command
'guest-suspend-ram': unknown QEMU command error
After this patch:
virsh # dompmsuspend --target mem f16
error: Domain f16 could not be suspended
error: internal error unable to execute QEMU command
'guest-suspend-ram': CommandNotFound
---
src/qemu/qemu_agent.c | 14 ++++++--------
1 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index b759b7f..decfd0e 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1035,19 +1035,17 @@ static const char *
qemuAgentStringifyError(virJSONValuePtr error)
{
const char *klass = virJSONValueObjectGetString(error, "class");
- const char *detail = NULL;
+ const char *detail = virJSONValueObjectGetString(error, "desc");
/* The QMP 'desc' field is usually sufficient for our generic
- * error reporting needs.
+ * error reporting needs. However, older agents did not provide
+ * any 'desc'. Reporting 'class' is not perfect but better
+ * than bare 'unknown error'.
*/
- if (klass)
- detail = virJSONValueObjectGetString(error, "desc");
-
-
- if (!detail)
+ if (!detail && !klass)
detail = "unknown QEMU command error";
- return detail;
+ return detail ? detail : klass;
}
static const char *
--
1.7.8.5
12 years, 10 months
[libvirt] [PATCH] qemuOpenFile: Don't force chown on NFS
by Michal Privoznik
If dynamic_ownership is off and we are creating a file on NFS
we force chown. This will fail as chown/chmod are not supported
on NFS. However, with no dynamic_ownership we are not required
to do any chown.
---
src/qemu/qemu_driver.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d9e35be..1b55eb1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2429,6 +2429,7 @@ qemuOpenFile(struct qemud_driver *driver, const char *path, int oflags,
bool bypass_security = false;
unsigned int vfoflags = 0;
int fd = -1;
+ int path_shared = virStorageFileIsSharedFS(path);
uid_t uid = getuid();
gid_t gid = getgid();
@@ -2437,7 +2438,12 @@ qemuOpenFile(struct qemud_driver *driver, const char *path, int oflags,
* in the failure case */
if (oflags & O_CREAT) {
need_unlink = true;
- vfoflags |= VIR_FILE_OPEN_FORCE_OWNER;
+
+ /* Don't force chown on network-shared FS
+ * as it is likely to fail. */
+ if (path_shared <= 0 || driver->dynamicOwnership)
+ vfoflags |= VIR_FILE_OPEN_FORCE_OWNER;
+
if (stat(path, &sb) == 0) {
is_reg = !!S_ISREG(sb.st_mode);
/* If the path is regular file which exists
@@ -2475,7 +2481,7 @@ qemuOpenFile(struct qemud_driver *driver, const char *path, int oflags,
}
/* On Linux we can also verify the FS-type of the directory. */
- switch (virStorageFileIsSharedFS(path)) {
+ switch (path_shared) {
case 1:
/* it was on a network share, so we'll continue
* as outlined above
--
1.7.8.5
12 years, 10 months
[libvirt] [libvirt-glib] Explicitly link conn-test against libvirt-gconfig libvirt-glib
by Guido Günther
otherwise the build fails with:
$ CCLD conn-test
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_domain_new_from_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_set_error(a)LIBVIRT_GLIB_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_network_new_from_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_storage_pool_new_from_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_init_check(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_domain_get_type(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_object_to_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_event_register(a)LIBVIRT_GLIB_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_init_check(a)LIBVIRT_GLIB_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_domain_get_devices(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_storage_vol_new_from_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_secret_new_from_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_interface_new_from_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_domain_disk_get_type(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_domain_disk_get_target_dev(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_domain_interface_get_type(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_node_device_new_from_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_domain_device_get_type(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_object_get_type(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_error_new_literal(a)LIBVIRT_GLIB_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_domain_snapshot_new_from_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_network_filter_new_from_xml(a)LIBVIRT_GCONFIG_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_set_error_literal(a)LIBVIRT_GLIB_0.0.4'
../libvirt-gobject/.libs/libvirt-gobject-1.0.so: undefined reference to `gvir_config_domain_interface_get_ifname(a)LIBVIRT_GCONFIG_0.0.4'
collect2: ld returned 1 exit status
---
examples/Makefile.am | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/examples/Makefile.am b/examples/Makefile.am
index b77076d..37a8447 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -25,6 +25,8 @@ conn_test_SOURCES = \
conn-test.c
conn_test_LDADD = \
../libvirt-gobject/libvirt-gobject-1.0.la \
+ ../libvirt-gconfig/libvirt-gconfig-1.0.la \
+ ../libvirt-glib/libvirt-glib-1.0.la \
$(LIBVIRT_LIBS) \
$(GLIB2_LIBS) \
$(GOBJECT2_LIBS)
--
1.7.9.1
12 years, 10 months