Blame SOURCES/autofs-5.1.5-use-bit-flags-for-autofs-mount-types-in-mnt_list.patch

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