8 #define HASH_BUCKETS 512
9 #define HASH_MASK (HASH_BUCKETS - 1)
11 unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct list_head);
13 static struct list_head *file_hash;
14 static struct fio_mutex *hash_lock;
16 static void dump_hash(void)
21 for (i = 0; i < HASH_BUCKETS; i++) {
22 list_for_each(n, &file_hash[i]) {
25 f = list_entry(n, struct fio_file, hash_list);
26 printf("%d: %s\n", i, f->file_name);
31 static unsigned short hash(const char *name)
33 return crc16((const unsigned char *) name, strlen(name)) & HASH_MASK;
36 void remove_file_hash(struct fio_file *f)
38 fio_mutex_down(hash_lock);
40 if (f->flags & FIO_FILE_HASHED) {
41 assert(!list_empty(&f->hash_list));
42 list_del_init(&f->hash_list);
43 f->flags &= ~FIO_FILE_HASHED;
46 fio_mutex_up(hash_lock);
49 static struct fio_file *__lookup_file_hash(const char *name)
51 struct list_head *bucket = &file_hash[hash(name)];
54 list_for_each(n, bucket) {
55 struct fio_file *f = list_entry(n, struct fio_file, hash_list);
57 if (!strcmp(f->file_name, name)) {
67 struct fio_file *lookup_file_hash(const char *name)
71 fio_mutex_down(hash_lock);
72 f = __lookup_file_hash(name);
73 fio_mutex_up(hash_lock);
77 struct fio_file *add_file_hash(struct fio_file *f)
79 struct fio_file *alias;
81 if (f->flags & FIO_FILE_HASHED)
84 INIT_LIST_HEAD(&f->hash_list);
86 fio_mutex_down(hash_lock);
88 alias = __lookup_file_hash(f->file_name);
90 f->flags |= FIO_FILE_HASHED;
91 list_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]);
94 fio_mutex_up(hash_lock);
98 void file_hash_init(void *ptr)
103 for (i = 0; i < HASH_BUCKETS; i++)
104 INIT_LIST_HEAD(&file_hash[i]);
106 hash_lock = fio_mutex_init(1);