[PATCH] cleanup sg ioctl vs read approach
[fio.git] / fio-ini.c
index d34956494557b32a51b18c2d25852cf6b6359c22..0c83f70246d4b23f59af47b54a862920db2edc7f 100644 (file)
--- a/fio-ini.c
+++ b/fio-ini.c
 
 #include "fio.h"
 
-#define DEF_BS         (4096)
-#define DEF_TIMEOUT    (0)
-#define DEF_RATE_CYCLE (1000)
-#define DEF_ODIRECT    (1)
-#define DEF_IO_ENGINE  (FIO_SYNCIO)
+#define DEF_BS                 (4096)
+#define DEF_TIMEOUT            (0)
+#define DEF_RATE_CYCLE         (1000)
+#define DEF_ODIRECT            (1)
+#define DEF_IO_ENGINE          (FIO_SYNCIO)
 #define DEF_IO_ENGINE_NAME     "sync"
-#define DEF_SEQUENTIAL (1)
-#define DEF_RAND_REPEAT        (1)
-#define DEF_OVERWRITE  (1)
-#define DEF_CREATE     (1)
-#define DEF_INVALIDATE (1)
-#define DEF_SYNCIO     (0)
-#define DEF_RANDSEED   (0xb1899bedUL)
-#define DEF_BWAVGTIME  (500)
-#define DEF_CREATE_SER (1)
+#define DEF_SEQUENTIAL         (1)
+#define DEF_RAND_REPEAT                (1)
+#define DEF_OVERWRITE          (1)
+#define DEF_CREATE             (1)
+#define DEF_INVALIDATE         (1)
+#define DEF_SYNCIO             (0)
+#define DEF_RANDSEED           (0xb1899bedUL)
+#define DEF_BWAVGTIME          (500)
+#define DEF_CREATE_SER         (1)
 #define DEF_CREATE_FSYNC       (1)
-#define DEF_LOOPS      (1)
-#define DEF_VERIFY     (0)
-#define DEF_STONEWALL  (0)
-#define DEF_NUMJOBS    (1)
-#define DEF_USE_THREAD (0)
-#define DEF_FILE_SIZE  (1024 * 1024 * 1024UL)
+#define DEF_LOOPS              (1)
+#define DEF_VERIFY             (0)
+#define DEF_STONEWALL          (0)
+#define DEF_NUMJOBS            (1)
+#define DEF_USE_THREAD         (0)
+#define DEF_FILE_SIZE          (1024 * 1024 * 1024UL)
+#define DEF_ZONE_SIZE          (0)
+#define DEF_ZONE_SKIP          (0)
 
-static char fio_version_string[] = "fio 1.1";
+static char fio_version_string[] = "fio 1.3";
 
 static int repeatable = DEF_RAND_REPEAT;
 static char *ini_file;
@@ -130,6 +132,8 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent)
        td->invalidate_cache = parent->invalidate_cache;
        td->file_size = parent->file_size;
        td->file_offset = parent->file_offset;
+       td->zone_size = parent->zone_size;
+       td->zone_skip = parent->zone_skip;
        td->rate = parent->rate;
        td->ratemin = parent->ratemin;
        td->ratecycle = parent->ratecycle;
@@ -193,15 +197,25 @@ static int add_job(struct thread_data *td, const char *jobname, int prioclass,
                        td->iodepth = 1;
        }
 
+       /*
+        * only really works for sequential io for now
+        */
+       if (td->zone_size && !td->sequential)
+               td->zone_size = 0;
+
        td->filetype = FIO_TYPE_FILE;
-       if (!stat(jobname, &sb) && S_ISBLK(sb.st_mode))
-               td->filetype = FIO_TYPE_BD;
+       if (!stat(jobname, &sb)) {
+               if (S_ISBLK(sb.st_mode))
+                       td->filetype = FIO_TYPE_BD;
+               else if (S_ISCHR(sb.st_mode))
+                       td->filetype = FIO_TYPE_CHAR;
+       }
 
        if (td->filetype == FIO_TYPE_FILE) {
                if (td->directory[0] != '\0')
-                       sprintf(td->file_name, "%s/%s.%d", td->directory, jobname, td->thread_number);
+                       sprintf(td->file_name, "%s/%s.%d", td->directory, jobname, td->jobnum);
                else
-                       sprintf(td->file_name, "%s.%d", jobname, td->thread_number);
+                       sprintf(td->file_name, "%s.%d", jobname, td->jobnum);
        } else
                strcpy(td->file_name, jobname);
 
@@ -249,6 +263,7 @@ static int add_job(struct thread_data *td, const char *jobname, int prioclass,
 
                td_new->numjobs = 1;
                td_new->stonewall = 0;
+               td_new->jobnum = numjobs;
 
                if (add_job(td_new, jobname, prioclass, prio))
                        goto err;
@@ -336,7 +351,7 @@ static int str_cnv(char *p, unsigned long long *val)
        char *str;
        int len;
 
-       str = strstr(p, "=");
+       str = strchr(p, '=');
        if (!str)
                return 1;
 
@@ -353,7 +368,7 @@ static int str_cnv(char *p, unsigned long long *val)
 
 static int check_strcnv(char *p, char *name, unsigned long long *val)
 {
-       if (!strstr(p, name))
+       if (strncmp(p, name, strlen(name) - 1))
                return 1;
 
        return str_cnv(p, val);
@@ -384,7 +399,7 @@ static int check_str(char *p, char *name, str_cb_fn *cb, struct thread_data *td)
        if (!s)
                return 1;
 
-       s = strstr(s, "=");
+       s = strchr(s, '=');
        if (!s)
                return 1;
 
@@ -400,7 +415,7 @@ static int check_strstore(char *p, char *name, char *dest)
        if (!s)
                return 1;
 
-       s = strstr(p, "=");
+       s = strchr(p, '=');
        if (!s)
                return 1;
 
@@ -414,47 +429,75 @@ static int check_strstore(char *p, char *name, char *dest)
        return 0;
 }
 
-static int check_range(char *p, char *name, unsigned long *s, unsigned long *e)
+static int __check_range(char *str, unsigned long *val)
 {
-       char str[128];
-       char s1, s2;
+       char suffix;
 
-       sprintf(str, "%s=%%lu%%c-%%lu%%c", name);
-       if (sscanf(p, str, s, &s1, e, &s2) == 4) {
-               *s *= get_mult(s1);
-               *e *= get_mult(s2);
+       if (sscanf(str, "%lu%c", val, &suffix) == 2) {
+               *val *= get_mult(suffix);
                return 0;
        }
 
-       sprintf(str, "%s = %%lu%%c-%%lu%%c", name);
-       if (sscanf(p, str, s, &s1, e, &s2) == 4) {
-               *s *= get_mult(s1);
-               *e *= get_mult(s2);
+       if (sscanf(str, "%lu", val) == 1)
                return 0;
-       }
 
-       sprintf(str, "%s=%%lu-%%lu", name);
-       if (sscanf(p, str, s, e) == 2)
-               return 0;
+       return 1;
+}
+
+static int check_range(char *p, char *name, unsigned long *s, unsigned long *e)
+{
+       char option[128];
+       char *str, *p1, *p2;
+
+       strcpy(option, p);
+       p = option;
+
+       str = strstr(p, name);
+       if (!str)
+               return 1;
+
+       p += strlen(name);
+
+       str = strchr(p, '=');
+       if (!str)
+               return 1;
+
+       /*
+        * 'p' now holds whatever is after the '=' sign
+        */
+       p1 = str + 1;
+
+       /*
+        * terminate p1 at the '-' sign
+        */
+       p = strchr(p1, '-');
+       if (!p)
+               return 1;
+
+       p2 = p + 1;
+       *p = '\0';
 
-       sprintf(str, "%s = %%lu-%%lu", name);
-       if (sscanf(p, str, s, e) == 2)
+       if (!__check_range(p1, s) && !__check_range(p2, e))
                return 0;
 
        return 1;
-
 }
 
 static int check_int(char *p, char *name, unsigned int *val)
 {
-       char str[128];
+       char *str;
 
-       sprintf(str, "%s=%%d", name);
-       if (sscanf(p, str, val) == 1)
-               return 0;
+       str = strstr(p, name);
+       if (!str)
+               return 1;
 
-       sprintf(str, "%s = %%d", name);
-       if (sscanf(p, str, val) == 1)
+       str = strchr(p, '=');
+       if (!str)
+               return 1;
+
+       str++;
+
+       if (sscanf(str, "%u", val) == 1)
                return 0;
 
        return 1;
@@ -727,6 +770,14 @@ int parse_jobs_ini(char *file)
                                fgetpos(f, &off);
                                continue;
                        }
+                       if (!check_strcnv(p, "zonesize", &td->zone_size)) {
+                               fgetpos(f, &off);
+                               continue;
+                       }
+                       if (!check_strcnv(p, "zoneskip", &td->zone_skip)) {
+                               fgetpos(f, &off);
+                               continue;
+                       }
                        if (!check_strstore(p, "directory", td->directory)) {
                                fgetpos(f, &off);
                                continue;