[PATCH] Fix character + O_DIRECT
[fio.git] / init.c
diff --git a/init.c b/init.c
index 54e2ecae28202622d6954308d192439bb55dca2c..0c888b8fcdca83a0bdc7691d2eb38202393ebcbb 100644 (file)
--- a/init.c
+++ b/init.c
@@ -29,7 +29,7 @@
 #define DEF_IO_ENGINE_NAME     "sync"
 #define DEF_SEQUENTIAL         (1)
 #define DEF_RAND_REPEAT                (1)
-#define DEF_OVERWRITE          (1)
+#define DEF_OVERWRITE          (0)
 #define DEF_INVALIDATE         (1)
 #define DEF_SYNCIO             (0)
 #define DEF_RANDSEED           (0xb1899bedUL)
@@ -48,7 +48,7 @@
 #define DEF_RWMIX_READ         (50)
 #define DEF_NICE               (0)
 #define DEF_NR_FILES           (1)
-#define DEF_UNLINK             (0)
+#define DEF_UNLINK             (1)
 #define DEF_WRITE_BW_LOG       (0)
 #define DEF_WRITE_LAT_LOG      (0)
 #define DEF_NO_RAND_MAP                (0)
@@ -409,7 +409,7 @@ static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
 
 static int def_timeout = DEF_TIMEOUT;
 
-static char fio_version_string[] = "fio 1.8";
+static char fio_version_string[] = "fio 1.9";
 
 static char **ini_file;
 static int max_jobs = MAX_JOBS;
@@ -417,7 +417,6 @@ static int max_jobs = MAX_JOBS;
 struct thread_data def_thread;
 struct thread_data *threads = NULL;
 
-int rate_quit = 0;
 int exitall_on_terminate = 0;
 int terse_output = 0;
 unsigned long long mlock_size = 0;
@@ -509,6 +508,12 @@ static void fixup_options(struct thread_data *td)
        }
        if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
                log_err("fio: bs_unaligned may not work with raw io\n");
+
+       /*
+        * O_DIRECT and char doesn't mix, clear that flag if necessary.
+        */
+       if (td->filetype == FIO_TYPE_CHAR && td->odirect)
+               td->odirect = 0;
 }
 
 /*
@@ -517,16 +522,16 @@ static void fixup_options(struct thread_data *td)
 static char *to_kmg(unsigned int val)
 {
        char *buf = malloc(32);
-       char post[] = { 0, 'K', 'M', 'G', 'P', -1 };
+       char post[] = { 0, 'K', 'M', 'G', 'P', 0 };
        char *p = post;
 
-       while (*p != -1) {
+       do {
                if (val & 1023)
                        break;
 
                val >>= 10;
                p++;
-       }
+       } while (*p);
 
        snprintf(buf, 31, "%u%c", val, *p);
        return buf;
@@ -565,8 +570,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        if (td->odirect)
                td->io_ops->flags |= FIO_RAWIO;
 
-       fixup_options(td);
-
        td->filetype = FIO_TYPE_FILE;
        if (!stat(jobname, &sb)) {
                if (S_ISBLK(sb.st_mode))
@@ -575,6 +578,8 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                        td->filetype = FIO_TYPE_CHAR;
        }
 
+       fixup_options(td);
+
        if (td->filename)
                td->nr_uniq_files = 1;
        else
@@ -583,7 +588,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        if (td->filetype == FIO_TYPE_FILE || td->filename) {
                char tmp[PATH_MAX];
                int len = 0;
-               int i;
 
                if (td->directory && td->directory[0] != '\0')
                        sprintf(tmp, "%s/", td->directory);
@@ -653,7 +657,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                                c3 = to_kmg(td->min_bs[DDIR_WRITE]);
                                c4 = to_kmg(td->max_bs[DDIR_WRITE]);
 
-                               fprintf(f_out, "%s: (g=%d): rw=%s, odir=%d, bs=%s-%s/%s-%s, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, c1, c2, c3, c4, td->rate, td->io_ops->name, td->iodepth);
+                               fprintf(f_out, "%s: (g=%d): rw=%s, odir=%u, bs=%s-%s/%s-%s, rate=%u, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[ddir], td->odirect, c1, c2, c3, c4, td->rate, td->io_ops->name, td->iodepth);
 
                                free(c1);
                                free(c2);
@@ -788,12 +792,12 @@ static int str_rw_cb(void *data, const char *mem)
                td->sequential = 0;
                return 0;
        } else if (!strncmp(mem, "rw", 2)) {
-               td->ddir = 0;
+               td->ddir = DDIR_READ;
                td->iomix = 1;
                td->sequential = 1;
                return 0;
        } else if (!strncmp(mem, "randrw", 6)) {
-               td->ddir = 0;
+               td->ddir = DDIR_READ;
                td->iomix = 1;
                td->sequential = 0;
                return 0;
@@ -829,15 +833,23 @@ static int str_mem_cb(void *data, const char *mem)
        if (!strncmp(mem, "malloc", 6)) {
                td->mem_type = MEM_MALLOC;
                return 0;
-       } else if (!strncmp(mem, "shm", 3)) {
-               td->mem_type = MEM_SHM;
-               return 0;
        } else if (!strncmp(mem, "mmap", 4)) {
                td->mem_type = MEM_MMAP;
                return 0;
+       } else if (!strncmp(mem, "shmhuge", 7)) {
+#ifdef FIO_HAVE_HUGETLB
+               td->mem_type = MEM_SHMHUGE;
+               return 0;
+#else
+               log_err("fio: shmhuge not available\n");
+               return 1;
+#endif
+       } else if (!strncmp(mem, "shm", 3)) {
+               td->mem_type = MEM_SHM;
+               return 0;
        }
 
-       log_err("fio: mem type: malloc, shm, mmap\n");
+       log_err("fio: mem type: malloc, shm, mmap, shmhuge\n");
        return 1;
 }
 
@@ -849,7 +861,8 @@ static int str_ioengine_cb(void *data, const char *str)
        if (td->io_ops)
                return 0;
 
-       log_err("fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice, cpu\n");
+       log_err("fio: ioengine= libaio, posixaio, sync, mmap, sgio, splice, cpu, null\n");
+       log_err("fio: or specify path to dynamic ioengine module\n");
        return 1;
 }
 
@@ -894,7 +907,7 @@ static int str_cpumask_cb(void *data, unsigned int *val)
 /*
  * This is our [ini] type file parser.
  */
-int parse_jobs_ini(char *file, int stonewall_flag)
+static int parse_jobs_ini(char *file, int stonewall_flag)
 {
        unsigned int global;
        struct thread_data *td;