X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filehash.c;h=392464e2ba61dd2f04caccba893ec5b0c17794cd;hp=97c0b3c7633d0e28ab4f44231679301a8d344e6c;hb=62cb17de316e5aa755228fef8ce19b5f5353a3cf;hpb=0ec7b3c9a0926e6377bd145206bb9f6a70be610d diff --git a/filehash.c b/filehash.c index 97c0b3c7..392464e2 100644 --- a/filehash.c +++ b/filehash.c @@ -3,9 +3,7 @@ #include "fio.h" #include "flist.h" -#include "crc/crc16.h" - -#include "spinlock.h" +#include "hash.h" #define HASH_BUCKETS 512 #define HASH_MASK (HASH_BUCKETS - 1) @@ -13,24 +11,24 @@ unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head); static struct flist_head *file_hash; -static struct fio_spinlock *hash_lock; +static struct fio_mutex *hash_lock; static unsigned short hash(const char *name) { - return crc16((const unsigned char *) name, strlen(name)) & HASH_MASK; + return jhash(name, strlen(name), 0) & HASH_MASK; } void remove_file_hash(struct fio_file *f) { - fio_spin_lock(hash_lock); + fio_mutex_down(hash_lock); - if (f->flags & FIO_FILE_HASHED) { + if (fio_file_hashed(f)) { assert(!flist_empty(&f->hash_list)); flist_del_init(&f->hash_list); - f->flags &= ~FIO_FILE_HASHED; + fio_file_clear_hashed(f); } - fio_spin_unlock(hash_lock); + fio_mutex_up(hash_lock); } static struct fio_file *__lookup_file_hash(const char *name) @@ -41,6 +39,9 @@ static struct fio_file *__lookup_file_hash(const char *name) flist_for_each(n, bucket) { struct fio_file *f = flist_entry(n, struct fio_file, hash_list); + if (!f->file_name) + continue; + if (!strcmp(f->file_name, name)) { assert(f->fd != -1); return f; @@ -54,9 +55,9 @@ struct fio_file *lookup_file_hash(const char *name) { struct fio_file *f; - fio_spin_lock(hash_lock); + fio_mutex_down(hash_lock); f = __lookup_file_hash(name); - fio_spin_unlock(hash_lock); + fio_mutex_up(hash_lock); return f; } @@ -64,20 +65,20 @@ struct fio_file *add_file_hash(struct fio_file *f) { struct fio_file *alias; - if (f->flags & FIO_FILE_HASHED) + if (fio_file_hashed(f)) return NULL; INIT_FLIST_HEAD(&f->hash_list); - fio_spin_lock(hash_lock); + fio_mutex_down(hash_lock); alias = __lookup_file_hash(f->file_name); if (!alias) { - f->flags |= FIO_FILE_HASHED; + fio_file_set_hashed(f); flist_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]); } - fio_spin_unlock(hash_lock); + fio_mutex_up(hash_lock); return alias; } @@ -85,17 +86,16 @@ void file_hash_exit(void) { unsigned int i, has_entries = 0; - fio_spin_lock(hash_lock); + fio_mutex_down(hash_lock); for (i = 0; i < HASH_BUCKETS; i++) has_entries += !flist_empty(&file_hash[i]); - - file_hash = NULL; - fio_spin_unlock(hash_lock); + fio_mutex_up(hash_lock); if (has_entries) log_err("fio: file hash not empty on exit\n"); - fio_spinlock_remove(hash_lock); + file_hash = NULL; + fio_mutex_remove(hash_lock); hash_lock = NULL; } @@ -107,5 +107,5 @@ void file_hash_init(void *ptr) for (i = 0; i < HASH_BUCKETS; i++) INIT_FLIST_HEAD(&file_hash[i]); - hash_lock = fio_spinlock_init(); + hash_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED); }