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

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