autofs-5.1.6 - move submount check into conditional_alarm_add()

From: Ian Kent <raven@themaw.net>

The expire of submounts is driven by the top level autofs mount in the
mount tree so an expire alarm doesn't need to set if the autofs point
is a submount.

Take that check into conditional_alarm_add().

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG          |    1 +
 daemon/automount.c |    6 ++----
 daemon/direct.c    |    3 +--
 daemon/indirect.c  |    3 +--
 daemon/state.c     |   26 +++++++++-----------------
 lib/alarm.c        |    2 ++
 lib/mounts.c       |    6 ++----
 7 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 536648e5..d12a9cad 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -66,6 +66,7 @@ xx/xx/2020 autofs-5.1.7
 - use struct mnt_list mounted list for expire.
 - remove unused function tree_get_mnt_list().
 - only add expre alarm for active mounts.
+- move submount check into conditional_alarm_add().
 
 07/10/2019 autofs-5.1.6
 - support strictexpire mount option.
diff --git a/daemon/automount.c b/daemon/automount.c
index a65428b5..559378bf 100644
--- a/daemon/automount.c
+++ b/daemon/automount.c
@@ -1844,8 +1844,7 @@ int handle_mounts_exit(struct autofs_point *ap)
 	}
 
 	if (ap->state != ST_SHUTDOWN) {
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 		/* Return to ST_READY is done immediately */
 		st_add_task(ap, ST_READY);
 		if (ap->submount)
@@ -1889,8 +1888,7 @@ int handle_mounts_exit(struct autofs_point *ap)
 
 	/* Failed shutdown returns to ready */
 	warn(ap->logopt, "can't shutdown: filesystem %s still busy", ap->path);
-	if (!ap->submount)
-		conditional_alarm_add(ap, ap->exp_runfreq);
+	conditional_alarm_add(ap, ap->exp_runfreq);
 	/* Return to ST_READY is done immediately */
 	st_add_task(ap, ST_READY);
 	if (ap->submount)
diff --git a/daemon/direct.c b/daemon/direct.c
index cddf559f..9fe4903a 100644
--- a/daemon/direct.c
+++ b/daemon/direct.c
@@ -1246,8 +1246,7 @@ static void *do_mount_direct(void *arg)
 
 		mnts_set_mounted_mount(ap, mt.name);
 
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 	} else {
 		/* TODO: get mount return status from lookup_nss_mount */
 		ops->send_fail(ap->logopt,
diff --git a/daemon/indirect.c b/daemon/indirect.c
index db45c380..65cfe4e3 100644
--- a/daemon/indirect.c
+++ b/daemon/indirect.c
@@ -754,8 +754,7 @@ static void *do_mount_indirect(void *arg)
 
 		mnts_set_mounted_mount(ap, mt.name);
 
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 	} else {
 		/* TODO: get mount return status from lookup_nss_mount */
 		ops->send_fail(ap->logopt,
diff --git a/daemon/state.c b/daemon/state.c
index 5200dfcb..091210a5 100644
--- a/daemon/state.c
+++ b/daemon/state.c
@@ -130,7 +130,7 @@ void expire_cleanup(void *arg)
 			} else if (ap->submount > 1)
 				ap->submount = 1;
 
-			if (ap->state == ST_EXPIRE && !ap->submount)
+			if (ap->state == ST_EXPIRE)
 				conditional_alarm_add(ap, ap->exp_runfreq);
 
 			/* FALLTHROUGH */
@@ -148,8 +148,7 @@ void expire_cleanup(void *arg)
 			rv = ops->askumount(ap->logopt, ap->ioctlfd, &idle);
 			if (!rv && !idle && !ap->shutdown) {
 				next = ST_READY;
-				if (!ap->submount)
-					conditional_alarm_add(ap, ap->exp_runfreq);
+				conditional_alarm_add(ap, ap->exp_runfreq);
 				break;
 			}
 
@@ -162,8 +161,7 @@ void expire_cleanup(void *arg)
 
 			/* Failed shutdown returns to ready */
 			warn(ap->logopt, "filesystem %s still busy", ap->path);
-			if (!ap->submount)
-				conditional_alarm_add(ap, ap->exp_runfreq);
+			conditional_alarm_add(ap, ap->exp_runfreq);
 			next = ST_READY;
 			break;
 #endif
@@ -553,8 +551,7 @@ static unsigned int st_readmap(struct autofs_point *ap)
 		error(ap->logopt, "failed to malloc readmap cond struct");
 		/* It didn't work: return to ready */
 		st_ready(ap);
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 		return 0;
 	}
 
@@ -580,8 +577,7 @@ static unsigned int st_readmap(struct autofs_point *ap)
 		free(ra);
 		/* It didn't work: return to ready */
 		st_ready(ap);
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 		return 0;
 	}
 	ap->readmap_thread = thid;
@@ -616,8 +612,7 @@ static unsigned int st_prepare_shutdown(struct autofs_point *ap)
 	case EXP_ERROR:
 	case EXP_PARTIAL:
 		/* It didn't work: return to ready */
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 		st_ready(ap);
 		return 0;
 
@@ -642,8 +637,7 @@ static unsigned int st_force_shutdown(struct autofs_point *ap)
 	case EXP_ERROR:
 	case EXP_PARTIAL:
 		/* It didn't work: return to ready */
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 		st_ready(ap);
 		return 0;
 
@@ -675,8 +669,7 @@ static unsigned int st_prune(struct autofs_point *ap)
 	switch (expire_proc(ap, AUTOFS_EXP_IMMEDIATE)) {
 	case EXP_ERROR:
 	case EXP_PARTIAL:
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 		st_ready(ap);
 		return 0;
 
@@ -696,8 +689,7 @@ static unsigned int st_expire(struct autofs_point *ap)
 	switch (expire_proc(ap, AUTOFS_EXP_NORMAL)) {
 	case EXP_ERROR:
 	case EXP_PARTIAL:
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 		st_ready(ap);
 		return 0;
 
diff --git a/lib/alarm.c b/lib/alarm.c
index 6ab4a49d..f27e13c4 100755
--- a/lib/alarm.c
+++ b/lib/alarm.c
@@ -187,6 +187,8 @@ int conditional_alarm_add(struct autofs_point *ap, time_t seconds)
 {
 	int status;
 
+	if (ap->submount)
+		return 1;
 	if (!mnts_has_mounted_mounts(ap))
 		return 1;
 
diff --git a/lib/mounts.c b/lib/mounts.c
index e5e9c195..e15e6da2 100644
--- a/lib/mounts.c
+++ b/lib/mounts.c
@@ -1921,8 +1921,7 @@ static int do_remount_direct(struct autofs_point *ap,
 
 		info(ap->logopt, "re-connected to %s", path);
 
-		if (!ap->submount)
-			conditional_alarm_add(ap, ap->exp_runfreq);
+		conditional_alarm_add(ap, ap->exp_runfreq);
 	} else {
 		status = REMOUNT_FAIL;
 		info(ap->logopt, "failed to re-connect %s", path);
@@ -1997,8 +1996,7 @@ static int do_remount_indirect(struct autofs_point *ap, const unsigned int type,
 
 			info(ap->logopt, "re-connected to %s", buf);
 
-			if (!ap->submount)
-				conditional_alarm_add(ap, ap->exp_runfreq);
+			conditional_alarm_add(ap, ap->exp_runfreq);
 		} else {
 			status = REMOUNT_FAIL;
 			info(ap->logopt, "failed to re-connect %s", buf);
