Blame SOURCES/autofs-5.1.7-fix-hosts-map-offset-order.patch

4bca17
autofs-5.1.7 - fix hosts map offset order
4bca17
4bca17
From: Ian Kent <raven@themaw.net>
4bca17
4bca17
Map entry offset paths to be in shortest to longest order but exports
4bca17
from a server could come in any order. If there are a large number of
4bca17
exports this can result in a lot of overhead when adding the offset
4bca17
to the ordered list use to mount the offset during parsing since the
4bca17
path length of exports can cary a lot.
4bca17
4bca17
So leverage the tree implemention to sort the export offsets into
4bca17
shortest to longest order as we go when constructing the mapent from
4bca17
the exports list.
4bca17
4bca17
Signed-off-by: Ian Kent <raven@themaw.net>
4bca17
---
4bca17
 CHANGELOG              |    1 
4bca17
 include/automount.h    |    2 -
4bca17
 include/mounts.h       |    8 +++++
4bca17
 include/rpc_subs.h     |    3 ++
4bca17
 lib/mounts.c           |   57 +++++++++++++++++++++++++++++++++++++--
4bca17
 modules/lookup_hosts.c |   71 ++++++++++++++++++++++++++++++++++++++-----------
4bca17
 6 files changed, 124 insertions(+), 18 deletions(-)
4bca17
4bca17
--- autofs-5.1.4.orig/CHANGELOG
4bca17
+++ autofs-5.1.4/CHANGELOG
4bca17
@@ -71,6 +71,7 @@
4bca17
 - fix offset entries order.
4bca17
 - use mapent tree root for tree_mapent_add_node().
4bca17
 - eliminate redundant cache lookup in tree_mapent_add_node().
4bca17
+- fix hosts map offset order.
4bca17
 
4bca17
 xx/xx/2018 autofs-5.1.5
4bca17
 - fix flag file permission.
4bca17
--- autofs-5.1.4.orig/include/automount.h
4bca17
+++ autofs-5.1.4/include/automount.h
4bca17
@@ -31,9 +31,9 @@
4bca17
 #include "master.h"
4bca17
 #include "macros.h"
4bca17
 #include "log.h"
4bca17
+#include "mounts.h"
4bca17
 #include "rpc_subs.h"
4bca17
 #include "parse_subs.h"
4bca17
-#include "mounts.h"
4bca17
 #include "dev-ioctl-lib.h"
4bca17
 #include "parse_amd.h"
4bca17
 
4bca17
--- autofs-5.1.4.orig/include/mounts.h
4bca17
+++ autofs-5.1.4/include/mounts.h
4bca17
@@ -52,6 +52,7 @@ extern const unsigned int t_direct;
4bca17
 extern const unsigned int t_offset;
4bca17
 
4bca17
 struct mnt_list;
4bca17
+struct exportinfo;
4bca17
 struct mapent;
4bca17
 
4bca17
 struct tree_ops;
4bca17
@@ -66,6 +67,9 @@ struct tree_node {
4bca17
 #define MNT_LIST(n)		(container_of(n, struct mnt_list, node))
4bca17
 #define MNT_LIST_NODE(ptr)	((struct tree_node *) &((struct mnt_list *) ptr)->node)
4bca17
 
4bca17
+#define EXPORTINFO(n)		(container_of(n, struct exportinfo, node))
4bca17
+#define EXPORT_NODE(ptr)	((struct tree_node *) &((struct exportinfo *) ptr)->node)
4bca17
+
4bca17
 #define MAPENT(n)		(container_of(n, struct mapent, node))
4bca17
 #define MAPENT_NODE(p)		((struct tree_node *) &((struct mapent *) p)->node)
4bca17
 #define MAPENT_ROOT(p)		((struct tree_node *) ((struct mapent *) p)->mm_root)
4bca17
@@ -166,9 +170,13 @@ struct mnt_list *mnts_add_mount(struct a
4bca17
 void mnts_remove_mount(const char *mp, unsigned int flags);
4bca17
 struct mnt_list *get_mnt_list(const char *path, int include);
4bca17
 unsigned int mnts_has_mounted_mounts(struct autofs_point *ap);
4bca17
+int tree_traverse_inorder(struct tree_node *n, tree_work_fn_t work, void *ptr);
4bca17
+void tree_free(struct tree_node *root);
4bca17
 void mnts_get_expire_list(struct list_head *mnts, struct autofs_point *ap);
4bca17
 void mnts_put_expire_list(struct list_head *mnts);
4bca17
 void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned int flags);
4bca17
+struct tree_node *tree_host_root(struct exportinfo *exp);
4bca17
+struct tree_node *tree_host_add_node(struct tree_node *root, struct exportinfo *exp);
4bca17
 struct tree_node *tree_mapent_root(struct mapent *me);
4bca17
 int tree_mapent_add_node(struct mapent_cache *mc, struct tree_node *root, struct mapent *me);
4bca17
 int tree_mapent_delete_offsets(struct mapent_cache *mc, const char *key);
4bca17
--- autofs-5.1.4.orig/include/rpc_subs.h
4bca17
+++ autofs-5.1.4/include/rpc_subs.h
4bca17
@@ -23,6 +23,8 @@
4bca17
 #include <linux/nfs2.h>
4bca17
 #include <linux/nfs3.h>
4bca17
 
4bca17
+#include "automount.h"
4bca17
+
4bca17
 #define NFS4_VERSION		4
4bca17
 
4bca17
 /* rpc helper subs */
4bca17
@@ -57,6 +59,7 @@ struct exportinfo {
4bca17
 	char *dir;
4bca17
 	struct hostinfo *hosts;
4bca17
 	struct exportinfo *next;
4bca17
+	struct tree_node node;
4bca17
 };
4bca17
 
4bca17
 struct conn_info {
4bca17
--- autofs-5.1.4.orig/lib/mounts.c
4bca17
+++ autofs-5.1.4/lib/mounts.c
4bca17
@@ -79,6 +79,17 @@ static struct tree_ops mnt_ops = {
4bca17
 };
4bca17
 static struct tree_ops *tree_mnt_ops = &mnt_ops;
4bca17
 
4bca17
+static struct tree_node *tree_host_new(void *ptr);
4bca17
+static int tree_host_cmp(struct tree_node *n, void *ptr);
4bca17
+static void tree_host_free(struct tree_node *n);
4bca17
+
4bca17
+static struct tree_ops host_ops = {
4bca17
+	.new = tree_host_new,
4bca17
+	.cmp = tree_host_cmp,
4bca17
+	.free = tree_host_free,
4bca17
+};
4bca17
+static struct tree_ops *tree_host_ops = &host_ops;
4bca17
+
4bca17
 static struct tree_node *tree_mapent_new(void *ptr);
4bca17
 static int tree_mapent_cmp(struct tree_node *n, void *ptr);
4bca17
 static void tree_mapent_free(struct tree_node *n);
4bca17
@@ -1341,7 +1352,7 @@ static struct tree_node *tree_add_node(s
4bca17
 	return NULL;
4bca17
 }
4bca17
 
4bca17
-static void tree_free(struct tree_node *root)
4bca17
+void tree_free(struct tree_node *root)
4bca17
 {
4bca17
 	struct tree_ops *ops = root->ops;
4bca17
 
4bca17
@@ -1352,7 +1363,7 @@ static void tree_free(struct tree_node *
4bca17
 	ops->free(root);
4bca17
 }
4bca17
 
4bca17
-static int tree_traverse_inorder(struct tree_node *n, tree_work_fn_t work, void *ptr)
4bca17
+int tree_traverse_inorder(struct tree_node *n, tree_work_fn_t work, void *ptr)
4bca17
 {
4bca17
 	int ret;
4bca17
 
4bca17
@@ -1479,6 +1490,48 @@ void mnts_put_expire_list(struct list_he
4bca17
 	mnts_hash_mutex_unlock();
4bca17
 }
4bca17
 
4bca17
+struct tree_node *tree_host_root(struct exportinfo *exp)
4bca17
+{
4bca17
+	return tree_root(tree_host_ops, exp);
4bca17
+}
4bca17
+
4bca17
+static struct tree_node *tree_host_new(void *ptr)
4bca17
+{
4bca17
+	struct tree_node *n = EXPORT_NODE(ptr);
4bca17
+
4bca17
+	n->ops = tree_host_ops;
4bca17
+	n->left = NULL;
4bca17
+	n->right = NULL;
4bca17
+
4bca17
+	return n;
4bca17
+}
4bca17
+
4bca17
+static int tree_host_cmp(struct tree_node *n, void *ptr)
4bca17
+{
4bca17
+	struct exportinfo *n_exp = EXPORTINFO(n);
4bca17
+	size_t n_exp_len = strlen(n_exp->dir);
4bca17
+	struct exportinfo *exp = ptr;
4bca17
+	size_t exp_len = strlen(exp->dir);
4bca17
+	int eq;
4bca17
+
4bca17
+	eq = strcmp(exp->dir, n_exp->dir);
4bca17
+	if (!eq)
4bca17
+		return 0;
4bca17
+	return (exp_len < n_exp_len) ? -1 : 1;
4bca17
+}
4bca17
+
4bca17
+static void tree_host_free(struct tree_node *n)
4bca17
+{
4bca17
+	n->ops = NULL;
4bca17
+	n->left = NULL;
4bca17
+	n->right = NULL;
4bca17
+}
4bca17
+
4bca17
+struct tree_node *tree_host_add_node(struct tree_node *root, struct exportinfo *exp)
4bca17
+{
4bca17
+	return tree_add_node(root, exp);
4bca17
+}
4bca17
+
4bca17
 struct tree_node *tree_mapent_root(struct mapent *me)
4bca17
 {
4bca17
 	return tree_root(tree_mapent_ops, me);
4bca17
--- autofs-5.1.4.orig/modules/lookup_hosts.c
4bca17
+++ autofs-5.1.4/modules/lookup_hosts.c
4bca17
@@ -84,14 +84,38 @@ int lookup_read_master(struct master *ma
4bca17
 	return NSS_STATUS_UNKNOWN;
4bca17
 }
4bca17
 
4bca17
+struct work_info {
4bca17
+	char *mapent;
4bca17
+	const char *host;
4bca17
+	int pos;
4bca17
+};
4bca17
+
4bca17
+static int tree_host_work(struct tree_node *n, void *ptr)
4bca17
+{
4bca17
+	struct exportinfo *exp = EXPORTINFO(n);
4bca17
+	struct work_info *wi = ptr;
4bca17
+	int len;
4bca17
+
4bca17
+	if (!wi->pos)
4bca17
+		len = sprintf(wi->mapent, "\"%s\" \"%s:%s\"",
4bca17
+				exp->dir, wi->host, exp->dir);
4bca17
+	else
4bca17
+		len = sprintf(wi->mapent + wi->pos, " \"%s\" \"%s:%s\"",
4bca17
+				exp->dir, wi->host, exp->dir);
4bca17
+	wi->pos += len;
4bca17
+
4bca17
+	return 1;
4bca17
+}
4bca17
+
4bca17
 static char *get_exports(struct autofs_point *ap, const char *host)
4bca17
 {
4bca17
 	char buf[MAX_ERR_BUF];
4bca17
 	char *mapent;
4bca17
 	struct exportinfo *exp, *this;
4bca17
+	struct tree_node *tree = NULL;
4bca17
+	struct work_info wi;
4bca17
 	size_t hostlen = strlen(host);
4bca17
 	size_t mapent_len;
4bca17
-	int len, pos;
4bca17
 
4bca17
 	debug(ap->logopt, MODPREFIX "fetchng export list for %s", host);
4bca17
 
4bca17
@@ -100,7 +124,28 @@ static char *get_exports(struct autofs_p
4bca17
 	this = exp;
4bca17
 	mapent_len = 0;
4bca17
 	while (this) {
4bca17
+		struct tree_node *n;
4bca17
+
4bca17
 		mapent_len += hostlen + 2*(strlen(this->dir) + 2) + 3;
4bca17
+
4bca17
+		if (!tree) {
4bca17
+			tree = tree_host_root(this);
4bca17
+			if (!tree) {
4bca17
+				error(ap->logopt, "failed to create exports tree root");
4bca17
+				rpc_exports_free(exp);
4bca17
+				return NULL;
4bca17
+			}
4bca17
+			goto next;
4bca17
+		}
4bca17
+
4bca17
+		n = tree_host_add_node(tree, this);
4bca17
+		if (!n) {
4bca17
+			error(ap->logopt, "failed to add exports tree node");
4bca17
+			tree_free(tree);
4bca17
+			rpc_exports_free(exp);
4bca17
+			return NULL;
4bca17
+		}
4bca17
+next:
4bca17
 		this = this->next;
4bca17
 	}
4bca17
 
4bca17
@@ -115,20 +160,16 @@ static char *get_exports(struct autofs_p
4bca17
 	}
4bca17
 	*mapent = 0;
4bca17
 
4bca17
-	pos = 0;
4bca17
-	this = exp;
4bca17
-	if (this) {
4bca17
-		len = sprintf(mapent, "\"%s\" \"%s:%s\"",
4bca17
-				this->dir, host, this->dir);
4bca17
-		pos += len;
4bca17
-		this = this->next;
4bca17
-	}
4bca17
-
4bca17
-	while (this) {
4bca17
-		len = sprintf(mapent + pos, " \"%s\" \"%s:%s\"",
4bca17
-				this->dir, host, this->dir);
4bca17
-		pos += len;
4bca17
-		this = this->next;
4bca17
+	wi.mapent = mapent;
4bca17
+	wi.host = host;
4bca17
+	wi.pos = 0;
4bca17
+
4bca17
+	if (!tree) {
4bca17
+		free(mapent);
4bca17
+		mapent = NULL;
4bca17
+	} else {
4bca17
+		tree_traverse_inorder(tree, tree_host_work, &wi;;
4bca17
+		tree_free(tree);
4bca17
 	}
4bca17
 	rpc_exports_free(exp);
4bca17