$(top_srcdir)/src/libvirt-stream.c \
$(top_srcdir)/src/libvirt-lxc.c \
$(top_srcdir)/src/libvirt-qemu.c \
- $(top_srcdir)/src/libvirt-admin.c \
+ $(top_srcdir)/src/admin/libvirt-admin.c \
$(top_srcdir)/src/util/virerror.c \
$(top_srcdir)/src/util/virevent.c \
$(top_srcdir)/src/util/virtypedparam-public.c
admin_included_files = {
"libvirt-admin.h": "header with admin specific API definitions",
- "libvirt-admin.c": "Implementations for the admin specific APIs",
+ "admin/libvirt-admin.c": "Implementations for the admin specific APIs",
}
ignored_words = {
if not quiet:
print("Rebuilding API description for %s" % name)
dirs = [srcdir + "/../src",
+ srcdir + "/../src/admin",
srcdir + "/../src/util",
srcdir + "/../include/libvirt"]
if (builddir and
AC_DEFUN([LIBVIRT_WIN_CHECK_SYMBOLS], [
LIBVIRT_SYMBOL_FILE=libvirt.syms
- LIBVIRT_ADMIN_SYMBOL_FILE=libvirt_admin.syms
+ LIBVIRT_ADMIN_SYMBOL_FILE=admin/libvirt_admin.syms
LIBVIRT_LXC_SYMBOL_FILE='$(srcdir)/libvirt_lxc.syms'
LIBVIRT_QEMU_SYMBOL_FILE='$(srcdir)/libvirt_qemu.syms'
case "$host" in
# from libvirt.syms and passes libvirt.def instead of libvirt.syms to the
# linker
LIBVIRT_SYMBOL_FILE=libvirt.def
- LIBVIRT_ADMIN_SYMBOL_FILE=libvirt_admin.def
+ LIBVIRT_ADMIN_SYMBOL_FILE=admin/libvirt_admin.def
LIBVIRT_LXC_SYMBOL_FILE=libvirt_lxc.def
LIBVIRT_QEMU_SYMBOL_FILE=libvirt_qemu.def
;;
src/admin/admin_server.c
src/admin/admin_server_dispatch.c
src/admin/admin_server_dispatch_stubs.h
+src/admin/libvirt-admin.c
src/bhyve/bhyve_capabilities.c
src/bhyve/bhyve_command.c
src/bhyve/bhyve_device.c
src/interface/interface_backend_netcf.c
src/interface/interface_backend_udev.c
src/internal.h
-src/libvirt-admin.c
src/libvirt-domain-checkpoint.c
src/libvirt-domain-snapshot.c
src/libvirt-domain.c
nodist_conf_DATA =
DRIVER_SOURCE_FILES =
STATEFUL_DRIVER_SOURCE_FILES =
+lib_LTLIBRARIES =
noinst_LTLIBRARIES =
mod_LTLIBRARIES =
INSTALL_DATA_DIRS =
endif WITH_SECDRIVER_APPARMOR
-lib_LTLIBRARIES = libvirt.la libvirt-qemu.la libvirt-lxc.la
+lib_LTLIBRARIES += libvirt.la libvirt-qemu.la libvirt-lxc.la
moddir = $(libdir)/libvirt/connection-driver
confdir = $(sysconfdir)/libvirt
-conf_DATA += libvirt.conf libvirt-admin.conf
+conf_DATA += libvirt.conf
CLEANFILES += $(nodist_conf_DATA)
BUILT_SOURCES += $(nodist_conf_DATA)
check-symfile: libvirt.syms libvirt.la
$(AM_V_GEN)$(PERL) $(srcdir)/check-symfile.pl libvirt.syms \
.libs/libvirt.so
-check-admin-symfile: libvirt_admin.syms libvirt-admin.la
- $(AM_V_GEN)$(PERL) $(srcdir)/check-symfile.pl libvirt_admin.syms \
- .libs/libvirt-admin.so
else ! WITH_LINUX
check-symfile:
-check-admin-symfile:
endif ! WITH_LINUX
check-symsorting:
$(AM_V_GEN)$(PERL) $(srcdir)/check-symsorting.pl \
$(srcdir) $(SYM_FILES)
-check-admin-symsorting:
- $(AM_V_GEN)$(PERL) $(srcdir)/check-symsorting.pl \
- $(srcdir) $(ADMIN_SYM_FILES)
EXTRA_DIST += check-symfile.pl check-symsorting.pl
# Keep this list synced with RPC_PROBE_FILES
$(AM_V_GEN)$(PERL) $(srcdir)/check-drivername.pl \
$(srcdir)/driver.h \
$(srcdir)/libvirt_public.syms \
- $(srcdir)/libvirt_admin_public.syms \
$(srcdir)/libvirt_qemu.syms \
$(srcdir)/libvirt_lxc.syms
check-local: check-protocol check-symfile check-symsorting \
check-drivername check-driverimpls check-aclrules \
- check-aclperms check-admin-symfile check-admin-symsorting
+ check-aclperms check-admin
.PHONY: check-protocol $(PROTOCOL_STRUCTS:structs=struct)
USED_SYM_FILES += $(srcdir)/libvirt_private.syms
GENERATED_SYM_FILES += \
libvirt.syms libvirt.def libvirt_qemu.def libvirt_lxc.def \
- libvirt_admin.syms libvirt_admin.def \
$(NULL)
libvirt_public.syms \
libvirt_lxc.syms \
libvirt_qemu.syms \
- libvirt_admin_public.syms \
$(SYM_FILES) \
- $(ADMIN_SYM_FILES) \
$(NULL)
BUILT_SOURCES += $(GENERATED_SYM_FILES)
chmod a-w $@-tmp && \
mv $@-tmp $@
-libvirt_admin.syms: libvirt_admin_public.syms $(ADMIN_SYM_FILES) \
- $(top_builddir)/config.status
- $(AM_V_GEN)rm -f $@-tmp $@ ; \
- printf '# WARNING: generated from the following:\n# $^\n\n' >$@-tmp && \
- cat $(srcdir)/libvirt_admin_public.syms >>$@-tmp && \
- printf '\n\n# Private symbols\n\n' >>$@-tmp && \
- printf 'LIBVIRT_ADMIN_PRIVATE_$(VERSION) {\n\n' >>$@-tmp && \
- printf 'global:\n\n' >>$@-tmp && \
- cat $(ADMIN_SYM_FILES) >>$@-tmp && \
- printf '\n\nlocal:\n*;\n\n};' >>$@-tmp && \
- chmod a-w $@-tmp && \
- mv $@-tmp libvirt_admin.syms
-
-
-lib_LTLIBRARIES += libvirt-admin.la
-libvirt_admin_la_SOURCES = \
- libvirt-admin.c \
- $(ADMIN_PROTOCOL_GENERATED) \
- $(DATATYPES_SOURCES)
-
-libvirt_admin_la_LDFLAGS = \
- $(VERSION_SCRIPT_FLAGS)$(LIBVIRT_ADMIN_SYMBOL_FILE) \
- -version-info $(LIBVIRT_VERSION_INFO) \
- $(LIBVIRT_NODELETE) \
- $(AM_LDFLAGS) \
- $(NULL)
-
-libvirt_admin_la_LIBADD = \
- libvirt.la \
- $(CYGWIN_EXTRA_LIBADD)
-
-libvirt_admin_la_CFLAGS = \
- $(AM_CFLAGS) \
- -I$(srcdir)/remote \
- -I$(srcdir)/rpc \
- -I$(srcdir)/admin
-
-libvirt_admin_la_CFLAGS += \
- $(XDR_CFLAGS) \
- $(CAPNG_CFLAGS) \
- $(YAJL_CFLAGS) \
- $(SSH2_CFLAGS) \
- $(SASL_CFLAGS) \
- $(GNUTLS_CFLAGS) \
- $(LIBSSH_CFLAGS)
-
-libvirt_admin_la_LIBADD += \
- $(CAPNG_LIBS) \
- $(YAJL_LIBS) \
- $(DEVMAPPER_LIBS) \
- $(LIBXML_LIBS) \
- $(GLIB_LIBS) \
- $(SSH2_LIBS) \
- $(SASL_LIBS) \
- $(GNUTLS_LIBS) \
- $(LIBSSH_LIBS)
-
-ADMIN_SYM_FILES = $(srcdir)/libvirt_admin_private.syms
-
-if WITH_DTRACE_PROBES
-libvirt_admin_la_LIBADD += libvirt_probes.lo
-endif WITH_DTRACE_PROBES
-
# Empty source list - it merely links a bunch of convenience libs together
libvirt_la_SOURCES =
libvirt_la_LDFLAGS = \
$(NULL)
endif WITH_SASL
-# admin/admin_remote.c is being included in libvirt-admin.c, so we
+GENERATED_SYM_FILES += admin/libvirt_admin.syms admin/libvirt_admin.def
+
+ADMIN_SYM_FILES = $(srcdir)/admin/libvirt_admin_private.syms
+
+# admin/admin_remote.c is being included in admin/libvirt-admin.c, so we
# need to include it in the dist
-EXTRA_DIST += admin/admin_remote.c
+EXTRA_DIST += \
+ admin/admin_remote.c \
+ admin/libvirt_admin_public.syms \
+ $(ADMIN_SYM_FILES) \
+ $(NULL)
+
+conf_DATA += admin/libvirt-admin.conf
+
+lib_LTLIBRARIES += libvirt-admin.la
+
+libvirt_admin_la_SOURCES = \
+ admin/libvirt-admin.c \
+ $(ADMIN_PROTOCOL_GENERATED) \
+ $(DATATYPES_SOURCES)
+
+libvirt_admin_la_LDFLAGS = \
+ $(VERSION_SCRIPT_FLAGS)$(LIBVIRT_ADMIN_SYMBOL_FILE) \
+ -version-info $(LIBVIRT_VERSION_INFO) \
+ $(LIBVIRT_NODELETE) \
+ $(AM_LDFLAGS) \
+ $(NULL)
+
+libvirt_admin_la_LIBADD = \
+ libvirt.la \
+ $(CYGWIN_EXTRA_LIBADD) \
+ $(CAPNG_LIBS) \
+ $(YAJL_LIBS) \
+ $(DEVMAPPER_LIBS) \
+ $(LIBXML_LIBS) \
+ $(GLIB_LIBS) \
+ $(SSH2_LIBS) \
+ $(SASL_LIBS) \
+ $(GNUTLS_LIBS) \
+ $(LIBSSH_LIBS)
+if WITH_DTRACE_PROBES
+libvirt_admin_la_LIBADD += libvirt_probes.lo
+endif WITH_DTRACE_PROBES
+
+libvirt_admin_la_CFLAGS = \
+ $(AM_CFLAGS) \
+ -I$(srcdir)/remote \
+ -I$(srcdir)/rpc \
+ $(XDR_CFLAGS) \
+ $(CAPNG_CFLAGS) \
+ $(YAJL_CFLAGS) \
+ $(SSH2_CFLAGS) \
+ $(SASL_CFLAGS) \
+ $(GNUTLS_CFLAGS) \
+ $(LIBSSH_CFLAGS)
+
+if WITH_LINUX
+check-admin-symfile: admin/libvirt_admin.syms libvirt-admin.la
+ $(AM_V_GEN)$(PERL) $(srcdir)/check-symfile.pl admin/libvirt_admin.syms \
+ .libs/libvirt-admin.so
+else ! WITH_LINUX
+check-admin-symfile:
+endif ! WITH_LINUX
+
+check-admin-symsorting:
+ $(AM_V_GEN)$(PERL) $(srcdir)/check-symsorting.pl \
+ $(srcdir) $(ADMIN_SYM_FILES)
+
+check-admin-drivername:
+ $(AM_V_GEN)$(PERL) $(srcdir)/check-drivername.pl \
+ $(srcdir)/admin/libvirt_admin_public.syms
+
+check-admin: check-admin-symfile check-admin-symsorting check-admin-drivername
admin/admin_client.h: $(srcdir)/rpc/gendispatch.pl \
$(ADMIN_PROTOCOL) Makefile.am
$(AM_V_GEN)$(PERL) -w $(srcdir)/rpc/gendispatch.pl --mode=server \
admin ADMIN $(ADMIN_PROTOCOL) \
> $(srcdir)/admin/admin_server_dispatch_stubs.h
+
+admin/libvirt_admin.syms: admin/libvirt_admin_public.syms $(ADMIN_SYM_FILES) \
+ $(top_builddir)/config.status
+ $(AM_V_GEN)rm -f $@-tmp $@ ; \
+ printf '# WARNING: generated from the following:\n# $^\n\n' >$@-tmp && \
+ cat $(srcdir)/admin/libvirt_admin_public.syms >>$@-tmp && \
+ printf '\n\n# Private symbols\n\n' >>$@-tmp && \
+ printf 'LIBVIRT_ADMIN_PRIVATE_$(VERSION) {\n\n' >>$@-tmp && \
+ printf 'global:\n\n' >>$@-tmp && \
+ cat $(ADMIN_SYM_FILES) >>$@-tmp && \
+ printf '\n\nlocal:\n*;\n\n};' >>$@-tmp && \
+ chmod a-w $@-tmp && \
+ mv $@-tmp admin/libvirt_admin.syms
--- /dev/null
+/*
+ * libvirt-admin.c
+ *
+ * Copyright (C) 2014-2015 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, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "internal.h"
+#include "datatypes.h"
+#include "configmake.h"
+
+#include "viralloc.h"
+#include "virconf.h"
+#include "virlog.h"
+#include "virnetclient.h"
+#include "virobject.h"
+#include "virstring.h"
+#include "viruri.h"
+#include "virutil.h"
+#include "viruuid.h"
+
+#define VIR_FROM_THIS VIR_FROM_ADMIN
+
+
+VIR_LOG_INIT("libvirt-admin");
+
+#include "admin_remote.c"
+
+static bool virAdmGlobalError;
+static virOnceControl virAdmGlobalOnce = VIR_ONCE_CONTROL_INITIALIZER;
+
+static void
+virAdmGlobalInit(void)
+{
+ /* It would be nice if we could trace the use of this call, to
+ * help diagnose in log files if a user calls something other than
+ * virAdmConnectOpen first. But we can't rely on VIR_DEBUG working
+ * until after initialization is complete, and since this is
+ * one-shot, we never get here again. */
+ if (virErrorInitialize() < 0)
+ goto error;
+
+ virLogSetFromEnv();
+
+#ifdef HAVE_LIBINTL_H
+ if (!bindtextdomain(PACKAGE, LOCALEDIR))
+ goto error;
+#endif /* HAVE_LIBINTL_H */
+
+ if (!VIR_CLASS_NEW(remoteAdminPriv, virClassForObjectLockable()))
+ goto error;
+
+ return;
+ error:
+ virAdmGlobalError = true;
+}
+
+/**
+ * virAdmInitialize:
+ *
+ * Initialize the library.
+ *
+ * This method is automatically invoked by virAdmConnectOpen() API. Therefore,
+ * in most cases it is unnecessary to call this method manually, unless an
+ * event loop should be set up by calling virEventRegisterImpl() or the error
+ * reporting of the first connection attempt with virSetErrorFunc() should be
+ * altered prior to setting up connections. If the latter is the case, it is
+ * necessary for the application to call virAdmInitialize.
+ *
+ * Returns 0 in case of success, -1 in case of error
+ */
+int
+virAdmInitialize(void)
+{
+ if (virOnce(&virAdmGlobalOnce, virAdmGlobalInit) < 0)
+ return -1;
+
+ if (virAdmGlobalError)
+ return -1;
+
+ return 0;
+}
+
+static char *
+getSocketPath(virURIPtr uri)
+{
+ char *rundir = virGetUserRuntimeDirectory();
+ char *sock_path = NULL;
+ size_t i = 0;
+
+ if (!uri)
+ goto cleanup;
+
+
+ for (i = 0; i < uri->paramsCount; i++) {
+ virURIParamPtr param = &uri->params[i];
+
+ if (STREQ(param->name, "socket")) {
+ VIR_FREE(sock_path);
+ sock_path = g_strdup(param->value);
+ } else {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unknown URI parameter '%s'"), param->name);
+ goto error;
+ }
+ }
+
+ if (!sock_path) {
+ g_autofree char *sockbase = NULL;
+ bool legacy = false;
+
+ if (!uri->scheme) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ "%s", _("No URI scheme specified"));
+ goto error;
+ }
+ if (STREQ(uri->scheme, "libvirtd")) {
+ legacy = true;
+ } else if (!STRPREFIX(uri->scheme, "virt")) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported URI scheme '%s'"),
+ uri->scheme);
+ goto error;
+ }
+
+ if (legacy) {
+ sockbase = g_strdup("libvirt-admin-sock");
+ } else {
+ if (virAsprintf(&sockbase, "%s-admin-sock", uri->scheme) < 0)
+ goto error;
+ }
+
+ if (STREQ_NULLABLE(uri->path, "/system")) {
+ if (virAsprintf(&sock_path, RUNSTATEDIR "/libvirt/%s",
+ sockbase) < 0)
+ goto error;
+ } else if (STREQ_NULLABLE(uri->path, "/session")) {
+ if (!rundir || virAsprintf(&sock_path, "%s/%s", rundir,
+ sockbase) < 0)
+ goto error;
+ } else {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid URI path '%s', try '/system'"),
+ NULLSTR_EMPTY(uri->path));
+ goto error;
+ }
+ }
+
+ cleanup:
+ VIR_FREE(rundir);
+ return sock_path;
+
+ error:
+ VIR_FREE(sock_path);
+ goto cleanup;
+}
+
+static int
+virAdmGetDefaultURI(virConfPtr conf, char **uristr)
+{
+ const char *defname = getenv("LIBVIRT_ADMIN_DEFAULT_URI");
+ if (defname && *defname) {
+ *uristr = g_strdup(defname);
+ VIR_DEBUG("Using LIBVIRT_ADMIN_DEFAULT_URI '%s'", *uristr);
+ } else {
+ if (virConfGetValueString(conf, "uri_default", uristr) < 0)
+ return -1;
+
+ if (*uristr) {
+ VIR_DEBUG("Using config file uri '%s'", *uristr);
+ } else {
+ /* Since we can't probe connecting via any hypervisor driver as libvirt
+ * does, if no explicit URI was given and neither the environment
+ * variable, nor the configuration parameter had previously been set,
+ * we set the default admin server URI to 'libvirtd:///system' or
+ * 'libvirtd:///session' depending on the process's EUID.
+ */
+ if (geteuid() == 0) {
+ *uristr = g_strdup("libvirtd:///system");
+ } else {
+ *uristr = g_strdup("libvirtd:///session");
+ }
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * virAdmConnectOpen:
+ * @name: uri of the daemon to connect to, NULL for default
+ * @flags: bitwise-OR of virConnectFlags; so far the only supported flag is
+ * VIR_CONNECT_NO_ALIASES
+ *
+ * Opens connection to admin interface of the daemon.
+ *
+ * Returns @virAdmConnectPtr object or NULL on error
+ */
+virAdmConnectPtr
+virAdmConnectOpen(const char *name, unsigned int flags)
+{
+ char *sock_path = NULL;
+ char *alias = NULL;
+ virAdmConnectPtr conn = NULL;
+ g_autoptr(virConf) conf = NULL;
+ char *uristr = NULL;
+
+ if (virAdmInitialize() < 0)
+ goto error;
+
+ VIR_DEBUG("name=%s flags=0x%x", NULLSTR(name), flags);
+ virResetLastError();
+
+ if (!(conn = virAdmConnectNew()))
+ goto error;
+
+ if (virConfLoadConfig(&conf, "libvirt-admin.conf") < 0)
+ goto error;
+
+ if (name) {
+ uristr = g_strdup(name);
+ } else {
+ if (virAdmGetDefaultURI(conf, &uristr) < 0)
+ goto error;
+ }
+
+ if ((!(flags & VIR_CONNECT_NO_ALIASES) &&
+ virURIResolveAlias(conf, uristr, &alias) < 0))
+ goto error;
+
+ if (alias) {
+ VIR_FREE(uristr);
+ uristr = alias;
+ }
+
+ if (!(conn->uri = virURIParse(uristr)))
+ goto error;
+
+ if (!(sock_path = getSocketPath(conn->uri)))
+ goto error;
+
+ if (!(conn->privateData = remoteAdminPrivNew(sock_path)))
+ goto error;
+
+ conn->privateDataFreeFunc = remoteAdminPrivFree;
+
+ if (remoteAdminConnectOpen(conn, flags) < 0)
+ goto error;
+
+ cleanup:
+ VIR_FREE(sock_path);
+ VIR_FREE(uristr);
+ return conn;
+
+ error:
+ virDispatchError(NULL);
+ virObjectUnref(conn);
+ conn = NULL;
+ goto cleanup;
+}
+
+/**
+ * virAdmConnectClose:
+ * @conn: pointer to admin connection to close
+ *
+ * This function closes the admin connection to the Hypervisor. This should not
+ * be called if further interaction with the Hypervisor are needed especially if
+ * there is running domain which need further monitoring by the application.
+ *
+ * Connections are reference counted; the count is explicitly increased by the
+ * initial virAdmConnectOpen, as well as virAdmConnectRef; it is also temporarily
+ * increased by other API that depend on the connection remaining alive. The
+ * open and every virAdmConnectRef call should have a matching
+ * virAdmConnectClose, and all other references will be released after the
+ * corresponding operation completes.
+ *
+ * Returns a positive number if at least 1 reference remains on success. The
+ * returned value should not be assumed to be the total reference count. A
+ * return of 0 implies no references remain and the connection is closed and
+ * memory has been freed. A return of -1 implies a failure.
+ *
+ * It is possible for the last virAdmConnectClose to return a positive value if
+ * some other object still has a temporary reference to the connection, but the
+ * application should not try to further use a connection after the
+ * virAdmConnectClose that matches the initial open.
+ */
+int
+virAdmConnectClose(virAdmConnectPtr conn)
+{
+ VIR_DEBUG("conn=%p", conn);
+
+ virResetLastError();
+ if (!conn)
+ return 0;
+
+ virCheckAdmConnectReturn(conn, -1);
+
+ if (!virObjectUnref(conn))
+ return 0;
+ return 1;
+}
+
+
+/**
+ * virAdmConnectRef:
+ * @conn: the connection to hold a reference on
+ *
+ * Increment the reference count on the connection. For each additional call to
+ * this method, there shall be a corresponding call to virAdmConnectClose to
+ * release the reference count, once the caller no longer needs the reference to
+ * this object.
+ *
+ * This method is typically useful for applications where multiple threads are
+ * using a connection, and it is required that the connection remain open until
+ * all threads have finished using it. I.e., each new thread using a connection
+ * would increment the reference count.
+ *
+ * Returns 0 in case of success, -1 in case of failure
+ */
+int
+virAdmConnectRef(virAdmConnectPtr conn)
+{
+ VIR_DEBUG("conn=%p refs=%d", conn,
+ conn ? conn->parent.parent.u.s.refs : 0);
+
+ virResetLastError();
+ virCheckAdmConnectReturn(conn, -1);
+
+ virObjectRef(conn);
+
+ return 0;
+}
+
+/**
+ * virAdmGetVersion:
+ * @libVer: where to store the library version
+ *
+ * Provides version information. @libVer is the version of the library and will
+ * always be set unless an error occurs in which case an error code and a
+ * generic message will be returned. @libVer format is as follows:
+ * major * 1,000,000 + minor * 1,000 + release.
+ *
+ * NOTE: To get the remote side library version use virAdmConnectGetLibVersion
+ * instead.
+ *
+ * Returns 0 on success, -1 in case of an error.
+ */
+int
+virAdmGetVersion(unsigned long long *libVer)
+{
+ if (virAdmInitialize() < 0)
+ goto error;
+
+ VIR_DEBUG("libVer=%p", libVer);
+
+ virResetLastError();
+ if (!libVer)
+ goto error;
+ *libVer = LIBVIR_VERSION_NUMBER;
+
+ return 0;
+
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmConnectIsAlive:
+ * @conn: connection to admin server
+ *
+ * Decide whether the connection to the admin server is alive or not.
+ * Connection is considered alive if the channel it is running over is not
+ * closed.
+ *
+ * Returns 1, if the connection is alive, 0 if there isn't an existing
+ * connection at all or the channel has already been closed, or -1 on error.
+ */
+int
+virAdmConnectIsAlive(virAdmConnectPtr conn)
+{
+ bool ret;
+ remoteAdminPrivPtr priv = NULL;
+
+ VIR_DEBUG("conn=%p", conn);
+
+ virResetLastError();
+
+ if (!conn)
+ return 0;
+
+ virCheckAdmConnectReturn(conn, -1);
+
+ priv = conn->privateData;
+ virObjectLock(priv);
+ ret = virNetClientIsOpen(priv->client);
+ virObjectUnlock(priv);
+
+ return ret;
+}
+
+/**
+ * virAdmConnectGetURI:
+ * @conn: pointer to an admin connection
+ *
+ * String returned by this method is normally the same as the string passed
+ * to the virAdmConnectOpen. Even if NULL was passed to virAdmConnectOpen,
+ * this method returns a non-null URI string.
+ *
+ * Returns an URI string related to the connection or NULL in case of an error.
+ * Caller is responsible for freeing the string.
+ */
+char *
+virAdmConnectGetURI(virAdmConnectPtr conn)
+{
+ char *uri = NULL;
+ VIR_DEBUG("conn=%p", conn);
+
+ virResetLastError();
+
+ virCheckAdmConnectReturn(conn, NULL);
+
+ if (!(uri = virURIFormat(conn->uri)))
+ virDispatchError(NULL);
+
+ return uri;
+}
+
+/**
+ * virAdmConnectRegisterCloseCallback:
+ * @conn: connection to admin server
+ * @cb: callback to be invoked upon connection close
+ * @opaque: user data to pass to @cb
+ * @freecb: callback to free @opaque
+ *
+ * Registers a callback to be invoked when the connection
+ * is closed. This callback is invoked when there is any
+ * condition that causes the socket connection to the
+ * hypervisor to be closed.
+ *
+ * The @freecb must not invoke any other libvirt public
+ * APIs, since it is not called from a re-entrant safe
+ * context.
+ *
+ * Returns 0 on success, -1 on error
+ */
+int virAdmConnectRegisterCloseCallback(virAdmConnectPtr conn,
+ virAdmConnectCloseFunc cb,
+ void *opaque,
+ virFreeCallback freecb)
+{
+ VIR_DEBUG("conn=%p", conn);
+
+ virResetLastError();
+
+ virCheckAdmConnectReturn(conn, -1);
+
+ virObjectRef(conn);
+
+ virObjectLock(conn->closeCallback);
+
+ virCheckNonNullArgGoto(cb, error);
+
+ if (conn->closeCallback->callback) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("A close callback is already registered"));
+ goto error;
+ }
+
+ conn->closeCallback->conn = conn;
+ conn->closeCallback->callback = cb;
+ conn->closeCallback->opaque = opaque;
+ conn->closeCallback->freeCallback = freecb;
+
+ virObjectUnlock(conn->closeCallback);
+
+ return 0;
+
+ error:
+ virObjectUnlock(conn->closeCallback);
+ virDispatchError(NULL);
+ virObjectUnref(conn);
+ return -1;
+
+}
+
+/**
+ * virAdmConnectUnregisterCloseCallback:
+ * @conn: pointer to connection object
+ * @cb: pointer to the current registered callback
+ *
+ * Unregisters the callback previously set with the
+ * virAdmConnectRegisterCloseCallback method. The callback
+ * will no longer receive notifications when the connection
+ * closes. If a virFreeCallback was provided at time of
+ * registration, it will be invoked.
+ *
+ * Returns 0 on success, -1 on error
+ */
+int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn,
+ virAdmConnectCloseFunc cb)
+{
+ VIR_DEBUG("conn=%p", conn);
+
+ virResetLastError();
+
+ virCheckAdmConnectReturn(conn, -1);
+ virCheckNonNullArgGoto(cb, error);
+
+ if (virAdmConnectCloseCallbackDataUnregister(conn->closeCallback, cb) < 0)
+ goto error;
+
+ return 0;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmConnectGetLibVersion:
+ * @conn: pointer to an active admin connection
+ * @libVer: stores the current remote libvirt version number
+ *
+ * Retrieves the remote side libvirt version used by the daemon. Format
+ * returned in @libVer is of a following pattern:
+ * major * 1,000,000 + minor * 1,000 + release.
+ *
+ * Returns 0 on success, -1 on failure and @libVer follows this format:
+ */
+int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
+ unsigned long long *libVer)
+{
+ VIR_DEBUG("conn=%p, libVir=%p", conn, libVer);
+
+ virResetLastError();
+
+ virCheckAdmConnectReturn(conn, -1);
+ virCheckNonNullArgReturn(libVer, -1);
+
+ if (remoteAdminConnectGetLibVersion(conn, libVer) < 0)
+ goto error;
+
+ return 0;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmServerGetName:
+ * @srv: a server object
+ *
+ * Get the public name for specified server
+ *
+ * Returns a pointer to the name or NULL. The string doesn't need to be
+ * deallocated since its lifetime will be the same as the server object.
+ */
+const char *
+virAdmServerGetName(virAdmServerPtr srv)
+{
+ VIR_DEBUG("server=%p", srv);
+
+ virResetLastError();
+ virCheckAdmServerReturn(srv, NULL);
+
+ return srv->name;
+}
+
+/**
+ * virAdmServerFree:
+ * @srv: server object
+ *
+ * Release the server object. The running instance is kept alive.
+ * The data structure is freed and should not be used thereafter.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int virAdmServerFree(virAdmServerPtr srv)
+{
+ VIR_DEBUG("server=%p", srv);
+
+ virResetLastError();
+
+ if (!srv)
+ return 0;
+
+ virCheckAdmServerReturn(srv, -1);
+
+ virObjectUnref(srv);
+ return 0;
+}
+
+/**
+ * virAdmClientGetID:
+ * @client: a client object
+ *
+ * Get client's unique numeric ID.
+ *
+ * Returns numeric value used for client's ID or -1 in case of an error.
+ */
+unsigned long long
+virAdmClientGetID(virAdmClientPtr client)
+{
+ VIR_DEBUG("client=%p", client);
+
+ virResetLastError();
+ virCheckAdmClientReturn(client, -1);
+ return client->id;
+}
+
+/**
+ * virAdmClientGetTimestamp:
+ * @client: a client object
+ *
+ * Get client's connection time.
+ * A situation may happen, that some clients had connected prior to the update
+ * to admin API, thus, libvirt assigns these clients epoch time to express that
+ * it doesn't know when the client connected.
+ *
+ * Returns client's connection timestamp (seconds from epoch in UTC) or 0
+ * (epoch time) if libvirt doesn't have any information about client's
+ * connection time, or -1 in case of an error.
+ */
+long long
+virAdmClientGetTimestamp(virAdmClientPtr client)
+{
+ VIR_DEBUG("client=%p", client);
+
+ virResetLastError();
+ virCheckAdmClientReturn(client, -1);
+ return client->timestamp;
+}
+
+/**
+ * virAdmClientGetTransport:
+ * @client: a client object
+ *
+ * Get client's connection transport type. This information can be helpful to
+ * differentiate between clients connected locally or remotely. An exception to
+ * this would be SSH which is one of libvirt's supported transports.
+ * Although SSH creates a channel between two (preferably) remote endpoints,
+ * the client process libvirt spawns automatically on the remote side will
+ * still connect to a UNIX socket, thus becoming indistinguishable from any
+ * other locally connected clients.
+ *
+ * Returns integer representation of the connection transport used by @client
+ * (this will be one of virClientTransport) or -1 in case of an error.
+ */
+int
+virAdmClientGetTransport(virAdmClientPtr client)
+{
+ VIR_DEBUG("client=%p", client);
+
+ virResetLastError();
+ virCheckAdmClientReturn(client, -1);
+ return client->transport;
+}
+
+/**
+ * virAdmClientFree:
+ * @client: a client object
+ *
+ * Release the client object. The running instance is kept alive. The data
+ * structure is freed and should not be used thereafter.
+ *
+ * Returns 0 in success, -1 on failure.
+ */
+int virAdmClientFree(virAdmClientPtr client)
+{
+ VIR_DEBUG("client=%p", client);
+
+ virResetLastError();
+
+ if (!client)
+ return 0;
+
+ virCheckAdmClientReturn(client, -1);
+
+ virObjectUnref(client);
+ return 0;
+}
+
+/**
+ * virAdmConnectListServers:
+ * @conn: daemon connection reference
+ * @servers: Pointer to a list to store an array containing objects or NULL
+ * if the list is not required (number of servers only)
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Collect list of all servers provided by daemon the client is connected to.
+ *
+ * Returns the number of servers available on daemon side or -1 in case of a
+ * failure, setting @servers to NULL. There is a guaranteed extra element set
+ * to NULL in the @servers list returned to make the iteration easier, excluding
+ * this extra element from the final count.
+ * Caller is responsible to call virAdmServerFree() on each list element,
+ * followed by freeing @servers.
+ */
+int
+virAdmConnectListServers(virAdmConnectPtr conn,
+ virAdmServerPtr **servers,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("conn=%p, servers=%p, flags=0x%x", conn, servers, flags);
+
+ virResetLastError();
+
+ if (servers)
+ *servers = NULL;
+
+ virCheckAdmConnectReturn(conn, -1);
+ if ((ret = remoteAdminConnectListServers(conn, servers, flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmConnectLookupServer:
+ * @conn: daemon connection reference
+ * @name: name of the server too lookup
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Try to lookup a server on the given daemon based on @name.
+ *
+ * virAdmServerFree() should be used to free the resources after the
+ * server object is no longer needed.
+ *
+ * Returns the requested server or NULL in case of failure. If the
+ * server cannot be found, then VIR_ERR_NO_SERVER error is raised.
+ */
+virAdmServerPtr
+virAdmConnectLookupServer(virAdmConnectPtr conn,
+ const char *name,
+ unsigned int flags)
+{
+ virAdmServerPtr ret = NULL;
+
+ VIR_DEBUG("conn=%p, name=%s, flags=0x%x", conn, NULLSTR(name), flags);
+ virResetLastError();
+
+ virCheckAdmConnectGoto(conn, cleanup);
+ virCheckNonNullArgGoto(name, cleanup);
+
+ ret = remoteAdminConnectLookupServer(conn, name, flags);
+ cleanup:
+ if (!ret)
+ virDispatchError(NULL);
+ return ret;
+}
+
+/**
+ * virAdmServerGetThreadPoolParameters:
+ * @srv: a valid server object reference
+ * @params: pointer to a list of typed parameters which will be allocated
+ * to store all returned parameters
+ * @nparams: pointer which will hold the number of params returned in @params
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Retrieves threadpool parameters from @srv. Upon successful completion,
+ * @params will be allocated automatically to hold all returned data, setting
+ * @nparams accordingly.
+ * When extracting parameters from @params, following search keys are
+ * supported:
+ * VIR_THREADPOOL_WORKERS_MIN
+ * VIR_THREADPOOL_WORKERS_MAX
+ * VIR_THREADPOOL_WORKERS_PRIORITY
+ * VIR_THREADPOOL_WORKERS_FREE
+ * VIR_THREADPOOL_WORKERS_CURRENT
+ *
+ * Returns 0 on success, -1 in case of an error.
+ */
+int
+virAdmServerGetThreadPoolParameters(virAdmServerPtr srv,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("srv=%p, params=%p, nparams=%p, flags=0x%x",
+ srv, params, nparams, flags);
+
+ virResetLastError();
+
+ virCheckAdmServerReturn(srv, -1);
+ virCheckNonNullArgGoto(params, error);
+
+ if ((ret = remoteAdminServerGetThreadPoolParameters(srv, params, nparams,
+ flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmServerSetThreadPoolParameters:
+ * @srv: a valid server object reference
+ * @params: pointer to threadpool typed parameter objects
+ * @nparams: number of parameters in @params
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Change server threadpool parameters according to @params. Note that some
+ * tunables are read-only, thus any attempt to set them will result in a
+ * failure.
+ *
+ * Returns 0 on success, -1 in case of an error.
+ */
+int
+virAdmServerSetThreadPoolParameters(virAdmServerPtr srv,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags)
+{
+ VIR_DEBUG("srv=%p, params=%p, nparams=%d, flags=0x%x",
+ srv, params, nparams, flags);
+
+ virResetLastError();
+
+ virCheckAdmServerReturn(srv, -1);
+ virCheckNonNullArgGoto(params, error);
+ virCheckNonNegativeArgGoto(nparams, error);
+
+ if (remoteAdminServerSetThreadPoolParameters(srv, params,
+ nparams, flags) < 0)
+ goto error;
+
+ return 0;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmServerListClients:
+ * @srv: a valid server object reference
+ * @clients: pointer to a list to store an array containing objects or NULL
+ * if the list is not required (number of clients only)
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Collect list of all clients connected to daemon on server @srv.
+ *
+ * Returns the number of clients connected to daemon on server @srv -1 in case
+ * of a failure, setting @clients to NULL. There is a guaranteed extra element
+ * set to NULL in the @clients list returned to make the iteration easier,
+ * excluding this extra element from the final count.
+ * Caller is responsible to call virAdmClientFree() on each list element,
+ * followed by freeing @clients.
+ */
+int
+virAdmServerListClients(virAdmServerPtr srv,
+ virAdmClientPtr **clients,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("srv=%p, clients=%p, flags=0x%x", srv, clients, flags);
+
+ virResetLastError();
+
+ if (clients)
+ *clients = NULL;
+
+ virCheckAdmServerReturn(srv, -1);
+ if ((ret = remoteAdminServerListClients(srv, clients, flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmServerLookupClient:
+ * @srv: a valid server object reference
+ * @id: ID of the client to lookup on server @srv
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Try to lookup a client on the given server based on @id.
+ *
+ * virAdmClientFree() should be used to free the resources after the
+ * client object is no longer needed.
+ *
+ * Returns the requested client or NULL in case of failure. If the
+ * client could not be found, then VIR_ERR_NO_CLIENT error is raised.
+ */
+virAdmClientPtr
+virAdmServerLookupClient(virAdmServerPtr srv,
+ unsigned long long id,
+ unsigned int flags)
+{
+ virAdmClientPtr ret = NULL;
+
+ VIR_DEBUG("srv=%p, id=%llu, flags=0x%x", srv, id, flags);
+ virResetLastError();
+
+ virCheckAdmServerGoto(srv, error);
+
+ if (!(ret = remoteAdminServerLookupClient(srv, id, flags)))
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return NULL;
+}
+
+/**
+ * virAdmClientGetInfo:
+ * @client: a client object reference
+ * @params: pointer to a list of typed parameters which will be allocated
+ * to store all returned parameters
+ * @nparams: pointer which will hold the number of params returned in @params
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Extract identity information about a client. Attributes returned in @params
+ * are mostly transport-dependent, i.e. some attributes including client
+ * process's pid, gid, uid, or remote side's socket address are only available
+ * for a specific connection type - local vs remote.
+ * Other identity attributes like authentication method used
+ * (if authentication is enabled on the remote host), SELinux context, or
+ * an indicator whether client is connected via a read-only connection are
+ * independent of the connection transport.
+ *
+ * Note that the read-only connection indicator returns false for TCP/TLS
+ * clients because libvirt treats such connections as read-write by default,
+ * even though a TCP client is able to restrict access to certain APIs for
+ * itself.
+ *
+ * Returns 0 if the information has been successfully retrieved or -1 in case
+ * of an error.
+ */
+int
+virAdmClientGetInfo(virAdmClientPtr client,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("client=%p, params=%p, nparams=%p, flags=0x%x",
+ client, params, nparams, flags);
+
+ virResetLastError();
+ virCheckAdmClientReturn(client, -1);
+ virCheckNonNullArgGoto(params, error);
+
+ if ((ret = remoteAdminClientGetInfo(client, params, nparams, flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmClientClose:
+ * @client: a valid client object reference
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Close @client's connection to daemon forcefully.
+ *
+ * Returns 0 if the daemon's connection with @client was closed successfully
+ * or -1 in case of an error.
+ */
+int virAdmClientClose(virAdmClientPtr client,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("client=%p, flags=0x%x", client, flags);
+ virResetLastError();
+
+ virCheckAdmClientGoto(client, error);
+
+ if ((ret = remoteAdminClientClose(client, flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmServerGetClientLimits:
+ * @srv: a valid server object reference
+ * @params: pointer to client limits object
+ * (return value, allocated automatically)
+ * @nparams: pointer to number of parameters returned in @params
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Retrieve client limits from server @srv. These include:
+ * - current number of clients connected to @srv,
+ * - maximum number of clients connected to @srv,
+ * - current number of clients connected to @srv waiting for authentication,
+ * - maximum number of clients connected to @srv that can be wainting for
+ * authentication.
+ *
+ * Returns 0 on success, allocating @params to size returned in @nparams, or
+ * -1 in case of an error. Caller is responsible for deallocating @params.
+ */
+int
+virAdmServerGetClientLimits(virAdmServerPtr srv,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("srv=%p, params=%p, nparams=%p, flags=0x%x",
+ srv, params, nparams, flags);
+ virResetLastError();
+
+ virCheckAdmServerGoto(srv, error);
+
+ if ((ret = remoteAdminServerGetClientLimits(srv, params,
+ nparams, flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmServerSetClientLimits:
+ * @srv: a valid server object reference
+ * @params: pointer to client limits object
+ * @nparams: number of parameters in @params
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Change client limits configuration on server @srv.
+ *
+ * Caller is responsible for allocating @params prior to calling this function.
+ * See 'Manage per-server client limits' in libvirt-admin.h for
+ * supported parameters in @params.
+ *
+ * Returns 0 if the limits have been changed successfully or -1 in case of an
+ * error.
+ */
+int
+virAdmServerSetClientLimits(virAdmServerPtr srv,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("srv=%p, params=%p, nparams=%d, flags=0x%x", srv, params, nparams,
+ flags);
+ VIR_TYPED_PARAMS_DEBUG(params, nparams);
+
+ virResetLastError();
+
+ virCheckAdmServerGoto(srv, error);
+ virCheckNonNullArgGoto(params, error);
+ virCheckNonNegativeArgGoto(nparams, error);
+
+ if ((ret = remoteAdminServerSetClientLimits(srv, params, nparams,
+ flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return ret;
+}
+
+/**
+ * virAdmConnectGetLoggingOutputs:
+ * @conn: pointer to an active admin connection
+ * @outputs: pointer to a variable to store a string containing all currently
+ * defined logging outputs on daemon (allocated automatically) or
+ * NULL if just the number of defined outputs is required
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Retrieves a list of currently installed logging outputs. Outputs returned
+ * are contained within an automatically allocated string and delimited by
+ * spaces. The format of each output conforms to the format described in
+ * daemon's configuration file (e.g. libvirtd.conf).
+ *
+ * To retrieve individual outputs, additional parsing needs to be done by the
+ * caller. Caller is also responsible for freeing @outputs correctly.
+ *
+ * Returns the count of outputs in @outputs, or -1 in case of an error.
+ */
+int
+virAdmConnectGetLoggingOutputs(virAdmConnectPtr conn,
+ char **outputs,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("conn=%p, flags=0x%x", conn, flags);
+
+ virResetLastError();
+ virCheckAdmConnectReturn(conn, -1);
+
+ if ((ret = remoteAdminConnectGetLoggingOutputs(conn, outputs,
+ flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmConnectGetLoggingFilters:
+ * @conn: pointer to an active admin connection
+ * @filters: pointer to a variable to store a string containing all currently
+ * defined logging filters on daemon (allocated automatically) or
+ * NULL if just the number of defined outputs is required
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Retrieves a list of currently installed logging filters. Filters returned
+ * are contained within an automatically allocated string and delimited by
+ * spaces. The format of each filter conforms to the format described in
+ * daemon's configuration file (e.g. libvirtd.conf).
+ *
+ * To retrieve individual filters, additional parsing needs to be done by the
+ * caller. Caller is also responsible for freeing @filters correctly.
+ *
+ * Returns the number of filters returned in @filters, or -1 in case of
+ * an error.
+ */
+int
+virAdmConnectGetLoggingFilters(virAdmConnectPtr conn,
+ char **filters,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("conn=%p, filters=%p, flags=0x%x",
+ conn, filters, flags);
+
+ virResetLastError();
+ virCheckAdmConnectReturn(conn, -1);
+
+ if ((ret = remoteAdminConnectGetLoggingFilters(conn, filters,
+ flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmConnectSetLoggingOutputs:
+ * @conn: pointer to an active admin connection
+ * @outputs: pointer to a string containing a list of outputs to be defined
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Redefine the existing (set of) outputs(s) with a new one specified in
+ * @outputs. If multiple outputs are specified, they need to be delimited by
+ * spaces. The format of each output must conform to the format described in
+ * daemon's configuration file (e.g. libvirtd.conf).
+ *
+ * To reset the existing (set of) output(s) to libvirt's defaults, an empty
+ * string ("") or NULL should be passed in @outputs.
+ *
+ * Returns 0 if the new output or the set of outputs has been defined
+ * successfully, or -1 in case of an error.
+ */
+int
+virAdmConnectSetLoggingOutputs(virAdmConnectPtr conn,
+ const char *outputs,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("conn=%p, outputs=%s, flags=0x%x", conn, outputs, flags);
+
+ virResetLastError();
+ virCheckAdmConnectReturn(conn, -1);
+
+ if ((ret = remoteAdminConnectSetLoggingOutputs(conn, outputs, flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
+
+/**
+ * virAdmConnectSetLoggingFilters:
+ * @conn: pointer to an active admin connection
+ * @filters: pointer to a string containing a list of filters to be defined
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Redefine the existing (set of) filter(s) with a new one specified in
+ * @filters. If multiple filters are specified, they need to be delimited by
+ * spaces. The format of each filter must conform to the format described in
+ * daemon's configuration file (e.g. libvirtd.conf).
+ *
+ * To clear the currently defined (set of) filter(s), pass either an empty
+ * string ("") or NULL in @filters.
+ *
+ * Returns 0 if the new filter or the set of filters has been defined
+ * successfully, or -1 in case of an error.
+ */
+int
+virAdmConnectSetLoggingFilters(virAdmConnectPtr conn,
+ const char *filters,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("conn=%p, filters=%s, flags=0x%x", conn, filters, flags);
+
+ virResetLastError();
+ virCheckAdmConnectReturn(conn, -1);
+
+ if ((ret = remoteAdminConnectSetLoggingFilters(conn, filters, flags)) < 0)
+ goto error;
+
+ return ret;
+ error:
+ virDispatchError(NULL);
+ return -1;
+}
--- /dev/null
+#
+# This can be used to setup URI aliases for frequently
+# used connection URIs. Aliases may contain only the
+# characters a-Z, 0-9, _, -.
+#
+# Following the '=' may be any valid libvirt admin connection
+# URI, including arbitrary parameters
+
+#uri_aliases = [
+# "admin=libvirtd:///system",
+#]
+
+# This specifies the default location the client tries to connect to if no other
+# URI is provided by the application
+
+#uri_default = "libvirtd:///system"
--- /dev/null
+#
+# General private symbols for libvirt_admin. Add symbols here, and see
+# Makefile.am for more details.
+#
+# Keep this file sorted by header name, then by symbols with each header.
+#
+
+# admin/admin_protocol.x
+xdr_admin_client_close_args;
+xdr_admin_client_get_info_args;
+xdr_admin_client_get_info_ret;
+xdr_admin_connect_get_lib_version_ret;
+xdr_admin_connect_get_logging_filters_args;
+xdr_admin_connect_get_logging_filters_ret;
+xdr_admin_connect_get_logging_outputs_args;
+xdr_admin_connect_get_logging_outputs_ret;
+xdr_admin_connect_list_servers_args;
+xdr_admin_connect_list_servers_ret;
+xdr_admin_connect_lookup_server_args;
+xdr_admin_connect_lookup_server_ret;
+xdr_admin_connect_open_args;
+xdr_admin_connect_set_logging_filters_args;
+xdr_admin_connect_set_logging_outputs_args;
+xdr_admin_server_get_client_limits_args;
+xdr_admin_server_get_client_limits_ret;
+xdr_admin_server_get_threadpool_parameters_args;
+xdr_admin_server_get_threadpool_parameters_ret;
+xdr_admin_server_list_clients_args;
+xdr_admin_server_list_clients_ret;
+xdr_admin_server_lookup_client_args;
+xdr_admin_server_lookup_client_ret;
+xdr_admin_server_set_client_limits_args;
+xdr_admin_server_set_threadpool_parameters_args;
+
+# datatypes.h
+virAdmClientClass;
+virAdmConnectClass;
+virAdmConnectCloseCallbackDataRegister;
+virAdmConnectCloseCallbackDataReset;
+virAdmConnectCloseCallbackDataUnregister;
+virAdmGetServer;
+virAdmServerClass;
+
+# Let emacs know we want case-insensitive sorting
+# Local Variables:
+# sort-fold-case: t
+# End:
--- /dev/null
+#
+# Officially exported symbols, for which header
+# file definitions are installed in /usr/include/libvirt
+# from libvirt-admin.h
+#
+# Versions here are *fixed* to match the libvirt version
+# at which the symbol was introduced. This ensures that
+# a new client app requiring symbol foo() can't accidentally
+# run with old libvirt-admin.so not providing foo() - the global
+# soname version info can't enforce this since we never
+# change the soname
+#
+LIBVIRT_ADMIN_2.0.0 {
+ global:
+ virAdmInitialize;
+ virAdmClientFree;
+ virAdmClientGetID;
+ virAdmClientGetTimestamp;
+ virAdmClientGetTransport;
+ virAdmConnectOpen;
+ virAdmConnectClose;
+ virAdmConnectRef;
+ virAdmGetVersion;
+ virAdmConnectIsAlive;
+ virAdmConnectGetURI;
+ virAdmConnectGetLibVersion;
+ virAdmConnectRegisterCloseCallback;
+ virAdmConnectUnregisterCloseCallback;
+ virAdmConnectListServers;
+ virAdmServerGetName;
+ virAdmServerGetThreadPoolParameters;
+ virAdmServerFree;
+ virAdmServerLookupClient;
+ virAdmConnectLookupServer;
+ virAdmServerSetThreadPoolParameters;
+ virAdmServerListClients;
+ virAdmClientGetInfo;
+ virAdmClientClose;
+ virAdmServerGetClientLimits;
+ virAdmServerSetClientLimits;
+};
+
+LIBVIRT_ADMIN_3.0.0 {
+ global:
+ virAdmConnectGetLoggingOutputs;
+ virAdmConnectGetLoggingFilters;
+ virAdmConnectSetLoggingOutputs;
+ virAdmConnectSetLoggingFilters;
+} LIBVIRT_ADMIN_2.0.0;
+++ /dev/null
-/*
- * libvirt-admin.c
- *
- * Copyright (C) 2014-2015 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, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-
-#include "internal.h"
-#include "datatypes.h"
-#include "configmake.h"
-
-#include "viralloc.h"
-#include "virconf.h"
-#include "virlog.h"
-#include "virnetclient.h"
-#include "virobject.h"
-#include "virstring.h"
-#include "viruri.h"
-#include "virutil.h"
-#include "viruuid.h"
-
-#define VIR_FROM_THIS VIR_FROM_ADMIN
-
-
-VIR_LOG_INIT("libvirt-admin");
-
-#include "admin_remote.c"
-
-static bool virAdmGlobalError;
-static virOnceControl virAdmGlobalOnce = VIR_ONCE_CONTROL_INITIALIZER;
-
-static void
-virAdmGlobalInit(void)
-{
- /* It would be nice if we could trace the use of this call, to
- * help diagnose in log files if a user calls something other than
- * virAdmConnectOpen first. But we can't rely on VIR_DEBUG working
- * until after initialization is complete, and since this is
- * one-shot, we never get here again. */
- if (virErrorInitialize() < 0)
- goto error;
-
- virLogSetFromEnv();
-
-#ifdef HAVE_LIBINTL_H
- if (!bindtextdomain(PACKAGE, LOCALEDIR))
- goto error;
-#endif /* HAVE_LIBINTL_H */
-
- if (!VIR_CLASS_NEW(remoteAdminPriv, virClassForObjectLockable()))
- goto error;
-
- return;
- error:
- virAdmGlobalError = true;
-}
-
-/**
- * virAdmInitialize:
- *
- * Initialize the library.
- *
- * This method is automatically invoked by virAdmConnectOpen() API. Therefore,
- * in most cases it is unnecessary to call this method manually, unless an
- * event loop should be set up by calling virEventRegisterImpl() or the error
- * reporting of the first connection attempt with virSetErrorFunc() should be
- * altered prior to setting up connections. If the latter is the case, it is
- * necessary for the application to call virAdmInitialize.
- *
- * Returns 0 in case of success, -1 in case of error
- */
-int
-virAdmInitialize(void)
-{
- if (virOnce(&virAdmGlobalOnce, virAdmGlobalInit) < 0)
- return -1;
-
- if (virAdmGlobalError)
- return -1;
-
- return 0;
-}
-
-static char *
-getSocketPath(virURIPtr uri)
-{
- char *rundir = virGetUserRuntimeDirectory();
- char *sock_path = NULL;
- size_t i = 0;
-
- if (!uri)
- goto cleanup;
-
-
- for (i = 0; i < uri->paramsCount; i++) {
- virURIParamPtr param = &uri->params[i];
-
- if (STREQ(param->name, "socket")) {
- VIR_FREE(sock_path);
- sock_path = g_strdup(param->value);
- } else {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Unknown URI parameter '%s'"), param->name);
- goto error;
- }
- }
-
- if (!sock_path) {
- g_autofree char *sockbase = NULL;
- bool legacy = false;
-
- if (!uri->scheme) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- "%s", _("No URI scheme specified"));
- goto error;
- }
- if (STREQ(uri->scheme, "libvirtd")) {
- legacy = true;
- } else if (!STRPREFIX(uri->scheme, "virt")) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Unsupported URI scheme '%s'"),
- uri->scheme);
- goto error;
- }
-
- if (legacy) {
- sockbase = g_strdup("libvirt-admin-sock");
- } else {
- if (virAsprintf(&sockbase, "%s-admin-sock", uri->scheme) < 0)
- goto error;
- }
-
- if (STREQ_NULLABLE(uri->path, "/system")) {
- if (virAsprintf(&sock_path, RUNSTATEDIR "/libvirt/%s",
- sockbase) < 0)
- goto error;
- } else if (STREQ_NULLABLE(uri->path, "/session")) {
- if (!rundir || virAsprintf(&sock_path, "%s/%s", rundir,
- sockbase) < 0)
- goto error;
- } else {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Invalid URI path '%s', try '/system'"),
- NULLSTR_EMPTY(uri->path));
- goto error;
- }
- }
-
- cleanup:
- VIR_FREE(rundir);
- return sock_path;
-
- error:
- VIR_FREE(sock_path);
- goto cleanup;
-}
-
-static int
-virAdmGetDefaultURI(virConfPtr conf, char **uristr)
-{
- const char *defname = getenv("LIBVIRT_ADMIN_DEFAULT_URI");
- if (defname && *defname) {
- *uristr = g_strdup(defname);
- VIR_DEBUG("Using LIBVIRT_ADMIN_DEFAULT_URI '%s'", *uristr);
- } else {
- if (virConfGetValueString(conf, "uri_default", uristr) < 0)
- return -1;
-
- if (*uristr) {
- VIR_DEBUG("Using config file uri '%s'", *uristr);
- } else {
- /* Since we can't probe connecting via any hypervisor driver as libvirt
- * does, if no explicit URI was given and neither the environment
- * variable, nor the configuration parameter had previously been set,
- * we set the default admin server URI to 'libvirtd:///system' or
- * 'libvirtd:///session' depending on the process's EUID.
- */
- if (geteuid() == 0) {
- *uristr = g_strdup("libvirtd:///system");
- } else {
- *uristr = g_strdup("libvirtd:///session");
- }
- }
- }
-
- return 0;
-}
-
-/**
- * virAdmConnectOpen:
- * @name: uri of the daemon to connect to, NULL for default
- * @flags: bitwise-OR of virConnectFlags; so far the only supported flag is
- * VIR_CONNECT_NO_ALIASES
- *
- * Opens connection to admin interface of the daemon.
- *
- * Returns @virAdmConnectPtr object or NULL on error
- */
-virAdmConnectPtr
-virAdmConnectOpen(const char *name, unsigned int flags)
-{
- char *sock_path = NULL;
- char *alias = NULL;
- virAdmConnectPtr conn = NULL;
- g_autoptr(virConf) conf = NULL;
- char *uristr = NULL;
-
- if (virAdmInitialize() < 0)
- goto error;
-
- VIR_DEBUG("name=%s flags=0x%x", NULLSTR(name), flags);
- virResetLastError();
-
- if (!(conn = virAdmConnectNew()))
- goto error;
-
- if (virConfLoadConfig(&conf, "libvirt-admin.conf") < 0)
- goto error;
-
- if (name) {
- uristr = g_strdup(name);
- } else {
- if (virAdmGetDefaultURI(conf, &uristr) < 0)
- goto error;
- }
-
- if ((!(flags & VIR_CONNECT_NO_ALIASES) &&
- virURIResolveAlias(conf, uristr, &alias) < 0))
- goto error;
-
- if (alias) {
- VIR_FREE(uristr);
- uristr = alias;
- }
-
- if (!(conn->uri = virURIParse(uristr)))
- goto error;
-
- if (!(sock_path = getSocketPath(conn->uri)))
- goto error;
-
- if (!(conn->privateData = remoteAdminPrivNew(sock_path)))
- goto error;
-
- conn->privateDataFreeFunc = remoteAdminPrivFree;
-
- if (remoteAdminConnectOpen(conn, flags) < 0)
- goto error;
-
- cleanup:
- VIR_FREE(sock_path);
- VIR_FREE(uristr);
- return conn;
-
- error:
- virDispatchError(NULL);
- virObjectUnref(conn);
- conn = NULL;
- goto cleanup;
-}
-
-/**
- * virAdmConnectClose:
- * @conn: pointer to admin connection to close
- *
- * This function closes the admin connection to the Hypervisor. This should not
- * be called if further interaction with the Hypervisor are needed especially if
- * there is running domain which need further monitoring by the application.
- *
- * Connections are reference counted; the count is explicitly increased by the
- * initial virAdmConnectOpen, as well as virAdmConnectRef; it is also temporarily
- * increased by other API that depend on the connection remaining alive. The
- * open and every virAdmConnectRef call should have a matching
- * virAdmConnectClose, and all other references will be released after the
- * corresponding operation completes.
- *
- * Returns a positive number if at least 1 reference remains on success. The
- * returned value should not be assumed to be the total reference count. A
- * return of 0 implies no references remain and the connection is closed and
- * memory has been freed. A return of -1 implies a failure.
- *
- * It is possible for the last virAdmConnectClose to return a positive value if
- * some other object still has a temporary reference to the connection, but the
- * application should not try to further use a connection after the
- * virAdmConnectClose that matches the initial open.
- */
-int
-virAdmConnectClose(virAdmConnectPtr conn)
-{
- VIR_DEBUG("conn=%p", conn);
-
- virResetLastError();
- if (!conn)
- return 0;
-
- virCheckAdmConnectReturn(conn, -1);
-
- if (!virObjectUnref(conn))
- return 0;
- return 1;
-}
-
-
-/**
- * virAdmConnectRef:
- * @conn: the connection to hold a reference on
- *
- * Increment the reference count on the connection. For each additional call to
- * this method, there shall be a corresponding call to virAdmConnectClose to
- * release the reference count, once the caller no longer needs the reference to
- * this object.
- *
- * This method is typically useful for applications where multiple threads are
- * using a connection, and it is required that the connection remain open until
- * all threads have finished using it. I.e., each new thread using a connection
- * would increment the reference count.
- *
- * Returns 0 in case of success, -1 in case of failure
- */
-int
-virAdmConnectRef(virAdmConnectPtr conn)
-{
- VIR_DEBUG("conn=%p refs=%d", conn,
- conn ? conn->parent.parent.u.s.refs : 0);
-
- virResetLastError();
- virCheckAdmConnectReturn(conn, -1);
-
- virObjectRef(conn);
-
- return 0;
-}
-
-/**
- * virAdmGetVersion:
- * @libVer: where to store the library version
- *
- * Provides version information. @libVer is the version of the library and will
- * always be set unless an error occurs in which case an error code and a
- * generic message will be returned. @libVer format is as follows:
- * major * 1,000,000 + minor * 1,000 + release.
- *
- * NOTE: To get the remote side library version use virAdmConnectGetLibVersion
- * instead.
- *
- * Returns 0 on success, -1 in case of an error.
- */
-int
-virAdmGetVersion(unsigned long long *libVer)
-{
- if (virAdmInitialize() < 0)
- goto error;
-
- VIR_DEBUG("libVer=%p", libVer);
-
- virResetLastError();
- if (!libVer)
- goto error;
- *libVer = LIBVIR_VERSION_NUMBER;
-
- return 0;
-
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmConnectIsAlive:
- * @conn: connection to admin server
- *
- * Decide whether the connection to the admin server is alive or not.
- * Connection is considered alive if the channel it is running over is not
- * closed.
- *
- * Returns 1, if the connection is alive, 0 if there isn't an existing
- * connection at all or the channel has already been closed, or -1 on error.
- */
-int
-virAdmConnectIsAlive(virAdmConnectPtr conn)
-{
- bool ret;
- remoteAdminPrivPtr priv = NULL;
-
- VIR_DEBUG("conn=%p", conn);
-
- virResetLastError();
-
- if (!conn)
- return 0;
-
- virCheckAdmConnectReturn(conn, -1);
-
- priv = conn->privateData;
- virObjectLock(priv);
- ret = virNetClientIsOpen(priv->client);
- virObjectUnlock(priv);
-
- return ret;
-}
-
-/**
- * virAdmConnectGetURI:
- * @conn: pointer to an admin connection
- *
- * String returned by this method is normally the same as the string passed
- * to the virAdmConnectOpen. Even if NULL was passed to virAdmConnectOpen,
- * this method returns a non-null URI string.
- *
- * Returns an URI string related to the connection or NULL in case of an error.
- * Caller is responsible for freeing the string.
- */
-char *
-virAdmConnectGetURI(virAdmConnectPtr conn)
-{
- char *uri = NULL;
- VIR_DEBUG("conn=%p", conn);
-
- virResetLastError();
-
- virCheckAdmConnectReturn(conn, NULL);
-
- if (!(uri = virURIFormat(conn->uri)))
- virDispatchError(NULL);
-
- return uri;
-}
-
-/**
- * virAdmConnectRegisterCloseCallback:
- * @conn: connection to admin server
- * @cb: callback to be invoked upon connection close
- * @opaque: user data to pass to @cb
- * @freecb: callback to free @opaque
- *
- * Registers a callback to be invoked when the connection
- * is closed. This callback is invoked when there is any
- * condition that causes the socket connection to the
- * hypervisor to be closed.
- *
- * The @freecb must not invoke any other libvirt public
- * APIs, since it is not called from a re-entrant safe
- * context.
- *
- * Returns 0 on success, -1 on error
- */
-int virAdmConnectRegisterCloseCallback(virAdmConnectPtr conn,
- virAdmConnectCloseFunc cb,
- void *opaque,
- virFreeCallback freecb)
-{
- VIR_DEBUG("conn=%p", conn);
-
- virResetLastError();
-
- virCheckAdmConnectReturn(conn, -1);
-
- virObjectRef(conn);
-
- virObjectLock(conn->closeCallback);
-
- virCheckNonNullArgGoto(cb, error);
-
- if (conn->closeCallback->callback) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("A close callback is already registered"));
- goto error;
- }
-
- conn->closeCallback->conn = conn;
- conn->closeCallback->callback = cb;
- conn->closeCallback->opaque = opaque;
- conn->closeCallback->freeCallback = freecb;
-
- virObjectUnlock(conn->closeCallback);
-
- return 0;
-
- error:
- virObjectUnlock(conn->closeCallback);
- virDispatchError(NULL);
- virObjectUnref(conn);
- return -1;
-
-}
-
-/**
- * virAdmConnectUnregisterCloseCallback:
- * @conn: pointer to connection object
- * @cb: pointer to the current registered callback
- *
- * Unregisters the callback previously set with the
- * virAdmConnectRegisterCloseCallback method. The callback
- * will no longer receive notifications when the connection
- * closes. If a virFreeCallback was provided at time of
- * registration, it will be invoked.
- *
- * Returns 0 on success, -1 on error
- */
-int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn,
- virAdmConnectCloseFunc cb)
-{
- VIR_DEBUG("conn=%p", conn);
-
- virResetLastError();
-
- virCheckAdmConnectReturn(conn, -1);
- virCheckNonNullArgGoto(cb, error);
-
- if (virAdmConnectCloseCallbackDataUnregister(conn->closeCallback, cb) < 0)
- goto error;
-
- return 0;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmConnectGetLibVersion:
- * @conn: pointer to an active admin connection
- * @libVer: stores the current remote libvirt version number
- *
- * Retrieves the remote side libvirt version used by the daemon. Format
- * returned in @libVer is of a following pattern:
- * major * 1,000,000 + minor * 1,000 + release.
- *
- * Returns 0 on success, -1 on failure and @libVer follows this format:
- */
-int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
- unsigned long long *libVer)
-{
- VIR_DEBUG("conn=%p, libVir=%p", conn, libVer);
-
- virResetLastError();
-
- virCheckAdmConnectReturn(conn, -1);
- virCheckNonNullArgReturn(libVer, -1);
-
- if (remoteAdminConnectGetLibVersion(conn, libVer) < 0)
- goto error;
-
- return 0;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmServerGetName:
- * @srv: a server object
- *
- * Get the public name for specified server
- *
- * Returns a pointer to the name or NULL. The string doesn't need to be
- * deallocated since its lifetime will be the same as the server object.
- */
-const char *
-virAdmServerGetName(virAdmServerPtr srv)
-{
- VIR_DEBUG("server=%p", srv);
-
- virResetLastError();
- virCheckAdmServerReturn(srv, NULL);
-
- return srv->name;
-}
-
-/**
- * virAdmServerFree:
- * @srv: server object
- *
- * Release the server object. The running instance is kept alive.
- * The data structure is freed and should not be used thereafter.
- *
- * Returns 0 on success, -1 on failure.
- */
-int virAdmServerFree(virAdmServerPtr srv)
-{
- VIR_DEBUG("server=%p", srv);
-
- virResetLastError();
-
- if (!srv)
- return 0;
-
- virCheckAdmServerReturn(srv, -1);
-
- virObjectUnref(srv);
- return 0;
-}
-
-/**
- * virAdmClientGetID:
- * @client: a client object
- *
- * Get client's unique numeric ID.
- *
- * Returns numeric value used for client's ID or -1 in case of an error.
- */
-unsigned long long
-virAdmClientGetID(virAdmClientPtr client)
-{
- VIR_DEBUG("client=%p", client);
-
- virResetLastError();
- virCheckAdmClientReturn(client, -1);
- return client->id;
-}
-
-/**
- * virAdmClientGetTimestamp:
- * @client: a client object
- *
- * Get client's connection time.
- * A situation may happen, that some clients had connected prior to the update
- * to admin API, thus, libvirt assigns these clients epoch time to express that
- * it doesn't know when the client connected.
- *
- * Returns client's connection timestamp (seconds from epoch in UTC) or 0
- * (epoch time) if libvirt doesn't have any information about client's
- * connection time, or -1 in case of an error.
- */
-long long
-virAdmClientGetTimestamp(virAdmClientPtr client)
-{
- VIR_DEBUG("client=%p", client);
-
- virResetLastError();
- virCheckAdmClientReturn(client, -1);
- return client->timestamp;
-}
-
-/**
- * virAdmClientGetTransport:
- * @client: a client object
- *
- * Get client's connection transport type. This information can be helpful to
- * differentiate between clients connected locally or remotely. An exception to
- * this would be SSH which is one of libvirt's supported transports.
- * Although SSH creates a channel between two (preferably) remote endpoints,
- * the client process libvirt spawns automatically on the remote side will
- * still connect to a UNIX socket, thus becoming indistinguishable from any
- * other locally connected clients.
- *
- * Returns integer representation of the connection transport used by @client
- * (this will be one of virClientTransport) or -1 in case of an error.
- */
-int
-virAdmClientGetTransport(virAdmClientPtr client)
-{
- VIR_DEBUG("client=%p", client);
-
- virResetLastError();
- virCheckAdmClientReturn(client, -1);
- return client->transport;
-}
-
-/**
- * virAdmClientFree:
- * @client: a client object
- *
- * Release the client object. The running instance is kept alive. The data
- * structure is freed and should not be used thereafter.
- *
- * Returns 0 in success, -1 on failure.
- */
-int virAdmClientFree(virAdmClientPtr client)
-{
- VIR_DEBUG("client=%p", client);
-
- virResetLastError();
-
- if (!client)
- return 0;
-
- virCheckAdmClientReturn(client, -1);
-
- virObjectUnref(client);
- return 0;
-}
-
-/**
- * virAdmConnectListServers:
- * @conn: daemon connection reference
- * @servers: Pointer to a list to store an array containing objects or NULL
- * if the list is not required (number of servers only)
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Collect list of all servers provided by daemon the client is connected to.
- *
- * Returns the number of servers available on daemon side or -1 in case of a
- * failure, setting @servers to NULL. There is a guaranteed extra element set
- * to NULL in the @servers list returned to make the iteration easier, excluding
- * this extra element from the final count.
- * Caller is responsible to call virAdmServerFree() on each list element,
- * followed by freeing @servers.
- */
-int
-virAdmConnectListServers(virAdmConnectPtr conn,
- virAdmServerPtr **servers,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("conn=%p, servers=%p, flags=0x%x", conn, servers, flags);
-
- virResetLastError();
-
- if (servers)
- *servers = NULL;
-
- virCheckAdmConnectReturn(conn, -1);
- if ((ret = remoteAdminConnectListServers(conn, servers, flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmConnectLookupServer:
- * @conn: daemon connection reference
- * @name: name of the server too lookup
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Try to lookup a server on the given daemon based on @name.
- *
- * virAdmServerFree() should be used to free the resources after the
- * server object is no longer needed.
- *
- * Returns the requested server or NULL in case of failure. If the
- * server cannot be found, then VIR_ERR_NO_SERVER error is raised.
- */
-virAdmServerPtr
-virAdmConnectLookupServer(virAdmConnectPtr conn,
- const char *name,
- unsigned int flags)
-{
- virAdmServerPtr ret = NULL;
-
- VIR_DEBUG("conn=%p, name=%s, flags=0x%x", conn, NULLSTR(name), flags);
- virResetLastError();
-
- virCheckAdmConnectGoto(conn, cleanup);
- virCheckNonNullArgGoto(name, cleanup);
-
- ret = remoteAdminConnectLookupServer(conn, name, flags);
- cleanup:
- if (!ret)
- virDispatchError(NULL);
- return ret;
-}
-
-/**
- * virAdmServerGetThreadPoolParameters:
- * @srv: a valid server object reference
- * @params: pointer to a list of typed parameters which will be allocated
- * to store all returned parameters
- * @nparams: pointer which will hold the number of params returned in @params
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Retrieves threadpool parameters from @srv. Upon successful completion,
- * @params will be allocated automatically to hold all returned data, setting
- * @nparams accordingly.
- * When extracting parameters from @params, following search keys are
- * supported:
- * VIR_THREADPOOL_WORKERS_MIN
- * VIR_THREADPOOL_WORKERS_MAX
- * VIR_THREADPOOL_WORKERS_PRIORITY
- * VIR_THREADPOOL_WORKERS_FREE
- * VIR_THREADPOOL_WORKERS_CURRENT
- *
- * Returns 0 on success, -1 in case of an error.
- */
-int
-virAdmServerGetThreadPoolParameters(virAdmServerPtr srv,
- virTypedParameterPtr *params,
- int *nparams,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("srv=%p, params=%p, nparams=%p, flags=0x%x",
- srv, params, nparams, flags);
-
- virResetLastError();
-
- virCheckAdmServerReturn(srv, -1);
- virCheckNonNullArgGoto(params, error);
-
- if ((ret = remoteAdminServerGetThreadPoolParameters(srv, params, nparams,
- flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmServerSetThreadPoolParameters:
- * @srv: a valid server object reference
- * @params: pointer to threadpool typed parameter objects
- * @nparams: number of parameters in @params
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Change server threadpool parameters according to @params. Note that some
- * tunables are read-only, thus any attempt to set them will result in a
- * failure.
- *
- * Returns 0 on success, -1 in case of an error.
- */
-int
-virAdmServerSetThreadPoolParameters(virAdmServerPtr srv,
- virTypedParameterPtr params,
- int nparams,
- unsigned int flags)
-{
- VIR_DEBUG("srv=%p, params=%p, nparams=%d, flags=0x%x",
- srv, params, nparams, flags);
-
- virResetLastError();
-
- virCheckAdmServerReturn(srv, -1);
- virCheckNonNullArgGoto(params, error);
- virCheckNonNegativeArgGoto(nparams, error);
-
- if (remoteAdminServerSetThreadPoolParameters(srv, params,
- nparams, flags) < 0)
- goto error;
-
- return 0;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmServerListClients:
- * @srv: a valid server object reference
- * @clients: pointer to a list to store an array containing objects or NULL
- * if the list is not required (number of clients only)
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Collect list of all clients connected to daemon on server @srv.
- *
- * Returns the number of clients connected to daemon on server @srv -1 in case
- * of a failure, setting @clients to NULL. There is a guaranteed extra element
- * set to NULL in the @clients list returned to make the iteration easier,
- * excluding this extra element from the final count.
- * Caller is responsible to call virAdmClientFree() on each list element,
- * followed by freeing @clients.
- */
-int
-virAdmServerListClients(virAdmServerPtr srv,
- virAdmClientPtr **clients,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("srv=%p, clients=%p, flags=0x%x", srv, clients, flags);
-
- virResetLastError();
-
- if (clients)
- *clients = NULL;
-
- virCheckAdmServerReturn(srv, -1);
- if ((ret = remoteAdminServerListClients(srv, clients, flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmServerLookupClient:
- * @srv: a valid server object reference
- * @id: ID of the client to lookup on server @srv
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Try to lookup a client on the given server based on @id.
- *
- * virAdmClientFree() should be used to free the resources after the
- * client object is no longer needed.
- *
- * Returns the requested client or NULL in case of failure. If the
- * client could not be found, then VIR_ERR_NO_CLIENT error is raised.
- */
-virAdmClientPtr
-virAdmServerLookupClient(virAdmServerPtr srv,
- unsigned long long id,
- unsigned int flags)
-{
- virAdmClientPtr ret = NULL;
-
- VIR_DEBUG("srv=%p, id=%llu, flags=0x%x", srv, id, flags);
- virResetLastError();
-
- virCheckAdmServerGoto(srv, error);
-
- if (!(ret = remoteAdminServerLookupClient(srv, id, flags)))
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return NULL;
-}
-
-/**
- * virAdmClientGetInfo:
- * @client: a client object reference
- * @params: pointer to a list of typed parameters which will be allocated
- * to store all returned parameters
- * @nparams: pointer which will hold the number of params returned in @params
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Extract identity information about a client. Attributes returned in @params
- * are mostly transport-dependent, i.e. some attributes including client
- * process's pid, gid, uid, or remote side's socket address are only available
- * for a specific connection type - local vs remote.
- * Other identity attributes like authentication method used
- * (if authentication is enabled on the remote host), SELinux context, or
- * an indicator whether client is connected via a read-only connection are
- * independent of the connection transport.
- *
- * Note that the read-only connection indicator returns false for TCP/TLS
- * clients because libvirt treats such connections as read-write by default,
- * even though a TCP client is able to restrict access to certain APIs for
- * itself.
- *
- * Returns 0 if the information has been successfully retrieved or -1 in case
- * of an error.
- */
-int
-virAdmClientGetInfo(virAdmClientPtr client,
- virTypedParameterPtr *params,
- int *nparams,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("client=%p, params=%p, nparams=%p, flags=0x%x",
- client, params, nparams, flags);
-
- virResetLastError();
- virCheckAdmClientReturn(client, -1);
- virCheckNonNullArgGoto(params, error);
-
- if ((ret = remoteAdminClientGetInfo(client, params, nparams, flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmClientClose:
- * @client: a valid client object reference
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Close @client's connection to daemon forcefully.
- *
- * Returns 0 if the daemon's connection with @client was closed successfully
- * or -1 in case of an error.
- */
-int virAdmClientClose(virAdmClientPtr client,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("client=%p, flags=0x%x", client, flags);
- virResetLastError();
-
- virCheckAdmClientGoto(client, error);
-
- if ((ret = remoteAdminClientClose(client, flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmServerGetClientLimits:
- * @srv: a valid server object reference
- * @params: pointer to client limits object
- * (return value, allocated automatically)
- * @nparams: pointer to number of parameters returned in @params
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Retrieve client limits from server @srv. These include:
- * - current number of clients connected to @srv,
- * - maximum number of clients connected to @srv,
- * - current number of clients connected to @srv waiting for authentication,
- * - maximum number of clients connected to @srv that can be wainting for
- * authentication.
- *
- * Returns 0 on success, allocating @params to size returned in @nparams, or
- * -1 in case of an error. Caller is responsible for deallocating @params.
- */
-int
-virAdmServerGetClientLimits(virAdmServerPtr srv,
- virTypedParameterPtr *params,
- int *nparams,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("srv=%p, params=%p, nparams=%p, flags=0x%x",
- srv, params, nparams, flags);
- virResetLastError();
-
- virCheckAdmServerGoto(srv, error);
-
- if ((ret = remoteAdminServerGetClientLimits(srv, params,
- nparams, flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmServerSetClientLimits:
- * @srv: a valid server object reference
- * @params: pointer to client limits object
- * @nparams: number of parameters in @params
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Change client limits configuration on server @srv.
- *
- * Caller is responsible for allocating @params prior to calling this function.
- * See 'Manage per-server client limits' in libvirt-admin.h for
- * supported parameters in @params.
- *
- * Returns 0 if the limits have been changed successfully or -1 in case of an
- * error.
- */
-int
-virAdmServerSetClientLimits(virAdmServerPtr srv,
- virTypedParameterPtr params,
- int nparams,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("srv=%p, params=%p, nparams=%d, flags=0x%x", srv, params, nparams,
- flags);
- VIR_TYPED_PARAMS_DEBUG(params, nparams);
-
- virResetLastError();
-
- virCheckAdmServerGoto(srv, error);
- virCheckNonNullArgGoto(params, error);
- virCheckNonNegativeArgGoto(nparams, error);
-
- if ((ret = remoteAdminServerSetClientLimits(srv, params, nparams,
- flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return ret;
-}
-
-/**
- * virAdmConnectGetLoggingOutputs:
- * @conn: pointer to an active admin connection
- * @outputs: pointer to a variable to store a string containing all currently
- * defined logging outputs on daemon (allocated automatically) or
- * NULL if just the number of defined outputs is required
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Retrieves a list of currently installed logging outputs. Outputs returned
- * are contained within an automatically allocated string and delimited by
- * spaces. The format of each output conforms to the format described in
- * daemon's configuration file (e.g. libvirtd.conf).
- *
- * To retrieve individual outputs, additional parsing needs to be done by the
- * caller. Caller is also responsible for freeing @outputs correctly.
- *
- * Returns the count of outputs in @outputs, or -1 in case of an error.
- */
-int
-virAdmConnectGetLoggingOutputs(virAdmConnectPtr conn,
- char **outputs,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("conn=%p, flags=0x%x", conn, flags);
-
- virResetLastError();
- virCheckAdmConnectReturn(conn, -1);
-
- if ((ret = remoteAdminConnectGetLoggingOutputs(conn, outputs,
- flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmConnectGetLoggingFilters:
- * @conn: pointer to an active admin connection
- * @filters: pointer to a variable to store a string containing all currently
- * defined logging filters on daemon (allocated automatically) or
- * NULL if just the number of defined outputs is required
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Retrieves a list of currently installed logging filters. Filters returned
- * are contained within an automatically allocated string and delimited by
- * spaces. The format of each filter conforms to the format described in
- * daemon's configuration file (e.g. libvirtd.conf).
- *
- * To retrieve individual filters, additional parsing needs to be done by the
- * caller. Caller is also responsible for freeing @filters correctly.
- *
- * Returns the number of filters returned in @filters, or -1 in case of
- * an error.
- */
-int
-virAdmConnectGetLoggingFilters(virAdmConnectPtr conn,
- char **filters,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("conn=%p, filters=%p, flags=0x%x",
- conn, filters, flags);
-
- virResetLastError();
- virCheckAdmConnectReturn(conn, -1);
-
- if ((ret = remoteAdminConnectGetLoggingFilters(conn, filters,
- flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmConnectSetLoggingOutputs:
- * @conn: pointer to an active admin connection
- * @outputs: pointer to a string containing a list of outputs to be defined
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Redefine the existing (set of) outputs(s) with a new one specified in
- * @outputs. If multiple outputs are specified, they need to be delimited by
- * spaces. The format of each output must conform to the format described in
- * daemon's configuration file (e.g. libvirtd.conf).
- *
- * To reset the existing (set of) output(s) to libvirt's defaults, an empty
- * string ("") or NULL should be passed in @outputs.
- *
- * Returns 0 if the new output or the set of outputs has been defined
- * successfully, or -1 in case of an error.
- */
-int
-virAdmConnectSetLoggingOutputs(virAdmConnectPtr conn,
- const char *outputs,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("conn=%p, outputs=%s, flags=0x%x", conn, outputs, flags);
-
- virResetLastError();
- virCheckAdmConnectReturn(conn, -1);
-
- if ((ret = remoteAdminConnectSetLoggingOutputs(conn, outputs, flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
-
-/**
- * virAdmConnectSetLoggingFilters:
- * @conn: pointer to an active admin connection
- * @filters: pointer to a string containing a list of filters to be defined
- * @flags: extra flags; not used yet, so callers should always pass 0
- *
- * Redefine the existing (set of) filter(s) with a new one specified in
- * @filters. If multiple filters are specified, they need to be delimited by
- * spaces. The format of each filter must conform to the format described in
- * daemon's configuration file (e.g. libvirtd.conf).
- *
- * To clear the currently defined (set of) filter(s), pass either an empty
- * string ("") or NULL in @filters.
- *
- * Returns 0 if the new filter or the set of filters has been defined
- * successfully, or -1 in case of an error.
- */
-int
-virAdmConnectSetLoggingFilters(virAdmConnectPtr conn,
- const char *filters,
- unsigned int flags)
-{
- int ret = -1;
-
- VIR_DEBUG("conn=%p, filters=%s, flags=0x%x", conn, filters, flags);
-
- virResetLastError();
- virCheckAdmConnectReturn(conn, -1);
-
- if ((ret = remoteAdminConnectSetLoggingFilters(conn, filters, flags)) < 0)
- goto error;
-
- return ret;
- error:
- virDispatchError(NULL);
- return -1;
-}
+++ /dev/null
-#
-# This can be used to setup URI aliases for frequently
-# used connection URIs. Aliases may contain only the
-# characters a-Z, 0-9, _, -.
-#
-# Following the '=' may be any valid libvirt admin connection
-# URI, including arbitrary parameters
-
-#uri_aliases = [
-# "admin=libvirtd:///system",
-#]
-
-# This specifies the default location the client tries to connect to if no other
-# URI is provided by the application
-
-#uri_default = "libvirtd:///system"
+++ /dev/null
-#
-# General private symbols for libvirt_admin. Add symbols here, and see
-# Makefile.am for more details.
-#
-# Keep this file sorted by header name, then by symbols with each header.
-#
-
-# admin/admin_protocol.x
-xdr_admin_client_close_args;
-xdr_admin_client_get_info_args;
-xdr_admin_client_get_info_ret;
-xdr_admin_connect_get_lib_version_ret;
-xdr_admin_connect_get_logging_filters_args;
-xdr_admin_connect_get_logging_filters_ret;
-xdr_admin_connect_get_logging_outputs_args;
-xdr_admin_connect_get_logging_outputs_ret;
-xdr_admin_connect_list_servers_args;
-xdr_admin_connect_list_servers_ret;
-xdr_admin_connect_lookup_server_args;
-xdr_admin_connect_lookup_server_ret;
-xdr_admin_connect_open_args;
-xdr_admin_connect_set_logging_filters_args;
-xdr_admin_connect_set_logging_outputs_args;
-xdr_admin_server_get_client_limits_args;
-xdr_admin_server_get_client_limits_ret;
-xdr_admin_server_get_threadpool_parameters_args;
-xdr_admin_server_get_threadpool_parameters_ret;
-xdr_admin_server_list_clients_args;
-xdr_admin_server_list_clients_ret;
-xdr_admin_server_lookup_client_args;
-xdr_admin_server_lookup_client_ret;
-xdr_admin_server_set_client_limits_args;
-xdr_admin_server_set_threadpool_parameters_args;
-
-# datatypes.h
-virAdmClientClass;
-virAdmConnectClass;
-virAdmConnectCloseCallbackDataRegister;
-virAdmConnectCloseCallbackDataReset;
-virAdmConnectCloseCallbackDataUnregister;
-virAdmGetServer;
-virAdmServerClass;
-
-# Let emacs know we want case-insensitive sorting
-# Local Variables:
-# sort-fold-case: t
-# End:
+++ /dev/null
-#
-# Officially exported symbols, for which header
-# file definitions are installed in /usr/include/libvirt
-# from libvirt-admin.h
-#
-# Versions here are *fixed* to match the libvirt version
-# at which the symbol was introduced. This ensures that
-# a new client app requiring symbol foo() can't accidentally
-# run with old libvirt-admin.so not providing foo() - the global
-# soname version info can't enforce this since we never
-# change the soname
-#
-LIBVIRT_ADMIN_2.0.0 {
- global:
- virAdmInitialize;
- virAdmClientFree;
- virAdmClientGetID;
- virAdmClientGetTimestamp;
- virAdmClientGetTransport;
- virAdmConnectOpen;
- virAdmConnectClose;
- virAdmConnectRef;
- virAdmGetVersion;
- virAdmConnectIsAlive;
- virAdmConnectGetURI;
- virAdmConnectGetLibVersion;
- virAdmConnectRegisterCloseCallback;
- virAdmConnectUnregisterCloseCallback;
- virAdmConnectListServers;
- virAdmServerGetName;
- virAdmServerGetThreadPoolParameters;
- virAdmServerFree;
- virAdmServerLookupClient;
- virAdmConnectLookupServer;
- virAdmServerSetThreadPoolParameters;
- virAdmServerListClients;
- virAdmClientGetInfo;
- virAdmClientClose;
- virAdmServerGetClientLimits;
- virAdmServerSetClientLimits;
-};
-
-LIBVIRT_ADMIN_3.0.0 {
- global:
- virAdmConnectGetLoggingOutputs;
- virAdmConnectGetLoggingFilters;
- virAdmConnectSetLoggingOutputs;
- virAdmConnectSetLoggingFilters;
-} LIBVIRT_ADMIN_2.0.0;