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