8 #define HASH_BUCKETS 512
9 #define HASH_MASK (HASH_BUCKETS - 1)
11 unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head);
13 static struct flist_head *file_hash;
14 static struct fio_mutex *hash_lock;
16 static unsigned short hash(const char *name)
18 return jhash(name, strlen(name), 0) & HASH_MASK;
21 void remove_file_hash(struct fio_file *f)
23 fio_mutex_down(hash_lock);
25 if (fio_file_hashed(f)) {
26 assert(!flist_empty(&f->hash_list));
27 flist_del_init(&f->hash_list);
28 fio_file_clear_hashed(f);
31 fio_mutex_up(hash_lock);
34 static struct fio_file *__lookup_file_hash(const char *name)
36 struct flist_head *bucket = &file_hash[hash(name)];
39 flist_for_each(n, bucket) {
40 struct fio_file *f = flist_entry(n, struct fio_file, hash_list);
45 if (!strcmp(f->file_name, name)) {
54 struct fio_file *lookup_file_hash(const char *name)
58 fio_mutex_down(hash_lock);
59 f = __lookup_file_hash(name);
60 fio_mutex_up(hash_lock);
64 struct fio_file *add_file_hash(struct fio_file *f)
66 struct fio_file *alias;
68 if (fio_file_hashed(f))
71 INIT_FLIST_HEAD(&f->hash_list);
73 fio_mutex_down(hash_lock);
75 alias = __lookup_file_hash(f->file_name);
77 fio_file_set_hashed(f);
78 flist_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]);
81 fio_mutex_up(hash_lock);
85 void file_hash_exit(void)
87 unsigned int i, has_entries = 0;
89 fio_mutex_down(hash_lock);
90 for (i = 0; i < HASH_BUCKETS; i++)
91 has_entries += !flist_empty(&file_hash[i]);
92 fio_mutex_up(hash_lock);
95 log_err("fio: file hash not empty on exit\n");
98 fio_mutex_remove(hash_lock);
102 void file_hash_init(void *ptr)
107 for (i = 0; i < HASH_BUCKETS; i++)
108 INIT_FLIST_HEAD(&file_hash[i]);
110 hash_lock = fio_mutex_init(1);