2015-04-15 14:16:24 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* Author: Martin Kletzander <mkletzan@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "datatypes.h"
|
2015-06-23 11:22:15 +00:00
|
|
|
#include "configmake.h"
|
|
|
|
|
2015-04-15 14:16:24 +00:00
|
|
|
#include "viralloc.h"
|
2015-10-12 14:07:52 +00:00
|
|
|
#include "virconf.h"
|
2015-04-15 14:16:24 +00:00
|
|
|
#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
|
|
|
|
|
|
|
|
#define LIBVIRTD_ADMIN_SOCK_NAME "/libvirt-admin-sock"
|
|
|
|
#define LIBVIRTD_ADMIN_UNIX_SOCKET LOCALSTATEDIR "/run/libvirt" LIBVIRTD_ADMIN_SOCK_NAME
|
|
|
|
|
|
|
|
VIR_LOG_INIT("libvirt-admin");
|
|
|
|
|
2015-10-15 12:48:58 +00:00
|
|
|
#include "admin_remote.c"
|
2015-04-15 14:16:24 +00:00
|
|
|
|
|
|
|
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
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectOpen first. But we can't rely on VIR_DEBUG working
|
2015-04-15 14:16:24 +00:00
|
|
|
* until after initialization is complete, and since this is
|
|
|
|
* one-shot, we never get here again. */
|
|
|
|
if (virThreadInitialize() < 0 ||
|
|
|
|
virErrorInitialize() < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
virLogSetFromEnv();
|
|
|
|
|
|
|
|
if (!bindtextdomain(PACKAGE, LOCALEDIR))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(remoteAdminPrivClass = virClassNew(virClassForObjectLockable(),
|
|
|
|
"remoteAdminPriv",
|
|
|
|
sizeof(remoteAdminPriv),
|
|
|
|
remoteAdminPrivDispose)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return;
|
|
|
|
error:
|
|
|
|
virAdmGlobalError = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virAdmInitialize:
|
|
|
|
*
|
|
|
|
* Initialize the library.
|
|
|
|
*
|
2016-06-29 14:12:58 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2015-04-15 14:16:24 +00:00
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
2016-06-29 14:12:58 +00:00
|
|
|
int
|
2015-04-15 14:16:24 +00:00
|
|
|
virAdmInitialize(void)
|
|
|
|
{
|
|
|
|
if (virOnce(&virAdmGlobalOnce, virAdmGlobalInit) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virAdmGlobalError)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2015-10-12 14:07:52 +00:00
|
|
|
getSocketPath(virURIPtr uri)
|
2015-04-15 14:16:24 +00:00
|
|
|
{
|
|
|
|
char *rundir = virGetUserRuntimeDirectory();
|
|
|
|
char *sock_path = NULL;
|
|
|
|
size_t i = 0;
|
|
|
|
|
2015-10-12 14:07:52 +00:00
|
|
|
if (!uri)
|
|
|
|
goto cleanup;
|
2015-04-15 14:16:24 +00:00
|
|
|
|
|
|
|
|
2015-10-12 14:07:52 +00:00
|
|
|
for (i = 0; i < uri->paramsCount; i++) {
|
|
|
|
virURIParamPtr param = &uri->params[i];
|
2015-04-15 14:16:24 +00:00
|
|
|
|
2015-10-12 14:07:52 +00:00
|
|
|
if (STREQ(param->name, "socket")) {
|
|
|
|
VIR_FREE(sock_path);
|
|
|
|
if (VIR_STRDUP(sock_path, param->value) < 0)
|
2015-04-15 14:16:24 +00:00
|
|
|
goto error;
|
2015-10-12 14:07:52 +00:00
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unknown URI parameter '%s'"), param->name);
|
|
|
|
goto error;
|
2015-04-15 14:16:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sock_path) {
|
2016-04-06 08:43:39 +00:00
|
|
|
if (STRNEQ_NULLABLE(uri->scheme, "libvirtd")) {
|
2015-10-12 14:07:52 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unsupported URI scheme '%s'"),
|
2016-04-06 08:43:39 +00:00
|
|
|
NULLSTR(uri->scheme));
|
2015-10-12 14:07:52 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (STREQ_NULLABLE(uri->path, "/system")) {
|
2015-04-15 14:16:24 +00:00
|
|
|
if (VIR_STRDUP(sock_path, LIBVIRTD_ADMIN_UNIX_SOCKET) < 0)
|
|
|
|
goto error;
|
|
|
|
} else if (STREQ_NULLABLE(uri->path, "/session")) {
|
2015-10-12 14:07:52 +00:00
|
|
|
if (!rundir || virAsprintf(&sock_path, "%s%s", rundir,
|
|
|
|
LIBVIRTD_ADMIN_SOCK_NAME) < 0)
|
2015-04-15 14:16:24 +00:00
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2015-10-12 14:07:52 +00:00
|
|
|
_("Invalid URI path '%s', try '/system'"),
|
|
|
|
uri->path ? uri->path : "");
|
2015-04-15 14:16:24 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(rundir);
|
|
|
|
return sock_path;
|
|
|
|
|
|
|
|
error:
|
|
|
|
VIR_FREE(sock_path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:38:17 +00:00
|
|
|
static int
|
|
|
|
virAdmGetDefaultURI(virConfPtr conf, char **uristr)
|
2015-10-12 14:07:52 +00:00
|
|
|
{
|
2016-07-08 10:38:17 +00:00
|
|
|
const char *defname = virGetEnvAllowSUID("LIBVIRT_ADMIN_DEFAULT_URI");
|
|
|
|
if (defname && *defname) {
|
|
|
|
if (VIR_STRDUP(*uristr, defname) < 0)
|
|
|
|
return -1;
|
|
|
|
VIR_DEBUG("Using LIBVIRT_ADMIN_DEFAULT_URI '%s'", *uristr);
|
2015-10-12 14:07:52 +00:00
|
|
|
} else {
|
2016-07-27 11:23:03 +00:00
|
|
|
if (virConfGetValueString(conf, "uri_default", uristr) < 0)
|
2016-07-08 10:38:17 +00:00
|
|
|
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,
|
2016-07-29 11:57:59 +00:00
|
|
|
* we set the default admin server URI to 'libvirtd:///system' or
|
|
|
|
* 'libvirtd:///session' depending on the process's EUID.
|
2016-07-08 10:38:17 +00:00
|
|
|
*/
|
2016-08-09 11:57:41 +00:00
|
|
|
if (geteuid() == 0) {
|
|
|
|
if (VIR_STRDUP(*uristr, "libvirtd:///system") < 0)
|
2016-07-29 11:57:59 +00:00
|
|
|
return -1;
|
2016-08-09 11:57:41 +00:00
|
|
|
} else {
|
|
|
|
if (VIR_STRDUP(*uristr, "libvirtd:///session") < 0)
|
2016-07-29 11:57:59 +00:00
|
|
|
return -1;
|
2016-08-09 11:57:41 +00:00
|
|
|
}
|
2016-07-08 10:38:17 +00:00
|
|
|
}
|
2015-10-12 14:07:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-08 10:38:17 +00:00
|
|
|
return 0;
|
2015-10-12 14:07:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 14:16:24 +00:00
|
|
|
/**
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectOpen:
|
2015-04-15 14:16:24 +00:00
|
|
|
* @name: uri of the daemon to connect to, NULL for default
|
2016-05-05 11:42:52 +00:00
|
|
|
* @flags: bitwise-OR of virConnectFlags; so far the only supported flag is
|
|
|
|
* VIR_CONNECT_NO_ALIASES
|
2015-04-15 14:16:24 +00:00
|
|
|
*
|
|
|
|
* Opens connection to admin interface of the daemon.
|
|
|
|
*
|
2015-12-10 12:46:45 +00:00
|
|
|
* Returns @virAdmConnectPtr object or NULL on error
|
2015-04-15 14:16:24 +00:00
|
|
|
*/
|
2015-12-10 12:46:45 +00:00
|
|
|
virAdmConnectPtr
|
|
|
|
virAdmConnectOpen(const char *name, unsigned int flags)
|
2015-04-15 14:16:24 +00:00
|
|
|
{
|
|
|
|
char *sock_path = NULL;
|
2015-10-30 11:11:52 +00:00
|
|
|
char *alias = NULL;
|
2015-12-10 12:46:45 +00:00
|
|
|
virAdmConnectPtr conn = NULL;
|
2015-10-12 14:07:52 +00:00
|
|
|
virConfPtr conf = NULL;
|
2016-07-08 10:38:17 +00:00
|
|
|
char *uristr = NULL;
|
2015-04-15 14:16:24 +00:00
|
|
|
|
|
|
|
if (virAdmInitialize() < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
VIR_DEBUG("flags=%x", flags);
|
|
|
|
virResetLastError();
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
if (!(conn = virAdmConnectNew()))
|
2015-04-15 14:16:24 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-10-12 14:07:52 +00:00
|
|
|
if (virConfLoadConfig(&conf, "libvirt-admin.conf") < 0)
|
|
|
|
goto error;
|
|
|
|
|
2016-07-08 10:38:17 +00:00
|
|
|
if (name) {
|
|
|
|
if (VIR_STRDUP(uristr, name) < 0)
|
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
if (virAdmGetDefaultURI(conf, &uristr) < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
2015-10-12 14:07:52 +00:00
|
|
|
|
2015-10-30 11:11:52 +00:00
|
|
|
if ((!(flags & VIR_CONNECT_NO_ALIASES) &&
|
2016-07-08 10:38:17 +00:00
|
|
|
virURIResolveAlias(conf, uristr, &alias) < 0))
|
2015-10-30 11:11:52 +00:00
|
|
|
goto error;
|
|
|
|
|
2016-07-08 10:38:17 +00:00
|
|
|
if (alias) {
|
|
|
|
VIR_FREE(uristr);
|
|
|
|
uristr = alias;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(conn->uri = virURIParse(uristr)))
|
2015-10-12 14:07:52 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
if (!(sock_path = getSocketPath(conn->uri)))
|
2015-04-15 14:16:24 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
if (!(conn->privateData = remoteAdminPrivNew(sock_path)))
|
2015-04-15 14:16:24 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
conn->privateDataFreeFunc = remoteAdminPrivFree;
|
2015-04-15 14:16:24 +00:00
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
if (remoteAdminConnectOpen(conn, flags) < 0)
|
2015-04-15 14:16:24 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(sock_path);
|
2016-07-08 10:38:17 +00:00
|
|
|
VIR_FREE(uristr);
|
2015-10-12 14:07:52 +00:00
|
|
|
virConfFree(conf);
|
2015-12-10 12:46:45 +00:00
|
|
|
return conn;
|
2015-04-15 14:16:24 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
2015-12-10 12:46:45 +00:00
|
|
|
virObjectUnref(conn);
|
|
|
|
conn = NULL;
|
2015-04-15 14:16:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectClose:
|
|
|
|
* @conn: pointer to admin connection to close
|
2015-04-15 14:16:24 +00:00
|
|
|
*
|
|
|
|
* 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
|
2015-12-10 12:46:45 +00:00
|
|
|
* initial virAdmConnectOpen, as well as virAdmConnectRef; it is also temporarily
|
2015-04-15 14:16:24 +00:00
|
|
|
* increased by other API that depend on the connection remaining alive. The
|
2015-12-10 12:46:45 +00:00
|
|
|
* open and every virAdmConnectRef call should have a matching
|
|
|
|
* virAdmConnectClose, and all other references will be released after the
|
2015-04-15 14:16:24 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2015-12-10 12:46:45 +00:00
|
|
|
* It is possible for the last virAdmConnectClose to return a positive value if
|
2015-04-15 14:16:24 +00:00
|
|
|
* some other object still has a temporary reference to the connection, but the
|
|
|
|
* application should not try to further use a connection after the
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectClose that matches the initial open.
|
2015-04-15 14:16:24 +00:00
|
|
|
*/
|
|
|
|
int
|
2015-12-10 12:46:45 +00:00
|
|
|
virAdmConnectClose(virAdmConnectPtr conn)
|
2015-04-15 14:16:24 +00:00
|
|
|
{
|
2015-12-10 12:46:45 +00:00
|
|
|
VIR_DEBUG("conn=%p", conn);
|
2015-04-15 14:16:24 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
2015-12-10 12:46:45 +00:00
|
|
|
if (!conn)
|
2015-04-15 14:16:24 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
2015-04-15 14:16:24 +00:00
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
if (!virObjectUnref(conn))
|
2015-04-15 14:16:24 +00:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectRef:
|
|
|
|
* @conn: the connection to hold a reference on
|
2015-04-15 14:16:24 +00:00
|
|
|
*
|
|
|
|
* Increment the reference count on the connection. For each additional call to
|
2015-12-10 12:46:45 +00:00
|
|
|
* this method, there shall be a corresponding call to virAdmConnectClose to
|
2015-04-15 14:16:24 +00:00
|
|
|
* 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
|
2015-12-10 12:46:45 +00:00
|
|
|
virAdmConnectRef(virAdmConnectPtr conn)
|
2015-04-15 14:16:24 +00:00
|
|
|
{
|
2015-12-10 12:46:45 +00:00
|
|
|
VIR_DEBUG("conn=%p refs=%d", conn,
|
|
|
|
conn ? conn->object.parent.u.s.refs : 0);
|
2015-04-15 14:16:24 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
2015-12-10 12:46:45 +00:00
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
2015-04-15 14:16:24 +00:00
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virObjectRef(conn);
|
2015-04-15 14:16:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-11-26 14:08:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virAdmGetVersion:
|
|
|
|
* @libVer: where to store the library version
|
|
|
|
*
|
|
|
|
* Provides version information. @libVer is the version of the library and will
|
2016-09-21 19:31:50 +00:00
|
|
|
* always be set unless an error occurs in which case an error code and a
|
2015-11-26 14:08:36 +00:00
|
|
|
* generic message will be returned. @libVer format is as follows:
|
|
|
|
* major * 1,000,000 + minor * 1,000 + release.
|
|
|
|
*
|
2015-12-10 12:46:45 +00:00
|
|
|
* NOTE: To get the remote side library version use virAdmConnectGetLibVersion
|
|
|
|
* instead.
|
2015-11-26 14:08:36 +00:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
}
|
2015-10-14 13:10:02 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectIsAlive:
|
|
|
|
* @conn: connection to admin server
|
2015-10-14 13:10:02 +00:00
|
|
|
*
|
|
|
|
* 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
|
2015-12-10 12:46:45 +00:00
|
|
|
virAdmConnectIsAlive(virAdmConnectPtr conn)
|
2015-10-14 13:10:02 +00:00
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
remoteAdminPrivPtr priv = NULL;
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
VIR_DEBUG("conn=%p", conn);
|
2015-10-14 13:10:02 +00:00
|
|
|
|
2016-03-02 15:29:11 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
if (!conn)
|
2015-10-14 13:10:02 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
2015-10-14 13:10:02 +00:00
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
priv = conn->privateData;
|
2015-10-14 13:10:02 +00:00
|
|
|
virObjectLock(priv);
|
|
|
|
ret = virNetClientIsOpen(priv->client);
|
|
|
|
virObjectUnlock(priv);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2015-10-12 14:07:52 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectGetURI:
|
|
|
|
* @conn: pointer to an admin connection
|
2015-10-12 14:07:52 +00:00
|
|
|
*
|
|
|
|
* String returned by this method is normally the same as the string passed
|
2015-12-10 12:46:45 +00:00
|
|
|
* to the virAdmConnectOpen. Even if NULL was passed to virAdmConnectOpen,
|
2015-10-12 14:07:52 +00:00
|
|
|
* 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 *
|
2015-12-10 12:46:45 +00:00
|
|
|
virAdmConnectGetURI(virAdmConnectPtr conn)
|
2015-10-12 14:07:52 +00:00
|
|
|
{
|
|
|
|
char *uri = NULL;
|
2015-12-10 12:46:45 +00:00
|
|
|
VIR_DEBUG("conn=%p", conn);
|
2015-10-12 14:07:52 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virCheckAdmConnectReturn(conn, NULL);
|
2015-10-12 14:07:52 +00:00
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
if (!(uri = virURIFormat(conn->uri)))
|
2015-10-12 14:07:52 +00:00
|
|
|
virDispatchError(NULL);
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
}
|
2015-10-12 15:10:57 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectRegisterCloseCallback:
|
|
|
|
* @conn: connection to admin server
|
2015-10-12 15:10:57 +00:00
|
|
|
* @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
|
|
|
|
*/
|
2015-12-10 12:46:45 +00:00
|
|
|
int virAdmConnectRegisterCloseCallback(virAdmConnectPtr conn,
|
|
|
|
virAdmConnectCloseFunc cb,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback freecb)
|
2015-10-12 15:10:57 +00:00
|
|
|
{
|
2015-12-10 12:46:45 +00:00
|
|
|
VIR_DEBUG("conn=%p", conn);
|
2015-10-12 15:10:57 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
2015-10-12 15:10:57 +00:00
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virObjectRef(conn);
|
2015-10-12 15:10:57 +00:00
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virObjectLock(conn->closeCallback);
|
2015-10-12 15:10:57 +00:00
|
|
|
|
|
|
|
virCheckNonNullArgGoto(cb, error);
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
if (conn->closeCallback->callback) {
|
2015-10-12 15:10:57 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("A close callback is already registered"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
conn->closeCallback->conn = conn;
|
|
|
|
conn->closeCallback->callback = cb;
|
|
|
|
conn->closeCallback->opaque = opaque;
|
|
|
|
conn->closeCallback->freeCallback = freecb;
|
2015-10-12 15:10:57 +00:00
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virObjectUnlock(conn->closeCallback);
|
2015-10-12 15:10:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
2015-12-10 12:46:45 +00:00
|
|
|
virObjectUnlock(conn->closeCallback);
|
2015-10-12 15:10:57 +00:00
|
|
|
virDispatchError(NULL);
|
2015-12-10 12:46:45 +00:00
|
|
|
virObjectUnref(conn);
|
2015-10-12 15:10:57 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectUnregisterCloseCallback:
|
|
|
|
* @conn: pointer to connection object
|
2015-10-12 15:10:57 +00:00
|
|
|
* @cb: pointer to the current registered callback
|
|
|
|
*
|
|
|
|
* Unregisters the callback previously set with the
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectRegisterCloseCallback method. The callback
|
2015-10-12 15:10:57 +00:00
|
|
|
* 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
|
|
|
|
*/
|
2015-12-10 12:46:45 +00:00
|
|
|
int virAdmConnectUnregisterCloseCallback(virAdmConnectPtr conn,
|
|
|
|
virAdmConnectCloseFunc cb)
|
2015-10-12 15:10:57 +00:00
|
|
|
{
|
2015-12-10 12:46:45 +00:00
|
|
|
VIR_DEBUG("conn=%p", conn);
|
2015-10-12 15:10:57 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
2015-10-12 15:10:57 +00:00
|
|
|
virCheckNonNullArgGoto(cb, error);
|
|
|
|
|
2016-11-10 12:21:29 +00:00
|
|
|
if (virAdmConnectCloseCallbackDataUnregister(conn->closeCallback, cb) < 0)
|
2015-10-12 15:10:57 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
2015-10-05 15:17:51 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-10 12:46:45 +00:00
|
|
|
* virAdmConnectGetLibVersion:
|
|
|
|
* @conn: pointer to an active admin connection
|
2015-10-05 15:17:51 +00:00
|
|
|
* @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:
|
|
|
|
*/
|
2015-12-10 12:46:45 +00:00
|
|
|
int virAdmConnectGetLibVersion(virAdmConnectPtr conn,
|
|
|
|
unsigned long long *libVer)
|
2015-10-05 15:17:51 +00:00
|
|
|
{
|
2015-12-10 12:46:45 +00:00
|
|
|
VIR_DEBUG("conn=%p, libVir=%p", conn, libVer);
|
2015-10-05 15:17:51 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
2015-10-05 15:17:51 +00:00
|
|
|
virCheckNonNullArgReturn(libVer, -1);
|
|
|
|
|
2015-12-10 12:46:45 +00:00
|
|
|
if (remoteAdminConnectGetLibVersion(conn, libVer) < 0)
|
2015-10-05 15:17:51 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
return 0;
|
2015-08-14 07:17:01 +00:00
|
|
|
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);
|
2015-10-05 15:17:51 +00:00
|
|
|
|
2015-08-14 07:17:01 +00:00
|
|
|
virResetLastError();
|
2016-03-01 13:56:12 +00:00
|
|
|
|
|
|
|
if (!srv)
|
|
|
|
return 0;
|
|
|
|
|
2015-08-14 07:17:01 +00:00
|
|
|
virCheckAdmServerReturn(srv, -1);
|
|
|
|
|
|
|
|
virObjectUnref(srv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 08:35:26 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2015-08-14 07:17:01 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
2016-03-01 14:03:04 +00:00
|
|
|
* @flags: extra flags; not used yet, so callers should always pass 0
|
2015-08-14 07:17:01 +00:00
|
|
|
*
|
|
|
|
* 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=%x", conn, servers, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (servers)
|
|
|
|
*servers = NULL;
|
|
|
|
|
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
|
|
|
if ((ret = remoteAdminConnectListServers(conn, servers, flags)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return ret;
|
2015-10-05 15:17:51 +00:00
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-01 16:33:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%x", conn, NULLSTR(name), flags);
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
virCheckAdmConnectGoto(conn, cleanup);
|
|
|
|
virCheckNonNullArgGoto(name, cleanup);
|
|
|
|
|
|
|
|
ret = remoteAdminConnectLookupServer(conn, name, flags);
|
|
|
|
cleanup:
|
|
|
|
if (!ret)
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-11-23 11:41:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%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;
|
|
|
|
}
|
admin: Introduce virAdmServerSetThreadPoolParameters
Since threadpool increments the current number of threads according to current
load, i.e. how many jobs are waiting in the queue. The count however, is
constrained by max and min limits of workers. The logic of this new API works
like this:
1) setting the minimum
a) When the limit is increased, depending on the current number of
threads, new threads are possibly spawned if the current number of
threads is less than the new minimum limit
b) Decreasing the minimum limit has no possible effect on the current
number of threads
2) setting the maximum
a) Icreasing the maximum limit has no immediate effect on the current
number of threads, it only allows the threadpool to spawn more
threads when new jobs, that would otherwise end up queued, arrive.
b) Decreasing the maximum limit may affect the current number of
threads, if the current number of threads is less than the new
maximum limit. Since there may be some ongoing time-consuming jobs
that would effectively block this API from killing any threads.
Therefore, this API is asynchronous with best-effort execution,
i.e. the necessary number of workers will be terminated once they
finish their previous job, unless other workers had already
terminated, decreasing the limit to the requested value.
3) setting priority workers
- both increase and decrease in count of these workers have an
immediate impact on the current number of workers, new ones will be
spawned or some of them get terminated respectively.
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-02-22 13:24:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%x, flags=%x",
|
|
|
|
srv, params, nparams, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
virCheckAdmServerReturn(srv, -1);
|
|
|
|
virCheckNonNullArgGoto(params, error);
|
2016-05-03 15:04:42 +00:00
|
|
|
virCheckNonNegativeArgGoto(nparams, error);
|
admin: Introduce virAdmServerSetThreadPoolParameters
Since threadpool increments the current number of threads according to current
load, i.e. how many jobs are waiting in the queue. The count however, is
constrained by max and min limits of workers. The logic of this new API works
like this:
1) setting the minimum
a) When the limit is increased, depending on the current number of
threads, new threads are possibly spawned if the current number of
threads is less than the new minimum limit
b) Decreasing the minimum limit has no possible effect on the current
number of threads
2) setting the maximum
a) Icreasing the maximum limit has no immediate effect on the current
number of threads, it only allows the threadpool to spawn more
threads when new jobs, that would otherwise end up queued, arrive.
b) Decreasing the maximum limit may affect the current number of
threads, if the current number of threads is less than the new
maximum limit. Since there may be some ongoing time-consuming jobs
that would effectively block this API from killing any threads.
Therefore, this API is asynchronous with best-effort execution,
i.e. the necessary number of workers will be terminated once they
finish their previous job, unless other workers had already
terminated, decreasing the limit to the requested value.
3) setting priority workers
- both increase and decrease in count of these workers have an
immediate impact on the current number of workers, new ones will be
spawned or some of them get terminated respectively.
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-02-22 13:24:04 +00:00
|
|
|
|
|
|
|
if (remoteAdminServerSetThreadPoolParameters(srv, params,
|
|
|
|
nparams, flags) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-04-14 22:20:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%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;
|
|
|
|
}
|
2016-04-22 07:47:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%x", srv, id, flags);
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
virCheckAdmServerGoto(srv, error);
|
|
|
|
|
|
|
|
if (!(ret = remoteAdminServerLookupClient(srv, id, flags)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-04-22 11:05:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%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;
|
|
|
|
}
|
2016-04-28 08:26:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%x", client, flags);
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
virCheckAdmClientGoto(client, error);
|
|
|
|
|
|
|
|
if ((ret = remoteAdminClientClose(client, flags)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-04-04 08:28:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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, flags=%x", srv, flags);
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
virCheckAdmServerGoto(srv, error);
|
|
|
|
|
|
|
|
if ((ret = remoteAdminServerGetClientLimits(srv, params,
|
|
|
|
nparams, flags)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-04-04 12:24:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%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;
|
|
|
|
}
|
2016-03-04 22:00:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%x", conn, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
|
|
|
|
|
|
|
if ((ret = remoteAdminConnectGetLoggingOutputs(conn, outputs,
|
|
|
|
flags)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-04 21:58:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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, flags=%x", conn, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
|
|
|
|
|
|
|
if ((ret = remoteAdminConnectGetLoggingFilters(conn, filters,
|
|
|
|
flags)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-08 12:37:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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=%x", conn, outputs, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
|
|
|
|
|
|
|
if ((ret = remoteAdminConnectSetLoggingOutputs(conn, outputs, flags)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-30 13:14:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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, flags=%x", conn, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
virCheckAdmConnectReturn(conn, -1);
|
|
|
|
|
|
|
|
if ((ret = remoteAdminConnectSetLoggingFilters(conn, filters, flags)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
error:
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|