From 292b4e42fdc023e307fde35e189285040d4b9cdd Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Wed, 28 Jun 2017 05:09:12 -0400 Subject: contrib/xxhash: Add xxhash library xxhash is a faster non-cryptographic hash. https://github.com/Cyan4973/xxHash Release Taken: "xxHash v0.6.2" -------------- Files added: contrib/xxhash/xxhash.c contrib/xxhash/xxhash.h contrib/xxhash/xxhsum.c Modifications to source: ------------------------ Following functions and data types got 'GF_' prefix as below to avoid any form of name collisions in future. ---- Functions ---- GF_XXH_versionNumber GF_XXH32 GF_XXH32_createState GF_XXH32_freeState GF_XXH32_copyState GF_XXH32_reset GF_XXH32_update GF_XXH32_digest GF_XXH32_canonicalFromHash GF_XXH32_hashFromCanonical GF_XXH64 GF_XXH64_createState GF_XXH64_freeState GF_XXH64_copyState GF_XXH64_reset GF_XXH64_update GF_XXH64_digest GF_XXH64_canonicalFromHash GF_XXH64_hashFromCanonical ---- Data Types ---- GF_XXH_errorcode GF_XXH32_state_t* GF_XXH32_canonical_t* GF_XXH32_hash_t GF_XXH64_state_t* GF_XXH64_canonical_t* GF_XXH64_hash_t It is linked with libglusterfs.so. A wrapper funtion is also added for the easy usage in common-utils.c. xxhash can be used for the all the usecases where a faster non-cryptographic hash is required. gfid to path infra would be using this for now. NOTE: ---- The gluster coding guidelines check is ignored as maintaining it further would be difficult. Updates: #253 Change-Id: Ib143f90d91d4ee99864a10246d5983e92900173b Signed-off-by: Kotresh HR Reviewed-on: https://review.gluster.org/17641 Smoke: Gluster Build System Reviewed-by: Amar Tumballi CentOS-regression: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: Niels de Vos --- libglusterfs/src/Makefile.am | 5 ++++- libglusterfs/src/common-utils.c | 18 ++++++++++++++++++ libglusterfs/src/common-utils.h | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index 52b73166ddb..768fe042a10 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -9,7 +9,8 @@ libglusterfs_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \ -I$(top_srcdir)/rpc/xdr/src/ -I$(top_builddir)/rpc/xdr/src/ \ -I$(top_srcdir)/rpc/rpc-lib/src/ -I$(CONTRIBDIR)/rbtree \ -I$(CONTRIBDIR)/libexecinfo ${ARGP_STANDALONE_CPPFLAGS} \ - -DSBIN_DIR=\"$(sbindir)\" -I$(CONTRIBDIR)/timer-wheel + -DSBIN_DIR=\"$(sbindir)\" -I$(CONTRIBDIR)/timer-wheel \ + -I$(CONTRIBDIR)/xxhash libglusterfs_la_LIBADD = @LEXLIB@ $(ZLIB_LIBS) $(MATH_LIB) $(UUID_LIBS) libglusterfs_la_LDFLAGS = -version-info $(LIBGLUSTERFS_LT_VERSION) @@ -33,6 +34,7 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \ $(CONTRIBDIR)/libexecinfo/execinfo.c quota-common-utils.c rot-buffs.c \ $(CONTRIBDIR)/timer-wheel/timer-wheel.c \ $(CONTRIBDIR)/timer-wheel/find_last_bit.c default-args.c locking.c \ + $(CONTRIBDIR)/xxhash/xxhash.c \ compound-fop-utils.c throttle-tbf.c nodist_libglusterfs_la_SOURCES = y.tab.c graph.lex.c defaults.c @@ -62,6 +64,7 @@ noinst_HEADERS = unittest/unittest.h \ $(CONTRIBDIR)/mount/mntent_compat.h \ $(CONTRIBDIR)/libexecinfo/execinfo_compat.h \ $(CONTRIBDIR)/timer-wheel/timer-wheel.h \ + $(CONTRIBDIR)/xxhash/xxhash.h \ tier-ctr-interface.h if !HAVE_LIBUUID diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 65557fefba2..5015d9666b6 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -49,6 +49,7 @@ #include "lkowner.h" #include "syscall.h" #include "cli1-xdr.h" +#include "xxhash.h" #include #include "libglusterfs-messages.h" @@ -82,6 +83,23 @@ md5_wrapper(const unsigned char *data, size_t len, char *md5) snprintf(md5 + i * 2, lim-i*2, "%02x", scratch[i]); } +void +gf_xxh64_wrapper(const unsigned char *data, size_t len, unsigned long long seed, + char *xxh64) +{ + unsigned short i = 0; + unsigned short lim = GF_XXH64_DIGEST_LENGTH*2+1; + GF_XXH64_hash_t hash = 0; + GF_XXH64_canonical_t c_hash = {{0,},}; + const uint8_t *p = (const uint8_t *) &c_hash; + + hash = GF_XXH64(data, len, seed); + GF_XXH64_canonicalFromHash(&c_hash, hash); + + for (i = 0; i < GF_XXH64_DIGEST_LENGTH; i++) + snprintf(xxh64 + i * 2, lim-i*2, "%02x", p[i]); +} + /* works similar to mkdir(1) -p. */ int diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 6bd24179592..c3c5ec77350 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -113,6 +113,9 @@ void trap (void); /* Default value of signing waiting time to sign a file for bitrot */ #define SIGNING_TIMEOUT "120" +/* xxhash */ +#define GF_XXH64_DIGEST_LENGTH 8 + /* Shard */ #define GF_XATTR_SHARD_FILE_SIZE "trusted.glusterfs.shard.file-size" #define SHARD_ROOT_GFID "be318638-e8a0-4c6d-977d-7a937aa84806" @@ -823,6 +826,8 @@ int gf_get_hostname_from_ip (char *client_ip, char **hostname); gf_boolean_t gf_is_local_addr (char *hostname); gf_boolean_t gf_is_same_address (char *host1, char *host2); void md5_wrapper(const unsigned char *data, size_t len, char *md5); +void gf_xxh64_wrapper(const unsigned char *data, size_t len, + unsigned long long seed, char *xxh64); int gf_set_timestamp (const char *src, const char* dest); int gf_thread_create (pthread_t *thread, const pthread_attr_t *attr, -- cgit