|
|
9a499a |
autofs-5.1.6 - only add expire alarm for active mounts
|
|
|
9a499a |
|
|
|
9a499a |
From: Ian Kent <raven@themaw.net>
|
|
|
9a499a |
|
|
|
9a499a |
There's no need to add expire alarms for mount points that have no
|
|
|
9a499a |
expirable mounts.
|
|
|
9a499a |
|
|
|
9a499a |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
9a499a |
---
|
|
|
9a499a |
CHANGELOG | 1
|
|
|
9a499a |
daemon/automount.c | 9 +-------
|
|
|
9a499a |
daemon/direct.c | 3 ++
|
|
|
9a499a |
daemon/indirect.c | 3 ++
|
|
|
9a499a |
daemon/state.c | 25 +++++++++++-----------
|
|
|
9a499a |
include/automount.h | 1
|
|
|
9a499a |
include/mounts.h | 1
|
|
|
9a499a |
lib/alarm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++----
|
|
|
9a499a |
lib/mounts.c | 19 +++++++++++++++++
|
|
|
9a499a |
9 files changed, 96 insertions(+), 23 deletions(-)
|
|
|
9a499a |
|
|
|
9a499a |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
9a499a |
+++ autofs-5.1.4/CHANGELOG
|
|
|
9a499a |
@@ -131,6 +131,7 @@ xx/xx/2018 autofs-5.1.5
|
|
|
9a499a |
- use struct mnt_list to track mounted mounts.
|
|
|
9a499a |
- use struct mnt_list mounted list for expire.
|
|
|
9a499a |
- remove unused function tree_get_mnt_list().
|
|
|
9a499a |
+- only add expre alarm for active mounts.
|
|
|
9a499a |
|
|
|
9a499a |
19/12/2017 autofs-5.1.4
|
|
|
9a499a |
- fix spec file url.
|
|
|
9a499a |
--- autofs-5.1.4.orig/daemon/automount.c
|
|
|
9a499a |
+++ autofs-5.1.4/daemon/automount.c
|
|
|
9a499a |
@@ -1844,7 +1844,7 @@ int handle_mounts_exit(struct autofs_poi
|
|
|
9a499a |
|
|
|
9a499a |
if (ap->state != ST_SHUTDOWN) {
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
/* Return to ST_READY is done immediately */
|
|
|
9a499a |
st_add_task(ap, ST_READY);
|
|
|
9a499a |
if (ap->submount)
|
|
|
9a499a |
@@ -1889,7 +1889,7 @@ int handle_mounts_exit(struct autofs_poi
|
|
|
9a499a |
/* Failed shutdown returns to ready */
|
|
|
9a499a |
warn(ap->logopt, "can't shutdown: filesystem %s still busy", ap->path);
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
/* Return to ST_READY is done immediately */
|
|
|
9a499a |
st_add_task(ap, ST_READY);
|
|
|
9a499a |
if (ap->submount)
|
|
|
9a499a |
@@ -1952,11 +1952,6 @@ void *handle_mounts(void *arg)
|
|
|
9a499a |
suc->status = 0;
|
|
|
9a499a |
pthread_cleanup_pop(1);
|
|
|
9a499a |
|
|
|
9a499a |
- /* We often start several automounters at the same time. Add some
|
|
|
9a499a |
- randomness so we don't all expire at the same time. */
|
|
|
9a499a |
- if (!ap->submount && ap->exp_runfreq)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq + rand() % ap->exp_runfreq);
|
|
|
9a499a |
-
|
|
|
9a499a |
pthread_setcancelstate(cancel_state, NULL);
|
|
|
9a499a |
|
|
|
9a499a |
while (1) {
|
|
|
9a499a |
--- autofs-5.1.4.orig/daemon/direct.c
|
|
|
9a499a |
+++ autofs-5.1.4/daemon/direct.c
|
|
|
9a499a |
@@ -1245,6 +1245,9 @@ static void *do_mount_direct(void *arg)
|
|
|
9a499a |
info(ap->logopt, "mounted %s", mt.name);
|
|
|
9a499a |
|
|
|
9a499a |
mnts_set_mounted_mount(ap, mt.name);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (!ap->submount)
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
} else {
|
|
|
9a499a |
/* TODO: get mount return status from lookup_nss_mount */
|
|
|
9a499a |
ops->send_fail(ap->logopt,
|
|
|
9a499a |
--- autofs-5.1.4.orig/daemon/indirect.c
|
|
|
9a499a |
+++ autofs-5.1.4/daemon/indirect.c
|
|
|
9a499a |
@@ -753,6 +753,9 @@ static void *do_mount_indirect(void *arg
|
|
|
9a499a |
info(ap->logopt, "mounted %s", buf);
|
|
|
9a499a |
|
|
|
9a499a |
mnts_set_mounted_mount(ap, mt.name);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (!ap->submount)
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
} else {
|
|
|
9a499a |
/* TODO: get mount return status from lookup_nss_mount */
|
|
|
9a499a |
ops->send_fail(ap->logopt,
|
|
|
9a499a |
--- autofs-5.1.4.orig/daemon/state.c
|
|
|
9a499a |
+++ autofs-5.1.4/daemon/state.c
|
|
|
9a499a |
@@ -155,7 +155,7 @@ void expire_cleanup(void *arg)
|
|
|
9a499a |
ap->submount = 1;
|
|
|
9a499a |
|
|
|
9a499a |
if (ap->state == ST_EXPIRE && !ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
|
|
|
9a499a |
/* FALLTHROUGH */
|
|
|
9a499a |
|
|
|
9a499a |
@@ -173,7 +173,7 @@ void expire_cleanup(void *arg)
|
|
|
9a499a |
if (!rv && !idle && !ap->shutdown) {
|
|
|
9a499a |
next = ST_READY;
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
break;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
@@ -187,7 +187,7 @@ void expire_cleanup(void *arg)
|
|
|
9a499a |
/* Failed shutdown returns to ready */
|
|
|
9a499a |
warn(ap->logopt, "filesystem %s still busy", ap->path);
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
next = ST_READY;
|
|
|
9a499a |
break;
|
|
|
9a499a |
#endif
|
|
|
9a499a |
@@ -522,9 +522,10 @@ static void *do_readmap(void *arg)
|
|
|
9a499a |
* alarm will have been added. So add it here if there are
|
|
|
9a499a |
* now map entries.
|
|
|
9a499a |
*/
|
|
|
9a499a |
- if (append_alarm && ap->exp_runfreq)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq +
|
|
|
9a499a |
- rand() % ap->exp_runfreq);
|
|
|
9a499a |
+ if (append_alarm && ap->exp_runfreq) {
|
|
|
9a499a |
+ time_t seconds = ap->exp_runfreq + rand() % ap->exp_runfreq;
|
|
|
9a499a |
+ conditional_alarm_add(ap, seconds);
|
|
|
9a499a |
+ }
|
|
|
9a499a |
|
|
|
9a499a |
pthread_cleanup_pop(1);
|
|
|
9a499a |
pthread_cleanup_pop(1);
|
|
|
9a499a |
@@ -577,7 +578,7 @@ static unsigned int st_readmap(struct au
|
|
|
9a499a |
/* It didn't work: return to ready */
|
|
|
9a499a |
st_ready(ap);
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
return 0;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
@@ -604,7 +605,7 @@ static unsigned int st_readmap(struct au
|
|
|
9a499a |
/* It didn't work: return to ready */
|
|
|
9a499a |
st_ready(ap);
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
return 0;
|
|
|
9a499a |
}
|
|
|
9a499a |
ap->readmap_thread = thid;
|
|
|
9a499a |
@@ -640,7 +641,7 @@ static unsigned int st_prepare_shutdown(
|
|
|
9a499a |
case EXP_PARTIAL:
|
|
|
9a499a |
/* It didn't work: return to ready */
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
st_ready(ap);
|
|
|
9a499a |
return 0;
|
|
|
9a499a |
|
|
|
9a499a |
@@ -666,7 +667,7 @@ static unsigned int st_force_shutdown(st
|
|
|
9a499a |
case EXP_PARTIAL:
|
|
|
9a499a |
/* It didn't work: return to ready */
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
st_ready(ap);
|
|
|
9a499a |
return 0;
|
|
|
9a499a |
|
|
|
9a499a |
@@ -699,7 +700,7 @@ static unsigned int st_prune(struct auto
|
|
|
9a499a |
case EXP_ERROR:
|
|
|
9a499a |
case EXP_PARTIAL:
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
st_ready(ap);
|
|
|
9a499a |
return 0;
|
|
|
9a499a |
|
|
|
9a499a |
@@ -720,7 +721,7 @@ static unsigned int st_expire(struct aut
|
|
|
9a499a |
case EXP_ERROR:
|
|
|
9a499a |
case EXP_PARTIAL:
|
|
|
9a499a |
if (!ap->submount)
|
|
|
9a499a |
- alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
st_ready(ap);
|
|
|
9a499a |
return 0;
|
|
|
9a499a |
|
|
|
9a499a |
--- autofs-5.1.4.orig/include/automount.h
|
|
|
9a499a |
+++ autofs-5.1.4/include/automount.h
|
|
|
9a499a |
@@ -637,6 +637,7 @@ static inline time_t monotonic_time(time
|
|
|
9a499a |
/* Expire alarm handling routines */
|
|
|
9a499a |
int alarm_start_handler(void);
|
|
|
9a499a |
int alarm_add(struct autofs_point *ap, time_t seconds);
|
|
|
9a499a |
+int conditional_alarm_add(struct autofs_point *ap, time_t seconds);
|
|
|
9a499a |
void alarm_delete(struct autofs_point *ap);
|
|
|
9a499a |
|
|
|
9a499a |
#endif
|
|
|
9a499a |
--- autofs-5.1.4.orig/include/mounts.h
|
|
|
9a499a |
+++ autofs-5.1.4/include/mounts.h
|
|
|
9a499a |
@@ -125,6 +125,7 @@ void mnts_remove_amdmount(const char *mp
|
|
|
9a499a |
struct mnt_list *mnts_add_mount(struct autofs_point *ap, const char *name, unsigned int flags);
|
|
|
9a499a |
void mnts_remove_mount(const char *mp, unsigned int flags);
|
|
|
9a499a |
struct mnt_list *get_mnt_list(const char *path, int include);
|
|
|
9a499a |
+unsigned int mnts_has_mounted_mounts(struct autofs_point *ap);
|
|
|
9a499a |
void mnts_get_expire_list(struct list_head *mnts, struct autofs_point *ap);
|
|
|
9a499a |
void mnts_put_expire_list(struct list_head *mnts);
|
|
|
9a499a |
void mnts_set_mounted_mount(struct autofs_point *ap, const char *name);
|
|
|
9a499a |
--- autofs-5.1.4.orig/lib/alarm.c
|
|
|
9a499a |
+++ autofs-5.1.4/lib/alarm.c
|
|
|
9a499a |
@@ -41,7 +41,7 @@ do { \
|
|
|
9a499a |
} while (0)
|
|
|
9a499a |
|
|
|
9a499a |
/* Insert alarm entry on ordered list. */
|
|
|
9a499a |
-int alarm_add(struct autofs_point *ap, time_t seconds)
|
|
|
9a499a |
+int __alarm_add(struct autofs_point *ap, time_t seconds)
|
|
|
9a499a |
{
|
|
|
9a499a |
struct list_head *head;
|
|
|
9a499a |
struct list_head *p;
|
|
|
9a499a |
@@ -62,8 +62,6 @@ int alarm_add(struct autofs_point *ap, t
|
|
|
9a499a |
new->cancel = 0;
|
|
|
9a499a |
new->time = now + seconds;
|
|
|
9a499a |
|
|
|
9a499a |
- alarm_lock();
|
|
|
9a499a |
-
|
|
|
9a499a |
head = &alarms;
|
|
|
9a499a |
|
|
|
9a499a |
/* Check if we have a pending alarm */
|
|
|
9a499a |
@@ -97,9 +95,42 @@ int alarm_add(struct autofs_point *ap, t
|
|
|
9a499a |
fatal(status);
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
+ return 1;
|
|
|
9a499a |
+}
|
|
|
9a499a |
+
|
|
|
9a499a |
+int alarm_add(struct autofs_point *ap, time_t seconds)
|
|
|
9a499a |
+{
|
|
|
9a499a |
+ int status;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ alarm_lock();
|
|
|
9a499a |
+ status = __alarm_add(ap, seconds);
|
|
|
9a499a |
alarm_unlock();
|
|
|
9a499a |
|
|
|
9a499a |
- return 1;
|
|
|
9a499a |
+ return status;
|
|
|
9a499a |
+}
|
|
|
9a499a |
+
|
|
|
9a499a |
+static int __alarm_exists(struct autofs_point *ap)
|
|
|
9a499a |
+{
|
|
|
9a499a |
+ struct list_head *head;
|
|
|
9a499a |
+ struct list_head *p;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ head = &alarms;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (list_empty(head))
|
|
|
9a499a |
+ return 0;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ p = head->next;
|
|
|
9a499a |
+ while (p != head) {
|
|
|
9a499a |
+ struct alarm *this;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ this = list_entry(p, struct alarm, list);
|
|
|
9a499a |
+ p = p->next;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (ap == this->ap)
|
|
|
9a499a |
+ return 1;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+
|
|
|
9a499a |
+ return 0;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
void alarm_delete(struct autofs_point *ap)
|
|
|
9a499a |
@@ -152,6 +183,24 @@ void alarm_delete(struct autofs_point *a
|
|
|
9a499a |
return;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
+int conditional_alarm_add(struct autofs_point *ap, time_t seconds)
|
|
|
9a499a |
+{
|
|
|
9a499a |
+ int status;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (!mnts_has_mounted_mounts(ap))
|
|
|
9a499a |
+ return 1;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ alarm_lock();
|
|
|
9a499a |
+ if (__alarm_exists(ap)) {
|
|
|
9a499a |
+ alarm_unlock();
|
|
|
9a499a |
+ return 1;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+ status = __alarm_add(ap, seconds);
|
|
|
9a499a |
+ alarm_unlock();
|
|
|
9a499a |
+
|
|
|
9a499a |
+ return status;
|
|
|
9a499a |
+}
|
|
|
9a499a |
+
|
|
|
9a499a |
static void *alarm_handler(void *arg)
|
|
|
9a499a |
{
|
|
|
9a499a |
struct list_head *head;
|
|
|
9a499a |
--- autofs-5.1.4.orig/lib/mounts.c
|
|
|
9a499a |
+++ autofs-5.1.4/lib/mounts.c
|
|
|
9a499a |
@@ -1208,6 +1208,19 @@ void mnts_set_mounted_mount(struct autof
|
|
|
9a499a |
}
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
+unsigned int mnts_has_mounted_mounts(struct autofs_point *ap)
|
|
|
9a499a |
+{
|
|
|
9a499a |
+ unsigned int has_mounted_mounts = 0;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ mnts_hash_mutex_lock();
|
|
|
9a499a |
+ if (list_empty(&ap->mounts))
|
|
|
9a499a |
+ goto done;
|
|
|
9a499a |
+ has_mounted_mounts = 1;
|
|
|
9a499a |
+done:
|
|
|
9a499a |
+ mnts_hash_mutex_unlock();
|
|
|
9a499a |
+ return has_mounted_mounts;
|
|
|
9a499a |
+}
|
|
|
9a499a |
+
|
|
|
9a499a |
struct node {
|
|
|
9a499a |
struct mnt_list *mnt;
|
|
|
9a499a |
struct node *left;
|
|
|
9a499a |
@@ -1907,6 +1920,9 @@ static int do_remount_direct(struct auto
|
|
|
9a499a |
mnts_set_mounted_mount(ap, path);
|
|
|
9a499a |
|
|
|
9a499a |
info(ap->logopt, "re-connected to %s", path);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (!ap->submount)
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
} else {
|
|
|
9a499a |
status = REMOUNT_FAIL;
|
|
|
9a499a |
info(ap->logopt, "failed to re-connect %s", path);
|
|
|
9a499a |
@@ -1980,6 +1996,9 @@ static int do_remount_indirect(struct au
|
|
|
9a499a |
mnts_set_mounted_mount(ap, buf);
|
|
|
9a499a |
|
|
|
9a499a |
info(ap->logopt, "re-connected to %s", buf);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (!ap->submount)
|
|
|
9a499a |
+ conditional_alarm_add(ap, ap->exp_runfreq);
|
|
|
9a499a |
} else {
|
|
|
9a499a |
status = REMOUNT_FAIL;
|
|
|
9a499a |
info(ap->logopt, "failed to re-connect %s", buf);
|