projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
server: use the wrapped MSG_DONTWAIT
[fio.git]
/
filehash.c
diff --git
a/filehash.c
b/filehash.c
index a00ac7885721c60b839f0b6c26144f6355b065a9..0d61f54cca0b2f8c526cd639f9749716069aa8ff 100644
(file)
--- a/
filehash.c
+++ b/
filehash.c
@@
-3,7
+3,8
@@
#include "fio.h"
#include "flist.h"
#include "fio.h"
#include "flist.h"
-#include "crc/crc16.h"
+#include "hash.h"
+#include "filehash.h"
#define HASH_BUCKETS 512
#define HASH_MASK (HASH_BUCKETS - 1)
#define HASH_BUCKETS 512
#define HASH_MASK (HASH_BUCKETS - 1)
@@
-15,17
+16,29
@@
static struct fio_mutex *hash_lock;
static unsigned short hash(const char *name)
{
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 fio_file_hash_lock(void)
+{
+ if (hash_lock)
+ fio_mutex_down(hash_lock);
+}
+
+void fio_file_hash_unlock(void)
+{
+ if (hash_lock)
+ fio_mutex_up(hash_lock);
}
void remove_file_hash(struct fio_file *f)
{
fio_mutex_down(hash_lock);
}
void remove_file_hash(struct fio_file *f)
{
fio_mutex_down(hash_lock);
- if (f
->flags & FIO_FILE_HASHED
) {
+ if (f
io_file_hashed(f)
) {
assert(!flist_empty(&f->hash_list));
flist_del_init(&f->hash_list);
assert(!flist_empty(&f->hash_list));
flist_del_init(&f->hash_list);
- f
->flags &= ~FIO_FILE_HASHED
;
+ f
io_file_clear_hashed(f)
;
}
fio_mutex_up(hash_lock);
}
fio_mutex_up(hash_lock);
@@
-39,6
+52,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);
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;
if (!strcmp(f->file_name, name)) {
assert(f->fd != -1);
return f;
@@
-62,7
+78,7
@@
struct fio_file *add_file_hash(struct fio_file *f)
{
struct fio_file *alias;
{
struct fio_file *alias;
- if (f
->flags & FIO_FILE_HASHED
)
+ if (f
io_file_hashed(f)
)
return NULL;
INIT_FLIST_HEAD(&f->hash_list);
return NULL;
INIT_FLIST_HEAD(&f->hash_list);
@@
-71,7
+87,7
@@
struct fio_file *add_file_hash(struct fio_file *f)
alias = __lookup_file_hash(f->file_name);
if (!alias) {
alias = __lookup_file_hash(f->file_name);
if (!alias) {
- f
->flags |= FIO_FILE_HASHED
;
+ f
io_file_set_hashed(f)
;
flist_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]);
}
flist_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]);
}
@@
-104,5
+120,5
@@
void file_hash_init(void *ptr)
for (i = 0; i < HASH_BUCKETS; i++)
INIT_FLIST_HEAD(&file_hash[i]);
for (i = 0; i < HASH_BUCKETS; i++)
INIT_FLIST_HEAD(&file_hash[i]);
- hash_lock = fio_mutex_init(
1
);
+ hash_lock = fio_mutex_init(
FIO_MUTEX_UNLOCKED
);
}
}