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

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