Add file hashing helpers
[fio.git] / init.c
diff --git a/init.c b/init.c
index 4f57ba31705e151f44859ce80109d3fb1c3a110e..4d336fa3eb6c08888a9cd7d0d2a3394d40b90479 100644 (file)
--- a/init.c
+++ b/init.c
@@ -16,6 +16,8 @@
 
 #include "fio.h"
 #include "parse.h"
+#include "smalloc.h"
+#include "filehash.h"
 
 static char fio_version_string[] = "fio 1.19";
 
@@ -466,7 +468,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                        f->real_file_size = -1ULL;
        }
 
-       td->mutex = fio_sem_init(0);
+       td->mutex = fio_mutex_init(0);
 
        td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
        td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
@@ -742,15 +744,20 @@ static void free_shm(void)
                threads = NULL;
                shmctl(shm_id, IPC_RMID, &sbuf);
        }
+
+       scleanup();
 }
 
 /*
  * The thread area is shared between the main process and the job
  * threads/processes. So setup a shared memory segment that will hold
- * all the job info.
+ * all the job info. We use the end of the region for keeping track of
+ * open files across jobs, for file sharing.
  */
 static int setup_thread_area(void)
 {
+       void *hash;
+
        /*
         * 1024 is too much on some machines, scale max_jobs if
         * we get a failure that looks like too large a shm segment
@@ -758,6 +765,8 @@ static int setup_thread_area(void)
        do {
                size_t size = max_jobs * sizeof(struct thread_data);
 
+               size += file_hash_size;
+
                shm_id = shmget(0, size, IPC_CREAT | 0600);
                if (shm_id != -1)
                        break;
@@ -779,6 +788,8 @@ static int setup_thread_area(void)
        }
 
        memset(threads, 0, max_jobs * sizeof(struct thread_data));
+       hash = (void *) threads + max_jobs * sizeof(struct thread_data);
+       file_hash_init(hash);
        atexit(free_shm);
        return 0;
 }
@@ -812,6 +823,7 @@ struct debug_level debug_levels[] = {
        { .name = "blktrace",   .shift = FD_BLKTRACE },
        { .name = "verify",     .shift = FD_VERIFY },
        { .name = "random",     .shift = FD_RANDOM },
+       { .name = "parse",      .shift = FD_PARSE },
        { },
 };