diff options
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/Makefile.am | 5 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.c | 18 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 5 |
3 files changed, 27 insertions, 1 deletions
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 <ifaddrs.h> #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, |