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