[libvirt] [PATCH 0/3] Enable admin API functionality and tar distribution

Finally enable admin API in our code and start distributing it both via a tarball and as part of an rpm package. I also added some usage examples, however the html documentation is missing, because of our current xsl stylesheet, more specifically because of how xsltproc works. It takes a stylesheet and an xml file which it processes and produces index.html for each xml file on its input. This way, we either get TOC for libvirt APIs or just the admin. The same story goes for libvirt-qemu and libvirt-lxc which we neither generate, nor distribute. I talked to Jirka and we thought about merging the xmls somehow to a temporary file and then generate the index.html but that requires some more digging, especially into xslt capabilities. So I haven't figured this one out yet, but once I do, I'll enable it for all of our *.xml API 'recipes'. Erik Skultety (3): admin: enable both admin API functionality and tarball distribution examples: admin: Add some examples for the new admin APIs spec: distribute admin API within libvirt-client package .gitignore | 6 ++ Makefile.am | 2 +- cfg.mk | 4 +- daemon/libvirtd.c | 2 +- docs/Makefile.am | 5 +- examples/Makefile.am | 14 +++- examples/admin/client_close.c | 57 +++++++++++++ examples/admin/client_info.c | 165 +++++++++++++++++++++++++++++++++++++ examples/admin/client_limits.c | 63 ++++++++++++++ examples/admin/list_clients.c | 111 +++++++++++++++++++++++++ examples/admin/list_servers.c | 42 ++++++++++ examples/admin/threadpool_params.c | 65 +++++++++++++++ include/libvirt/Makefile.am | 6 +- libvirt.spec.in | 14 ++-- src/libvirt_admin_public.syms | 2 +- 15 files changed, 538 insertions(+), 20 deletions(-) create mode 100644 examples/admin/client_close.c create mode 100644 examples/admin/client_info.c create mode 100644 examples/admin/client_limits.c create mode 100644 examples/admin/list_clients.c create mode 100644 examples/admin/list_servers.c create mode 100644 examples/admin/threadpool_params.c -- 2.5.5

This patch enables admin socket creation in daemon's code, bumps the library version in libvirt_admin_public.syms, and performs all necessary modifications to our makefiles so that admin API can finally be included in the tarball, and eventually become part of an rpm package (a patch later in this series). Signed-off-by: Erik Skultety <eskultet@redhat.com> --- Makefile.am | 2 +- daemon/libvirtd.c | 2 +- docs/Makefile.am | 5 +++-- include/libvirt/Makefile.am | 6 +----- src/libvirt_admin_public.syms | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Makefile.am b/Makefile.am index ef88067..99ee476 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,7 +44,7 @@ EXTRA_DIST = \ AUTHORS.in pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libvirt.pc libvirt-qemu.pc libvirt-lxc.pc +pkgconfig_DATA = libvirt.pc libvirt-qemu.pc libvirt-lxc.pc libvirt-admin.pc NEWS: $(top_srcdir)/docs/news.xsl $(top_srcdir)/docs/news.html.in $(AM_V_GEN)if [ -x $(XSLTPROC) ] ; then \ diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index a1e2015..77c57a6 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -534,7 +534,7 @@ daemonSetupNetworking(virNetServerPtr srv, goto cleanup; /* Temporarily disabled */ - if (sock_path_adm && false) { + if (sock_path_adm) { VIR_DEBUG("Registering unix socket %s", sock_path_adm); if (!(svcAdm = virNetServerServiceNewUNIX(sock_path_adm, unix_sock_adm_mask, diff --git a/docs/Makefile.am b/docs/Makefile.am index 282d101..206ef3b 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -132,7 +132,8 @@ apidir = $(pkgdatadir)/api api_DATA = \ libvirt-api.xml \ libvirt-qemu-api.xml \ - libvirt-lxc-api.xml + libvirt-lxc-api.xml \ + libvirt-admin-api.xml fig = \ libvirt-net-logical.fig \ @@ -155,7 +156,7 @@ EXTRA_DIST= \ hacking1.xsl hacking2.xsl wrapstring.xsl \ $(dot_html) $(dot_html_in) $(gif) $(apihtml) $(apipng) \ $(devhelphtml) $(devhelppng) $(devhelpcss) $(devhelpxsl) \ - $(xml) $(qemu_xml) $(lxc_xml) $(fig) $(png) $(css) \ + $(xml) $(qemu_xml) $(lxc_xml) $(admin_xml) $(fig) $(png) $(css) \ $(patches) $(dot_php_in) $(dot_php_code_in) $(dot_php)\ $(internals_html_in) $(internals_html) \ sitemap.html.in aclperms.htmlinc \ diff --git a/include/libvirt/Makefile.am b/include/libvirt/Makefile.am index a59b8ab..65a1b23 100644 --- a/include/libvirt/Makefile.am +++ b/include/libvirt/Makefile.am @@ -19,14 +19,10 @@ virincdir = $(includedir)/libvirt allheaders = $(wildcard $(srcdir)/*.h) -virinc_HEADERS = $(filter-out $(srcdir)/libvirt-admin.h \ - $(srcdir)/libvirt-common.h, $(allheaders)) +virinc_HEADERS = $(filter-out $(srcdir)/libvirt-common.h, $(allheaders)) virinc_HEADERS += libvirt-common.h EXTRA_DIST = libvirt-common.h.in -# Temporarily disabled, but we need it for building -EXTRA_DIST += libvirt-admin.h - install-exec-hook: $(mkinstalldirs) $(DESTDIR)$(virincdir) diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms index 53df5fc..c63b9bd 100644 --- a/src/libvirt_admin_public.syms +++ b/src/libvirt_admin_public.syms @@ -10,7 +10,7 @@ # soname version info can't enforce this since we never # change the soname # -LIBVIRT_ADMIN_1.3.0 { +LIBVIRT_ADMIN_2.0.0 { global: virAdmClientFree; virAdmClientGetID; -- 2.5.5

Some of the examples make use of asprintf and strtol functions (to keep things simple) which are prohibited to use within our code (enforced by syntax-check). Therefore besides adding some examples, this patch also updates cfg.mk to exclude examples directory from asprintf and strtol rules, as well as updates .gitignore to exclude all the new admin binaries created in the 'examples' dir. Signed-off-by: Erik Skultety <eskultet@redhat.com> --- .gitignore | 6 ++ cfg.mk | 4 +- examples/Makefile.am | 14 +++- examples/admin/client_close.c | 57 +++++++++++++ examples/admin/client_info.c | 165 +++++++++++++++++++++++++++++++++++++ examples/admin/client_limits.c | 63 ++++++++++++++ examples/admin/list_clients.c | 111 +++++++++++++++++++++++++ examples/admin/list_servers.c | 42 ++++++++++ examples/admin/threadpool_params.c | 65 +++++++++++++++ 9 files changed, 523 insertions(+), 4 deletions(-) create mode 100644 examples/admin/client_close.c create mode 100644 examples/admin/client_info.c create mode 100644 examples/admin/client_limits.c create mode 100644 examples/admin/list_clients.c create mode 100644 examples/admin/list_servers.c create mode 100644 examples/admin/threadpool_params.c diff --git a/.gitignore b/.gitignore index fba1464..e87c085 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,12 @@ /docs/libvirt-refs.xml /docs/search.php /docs/todo.html.in +/examples/admin/client_close +/examples/admin/client_info +/examples/admin/client_limits +/examples/admin/list_clients +/examples/admin/list_servers +/examples/admin/threadpool_params /examples/object-events/event-test /examples/dominfo/info1 /examples/domsuspend/suspend diff --git a/cfg.mk b/cfg.mk index 0475bd9..cf47d4c 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1147,7 +1147,7 @@ exclude_file_name_regexp--sc_prohibit_access_xok = \ ^(cfg\.mk|src/util/virutil\.c)$$ exclude_file_name_regexp--sc_prohibit_asprintf = \ - ^(cfg\.mk|bootstrap.conf$$|src/util/virstring\.[ch]$$|tests/vircgroupmock\.c$$) + ^(cfg\.mk|bootstrap.conf$$|examples/|src/util/virstring\.[ch]$$|tests/vircgroupmock\.c$$) exclude_file_name_regexp--sc_prohibit_strdup = \ ^(docs/|examples/|src/util/virstring\.c|tests/vir(netserverclient|cgroup)mock.c$$) @@ -1189,7 +1189,7 @@ exclude_file_name_regexp--sc_prohibit_sprintf = \ exclude_file_name_regexp--sc_prohibit_strncpy = ^src/util/virstring\.c$$ -exclude_file_name_regexp--sc_prohibit_strtol = ^examples/dom.*/.*\.c$$ +exclude_file_name_regexp--sc_prohibit_strtol = ^examples/.*$$ exclude_file_name_regexp--sc_prohibit_gethostby = ^docs/nss.html.in$$ diff --git a/examples/Makefile.am b/examples/Makefile.am index e1c37f0..bd8460d 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -37,11 +37,14 @@ EXTRA_DIST = \ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir) \ -I$(top_builddir)/gnulib/lib -I$(top_srcdir)/gnulib/lib LDADD = $(STATIC_BINARIES) $(WARN_CFLAGS) $(COVERAGE_LDFLAGS) \ - $(top_builddir)/src/libvirt.la $(top_builddir)/gnulib/lib/libgnu.la + $(top_builddir)/src/libvirt.la $(top_builddir)/gnulib/lib/libgnu.la \ + $(top_builddir)/src/libvirt-admin.la noinst_PROGRAMS=dominfo/info1 dommigrate/dommigrate domsuspend/suspend \ domtop/domtop hellolibvirt/hellolibvirt object-events/event-test \ - openauth/openauth rename/rename + openauth/openauth rename/rename admin/list_servers admin/list_clients \ + admin/threadpool_params admin/client_limits admin/client_info \ + admin/client_close dominfo_info1_SOURCES = dominfo/info1.c dommigrate_dommigrate_SOURCES = dommigrate/dommigrate.c @@ -57,6 +60,13 @@ object_events_event_test_SOURCES = object-events/event-test.c openauth_openauth_SOURCES = openauth/openauth.c rename_rename_SOURCES = rename/rename.c +admin_list_servers_SOURCES = admin/list_servers.c +admin_list_clients_SOURCES = admin/list_clients.c +admin_threadpool_params_SOURCES = admin/threadpool_params.c +admin_client_limits_SOURCES = admin/client_limits.c +admin_client_info_SOURCES = admin/client_info.c +admin_client_close_SOURCES = admin/client_close.c + if WITH_APPARMOR_PROFILES apparmordir = $(sysconfdir)/apparmor.d/ apparmor_DATA = \ diff --git a/examples/admin/client_close.c b/examples/admin/client_close.c new file mode 100644 index 0000000..a392707 --- /dev/null +++ b/examples/admin/client_close.c @@ -0,0 +1,57 @@ +#include<stdio.h> +#include<stdlib.h> +#include<libvirt/libvirt.h> +#include<libvirt/libvirt-admin.h> + +int main(void) +{ + int ret = -1; + virAdmConnectPtr conn1 = NULL; /* admin connection */ + virConnectPtr conn2 = NULL; /* libvirt standard connection */ + virAdmServerPtr srv = NULL; /* which server is the client connected to */ + virAdmClientPtr clnt = NULL; /* which client to disconnect */ + + /* first, open a standard libvirt connection to the daemon */ + if (!(conn2 = virConnectOpen(NULL))) + return -1; + + /* next, open an admin connection that will be used to disconnect the + * standard libvirt client + */ + if (!(conn1 = virAdmConnectOpen(NULL, 0))) + goto cleanup; + + /* a virAdmServerPtr handle is needed, so a server lookup is performed */ + if (!(srv = virAdmConnectLookupServer(conn1, "libvirtd", 0))) + goto cleanup; + + /* a virAdmClientPtr handle is also necessary, so lookup for client is + * performed as well + */ + if (!(clnt = virAdmServerLookupClient(srv, 1, 0))) + goto cleanup; + + /* finally, use the client handle to disconnect the standard libvirt client + * from libvirtd daemon + */ + if (virAdmClientClose(clnt, 0) < 0) + goto cleanup; + + ret = 0; + cleanup: + /* Once finished, both server and client handles need to be freed and + * both connections @conn1 and @conn2 should be closed to free the + * memory. + * NOTE: Although @conn2 has been disconnected, unlike disconnecting by + * calling virConnectClose which closes the connection voluntarily and + * frees the object automatically, virAdmClientClose is a forceful + * disconnect of another client (client can use it on itself as well). + * Therefore no automatic deallocation of the object takes place and is + * the callers responsibility to do so. + */ + virAdmClientFree(clnt); + virAdmServerFree(srv); + virAdmConnectClose(conn1); + virConnectClose(conn2); + return ret; +} diff --git a/examples/admin/client_info.c b/examples/admin/client_info.c new file mode 100644 index 0000000..dd0a04a --- /dev/null +++ b/examples/admin/client_info.c @@ -0,0 +1,165 @@ +#define _GNU_SOURCE +#include<stdio.h> +#include<stdlib.h> +#include<time.h> +#include<string.h> +#include<libvirt/libvirt-admin.h> + +static const char * +exampleTransportToString(int transport) +{ + const char *str = NULL; + + switch ((virClientTransport) transport) { + case VIR_CLIENT_TRANS_UNIX: + str = "unix"; + break; + case VIR_CLIENT_TRANS_TCP: + str = "tcp"; + break; + case VIR_CLIENT_TRANS_TLS: + str = "tls"; + break; + } + + return str ? str : "unknown"; +} + +static char * +exampleGetTimeStr(time_t then) +{ + char *ret = NULL; + struct tm timeinfo; + + if (!localtime_r(&then, &timeinfo)) + return NULL; + + if (!(ret = calloc(64, sizeof(char)))) + return NULL; + + if (strftime(ret, 64, "%Y-%m-%d %H:%M:%S%z", + &timeinfo) == 0) { + free(ret); + return NULL; + } + + return ret; +} + +static char * +exampleGetTypedParamValue(virTypedParameterPtr item) +{ + int ret = 0; + char *str = NULL; + + switch (item->type) { + case VIR_TYPED_PARAM_INT: + ret = asprintf(&str, "%d", item->value.i); + break; + + case VIR_TYPED_PARAM_UINT: + ret = asprintf(&str, "%u", item->value.ui); + break; + + case VIR_TYPED_PARAM_LLONG: + ret = asprintf(&str, "%lld", item->value.l); + break; + + case VIR_TYPED_PARAM_ULLONG: + ret = asprintf(&str, "%llu", item->value.ul); + break; + + case VIR_TYPED_PARAM_DOUBLE: + ret = asprintf(&str, "%f", item->value.d); + break; + + case VIR_TYPED_PARAM_BOOLEAN: + str = strdup(item->value.b ? "yes" : "no"); + break; + + case VIR_TYPED_PARAM_STRING: + str = strdup(item->value.s); + break; + + default: + fprintf(stderr, "unimplemented parameter type %d\n", item->type); + return NULL; + } + + return str; +} + +int main(int argc, char **argv) +{ + int ret = -1; + virAdmConnectPtr conn = NULL; + virAdmServerPtr srv = NULL; /* which server is the client connected to */ + virAdmClientPtr clnt = NULL; /* which client get identity for */ + virTypedParameterPtr params = NULL; /* where to store identity info */ + int nparams = 0; + size_t i = 0; + char *timestr = NULL; + + if (argc != 3) { + fprintf(stderr, "Two arguments, first specifying the server client is " + "connected to and second, specifying the client's ID for which " + "identity information should be retrieved, are expected\n"); + return -1; + } + + /* first, open a connection to the daemon */ + if (!(conn = virAdmConnectOpen(NULL, 0))) + return -1; + + /* first a virAdmServerPtr handle is necessary to obtain, that is done by + * doing a lookup for specific server, argv[1] holds the server name + */ + if (!(srv = virAdmConnectLookupServer(conn, argv[1], 0))) + goto cleanup; + + /* next, virAdmClientPtr handle is necessary to obtain, that is done by + * doing a lookup on a specific server, argv[2] holds the client's ID + */ + if (!(clnt = virAdmServerLookupClient(srv, strtoll(argv[2], NULL, 10), 0))) + goto cleanup; + + /* finally, retrieve @clnt's identity information */ + if (virAdmClientGetInfo(clnt, ¶ms, &nparams, 0) < 0) + goto cleanup; + + /* this information is provided by the client object itself, not by typed + * params container; it is unnecessary to call virAdmClientGetInfo if only + * ID, transport method, and timestamp are the required data + */ + if (!(timestr = exampleGetTimeStr(virAdmClientGetTimestamp(clnt)))) + goto cleanup; + + printf("%-15s: %llu\n", "id", virAdmClientGetID(clnt)); + printf("%-15s: %s\n", "connection_time", timestr); + printf("%-15s: %s\n", "transport", + exampleTransportToString(virAdmClientGetTransport(clnt))); + + /* this is the actual identity information retrieved in typed params + * container + */ + for (i = 0; i < nparams; i++) { + char *str = NULL; + if (!(str = exampleGetTypedParamValue(¶ms[i]))) + goto cleanup; + printf("%-15s: %s\n", params[i].field, str); + free(str); + } + + ret = 0; + cleanup: + /* Once finished, free the typed params container, server and client + * handles and close the connection properly, @conn will be deallocated + * automatically + */ + virTypedParamsFree(params, nparams); + virAdmClientFree(clnt); + virAdmServerFree(srv); + virAdmConnectClose(conn); + free(timestr); + return ret; +} diff --git a/examples/admin/client_limits.c b/examples/admin/client_limits.c new file mode 100644 index 0000000..2d5b754 --- /dev/null +++ b/examples/admin/client_limits.c @@ -0,0 +1,63 @@ +#include<stdio.h> +#include<stdlib.h> +#include<libvirt/libvirt-admin.h> + +int main(int argc, char **argv) +{ + int ret = -1; + virAdmConnectPtr conn = NULL; + virAdmServerPtr srv = NULL; /* which server to work with */ + virTypedParameterPtr params = NULL; + int nparams = 0; + size_t i; + + if (argc != 2) { + fprintf(stderr, "One argument specifying the server which to work " + "with is expected\n"); + return -1; + } + + /* first, open a connection to the daemon */ + if (!(conn = virAdmConnectOpen(NULL, 0))) + goto cleanup; + + /* a server handle is necessary before any API regarding threadpool + * parameters can be issued + */ + if (!(srv = virAdmConnectLookupServer(conn, argv[1], 0))) + goto cleanup; + + /* get the current client limits */ + if (virAdmServerGetClientLimits(srv, ¶ms, &nparams, 0) < 0) + goto cleanup; + + for (i = 0; i < nparams; i++) + printf("%-15s: %d\n", params[i].field, params[i].value.ui); + + virTypedParamsFree(params, nparams); + params = NULL; + nparams = 0; + + /* set nclients_max to 100 and nclients_unauth_max to 20 */ + int maxparams = 0; + if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams, + VIR_SERVER_CLIENTS_MAX, 100) < 0 || + virTypedParamsAddUInt(¶ms, &nparams, &maxparams, + VIR_SERVER_CLIENTS_UNAUTH_MAX, 20) < 0) + goto cleanup; + + /* now, change the client limits on the server */ + if (virAdmServerSetClientLimits(srv, params, nparams, 0) < 0) + goto cleanup; + + ret = 0; + cleanup: + virTypedParamsFree(params, nparams); + + /* Once finished deallocate the server handle and close the connection + * properly, @conn will be deallocated automatically + */ + virAdmServerFree(srv); + virAdmConnectClose(conn); + return ret; +} diff --git a/examples/admin/list_clients.c b/examples/admin/list_clients.c new file mode 100644 index 0000000..3b4496e --- /dev/null +++ b/examples/admin/list_clients.c @@ -0,0 +1,111 @@ +#include<stdio.h> +#include<stdlib.h> +#include<time.h> +#include<libvirt/libvirt-admin.h> + +static const char * +exampleTransportToString(int transport) +{ + const char *str = NULL; + + switch ((virClientTransport) transport) { + case VIR_CLIENT_TRANS_UNIX: + str = "unix"; + break; + case VIR_CLIENT_TRANS_TCP: + str = "tcp"; + break; + case VIR_CLIENT_TRANS_TLS: + str = "tls"; + break; + } + + return str ? str : "unknown"; +} + +static char * +exampleGetTimeStr(time_t then) +{ + char *ret = NULL; + struct tm timeinfo; + + if (!localtime_r(&then, &timeinfo)) + return NULL; + + if (!(ret = calloc(64, sizeof(char)))) + return NULL; + + if (strftime(ret, 64, "%Y-%m-%d %H:%M:%S%z", + &timeinfo) == 0) { + free(ret); + return NULL; + } + + return ret; +} + +int main(int argc, char **argv) +{ + int ret = -1; + virAdmConnectPtr conn = NULL; + virAdmServerPtr srv = NULL; /* which server list the clients from */ + virAdmClientPtr *clients = NULL; /* where to store the servers */ + size_t i = 0; + int count = 0; + + if (argc != 2) { + fprintf(stderr, "One argument specifying the server to list connected " + "clients for is expected\n"); + return -1; + } + + /* first, open a connection to the daemon */ + if (!(conn = virAdmConnectOpen(NULL, 0))) + return -1; + + /* first a virAdmServerPtr handle is necessary to obtain, that is done by + * doing a lookup for specific server, let's get a handle on "libvirtd" + * server + */ + if (!(srv = virAdmConnectLookupServer(conn, argv[1], 0))) + goto cleanup; + + /* now get the currently connected clients to server @srv */ + if ((count = virAdmServerListClients(srv, &clients, 0)) < 0) + goto cleanup; + + /* let's print the currently connected clients and some basic info about + * them, we have 2 options how to interate over the returned list, + * use @count as the boundary or use the fact that @clients are guaranteed + * to contain 1 extra element NULL; + * this example uses the first option + */ + printf(" %-5s %-15s %-15s\n%s\n", "Id", "Transport", "Connected since", + "--------------------------------------------------"); + + for (i = 0; i < count; i++) { + virAdmClientPtr client = clients[i]; + unsigned long long id = virAdmClientGetID(client); + int transport = virAdmClientGetTransport(client); + char * timestr = NULL; + if (!(timestr = + exampleGetTimeStr(virAdmClientGetTimestamp(client)))) + goto cleanup; + + printf(" %-5llu %-15s %-15s\n", id, + exampleTransportToString(transport), timestr); + free(timestr); + } + + ret = 0; + cleanup: + /* Once finished, free the list of clients, free the server handle and + * close the connection properly, @conn will be deallocated automatically + */ + for (i = 0; i < count; i++) + virAdmClientFree(clients[i]); + free(clients); + virAdmServerFree(srv); + virAdmConnectClose(conn); + return ret; +} diff --git a/examples/admin/list_servers.c b/examples/admin/list_servers.c new file mode 100644 index 0000000..1f6f4c6 --- /dev/null +++ b/examples/admin/list_servers.c @@ -0,0 +1,42 @@ +#include<stdio.h> +#include<stdlib.h> +#include<libvirt/libvirt-admin.h> + +int main(void) +{ + int ret = -1; + virAdmConnectPtr conn = NULL; + virAdmServerPtr *servers = NULL; /* where to store the servers */ + virAdmServerPtr *tmp = NULL; + size_t i = 0; + int count = 0; + + /* first, open a connection to the daemon */ + if (!(conn = virAdmConnectOpen(NULL, 0))) + goto cleanup; + + /* get the available servers on the default daemon - libvirtd */ + if ((count = virAdmConnectListServers(conn, &servers, 0)) < 0) + goto cleanup; + + /* let's print the available servers, we have 2 options how to interate + * over the returned list, use @count as the boundary or use the fact + * that @servers are guaranteed to contain 1 extra element NULL; + * this example uses the second option + */ + printf(" %-15s\n", "Server name"); + printf("---------------\n"); + for (tmp = servers; *tmp; tmp++) + printf(" %-15s\n", virAdmServerGetName(*tmp)); + + ret = 0; + cleanup: + /* Once finished, free the list of servers and close the connection + * properly, @conn will be deallocated automatically + */ + for (i = 0; i < count; i++) + virAdmServerFree(servers[i]); + free(servers); + virAdmConnectClose(conn); + return ret; +} diff --git a/examples/admin/threadpool_params.c b/examples/admin/threadpool_params.c new file mode 100644 index 0000000..ee9ce83 --- /dev/null +++ b/examples/admin/threadpool_params.c @@ -0,0 +1,65 @@ +#include<stdio.h> +#include<stdlib.h> +#include<libvirt/libvirt-admin.h> + +int main(int argc, char **argv) +{ + int ret = -1; + virAdmConnectPtr conn = NULL; + virAdmServerPtr srv = NULL; /* which server to work with */ + virTypedParameterPtr params = NULL; + int nparams = 0; + size_t i; + + if (argc != 2) { + fprintf(stderr, "One argument specifying the server which to work " + "with is expected\n"); + return -1; + } + + /* first, open a connection to the daemon */ + if (!(conn = virAdmConnectOpen(NULL, 0))) + goto cleanup; + + /* a server handle is necessary before any API regarding threadpool + * parameters can be issued + */ + if (!(srv = virAdmConnectLookupServer(conn, argv[1], 0))) + goto cleanup; + + /* get the current threadpool parameters */ + if (virAdmServerGetThreadPoolParameters(srv, ¶ms, &nparams, 0) < 0) + goto cleanup; + + for (i = 0; i < nparams; i++) + printf("%-15s: %d\n", params[i].field, params[i].value.ui); + + virTypedParamsFree(params, nparams); + params = NULL; + nparams = 0; + + /* let's set minWorkers to 10, maxWorkers to 15 and prioWorkers to 10 */ + int maxparams = 0; + if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams, + VIR_THREADPOOL_WORKERS_MIN, 10) < 0 || + virTypedParamsAddUInt(¶ms, &nparams, &maxparams, + VIR_THREADPOOL_WORKERS_MAX, 15) < 0 || + virTypedParamsAddUInt(¶ms, &nparams, &maxparams, + VIR_THREADPOOL_WORKERS_PRIORITY, 10) < 0) + goto cleanup; + + /* now, change the threadpool settings to some different values */ + if (virAdmServerSetThreadPoolParameters(srv, params, nparams, 0) < 0) + goto cleanup; + + ret = 0; + cleanup: + virTypedParamsFree(params, nparams); + + /* Once finished deallocate the server handle and close the connection + * properly, @conn will be deallocated automatically + */ + virAdmServerFree(srv); + virAdmConnectClose(conn); + return ret; +} -- 2.5.5

With respect to to the following thread https://www.redhat.com/archives/libvir-list/2016-June/msg01822.html, until we introduce a new rpm package '-libs' that would allow us to drop daemon's dependency on the client package, distribute admin API related stuff within the client package (since it's the best analogy to the virsh client). Signed-off-by: Erik Skultety <eskultet@redhat.com> --- libvirt.spec.in | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libvirt.spec.in b/libvirt.spec.in index 816a950..4a46664 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1189,12 +1189,6 @@ mv $RPM_BUILD_ROOT%{_libdir}/wireshark/plugins/*/libvirt.so \ $RPM_BUILD_ROOT%{_libdir}/wireshark/plugins/libvirt.so %endif -# Temporarily get rid of not-installed admin-related files -rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt-admin.so -rm -f $RPM_BUILD_ROOT%{_bindir}/virt-admin -rm -f $RPM_BUILD_ROOT%{_mandir}/man1/virt-admin.1* -rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/libvirt-admin.conf - install -d -m 0755 $RPM_BUILD_ROOT%{_datadir}/lib/libvirt/dnsmasq/ # We don't want to install /etc/libvirt/qemu/networks in the main %files list # because if the admin wants to delete the default network completely, we don't @@ -1536,6 +1530,7 @@ exit 0 %doc examples/xml %doc examples/rename %doc examples/systemtap +%doc examples/admin %files daemon @@ -1746,11 +1741,14 @@ exit 0 %doc COPYING COPYING.LESSER %config(noreplace) %{_sysconfdir}/libvirt/libvirt.conf +%config(noreplace) %{_sysconfdir}/libvirt/libvirt-admin.conf %{_mandir}/man1/virsh.1* +%{_mandir}/man1/virt-admin.1* %{_mandir}/man1/virt-xml-validate.1* %{_mandir}/man1/virt-pki-validate.1* %{_mandir}/man1/virt-host-validate.1* %{_bindir}/virsh +%{_bindir}/virt-admin %{_bindir}/virt-xml-validate %{_bindir}/virt-pki-validate %{_bindir}/virt-host-validate @@ -1813,11 +1811,13 @@ exit 0 %files devel %{_libdir}/libvirt.so +%{_libdir}/libvirt-admin.so %{_libdir}/libvirt-qemu.so %{_libdir}/libvirt-lxc.so %dir %{_includedir}/libvirt %{_includedir}/libvirt/virterror.h %{_includedir}/libvirt/libvirt.h +%{_includedir}/libvirt/libvirt-admin.h %{_includedir}/libvirt/libvirt-common.h %{_includedir}/libvirt/libvirt-domain.h %{_includedir}/libvirt/libvirt-domain-snapshot.h @@ -1833,11 +1833,13 @@ exit 0 %{_includedir}/libvirt/libvirt-qemu.h %{_includedir}/libvirt/libvirt-lxc.h %{_libdir}/pkgconfig/libvirt.pc +%{_libdir}/pkgconfig/libvirt-admin.pc %{_libdir}/pkgconfig/libvirt-qemu.pc %{_libdir}/pkgconfig/libvirt-lxc.pc %dir %{_datadir}/libvirt/api/ %{_datadir}/libvirt/api/libvirt-api.xml +%{_datadir}/libvirt/api/libvirt-admin-api.xml %{_datadir}/libvirt/api/libvirt-qemu-api.xml %{_datadir}/libvirt/api/libvirt-lxc-api.xml # Needed building python bindings -- 2.5.5

On Fri, Jun 24, 2016 at 08:34:16PM +0200, Erik Skultety wrote:
Finally enable admin API in our code and start distributing it both via a tarball and as part of an rpm package. I also added some usage examples, however the html documentation is missing, because of our current xsl stylesheet, more specifically because of how xsltproc works. It takes a stylesheet and an xml file which it processes and produces index.html for each xml file on its input. This way, we either get TOC for libvirt APIs or just the admin. The same story goes for libvirt-qemu and libvirt-lxc which we neither generate, nor distribute. I talked to Jirka and we thought about merging the xmls somehow to a temporary file and then generate the index.html but that requires some more digging, especially into xslt capabilities. So I haven't figured this one out yet, but once I do, I'll enable it for all of our *.xml API 'recipes'.
Erik Skultety (3): admin: enable both admin API functionality and tarball distribution examples: admin: Add some examples for the new admin APIs spec: distribute admin API within libvirt-client package
.gitignore | 6 ++ Makefile.am | 2 +- cfg.mk | 4 +- daemon/libvirtd.c | 2 +- docs/Makefile.am | 5 +- examples/Makefile.am | 14 +++- examples/admin/client_close.c | 57 +++++++++++++ examples/admin/client_info.c | 165 +++++++++++++++++++++++++++++++++++++ examples/admin/client_limits.c | 63 ++++++++++++++ examples/admin/list_clients.c | 111 +++++++++++++++++++++++++ examples/admin/list_servers.c | 42 ++++++++++ examples/admin/threadpool_params.c | 65 +++++++++++++++ include/libvirt/Makefile.am | 6 +- libvirt.spec.in | 14 ++-- src/libvirt_admin_public.syms | 2 +- 15 files changed, 538 insertions(+), 20 deletions(-) create mode 100644 examples/admin/client_close.c create mode 100644 examples/admin/client_info.c create mode 100644 examples/admin/client_limits.c create mode 100644 examples/admin/list_clients.c create mode 100644 examples/admin/list_servers.c create mode 100644 examples/admin/threadpool_params.c
ACK series Jan

On 25/06/16 11:07, Ján Tomko wrote:
On Fri, Jun 24, 2016 at 08:34:16PM +0200, Erik Skultety wrote:
Finally enable admin API in our code and start distributing it both via a tarball and as part of an rpm package. I also added some usage examples, however the html documentation is missing, because of our current xsl stylesheet, more specifically because of how xsltproc works. It takes a stylesheet and an xml file which it processes and produces index.html for each xml file on its input. This way, we either get TOC for libvirt APIs or just the admin. The same story goes for libvirt-qemu and libvirt-lxc which we neither generate, nor distribute. I talked to Jirka and we thought about merging the xmls somehow to a temporary file and then generate the index.html but that requires some more digging, especially into xslt capabilities. So I haven't figured this one out yet, but once I do, I'll enable it for all of our *.xml API 'recipes'.
Erik Skultety (3): admin: enable both admin API functionality and tarball distribution examples: admin: Add some examples for the new admin APIs spec: distribute admin API within libvirt-client package
.gitignore | 6 ++ Makefile.am | 2 +- cfg.mk | 4 +- daemon/libvirtd.c | 2 +- docs/Makefile.am | 5 +- examples/Makefile.am | 14 +++- examples/admin/client_close.c | 57 +++++++++++++ examples/admin/client_info.c | 165 +++++++++++++++++++++++++++++++++++++ examples/admin/client_limits.c | 63 ++++++++++++++ examples/admin/list_clients.c | 111 +++++++++++++++++++++++++ examples/admin/list_servers.c | 42 ++++++++++ examples/admin/threadpool_params.c | 65 +++++++++++++++ include/libvirt/Makefile.am | 6 +- libvirt.spec.in | 14 ++-- src/libvirt_admin_public.syms | 2 +- 15 files changed, 538 insertions(+), 20 deletions(-) create mode 100644 examples/admin/client_close.c create mode 100644 examples/admin/client_info.c create mode 100644 examples/admin/client_limits.c create mode 100644 examples/admin/list_clients.c create mode 100644 examples/admin/list_servers.c create mode 100644 examples/admin/threadpool_params.c
ACK series
Jan
I pushed the patches, thanks. Erik
participants (2)
-
Erik Skultety
-
Ján Tomko