cluster: STABLE3 - cman: move fnv hash function into its own file

Christine Caulfield chrissie at fedoraproject.org
Fri Mar 26 11:45:14 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=bc01b7a1a057aaed39fde3daa7f484de276cedcb
Commit:        bc01b7a1a057aaed39fde3daa7f484de276cedcb
Parent:        980cb15f64083b3f7fc2e74b5e43588616a7e282
Author:        Christine Caulfield <ccaulfie at redhat.com>
AuthorDate:    Fri Mar 26 11:44:39 2010 +0000
Committer:     Christine Caulfield <ccaulfie at redhat.com>
CommitterDate: Fri Mar 26 11:44:39 2010 +0000

cman: move fnv hash function into its own file

And add it to the COPYRIGHT exceptions file too.

Signed-off-by: Christine Caulfield <ccaulfie at redhat.com>
---
 cman/daemon/Makefile         |    3 +-
 cman/daemon/cman-preconfig.c |  105 +++--------------------------------------
 cman/daemon/fnvhash.c        |   93 +++++++++++++++++++++++++++++++++++++
 cman/daemon/fnvhash.h        |    1 +
 doc/COPYRIGHT                |    6 ++
 5 files changed, 110 insertions(+), 98 deletions(-)

diff --git a/cman/daemon/Makefile b/cman/daemon/Makefile
index 9a495eb..1329de3 100644
--- a/cman/daemon/Makefile
+++ b/cman/daemon/Makefile
@@ -23,7 +23,8 @@ OBJS1=	daemon.o \
 	barrier.o \
 	cmanconfig.o
 
-OBJS2=	cman-preconfig.o
+OBJS2=	cman-preconfig.o \
+	fnvhash.o
 
 ${TARGET1}: ${OBJS1}
 	$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
diff --git a/cman/daemon/cman-preconfig.c b/cman/daemon/cman-preconfig.c
index 3339f1d..e8248b4 100644
--- a/cman/daemon/cman-preconfig.c
+++ b/cman/daemon/cman-preconfig.c
@@ -25,6 +25,7 @@
 #define OBJDB_API struct objdb_iface_ver0
 #include "cnxman-socket.h"
 #include "nodelist.h"
+#include "fnvhash.h"
 
 #define MAX_PATH_LEN PATH_MAX
 
@@ -284,99 +285,6 @@ static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr,
 	return ret;
 }
 
-
-/***
- *
- * Fowler/Noll/Vo hash
- *
- * The basis of this hash algorithm was taken from an idea sent
- * as reviewer comments to the IEEE POSIX P1003.2 committee by:
- *
- *      Phong Vo (http://www.research.att.com/info/kpv/)
- *      Glenn Fowler (http://www.research.att.com/~gsf/)
- *
- * In a subsequent ballot round:
- *
- *      Landon Curt Noll (http://www.isthe.com/chongo/)
- *
- * improved on their algorithm.  Some people tried this hash
- * and found that it worked rather well.  In an EMail message
- * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash.
- *
- * FNV hashes are designed to be fast while maintaining a low
- * collision rate. The FNV speed allows one to quickly hash lots
- * of data while maintaining a reasonable collision rate.  See:
- *
- *      http://www.isthe.com/chongo/tech/comp/fnv/index.html
- *
- * for more details as well as other forms of the FNV hash.
- ***
- *
- * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the
- * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str().
- *
- ***
- *
- * Please do not copyright this code.  This code is in the public domain.
- *
- * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
- * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
- * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
- * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * By:
- *	chongo <Landon Curt Noll> /\oo/\
- *      http://www.isthe.com/chongo/
- *
- * Share and Enjoy!	:-)
- */
-
-/* 
- * Modified to be a little more simple to understand and to provide a 16 bit
- * value rather then 32 bit for cluster id generation
- *
- * sdake at redhat.com
- */
-
-/* 32 bit magic FNV-1a prime */
-#define FNV_32_PRIME ((uint32_t)0x01000193)
-
-/* Default initialization for FNV-1a */
-#define FNV_32_INIT ((uint32_t)0x811c9dc5)
-
-static uint16_t generate_hashed_cluster_id(char *str)
-{
-	unsigned char *s = (unsigned char *)str;
-	uint32_t hval = FNV_32_INIT;
-	uint32_t ret;
-
-	/*
-	* FNV-1a hash each octet in the buffer
-	*/
-	while (*s) {
-		/*
-		 * xor the bottom with the current octet
-		 */
-		hval ^= (uint32_t)*s++;
-		/*
-		 * multiply by the 32 bit FNV magic prime mod 2^32
-		 */
-		hval *= FNV_32_PRIME;
-	}
-
-	/*
-	 * Use XOR folding as recommended by authors of algorithm
-	 * to create a different hash size that is a power of two
-	 */
-	ret = (hval >> 16) ^ (hval & 0xFFFF);
-
-	sprintf(error_reason, "Generated hashed cluster id for '%s' is %d\n", str, ret);
-	return (ret);
-}
-
 static uint16_t generate_cluster_id(char *name)
 {
 	int i;
@@ -386,7 +294,6 @@ static uint16_t generate_cluster_id(char *name)
 		value <<= 1;
 		value += name[i];
 	}
-	sprintf(error_reason, "Generated cluster id for '%s' is %d\n", name, value & 0xFFFF);
 	return value & 0xFFFF;
 }
 
@@ -1012,9 +919,11 @@ static int set_noccs_defaults(struct objdb_iface_ver0 *objdb)
 
 	if (!cluster_id) {
 	    if (use_hashed_cluster_id)
-	        cluster_id = generate_hashed_cluster_id(cluster_name);
+	        cluster_id = fnv_hash(cluster_name);
 	    else
 	        cluster_id = generate_cluster_id(cluster_name);
+
+	    sprintf(error_reason, "Generated cluster id for '%s' is %d\n", cluster_name, cluster_id);
 	}
 
 	if (!nodename_env) {
@@ -1206,9 +1115,11 @@ static int get_cman_globals(struct objdb_iface_ver0 *objdb)
 
 		if (!cluster_id) {
 		    if (use_hashed_cluster_id)
-		        cluster_id = generate_hashed_cluster_id(cluster_name);
+		        cluster_id = fnv_hash(cluster_name);
 		    else
 		        cluster_id = generate_cluster_id(cluster_name);
+
+		    sprintf(error_reason, "Generated cluster id for '%s' is %d\n", cluster_name, cluster_id);
 		}
 	}
 	objdb->object_find_destroy(find_handle);
@@ -1311,7 +1222,7 @@ static void setup_old_compat(struct objdb_iface_ver0 *objdb, hdb_handle_t cluste
 	hdb_handle_t totem_handle;
 	hdb_handle_t gfs_handle;
 	char *value;
-	
+
 	use_hashed_cluster_id = 0;
 
 	/* Set groupd to backwards compatibility mode */
diff --git a/cman/daemon/fnvhash.c b/cman/daemon/fnvhash.c
new file mode 100644
index 0000000..47e221a
--- /dev/null
+++ b/cman/daemon/fnvhash.c
@@ -0,0 +1,93 @@
+#include <stdint.h>
+#include "fnvhash.h"
+
+/***
+ *
+ * Fowler/Noll/Vo hash
+ *
+ * The basis of this hash algorithm was taken from an idea sent
+ * as reviewer comments to the IEEE POSIX P1003.2 committee by:
+ *
+ *      Phong Vo (http://www.research.att.com/info/kpv/)
+ *      Glenn Fowler (http://www.research.att.com/~gsf/)
+ *
+ * In a subsequent ballot round:
+ *
+ *      Landon Curt Noll (http://www.isthe.com/chongo/)
+ *
+ * improved on their algorithm.  Some people tried this hash
+ * and found that it worked rather well.  In an EMail message
+ * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash.
+ *
+ * FNV hashes are designed to be fast while maintaining a low
+ * collision rate. The FNV speed allows one to quickly hash lots
+ * of data while maintaining a reasonable collision rate.  See:
+ *
+ *      http://www.isthe.com/chongo/tech/comp/fnv/index.html
+ *
+ * for more details as well as other forms of the FNV hash.
+ ***
+ *
+ * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the
+ * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str().
+ *
+ ***
+ *
+ * Please do not copyright this code.  This code is in the public domain.
+ *
+ * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
+ * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ * By:
+ *	chongo <Landon Curt Noll> /\oo/\
+ *      http://www.isthe.com/chongo/
+ *
+ * Share and Enjoy!	:-)
+ */
+
+/* 
+ * Modified to be a little more simple to understand and to provide a 16 bit
+ * value rather then 32 bit for cluster id generation
+ *
+ * sdake at redhat.com
+ */
+
+/* 32 bit magic FNV-1a prime */
+#define FNV_32_PRIME ((uint32_t)0x01000193)
+
+/* Default initialization for FNV-1a */
+#define FNV_32_INIT ((uint32_t)0x811c9dc5)
+
+uint16_t fnv_hash(char *str)
+{
+	unsigned char *s = (unsigned char *)str;
+	uint32_t hval = FNV_32_INIT;
+	uint32_t ret;
+
+	/*
+	* FNV-1a hash each octet in the buffer
+	*/
+	while (*s) {
+		/*
+		 * xor the bottom with the current octet
+		 */
+		hval ^= (uint32_t)*s++;
+		/*
+		 * multiply by the 32 bit FNV magic prime mod 2^32
+		 */
+		hval *= FNV_32_PRIME;
+	}
+
+	/*
+	 * Use XOR folding as recommended by authors of algorithm
+	 * to create a different hash size that is a power of two
+	 */
+	ret = (hval >> 16) ^ (hval & 0xFFFF);
+
+	return (ret);
+}
diff --git a/cman/daemon/fnvhash.h b/cman/daemon/fnvhash.h
new file mode 100644
index 0000000..65e9c11
--- /dev/null
+++ b/cman/daemon/fnvhash.h
@@ -0,0 +1 @@
+uint16_t fnv_hash(char *str);
diff --git a/doc/COPYRIGHT b/doc/COPYRIGHT
index 313587b..55331b3 100644
--- a/doc/COPYRIGHT
+++ b/doc/COPYRIGHT
@@ -27,6 +27,12 @@ cman/qdisk/scandisk.{c,h}:
  Original design by: Joel Becker <Joel.Becker at oracle.com> and
  Fabio M. Di Nitto <fdinitto at redhat.com>
 
+cman/daemon/fnvhash.c
+ This code is in the public domain.
+ Phong Vo (http://www.research.att.com/info/kpv/)
+ Glenn Fowler (http://www.research.att.com/~gsf/)
+ Landon Curt Noll (http://www.isthe.com/chongo/)
+
 dlm/doc/example.c:
  Author: Daniel Phillips <phillips at redhat.com>
 


More information about the cluster-commits mailing list