2014-02-26 13:52:11 +01:00
|
|
|
Avoid possible race on NFS shares in which may that the network devices disappears
|
|
|
|
before the associated NFS share becomes unmounted (bug #861489).
|
|
|
|
To do this make sure that sys-subsystem-net-devices-<iface>.device used for the
|
|
|
|
NFS share is added as "After=" dependency to the <nfs-share-mount-point>.mount.
|
|
|
|
|
|
|
|
---
|
|
|
|
Makefile.am | 2
|
|
|
|
src/core/mount-iface.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
src/core/mount-iface.h | 25 +++++++
|
2014-03-03 15:25:26 +01:00
|
|
|
src/core/mount.c | 35 +++++++++
|
2015-12-02 16:45:15 +01:00
|
|
|
4 files changed, 233 insertions(+), 2 deletions(-)
|
2014-02-26 13:52:11 +01:00
|
|
|
|
2015-12-02 16:45:15 +01:00
|
|
|
Index: systemd-228/Makefile.am
|
2015-02-13 10:43:21 +01:00
|
|
|
===================================================================
|
2015-12-02 16:45:15 +01:00
|
|
|
--- systemd-228.orig/Makefile.am
|
|
|
|
+++ systemd-228/Makefile.am
|
|
|
|
@@ -1223,6 +1223,8 @@ libcore_la_SOURCES = \
|
2014-02-26 13:52:11 +01:00
|
|
|
src/core/machine-id-setup.h \
|
|
|
|
src/core/mount-setup.c \
|
|
|
|
src/core/mount-setup.h \
|
|
|
|
+ src/core/mount-iface.c \
|
|
|
|
+ src/core/mount-iface.h \
|
2015-02-13 10:43:21 +01:00
|
|
|
src/core/kmod-setup.c \
|
|
|
|
src/core/kmod-setup.h \
|
2014-02-26 13:52:11 +01:00
|
|
|
src/core/loopback-setup.h \
|
2015-12-02 16:45:15 +01:00
|
|
|
Index: systemd-228/src/core/mount-iface.c
|
2015-02-13 10:43:21 +01:00
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
2015-12-02 16:45:15 +01:00
|
|
|
+++ systemd-228/src/core/mount-iface.c
|
2014-02-26 13:52:11 +01:00
|
|
|
@@ -0,0 +1,173 @@
|
|
|
|
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
|
+
|
|
|
|
+/***
|
|
|
|
+ This file is part of systemd.
|
|
|
|
+
|
|
|
|
+ Copyright 2014 Werner Fink
|
|
|
|
+
|
|
|
|
+ systemd 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.
|
|
|
|
+
|
|
|
|
+ systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
+***/
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * Find the name of the network interface to which a IP address belongs to.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#include <stdio.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
+#include <string.h>
|
|
|
|
+#include <arpa/inet.h>
|
|
|
|
+#include <ifaddrs.h>
|
|
|
|
+#include <net/if.h>
|
|
|
|
+#include <assert.h>
|
|
|
|
+
|
|
|
|
+#include "log.h"
|
|
|
|
+#include "def.h"
|
|
|
|
+#include "mount-iface.h"
|
|
|
|
+
|
|
|
|
+static struct ifaddrs *ifa_list;
|
|
|
|
+
|
|
|
|
+_pure_ static unsigned int mask2prefix(const void* ipv6)
|
|
|
|
+{
|
2014-02-26 16:16:45 +01:00
|
|
|
+ unsigned int nippels = 0;
|
|
|
|
+ unsigned int i;
|
|
|
|
+
|
|
|
|
+ assert(ipv6);
|
|
|
|
+
|
|
|
|
+ for (i = 0; i < sizeof(struct in6_addr); i++) {
|
|
|
|
+ uint8_t byte = ((const uint8_t*)ipv6)[i];
|
|
|
|
+ if (byte == 0xFF) {
|
|
|
|
+ nippels += sizeof(uint8_t);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ while (byte & 0x80) {
|
|
|
|
+ nippels++;
|
|
|
|
+ byte <<= 1;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nippels;
|
2014-02-26 13:52:11 +01:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void netmask(unsigned int prefix, const void* in6, void* out6)
|
|
|
|
+{
|
2014-02-26 16:16:45 +01:00
|
|
|
+ unsigned int nippels;
|
|
|
|
+ unsigned int i;
|
2014-02-26 13:52:11 +01:00
|
|
|
+
|
2014-02-26 16:16:45 +01:00
|
|
|
+ assert(in6);
|
|
|
|
+ assert(out6);
|
2014-02-26 13:52:11 +01:00
|
|
|
+
|
2014-02-26 16:16:45 +01:00
|
|
|
+ for (i = 0; i < sizeof(struct in6_addr); i++) {
|
|
|
|
+ nippels = (prefix < sizeof(uint8_t)) ? prefix : sizeof(uint8_t);
|
|
|
|
+ ((uint8_t*)out6)[i] = ((const uint8_t*)in6)[i] & (0xFF00>>nippels);
|
|
|
|
+ prefix -= nippels;
|
|
|
|
+ }
|
2014-02-26 13:52:11 +01:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+char *host2iface(const char *ip)
|
|
|
|
+{
|
2014-02-26 16:16:45 +01:00
|
|
|
+ const struct ifaddrs *ifa;
|
|
|
|
+ uint32_t ip4 = 0;
|
|
|
|
+ char *ret = NULL;
|
|
|
|
+ struct search {
|
|
|
|
+ union {
|
|
|
|
+ struct in_addr addr;
|
|
|
|
+ struct in6_addr addr6;
|
|
|
|
+ };
|
|
|
|
+ int family;
|
|
|
|
+ } host;
|
|
|
|
+ int r;
|
|
|
|
+
|
|
|
|
+ if (!ifa_list && (getifaddrs(&ifa_list) < 0)) {
|
|
|
|
+ log_oom();
|
|
|
|
+ goto err;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (strchr(ip, ':')) {
|
|
|
|
+ r = inet_pton(AF_INET6, ip, &host.addr6);
|
|
|
|
+ host.family = AF_INET6;
|
|
|
|
+ } else {
|
|
|
|
+ r = inet_pton(AF_INET, ip, &host.addr);
|
|
|
|
+ host.family = AF_INET;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (r < 0) {
|
|
|
|
+ log_error("Failed to convert IP address %s from text to binary: %m", ip);
|
|
|
|
+ goto err;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (ifa = ifa_list; ifa != NULL; ifa = ifa->ifa_next) {
|
|
|
|
+
|
|
|
|
+ if (!ifa->ifa_addr)
|
|
|
|
+ continue;
|
|
|
|
+ if (ifa->ifa_flags & IFF_POINTOPOINT)
|
|
|
|
+ continue;
|
|
|
|
+ if (!ifa->ifa_addr)
|
|
|
|
+ continue;
|
|
|
|
+ if (!ifa->ifa_netmask)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ if (ifa->ifa_addr->sa_family == AF_INET) {
|
|
|
|
+ uint32_t addr, dest, mask;
|
|
|
|
+
|
|
|
|
+ if (host.family != AF_INET)
|
|
|
|
+ continue;
|
|
|
|
+ if (!ifa->ifa_broadaddr)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ if (!ip4)
|
|
|
|
+ ip4 = (uint32_t)ntohl(host.addr.s_addr);
|
|
|
|
+
|
|
|
|
+ addr = (uint32_t)ntohl(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr);
|
|
|
|
+ if ((addr & 0xFF000000) == 0x7F000000) /* IPV4 loopback */
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ mask = (uint32_t)ntohl(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr.s_addr);
|
|
|
|
+ dest = (uint32_t)ntohl(((struct sockaddr_in*)ifa->ifa_broadaddr)->sin_addr.s_addr);
|
|
|
|
+ if ((ip4 & mask) != (dest & mask))
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ ret = ifa->ifa_name;
|
2015-02-13 10:43:21 +01:00
|
|
|
+ break;
|
2014-02-26 16:16:45 +01:00
|
|
|
+ } else if (ifa->ifa_addr->sa_family == AF_INET6) {
|
|
|
|
+ struct in6_addr *addr, *mask, dest, ip6;
|
|
|
|
+ unsigned int prefix;
|
|
|
|
+
|
|
|
|
+ if (host.family != AF_INET6)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ addr = &((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr;
|
|
|
|
+ mask = &((struct sockaddr_in6*)ifa->ifa_netmask)->sin6_addr;
|
|
|
|
+ prefix = mask2prefix(mask);
|
|
|
|
+
|
|
|
|
+ netmask(prefix, addr, &dest);
|
|
|
|
+ netmask(prefix, &host.addr6, &ip6);
|
|
|
|
+
|
|
|
|
+ if (memcmp(&dest, &ip6, sizeof(struct in6_addr)) != 0)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ ret = ifa->ifa_name;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
2014-02-26 13:52:11 +01:00
|
|
|
+err:
|
2014-02-26 16:16:45 +01:00
|
|
|
+ return ret;
|
2014-02-26 13:52:11 +01:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void freeroutes(void)
|
|
|
|
+{
|
2014-02-26 16:16:45 +01:00
|
|
|
+ if (ifa_list)
|
|
|
|
+ freeifaddrs(ifa_list);
|
|
|
|
+ ifa_list = NULL;
|
2014-02-26 13:52:11 +01:00
|
|
|
+}
|
2015-12-02 16:45:15 +01:00
|
|
|
Index: systemd-228/src/core/mount-iface.h
|
2015-02-13 10:43:21 +01:00
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
2015-12-02 16:45:15 +01:00
|
|
|
+++ systemd-228/src/core/mount-iface.h
|
2014-02-26 13:52:11 +01:00
|
|
|
@@ -0,0 +1,25 @@
|
|
|
|
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
|
+
|
|
|
|
+#pragma once
|
|
|
|
+
|
|
|
|
+/***
|
|
|
|
+ This file is part of systemd.
|
|
|
|
+
|
|
|
|
+ Copyright 2014 Werner Fink
|
|
|
|
+
|
|
|
|
+ systemd 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.
|
|
|
|
+
|
|
|
|
+ systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
+***/
|
|
|
|
+
|
|
|
|
+char *host2iface(const char *ip);
|
|
|
|
+void freeroutes(void);
|
2015-12-02 16:45:15 +01:00
|
|
|
Index: systemd-228/src/core/mount.c
|
2015-02-13 10:43:21 +01:00
|
|
|
===================================================================
|
2015-12-02 16:45:15 +01:00
|
|
|
--- systemd-228.orig/src/core/mount.c
|
|
|
|
+++ systemd-228/src/core/mount.c
|
|
|
|
@@ -36,6 +36,7 @@
|
|
|
|
#include "manager.h"
|
2014-02-26 13:52:11 +01:00
|
|
|
#include "mkdir.h"
|
|
|
|
#include "mount-setup.h"
|
|
|
|
+#include "mount-iface.h"
|
2015-12-02 16:45:15 +01:00
|
|
|
#include "mount-util.h"
|
|
|
|
#include "mount.h"
|
|
|
|
#include "parse-util.h"
|
|
|
|
@@ -1344,8 +1345,9 @@ static int mount_setup_unit(
|
2014-02-28 18:10:52 +01:00
|
|
|
_cleanup_free_ char *e = NULL, *w = NULL, *o = NULL, *f = NULL;
|
|
|
|
bool load_extras = false;
|
|
|
|
MountParameters *p;
|
2014-03-03 15:25:26 +01:00
|
|
|
- bool delete, changed = false;
|
|
|
|
+ bool delete, changed = false, isnetwork;
|
2014-02-28 18:10:52 +01:00
|
|
|
Unit *u;
|
|
|
|
+ char *c;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(m);
|
2015-12-02 16:45:15 +01:00
|
|
|
@@ -1370,6 +1372,8 @@ static int mount_setup_unit(
|
2015-06-23 14:56:50 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-02-26 13:52:11 +01:00
|
|
|
|
|
|
|
+ isnetwork = fstype_is_network(fstype);
|
|
|
|
+
|
|
|
|
u = manager_get_unit(m, e);
|
|
|
|
if (!u) {
|
|
|
|
delete = true;
|
2015-12-02 16:45:15 +01:00
|
|
|
@@ -1397,7 +1401,7 @@ static int mount_setup_unit(
|
2015-06-23 14:56:50 +02:00
|
|
|
if (m->running_as == MANAGER_SYSTEM) {
|
2014-02-28 18:10:52 +01:00
|
|
|
const char* target;
|
|
|
|
|
2015-02-13 10:43:21 +01:00
|
|
|
- target = mount_needs_network(options, fstype) ? SPECIAL_REMOTE_FS_TARGET : SPECIAL_LOCAL_FS_TARGET;
|
2014-02-28 18:10:52 +01:00
|
|
|
+ target = isnetwork ? SPECIAL_REMOTE_FS_TARGET : SPECIAL_LOCAL_FS_TARGET;
|
|
|
|
r = unit_add_dependency_by_name(u, UNIT_BEFORE, target, NULL, true);
|
|
|
|
if (r < 0)
|
2015-02-13 10:43:21 +01:00
|
|
|
goto fail;
|
2015-12-02 16:45:15 +01:00
|
|
|
@@ -1483,6 +1487,32 @@ static int mount_setup_unit(
|
2014-02-26 13:52:11 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-02-28 18:10:52 +01:00
|
|
|
+ if (isnetwork && (c = strrchr(p->what, ':')) && *(c+1) == '/') {
|
|
|
|
+ _cleanup_free_ char *opt = strdup(p->options);
|
|
|
|
+ char *addr;
|
|
|
|
+
|
|
|
|
+ if (opt && (addr = strstr(opt, ",addr="))) {
|
2014-02-26 13:52:11 +01:00
|
|
|
+ char *colon, *iface;
|
|
|
|
+
|
|
|
|
+ addr += 6;
|
|
|
|
+ if ((colon = strchr(addr, ',')))
|
|
|
|
+ *colon = '\0';
|
|
|
|
+
|
|
|
|
+ iface = host2iface(addr);
|
|
|
|
+ if (iface) {
|
2014-02-28 18:10:52 +01:00
|
|
|
+ _cleanup_free_ char* target = NULL;
|
2014-02-26 13:52:11 +01:00
|
|
|
+ if (asprintf(&target, "sys-subsystem-net-devices-%s.device", iface) < 0)
|
|
|
|
+ log_oom();
|
|
|
|
+ else {
|
|
|
|
+ r = unit_add_dependency_by_name(u, UNIT_AFTER, target, NULL, true);
|
|
|
|
+ if (r < 0)
|
2015-06-23 14:56:50 +02:00
|
|
|
+ log_unit_error(u, "Failed to add dependency on %s, ignoring: %s",
|
2014-02-26 13:52:11 +01:00
|
|
|
+ target, strerror(-r));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2014-03-03 15:25:26 +01:00
|
|
|
if (changed)
|
|
|
|
unit_add_to_dbus_queue(u);
|
2014-02-26 13:52:11 +01:00
|
|
|
|
2015-12-02 16:45:15 +01:00
|
|
|
@@ -1549,6 +1579,7 @@ static int mount_load_proc_self_mountinf
|
2015-02-13 10:43:21 +01:00
|
|
|
if (r == 0 && k < 0)
|
2014-02-26 13:52:11 +01:00
|
|
|
r = k;
|
|
|
|
}
|
|
|
|
+ freeroutes(); /* Just in case of using the routing table with host2iface() */
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|