|
|
9a499a |
autofs-5.1.7 - eliminate cache_lookup_offset() usage
|
|
|
9a499a |
|
|
|
9a499a |
From: Ian Kent <raven@themaw.net>
|
|
|
9a499a |
|
|
|
9a499a |
The function cache_lookup_offset() will do a linear search when
|
|
|
9a499a |
looking for an offset. If the number of offsets is large this
|
|
|
9a499a |
can be a lot of overhead.
|
|
|
9a499a |
|
|
|
9a499a |
But it's possible to use the information already present where
|
|
|
9a499a |
this is called to to do a hashed lookup instead.
|
|
|
9a499a |
|
|
|
9a499a |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
9a499a |
---
|
|
|
9a499a |
CHANGELOG | 1
|
|
|
9a499a |
lib/mounts.c | 82 +++++++++++++++++++++++++++++++++-------------------
|
|
|
9a499a |
modules/parse_sun.c | 77 ++++++++++++++++++++++++++++++------------------
|
|
|
9a499a |
3 files changed, 102 insertions(+), 58 deletions(-)
|
|
|
9a499a |
|
|
|
9a499a |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
9a499a |
+++ autofs-5.1.4/CHANGELOG
|
|
|
9a499a |
@@ -4,6 +4,7 @@
|
|
|
9a499a |
- dont use realloc in host exports list processing.
|
|
|
9a499a |
- use sprintf() when constructing hosts mapent.
|
|
|
9a499a |
- fix mnts_remove_amdmount() uses wrong list.
|
|
|
9a499a |
+- eliminate cache_lookup_offset() usage.
|
|
|
9a499a |
|
|
|
9a499a |
xx/xx/2018 autofs-5.1.5
|
|
|
9a499a |
- fix flag file permission.
|
|
|
9a499a |
--- autofs-5.1.4.orig/lib/mounts.c
|
|
|
9a499a |
+++ autofs-5.1.4/lib/mounts.c
|
|
|
9a499a |
@@ -2489,24 +2489,27 @@ int mount_multi_triggers(struct autofs_p
|
|
|
9a499a |
char *offset = path;
|
|
|
9a499a |
struct mapent *oe;
|
|
|
9a499a |
struct list_head *pos = NULL;
|
|
|
9a499a |
- unsigned int fs_path_len;
|
|
|
9a499a |
+ unsigned int root_len = strlen(root);
|
|
|
9a499a |
int mounted;
|
|
|
9a499a |
|
|
|
9a499a |
- fs_path_len = start + strlen(base);
|
|
|
9a499a |
- if (fs_path_len > PATH_MAX)
|
|
|
9a499a |
- return -1;
|
|
|
9a499a |
-
|
|
|
9a499a |
mounted = 0;
|
|
|
9a499a |
offset = cache_get_offset(base, offset, start, &me->multi_list, &pos;;
|
|
|
9a499a |
while (offset) {
|
|
|
9a499a |
- int plen = fs_path_len + strlen(offset);
|
|
|
9a499a |
+ char key[PATH_MAX + 1];
|
|
|
9a499a |
+ int key_len = root_len + strlen(offset);
|
|
|
9a499a |
|
|
|
9a499a |
- if (plen > PATH_MAX) {
|
|
|
9a499a |
+ if (key_len > PATH_MAX) {
|
|
|
9a499a |
warn(ap->logopt, "path loo long");
|
|
|
9a499a |
goto cont;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
- oe = cache_lookup_offset(base, offset, start, &me->multi_list);
|
|
|
9a499a |
+ /* The root offset is always mounted seperately so the
|
|
|
9a499a |
+ * offset path will always be root + offset.
|
|
|
9a499a |
+ */
|
|
|
9a499a |
+ strcpy(key, root);
|
|
|
9a499a |
+ strcat(key, offset);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ oe = cache_lookup_distinct(me->mc, key);
|
|
|
9a499a |
if (!oe || !oe->mapent)
|
|
|
9a499a |
goto cont;
|
|
|
9a499a |
|
|
|
9a499a |
@@ -2519,12 +2522,8 @@ int mount_multi_triggers(struct autofs_p
|
|
|
9a499a |
*/
|
|
|
9a499a |
if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
|
|
|
9a499a |
if (oe->ioctlfd != -1 ||
|
|
|
9a499a |
- is_mounted(oe->key, MNTS_REAL)) {
|
|
|
9a499a |
- char oe_root[PATH_MAX + 1];
|
|
|
9a499a |
- strcpy(oe_root, root);
|
|
|
9a499a |
- strcat(oe_root, offset);
|
|
|
9a499a |
- mount_multi_triggers(ap, oe, oe_root, strlen(oe_root), base);
|
|
|
9a499a |
- }
|
|
|
9a499a |
+ is_mounted(oe->key, MNTS_REAL))
|
|
|
9a499a |
+ mount_multi_triggers(ap, oe, key, strlen(key), base);
|
|
|
9a499a |
}
|
|
|
9a499a |
cont:
|
|
|
9a499a |
offset = cache_get_offset(base,
|
|
|
9a499a |
@@ -2578,6 +2577,8 @@ int umount_multi_triggers(struct autofs_
|
|
|
9a499a |
const char o_root[] = "/";
|
|
|
9a499a |
const char *mm_base;
|
|
|
9a499a |
int left, start;
|
|
|
9a499a |
+ unsigned int root_len;
|
|
|
9a499a |
+ unsigned int mm_base_len;
|
|
|
9a499a |
|
|
|
9a499a |
left = 0;
|
|
|
9a499a |
start = strlen(root);
|
|
|
9a499a |
@@ -2591,11 +2592,28 @@ int umount_multi_triggers(struct autofs_
|
|
|
9a499a |
|
|
|
9a499a |
pos = NULL;
|
|
|
9a499a |
offset = path;
|
|
|
9a499a |
+ root_len = start;
|
|
|
9a499a |
+ mm_base_len = strlen(mm_base);
|
|
|
9a499a |
|
|
|
9a499a |
while ((offset = cache_get_offset(mm_base, offset, start, mm_root, &pos))) {
|
|
|
9a499a |
+ char key[PATH_MAX + 1];
|
|
|
9a499a |
+ int key_len = root_len + strlen(offset);
|
|
|
9a499a |
char *oe_base;
|
|
|
9a499a |
|
|
|
9a499a |
- oe = cache_lookup_offset(mm_base, offset, start, &me->multi_list);
|
|
|
9a499a |
+ if (mm_base_len > 1)
|
|
|
9a499a |
+ key_len += mm_base_len;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (key_len > PATH_MAX) {
|
|
|
9a499a |
+ warn(ap->logopt, "path loo long");
|
|
|
9a499a |
+ continue;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+
|
|
|
9a499a |
+ strcpy(key, root);
|
|
|
9a499a |
+ if (mm_base_len > 1)
|
|
|
9a499a |
+ strcat(key, mm_base);
|
|
|
9a499a |
+ strcat(key, offset);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ oe = cache_lookup_distinct(me->mc, key);
|
|
|
9a499a |
/* root offset is a special case */
|
|
|
9a499a |
if (!oe || (strlen(oe->key) - start) == 1)
|
|
|
9a499a |
continue;
|
|
|
9a499a |
@@ -2680,13 +2698,14 @@ int clean_stale_multi_triggers(struct au
|
|
|
9a499a |
char *root;
|
|
|
9a499a |
char mm_top[PATH_MAX + 1];
|
|
|
9a499a |
char path[PATH_MAX + 1];
|
|
|
9a499a |
- char buf[MAX_ERR_BUF];
|
|
|
9a499a |
char *offset;
|
|
|
9a499a |
struct mapent *oe;
|
|
|
9a499a |
struct list_head *mm_root, *pos;
|
|
|
9a499a |
const char o_root[] = "/";
|
|
|
9a499a |
const char *mm_base;
|
|
|
9a499a |
int left, start;
|
|
|
9a499a |
+ unsigned int root_len;
|
|
|
9a499a |
+ unsigned int mm_base_len;
|
|
|
9a499a |
time_t age;
|
|
|
9a499a |
|
|
|
9a499a |
if (top)
|
|
|
9a499a |
@@ -2714,14 +2733,30 @@ int clean_stale_multi_triggers(struct au
|
|
|
9a499a |
|
|
|
9a499a |
pos = NULL;
|
|
|
9a499a |
offset = path;
|
|
|
9a499a |
+ root_len = start;
|
|
|
9a499a |
+ mm_base_len = strlen(mm_base);
|
|
|
9a499a |
age = me->multi->age;
|
|
|
9a499a |
|
|
|
9a499a |
while ((offset = cache_get_offset(mm_base, offset, start, mm_root, &pos))) {
|
|
|
9a499a |
+ char key[PATH_MAX + 1];
|
|
|
9a499a |
+ int key_len = root_len + strlen(offset);
|
|
|
9a499a |
char *oe_base;
|
|
|
9a499a |
- char *key;
|
|
|
9a499a |
int ret;
|
|
|
9a499a |
|
|
|
9a499a |
- oe = cache_lookup_offset(mm_base, offset, start, &me->multi_list);
|
|
|
9a499a |
+ if (mm_base_len > 1)
|
|
|
9a499a |
+ key_len += mm_base_len;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (key_len > PATH_MAX) {
|
|
|
9a499a |
+ warn(ap->logopt, "path loo long");
|
|
|
9a499a |
+ continue;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+
|
|
|
9a499a |
+ strcpy(key, root);
|
|
|
9a499a |
+ if (mm_base_len > 1)
|
|
|
9a499a |
+ strcat(key, mm_base);
|
|
|
9a499a |
+ strcat(key, offset);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ oe = cache_lookup_distinct(me->mc, key);
|
|
|
9a499a |
/* root offset is a special case */
|
|
|
9a499a |
if (!oe || (strlen(oe->key) - start) == 1)
|
|
|
9a499a |
continue;
|
|
|
9a499a |
@@ -2772,14 +2807,6 @@ int clean_stale_multi_triggers(struct au
|
|
|
9a499a |
}
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
- key = strdup(oe->key);
|
|
|
9a499a |
- if (!key) {
|
|
|
9a499a |
- char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
9a499a |
- error(ap->logopt, "malloc: %s", estr);
|
|
|
9a499a |
- left++;
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
- }
|
|
|
9a499a |
-
|
|
|
9a499a |
debug(ap->logopt, "umount offset %s", oe->key);
|
|
|
9a499a |
|
|
|
9a499a |
if (umount_autofs_offset(ap, oe)) {
|
|
|
9a499a |
@@ -2794,7 +2821,6 @@ int clean_stale_multi_triggers(struct au
|
|
|
9a499a |
if (cache_delete_offset(oe->mc, key) == CHE_FAIL)
|
|
|
9a499a |
error(ap->logopt,
|
|
|
9a499a |
"failed to delete offset key %s", key);
|
|
|
9a499a |
- free(key);
|
|
|
9a499a |
continue;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
@@ -2810,7 +2836,6 @@ int clean_stale_multi_triggers(struct au
|
|
|
9a499a |
left++;
|
|
|
9a499a |
/* But we did origianlly create this */
|
|
|
9a499a |
oe->flags |= MOUNT_FLAG_DIR_CREATED;
|
|
|
9a499a |
- free(key);
|
|
|
9a499a |
continue;
|
|
|
9a499a |
}
|
|
|
9a499a |
/*
|
|
|
9a499a |
@@ -2828,7 +2853,6 @@ int clean_stale_multi_triggers(struct au
|
|
|
9a499a |
error(ap->logopt,
|
|
|
9a499a |
"failed to delete offset key %s", key);
|
|
|
9a499a |
}
|
|
|
9a499a |
- free(key);
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
return left;
|
|
|
9a499a |
--- autofs-5.1.4.orig/modules/parse_sun.c
|
|
|
9a499a |
+++ autofs-5.1.4/modules/parse_sun.c
|
|
|
9a499a |
@@ -1088,6 +1088,8 @@ static void cleanup_multi_triggers(struc
|
|
|
9a499a |
struct list_head *mm_root, *pos;
|
|
|
9a499a |
const char o_root[] = "/";
|
|
|
9a499a |
const char *mm_base;
|
|
|
9a499a |
+ unsigned int root_len;
|
|
|
9a499a |
+ unsigned int mm_base_len;
|
|
|
9a499a |
|
|
|
9a499a |
mm_root = &me->multi->multi_list;
|
|
|
9a499a |
|
|
|
9a499a |
@@ -1097,16 +1099,31 @@ static void cleanup_multi_triggers(struc
|
|
|
9a499a |
mm_base = base;
|
|
|
9a499a |
|
|
|
9a499a |
pos = NULL;
|
|
|
9a499a |
+ root_len = strlen(root);
|
|
|
9a499a |
+ mm_base_len = strlen(mm_base);
|
|
|
9a499a |
|
|
|
9a499a |
/* Make sure "none" of the offsets have an active mount. */
|
|
|
9a499a |
while ((poffset = cache_get_offset(mm_base, poffset, start, mm_root, &pos))) {
|
|
|
9a499a |
- oe = cache_lookup_offset(mm_base, poffset, start, &me->multi_list);
|
|
|
9a499a |
- /* root offset is a special case */
|
|
|
9a499a |
- if (!oe || !oe->mapent || (strlen(oe->key) - start) == 1)
|
|
|
9a499a |
+ unsigned int path_len = root_len + strlen(poffset);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (mm_base_len > 1)
|
|
|
9a499a |
+ path_len += mm_base_len;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (path_len > PATH_MAX) {
|
|
|
9a499a |
+ warn(ap->logopt, "path loo long");
|
|
|
9a499a |
continue;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
|
|
|
9a499a |
strcpy(path, root);
|
|
|
9a499a |
+ if (mm_base_len > 1)
|
|
|
9a499a |
+ strcat(path, mm_base);
|
|
|
9a499a |
strcat(path, poffset);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ oe = cache_lookup_distinct(me->mc, path);
|
|
|
9a499a |
+ /* root offset is a special case */
|
|
|
9a499a |
+ if (!oe || !oe->mapent || (strlen(oe->key) - start) == 1)
|
|
|
9a499a |
+ continue;
|
|
|
9a499a |
+
|
|
|
9a499a |
if (umount(path)) {
|
|
|
9a499a |
error(ap->logopt, "error recovering from mount fail");
|
|
|
9a499a |
error(ap->logopt, "cannot umount offset %s", path);
|
|
|
9a499a |
@@ -1119,17 +1136,14 @@ static void cleanup_multi_triggers(struc
|
|
|
9a499a |
static int mount_subtree(struct autofs_point *ap, struct mapent *me,
|
|
|
9a499a |
const char *name, char *loc, char *options, void *ctxt)
|
|
|
9a499a |
{
|
|
|
9a499a |
- struct mapent *mm;
|
|
|
9a499a |
struct mapent *ro;
|
|
|
9a499a |
char *mm_root, *mm_base, *mm_key;
|
|
|
9a499a |
- const char *mnt_root;
|
|
|
9a499a |
- unsigned int mm_root_len, mnt_root_len;
|
|
|
9a499a |
+ unsigned int mm_root_len;
|
|
|
9a499a |
int start, ret = 0, rv;
|
|
|
9a499a |
|
|
|
9a499a |
rv = 0;
|
|
|
9a499a |
|
|
|
9a499a |
- mm = me->multi;
|
|
|
9a499a |
- mm_key = mm->key;
|
|
|
9a499a |
+ mm_key = me->multi->key;
|
|
|
9a499a |
|
|
|
9a499a |
if (*mm_key == '/') {
|
|
|
9a499a |
mm_root = mm_key;
|
|
|
9a499a |
@@ -1143,20 +1157,26 @@ static int mount_subtree(struct autofs_p
|
|
|
9a499a |
}
|
|
|
9a499a |
mm_root_len = strlen(mm_root);
|
|
|
9a499a |
|
|
|
9a499a |
- mnt_root = mm_root;
|
|
|
9a499a |
- mnt_root_len = mm_root_len;
|
|
|
9a499a |
-
|
|
|
9a499a |
if (me == me->multi) {
|
|
|
9a499a |
+ char key[PATH_MAX + 1];
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (mm_root_len + 1 > PATH_MAX) {
|
|
|
9a499a |
+ warn(ap->logopt, "path loo long");
|
|
|
9a499a |
+ return 1;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+
|
|
|
9a499a |
/* name = NULL */
|
|
|
9a499a |
/* destination = mm_root */
|
|
|
9a499a |
mm_base = "/";
|
|
|
9a499a |
|
|
|
9a499a |
+ strcpy(key, mm_root);
|
|
|
9a499a |
+ strcat(key, mm_base);
|
|
|
9a499a |
+
|
|
|
9a499a |
/* Mount root offset if it exists */
|
|
|
9a499a |
- ro = cache_lookup_offset(mm_base, mm_base, strlen(mm_root), &me->multi_list);
|
|
|
9a499a |
+ ro = cache_lookup_distinct(me->mc, key);
|
|
|
9a499a |
if (ro) {
|
|
|
9a499a |
- char *myoptions, *ro_loc, *tmp;
|
|
|
9a499a |
+ char *myoptions, *ro_loc;
|
|
|
9a499a |
int namelen = name ? strlen(name) : 0;
|
|
|
9a499a |
- const char *root;
|
|
|
9a499a |
int ro_len;
|
|
|
9a499a |
|
|
|
9a499a |
myoptions = NULL;
|
|
|
9a499a |
@@ -1174,13 +1194,7 @@ static int mount_subtree(struct autofs_p
|
|
|
9a499a |
if (ro_loc)
|
|
|
9a499a |
ro_len = strlen(ro_loc);
|
|
|
9a499a |
|
|
|
9a499a |
- tmp = alloca(mnt_root_len + 2);
|
|
|
9a499a |
- strcpy(tmp, mnt_root);
|
|
|
9a499a |
- tmp[mnt_root_len] = '/';
|
|
|
9a499a |
- tmp[mnt_root_len + 1] = '\0';
|
|
|
9a499a |
- root = tmp;
|
|
|
9a499a |
-
|
|
|
9a499a |
- rv = sun_mount(ap, root, name, namelen, ro_loc, ro_len, myoptions, ctxt);
|
|
|
9a499a |
+ rv = sun_mount(ap, key, name, namelen, ro_loc, ro_len, myoptions, ctxt);
|
|
|
9a499a |
|
|
|
9a499a |
free(myoptions);
|
|
|
9a499a |
if (ro_loc)
|
|
|
9a499a |
@@ -1188,11 +1202,11 @@ static int mount_subtree(struct autofs_p
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
if (ro && rv == 0) {
|
|
|
9a499a |
- ret = mount_multi_triggers(ap, me, mnt_root, start, mm_base);
|
|
|
9a499a |
+ ret = mount_multi_triggers(ap, me, mm_root, start, mm_base);
|
|
|
9a499a |
if (ret == -1) {
|
|
|
9a499a |
error(ap->logopt, MODPREFIX
|
|
|
9a499a |
"failed to mount offset triggers");
|
|
|
9a499a |
- cleanup_multi_triggers(ap, me, mnt_root, start, mm_base);
|
|
|
9a499a |
+ cleanup_multi_triggers(ap, me, mm_root, start, mm_base);
|
|
|
9a499a |
return 1;
|
|
|
9a499a |
}
|
|
|
9a499a |
} else if (rv <= 0) {
|
|
|
9a499a |
@@ -1208,24 +1222,29 @@ static int mount_subtree(struct autofs_p
|
|
|
9a499a |
int loclen = strlen(loc);
|
|
|
9a499a |
int namelen = strlen(name);
|
|
|
9a499a |
|
|
|
9a499a |
- mnt_root = name;
|
|
|
9a499a |
-
|
|
|
9a499a |
/* name = mm_root + mm_base */
|
|
|
9a499a |
/* destination = mm_root + mm_base = name */
|
|
|
9a499a |
mm_base = &me->key[start];
|
|
|
9a499a |
|
|
|
9a499a |
- rv = sun_mount(ap, mnt_root, name, namelen, loc, loclen, options, ctxt);
|
|
|
9a499a |
+ rv = sun_mount(ap, name, name, namelen, loc, loclen, options, ctxt);
|
|
|
9a499a |
if (rv == 0) {
|
|
|
9a499a |
- ret = mount_multi_triggers(ap, me->multi, mnt_root, start, mm_base);
|
|
|
9a499a |
+ ret = mount_multi_triggers(ap, me->multi, name, start, mm_base);
|
|
|
9a499a |
if (ret == -1) {
|
|
|
9a499a |
error(ap->logopt, MODPREFIX
|
|
|
9a499a |
"failed to mount offset triggers");
|
|
|
9a499a |
- cleanup_multi_triggers(ap, me, mnt_root, start, mm_base);
|
|
|
9a499a |
+ cleanup_multi_triggers(ap, me, name, start, mm_base);
|
|
|
9a499a |
return 1;
|
|
|
9a499a |
}
|
|
|
9a499a |
} else if (rv < 0) {
|
|
|
9a499a |
- char *mm_root_base = alloca(strlen(mm_root) + strlen(mm_base) + 1);
|
|
|
9a499a |
+ char mm_root_base[PATH_MAX + 1];
|
|
|
9a499a |
+ unsigned int mm_root_base_len = mm_root_len + strlen(mm_base) + 1;
|
|
|
9a499a |
|
|
|
9a499a |
+ if (mm_root_base_len > PATH_MAX) {
|
|
|
9a499a |
+ warn(ap->logopt, MODPREFIX "path too long");
|
|
|
9a499a |
+ cache_delete_offset_list(me->mc, name);
|
|
|
9a499a |
+ return 1;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+
|
|
|
9a499a |
strcpy(mm_root_base, mm_root);
|
|
|
9a499a |
strcat(mm_root_base, mm_base);
|
|
|
9a499a |
|