|
|
beb904 |
autofs-5.1.6 - use struct mnt_list mounted list for expire
|
|
|
beb904 |
|
|
|
beb904 |
From: Ian Kent <raven@themaw.net>
|
|
|
beb904 |
|
|
|
beb904 |
Now we are keeping track of mounted mounts using the mnt_list struct
|
|
|
beb904 |
use it to drive the expire instead of using the system mount table.
|
|
|
beb904 |
|
|
|
beb904 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
beb904 |
---
|
|
|
beb904 |
CHANGELOG | 1
|
|
|
beb904 |
daemon/direct.c | 61 +++++++----------
|
|
|
beb904 |
daemon/indirect.c | 66 +++++++++----------
|
|
|
beb904 |
include/mounts.h | 5 -
|
|
|
beb904 |
lib/master.c | 36 +---------
|
|
|
beb904 |
lib/mounts.c | 185 ++++++++++++++++++++++++++++++++++++++++++++++--------
|
|
|
beb904 |
6 files changed, 223 insertions(+), 131 deletions(-)
|
|
|
beb904 |
|
|
|
beb904 |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
beb904 |
+++ autofs-5.1.4/CHANGELOG
|
|
|
beb904 |
@@ -129,6 +129,7 @@ xx/xx/2018 autofs-5.1.5
|
|
|
beb904 |
- fix remount expire.
|
|
|
beb904 |
- fix stale offset directories disable mount.
|
|
|
beb904 |
- use struct mnt_list to track mounted mounts.
|
|
|
beb904 |
+- use struct mnt_list mounted list for expire.
|
|
|
beb904 |
|
|
|
beb904 |
19/12/2017 autofs-5.1.4
|
|
|
beb904 |
- fix spec file url.
|
|
|
beb904 |
--- autofs-5.1.4.orig/daemon/direct.c
|
|
|
beb904 |
+++ autofs-5.1.4/daemon/direct.c
|
|
|
beb904 |
@@ -77,9 +77,8 @@ static void key_mnt_params_init(void)
|
|
|
beb904 |
|
|
|
beb904 |
static void mnts_cleanup(void *arg)
|
|
|
beb904 |
{
|
|
|
beb904 |
- struct mnt_list *mnts = (struct mnt_list *) arg;
|
|
|
beb904 |
- tree_free_mnt_tree(mnts);
|
|
|
beb904 |
- return;
|
|
|
beb904 |
+ struct list_head *mnts = (struct list_head *) arg;
|
|
|
beb904 |
+ mnts_put_expire_list(mnts);
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
int do_umount_autofs_direct(struct autofs_point *ap, struct mapent *me)
|
|
|
beb904 |
@@ -788,8 +787,8 @@ out_err:
|
|
|
beb904 |
void *expire_proc_direct(void *arg)
|
|
|
beb904 |
{
|
|
|
beb904 |
struct ioctl_ops *ops = get_ioctl_ops();
|
|
|
beb904 |
- struct mnt_list *mnts = NULL, *next;
|
|
|
beb904 |
- struct list_head list, *p;
|
|
|
beb904 |
+ struct mnt_list *mnt;
|
|
|
beb904 |
+ LIST_HEAD(mnts);
|
|
|
beb904 |
struct expire_args *ea;
|
|
|
beb904 |
struct expire_args ec;
|
|
|
beb904 |
struct autofs_point *ap;
|
|
|
beb904 |
@@ -821,31 +820,24 @@ void *expire_proc_direct(void *arg)
|
|
|
beb904 |
|
|
|
beb904 |
left = 0;
|
|
|
beb904 |
|
|
|
beb904 |
- mnts = tree_make_mnt_tree("/");
|
|
|
beb904 |
- pthread_cleanup_push(mnts_cleanup, mnts);
|
|
|
beb904 |
-
|
|
|
beb904 |
- /* Get a list of mounts select real ones and expire them if possible */
|
|
|
beb904 |
- INIT_LIST_HEAD(&list);
|
|
|
beb904 |
- if (!tree_get_mnt_list(mnts, &list, "/", 0)) {
|
|
|
beb904 |
- ec.status = 0;
|
|
|
beb904 |
- return NULL;
|
|
|
beb904 |
- }
|
|
|
beb904 |
-
|
|
|
beb904 |
- list_for_each(p, &list) {
|
|
|
beb904 |
- next = list_entry(p, struct mnt_list, list);
|
|
|
beb904 |
-
|
|
|
beb904 |
+ /* Get the list of real mounts and expire them if possible */
|
|
|
beb904 |
+ mnts_get_expire_list(&mnts, ap);
|
|
|
beb904 |
+ if (list_empty(&mnts))
|
|
|
beb904 |
+ goto done;
|
|
|
beb904 |
+ pthread_cleanup_push(mnts_cleanup, &mnts);
|
|
|
beb904 |
+ list_for_each_entry(mnt, &mnts, expire) {
|
|
|
beb904 |
/*
|
|
|
beb904 |
* All direct mounts must be present in the map
|
|
|
beb904 |
* entry cache.
|
|
|
beb904 |
*/
|
|
|
beb904 |
pthread_cleanup_push(master_source_lock_cleanup, ap->entry);
|
|
|
beb904 |
master_source_readlock(ap->entry);
|
|
|
beb904 |
- me = lookup_source_mapent(ap, next->mp, LKP_DISTINCT);
|
|
|
beb904 |
+ me = lookup_source_mapent(ap, mnt->mp, LKP_DISTINCT);
|
|
|
beb904 |
pthread_cleanup_pop(1);
|
|
|
beb904 |
if (!me)
|
|
|
beb904 |
continue;
|
|
|
beb904 |
|
|
|
beb904 |
- if (next->flags & MNTS_AUTOFS) {
|
|
|
beb904 |
+ if (mnt->flags & (MNTS_AUTOFS|MNTS_OFFSET)) {
|
|
|
beb904 |
struct stat st;
|
|
|
beb904 |
int ioctlfd;
|
|
|
beb904 |
|
|
|
beb904 |
@@ -856,22 +848,17 @@ void *expire_proc_direct(void *arg)
|
|
|
beb904 |
* one of them and pass on state change.
|
|
|
beb904 |
*/
|
|
|
beb904 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
beb904 |
- if (next->flags & MNTS_INDIRECT) {
|
|
|
beb904 |
- master_notify_submount(ap, next->mp, ap->state);
|
|
|
beb904 |
- pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
- continue;
|
|
|
beb904 |
- }
|
|
|
beb904 |
+ if (mnt->flags & MNTS_AUTOFS)
|
|
|
beb904 |
+ master_notify_submount(ap, mnt->mp, ap->state);
|
|
|
beb904 |
|
|
|
beb904 |
if (me->ioctlfd == -1) {
|
|
|
beb904 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
continue;
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
- /* It's got a mount, deal with in the outer loop */
|
|
|
beb904 |
- if (is_mounted(me->key, MNTS_REAL)) {
|
|
|
beb904 |
- pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
- continue;
|
|
|
beb904 |
- }
|
|
|
beb904 |
+ /* It's got a mount, just send the expire. */
|
|
|
beb904 |
+ if (is_mounted(me->key, MNTS_REAL))
|
|
|
beb904 |
+ goto cont;
|
|
|
beb904 |
|
|
|
beb904 |
/*
|
|
|
beb904 |
* Maybe a manual umount, repair.
|
|
|
beb904 |
@@ -888,19 +875,19 @@ void *expire_proc_direct(void *arg)
|
|
|
beb904 |
cache_writelock(me->mc);
|
|
|
beb904 |
if (me->ioctlfd != -1 &&
|
|
|
beb904 |
fstat(me->ioctlfd, &st) != -1 &&
|
|
|
beb904 |
- !count_mounts(ap, next->mp, st.st_dev)) {
|
|
|
beb904 |
+ !count_mounts(ap, mnt->mp, st.st_dev)) {
|
|
|
beb904 |
ops->close(ap->logopt, me->ioctlfd);
|
|
|
beb904 |
me->ioctlfd = -1;
|
|
|
beb904 |
cache_unlock(me->mc);
|
|
|
beb904 |
- mnts_remove_mount(next->mp, MNTS_MOUNTED);
|
|
|
beb904 |
+ mnts_remove_mount(mnt->mp, MNTS_MOUNTED);
|
|
|
beb904 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
continue;
|
|
|
beb904 |
}
|
|
|
beb904 |
cache_unlock(me->mc);
|
|
|
beb904 |
-
|
|
|
beb904 |
+cont:
|
|
|
beb904 |
ioctlfd = me->ioctlfd;
|
|
|
beb904 |
|
|
|
beb904 |
- ret = ops->expire(ap->logopt, ioctlfd, next->mp, how);
|
|
|
beb904 |
+ ret = ops->expire(ap->logopt, ioctlfd, mnt->mp, how);
|
|
|
beb904 |
if (ret) {
|
|
|
beb904 |
left++;
|
|
|
beb904 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
@@ -923,10 +910,10 @@ void *expire_proc_direct(void *arg)
|
|
|
beb904 |
if (ap->state == ST_EXPIRE || ap->state == ST_PRUNE)
|
|
|
beb904 |
pthread_testcancel();
|
|
|
beb904 |
|
|
|
beb904 |
- debug(ap->logopt, "send expire to trigger %s", next->mp);
|
|
|
beb904 |
+ debug(ap->logopt, "send expire to trigger %s", mnt->mp);
|
|
|
beb904 |
|
|
|
beb904 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
beb904 |
- ret = ops->expire(ap->logopt, ioctlfd, next->mp, how);
|
|
|
beb904 |
+ ret = ops->expire(ap->logopt, ioctlfd, mnt->mp, how);
|
|
|
beb904 |
if (ret)
|
|
|
beb904 |
left++;
|
|
|
beb904 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
@@ -935,7 +922,7 @@ void *expire_proc_direct(void *arg)
|
|
|
beb904 |
|
|
|
beb904 |
if (left)
|
|
|
beb904 |
debug(ap->logopt, "%d remaining in %s", left, ap->path);
|
|
|
beb904 |
-
|
|
|
beb904 |
+done:
|
|
|
beb904 |
ec.status = left;
|
|
|
beb904 |
|
|
|
beb904 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
beb904 |
--- autofs-5.1.4.orig/daemon/indirect.c
|
|
|
beb904 |
+++ autofs-5.1.4/daemon/indirect.c
|
|
|
beb904 |
@@ -343,17 +343,17 @@ force_umount:
|
|
|
beb904 |
|
|
|
beb904 |
static void mnts_cleanup(void *arg)
|
|
|
beb904 |
{
|
|
|
beb904 |
- struct mnt_list *mnts = (struct mnt_list *) arg;
|
|
|
beb904 |
- free_mnt_list(mnts);
|
|
|
beb904 |
- return;
|
|
|
beb904 |
+ struct list_head *mnts = (struct list_head *) arg;
|
|
|
beb904 |
+ mnts_put_expire_list(mnts);
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
void *expire_proc_indirect(void *arg)
|
|
|
beb904 |
{
|
|
|
beb904 |
struct ioctl_ops *ops = get_ioctl_ops();
|
|
|
beb904 |
struct autofs_point *ap;
|
|
|
beb904 |
- struct mapent *me = NULL;
|
|
|
beb904 |
- struct mnt_list *mnts = NULL, *next;
|
|
|
beb904 |
+ struct mnt_list *mnt;
|
|
|
beb904 |
+ LIST_HEAD(mnts);
|
|
|
beb904 |
+ struct mapent *me;
|
|
|
beb904 |
struct expire_args *ea;
|
|
|
beb904 |
struct expire_args ec;
|
|
|
beb904 |
unsigned int how;
|
|
|
beb904 |
@@ -385,36 +385,34 @@ void *expire_proc_indirect(void *arg)
|
|
|
beb904 |
|
|
|
beb904 |
left = 0;
|
|
|
beb904 |
|
|
|
beb904 |
- /* Get a list of real mounts and expire them if possible */
|
|
|
beb904 |
- mnts = get_mnt_list(ap->path, 0);
|
|
|
beb904 |
- pthread_cleanup_push(mnts_cleanup, mnts);
|
|
|
beb904 |
- for (next = mnts; next; next = next->next) {
|
|
|
beb904 |
+ /* Get the list of real mounts and expire them if possible */
|
|
|
beb904 |
+ mnts_get_expire_list(&mnts, ap);
|
|
|
beb904 |
+ if (list_empty(&mnts))
|
|
|
beb904 |
+ goto done;
|
|
|
beb904 |
+ pthread_cleanup_push(mnts_cleanup, &mnts);
|
|
|
beb904 |
+ list_for_each_entry(mnt, &mnts, expire) {
|
|
|
beb904 |
char *ind_key;
|
|
|
beb904 |
int ret;
|
|
|
beb904 |
|
|
|
beb904 |
- if (next->flags & MNTS_AUTOFS) {
|
|
|
beb904 |
+ if (mnt->flags & (MNTS_AUTOFS|MNTS_OFFSET)) {
|
|
|
beb904 |
/*
|
|
|
beb904 |
* If we have submounts check if this path lives below
|
|
|
beb904 |
* one of them and pass on the state change.
|
|
|
beb904 |
*/
|
|
|
beb904 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
beb904 |
- if (next->flags & MNTS_INDIRECT)
|
|
|
beb904 |
- master_notify_submount(ap, next->mp, ap->state);
|
|
|
beb904 |
- else if (next->flags & MNTS_OFFSET) {
|
|
|
beb904 |
+ if (mnt->flags & MNTS_AUTOFS)
|
|
|
beb904 |
+ master_notify_submount(ap, mnt->mp, ap->state);
|
|
|
beb904 |
+
|
|
|
beb904 |
+ /* An offset without a real mount, check for manual umount */
|
|
|
beb904 |
+ if (mnt->flags & MNTS_OFFSET &&
|
|
|
beb904 |
+ !is_mounted(mnt->mp, MNTS_REAL)) {
|
|
|
beb904 |
struct mnt_list *sbmnt;
|
|
|
beb904 |
struct map_source *map;
|
|
|
beb904 |
struct mapent_cache *mc = NULL;
|
|
|
beb904 |
- struct mapent *me = NULL;
|
|
|
beb904 |
struct stat st;
|
|
|
beb904 |
|
|
|
beb904 |
- /* It's got a mount, deal with in the outer loop */
|
|
|
beb904 |
- if (is_mounted(next->mp, MNTS_REAL)) {
|
|
|
beb904 |
- pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
- continue;
|
|
|
beb904 |
- }
|
|
|
beb904 |
-
|
|
|
beb904 |
/* Don't touch submounts */
|
|
|
beb904 |
- sbmnt = mnts_find_submount(next->mp);
|
|
|
beb904 |
+ sbmnt = mnts_find_submount(mnt->mp);
|
|
|
beb904 |
if (sbmnt) {
|
|
|
beb904 |
mnts_put_mount(sbmnt);
|
|
|
beb904 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
@@ -427,7 +425,7 @@ void *expire_proc_indirect(void *arg)
|
|
|
beb904 |
while (map) {
|
|
|
beb904 |
mc = map->mc;
|
|
|
beb904 |
cache_writelock(mc);
|
|
|
beb904 |
- me = cache_lookup_distinct(mc, next->mp);
|
|
|
beb904 |
+ me = cache_lookup_distinct(mc, mnt->mp);
|
|
|
beb904 |
if (me)
|
|
|
beb904 |
break;
|
|
|
beb904 |
cache_unlock(mc);
|
|
|
beb904 |
@@ -456,10 +454,10 @@ void *expire_proc_indirect(void *arg)
|
|
|
beb904 |
|
|
|
beb904 |
cache_unlock(mc);
|
|
|
beb904 |
master_source_unlock(ap->entry);
|
|
|
beb904 |
+ pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
+ continue;
|
|
|
beb904 |
}
|
|
|
beb904 |
-
|
|
|
beb904 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
- continue;
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
if (ap->state == ST_EXPIRE || ap->state == ST_PRUNE)
|
|
|
beb904 |
@@ -469,7 +467,7 @@ void *expire_proc_indirect(void *arg)
|
|
|
beb904 |
* If the mount corresponds to an offset trigger then
|
|
|
beb904 |
* the key is the path, otherwise it's the last component.
|
|
|
beb904 |
*/
|
|
|
beb904 |
- ind_key = strrchr(next->mp, '/');
|
|
|
beb904 |
+ ind_key = strrchr(mnt->mp, '/');
|
|
|
beb904 |
if (ind_key)
|
|
|
beb904 |
ind_key++;
|
|
|
beb904 |
|
|
|
beb904 |
@@ -482,7 +480,7 @@ void *expire_proc_indirect(void *arg)
|
|
|
beb904 |
*/
|
|
|
beb904 |
pthread_cleanup_push(master_source_lock_cleanup, ap->entry);
|
|
|
beb904 |
master_source_readlock(ap->entry);
|
|
|
beb904 |
- me = lookup_source_mapent(ap, next->mp, LKP_DISTINCT);
|
|
|
beb904 |
+ me = lookup_source_mapent(ap, mnt->mp, LKP_DISTINCT);
|
|
|
beb904 |
if (!me && ind_key)
|
|
|
beb904 |
me = lookup_source_mapent(ap, ind_key, LKP_NORMAL);
|
|
|
beb904 |
pthread_cleanup_pop(1);
|
|
|
beb904 |
@@ -494,10 +492,10 @@ void *expire_proc_indirect(void *arg)
|
|
|
beb904 |
cache_unlock(me->mc);
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
- debug(ap->logopt, "expire %s", next->mp);
|
|
|
beb904 |
+ debug(ap->logopt, "expire %s", mnt->mp);
|
|
|
beb904 |
|
|
|
beb904 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
beb904 |
- ret = ops->expire(ap->logopt, ioctlfd, next->mp, how);
|
|
|
beb904 |
+ ret = ops->expire(ap->logopt, ioctlfd, mnt->mp, how);
|
|
|
beb904 |
if (ret)
|
|
|
beb904 |
left++;
|
|
|
beb904 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
beb904 |
@@ -519,14 +517,14 @@ void *expire_proc_indirect(void *arg)
|
|
|
beb904 |
pthread_cleanup_pop(1);
|
|
|
beb904 |
|
|
|
beb904 |
count = offsets = submnts = 0;
|
|
|
beb904 |
- mnts = get_mnt_list(ap->path, 0);
|
|
|
beb904 |
- pthread_cleanup_push(mnts_cleanup, mnts);
|
|
|
beb904 |
+ mnts_get_expire_list(&mnts, ap);
|
|
|
beb904 |
+ pthread_cleanup_push(mnts_cleanup, &mnts);
|
|
|
beb904 |
/* Are there any real mounts left */
|
|
|
beb904 |
- for (next = mnts; next; next = next->next) {
|
|
|
beb904 |
- if (!(next->flags & MNTS_AUTOFS))
|
|
|
beb904 |
+ list_for_each_entry(mnt, &mnts, expire) {
|
|
|
beb904 |
+ if (!(mnt->flags & MNTS_AUTOFS))
|
|
|
beb904 |
count++;
|
|
|
beb904 |
else {
|
|
|
beb904 |
- if (next->flags & MNTS_INDIRECT)
|
|
|
beb904 |
+ if (mnt->flags & MNTS_INDIRECT)
|
|
|
beb904 |
submnts++;
|
|
|
beb904 |
else
|
|
|
beb904 |
offsets++;
|
|
|
beb904 |
@@ -544,7 +542,7 @@ void *expire_proc_indirect(void *arg)
|
|
|
beb904 |
*/
|
|
|
beb904 |
if (count)
|
|
|
beb904 |
debug(ap->logopt, "%d remaining in %s", count, ap->path);
|
|
|
beb904 |
-
|
|
|
beb904 |
+done:
|
|
|
beb904 |
ec.status = left;
|
|
|
beb904 |
|
|
|
beb904 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
beb904 |
--- autofs-5.1.4.orig/include/mounts.h
|
|
|
beb904 |
+++ autofs-5.1.4/include/mounts.h
|
|
|
beb904 |
@@ -63,6 +63,8 @@ struct mnt_list {
|
|
|
beb904 |
|
|
|
beb904 |
/* List of mounts of an autofs_point */
|
|
|
beb904 |
struct list_head mount;
|
|
|
beb904 |
+ /* Mounted mounts list for expire */
|
|
|
beb904 |
+ struct list_head expire;
|
|
|
beb904 |
|
|
|
beb904 |
/* List of sub-mounts of an autofs_point */
|
|
|
beb904 |
struct autofs_point *ap;
|
|
|
beb904 |
@@ -129,15 +131,12 @@ void mnts_put_mount(struct mnt_list *mnt
|
|
|
beb904 |
struct mnt_list *mnts_find_submount(const char *path);
|
|
|
beb904 |
struct mnt_list *mnts_add_submount(struct autofs_point *ap);
|
|
|
beb904 |
void mnts_remove_submount(const char *mp);
|
|
|
beb904 |
-void mnts_get_submount_list(struct list_head *mnts, struct autofs_point *ap);
|
|
|
beb904 |
-void mnts_put_submount_list(struct list_head *mnts);
|
|
|
beb904 |
struct mnt_list *mnts_find_amdmount(const char *path);
|
|
|
beb904 |
struct mnt_list *mnts_add_amdmount(struct autofs_point *ap, struct amd_entry *entry);
|
|
|
beb904 |
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/master.c
|
|
|
beb904 |
+++ autofs-5.1.4/lib/master.c
|
|
|
beb904 |
@@ -1133,40 +1133,17 @@ int master_submount_list_empty(struct au
|
|
|
beb904 |
int master_notify_submount(struct autofs_point *ap, const char *path, enum states state)
|
|
|
beb904 |
{
|
|
|
beb904 |
struct mnt_list *this, *sbmnt;
|
|
|
beb904 |
- LIST_HEAD(sbmnts);
|
|
|
beb904 |
int ret = 1;
|
|
|
beb904 |
|
|
|
beb904 |
- mnts_get_submount_list(&sbmnts, ap);
|
|
|
beb904 |
- if (list_empty(&sbmnts))
|
|
|
beb904 |
- return 1;
|
|
|
beb904 |
-
|
|
|
beb904 |
- list_for_each_entry(this, &sbmnts, submount_work) {
|
|
|
beb904 |
- /* Not a submount */
|
|
|
beb904 |
- if (!(this->flags & MNTS_AUTOFS))
|
|
|
beb904 |
- continue;
|
|
|
beb904 |
-
|
|
|
beb904 |
- /* path not the same */
|
|
|
beb904 |
- if (strcmp(this->mp, path))
|
|
|
beb904 |
- continue;
|
|
|
beb904 |
-
|
|
|
beb904 |
- if (!master_submount_list_empty(this->ap)) {
|
|
|
beb904 |
- struct mnt_list *sm;
|
|
|
beb904 |
-
|
|
|
beb904 |
- master_notify_submount(this->ap, path, state);
|
|
|
beb904 |
- sm = mnts_find_submount(path);
|
|
|
beb904 |
- if (!sm)
|
|
|
beb904 |
- continue;
|
|
|
beb904 |
- mnts_put_mount(sm);
|
|
|
beb904 |
- }
|
|
|
beb904 |
-
|
|
|
beb904 |
- /* Now we have found the submount we want to expire */
|
|
|
beb904 |
-
|
|
|
beb904 |
+ this = mnts_find_submount(path);
|
|
|
beb904 |
+ if (this) {
|
|
|
beb904 |
+ /* We have found a submount to expire */
|
|
|
beb904 |
st_mutex_lock();
|
|
|
beb904 |
|
|
|
beb904 |
if (this->ap->state == ST_SHUTDOWN) {
|
|
|
beb904 |
this = NULL;
|
|
|
beb904 |
st_mutex_unlock();
|
|
|
beb904 |
- break;
|
|
|
beb904 |
+ goto done;
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
this->ap->shutdown = ap->shutdown;
|
|
|
beb904 |
@@ -1202,11 +1179,10 @@ int master_notify_submount(struct autofs
|
|
|
beb904 |
st_mutex_lock();
|
|
|
beb904 |
}
|
|
|
beb904 |
st_mutex_unlock();
|
|
|
beb904 |
- break;
|
|
|
beb904 |
+done:
|
|
|
beb904 |
+ mnts_put_mount(this);
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
- mnts_put_submount_list(&sbmnts);
|
|
|
beb904 |
-
|
|
|
beb904 |
return ret;
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
--- autofs-5.1.4.orig/lib/mounts.c
|
|
|
beb904 |
+++ autofs-5.1.4/lib/mounts.c
|
|
|
beb904 |
@@ -888,6 +888,7 @@ static struct mnt_list *mnts_alloc_mount
|
|
|
beb904 |
INIT_LIST_HEAD(&this->submount);
|
|
|
beb904 |
INIT_LIST_HEAD(&this->submount_work);
|
|
|
beb904 |
INIT_LIST_HEAD(&this->amdmount);
|
|
|
beb904 |
+ INIT_LIST_HEAD(&this->expire);
|
|
|
beb904 |
done:
|
|
|
beb904 |
return this;
|
|
|
beb904 |
}
|
|
|
beb904 |
@@ -1022,33 +1023,6 @@ void mnts_remove_submount(const char *mp
|
|
|
beb904 |
mnts_hash_mutex_unlock();
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
-void mnts_get_submount_list(struct list_head *mnts, struct autofs_point *ap)
|
|
|
beb904 |
-{
|
|
|
beb904 |
- struct mnt_list *mnt;
|
|
|
beb904 |
-
|
|
|
beb904 |
- mnts_hash_mutex_lock();
|
|
|
beb904 |
- if (list_empty(&ap->submounts))
|
|
|
beb904 |
- goto done;
|
|
|
beb904 |
- list_for_each_entry(mnt, &ap->submounts, submount) {
|
|
|
beb904 |
- __mnts_get_mount(mnt);
|
|
|
beb904 |
- list_add(&mnt->submount_work, mnts);
|
|
|
beb904 |
- }
|
|
|
beb904 |
-done:
|
|
|
beb904 |
- mnts_hash_mutex_unlock();
|
|
|
beb904 |
-}
|
|
|
beb904 |
-
|
|
|
beb904 |
-void mnts_put_submount_list(struct list_head *mnts)
|
|
|
beb904 |
-{
|
|
|
beb904 |
- struct mnt_list *mnt, *tmp;
|
|
|
beb904 |
-
|
|
|
beb904 |
- mnts_hash_mutex_lock();
|
|
|
beb904 |
- list_for_each_entry_safe(mnt, tmp, mnts, submount_work) {
|
|
|
beb904 |
- list_del_init(&mnt->submount_work);
|
|
|
beb904 |
- __mnts_put_mount(mnt);
|
|
|
beb904 |
- }
|
|
|
beb904 |
- mnts_hash_mutex_unlock();
|
|
|
beb904 |
-}
|
|
|
beb904 |
-
|
|
|
beb904 |
struct mnt_list *mnts_find_amdmount(const char *path)
|
|
|
beb904 |
{
|
|
|
beb904 |
struct mnt_list *mnt;
|
|
|
beb904 |
@@ -1234,6 +1208,163 @@ void mnts_set_mounted_mount(struct autof
|
|
|
beb904 |
}
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
+struct node {
|
|
|
beb904 |
+ struct mnt_list *mnt;
|
|
|
beb904 |
+ struct node *left;
|
|
|
beb904 |
+ struct node *right;
|
|
|
beb904 |
+};
|
|
|
beb904 |
+
|
|
|
beb904 |
+static struct node *new(struct mnt_list *mnt)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct node *n;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ n = malloc(sizeof(struct node));
|
|
|
beb904 |
+ if (!n)
|
|
|
beb904 |
+ return NULL;
|
|
|
beb904 |
+ memset(n, 0, sizeof(struct node));
|
|
|
beb904 |
+ n->mnt = mnt;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ return n;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static struct node *tree_root(struct mnt_list *mnt)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct node *n;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ n = new(mnt);
|
|
|
beb904 |
+ if (!n) {
|
|
|
beb904 |
+ error(LOGOPT_ANY, "failed to allcate tree root");
|
|
|
beb904 |
+ return NULL;
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+
|
|
|
beb904 |
+ return n;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static struct node *add_left(struct node *this, struct mnt_list *mnt)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct node *n;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ n = new(mnt);
|
|
|
beb904 |
+ if (!n) {
|
|
|
beb904 |
+ error(LOGOPT_ANY, "failed to allcate tree node");
|
|
|
beb904 |
+ return NULL;
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+ this->left = n;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ return n;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static struct node *add_right(struct node *this, struct mnt_list *mnt)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct node *n;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ n = new(mnt);
|
|
|
beb904 |
+ if (!n) {
|
|
|
beb904 |
+ error(LOGOPT_ANY, "failed to allcate tree node");
|
|
|
beb904 |
+ return NULL;
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+ this->right = n;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ return n;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static struct node *add_node(struct node *root, struct mnt_list *mnt)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct node *p, *q;
|
|
|
beb904 |
+ unsigned int mp_len;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ mp_len = strlen(mnt->mp);
|
|
|
beb904 |
+
|
|
|
beb904 |
+ q = root;
|
|
|
beb904 |
+ p = root;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ while (q && strcmp(mnt->mp, p->mnt->mp)) {
|
|
|
beb904 |
+ p = q;
|
|
|
beb904 |
+ if (mp_len < strlen(p->mnt->mp))
|
|
|
beb904 |
+ q = p->left;
|
|
|
beb904 |
+ else
|
|
|
beb904 |
+ q = p->right;
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+
|
|
|
beb904 |
+ if (strcmp(mnt->mp, p->mnt->mp) == 0)
|
|
|
beb904 |
+ error(LOGOPT_ANY, "duplicate entry in mounts list");
|
|
|
beb904 |
+ else {
|
|
|
beb904 |
+ if (mp_len < strlen(p->mnt->mp))
|
|
|
beb904 |
+ return add_left(p, mnt);
|
|
|
beb904 |
+ else
|
|
|
beb904 |
+ return add_right(p, mnt);
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+
|
|
|
beb904 |
+ return NULL;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static void tree_free(struct node *tree)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ if (tree->right)
|
|
|
beb904 |
+ tree_free(tree->right);
|
|
|
beb904 |
+ if (tree->left)
|
|
|
beb904 |
+ tree_free(tree->left);
|
|
|
beb904 |
+ free(tree);
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static void traverse(struct node *node, struct list_head *mnts)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ if (node->right)
|
|
|
beb904 |
+ traverse(node->right, mnts);
|
|
|
beb904 |
+ list_add_tail(&node->mnt->expire, mnts);
|
|
|
beb904 |
+ if (node->left)
|
|
|
beb904 |
+ traverse(node->left, mnts);
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+void mnts_get_expire_list(struct list_head *mnts, struct autofs_point *ap)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct mnt_list *mnt;
|
|
|
beb904 |
+ struct node *tree = NULL;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ mnts_hash_mutex_lock();
|
|
|
beb904 |
+ if (list_empty(&ap->mounts))
|
|
|
beb904 |
+ goto done;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ list_for_each_entry(mnt, &ap->mounts, mount) {
|
|
|
beb904 |
+ struct node *n;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ __mnts_get_mount(mnt);
|
|
|
beb904 |
+
|
|
|
beb904 |
+ if (!tree) {
|
|
|
beb904 |
+ tree = tree_root(mnt);
|
|
|
beb904 |
+ if (!tree) {
|
|
|
beb904 |
+ error(LOGOPT_ANY, "failed to create expire tree root");
|
|
|
beb904 |
+ goto done;
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+ continue;
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+
|
|
|
beb904 |
+ n = add_node(tree, mnt);
|
|
|
beb904 |
+ if (!n) {
|
|
|
beb904 |
+ error(LOGOPT_ANY, "failed to add expire tree node");
|
|
|
beb904 |
+ tree_free(tree);
|
|
|
beb904 |
+ goto done;
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+
|
|
|
beb904 |
+ traverse(tree, mnts);
|
|
|
beb904 |
+ tree_free(tree);
|
|
|
beb904 |
+done:
|
|
|
beb904 |
+ mnts_hash_mutex_unlock();
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+void mnts_put_expire_list(struct list_head *mnts)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct mnt_list *mnt, *tmp;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ mnts_hash_mutex_lock();
|
|
|
beb904 |
+ list_for_each_entry_safe(mnt, tmp, mnts, expire) {
|
|
|
beb904 |
+ list_del_init(&mnt->expire);
|
|
|
beb904 |
+ __mnts_put_mount(mnt);
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+ mnts_hash_mutex_unlock();
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
/* From glibc decode_name() */
|
|
|
beb904 |
/* Since the values in a line are separated by spaces, a name cannot
|
|
|
beb904 |
* contain a space. Therefore some programs encode spaces in names
|