jbd2: use a better hash function for the revoke table

The old hash function didn't work well for 64-bit block numbers, and
used undefined (negative) shift right behavior.  Use the generic
64-bit hash function instead.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reported-by: Andrey Ryabinin <a.ryabinin@samsung.com>
This commit is contained in:
Theodore Ts'o 2014-10-30 10:53:17 -04:00
parent a41537e69b
commit d48458d4a7
1 changed files with 2 additions and 8 deletions

View File

@ -92,6 +92,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/bio.h> #include <linux/bio.h>
#include <linux/log2.h> #include <linux/log2.h>
#include <linux/hash.h>
#endif #endif
static struct kmem_cache *jbd2_revoke_record_cache; static struct kmem_cache *jbd2_revoke_record_cache;
@ -130,16 +131,9 @@ static void flush_descriptor(journal_t *, struct buffer_head *, int, int);
/* Utility functions to maintain the revoke table */ /* Utility functions to maintain the revoke table */
/* Borrowed from buffer.c: this is a tried and tested block hash function */
static inline int hash(journal_t *journal, unsigned long long block) static inline int hash(journal_t *journal, unsigned long long block)
{ {
struct jbd2_revoke_table_s *table = journal->j_revoke; return hash_64(block, journal->j_revoke->hash_shift);
int hash_shift = table->hash_shift;
int hash = (int)block ^ (int)((block >> 31) >> 1);
return ((hash << (hash_shift - 6)) ^
(hash >> 13) ^
(hash << (hash_shift - 12))) & (table->hash_size - 1);
} }
static int insert_revoke_hash(journal_t *journal, unsigned long long blocknr, static int insert_revoke_hash(journal_t *journal, unsigned long long blocknr,