Import stripped down virtlockd code as basis of virtlogd

Copy the virtlockd codebase across to form the initial virlogd
code. Simple search & replace of s/lock/log/ and gut the remote
protocol & dispatcher. This gives us a daemon that starts up
and listens for connections, but does nothing with them.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2015-02-09 16:35:05 +00:00
parent 910e65d973
commit 323a329b26
22 changed files with 2145 additions and 22 deletions

7
.gitignore vendored
View File

@ -137,6 +137,8 @@
/src/locking/qemu-lockd.conf
/src/locking/qemu-sanlock.conf
/src/locking/test_libvirt_sanlock.aug
/src/logging/log_daemon_dispatch_stubs.h
/src/logging/log_protocol.[ch]
/src/lxc/lxc_controller_dispatch.h
/src/lxc/lxc_monitor_dispatch.h
/src/lxc/lxc_monitor_protocol.c
@ -150,12 +152,17 @@
/src/rpc/virnetprotocol.[ch]
/src/test_libvirt*.aug
/src/test_virtlockd.aug
/src/test_virtlogd.aug
/src/util/virkeymaps.h
/src/virt-aa-helper
/src/virtlockd
/src/virtlockd.8
/src/virtlockd.8.in
/src/virtlockd.init
/src/virtlogd
/src/virtlogd.8
/src/virtlogd.8.in
/src/virtlogd.init
/tests/*.log
/tests/*.pid
/tests/*.trs

4
cfg.mk
View File

@ -1121,7 +1121,7 @@ $(srcdir)/src/admin/admin_client.h: $(srcdir)/src/admin/admin_protocol.x
# List all syntax-check exemptions:
exclude_file_name_regexp--sc_avoid_strcase = ^tools/vsh\.h$$
_src1=libvirt-stream|fdstream|qemu/qemu_monitor|util/(vircommand|virfile)|xen/xend_internal|rpc/virnetsocket|lxc/lxc_controller|locking/lock_daemon
_src1=libvirt-stream|fdstream|qemu/qemu_monitor|util/(vircommand|virfile)|xen/xend_internal|rpc/virnetsocket|lxc/lxc_controller|locking/lock_daemon|logging/log_daemon
_test1=shunloadtest|virnettlscontexttest|virnettlssessiontest|vircgroupmock
exclude_file_name_regexp--sc_avoid_write = \
^(src/($(_src1))|daemon/libvirtd|tools/virsh-console|tests/($(_test1)))\.c$$
@ -1156,7 +1156,7 @@ exclude_file_name_regexp--sc_prohibit_close = \
exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = \
(^tests/(qemuhelp|nodeinfo|virpcitest)data/|\.diff$$)
_src2=src/(util/vircommand|libvirt|lxc/lxc_controller|locking/lock_daemon)
_src2=src/(util/vircommand|libvirt|lxc/lxc_controller|locking/lock_daemon|logging/log_daemon)
exclude_file_name_regexp--sc_prohibit_fork_wrappers = \
(^($(_src2)|tests/testutils|daemon/libvirtd)\.c$$)

View File

@ -127,6 +127,7 @@ typedef enum {
VIR_FROM_POLKIT = 60, /* Error from polkit code */
VIR_FROM_THREAD = 61, /* Error from thread utils */
VIR_FROM_ADMIN = 62, /* Error from admin backend */
VIR_FROM_LOGGING = 63, /* Error from log manager */
# ifdef VIR_ENUM_SENTINELS
VIR_ERR_DOMAIN_LAST

View File

@ -1690,12 +1690,13 @@ exit 0
%if %{with_systemd}
%if %{with_systemd_macros}
%systemd_post virtlockd.socket libvirtd.service libvirtd.socket
%systemd_post virtlockd.socket virtlogd.socket libvirtd.service libvirtd.socket
%else
if [ $1 -eq 1 ] ; then
# Initial installation
/bin/systemctl enable \
virtlockd.socket \
virtlogd.socket \
libvirtd.service >/dev/null 2>&1 || :
fi
%endif
@ -1711,24 +1712,29 @@ fi
%endif
/sbin/chkconfig --add libvirtd
/sbin/chkconfig --add virtlogd
/sbin/chkconfig --add virtlockd
%endif
%preun daemon
%if %{with_systemd}
%if %{with_systemd_macros}
%systemd_preun libvirtd.socket libvirtd.service virtlockd.socket virtlockd.service
%systemd_preun libvirtd.socket libvirtd.service virtlogd.socket virtlogd.service virtlockd.socket virtlockd.service
%else
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
/bin/systemctl --no-reload disable \
libvirtd.socket \
libvirtd.service \
virtlogd.socket \
virtlogd.service \
virtlockd.socket \
virtlockd.service > /dev/null 2>&1 || :
/bin/systemctl stop \
libvirtd.socket \
libvirtd.service \
virtlogd.socket \
virtlogd.service \
virtlockd.socket \
virtlockd.service > /dev/null 2>&1 || :
fi
@ -1737,6 +1743,8 @@ fi
if [ $1 = 0 ]; then
/sbin/service libvirtd stop 1>/dev/null 2>&1
/sbin/chkconfig --del libvirtd
/sbin/service virtlogd stop 1>/dev/null 2>&1
/sbin/chkconfig --del virtlogd
/sbin/service virtlockd stop 1>/dev/null 2>&1
/sbin/chkconfig --del virtlockd
fi
@ -1747,11 +1755,13 @@ fi
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
if [ $1 -ge 1 ] ; then
/bin/systemctl reload-or-try-restart virtlockd.service >/dev/null 2>&1 || :
/bin/systemctl reload-or-try-restart virtlogd.service >/dev/null 2>&1 || :
/bin/systemctl try-restart libvirtd.service >/dev/null 2>&1 || :
fi
%else
if [ $1 -ge 1 ]; then
/sbin/service virtlockd reload > /dev/null 2>&1 || :
/sbin/service virtlogd reload > /dev/null 2>&1 || :
/sbin/service libvirtd condrestart > /dev/null 2>&1
fi
%endif
@ -1761,6 +1771,7 @@ fi
%triggerpostun daemon -- libvirt-daemon < 1.2.1
if [ "$1" -ge "1" ]; then
/sbin/service virtlockd reload > /dev/null 2>&1 || :
/sbin/service virtlogd reload > /dev/null 2>&1 || :
/sbin/service libvirtd condrestart > /dev/null 2>&1
fi
%endif
@ -1917,16 +1928,21 @@ exit 0
%if %{with_systemd}
%{_unitdir}/libvirtd.service
%{_unitdir}/libvirtd.socket
%{_unitdir}/virtlogd.service
%{_unitdir}/virtlogd.socket
%{_unitdir}/virtlockd.service
%{_unitdir}/virtlockd.socket
%else
%{_sysconfdir}/rc.d/init.d/libvirtd
%{_sysconfdir}/rc.d/init.d/virtlogd
%{_sysconfdir}/rc.d/init.d/virtlockd
%endif
%doc daemon/libvirtd.upstart
%config(noreplace) %{_sysconfdir}/sysconfig/libvirtd
%config(noreplace) %{_sysconfdir}/sysconfig/virtlogd
%config(noreplace) %{_sysconfdir}/sysconfig/virtlockd
%config(noreplace) %{_sysconfdir}/libvirt/libvirtd.conf
%config(noreplace) %{_sysconfdir}/libvirt/virtlogd.conf
%config(noreplace) %{_sysconfdir}/libvirt/virtlockd.conf
%if 0%{?fedora} || 0%{?rhel} >= 6
%config(noreplace) %{_prefix}/lib/sysctl.d/60-libvirtd.conf
@ -1948,6 +1964,8 @@ exit 0
%{_datadir}/augeas/lenses/libvirtd.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd.aug
%{_datadir}/augeas/lenses/virtlogd.aug
%{_datadir}/augeas/lenses/tests/test_virtlogd.aug
%{_datadir}/augeas/lenses/virtlockd.aug
%{_datadir}/augeas/lenses/tests/test_virtlockd.aug
%{_datadir}/augeas/lenses/libvirt_lockd.aug
@ -1974,9 +1992,11 @@ exit 0
%endif
%attr(0755, root, root) %{_sbindir}/libvirtd
%attr(0755, root, root) %{_sbindir}/virtlogd
%attr(0755, root, root) %{_sbindir}/virtlockd
%{_mandir}/man8/libvirtd.8*
%{_mandir}/man8/virtlogd.8*
%{_mandir}/man8/virtlockd.8*
%if ! %{with_driver_modules}

View File

@ -78,6 +78,8 @@ src/locking/lock_driver_lockd.c
src/locking/lock_driver_sanlock.c
src/locking/lock_manager.c
src/locking/sanlock_helper.c
src/logging/log_daemon.c
src/logging/log_daemon_config.c
src/lxc/lxc_cgroup.c
src/lxc/lxc_fuse.c
src/lxc/lxc_hostdev.c

View File

@ -263,6 +263,41 @@ locking/lock_daemon_dispatch_stubs.h: $(LOCK_PROTOCOL) \
$(LOCK_PROTOCOL) > $(srcdir)/locking/lock_daemon_dispatch_stubs.h
LOG_PROTOCOL_GENERATED = \
logging/log_protocol.h \
logging/log_protocol.c \
$(NULL)
LOG_PROTOCOL = $(srcdir)/logging/log_protocol.x
EXTRA_DIST += $(LOG_PROTOCOL) \
$(LOG_PROTOCOL_GENERATED)
BUILT_SOURCES += $(LOG_PROTOCOL_GENERATED)
MAINTAINERCLEANFILES += $(LOG_PROTOCOL_GENERATED)
LOG_DAEMON_GENERATED = \
logging/log_daemon_dispatch_stubs.h
$(NULL)
BUILT_SOURCES += $(LOG_DAEMON_GENERATED)
EXTRA_DIST += $(LOG_DAEMON_GENERATED)
MAINTAINERCLEANFILES += $(LOG_DAEMON_GENERATED)
LOG_DAEMON_SOURCES = \
logging/log_daemon.h \
logging/log_daemon.c \
logging/log_daemon_config.h \
logging/log_daemon_config.c \
logging/log_daemon_dispatch.c \
logging/log_daemon_dispatch.h \
$(NULL)
logging/log_daemon_dispatch_stubs.h: $(LOG_PROTOCOL) \
$(srcdir)/rpc/gendispatch.pl Makefile.am
$(AM_V_GEN)perl -w $(srcdir)/rpc/gendispatch.pl --mode=server \
virLogManagerProtocol VIR_LOG_MANAGER_PROTOCOL \
$(LOG_PROTOCOL) > $(srcdir)/logging/log_daemon_dispatch_stubs.h
NETDEV_CONF_SOURCES = \
conf/netdev_bandwidth_conf.h conf/netdev_bandwidth_conf.c \
conf/netdev_vport_profile_conf.h conf/netdev_vport_profile_conf.c \
@ -1838,7 +1873,8 @@ check-local: check-augeas
$(NULL)
check-augeas: check-augeas-qemu check-augeas-lxc check-augeas-sanlock \
check-augeas-lockd check-augeas-virtlockd check-augeas-libxl
check-augeas-lockd check-augeas-virtlockd check-augeas-libxl \
check-augeas-virtlogd
AUG_GENTEST = $(PERL) $(top_srcdir)/build-aux/augeas-gentest.pl
EXTRA_DIST += $(top_srcdir)/build-aux/augeas-gentest.pl
@ -1921,6 +1957,15 @@ else ! WITH_LIBXL
check-augeas-libxl:
endif ! WITH_LIBXL
test_virtlogd.aug: logging/test_virtlogd.aug.in \
logging/virtlogd.conf $(AUG_GENTEST)
$(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/logging/virtlogd.conf $< $@
check-augeas-virtlogd: test_virtlogd.aug
$(AM_V_GEN)if test -x '$(AUGPARSE)'; then \
'$(AUGPARSE)' -I $(srcdir)/logging test_virtlogd.aug; \
fi
#
# Build our version script. This is composed of three parts:
#
@ -2345,7 +2390,7 @@ locking/%-lockd.conf: $(srcdir)/locking/lockd.conf
cp $< $@
sbin_PROGRAMS = virtlockd
sbin_PROGRAMS = virtlockd virtlogd
virtlockd_SOURCES = \
$(LOCK_DAEMON_SOURCES) \
@ -2374,40 +2419,79 @@ if WITH_DTRACE_PROBES
virtlockd_LDADD += libvirt_probes.lo
endif WITH_DTRACE_PROBES
virtlogd_SOURCES = \
$(LOG_DAEMON_SOURCES) \
$(LOG_PROTOCOL_GENERATED) \
$(LOG_DAEMON_GENERATED) \
$(NULL)
virtlogd_CFLAGS = \
$(AM_CFLAGS) \
$(PIE_CFLAGS) \
$(XDR_CFLAGS) \
$(NULL)
virtlogd_LDFLAGS = \
$(AM_LDFLAGS) \
$(PIE_LDFLAGS) \
$(CYGWIN_EXTRA_LDFLAGS) \
$(MINGW_EXTRA_LDFLAGS) \
$(NULL)
virtlogd_LDADD = \
libvirt-net-rpc-server.la \
libvirt-net-rpc.la \
libvirt_util.la \
../gnulib/lib/libgnu.la \
$(CYGWIN_EXTRA_LIBADD) \
$(NULL)
if WITH_DTRACE_PROBES
virtlogd_LDADD += libvirt_probes.lo
endif WITH_DTRACE_PROBES
else ! WITH_LIBVIRTD
EXTRA_DIST += $(LOCK_DAEMON_SOURCES) \
$(LOCK_DRIVER_LOCKD_SOURCES)
$(LOCK_DRIVER_LOCKD_SOURCES) \
$(LOG_DAEMON_SOURCES)
endif ! WITH_LIBVIRTD
EXTRA_DIST += locking/virtlockd.sysconf \
EXTRA_DIST += \
locking/virtlockd.sysconf \
locking/lockd.conf \
locking/libvirt_lockd.aug \
locking/test_libvirt_lockd.aug.in
locking/test_libvirt_lockd.aug.in \
logging/virtlogd.sysconf \
logging/libvirt_logd.aug \
logging/test_libvirt_logd.aug.in
install-sysconfig:
$(MKDIR_P) $(DESTDIR)$(sysconfdir)/sysconfig
$(INSTALL_DATA) $(srcdir)/locking/virtlockd.sysconf \
$(DESTDIR)$(sysconfdir)/sysconfig/virtlockd
$(INSTALL_DATA) $(srcdir)/logging/virtlogd.sysconf \
$(DESTDIR)$(sysconfdir)/sysconfig/virtlogd
uninstall-sysconfig:
rm -f $(DESTDIR)$(sysconfdir)/sysconfig/virtlogd
rm -f $(DESTDIR)$(sysconfdir)/sysconfig/virtlockd
rmdir $(DESTDIR)$(sysconfdir)/sysconfig || :
EXTRA_DIST += locking/virtlockd.init.in
EXTRA_DIST += locking/virtlockd.init.in logging/virtlogd.init.in
if WITH_LIBVIRTD
if LIBVIRT_INIT_SCRIPT_RED_HAT
install-init:: virtlockd.init install-sysconfig
install-init:: virtlockd.init virtlogd.init install-sysconfig
$(MKDIR_P) $(DESTDIR)$(sysconfdir)/rc.d/init.d
$(INSTALL_SCRIPT) virtlockd.init \
$(DESTDIR)$(sysconfdir)/rc.d/init.d/virtlockd
$(INSTALL_SCRIPT) virtlogd.init \
$(DESTDIR)$(sysconfdir)/rc.d/init.d/virtlogd
uninstall-init:: uninstall-sysconfig
rm -f $(DESTDIR)$(sysconfdir)/rc.d/init.d/virtlockd
rm -f $(DESTDIR)$(sysconfdir)/rc.d/init.d/virtlogd
rmdir $(DESTDIR)$(sysconfdir)/rc.d/init.d || :
BUILT_SOURCES += virtlockd.init
DISTCLEANFILES += virtlockd.init
BUILT_SOURCES += virtlockd.init virtlogd.init
DISTCLEANFILES += virtlockd.init virtlogd.init
else ! LIBVIRT_INIT_SCRIPT_RED_HAT
install-init::
uninstall-init::
@ -2426,6 +2510,15 @@ virtlockd.init: locking/virtlockd.init.in $(top_builddir)/config.status
chmod a+x $@-t && \
mv $@-t $@
virtlogd.init: logging/virtlogd.init.in $(top_builddir)/config.status
$(AM_V_GEN)sed \
-e 's|[@]localstatedir[@]|$(localstatedir)|g' \
-e 's|[@]sbindir[@]|$(sbindir)|g' \
-e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
< $< > $@-t && \
chmod a+x $@-t && \
mv $@-t $@
POD2MAN = pod2man -c "Virtualization Support" \
-r "$(PACKAGE)-$(VERSION)" -s 8
@ -2440,17 +2533,29 @@ virtlockd.8: $(srcdir)/virtlockd.8.in
< $< > $@-t && \
mv $@-t $@
$(srcdir)/virtlogd.8.in: logging/virtlogd.pod.in $(top_srcdir)/configure.ac
$(AM_V_GEN)$(POD2MAN) --name VIRTLOGD $< $@ \
&& if grep 'POD ERROR' $@ ; then rm $@; exit 1; fi
virtlogd.8: $(srcdir)/virtlogd.8.in
$(AM_V_GEN)sed \
-e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
-e 's|[@]localstatedir[@]|$(localstatedir)|g' \
< $< > $@-t && \
mv $@-t $@
if WITH_LIBVIRTD
man8_MANS = virtlockd.8
man8_MANS = virtlockd.8 virtlogd.8
conf_DATA += locking/virtlockd.conf
conf_DATA += locking/virtlockd.conf logging/virtlogd.conf
augeas_DATA += locking/virtlockd.aug
augeastest_DATA += test_virtlockd.aug
augeas_DATA += locking/virtlockd.aug logging/virtlogd.aug
augeastest_DATA += test_virtlockd.aug test_virtlogd.aug
endif WITH_LIBVIRTD
CLEANFILES += test_virtlockd.aug virtlockd.8
MAINTAINERCLEANFILES += $(srcdir)/virtlockd.8.in
CLEANFILES += test_virtlockd.aug virtlockd.8 \
test_virtlogd.aug virtlogd.8
MAINTAINERCLEANFILES += $(srcdir)/virtlockd.8.in $(srcdir)/virtlogd.8.in
EXTRA_DIST += \
locking/virtlockd.service.in \
@ -2460,6 +2565,13 @@ EXTRA_DIST += \
locking/virtlockd.aug \
locking/virtlockd.conf \
locking/test_virtlockd.aug.in \
logging/virtlogd.service.in \
logging/virtlogd.socket.in \
logging/virtlogd.pod.in \
virtlogd.8.in \
logging/virtlogd.aug \
logging/virtlogd.conf \
logging/test_virtlogd.aug.in \
$(NULL)
@ -2468,19 +2580,28 @@ if LIBVIRT_INIT_SCRIPT_SYSTEMD
SYSTEMD_UNIT_DIR = $(prefix)/lib/systemd/system
BUILT_SOURCES += virtlockd.service virtlockd.socket
DISTCLEANFILES += virtlockd.service virtlockd.socket
BUILT_SOURCES += virtlockd.service virtlockd.socket \
virtlogd.service virtlogd.socket
DISTCLEANFILES += virtlockd.service virtlockd.socket \
virtlogd.service virtlogd.socket
install-systemd: virtlockd.service virtlockd.socket install-sysconfig
install-systemd: virtlockd.service virtlockd.socket \
virtlogd.service virtlogd.socket install-sysconfig
$(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNIT_DIR)
$(INSTALL_DATA) virtlockd.service \
$(DESTDIR)$(SYSTEMD_UNIT_DIR)/
$(INSTALL_DATA) virtlockd.socket \
$(DESTDIR)$(SYSTEMD_UNIT_DIR)/
$(INSTALL_DATA) virtlogd.service \
$(DESTDIR)$(SYSTEMD_UNIT_DIR)/
$(INSTALL_DATA) virtlogd.socket \
$(DESTDIR)$(SYSTEMD_UNIT_DIR)/
uninstall-systemd: uninstall-sysconfig
rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/virtlockd.service \
$(DESTDIR)$(SYSTEMD_UNIT_DIR)/virtlockd.socket
rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/virtlogd.service \
$(DESTDIR)$(SYSTEMD_UNIT_DIR)/virtlogd.socket
rmdir $(DESTDIR)$(SYSTEMD_UNIT_DIR) || :
else ! LIBVIRT_INIT_SCRIPT_SYSTEMD
install-systemd:
@ -2503,6 +2624,18 @@ virtlockd.socket: locking/virtlockd.socket.in $(top_builddir)/config.status
< $< > $@-t && \
mv $@-t $@
virtlogd.service: logging/virtlogd.service.in $(top_builddir)/config.status
$(AM_V_GEN)sed \
-e 's|[@]sbindir[@]|$(sbindir)|g' \
< $< > $@-t && \
mv $@-t $@
virtlogd.socket: logging/virtlogd.socket.in $(top_builddir)/config.status
$(AM_V_GEN)sed \
-e 's|[@]localstatedir[@]|$(localstatedir)|g' \
< $< > $@-t && \
mv $@-t $@
if WITH_SANLOCK
lockdriver_LTLIBRARIES += sanlock.la

1172
src/logging/log_daemon.c Normal file

File diff suppressed because it is too large Load Diff

42
src/logging/log_daemon.h Normal file
View File

@ -0,0 +1,42 @@
/*
* log_daemon.h: log management daemon
*
* Copyright (C) 2006-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: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef __VIR_LOG_DAEMON_H__
# define __VIR_LOG_DAEMON_H__
# include "virthread.h"
typedef struct _virLogDaemon virLogDaemon;
typedef virLogDaemon *virLogDaemonPtr;
typedef struct _virLogDaemonClient virLogDaemonClient;
typedef virLogDaemonClient *virLogDaemonClientPtr;
struct _virLogDaemonClient {
virMutex lock;
pid_t clientPid;
};
extern virLogDaemonPtr logDaemon;
#endif /* __VIR_LOG_DAEMON_H__ */

View File

@ -0,0 +1,202 @@
/*
* log_daemon_config.c: virtlogd config file handling
*
* Copyright (C) 2006-2015 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* 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: Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
#include "log_daemon_config.h"
#include "virconf.h"
#include "viralloc.h"
#include "virerror.h"
#include "virlog.h"
#include "rpc/virnetserver.h"
#include "configmake.h"
#include "virstring.h"
#include "virutil.h"
#define VIR_FROM_THIS VIR_FROM_CONF
VIR_LOG_INIT("logging.log_daemon_config");
/* A helper function used by each of the following macros. */
static int
checkType(virConfValuePtr p, const char *filename,
const char *key, virConfType required_type)
{
if (p->type != required_type) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("remoteReadConfigFile: %s: %s: invalid type:"
" got %s; expected %s"), filename, key,
virConfTypeToString(p->type),
virConfTypeToString(required_type));
return -1;
}
return 0;
}
/* If there is no config data for the key, #var_name, then do nothing.
If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds,
store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP
failure), give a diagnostic and "goto" the cleanup-and-fail label. */
#define GET_CONF_STR(conf, filename, var_name) \
do { \
virConfValuePtr p = virConfGetValue(conf, #var_name); \
if (p) { \
if (checkType(p, filename, #var_name, VIR_CONF_STRING) < 0) \
goto error; \
VIR_FREE(data->var_name); \
if (VIR_STRDUP(data->var_name, p->str) < 0) \
goto error; \
} \
} while (0)
/* Like GET_CONF_STR, but for signed integer values. */
#define GET_CONF_INT(conf, filename, var_name) \
do { \
virConfValuePtr p = virConfGetValue(conf, #var_name); \
if (p) { \
if (p->type != VIR_CONF_ULONG && \
checkType(p, filename, #var_name, VIR_CONF_LONG) < 0) \
goto error; \
data->var_name = p->l; \
} \
} while (0)
/* Like GET_CONF_STR, but for unsigned integer values. */
#define GET_CONF_UINT(conf, filename, var_name) \
do { \
virConfValuePtr p = virConfGetValue(conf, #var_name); \
if (p) { \
if (checkType(p, filename, #var_name, VIR_CONF_ULONG) < 0) \
goto error; \
data->var_name = p->l; \
} \
} while (0)
int
virLogDaemonConfigFilePath(bool privileged, char **configfile)
{
if (privileged) {
if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/virtlogd.conf") < 0)
goto error;
} else {
char *configdir = NULL;
if (!(configdir = virGetUserConfigDirectory()))
goto error;
if (virAsprintf(configfile, "%s/virtlogd.conf", configdir) < 0) {
VIR_FREE(configdir);
goto error;
}
VIR_FREE(configdir);
}
return 0;
error:
return -1;
}
virLogDaemonConfigPtr
virLogDaemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
{
virLogDaemonConfigPtr data;
if (VIR_ALLOC(data) < 0)
return NULL;
data->max_clients = 1024;
return data;
}
void
virLogDaemonConfigFree(virLogDaemonConfigPtr data)
{
if (!data)
return;
VIR_FREE(data->log_filters);
VIR_FREE(data->log_outputs);
VIR_FREE(data);
}
static int
virLogDaemonConfigLoadOptions(virLogDaemonConfigPtr data,
const char *filename,
virConfPtr conf)
{
GET_CONF_UINT(conf, filename, log_level);
GET_CONF_STR(conf, filename, log_filters);
GET_CONF_STR(conf, filename, log_outputs);
GET_CONF_UINT(conf, filename, max_clients);
return 0;
error:
return -1;
}
/* Read the config file if it exists.
*/
int
virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data,
const char *filename,
bool allow_missing)
{
virConfPtr conf;
int ret;
if (allow_missing &&
access(filename, R_OK) == -1 &&
errno == ENOENT)
return 0;
conf = virConfReadFile(filename, 0);
if (!conf)
return -1;
ret = virLogDaemonConfigLoadOptions(data, filename, conf);
virConfFree(conf);
return ret;
}
int virLogDaemonConfigLoadData(virLogDaemonConfigPtr data,
const char *filename,
const char *filedata)
{
virConfPtr conf;
int ret;
conf = virConfReadMem(filedata, strlen(filedata), 0);
if (!conf)
return -1;
ret = virLogDaemonConfigLoadOptions(data, filename, conf);
virConfFree(conf);
return ret;
}

View File

@ -0,0 +1,50 @@
/*
* log_daemon_config.h: virtlogd config file handling
*
* Copyright (C) 2006-2015 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* 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: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef __VIR_LOG_DAEMON_CONFIG_H__
# define __VIR_LOG_DAEMON_CONFIG_H__
# include "internal.h"
typedef struct _virLogDaemonConfig virLogDaemonConfig;
typedef virLogDaemonConfig *virLogDaemonConfigPtr;
struct _virLogDaemonConfig {
int log_level;
char *log_filters;
char *log_outputs;
int max_clients;
};
int virLogDaemonConfigFilePath(bool privileged, char **configfile);
virLogDaemonConfigPtr virLogDaemonConfigNew(bool privileged);
void virLogDaemonConfigFree(virLogDaemonConfigPtr data);
int virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data,
const char *filename,
bool allow_missing);
int virLogDaemonConfigLoadData(virLogDaemonConfigPtr data,
const char *filename,
const char *filedata);
#endif /* __LIBVIRTD_CONFIG_H__ */

View File

@ -0,0 +1,37 @@
/*
* log_daemon_dispatch.c: log management daemon dispatch
*
* Copyright (C) 2006-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: Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
#include "rpc/virnetserver.h"
#include "rpc/virnetserverclient.h"
#include "virlog.h"
#include "virstring.h"
#include "log_daemon.h"
#include "log_protocol.h"
#include "virerror.h"
#define VIR_FROM_THIS VIR_FROM_RPC
VIR_LOG_INIT("logging.log_daemon_dispatch");
#include "log_daemon_dispatch_stubs.h"

View File

@ -0,0 +1,31 @@
/*
* log_daemon_dispatch.h: log management daemon dispatch
*
* Copyright (C) 2006-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: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef __VIR_LOG_DAEMON_DISPATCH_H__
# define __VIR_LOG_DAEMON_DISPATCH_H__
# include "rpc/virnetserverprogram.h"
extern virNetServerProgramProc virLogManagerProtocolProcs[];
extern size_t virLogManagerProtocolNProcs;
#endif /* __VIR_LOG_DAEMON_DISPATCH_H__ */

View File

@ -0,0 +1,22 @@
/* -*- c -*-
*/
%#include "internal.h"
typedef opaque virLogManagerProtocolUUID[VIR_UUID_BUFLEN];
/* Length of long, but not unbounded, strings.
* This is an arbitrary limit designed to stop the decoder from trying
* to allocate unbounded amounts of memory when fed with a bad message.
*/
const VIR_LOG_MANAGER_PROTOCOL_STRING_MAX = 4194304;
/* A long string, which may NOT be NULL. */
typedef string virLogManagerProtocolNonNullString<VIR_LOG_MANAGER_PROTOCOL_STRING_MAX>;
/* A long string, which may be NULL. */
typedef virLogManagerProtocolNonNullString *virLogManagerProtocolString;
/* Define the program number, protocol version and procedure numbers here. */
const VIR_LOG_MANAGER_PROTOCOL_PROGRAM = 0x87539319;
const VIR_LOG_MANAGER_PROTOCOL_PROGRAM_VERSION = 1;

View File

@ -0,0 +1,10 @@
module Test_virtlogd =
let conf = "log_level = 3
log_filters=\"3:remote 4:event\"
log_outputs=\"3:syslog:virtlogd\"
"
test Virtlogd.lns get conf =
{ "log_level" = "3" }
{ "log_filters" = "3:remote 4:event" }
{ "log_outputs" = "3:syslog:virtlogd" }

45
src/logging/virtlogd.aug Normal file
View File

@ -0,0 +1,45 @@
(* /etc/libvirt/virtlogd.conf *)
module Virtlogd =
autoload xfm
let eol = del /[ \t]*\n/ "\n"
let value_sep = del /[ \t]*=[ \t]*/ " = "
let indent = del /[ \t]*/ ""
let array_sep = del /,[ \t\n]*/ ", "
let array_start = del /\[[ \t\n]*/ "[ "
let array_end = del /\]/ "]"
let str_val = del /\"/ "\"" . store /[^\"]*/ . del /\"/ "\""
let bool_val = store /0|1/
let int_val = store /[0-9]+/
let str_array_element = [ seq "el" . str_val ] . del /[ \t\n]*/ ""
let str_array_val = counter "el" . array_start . ( str_array_element . ( array_sep . str_array_element ) * ) ? . array_end
let str_entry (kw:string) = [ key kw . value_sep . str_val ]
let bool_entry (kw:string) = [ key kw . value_sep . bool_val ]
let int_entry (kw:string) = [ key kw . value_sep . int_val ]
let str_array_entry (kw:string) = [ key kw . value_sep . str_array_val ]
(* Config entry grouped by function - same order as example config *)
let logging_entry = int_entry "log_level"
| str_entry "log_filters"
| str_entry "log_outputs"
| int_entry "log_buffer_size"
| int_entry "max_clients"
(* Each enty in the config is one of the following three ... *)
let entry = logging_entry
let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
let empty = [ label "#empty" . eol ]
let record = indent . entry . eol
let lns = ( record | comment | empty ) *
let filter = incl "/etc/libvirt/virtlogd.conf"
. Util.stdexcl
let xfm = transform lns filter

59
src/logging/virtlogd.conf Normal file
View File

@ -0,0 +1,59 @@
# Master virtlogd daemon configuration file
#
#################################################################
#
# Logging controls
#
# Logging level: 4 errors, 3 warnings, 2 information, 1 debug
# basically 1 will log everything possible
#log_level = 3
# Logging filters:
# A filter allows to select a different logging level for a given category
# of logs
# The format for a filter is one of:
# x:name
# x:+name
# where name is a string which is matched against source file name,
# e.g., "remote", "qemu", or "util/json", the optional "+" prefix
# tells libvirt to log stack trace for each message matching name,
# and x is the minimal level where matching messages should be logged:
# 1: DEBUG
# 2: INFO
# 3: WARNING
# 4: ERROR
#
# Multiple filter can be defined in a single @filters, they just need to be
# separated by spaces.
#
# e.g. to only get warning or errors from the remote layer and only errors
# from the event layer:
#log_filters="3:remote 4:event"
# Logging outputs:
# An output is one of the places to save logging information
# The format for an output can be:
# x:stderr
# output goes to stderr
# x:syslog:name
# use syslog for the output and use the given name as the ident
# x:file:file_path
# output to a file, with the given filepath
# x:journald
# ouput to the systemd journal
# In all case the x prefix is the minimal level, acting as a filter
# 1: DEBUG
# 2: INFO
# 3: WARNING
# 4: ERROR
#
# Multiple output can be defined, they just need to be separated by spaces.
# e.g. to log all warnings and errors to syslog under the virtlogd ident:
#log_outputs="3:syslog:virtlogd"
#
# The maximum number of concurrent client connections to allow
# over all sockets combined.
#max_clients = 1024

View File

@ -0,0 +1,94 @@
#!/bin/sh
# the following is the LSB init header see
# http://www.linux-foundation.org/spec//booksets/LSB-Core-generic/LSB-Core-generic.html#INITSCRCOMCONV
#
### BEGIN INIT INFO
# Provides: virtlogd
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: virtual machine log manager
# Description: This is a daemon for managing logs
# of virtual machine consoles
### END INIT INFO
# the following is chkconfig init header
#
# virtlogd: virtual machine log manager
#
# chkconfig: - 96 04
# description: This is a daemon for managing logs \
# of virtual machine consoles
#
# processname: virtlogd
# pidfile: @localstatedir@/run/virtlogd.pid
#
# Source function library.
. @sysconfdir@/rc.d/init.d/functions
SERVICE=virtlogd
PROCESS=virtlogd
PIDFILE=@localstatedir@/run/$SERVICE.pid
VIRTLOGD_ARGS=
test -f @sysconfdir@/sysconfig/virtlogd && . @sysconfdir@/sysconfig/virtlogd
RETVAL=0
start() {
echo -n $"Starting $SERVICE daemon: "
daemon --pidfile $PIDFILE --check $SERVICE $PROCESS --daemon $VIRTLOGD_ARGS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch @localstatedir@/log/subsys/$SERVICE
}
stop() {
echo -n $"Stopping $SERVICE daemon: "
killproc -p $PIDFILE $PROCESS
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
rm -f @localstatedir@/log/subsys/$SERVICE
rm -f $PIDFILE
fi
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $SERVICE configuration: "
killproc -p $PIDFILE $PROCESS -USR1
RETVAL=$?
echo
return $RETVAL
}
# See how we were called.
case "$1" in
start|stop|restart|reload)
$1
;;
status)
status -p $PIDFILE $PROCESS
RETVAL=$?
;;
force-reload)
reload
;;
condrestart|try-restart)
[ -f @localstatedir@/log/subsys/$SERVICE ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload|try-restart}"
exit 2
;;
esac
exit $RETVAL

167
src/logging/virtlogd.pod.in Normal file
View File

@ -0,0 +1,167 @@
=head1 NAME
virtlogd - libvirt log management daemon
=head1 SYNOPSIS
B<virtlogd> [ -dvV ] [-t timeout] [ -f config_file ] [ -p pid_file ]
B<virtlogd> --version
=head1 DESCRIPTION
The B<virtlogd> program is a server side daemon component of the libvirt
virtualization management system that is used to manage logs from virtual
machine consoles.
This daemon is not used directly by libvirt client applications, rather it
is called on their behalf by B<libvirtd>. By maintaining the logs in a
standalone daemon, the main libvirtd daemon can be restarted without risk
of losing logs. The B<virtlogd> daemon has the ability to re-exec()
itself upon receiving SIGUSR1, to allow live upgrades without downtime.
The virtlogd daemon listens for requests on a local Unix domain socket.
=head1 OPTIONS
=over
=item B<-h, --help>
Display command line help usage then exit.
=item B<-d, --daemon>
Run as a daemon and write PID file.
=item B<-f, --config> I<FILE>
Use this configuration file, overriding the default value.
=item B<-t, --timeout> I<SECONDS>
Automatically shutdown after I<SECONDS> have elapsed with
no active console log.
=item B<-p, --pid-file> I<FILE>
Use this name for the PID file, overriding the default value.
=item B<-v, --verbose>
Enable output of verbose messages.
=item B<-V, --version>
Display version information then exit.
=back
=head1 SIGNALS
On receipt of B<SIGUSR1> virtlogd will re-exec() its binary, while
maintaining all current logs and clients. This allows for live
upgrades of the virtlogd service.
=head1 FILES
=head2 When run as B<root>.
=over
=item F<SYSCONFDIR/virtlogd.conf>
The default configuration file used by virtlogd, unless overridden on the
command line using the B<-f>|B<--config> option.
=item F<LOCALSTATEDIR/run/libvirt/virtlogd-sock>
The sockets libvirtd will use.
=item F<LOCALSTATEDIR/run/virtlogd.pid>
The PID file to use, unless overridden by the B<-p>|B<--pid-file> option.
=back
=head2 When run as B<non-root>.
=over
=item F<$XDG_CONFIG_HOME/virtlogd.conf>
The default configuration file used by libvirtd, unless overridden on the
command line using the B<-f>|B<--config> option.
=item F<$XDG_RUNTIME_DIR/libvirt/virtlogd-sock>
The socket libvirtd will use.
=item F<$XDG_RUNTIME_DIR/libvirt/virtlogd.pid>
The PID file to use, unless overridden by the B<-p>|B<--pid-file> option.
=item If $XDG_CONFIG_HOME is not set in your environment, libvirtd will use F<$HOME/.config>
=item If $XDG_RUNTIME_DIR is not set in your environment, libvirtd will use F<$HOME/.cache>
=back
=head1 EXAMPLES
To retrieve the version of virtlogd:
# virtlogd --version
virtlogd (libvirt) 1.1.1
#
To start virtlogd, instructing it to daemonize and create a PID file:
# virtlogd -d
# ls -la LOCALSTATEDIR/run/virtlogd.pid
-rw-r--r-- 1 root root 6 Jul 9 02:40 LOCALSTATEDIR/run/virtlogd.pid
#
=head1 BUGS
Please report all bugs you discover. This should be done via either:
=over
=item a) the mailing list
L<http://libvirt.org/contact.html>
=item or,
B<>
=item b) the bug tracker
L<http://libvirt.org/bugs.html>
=item Alternatively, you may report bugs to your software distributor / vendor.
=back
=head1 AUTHORS
Please refer to the AUTHORS file distributed with libvirt.
=head1 COPYRIGHT
Copyright (C) 2006-2015 Red Hat, Inc., and the authors listed in the
libvirt AUTHORS file.
=head1 LICENSE
virtlogd is distributed under the terms of the GNU LGPL v2.1+.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE
=head1 SEE ALSO
L<libvirtd(8)>, L<http://www.libvirt.org/>
=cut

View File

@ -0,0 +1,17 @@
[Unit]
Description=Virtual machine log manager
Requires=virtlogd.socket
Documentation=man:virtlogd(8)
Documentation=http://libvirt.org
[Service]
EnvironmentFile=-/etc/sysconfig/virtlogd
ExecStart=@sbindir@/virtlogd $VIRTLOGD_ARGS
ExecReload=/bin/kill -USR1 $MAINPID
# Loosing the logs is a really bad thing that will
# cause the machine to be fenced (rebooted), so make
# sure we discourage OOM killer
OOMScoreAdjust=-900
[Install]
Also=virtlogd.socket

View File

@ -0,0 +1,8 @@
[Unit]
Description=Virtual machine log manager socket
[Socket]
ListenStream=@localstatedir@/run/libvirt/virtlogd-sock
[Install]
WantedBy=sockets.target

View File

@ -0,0 +1,3 @@
#
# Pass extra arguments to virtlogd
#VIRTLOGD_ARGS=

View File

@ -134,6 +134,7 @@ VIR_ENUM_IMPL(virErrorDomain, VIR_ERR_DOMAIN_LAST,
"Polkit", /* 60 */
"Thread jobs",
"Admin Interface",
"Log Manager",
)