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

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