summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@suse.de>2005-12-02 15:03:14 +0100
committerJens Axboe <axboe@suse.de>2005-12-02 15:03:14 +0100
commit3f91ddf9de26dd27018c36b350ffc1674443b2fa (patch)
tree1e9f0185b694892a205600c9759e3e8b686bc5de
parent91e6eb54bc406a5f30c690747dddbb8891ba7418 (diff)
[PATCH] fio: better check_str() setup
-rw-r--r--fio-ini.c140
1 files changed, 88 insertions, 52 deletions
diff --git a/fio-ini.c b/fio-ini.c
index fdeea52..fc71e2b 100644
--- a/fio-ini.c
+++ b/fio-ini.c
@@ -331,18 +331,38 @@ static int check_strcnv(char *p, char *name, unsigned long long *val)
return str_cnv(p, val);
}
-static int check_str(char *p, char *name, char *option)
+static void strip_blank_front(char **p)
+{
+ char *s = *p;
+
+ while (isblank(*s))
+ s++;
+}
+
+static void strip_blank_end(char *p)
+{
+ while (isblank(*p)) {
+ *p = '\0';
+ p--;
+ }
+}
+
+typedef int (str_cb_fn)(struct thread_data *, char *);
+
+static int check_str(char *p, char *name, str_cb_fn *cb, struct thread_data *td)
{
char *s = strstr(p, name);
if (!s)
return 1;
- s += strlen(name);
- if (strstr(s, option))
- return 0;
+ s = strstr(s, "=");
+ if (!s)
+ return 1;
- return 1;
+ s++;
+ strip_blank_front(&s);
+ return cb(td, s);
}
static int check_strstore(char *p, char *name, char *dest)
@@ -357,17 +377,12 @@ static int check_strstore(char *p, char *name, char *dest)
return 1;
s++;
- while (isblank(*s))
- s++;
+ strip_blank_front(&s);
strcpy(dest, s);
s = dest + strlen(dest) - 1;
- while (isblank(*s)) {
- *s = '\0';
- s--;
- }
-
+ strip_blank_end(s);
return 0;
}
@@ -436,6 +451,64 @@ static int is_empty_or_comment(char *line)
return 1;
}
+static int str_rw_cb(struct thread_data *td, char *mem)
+{
+ if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) {
+ td->ddir = DDIR_READ;
+ td->sequential = 1;
+ return 0;
+ } else if (!strncmp(mem, "randread", 8)) {
+ td->ddir = DDIR_READ;
+ td->sequential = 0;
+ return 0;
+ } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) {
+ td->ddir = DDIR_WRITE;
+ td->sequential = 1;
+ return 0;
+ } else if (!strncmp(mem, "randwrite", 9)) {
+ td->ddir = DDIR_WRITE;
+ td->sequential = 0;
+ return 0;
+ }
+
+ fprintf(stderr, "bad data direction: %s\n", mem);
+ return 1;
+}
+
+static int str_verify_cb(struct thread_data *td, char *mem)
+{
+ if (!strncmp(mem, "0", 1)) {
+ td->verify = VERIFY_NONE;
+ return 0;
+ } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) {
+ td->verify = VERIFY_MD5;
+ return 0;
+ } else if (!strncmp(mem, "crc32", 5)) {
+ td->verify = VERIFY_CRC32;
+ return 0;
+ }
+
+ fprintf(stderr, "bad verify type: %s\n", mem);
+ return 1;
+}
+
+static int str_mem_cb(struct thread_data *td, 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;
+ }
+
+ fprintf(stderr, "bad mem type: %s\n", mem);
+ return 1;
+}
+
int parse_jobs_ini(char *file)
{
unsigned int prioclass, prio, cpu, global;
@@ -596,52 +669,15 @@ int parse_jobs_ini(char *file)
fgetpos(f, &off);
continue;
}
- if (!check_str(p, "mem", "malloc")) {
- td->mem_type = MEM_MALLOC;
- fgetpos(f, &off);
- continue;
- }
- if (!check_str(p, "mem", "shm")) {
- td->mem_type = MEM_SHM;
- fgetpos(f, &off);
- continue;
- }
- if (!check_str(p, "mem", "mmap")) {
- td->mem_type = MEM_MMAP;
- fgetpos(f, &off);
- continue;
- }
- if (!check_str(p, "verify", "md5")) {
- td->verify = VERIFY_MD5;
- fgetpos(f, &off);
- continue;
- }
- if (!check_str(p, "verify", "crc32")) {
- td->verify = VERIFY_CRC32;
- fgetpos(f, &off);
- continue;
- }
- if (!check_str(p, "rw", "randread")) {
- td->ddir = DDIR_READ;
- td->sequential = 0;
- fgetpos(f, &off);
- continue;
- }
- if (!check_str(p, "rw", "read")) {
- td->ddir = DDIR_READ;
- td->sequential = 1;
+ if (!check_str(p, "mem", str_mem_cb, td)) {
fgetpos(f, &off);
continue;
}
- if (!check_str(p, "rw", "randwrite")) {
- td->ddir = DDIR_WRITE;
- td->sequential = 0;
+ if (!check_str(p, "verify", str_verify_cb, td)) {
fgetpos(f, &off);
continue;
}
- if (!check_str(p, "rw", "write")) {
- td->ddir = DDIR_WRITE;
- td->sequential = 1;
+ if (!check_str(p, "rw", str_rw_cb, td)) {
fgetpos(f, &off);
continue;
}