autofs/SOURCES/autofs-5.1.5-dont-use-tree_is_mounted-for-mounted-checks.patch
2021-09-09 14:54:57 +00:00

173 lines
5.5 KiB
Diff

autofs-5.1.5 - don't use tree_is_mounted() for mounted checks
From: Ian Kent <raven@themaw.net>
Always use is_mounted() for mounted checks.
If the proc mount table actually needs to be used this could be
very inefficient but the miscelaneous device ioctl interface
has been available to quite a few years now so it really needs
to be used to avoid the scanning of mount tables.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/direct.c | 12 ++++--------
daemon/state.c | 4 ++--
include/automount.h | 2 +-
include/mounts.h | 1 -
lib/mounts.c | 40 ----------------------------------------
6 files changed, 8 insertions(+), 52 deletions(-)
--- autofs-5.1.4.orig/CHANGELOG
+++ autofs-5.1.4/CHANGELOG
@@ -69,6 +69,7 @@ xx/xx/2018 autofs-5.1.5
- add glibc getmntent_r().
- use local getmntent_r in table_is_mounted().
- refactor unlink_active_mounts() in direct.c.
+- don't use tree_is_mounted() for mounted checks.
19/12/2017 autofs-5.1.4
- fix spec file url.
--- autofs-5.1.4.orig/daemon/direct.c
+++ autofs-5.1.4/daemon/direct.c
@@ -82,7 +82,7 @@ static void mnts_cleanup(void *arg)
return;
}
-int do_umount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me)
+int do_umount_autofs_direct(struct autofs_point *ap, struct mapent *me)
{
struct ioctl_ops *ops = get_ioctl_ops();
char buf[MAX_ERR_BUF];
@@ -98,7 +98,7 @@ int do_umount_autofs_direct(struct autof
if (me->ioctlfd != -1) {
if (ap->state == ST_READMAP &&
- tree_is_mounted(mnts, me->key, MNTS_REAL)) {
+ is_mounted(me->key, MNTS_REAL)) {
error(ap->logopt,
"attempt to umount busy direct mount %s",
me->key);
@@ -204,11 +204,8 @@ int umount_autofs_direct(struct autofs_p
{
struct map_source *map;
struct mapent_cache *nc, *mc;
- struct mnt_list *mnts;
struct mapent *me, *ne;
- mnts = tree_make_mnt_tree("/");
- pthread_cleanup_push(mnts_cleanup, mnts);
nc = ap->entry->master->nc;
cache_readlock(nc);
pthread_cleanup_push(cache_lock_cleanup, nc);
@@ -233,7 +230,7 @@ int umount_autofs_direct(struct autofs_p
* catatonic regardless of the reason for the
* failed umount.
*/
- error = do_umount_autofs_direct(ap, mnts, me);
+ error = do_umount_autofs_direct(ap, me);
if (!error)
goto done;
@@ -246,7 +243,6 @@ done:
map = map->next;
}
pthread_cleanup_pop(1);
- pthread_cleanup_pop(1);
close(ap->state_pipe[0]);
close(ap->state_pipe[1]);
@@ -947,7 +943,7 @@ void *expire_proc_direct(void *arg)
}
/* It's got a mount, deal with in the outer loop */
- if (tree_is_mounted(mnts, me->key, MNTS_REAL)) {
+ if (is_mounted(me->key, MNTS_REAL)) {
pthread_setcancelstate(cur_state, NULL);
continue;
}
--- autofs-5.1.4.orig/daemon/state.c
+++ autofs-5.1.4/daemon/state.c
@@ -438,8 +438,8 @@ static void do_readmap_mount(struct auto
else
ap->exp_runfreq = runfreq;
}
- } else if (!tree_is_mounted(mnts, me->key, MNTS_REAL))
- do_umount_autofs_direct(ap, mnts, me);
+ } else if (!is_mounted(me->key, MNTS_REAL))
+ do_umount_autofs_direct(ap, me);
else
debug(ap->logopt,
"%s is mounted", me->key);
--- autofs-5.1.4.orig/include/automount.h
+++ autofs-5.1.4/include/automount.h
@@ -613,7 +613,7 @@ void submount_signal_parent(struct autof
void close_mount_fds(struct autofs_point *ap);
int umount_autofs(struct autofs_point *ap, const char *root, int force);
int umount_autofs_indirect(struct autofs_point *ap, const char *root);
-int do_umount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me);
+int do_umount_autofs_direct(struct autofs_point *ap, struct mapent *me);
int umount_autofs_direct(struct autofs_point *ap);
int umount_autofs_offset(struct autofs_point *ap, struct mapent *me);
int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_indirect_t *pkt);
--- autofs-5.1.4.orig/include/mounts.h
+++ autofs-5.1.4/include/mounts.h
@@ -107,7 +107,6 @@ struct mnt_list *tree_make_mnt_tree(cons
int tree_get_mnt_list(struct mnt_list *mnts, struct list_head *list, const char *path, int include);
int tree_get_mnt_sublist(struct mnt_list *mnts, struct list_head *list, const char *path, int include);
int tree_find_mnt_ents(struct mnt_list *mnts, struct list_head *list, const char *path);
-int tree_is_mounted(struct mnt_list *mnts, const char *path, unsigned int type);
void set_tsd_user_vars(unsigned int, uid_t, gid_t);
const char *mount_type_str(unsigned int);
void set_exp_timeout(struct autofs_point *ap, struct map_source *source, time_t timeout);
--- autofs-5.1.4.orig/lib/mounts.c
+++ autofs-5.1.4/lib/mounts.c
@@ -1368,46 +1368,6 @@ int tree_find_mnt_ents(struct mnt_list *
return 0;
}
-int tree_is_mounted(struct mnt_list *mnts, const char *path, unsigned int type)
-{
- struct ioctl_ops *ops = get_ioctl_ops();
- struct list_head *p;
- struct list_head list;
- int mounted = 0;
-
- if (ops->ismountpoint)
- return ioctl_is_mounted(path, type);
-
- INIT_LIST_HEAD(&list);
-
- if (!tree_find_mnt_ents(mnts, &list, path))
- return 0;
-
- list_for_each(p, &list) {
- struct mnt_list *mptr;
-
- mptr = list_entry(p, struct mnt_list, entries);
-
- if (type) {
- if (type & MNTS_REAL) {
- if (mptr->flags & MNTS_AUTOFS) {
- mounted = 1;
- break;
- }
- } else if (type & MNTS_AUTOFS) {
- if (mptr->flags & MNTS_AUTOFS) {
- mounted = 1;
- break;
- }
- } else {
- mounted = 1;
- break;
- }
- }
- }
- return mounted;
-}
-
void set_tsd_user_vars(unsigned int logopt, uid_t uid, gid_t gid)
{
struct thread_stdenv_vars *tsv;