diff options
author | Jeremy Allison <jra@samba.org> | 2004-08-25 01:04:02 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2004-08-25 01:04:02 +0000 |
commit | 44bf3b98ef133ba7ee985859da7b90e53d98c871 (patch) | |
tree | 8e9788515f66956e48f0df08c4b88f3818899f03 /source | |
parent | 3733e75a5bec23c07c196a95df14b4751c5fb134 (diff) | |
download | samba-44bf3b98ef133ba7ee985859da7b90e53d98c871.tar.gz samba-44bf3b98ef133ba7ee985859da7b90e53d98c871.tar.xz samba-44bf3b98ef133ba7ee985859da7b90e53d98c871.zip |
r2032: If you're selecting a hash algorithm for tdb, you need to do it at open time,
it doesn't make sense anywhere else.
Jeremy.
Diffstat (limited to 'source')
-rw-r--r-- | source/smbd/statcache.c | 36 | ||||
-rw-r--r-- | source/tdb/tdb.c | 12 | ||||
-rw-r--r-- | source/tdb/tdb.h | 4 | ||||
-rw-r--r-- | source/tdb/tdbutil.c | 2 |
4 files changed, 21 insertions, 33 deletions
diff --git a/source/smbd/statcache.c b/source/smbd/statcache.c index 07a9e3ca858..dfc1a6ed959 100644 --- a/source/smbd/statcache.c +++ b/source/smbd/statcache.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. stat cache code Copyright (C) Andrew Tridgell 1992-2000 - Copyright (C) Jeremy Allison 1999-2000 + Copyright (C) Jeremy Allison 1999-2004 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003 This program is free software; you can redistribute it and/or modify @@ -280,16 +280,11 @@ BOOL stat_cache_lookup(connection_struct *conn, pstring name, pstring dirpath, } } -/* - ************************************************************** - * Compute a hash value based on a string key value. - * Make the string key into an array of int's if possible. - * For the last few chars that cannot be int'ed, use char instead. - * The function returns the bucket index number for the hashed - * key. - * JRA. Use a djb-algorithm hash for speed. - ************************************************************** - */ +/*************************************************************** + Compute a hash value based on a string key value. + The function returns the bucket index number for the hashed key. + JRA. Use a djb-algorithm hash for speed. +***************************************************************/ static u32 string_hash(TDB_DATA *key) { @@ -301,14 +296,10 @@ static u32 string_hash(TDB_DATA *key) return n; } -/*************************************************************************** ** - * Initializes or clears the stat cache. - * - * Input: none. - * Output: none. - * - * ************************************************************************** ** - */ +/*************************************************************************** + Initializes or clears the stat cache. +**************************************************************************/ + BOOL reset_stat_cache( void ) { if (!lp_stat_cache()) @@ -318,10 +309,11 @@ BOOL reset_stat_cache( void ) tdb_close(tdb_stat_cache); } - /* Create the in-memory tdb. */ - tdb_stat_cache = tdb_open_log("statcache", 0, TDB_INTERNAL, (O_RDWR|O_CREAT), 0644); + /* Create the in-memory tdb using our custom hash function. */ + tdb_stat_cache = tdb_open_ex("statcache", 0, TDB_INTERNAL, + (O_RDWR|O_CREAT), 0644, NULL, string_hash); + if (!tdb_stat_cache) return False; - tdb_set_hash_function(tdb_stat_cache, string_hash); return True; } diff --git a/source/tdb/tdb.c b/source/tdb/tdb.c index 0ebbc8b21eb..9a059d459ef 100644 --- a/source/tdb/tdb.c +++ b/source/tdb/tdb.c @@ -1689,11 +1689,6 @@ static u32 default_tdb_hash(TDB_DATA *key) return (1103515243 * value + 12345); } -void tdb_set_hash_function(TDB_CONTEXT *tdb, tdb_hash_func fn) -{ - tdb->hash_fn = fn; -} - /* open the database, creating it if necessary The open_flags and mode are passed straight to the open call on the @@ -1707,13 +1702,14 @@ void tdb_set_hash_function(TDB_CONTEXT *tdb, tdb_hash_func fn) TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode) { - return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL); + return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL, NULL); } TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode, - tdb_log_func log_fn) + tdb_log_func log_fn, + tdb_hash_func hash_fn) { TDB_CONTEXT *tdb; struct stat st; @@ -1733,7 +1729,7 @@ TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags, tdb->flags = tdb_flags; tdb->open_flags = open_flags; tdb->log_fn = log_fn; - tdb->hash_fn = default_tdb_hash; + tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash; if ((open_flags & O_ACCMODE) == O_WRONLY) { TDB_LOG((tdb, 0, "tdb_open_ex: can't open tdb %s write-only\n", diff --git a/source/tdb/tdb.h b/source/tdb/tdb.h index 8f4421d8faa..c28e10af693 100644 --- a/source/tdb/tdb.h +++ b/source/tdb/tdb.h @@ -114,12 +114,12 @@ TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode); TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode, - tdb_log_func log_fn); + tdb_log_func log_fn, + tdb_hash_func hash_fn); int tdb_reopen(TDB_CONTEXT *tdb); int tdb_reopen_all(void); void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func); -void tdb_set_hash_function(TDB_CONTEXT *tdb, tdb_hash_func); enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb); const char *tdb_errorstr(TDB_CONTEXT *tdb); TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key); diff --git a/source/tdb/tdbutil.c b/source/tdb/tdbutil.c index 09e55e2e702..e57eccfe598 100644 --- a/source/tdb/tdbutil.c +++ b/source/tdb/tdbutil.c @@ -740,7 +740,7 @@ TDB_CONTEXT *tdb_open_log(const char *name, int hash_size, int tdb_flags, tdb_flags |= TDB_NOMMAP; tdb = tdb_open_ex(name, hash_size, tdb_flags, - open_flags, mode, tdb_log); + open_flags, mode, tdb_log, NULL); if (!tdb) return NULL; |