``libvirtd.socket``, ``libvirtd-ro.socket`` and ``libvirtd-admin.socket`` unit
files.
-Systemd releases prior to version 227 lacked support for passing the activation
-socket unit names into the service. When using these old versions, the
-``tcp_port``, ``tls_port`` and ``unix_sock_dir`` settings in ``libvirtd.conf``
-must be changed in lock-step with the equivalent settings in the unit files to
-ensure that ``libvirtd`` can identify the sockets.
-
-
Modular driver daemons
======================
``virt${DRIVER}d.socket``, ``virt${DRIVER}d-ro.socket`` and
``virt${DRIVER}d-admin.socket`` unit files.
-Systemd releases prior to version 227 lacked support for passing the activation
-socket unit names into the service. When using these old versions, the
-``unix_sock_dir`` setting in ``virt${DRIVER}d.conf`` must be changed in
-lock-step with the equivalent setting in the unit files to ensure that
-``virt${DRIVER}d`` can identify the sockets.
-
-
Switching to modular daemons
----------------------------
independently controlled via the ``ListenStream`` parameter in any of the
``virtlogd.socket`` and ``virtlogd-admin.socket`` unit files.
-Systemd releases prior to version 227 lacked support for passing the activation
-socket unit names into the service. When using these old versions, the
-``unix_sock_dir`` setting in ``virtlogd.conf`` must be changed in
-lock-step with the equivalent setting in the unit files to ensure that
-``virtlogd`` can identify the sockets.
-
Locking daemon
==============
independently controlled via the ``ListenStream`` parameter in any of the
``virtlockd.socket`` and ``virtlockd-admin.socket`` unit files.
-Systemd releases prior to version 227 lacked support for passing the activation
-socket unit names into the service. When using these old versions, the
-``unix_sock_dir`` setting in ``virtlockd.conf`` must be changed in
-lock-step with the equivalent setting in the unit files to ensure that
-``virtlockd`` can identify the sockets.
-
Changing command line options for daemons
=========================================
* saved state is present, therefore initialize from scratch here. */
if (rv == 0) {
g_autoptr(virSystemdActivation) act = NULL;
- virSystemdActivationMap actmap[] = {
- { .name = "virtlockd.socket", .family = AF_UNIX, .path = sock_file },
- { .name = "virtlockd-admin.socket", .family = AF_UNIX, .path = admin_sock_file },
- };
if (godaemon) {
if (chdir("/") < 0) {
goto cleanup;
}
- if (virSystemdGetActivation(actmap,
- G_N_ELEMENTS(actmap),
- &act) < 0) {
+ if (virSystemdGetActivation(&act) < 0) {
ret = VIR_DAEMON_ERR_NETWORK;
goto cleanup;
}
*/
if (rv == 0) {
g_autoptr(virSystemdActivation) act = NULL;
- virSystemdActivationMap actmap[] = {
- { .name = "virtlogd.socket", .family = AF_UNIX, .path = sock_file },
- { .name = "virtlogd-admin.socket", .family = AF_UNIX, .path = admin_sock_file },
- };
if (godaemon) {
if (chdir("/") < 0) {
goto cleanup;
}
- if (virSystemdGetActivation(actmap,
- G_N_ELEMENTS(actmap),
- &act) < 0) {
+ if (virSystemdGetActivation(&act) < 0) {
ret = VIR_DAEMON_ERR_NETWORK;
goto cleanup;
}
@deps@
[Socket]
-# The directory must match the @sysconfdir@/libvirt/@service@.conf unix_sock_dir setting
-# when using systemd version < 227
ListenStream=@runstatedir@/libvirt/@sockprefix@-admin-sock
Service=@service@.service
SocketMode=0600
@deps@
[Socket]
-# The directory must match the @sysconfdir@/libvirt/@service@.conf unix_sock_dir setting
-# when using systemd version < 227
ListenStream=@runstatedir@/libvirt/@sockprefix@-sock-ro
Service=@service@.service
SocketMode=0666
@deps@
[Socket]
-# This must match the @sysconfdir@/libvirt/@service@.conf tcp_port setting
-# when using systemd version < 227
ListenStream=16509
Service=@service@.service
@deps@
[Socket]
-# This must match the @sysconfdir@/libvirt/@service@.conf tls_port setting
-# when using systemd version < 227
ListenStream=16514
Service=@service@.service
# This can be a port number, or service name
#
# This setting is not required or honoured if using systemd socket
-# activation with systemd version >= 227
+# activation.
#
#tls_port = "16514"
# This can be a port number, or service name
#
# This setting is not required or honoured if using systemd socket
-# activation with systemd version >= 227
+# activation.
#
#tcp_port = "16509"
# Set the name of the directory in which sockets will be found/created.
#
# This setting is not required or honoured if using systemd socket
-# activation with systemd version >= 227
+# activation.
#
#unix_sock_dir = "@runstatedir@/libvirt"
@deps@
[Socket]
-# The directory must match the @sysconfdir@/libvirt/@service@.conf unix_sock_dir setting
-# when using systemd version < 227
ListenStream=@runstatedir@/libvirt/@sockprefix@-sock
Service=@service@.service
SocketMode=@mode@
unsigned int tcp_min_ssf = 0;
#endif /* !WITH_SASL */
g_autoptr(virSystemdActivation) act = NULL;
- virSystemdActivationMap actmap[] = {
- { .name = DAEMON_NAME ".socket", .family = AF_UNIX, .path = sock_path },
- { .name = DAEMON_NAME "-ro.socket", .family = AF_UNIX, .path = sock_path_ro },
- { .name = DAEMON_NAME "-admin.socket", .family = AF_UNIX, .path = sock_path_adm },
-#ifdef WITH_IP
- { .name = DAEMON_NAME "-tcp.socket", .family = AF_INET },
- { .name = DAEMON_NAME "-tls.socket", .family = AF_INET },
-#endif /* ! WITH_IP */
- };
-
-#ifdef WITH_IP
- if ((actmap[3].port = virSocketAddrResolveService(config->tcp_port)) < 0)
- return -1;
-
- if ((actmap[4].port = virSocketAddrResolveService(config->tls_port)) < 0)
- return -1;
-#endif /* ! WITH_IP */
- if (virSystemdGetActivation(actmap, G_N_ELEMENTS(actmap), &act) < 0)
+ if (virSystemdGetActivation(&act) < 0)
return -1;
#ifdef WITH_IP
}
-/*
- * Back compat for systemd < v227 which lacks LISTEN_FDNAMES.
- * Delete when min systemd is increased ie RHEL7 dropped
- */
-static int
-virSystemdActivationInitFromMap(virSystemdActivation *act,
- int nfds,
- virSystemdActivationMap *map,
- size_t nmap)
-{
- int nextfd = STDERR_FILENO + 1;
- size_t i;
-
- while (nfds) {
- virSocketAddr addr;
- const char *name = NULL;
-
- memset(&addr, 0, sizeof(addr));
-
- addr.len = sizeof(addr.data);
- if (getsockname(nextfd, &addr.data.sa, &addr.len) < 0) {
- virReportSystemError(errno, "%s", _("Unable to get local socket name"));
- goto error;
- }
-
- VIR_DEBUG("Got socket family %d for FD %d",
- addr.data.sa.sa_family, nextfd);
-
- for (i = 0; i < nmap && !name; i++) {
- if (map[i].name == NULL)
- continue;
-
- if (addr.data.sa.sa_family == AF_INET) {
- if (map[i].family == AF_INET) {
- VIR_DEBUG("Expect %d got %d",
- map[i].port, ntohs(addr.data.inet4.sin_port));
- if (addr.data.inet4.sin_port == htons(map[i].port))
- name = map[i].name;
- }
- } else if (addr.data.sa.sa_family == AF_INET6) {
- /* NB use of AF_INET here is correct. The "map" struct
- * only refers to AF_INET. The socket may be AF_INET
- * or AF_INET6
- */
- if (map[i].family == AF_INET) {
- VIR_DEBUG("Expect %d got %d",
- map[i].port, ntohs(addr.data.inet6.sin6_port));
- if (addr.data.inet6.sin6_port == htons(map[i].port))
- name = map[i].name;
- }
-#ifndef WIN32
- } else if (addr.data.sa.sa_family == AF_UNIX) {
- if (map[i].family == AF_UNIX) {
- VIR_DEBUG("Expect %s got %s", map[i].path, addr.data.un.sun_path);
- if (STREQLEN(map[i].path,
- addr.data.un.sun_path,
- sizeof(addr.data.un.sun_path)))
- name = map[i].name;
- }
-#endif
- } else {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unexpected socket family %d"),
- addr.data.sa.sa_family);
- goto error;
- }
- }
-
- if (!name) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Cannot find name for FD %d socket family %d"),
- nextfd, addr.data.sa.sa_family);
- goto error;
- }
-
- if (virSystemdActivationAddFD(act, name, nextfd) < 0)
- goto error;
-
- nfds--;
- nextfd++;
- }
-
- return 0;
-
- error:
- for (i = 0; i < nfds; i++) {
- int fd = nextfd + i;
- VIR_FORCE_CLOSE(fd);
- }
- return -1;
-}
-
#ifndef WIN32
/**
#endif /* WIN32 */
static virSystemdActivation *
-virSystemdActivationNew(virSystemdActivationMap *map,
- size_t nmap,
- int nfds)
+virSystemdActivationNew(int nfds)
{
g_autoptr(virSystemdActivation) act = g_new0(virSystemdActivation, 1);
const char *fdnames;
act->fds = virHashNew(virSystemdActivationEntryFree);
fdnames = getenv("LISTEN_FDNAMES");
- if (fdnames) {
- if (virSystemdActivationInitFromNames(act, nfds, fdnames) < 0)
- return NULL;
- } else {
- if (virSystemdActivationInitFromMap(act, nfds, map, nmap) < 0)
- return NULL;
+ if (!fdnames) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Missing LISTEN_FDNAMES env from systemd socket activation"));
+ return NULL;
}
+ if (virSystemdActivationInitFromNames(act, nfds, fdnames) < 0)
+ return NULL;
+
VIR_DEBUG("Created activation object for %d FDs", nfds);
return g_steal_pointer(&act);
}
/**
* virSystemdGetActivation:
- * @map: mapping of socket addresses to names
- * @nmap: number of entries in @map
* @act: filled with allocated activation object
*
* Acquire an object for handling systemd activation.
* Returns: 0 on success, -1 on failure
*/
int
-virSystemdGetActivation(virSystemdActivationMap *map,
- size_t nmap,
- virSystemdActivation **act)
+virSystemdGetActivation(virSystemdActivation **act)
{
int nfds = 0;
return 0;
}
- *act = virSystemdActivationNew(map, nmap, nfds);
+ *act = virSystemdActivationNew(nfds);
return 0;
}
typedef struct _virSystemdActivation virSystemdActivation;
-/*
- * Back compat for systemd < v227 which lacks LISTEN_FDNAMES.
- * Delete when min systemd is increased ie RHEL7 dropped
- */
-typedef struct _virSystemdActivationMap {
- const char *name;
- int family;
- int port; /* if family == AF_INET/AF_INET6 */
- const char *path; /* if family == AF_UNIX */
-} virSystemdActivationMap;
-
char *virSystemdMakeScopeName(const char *name,
const char *drivername,
bool legacy_behaviour);
char *virSystemdGetMachineUnitByPID(pid_t pid);
-int virSystemdGetActivation(virSystemdActivationMap *map,
- size_t nmap,
- virSystemdActivation **act);
+int virSystemdGetActivation(virSystemdActivation **act);
bool virSystemdActivationHasName(virSystemdActivation *act,
const char *name);
static int
-testActivation(bool useNames)
+testActivationFDNames(const void *opaque G_GNUC_UNUSED)
{
virNetSocket *sockUNIX;
virNetSocket **sockIP;
size_t i;
char nfdstr[VIR_INT64_STR_BUFLEN];
char pidstr[VIR_INT64_STR_BUFLEN];
- virSystemdActivationMap map[2];
int *fds = NULL;
size_t nfds = 0;
g_autoptr(virSystemdActivation) act = NULL;
g_setenv("LISTEN_FDS", nfdstr, TRUE);
g_setenv("LISTEN_PID", pidstr, TRUE);
+ g_setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), TRUE);
- if (useNames)
- g_setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), TRUE);
- else
- g_unsetenv("LISTEN_FDNAMES");
-
- map[0].name = "demo-unix.socket";
- map[0].family = AF_UNIX;
- map[0].path = demo_socket_path;
-
- map[1].name = "demo-ip.socket";
- map[1].family = AF_INET;
- map[1].port = virNetSocketGetPort(sockIP[0]);
-
- if (virSystemdGetActivation(map, G_N_ELEMENTS(map), &act) < 0)
+ if (virSystemdGetActivation(&act) < 0)
goto cleanup;
if (act == NULL) {
g_unsetenv("LISTEN_FDS");
- if (virSystemdGetActivation(NULL, 0, &act) < 0)
+ if (virSystemdGetActivation(&act) < 0)
return -1;
if (act != NULL) {
return 0;
}
-
-static int
-testActivationFDNames(const void *opaque G_GNUC_UNUSED)
-{
- return testActivation(true);
-}
-
-
-static int
-testActivationFDAddrs(const void *opaque G_GNUC_UNUSED)
-{
- return testActivation(false);
-}
-
-
static int
mymain(void)
{
fcntl(STDERR_FILENO + 3, F_GETFL) == -1 && errno == EBADF) {
if (virTestRun("Test activation names", testActivationFDNames, NULL) < 0)
ret = -1;
- if (virTestRun("Test activation addrs", testActivationFDAddrs, NULL) < 0)
- ret = -1;
} else {
VIR_INFO("Skipping activation tests as FD 3/4/5 is open");
}