Blame SOURCES/autofs-5.1.6-make-external-mounts-use-simpler-hashtable.patch

49b67f
autofs-5.1.6 - make external mounts use simpler hashtable
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Use the added hashtable implementation for the external mounts
49b67f
hashtable.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG    |    1 +
49b67f
 lib/mounts.c |   49 +++++++++++++++----------------------------------
49b67f
 2 files changed, 16 insertions(+), 34 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -120,6 +120,7 @@ xx/xx/2018 autofs-5.1.5
49b67f
 - add hashtable implementation.
49b67f
 - change mountpoint to mp in struct ext_mount.
49b67f
 - make external mounts independent of amd_entry.
49b67f
+- make external mounts use simpler hashtable.
49b67f
 
49b67f
 19/12/2017 autofs-5.1.4
49b67f
 - fix spec file url.
49b67f
--- autofs-5.1.4.orig/lib/mounts.c
49b67f
+++ autofs-5.1.4/lib/mounts.c
49b67f
@@ -29,6 +29,7 @@
49b67f
 #include <libgen.h>
49b67f
 
49b67f
 #include "automount.h"
49b67f
+#include "hashtable.h"
49b67f
 
49b67f
 #define MAX_OPTIONS_LEN		80
49b67f
 #define MAX_MNT_NAME_LEN	30
49b67f
@@ -51,16 +52,15 @@ static const char kver_options_template[
49b67f
 extern size_t detached_thread_stack_size;
49b67f
 static size_t maxgrpbuf = 0;
49b67f
 
49b67f
-#define EXT_MOUNTS_HASH_SIZE    50
49b67f
+#define EXT_MOUNTS_HASH_BITS	6
49b67f
 
49b67f
 struct ext_mount {
49b67f
 	unsigned int ref;
49b67f
 	char *mp;
49b67f
 	char *umount;
49b67f
-	struct list_head mount;
49b67f
+	struct hlist_node mount;
49b67f
 };
49b67f
-static struct list_head ext_mounts_hash[EXT_MOUNTS_HASH_SIZE];
49b67f
-static unsigned int ext_mounts_hash_init_done = 0;
49b67f
+static DEFINE_HASHTABLE(ext_mounts_hash, EXT_MOUNTS_HASH_BITS);
49b67f
 static pthread_mutex_t ext_mount_hash_mutex = PTHREAD_MUTEX_INITIALIZER;
49b67f
 
49b67f
 unsigned int linux_version_code(void)
49b67f
@@ -734,38 +734,22 @@ char *make_mnt_name_string(char *path)
49b67f
 	return mnt_name;
49b67f
 }
49b67f
 
49b67f
-static void ext_mounts_hash_init(void)
49b67f
-{
49b67f
-	int i;
49b67f
-	for (i = 0; i < EXT_MOUNTS_HASH_SIZE; i++)
49b67f
-		INIT_LIST_HEAD(&ext_mounts_hash[i]);
49b67f
-	ext_mounts_hash_init_done = 1;
49b67f
-}
49b67f
-
49b67f
 static struct ext_mount *ext_mount_lookup(const char *mp)
49b67f
 {
49b67f
-	u_int32_t hval = hash(mp, EXT_MOUNTS_HASH_SIZE);
49b67f
-	struct list_head *p, *head;
49b67f
-
49b67f
-	if (!ext_mounts_hash_init_done)
49b67f
-		ext_mounts_hash_init();
49b67f
-
49b67f
-	if (list_empty(&ext_mounts_hash[hval]))
49b67f
-		return NULL;
49b67f
+	uint32_t hval = hash(mp, HASH_SIZE(ext_mounts_hash));
49b67f
+	struct ext_mount *this;
49b67f
 
49b67f
-	head = &ext_mounts_hash[hval];
49b67f
-	list_for_each(p, head) {
49b67f
-		struct ext_mount *this = list_entry(p, struct ext_mount, mount);
49b67f
+	hlist_for_each_entry(this, &ext_mounts_hash[hval], mount) {
49b67f
 		if (!strcmp(this->mp, mp))
49b67f
 			return this;
49b67f
 	}
49b67f
+
49b67f
 	return NULL;
49b67f
 }
49b67f
 
49b67f
 int ext_mount_add(const char *path, const char *umount)
49b67f
 {
49b67f
 	struct ext_mount *em;
49b67f
-	u_int32_t hval;
49b67f
 	int ret = 0;
49b67f
 
49b67f
 	pthread_mutex_lock(&ext_mount_hash_mutex);
49b67f
@@ -796,10 +780,9 @@ int ext_mount_add(const char *path, cons
49b67f
 		}
49b67f
 	}
49b67f
 	em->ref = 1;
49b67f
-	INIT_LIST_HEAD(&em->mount);
49b67f
+	INIT_HLIST_NODE(&em->mount);
49b67f
 
49b67f
-	hval = hash(path, EXT_MOUNTS_HASH_SIZE);
49b67f
-	list_add_tail(&em->mount, &ext_mounts_hash[hval]);
49b67f
+	hash_add_str(ext_mounts_hash, &em->mount, em->mp);
49b67f
 
49b67f
 	ret = 1;
49b67f
 done:
49b67f
@@ -822,13 +805,11 @@ int ext_mount_remove(const char *path)
49b67f
 	if (em->ref)
49b67f
 		goto done;
49b67f
 	else {
49b67f
-		list_del_init(&em->mount);
49b67f
-		if (list_empty(&em->mount)) {
49b67f
-			free(em->mp);
49b67f
-			if (em->umount)
49b67f
-				free(em->umount);
49b67f
-			free(em);
49b67f
-		}
49b67f
+		hlist_del_init(&em->mount);
49b67f
+		free(em->mp);
49b67f
+		if (em->umount)
49b67f
+			free(em->umount);
49b67f
+		free(em);
49b67f
 		ret = 1;
49b67f
 	}
49b67f
 done: