|
|
923a60 |
From 85eeadc898d2c0f8b7524982c84b88b01a5dcb89 Mon Sep 17 00:00:00 2001
|
|
|
923a60 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
923a60 |
Date: Wed, 1 Mar 2017 04:03:48 +0100
|
|
|
923a60 |
Subject: [PATCH] automount: if an automount unit is masked, don't react to
|
|
|
923a60 |
activation anymore (#5445)
|
|
|
923a60 |
|
|
|
923a60 |
Otherwise we'll hit an assert sooner or later.
|
|
|
923a60 |
|
|
|
923a60 |
This requires us to initialize ->where even if we come back in "masked"
|
|
|
923a60 |
mode, as otherwise we don't know how to operate on the automount and
|
|
|
923a60 |
detach it.
|
|
|
923a60 |
|
|
|
923a60 |
Fixes: #5441
|
|
|
923a60 |
(cherry picked from commit e350ca3f1ecb6672b74cd25d09ef23c7b309aa5a)
|
|
|
923a60 |
|
|
|
923a60 |
Resolves: #1498318
|
|
|
923a60 |
---
|
|
|
923a60 |
src/core/automount.c | 74 ++++++++++++++++++++++++++++++--------------
|
|
|
923a60 |
1 file changed, 50 insertions(+), 24 deletions(-)
|
|
|
923a60 |
|
|
|
923a60 |
diff --git a/src/core/automount.c b/src/core/automount.c
|
|
|
923a60 |
index 4e066613d7..20a5de8cae 100644
|
|
|
923a60 |
--- a/src/core/automount.c
|
|
|
923a60 |
+++ b/src/core/automount.c
|
|
|
923a60 |
@@ -106,18 +106,18 @@ static void unmount_autofs(Automount *a) {
|
|
|
923a60 |
if (a->pipe_fd < 0)
|
|
|
923a60 |
return;
|
|
|
923a60 |
|
|
|
923a60 |
- automount_send_ready(a, a->tokens, -EHOSTDOWN);
|
|
|
923a60 |
- automount_send_ready(a, a->expire_tokens, -EHOSTDOWN);
|
|
|
923a60 |
-
|
|
|
923a60 |
a->pipe_event_source = sd_event_source_unref(a->pipe_event_source);
|
|
|
923a60 |
a->pipe_fd = safe_close(a->pipe_fd);
|
|
|
923a60 |
|
|
|
923a60 |
- /* If we reload/reexecute things we keep the mount point
|
|
|
923a60 |
- * around */
|
|
|
923a60 |
- if (a->where &&
|
|
|
923a60 |
- (UNIT(a)->manager->exit_code != MANAGER_RELOAD &&
|
|
|
923a60 |
- UNIT(a)->manager->exit_code != MANAGER_REEXECUTE))
|
|
|
923a60 |
- repeat_unmount(a->where);
|
|
|
923a60 |
+ /* If we reload/reexecute things we keep the mount point around */
|
|
|
923a60 |
+ if (!IN_SET(UNIT(a)->manager->exit_code, MANAGER_RELOAD, MANAGER_REEXECUTE)) {
|
|
|
923a60 |
+
|
|
|
923a60 |
+ automount_send_ready(a, a->tokens, -EHOSTDOWN);
|
|
|
923a60 |
+ automount_send_ready(a, a->expire_tokens, -EHOSTDOWN);
|
|
|
923a60 |
+
|
|
|
923a60 |
+ if (a->where)
|
|
|
923a60 |
+ repeat_unmount(a->where);
|
|
|
923a60 |
+ }
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
static void automount_done(Unit *u) {
|
|
|
923a60 |
@@ -193,6 +193,20 @@ static int automount_verify(Automount *a) {
|
|
|
923a60 |
return 0;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
+static int automount_set_where(Automount *a) {
|
|
|
923a60 |
+ assert(a);
|
|
|
923a60 |
+
|
|
|
923a60 |
+ if (a->where)
|
|
|
923a60 |
+ return 0;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ a->where = unit_name_to_path(UNIT(a)->id);
|
|
|
923a60 |
+ if (!a->where)
|
|
|
923a60 |
+ return -ENOMEM;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ path_kill_slashes(a->where);
|
|
|
923a60 |
+ return 1;
|
|
|
923a60 |
+}
|
|
|
923a60 |
+
|
|
|
923a60 |
static int automount_load(Unit *u) {
|
|
|
923a60 |
Automount *a = AUTOMOUNT(u);
|
|
|
923a60 |
int r;
|
|
|
923a60 |
@@ -208,13 +222,9 @@ static int automount_load(Unit *u) {
|
|
|
923a60 |
if (u->load_state == UNIT_LOADED) {
|
|
|
923a60 |
Unit *x;
|
|
|
923a60 |
|
|
|
923a60 |
- if (!a->where) {
|
|
|
923a60 |
- a->where = unit_name_to_path(u->id);
|
|
|
923a60 |
- if (!a->where)
|
|
|
923a60 |
- return -ENOMEM;
|
|
|
923a60 |
- }
|
|
|
923a60 |
-
|
|
|
923a60 |
- path_kill_slashes(a->where);
|
|
|
923a60 |
+ r = automount_set_where(a);
|
|
|
923a60 |
+ if (r < 0)
|
|
|
923a60 |
+ return r;
|
|
|
923a60 |
|
|
|
923a60 |
r = unit_load_related_unit(u, ".mount", &x);
|
|
|
923a60 |
if (r < 0)
|
|
|
923a60 |
@@ -259,6 +269,8 @@ static void automount_set_state(Automount *a, AutomountState state) {
|
|
|
923a60 |
unit_notify(UNIT(a), state_translation_table[old_state], state_translation_table[state], true);
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
+static int automount_start_expire(Automount *a);
|
|
|
923a60 |
+
|
|
|
923a60 |
static int automount_coldplug(Unit *u, Hashmap *deferred_work) {
|
|
|
923a60 |
Automount *a = AUTOMOUNT(u);
|
|
|
923a60 |
int r;
|
|
|
923a60 |
@@ -266,20 +278,30 @@ static int automount_coldplug(Unit *u, Hashmap *deferred_work) {
|
|
|
923a60 |
assert(a);
|
|
|
923a60 |
assert(a->state == AUTOMOUNT_DEAD);
|
|
|
923a60 |
|
|
|
923a60 |
- if (a->deserialized_state != a->state) {
|
|
|
923a60 |
+ if (a->deserialized_state == a->state)
|
|
|
923a60 |
+ return 0;
|
|
|
923a60 |
+
|
|
|
923a60 |
+ if (IN_SET(a->deserialized_state, AUTOMOUNT_WAITING, AUTOMOUNT_RUNNING)) {
|
|
|
923a60 |
+
|
|
|
923a60 |
+ r = automount_set_where(a);
|
|
|
923a60 |
+ if (r < 0)
|
|
|
923a60 |
+ return r;
|
|
|
923a60 |
|
|
|
923a60 |
r = open_dev_autofs(u->manager);
|
|
|
923a60 |
if (r < 0)
|
|
|
923a60 |
return r;
|
|
|
923a60 |
|
|
|
923a60 |
- if (a->deserialized_state == AUTOMOUNT_WAITING ||
|
|
|
923a60 |
- a->deserialized_state == AUTOMOUNT_RUNNING) {
|
|
|
923a60 |
+ assert(a->pipe_fd >= 0);
|
|
|
923a60 |
|
|
|
923a60 |
- assert(a->pipe_fd >= 0);
|
|
|
923a60 |
+ r = sd_event_add_io(u->manager->event, &a->pipe_event_source, a->pipe_fd, EPOLLIN, automount_dispatch_io, u);
|
|
|
923a60 |
+ if (r < 0)
|
|
|
923a60 |
+ return r;
|
|
|
923a60 |
|
|
|
923a60 |
- r = sd_event_add_io(u->manager->event, &a->pipe_event_source, a->pipe_fd, EPOLLIN, automount_dispatch_io, u);
|
|
|
923a60 |
+ (void) sd_event_source_set_description(a->pipe_event_source, "automount-io");
|
|
|
923a60 |
+ if (a->deserialized_state == AUTOMOUNT_RUNNING) {
|
|
|
923a60 |
+ r = automount_start_expire(a);
|
|
|
923a60 |
if (r < 0)
|
|
|
923a60 |
- return r;
|
|
|
923a60 |
+ log_unit_warning_errno(UNIT(a)->id, r, "Failed to start expiration timer, ignoring: %m");
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
automount_set_state(a, a->deserialized_state);
|
|
|
923a60 |
@@ -636,8 +658,6 @@ static void *expire_thread(void *p) {
|
|
|
923a60 |
return NULL;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
-static int automount_start_expire(Automount *a);
|
|
|
923a60 |
-
|
|
|
923a60 |
static int automount_dispatch_expire(sd_event_source *source, usec_t usec, void *userdata) {
|
|
|
923a60 |
Automount *a = AUTOMOUNT(userdata);
|
|
|
923a60 |
_cleanup_(expire_data_freep) struct expire_data *data = NULL;
|
|
|
923a60 |
@@ -699,6 +719,12 @@ static void automount_enter_runnning(Automount *a) {
|
|
|
923a60 |
|
|
|
923a60 |
assert(a);
|
|
|
923a60 |
|
|
|
923a60 |
+ /* If the user masked our unit in the meantime, fail */
|
|
|
923a60 |
+ if (UNIT(a)->load_state != UNIT_LOADED) {
|
|
|
923a60 |
+ log_unit_error(UNIT(a)->id, "Suppressing automount event since unit is no longer loaded.");
|
|
|
923a60 |
+ goto fail;
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+
|
|
|
923a60 |
/* We don't take mount requests anymore if we are supposed to
|
|
|
923a60 |
* shut down anyway */
|
|
|
923a60 |
if (unit_stop_pending(UNIT(a))) {
|