Skip to content

Commit 55e0c84

Browse files
committed
Add libvirt-admin library
Initial scratch of the admin library. It has its own virAdmConnectPtr that inherits from virAbstractConnectPtr and thus trivially supports error reporting. There's pkg-config file added and spec-file adjusted as well. Since the library should be "minimalistic" and not depend on any other library, the list of files is especially crafted for it. Most of them could've been put to it's own sub-libraries that would be LIBADD'd to libvirt_util, libvirt_net_rpc and libvirt_setuid_rpc_client to minimize the number of object files being built, but that's a refactoring that isn't the orginal aim of this commit. Signed-off-by: Martin Kletzander <[email protected]>
1 parent 653acbf commit 55e0c84

14 files changed

+628
-3
lines changed

Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ EXTRA_DIST = \
4040
libvirt.pc.in \
4141
libvirt-qemu.pc.in \
4242
libvirt-lxc.pc.in \
43+
libvirt-admin.pc.in \
4344
autobuild.sh \
4445
Makefile.nonreentrant \
4546
autogen.sh \
@@ -49,7 +50,7 @@ EXTRA_DIST = \
4950
$(XML_EXAMPLES)
5051

5152
pkgconfigdir = $(libdir)/pkgconfig
52-
pkgconfig_DATA = libvirt.pc libvirt-qemu.pc libvirt-lxc.pc
53+
pkgconfig_DATA = libvirt.pc libvirt-qemu.pc libvirt-lxc.pc libvirt-admin.pc
5354

5455
NEWS: $(top_srcdir)/docs/news.xsl $(top_srcdir)/docs/news.html.in
5556
$(AM_V_GEN)if [ -x $(XSLTPROC) ] ; then \

cfg.mk

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ sc_flags_usage:
304304
$(srcdir)/include/libvirt/virterror.h \
305305
$(srcdir)/include/libvirt/libvirt-qemu.h \
306306
$(srcdir)/include/libvirt/libvirt-lxc.h \
307+
$(srcdir)/include/libvirt/libvirt-admin.h \
307308
| grep -c '\(long\|unsigned\) flags')" != 4 && \
308309
{ echo '$(ME): new API should use "unsigned int flags"' 1>&2; \
309310
exit 1; } || :

configure.ac

+4-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,6 @@ if test "$with_libvirtd" = "yes" ; then
825825
fi
826826
AM_CONDITIONAL([WITH_LIBVIRTD], [test "$with_libvirtd" = "yes"])
827827

828-
829828
old_LIBS="$LIBS"
830829
old_CFLAGS="$CFLAGS"
831830
LIBXENSERVER_LIBS=""
@@ -2353,6 +2352,7 @@ WIN32_EXTRA_CFLAGS=
23532352
dnl libvirt.syms is generated in builddir, but libvirt_qemu.syms is in git;
23542353
dnl hence the asymmetric naming of these two symbol files.
23552354
LIBVIRT_SYMBOL_FILE=libvirt.syms
2355+
LIBVIRT_ADMIN_SYMBOL_FILE='$(srcdir)/libvirt_admin.syms'
23562356
LIBVIRT_LXC_SYMBOL_FILE='$(srcdir)/libvirt_lxc.syms'
23572357
LIBVIRT_QEMU_SYMBOL_FILE='$(srcdir)/libvirt_qemu.syms'
23582358
MSCOM_LIBS=
@@ -2383,6 +2383,7 @@ case "$host" in
23832383
# Also set the symbol file to .def, so src/Makefile generates libvirt.def
23842384
# from libvirt.syms and passes libvirt.def instead of libvirt.syms to the linker
23852385
LIBVIRT_SYMBOL_FILE=libvirt.def
2386+
LIBVIRT_ADMIN_SYMBOL_FILE=libvirt_admin.def
23862387
LIBVIRT_LXC_SYMBOL_FILE=libvirt_lxc.def
23872388
LIBVIRT_QEMU_SYMBOL_FILE=libvirt_qemu.def
23882389
# mingw's ld has the --version-script parameter, but it requires a .def file
@@ -2398,6 +2399,7 @@ AC_SUBST([CYGWIN_EXTRA_LIBADD])
23982399
AC_SUBST([MINGW_EXTRA_LDFLAGS])
23992400
AC_SUBST([WIN32_EXTRA_CFLAGS])
24002401
AC_SUBST([LIBVIRT_SYMBOL_FILE])
2402+
AC_SUBST([LIBVIRT_ADMIN_SYMBOL_FILE])
24012403
AC_SUBST([LIBVIRT_LXC_SYMBOL_FILE])
24022404
AC_SUBST([LIBVIRT_QEMU_SYMBOL_FILE])
24032405
AC_SUBST([VERSION_SCRIPT_FLAGS])
@@ -2788,6 +2790,7 @@ AC_CONFIG_FILES([\
27882790
libvirt.pc \
27892791
libvirt-qemu.pc \
27902792
libvirt-lxc.pc \
2793+
libvirt-admin.pc \
27912794
src/libvirt.pc \
27922795
src/libvirt-qemu.pc \
27932796
src/libvirt-lxc.pc \

include/libvirt/Makefile.am

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Process this file with automake to produce Makefile.in
22

3-
## Copyright (C) 2005-2011, 2013 Red Hat, Inc.
3+
## Copyright (C) 2005-2011, 2013-2015 Red Hat, Inc.
44
##
55
## This library is free software; you can redistribute it and/or
66
## modify it under the terms of the GNU Lesser General Public
@@ -34,6 +34,8 @@ virinc_HEADERS = libvirt.h \
3434
libvirt-qemu.h \
3535
virterror.h
3636

37+
virinc_HEADERS += libvirt-admin.h
38+
3739
install-exec-hook:
3840
$(mkinstalldirs) $(DESTDIR)$(virincdir)
3941

include/libvirt/libvirt-admin.h

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* libvirt-admin.h: Admin interface for libvirt
3+
* Summary: Interfaces for handling server-related tasks
4+
* Description: Provides the interfaces of the libvirt library to operate
5+
* with the server itself, not any hypervisors.
6+
*
7+
* Copyright (C) 2014-2015 Red Hat, Inc.
8+
*
9+
* This library is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with this library. If not, see
21+
* <http://www.gnu.org/licenses/>.
22+
*
23+
* Author: Martin Kletzander <[email protected]>
24+
*/
25+
26+
#ifndef __VIR_ADMIN_H__
27+
# define __VIR_ADMIN_H__
28+
29+
# include "internal.h"
30+
31+
# ifdef __cplusplus
32+
extern "C" {
33+
# endif
34+
35+
36+
/**
37+
* virAdmConnect:
38+
*
39+
* a virAdmConnect is a private structure representing a connection to
40+
* libvirt daemon.
41+
*/
42+
typedef struct _virAdmConnect virAdmConnect;
43+
44+
/**
45+
* virAdmConnectPtr:
46+
*
47+
* a virAdmConnectPtr is pointer to a virAdmConnect private structure,
48+
* this is the type used to reference a connection to the daemon
49+
* in the API.
50+
*/
51+
typedef virAdmConnect *virAdmConnectPtr;
52+
53+
virAdmConnectPtr virAdmConnectOpen(const char *name, unsigned int flags);
54+
int virAdmConnectClose(virAdmConnectPtr conn);
55+
56+
int virAdmConnectRef(virAdmConnectPtr conn);
57+
58+
# ifdef __cplusplus
59+
}
60+
# endif
61+
62+
#endif /* __VIR_ADMIN_H__ */

libvirt-admin.pc.in

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
prefix=@prefix@
2+
exec_prefix=@exec_prefix@
3+
libdir=@libdir@
4+
includedir=@includedir@
5+
datarootdir=@datarootdir@
6+
7+
libvirt_admin_api=@datadir@/libvirt/api/libvirt-admin-api.xml
8+
9+
Name: libvirt-admin
10+
Version: @VERSION@
11+
Description: libvirt admin library
12+
Libs: -L${libdir} -lvirt-admin
13+
Cflags: -I${includedir}

libvirt.spec.in

+20
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,16 @@ Includes the Sanlock lock manager plugin for the QEMU
12161216
driver
12171217
%endif
12181218

1219+
%package admin
1220+
Summary: Client side library and binary for the libvirt admin interface
1221+
Group: Development/Libraries
1222+
Requires: readline
1223+
Requires: %{name}-client = %{version}-%{release}
1224+
1225+
%description admin
1226+
Shared library and client for admin access to libvirt daemon
1227+
1228+
12191229
%prep
12201230
%setup -q
12211231

@@ -2209,6 +2219,12 @@ exit 0
22092219
%attr(0755, root, root) %{_libexecdir}/libvirt_sanlock_helper
22102220
%endif
22112221

2222+
%files admin
2223+
%defattr(-, root, root)
2224+
%{_mandir}/man1/virt-admin.1*
2225+
%{_bindir}/virt-admin
2226+
%{_libdir}/libvirt-admin.so.*
2227+
22122228
%files client -f %{name}.lang
22132229
%defattr(-, root, root)
22142230
%doc COPYING COPYING.LESSER
@@ -2285,6 +2301,7 @@ exit 0
22852301
%{_libdir}/libvirt.so
22862302
%{_libdir}/libvirt-qemu.so
22872303
%{_libdir}/libvirt-lxc.so
2304+
%{_libdir}/libvirt-admin.so
22882305
%dir %{_includedir}/libvirt
22892306
%{_includedir}/libvirt/virterror.h
22902307
%{_includedir}/libvirt/libvirt.h
@@ -2301,15 +2318,18 @@ exit 0
23012318
%{_includedir}/libvirt/libvirt-stream.h
23022319
%{_includedir}/libvirt/libvirt-qemu.h
23032320
%{_includedir}/libvirt/libvirt-lxc.h
2321+
%{_includedir}/libvirt/libvirt-admin.h
23042322
%{_libdir}/pkgconfig/libvirt.pc
23052323
%{_libdir}/pkgconfig/libvirt-qemu.pc
23062324
%{_libdir}/pkgconfig/libvirt-lxc.pc
2325+
%{_libdir}/pkgconfig/libvirt-admin.pc
23072326

23082327
%dir %{_datadir}/libvirt/api/
23092328
%{_datadir}/libvirt/api/libvirt-api.xml
23102329
%{_datadir}/libvirt/api/libvirt-qemu-api.xml
23112330
%{_datadir}/libvirt/api/libvirt-lxc-api.xml
23122331

2332+
23132333
%doc docs/*.html docs/html docs/*.gif
23142334
%doc docs/libvirt-api.xml
23152335
%doc examples/hellolibvirt

po/POTFILES.in

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ src/interface/interface_backend_netcf.c
5959
src/interface/interface_backend_udev.c
6060
src/internal.h
6161
src/libvirt.c
62+
src/libvirt-admin.c
6263
src/libvirt-domain.c
6364
src/libvirt-domain-snapshot.c
6465
src/libvirt-host.c

src/Makefile.am

+50
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ PROTOCOL_STRUCTS = \
503503
$(srcdir)/virkeepaliveprotocol-structs \
504504
$(srcdir)/lxc_monitor_protocol-structs \
505505
$(srcdir)/lock_protocol-structs \
506+
$(srcdir)/admin_protocol-structs \
506507
$(NULL)
507508

508509
if WITH_REMOTE
@@ -524,6 +525,9 @@ $(srcdir)/lxc_monitor_protocol-struct: \
524525
$(srcdir)/lock_protocol-struct: \
525526
$(srcdir)/%-struct: locking/lockd_la-%.lo
526527
$(PDWTAGS)
528+
$(srcdir)/admin_protocol-struct: \
529+
$(srcdir)/%-struct: admin/libvirt_admin_la-%.lo
530+
$(PDWTAGS)
527531

528532
else !WITH_REMOTE
529533
# The $(PROTOCOL_STRUCTS) files must live in git, because they cannot be
@@ -536,6 +540,7 @@ check-drivername:
536540
$(AM_V_GEN)$(PERL) $(srcdir)/check-drivername.pl \
537541
$(srcdir)/driver.h \
538542
$(srcdir)/libvirt_public.syms \
543+
$(srcdir)/libvirt_admin.syms \
539544
$(srcdir)/libvirt_qemu.syms \
540545
$(srcdir)/libvirt_lxc.syms
541546

@@ -1094,6 +1099,7 @@ USED_SYM_FILES = $(srcdir)/libvirt_private.syms
10941099
GENERATED_SYM_FILES = \
10951100
$(ACCESS_DRIVER_SYM_FILES) \
10961101
libvirt.syms libvirt.def libvirt_qemu.def libvirt_lxc.def \
1102+
libvirt_admin.def \
10971103
$(NULL)
10981104

10991105
if WITH_TEST
@@ -2003,6 +2009,7 @@ EXTRA_DIST += \
20032009
libvirt_public.syms \
20042010
libvirt_lxc.syms \
20052011
libvirt_qemu.syms \
2012+
libvirt_admin.syms \
20062013
$(SYM_FILES) \
20072014
$(NULL)
20082015

@@ -2030,6 +2037,49 @@ libvirt.syms: libvirt_public.syms $(USED_SYM_FILES) \
20302037
chmod a-w $@-tmp && \
20312038
mv $@-tmp $@
20322039

2040+
lib_LTLIBRARIES += libvirt-admin.la
2041+
libvirt_admin_la_SOURCES = \
2042+
libvirt-admin.c \
2043+
$(ADMIN_PROTOCOL_GENERATED) \
2044+
$(DATATYPES_SOURCES)
2045+
2046+
libvirt_admin_la_LDFLAGS = \
2047+
$(VERSION_SCRIPT_FLAGS)$(LIBVIRT_ADMIN_SYMBOL_FILE) \
2048+
-version-info $(LIBVIRT_VERSION_INFO) \
2049+
$(AM_LDFLAGS) \
2050+
$(CYGWIN_EXTRA_LDFLAGS) \
2051+
$(MINGW_EXTRA_LDFLAGS)
2052+
2053+
libvirt_admin_la_LIBADD = \
2054+
libvirt.la \
2055+
$(CYGWIN_EXTRA_LIBADD)
2056+
2057+
libvirt_admin_la_CFLAGS = \
2058+
$(AM_CFLAGS) \
2059+
-I$(srcdir)/remote \
2060+
-I$(srcdir)/rpc \
2061+
-I$(srcdir)/admin
2062+
2063+
libvirt_admin_la_CFLAGS += \
2064+
$(CAPNG_CFLAGS) \
2065+
$(YAJL_CFLAGS) \
2066+
$(SSH2_CFLAGS) \
2067+
$(SASL_CFLAGS) \
2068+
$(GNUTLS_CFLAGS)
2069+
2070+
libvirt_admin_la_LIBADD += \
2071+
$(CAPNG_LIBS) \
2072+
$(YAJL_LIBS) \
2073+
$(DEVMAPPER_LIBS) \
2074+
$(LIBXML_LIBS) \
2075+
$(SSH2_LIBS) \
2076+
$(SASL_LIBS) \
2077+
$(GNUTLS_LIBS)
2078+
2079+
if WITH_DTRACE_PROBES
2080+
libvirt_admin_la_LIBADD += libvirt_probes.lo
2081+
endif WITH_DTRACE_PROBES
2082+
20332083
# Empty source list - it merely links a bunch of convenience libs together
20342084
libvirt_la_SOURCES =
20352085
libvirt_la_LDFLAGS = \

src/datatypes.c

+30
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ static void virStreamDispose(void *obj);
5959
static void virStorageVolDispose(void *obj);
6060
static void virStoragePoolDispose(void *obj);
6161

62+
virClassPtr virAdmConnectClass;
63+
64+
static void virAdmConnectDispose(void *obj);
65+
6266
static int
6367
virDataTypesOnceInit(void)
6468
{
@@ -86,6 +90,8 @@ virDataTypesOnceInit(void)
8690
DECLARE_CLASS(virStorageVol);
8791
DECLARE_CLASS(virStoragePool);
8892

93+
DECLARE_CLASS_LOCKABLE(virAdmConnect);
94+
8995
#undef DECLARE_CLASS_COMMON
9096
#undef DECLARE_CLASS_LOCKABLE
9197
#undef DECLARE_CLASS
@@ -803,3 +809,27 @@ virDomainSnapshotDispose(void *obj)
803809
VIR_FREE(snapshot->name);
804810
virObjectUnref(snapshot->domain);
805811
}
812+
813+
814+
virAdmConnectPtr
815+
virAdmConnectNew(void)
816+
{
817+
virAdmConnectPtr ret;
818+
819+
if (virDataTypesInitialize() < 0)
820+
return NULL;
821+
822+
if (!(ret = virObjectLockableNew(virAdmConnectClass)))
823+
return NULL;
824+
825+
return ret;
826+
}
827+
828+
static void
829+
virAdmConnectDispose(void *obj)
830+
{
831+
virAdmConnectPtr conn = obj;
832+
833+
if (conn->privateDataFreeFunc)
834+
conn->privateDataFreeFunc(conn);
835+
}

0 commit comments

Comments
 (0)