Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Mon, 6 Jan 2003 23:54:59 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Mon, 6 Jan 2003 23:54:59 -0500 Received: from tone.orchestra.cse.unsw.EDU.AU ([129.94.242.28]:9673 "HELO tone.orchestra.cse.unsw.EDU.AU") by vger.kernel.org with SMTP id ; Mon, 6 Jan 2003 23:54:56 -0500 From: Neil Brown To: Linus Torvalds Date: Tue, 7 Jan 2003 16:03:28 +1100 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15898.24480.346258.361959@notabene.cse.unsw.edu.au> cc: linux-kernel@vger.kernel.org Subject: [PATCH] Define hash_mem in lib/hash.c to apply hash_long to an arbitraty piece of memory. X-Mailer: VM 7.07 under Emacs 20.7.2 X-face: [Gw_3E*Gng}4rRrKRYotwlE?.2|**#s9D #include #include -#include struct svc_cred { uid_t cr_uid; @@ -113,12 +112,6 @@ extern struct auth_domain *auth_unix_loo extern int auth_unix_forget_old(struct auth_domain *dom); extern void svcauth_unix_purge(void); -extern int hash_mem(char *buf, int len, int bits); -static inline int hash_str(char *name, int bits) -{ - return hash_mem(name, strlen(name), bits); -} - extern struct cache_detail auth_domain_cache, ip_map_cache; #endif /* __KERNEL__ */ diff ./lib/Makefile~current~ ./lib/Makefile --- ./lib/Makefile~current~ 2003-01-07 14:43:38.000000000 +1100 +++ ./lib/Makefile 2003-01-07 13:51:45.000000000 +1100 @@ -9,11 +9,11 @@ L_TARGET := lib.a export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o \ - crc32.o rbtree.o radix-tree.o kobject.o + crc32.o rbtree.o radix-tree.o kobject.o hash.o obj-y := errno.o ctype.o string.o vsprintf.o brlock.o cmdline.o \ bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \ - kobject.o + kobject.o hash.o obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o diff ./lib/hash.c~current~ ./lib/hash.c --- ./lib/hash.c~current~ 2003-01-07 14:43:38.000000000 +1100 +++ ./lib/hash.c 2003-01-07 14:00:53.000000000 +1100 @@ -0,0 +1,47 @@ +/* + * linux/lib/hash.c + * + * No Copyright Claimed. + * Author: Neil Brown + */ + +#include +#include +#include +#include + +#define BYTES_PER_LONG (BITS_PER_LONG/8) +#define IsLongAligned(ptr) (((unsigned long)ptr & (BYTES_PER_LONG-1))==0) +unsigned long hash_mem(void *buf, unsigned int len, unsigned int bits) +{ + int hash = 0; + unsigned long l; + + if (unlikely(IsLongAligned(buf))) { + + /* Some architectures don't like dereferencing a long + * pointer that isn't aligned, so we do it by hand... + */ + while (len >= BYTES_PER_LONG) { + memcpy(&l, buf, BYTES_PER_LONG); + buf += BYTES_PER_LONG; + len -= BYTES_PER_LONG; + hash ^= hash_long(l, bits); + } + } else { + while (len >= BYTES_PER_LONG) { + l = *(unsigned long *)buf; + buf += BYTES_PER_LONG; + len -= BYTES_PER_LONG; + hash ^= hash_long(l, bits); + } + } + if (len) { + l=0; + memcpy((char*)&l, buf, len); + hash ^= hash_long(l, bits); + } + return hash; +} + +EXPORT_SYMBOL(hash_mem); diff ./net/sunrpc/svcauth.c~current~ ./net/sunrpc/svcauth.c --- ./net/sunrpc/svcauth.c~current~ 2003-01-07 14:43:38.000000000 +1100 +++ ./net/sunrpc/svcauth.c 2003-01-07 14:44:02.000000000 +1100 @@ -17,6 +17,7 @@ #include #include #include +#include #define RPCDBG_FACILITY RPCDBG_AUTH @@ -97,25 +98,6 @@ svc_auth_unregister(rpc_authflavor_t fla * it will complain. */ -int hash_mem(char *buf, int len, int bits) -{ - int hash = 0; - unsigned long l; - while (len >= BITS_PER_LONG/8) { - l = *(unsigned long *)buf; - buf += BITS_PER_LONG/8; - len -= BITS_PER_LONG/8; - hash ^= hash_long(l, bits); - } - if (len) { - l=0; - memcpy((char*)&l, buf, len); - hash ^= hash_long(l, bits); - } - return hash; -} - - /* * Auth auth_domain cache is somewhat different to other caches, * largely because the entries are possibly of different types: diff ./net/sunrpc/svcauth_unix.c~current~ ./net/sunrpc/svcauth_unix.c --- ./net/sunrpc/svcauth_unix.c~current~ 2003-01-07 14:43:38.000000000 +1100 +++ ./net/sunrpc/svcauth_unix.c 2003-01-07 14:31:11.000000000 +1100 @@ -7,6 +7,7 @@ #include #include #include +#include #define RPCDBG_FACILITY RPCDBG_AUTH - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/