|
|
135b98 |
autofs-5.1.5 - use bit flags for autofs mount types in mnt_list
|
|
|
135b98 |
|
|
|
135b98 |
From: Ian Kent <raven@themaw.net>
|
|
|
135b98 |
|
|
|
135b98 |
Several fields in struct mnt_list don't need to be saved as strings
|
|
|
135b98 |
so change to using bit flags for them instead.
|
|
|
135b98 |
|
|
|
135b98 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
135b98 |
---
|
|
|
135b98 |
CHANGELOG | 1
|
|
|
135b98 |
daemon/direct.c | 10 ++---
|
|
|
135b98 |
daemon/indirect.c | 16 ++++----
|
|
|
135b98 |
include/mounts.h | 7 ++-
|
|
|
135b98 |
lib/mounts.c | 97 +++++++++++-------------------------------------------
|
|
|
135b98 |
5 files changed, 38 insertions(+), 93 deletions(-)
|
|
|
135b98 |
|
|
|
135b98 |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
135b98 |
+++ autofs-5.1.4/CHANGELOG
|
|
|
135b98 |
@@ -63,6 +63,7 @@ xx/xx/2018 autofs-5.1.5
|
|
|
135b98 |
- add ignore mount option.
|
|
|
135b98 |
- use ignore option for offset mounts as well.
|
|
|
135b98 |
- add config option for "ignore" mount option
|
|
|
135b98 |
+- use bit flags for autofs mount types in mnt_list.
|
|
|
135b98 |
|
|
|
135b98 |
19/12/2017 autofs-5.1.4
|
|
|
135b98 |
- fix spec file url.
|
|
|
135b98 |
--- autofs-5.1.4.orig/daemon/direct.c
|
|
|
135b98 |
+++ autofs-5.1.4/daemon/direct.c
|
|
|
135b98 |
@@ -271,10 +271,10 @@ static int unlink_mount_tree(struct auto
|
|
|
135b98 |
|
|
|
135b98 |
mnt = list_entry(p, struct mnt_list, list);
|
|
|
135b98 |
|
|
|
135b98 |
- if (strcmp(mnt->fs_type, "autofs"))
|
|
|
135b98 |
- rv = spawn_umount(ap->logopt, "-l", mnt->path, NULL);
|
|
|
135b98 |
- else
|
|
|
135b98 |
+ if (mnt->flags & MNTS_AUTOFS)
|
|
|
135b98 |
rv = umount2(mnt->path, MNT_DETACH);
|
|
|
135b98 |
+ else
|
|
|
135b98 |
+ rv = spawn_umount(ap->logopt, "-l", mnt->path, NULL);
|
|
|
135b98 |
if (rv == -1) {
|
|
|
135b98 |
debug(ap->logopt,
|
|
|
135b98 |
"can't unlink %s from mount tree", mnt->path);
|
|
|
135b98 |
@@ -925,7 +925,7 @@ void *expire_proc_direct(void *arg)
|
|
|
135b98 |
if (!me)
|
|
|
135b98 |
continue;
|
|
|
135b98 |
|
|
|
135b98 |
- if (!strcmp(next->fs_type, "autofs")) {
|
|
|
135b98 |
+ if (next->flags & MNTS_AUTOFS) {
|
|
|
135b98 |
struct stat st;
|
|
|
135b98 |
int ioctlfd;
|
|
|
135b98 |
|
|
|
135b98 |
@@ -936,7 +936,7 @@ void *expire_proc_direct(void *arg)
|
|
|
135b98 |
* one of them and pass on state change.
|
|
|
135b98 |
*/
|
|
|
135b98 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
135b98 |
- if (strstr(next->opts, "indirect")) {
|
|
|
135b98 |
+ if (next->flags & MNTS_INDIRECT) {
|
|
|
135b98 |
master_notify_submount(ap, next->path, ap->state);
|
|
|
135b98 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
135b98 |
continue;
|
|
|
135b98 |
--- autofs-5.1.4.orig/daemon/indirect.c
|
|
|
135b98 |
+++ autofs-5.1.4/daemon/indirect.c
|
|
|
135b98 |
@@ -48,10 +48,10 @@ static int unlink_mount_tree(struct auto
|
|
|
135b98 |
ret = 1;
|
|
|
135b98 |
this = mnts;
|
|
|
135b98 |
while (this) {
|
|
|
135b98 |
- if (strcmp(this->fs_type, "autofs"))
|
|
|
135b98 |
- rv = spawn_umount(ap->logopt, "-l", this->path, NULL);
|
|
|
135b98 |
- else
|
|
|
135b98 |
+ if (this->flags & MNTS_AUTOFS)
|
|
|
135b98 |
rv = umount2(this->path, MNT_DETACH);
|
|
|
135b98 |
+ else
|
|
|
135b98 |
+ rv = spawn_umount(ap->logopt, "-l", this->path, NULL);
|
|
|
135b98 |
if (rv == -1) {
|
|
|
135b98 |
debug(ap->logopt,
|
|
|
135b98 |
"can't unlink %s from mount tree", this->path);
|
|
|
135b98 |
@@ -439,15 +439,15 @@ void *expire_proc_indirect(void *arg)
|
|
|
135b98 |
char *ind_key;
|
|
|
135b98 |
int ret;
|
|
|
135b98 |
|
|
|
135b98 |
- if (!strcmp(next->fs_type, "autofs")) {
|
|
|
135b98 |
+ if (next->flags & MNTS_AUTOFS) {
|
|
|
135b98 |
/*
|
|
|
135b98 |
* If we have submounts check if this path lives below
|
|
|
135b98 |
* one of them and pass on the state change.
|
|
|
135b98 |
*/
|
|
|
135b98 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
135b98 |
- if (strstr(next->opts, "indirect"))
|
|
|
135b98 |
+ if (next->flags & MNTS_INDIRECT)
|
|
|
135b98 |
master_notify_submount(ap, next->path, ap->state);
|
|
|
135b98 |
- else if (strstr(next->opts, "offset")) {
|
|
|
135b98 |
+ else if (next->flags & MNTS_OFFSET) {
|
|
|
135b98 |
struct map_source *map;
|
|
|
135b98 |
struct mapent_cache *mc = NULL;
|
|
|
135b98 |
struct mapent *me = NULL;
|
|
|
135b98 |
@@ -567,10 +567,10 @@ void *expire_proc_indirect(void *arg)
|
|
|
135b98 |
pthread_cleanup_push(mnts_cleanup, mnts);
|
|
|
135b98 |
/* Are there any real mounts left */
|
|
|
135b98 |
for (next = mnts; next; next = next->next) {
|
|
|
135b98 |
- if (strcmp(next->fs_type, "autofs"))
|
|
|
135b98 |
+ if (!(next->flags & MNTS_AUTOFS))
|
|
|
135b98 |
count++;
|
|
|
135b98 |
else {
|
|
|
135b98 |
- if (strstr(next->opts, "indirect"))
|
|
|
135b98 |
+ if (next->flags & MNTS_INDIRECT)
|
|
|
135b98 |
submnts++;
|
|
|
135b98 |
else
|
|
|
135b98 |
offsets++;
|
|
|
135b98 |
--- autofs-5.1.4.orig/include/mounts.h
|
|
|
135b98 |
+++ autofs-5.1.4/include/mounts.h
|
|
|
135b98 |
@@ -35,6 +35,9 @@
|
|
|
135b98 |
#define MNTS_ALL 0x0001
|
|
|
135b98 |
#define MNTS_REAL 0x0002
|
|
|
135b98 |
#define MNTS_AUTOFS 0x0004
|
|
|
135b98 |
+#define MNTS_INDIRECT 0x0008
|
|
|
135b98 |
+#define MNTS_DIRECT 0x0010
|
|
|
135b98 |
+#define MNTS_OFFSET 0x0020
|
|
|
135b98 |
|
|
|
135b98 |
#define REMOUNT_SUCCESS 0x0000
|
|
|
135b98 |
#define REMOUNT_FAIL 0x0001
|
|
|
135b98 |
@@ -50,9 +53,7 @@ struct mapent;
|
|
|
135b98 |
|
|
|
135b98 |
struct mnt_list {
|
|
|
135b98 |
char *path;
|
|
|
135b98 |
- char *fs_name;
|
|
|
135b98 |
- char *fs_type;
|
|
|
135b98 |
- char *opts;
|
|
|
135b98 |
+ unsigned int flags;
|
|
|
135b98 |
/*
|
|
|
135b98 |
* List operations ie. get_mnt_list.
|
|
|
135b98 |
*/
|
|
|
135b98 |
--- autofs-5.1.4.orig/lib/mounts.c
|
|
|
135b98 |
+++ autofs-5.1.4/lib/mounts.c
|
|
|
135b98 |
@@ -855,29 +855,17 @@ struct mnt_list *get_mnt_list(const char
|
|
|
135b98 |
}
|
|
|
135b98 |
strcpy(ent->path, mnt->mnt_dir);
|
|
|
135b98 |
|
|
|
135b98 |
- ent->fs_name = malloc(strlen(mnt->mnt_fsname) + 1);
|
|
|
135b98 |
- if (!ent->fs_name) {
|
|
|
135b98 |
- endmntent(tab);
|
|
|
135b98 |
- free_mnt_list(list);
|
|
|
135b98 |
- return NULL;
|
|
|
135b98 |
- }
|
|
|
135b98 |
- strcpy(ent->fs_name, mnt->mnt_fsname);
|
|
|
135b98 |
+ if (!strcmp(mnt->mnt_type, "autofs"))
|
|
|
135b98 |
+ ent->flags |= MNTS_AUTOFS;
|
|
|
135b98 |
|
|
|
135b98 |
- ent->fs_type = malloc(strlen(mnt->mnt_type) + 1);
|
|
|
135b98 |
- if (!ent->fs_type) {
|
|
|
135b98 |
- endmntent(tab);
|
|
|
135b98 |
- free_mnt_list(list);
|
|
|
135b98 |
- return NULL;
|
|
|
135b98 |
- }
|
|
|
135b98 |
- strcpy(ent->fs_type, mnt->mnt_type);
|
|
|
135b98 |
-
|
|
|
135b98 |
- ent->opts = malloc(strlen(mnt->mnt_opts) + 1);
|
|
|
135b98 |
- if (!ent->opts) {
|
|
|
135b98 |
- endmntent(tab);
|
|
|
135b98 |
- free_mnt_list(list);
|
|
|
135b98 |
- return NULL;
|
|
|
135b98 |
+ if (ent->flags & MNTS_AUTOFS) {
|
|
|
135b98 |
+ if (strstr(mnt->mnt_opts, "indirect"))
|
|
|
135b98 |
+ ent->flags |= MNTS_INDIRECT;
|
|
|
135b98 |
+ else if (strstr(mnt->mnt_opts, "direct"))
|
|
|
135b98 |
+ ent->flags |= MNTS_DIRECT;
|
|
|
135b98 |
+ else if (strstr(mnt->mnt_opts, "offset"))
|
|
|
135b98 |
+ ent->flags |= MNTS_OFFSET;
|
|
|
135b98 |
}
|
|
|
135b98 |
- strcpy(ent->opts, mnt->mnt_opts);
|
|
|
135b98 |
}
|
|
|
135b98 |
endmntent(tab);
|
|
|
135b98 |
|
|
|
135b98 |
@@ -900,15 +888,6 @@ void free_mnt_list(struct mnt_list *list
|
|
|
135b98 |
if (this->path)
|
|
|
135b98 |
free(this->path);
|
|
|
135b98 |
|
|
|
135b98 |
- if (this->fs_name)
|
|
|
135b98 |
- free(this->fs_name);
|
|
|
135b98 |
-
|
|
|
135b98 |
- if (this->fs_type)
|
|
|
135b98 |
- free(this->fs_type);
|
|
|
135b98 |
-
|
|
|
135b98 |
- if (this->opts)
|
|
|
135b98 |
- free(this->opts);
|
|
|
135b98 |
-
|
|
|
135b98 |
free(this);
|
|
|
135b98 |
}
|
|
|
135b98 |
}
|
|
|
135b98 |
@@ -1028,22 +1007,11 @@ void tree_free_mnt_tree(struct mnt_list
|
|
|
135b98 |
list_del(&this->self);
|
|
|
135b98 |
|
|
|
135b98 |
free(this->path);
|
|
|
135b98 |
- free(this->fs_name);
|
|
|
135b98 |
- free(this->fs_type);
|
|
|
135b98 |
-
|
|
|
135b98 |
- if (this->opts)
|
|
|
135b98 |
- free(this->opts);
|
|
|
135b98 |
|
|
|
135b98 |
free(this);
|
|
|
135b98 |
}
|
|
|
135b98 |
|
|
|
135b98 |
free(tree->path);
|
|
|
135b98 |
- free(tree->fs_name);
|
|
|
135b98 |
- free(tree->fs_type);
|
|
|
135b98 |
-
|
|
|
135b98 |
- if (tree->opts)
|
|
|
135b98 |
- free(tree->opts);
|
|
|
135b98 |
-
|
|
|
135b98 |
free(tree);
|
|
|
135b98 |
}
|
|
|
135b98 |
|
|
|
135b98 |
@@ -1103,38 +1071,17 @@ struct mnt_list *tree_make_mnt_tree(cons
|
|
|
135b98 |
}
|
|
|
135b98 |
strcpy(ent->path, mnt->mnt_dir);
|
|
|
135b98 |
|
|
|
135b98 |
- ent->fs_name = malloc(strlen(mnt->mnt_fsname) + 1);
|
|
|
135b98 |
- if (!ent->fs_name) {
|
|
|
135b98 |
- free(ent->path);
|
|
|
135b98 |
- free(ent);
|
|
|
135b98 |
- endmntent(tab);
|
|
|
135b98 |
- tree_free_mnt_tree(tree);
|
|
|
135b98 |
- return NULL;
|
|
|
135b98 |
- }
|
|
|
135b98 |
- strcpy(ent->fs_name, mnt->mnt_fsname);
|
|
|
135b98 |
-
|
|
|
135b98 |
- ent->fs_type = malloc(strlen(mnt->mnt_type) + 1);
|
|
|
135b98 |
- if (!ent->fs_type) {
|
|
|
135b98 |
- free(ent->fs_name);
|
|
|
135b98 |
- free(ent->path);
|
|
|
135b98 |
- free(ent);
|
|
|
135b98 |
- endmntent(tab);
|
|
|
135b98 |
- tree_free_mnt_tree(tree);
|
|
|
135b98 |
- return NULL;
|
|
|
135b98 |
- }
|
|
|
135b98 |
- strcpy(ent->fs_type, mnt->mnt_type);
|
|
|
135b98 |
+ if (!strcmp(mnt->mnt_type, "autofs"))
|
|
|
135b98 |
+ ent->flags |= MNTS_AUTOFS;
|
|
|
135b98 |
|
|
|
135b98 |
- ent->opts = malloc(strlen(mnt->mnt_opts) + 1);
|
|
|
135b98 |
- if (!ent->opts) {
|
|
|
135b98 |
- free(ent->fs_type);
|
|
|
135b98 |
- free(ent->fs_name);
|
|
|
135b98 |
- free(ent->path);
|
|
|
135b98 |
- free(ent);
|
|
|
135b98 |
- endmntent(tab);
|
|
|
135b98 |
- tree_free_mnt_tree(tree);
|
|
|
135b98 |
- return NULL;
|
|
|
135b98 |
+ if (ent->flags & MNTS_AUTOFS) {
|
|
|
135b98 |
+ if (strstr(mnt->mnt_opts, "indirect"))
|
|
|
135b98 |
+ ent->flags |= MNTS_INDIRECT;
|
|
|
135b98 |
+ else if (strstr(mnt->mnt_opts, "direct"))
|
|
|
135b98 |
+ ent->flags |= MNTS_DIRECT;
|
|
|
135b98 |
+ else if (strstr(mnt->mnt_opts, "offset"))
|
|
|
135b98 |
+ ent->flags |= MNTS_OFFSET;
|
|
|
135b98 |
}
|
|
|
135b98 |
- strcpy(ent->opts, mnt->mnt_opts);
|
|
|
135b98 |
|
|
|
135b98 |
mptr = tree;
|
|
|
135b98 |
while (mptr) {
|
|
|
135b98 |
@@ -1347,17 +1294,13 @@ int tree_is_mounted(struct mnt_list *mnt
|
|
|
135b98 |
mptr = list_entry(p, struct mnt_list, entries);
|
|
|
135b98 |
|
|
|
135b98 |
if (type) {
|
|
|
135b98 |
- unsigned int autofs_fs;
|
|
|
135b98 |
-
|
|
|
135b98 |
- autofs_fs = !strcmp(mptr->fs_type, "autofs");
|
|
|
135b98 |
-
|
|
|
135b98 |
if (type & MNTS_REAL) {
|
|
|
135b98 |
- if (!autofs_fs) {
|
|
|
135b98 |
+ if (mptr->flags & MNTS_AUTOFS) {
|
|
|
135b98 |
mounted = 1;
|
|
|
135b98 |
break;
|
|
|
135b98 |
}
|
|
|
135b98 |
} else if (type & MNTS_AUTOFS) {
|
|
|
135b98 |
- if (autofs_fs) {
|
|
|
135b98 |
+ if (mptr->flags & MNTS_AUTOFS) {
|
|
|
135b98 |
mounted = 1;
|
|
|
135b98 |
break;
|
|
|
135b98 |
}
|