int exitall_on_terminate = 0;
unsigned long long mlock_size = 0;
-static int setup_rate(struct thread_data *td)
-{
- int nr_reads_per_sec;
-
- if (!td->rate)
- return 0;
-
- if (td->rate < td->ratemin) {
- fprintf(stderr, "min rate larger than nominal rate\n");
- return -1;
- }
-
- nr_reads_per_sec = (td->rate * 1024) / td->min_bs;
- td->rate_usec_cycle = 1000000 / nr_reads_per_sec;
- td->rate_pending_usleep = 0;
- return 0;
-}
-
-static void setup_log(struct io_log **log)
-{
- struct io_log *l = malloc(sizeof(*l));
-
- l->nr_samples = 0;
- l->max_samples = 1024;
- l->log = malloc(l->max_samples * sizeof(struct io_sample));
- *log = l;
-}
-
-void finish_log(struct thread_data *td, struct io_log *log, const char *name)
-{
- char file_name[256];
- FILE *f;
- unsigned int i;
-
- snprintf(file_name, 200, "client%d_%s.log", td->thread_number, name);
- f = fopen(file_name, "w");
- if (!f) {
- perror("fopen log");
- return;
- }
-
- for (i = 0; i < log->nr_samples; i++)
- fprintf(f, "%lu, %lu, %u\n", log->log[i].time, log->log[i].val, log->log[i].ddir);
-
- fclose(f);
- free(log->log);
- free(log);
-}
-
static struct thread_data *get_new_job(int global, struct thread_data *parent)
{
struct thread_data *td;
return NULL;
td = &threads[thread_number++];
- if (parent)
- *td = *parent;
- else
- memset(td, 0, sizeof(*td));
+ *td = *parent;
+ td->name[0] = '\0';
td->fd = -1;
td->thread_number = thread_number;
- td->ddir = parent->ddir;
- td->ioprio = parent->ioprio;
- td->sequential = parent->sequential;
- td->bs = parent->bs;
- td->min_bs = parent->min_bs;
- td->max_bs = parent->max_bs;
- td->odirect = parent->odirect;
- td->thinktime = parent->thinktime;
- td->fsync_blocks = parent->fsync_blocks;
- td->start_delay = parent->start_delay;
- td->timeout = parent->timeout;
- td->io_engine = parent->io_engine;
- td->create_file = parent->create_file;
- td->overwrite = parent->overwrite;
- 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;
- td->iodepth = parent->iodepth;
- td->sync_io = parent->sync_io;
- td->mem_type = parent->mem_type;
- td->bw_avg_time = parent->bw_avg_time;
- td->create_serialize = parent->create_serialize;
- td->create_fsync = parent->create_fsync;
- td->loops = parent->loops;
- td->verify = parent->verify;
- td->stonewall = parent->stonewall;
- td->numjobs = parent->numjobs;
- td->use_thread = parent->use_thread;
- td->do_disk_util = parent->do_disk_util;
- memcpy(&td->cpumask, &parent->cpumask, sizeof(td->cpumask));
- strcpy(td->io_engine_name, parent->io_engine_name);
-
return td;
}
}
if (td->filetype == FIO_TYPE_FILE) {
+ char tmp[PATH_MAX];
+
if (td->directory && td->directory[0] != '\0')
- sprintf(td->file_name, "%s/%s.%d", td->directory, jobname, td->jobnum);
+ sprintf(tmp, "%s/%s.%d", td->directory, jobname, td->jobnum);
else
- sprintf(td->file_name, "%s.%d", jobname, td->jobnum);
+ sprintf(tmp, "%s.%d", jobname, td->jobnum);
+ td->file_name = strdup(tmp);
} else
- strncpy(td->file_name, jobname, sizeof(td->file_name) - 1);
+ td->file_name = strdup(jobname);
- sem_init(&td->mutex, 0, 0);
+ fio_sem_init(&td->mutex, 0);
td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
close(fd);
- srand48_r(seeds[0], &td->bsrange_state);
- srand48_r(seeds[1], &td->verify_state);
- srand48_r(seeds[2], &td->rwmix_state);
+ os_random_seed(seeds[0], &td->bsrange_state);
+ os_random_seed(seeds[1], &td->verify_state);
+ os_random_seed(seeds[2], &td->rwmix_state);
if (td->sequential)
return 0;
td->num_maps = num_maps;
memset(td->file_map, 0, num_maps * sizeof(long));
- srand48_r(seeds[3], &td->random_state);
+ os_random_seed(seeds[3], &td->random_state);
return 0;
}
fpos_t off;
FILE *f;
char *p;
+ int ret = 0;
f = fopen(file, "r");
if (!f) {
tmpbuf = malloc(4096);
while ((p = fgets(string, 4096, f)) != NULL) {
+ if (ret)
+ break;
if (is_empty_or_comment(p))
continue;
if (sscanf(p, "[%s]", name) != 1)
name[strlen(name) - 1] = '\0';
td = get_new_job(global, &def_thread);
- if (!td)
- return 1;
+ if (!td) {
+ ret = 1;
+ break;
+ }
fgetpos(f, &off);
while ((p = fgets(string, 4096, f)) != NULL) {
if (!check_int(p, "prio", &prio)) {
#ifndef FIO_HAVE_IOPRIO
fprintf(stderr, "io priorities not available\n");
- return 1;
+ ret = 1;
+ break;
#endif
td->ioprio |= prio;
fgetpos(f, &off);
if (!check_int(p, "prioclass", &prioclass)) {
#ifndef FIO_HAVE_IOPRIO
fprintf(stderr, "io priorities not available\n");
- return 1;
-#endif
+ ret = 1;
+ break;
+#else
td->ioprio |= prioclass << IOPRIO_CLASS_SHIFT;
fgetpos(f, &off);
continue;
+#endif
}
- if (!check_int(p, "direct", &td->odirect)) {
+ if (!check_int(p, "direct", &il)) {
+ td->odirect = il;
fgetpos(f, &off);
continue;
}
if (!check_int(p, "cpumask", &cpu)) {
#ifndef FIO_HAVE_CPU_AFFINITY
fprintf(stderr, "cpu affinity not available\n");
- return 1;
+ ret = 1;
+ break;
#endif
fill_cpu_mask(td->cpumask, cpu);
fgetpos(f, &off);
fgetpos(f, &off);
continue;
}
- if (!check_int(p, "invalidate",&td->invalidate_cache)) {
+ if (!check_int(p, "invalidate", &il)) {
+ td->invalidate_cache = il;
fgetpos(f, &off);
continue;
}
fgetpos(f, &off);
continue;
}
- if (!check_int(p, "sync", &td->sync_io)) {
+ if (!check_int(p, "sync", &il)) {
+ td->sync_io = il;
fgetpos(f, &off);
continue;
}
fgetpos(f, &off);
continue;
}
- if (!check_int(p, "create_serialize", &td->create_serialize)) {
+ if (!check_int(p, "create_serialize", &il)) {
+ td->create_serialize = il;
fgetpos(f, &off);
continue;
}
- if (!check_int(p, "create_fsync", &td->create_fsync)) {
+ if (!check_int(p, "create_fsync", &il)) {
+ td->create_fsync = il;
fgetpos(f, &off);
continue;
}
- if (!check_int(p, "end_fsync", &td->end_fsync)) {
+ if (!check_int(p, "end_fsync", &il)) {
+ td->end_fsync = il;
fgetpos(f, &off);
continue;
}
fgetpos(f, &off);
continue;
}
- if (!check_int(p, "overwrite", &td->overwrite)) {
+ if (!check_int(p, "overwrite", &il)) {
+ td->overwrite = il;
fgetpos(f, &off);
continue;
}
continue;
}
if (!check_strstore(p, "iolog", tmpbuf)) {
+ if (td->write_iolog) {
+ fprintf(stderr, "fio: read iolog overrides given write_iolog\n");
+ free(td->iolog_file);
+ td->write_iolog = 0;
+ }
td->iolog_file = strdup(tmpbuf);
td->read_iolog = 1;
- td->write_iolog = 0;
fgetpos(f, &off);
continue;
}
- if (!td->read_iolog &&
- !check_strstore(p, "write_iolog", tmpbuf)) {
- td->iolog_file = strdup(tmpbuf);
- td->write_iolog = 1;
+ if (!check_strstore(p, "write_iolog", tmpbuf)) {
+ if (!td->read_iolog) {
+ td->iolog_file = strdup(tmpbuf);
+ td->write_iolog = 1;
+ } else
+ fprintf(stderr, "fio: read iolog overrides given write_iolog\n");
fgetpos(f, &off);
continue;
}
continue;
}
if (!check_strstore(p, "ioscheduler", tmpbuf)) {
+#ifndef FIO_HAVE_IOSCHED_SWITCH
+ fprintf(stderr, "io scheduler switching not available\n");
+ ret = 1;
+ break;
+#else
td->ioscheduler = strdup(tmpbuf);
fgetpos(f, &off);
continue;
+#endif
}
+ /*
+ * Don't break here, continue parsing options so we
+ * dump all the bad ones. Makes trial/error fixups
+ * easier on the user.
+ */
printf("Client%d: bad option %s\n",td->thread_number,p);
- return 1;
+ ret = 1;
}
- fsetpos(f, &off);
- if (add_job(td, name, 0))
- return 1;
+ if (!ret) {
+ fsetpos(f, &off);
+ ret = add_job(td, name, 0);
+ }
+ if (ret)
+ break;
}
free(string);
free(name);
free(tmpbuf);
fclose(f);
- return 0;
+ return ret;
}
static int fill_def_thread(void)
struct shmid_ds sbuf;
if (threads) {
- shmdt(threads);
+ shmdt((void *) threads);
threads = NULL;
shmctl(shm_id, IPC_RMID, &sbuf);
}