return jhash(name, strlen(name), 0) & HASH_MASK;
}
+void fio_file_hash_lock(void)
+{
+ fio_mutex_down(hash_lock);
+}
+
+void fio_file_hash_unlock(void)
+{
+ fio_mutex_up(hash_lock);
+}
+
void remove_file_hash(struct fio_file *f)
{
fio_mutex_down(hash_lock);
}
}
-static void set_already_allocated(const char *fname)
+static int __is_already_allocated(const char *fname)
{
- struct file_name *fn;
+ struct flist_head *entry;
+ char *filename;
- fn = malloc(sizeof(struct file_name));
- fn->filename = strdup(fname);
- flist_add_tail(&fn->list, &filename_list);
+ if (flist_empty(&filename_list))
+ return 0;
+
+ flist_for_each(entry, &filename_list) {
+ filename = flist_entry(entry, struct file_name, list)->filename;
+
+ if (strcmp(filename, fname) == 0)
+ return 1;
+ }
+
+ return 0;
}
static int is_already_allocated(const char *fname)
{
- struct flist_head *entry;
- char *filename;
+ int ret;
- if (!flist_empty(&filename_list))
- {
- flist_for_each(entry, &filename_list) {
- filename = flist_entry(entry, struct file_name, list)->filename;
+ fio_file_hash_lock();
+ ret = __is_already_allocated(fname);
+ fio_file_hash_unlock();
+ return ret;
+}
- if (strcmp(filename, fname) == 0)
- return 1;
- }
+static void set_already_allocated(const char *fname)
+{
+ struct file_name *fn;
+
+ fn = malloc(sizeof(struct file_name));
+ fn->filename = strdup(fname);
+
+ fio_file_hash_lock();
+ if (!__is_already_allocated(fname)) {
+ flist_add_tail(&fn->list, &filename_list);
+ fn = NULL;
}
+ fio_file_hash_unlock();
- return 0;
+ if (fn) {
+ free(fn->filename);
+ free(fn);
+ }
}
+
static void free_already_allocated(void)
{
struct flist_head *entry, *tmp;
struct file_name *fn;
- if (!flist_empty(&filename_list))
- {
- flist_for_each_safe(entry, tmp, &filename_list) {
- fn = flist_entry(entry, struct file_name, list);
- free(fn->filename);
- flist_del(&fn->list);
- free(fn);
- }
+ if (flist_empty(&filename_list))
+ return;
+
+ fio_file_hash_lock();
+ flist_for_each_safe(entry, tmp, &filename_list) {
+ fn = flist_entry(entry, struct file_name, list);
+ free(fn->filename);
+ flist_del(&fn->list);
+ free(fn);
}
+
+ fio_file_hash_unlock();
}
int add_file(struct thread_data *td, const char *fname, int numjob, int inc)