autofs-5.1.5 - move unlink_mount_tree() to lib/mounts.c From: Ian Kent Both daemon/direct.c and daemon/indirect.c use the same function to lazy umount a list of mounts, move that function to lib/mounts.c. Signed-off-by: Ian Kent --- CHANGELOG | 1 + daemon/direct.c | 2 -- daemon/indirect.c | 34 ---------------------------------- include/mounts.h | 1 + lib/mounts.c | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 60826d8c..023bfdf7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,6 +33,7 @@ xx/xx/2019 autofs-5.1.6 - refactor unlink_active_mounts() in direct.c. - don't use tree_is_mounted() for mounted checks. - use single unlink_umount_tree() for both direct and indirect mounts. +- move unlink_mount_tree() to lib/mounts.c. 30/10/2018 autofs-5.1.5 - fix flag file permission. diff --git a/daemon/direct.c b/daemon/direct.c index f9ffaaae..1cc66237 100644 --- a/daemon/direct.c +++ b/daemon/direct.c @@ -49,8 +49,6 @@ pthread_key_t key_mnt_direct_params; pthread_key_t key_mnt_offset_params; pthread_once_t key_mnt_params_once = PTHREAD_ONCE_INIT; -int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts); - static void key_mnt_params_destroy(void *arg) { struct mnt_params *mp; diff --git a/daemon/indirect.c b/daemon/indirect.c index 750a563f..1ef481ee 100644 --- a/daemon/indirect.c +++ b/daemon/indirect.c @@ -40,40 +40,6 @@ /* Attribute to create detached thread */ extern pthread_attr_t th_attr_detached; -int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts) -{ - struct mnt_list *this; - int rv, ret; - - ret = 1; - this = mnts; - while (this) { - if (this->flags & MNTS_AUTOFS) - rv = umount2(this->mp, MNT_DETACH); - else - rv = spawn_umount(ap->logopt, "-l", this->mp, NULL); - if (rv == -1) { - debug(ap->logopt, - "can't unlink %s from mount tree", this->mp); - - switch (errno) { - case EINVAL: - warn(ap->logopt, - "bad superblock or not mounted"); - break; - - case ENOENT: - case EFAULT: - ret = 0; - warn(ap->logopt, "bad path for mount"); - break; - } - } - this = this->next; - } - return ret; -} - static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root) { const char *str_indirect = mount_type_str(t_indirect); diff --git a/include/mounts.h b/include/mounts.h index 3e2c2665..27a224c7 100644 --- a/include/mounts.h +++ b/include/mounts.h @@ -100,6 +100,7 @@ int ext_mount_add(struct list_head *, const char *, unsigned int); int ext_mount_remove(struct list_head *, const char *); int ext_mount_inuse(const char *); struct mnt_list *get_mnt_list(const char *path, int include); +int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts); void free_mnt_list(struct mnt_list *list); int is_mounted(const char *mp, unsigned int type); void tree_free_mnt_tree(struct mnt_list *tree); diff --git a/lib/mounts.c b/lib/mounts.c index 10827710..64924737 100644 --- a/lib/mounts.c +++ b/lib/mounts.c @@ -881,6 +881,41 @@ local_getmntent_r(FILE *tab, struct mntent *mnt, char *buf, int size) return mnt; } +int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts) +{ + struct mnt_list *this; + int rv, ret; + + ret = 1; + this = mnts; + while (this) { + if (this->flags & MNTS_AUTOFS) + rv = umount2(this->mp, MNT_DETACH); + else + rv = spawn_umount(ap->logopt, "-l", this->mp, NULL); + if (rv == -1) { + debug(ap->logopt, + "can't unlink %s from mount tree", this->mp); + + switch (errno) { + case EINVAL: + warn(ap->logopt, + "bad superblock or not mounted"); + break; + + case ENOENT: + case EFAULT: + ret = 0; + warn(ap->logopt, "bad path for mount"); + break; + } + } + this = this->next; + } + + return ret; +} + /* * Get list of mounts under path in longest->shortest order */