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

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