autofs/autofs-5.1.8-eliminate-last-remaining-state_pipe-usage.patch

293 lines
7.9 KiB
Diff
Raw Normal View History

2023-03-28 02:44:40 +00:00
autofs-5.1.8 - eliminate last remaining state_pipe usage
From: Ian Kent <raven@themaw.net>
Eliminate the last remaining usage autofs mount struct state_pipe that
is used when changing state to ST_SHUTDOWN at submount exit. Ths single
usage consumes a pipe file handle pair for every autofs file system
mount.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
daemon/automount.c | 78 ++++++++++++++++++++--------------------------------
daemon/direct.c | 2 -
daemon/indirect.c | 7 ----
daemon/master.c | 21 ++------------
daemon/state.c | 16 +++-------
include/automount.h | 1
include/state.h | 1
8 files changed, 40 insertions(+), 87 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -123,6 +123,7 @@
- rename statemachine() to signal_handler().
- make signal handling consistent.
- fix incorrect print format specifiers in get_pkt().
+- eliminate last remaining state_pipe usage.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/daemon/automount.c
+++ autofs-5.1.7/daemon/automount.c
@@ -1063,58 +1063,51 @@ static int set_log_priority(const char *
return 0;
}
+static void dummy(int sig)
+{
+}
+
static int get_pkt(struct autofs_point *ap, union autofs_v5_packet_union *pkt)
{
- struct pollfd fds[3];
- int pollfds = 3;
+ struct sigaction sa;
+ sigset_t signalset;
+ struct pollfd fds[2];
+ int pollfds = 2;
char buf[MAX_ERR_BUF];
size_t read;
char *estr;
fds[0].fd = ap->pipefd;
fds[0].events = POLLIN;
- fds[1].fd = ap->state_pipe[0];
+ fds[1].fd = ap->logpri_fifo;
fds[1].events = POLLIN;
- fds[2].fd = ap->logpri_fifo;
- fds[2].events = POLLIN;
- if (fds[2].fd == -1)
+ if (fds[1].fd == -1)
pollfds--;
- for (;;) {
- if (poll(fds, pollfds, -1) == -1) {
- if (errno == EINTR)
- continue;
- estr = strerror_r(errno, buf, MAX_ERR_BUF);
- logerr("poll failed: %s", estr);
- return -1;
- }
-
- if (fds[1].revents & POLLIN) {
- enum states next_state;
- size_t read_size = sizeof(next_state);
- int state_pipe;
+ sa.sa_handler = dummy;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ if (sigaction(SIGCONT, &sa, NULL) == -1)
+ error(LOGOPT_ANY, "failed to set signal handler %d", errno);
- next_state = ST_INVAL;
+ sigfillset(&signalset);
+ sigdelset(&signalset, SIGCONT);
- st_mutex_lock();
-
- state_pipe = ap->state_pipe[0];
-
- read = fullread(state_pipe, &next_state, read_size);
- if (read) {
- estr = strerror_r(errno, buf, MAX_ERR_BUF);
- error(ap->logopt,
- "read error on state pipe, "
- "read %lu, error %s",
- read, estr);
+ for (;;) {
+ errno = 0;
+ if (ppoll(fds, pollfds, NULL, &signalset) == -1) {
+ if (errno == EINTR) {
+ st_mutex_lock();
+ if (ap->state == ST_SHUTDOWN) {
+ st_mutex_unlock();
+ return -1;
+ }
st_mutex_unlock();
continue;
}
-
- st_mutex_unlock();
-
- if (next_state == ST_SHUTDOWN)
- return -1;
+ estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ logerr("poll failed: %s", estr);
+ return -1;
}
if (fds[0].revents & POLLIN) {
@@ -1129,9 +1122,9 @@ static int get_pkt(struct autofs_point *
return read;
}
- if (fds[2].fd != -1 && fds[2].revents & POLLIN) {
+ if (fds[1].fd != -1 && fds[1].revents & POLLIN) {
debug(ap->logopt, "message pending on control fifo.");
- handle_fifo_message(ap, fds[2].fd);
+ handle_fifo_message(ap, fds[1].fd);
}
}
}
@@ -1191,15 +1184,6 @@ static int autofs_init_ap(struct autofs_
ap->pipefd = pipefd[0];
ap->kpipefd = pipefd[1];
- /* Pipe state changes from signal handler to main loop */
- if (open_pipe(ap->state_pipe) < 0) {
- crit(ap->logopt,
- "failed create state pipe for autofs path %s", ap->path);
- close(ap->pipefd);
- close(ap->kpipefd); /* Close kernel pipe end */
- return -1;
- }
-
if (create_logpri_fifo(ap) < 0) {
logmsg("could not create FIFO for path %s\n", ap->path);
logmsg("dynamic log level changes not available for %s", ap->path);
--- autofs-5.1.7.orig/daemon/direct.c
+++ autofs-5.1.7/daemon/direct.c
@@ -263,8 +263,6 @@ done:
}
pthread_cleanup_pop(1);
- close(ap->state_pipe[0]);
- close(ap->state_pipe[1]);
if (ap->pipefd >= 0)
close(ap->pipefd);
if (ap->kpipefd >= 0) {
--- autofs-5.1.7.orig/daemon/indirect.c
+++ autofs-5.1.7/daemon/indirect.c
@@ -152,8 +152,6 @@ out_rmdir:
out_err:
if (options)
free(options);
- close(ap->state_pipe[0]);
- close(ap->state_pipe[1]);
close(ap->pipefd);
close(ap->kpipefd);
@@ -216,11 +214,6 @@ void close_mount_fds(struct autofs_point
if (ap->submount)
lookup_source_close_ioctlfd(ap->parent, ap->path);
- close(ap->state_pipe[0]);
- close(ap->state_pipe[1]);
- ap->state_pipe[0] = -1;
- ap->state_pipe[1] = -1;
-
if (ap->pipefd >= 0)
close(ap->pipefd);
--- autofs-5.1.7.orig/daemon/master.c
+++ autofs-5.1.7/daemon/master.c
@@ -112,8 +112,6 @@ int master_add_autofs_point(struct maste
ap->state = ST_INIT;
- ap->state_pipe[0] = -1;
- ap->state_pipe[1] = -1;
ap->logpri_fifo = -1;
ap->path = strdup(entry->path);
@@ -1390,7 +1388,7 @@ static int master_do_mount(struct master
handle_mounts_startup_cond_destroy(&suc);
return 0;
}
- entry->thid = thid;
+ entry->thid = ap->thid = thid;
handle_mounts_startup_cond_destroy(&suc);
@@ -1474,9 +1472,6 @@ int master_mount_mounts(struct master *m
struct master_mapent *this;
struct autofs_point *ap;
struct mapent *ne, *nested;
- struct stat st;
- int state_pipe, save_errno;
- int ret;
this = list_entry(p, struct master_mapent, list);
p = p->next;
@@ -1533,19 +1528,9 @@ int master_mount_mounts(struct master *m
}
cache_unlock(nc);
cont:
- st_mutex_lock();
-
- state_pipe = this->ap->state_pipe[1];
-
- /* No pipe so mount is needed */
- ret = fstat(state_pipe, &st);
- save_errno = errno;
-
- st_mutex_unlock();
-
- if (!ret)
+ if (ap->thid && is_mounted(this->path, MNTS_AUTOFS))
check_update_map_sources(this, master->readall);
- else if (ret == -1 && save_errno == EBADF) {
+ else {
if (!master_do_mount(this)) {
list_del_init(&this->list);
master_free_mapent_sources(ap->entry, 1);
--- autofs-5.1.7.orig/daemon/state.c
+++ autofs-5.1.7/daemon/state.c
@@ -52,16 +52,6 @@ void st_mutex_unlock(void)
fatal(status);
}
-void nextstate(int statefd, enum states next)
-{
- char buf[MAX_ERR_BUF];
-
- if (write(statefd, &next, sizeof(next)) != sizeof(next)) {
- char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
- logerr("write failed %s", estr);
- }
-}
-
/*
* Handle expire thread cleanup and return the next state the system
* should enter as a result.
@@ -631,12 +621,16 @@ static unsigned int st_force_shutdown(st
static unsigned int st_shutdown(struct autofs_point *ap)
{
+ int ret;
+
debug(ap->logopt, "state %d path %s", ap->state, ap->path);
assert(ap->state == ST_SHUTDOWN_PENDING || ap->state == ST_SHUTDOWN_FORCE);
ap->state = ST_SHUTDOWN;
- nextstate(ap->state_pipe[1], ST_SHUTDOWN);
+ ret = pthread_kill(ap->thid, SIGCONT);
+ if (ret)
+ error(LOGOPT_ANY, "error %d sending shutdown signal", ret);
return 0;
}
--- autofs-5.1.7.orig/include/automount.h
+++ autofs-5.1.7/include/automount.h
@@ -564,7 +564,6 @@ struct autofs_point {
pthread_t exp_thread; /* Thread that is expiring */
pthread_t readmap_thread; /* Thread that is reading maps */
enum states state; /* Current state */
- int state_pipe[2]; /* State change router pipe */
struct autofs_point *parent; /* Owner of mounts list for submount */
struct list_head mounts; /* List of autofs mounts at current level */
unsigned int submount; /* Is this a submount */
--- autofs-5.1.7.orig/include/state.h
+++ autofs-5.1.7/include/state.h
@@ -86,7 +86,6 @@ void st_mutex_unlock(void);
void expire_cleanup(void *);
void expire_proc_cleanup(void *);
-void nextstate(int, enum states);
int st_add_task(struct autofs_point *, enum states);
int __st_add_task(struct autofs_point *, enum states);