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