Add file hashing helpers
[fio.git] / init.c
diff --git a/init.c b/init.c
index d860179df6dcbe98f43f60d5a8ba999609b87824..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";
 
@@ -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;
 }