- /*
- * Sort the entry into the verification list
- */
-restart:
- p = &td->io_hist_tree.rb_node;
- parent = NULL;
- while (*p) {
- parent = *p;
-
- __ipo = rb_entry(parent, struct io_piece, rb_node);
- if (ipo->file < __ipo->file)
- p = &(*p)->rb_left;
- else if (ipo->file > __ipo->file)
- p = &(*p)->rb_right;
- else if (ipo->offset < __ipo->offset)
- p = &(*p)->rb_left;
- else if (ipo->offset > __ipo->offset)
- p = &(*p)->rb_right;
- else {
- assert(ipo->len == __ipo->len);
- td->io_hist_len--;
- rb_erase(parent, &td->io_hist_tree);
- free(__ipo);
- goto restart;
- }
- }
-
- rb_link_node(&ipo->rb_node, parent, p);
- rb_insert_color(&ipo->rb_node, &td->io_hist_tree);
- td->io_hist_len++;
-}
-
-void write_iolog_close(struct thread_data *td)
-{
- fflush(td->iolog_f);
- fclose(td->iolog_f);
- free(td->iolog_buf);
- td->iolog_f = NULL;
- td->iolog_buf = NULL;
-}
-
-/*
- * Read version 2 iolog data. It is enhanced to include per-file logging,
- * syncs, etc.
- */
-static int read_iolog2(struct thread_data *td, FILE *f)
-{
- unsigned long long offset;
- unsigned int bytes;
- int reads, writes, waits, fileno = 0, file_action = 0; /* stupid gcc */
- char *fname, *act;
- char *str, *p;
- enum fio_ddir rw;
-
- free_release_files(td);
-
- /*
- * Read in the read iolog and store it, reuse the infrastructure
- * for doing verifications.
- */
- str = malloc(4096);
- fname = malloc(256+16);
- act = malloc(256+16);
-
- reads = writes = waits = 0;
- while ((p = fgets(str, 4096, f)) != NULL) {
- struct io_piece *ipo;
- int r;
-
- r = sscanf(p, "%256s %256s %llu %u", fname, act, &offset,
- &bytes);
- if (r == 4) {
- /*
- * Check action first
- */
- if (!strcmp(act, "wait"))
- rw = DDIR_WAIT;
- else if (!strcmp(act, "read"))
- rw = DDIR_READ;
- else if (!strcmp(act, "write"))
- rw = DDIR_WRITE;
- else if (!strcmp(act, "sync"))
- rw = DDIR_SYNC;
- else if (!strcmp(act, "datasync"))
- rw = DDIR_DATASYNC;
- else {
- log_err("fio: bad iolog file action: %s\n",
- act);
- continue;
- }
- } else if (r == 2) {
- rw = DDIR_INVAL;
- if (!strcmp(act, "add")) {
- td->o.nr_files++;
- fileno = add_file(td, fname);
- file_action = FIO_LOG_ADD_FILE;
- continue;
- } else if (!strcmp(act, "open")) {
- fileno = get_fileno(td, fname);
- file_action = FIO_LOG_OPEN_FILE;
- } else if (!strcmp(act, "close")) {
- fileno = get_fileno(td, fname);
- file_action = FIO_LOG_CLOSE_FILE;
- } else {
- log_err("fio: bad iolog file action: %s\n",
- act);
- continue;
- }
- } else {
- log_err("bad iolog2: %s", p);
- continue;
- }
-
- if (rw == DDIR_READ)
- reads++;
- else if (rw == DDIR_WRITE) {
- /*
- * Don't add a write for ro mode
- */
- if (read_only)
- continue;
- writes++;
- } else if (rw == DDIR_WAIT) {
- waits++;
- } else if (rw == DDIR_INVAL) {
- } else if (!ddir_sync(rw)) {
- log_err("bad ddir: %d\n", rw);
- continue;
- }
-
- /*
- * Make note of file
- */
- ipo = malloc(sizeof(*ipo));
- memset(ipo, 0, sizeof(*ipo));
- INIT_FLIST_HEAD(&ipo->list);
- ipo->ddir = rw;
- if (rw == DDIR_WAIT) {
- ipo->delay = offset;
- } else {
- ipo->offset = offset;
- ipo->len = bytes;
- if (bytes > td->o.max_bs[rw])
- td->o.max_bs[rw] = bytes;
- ipo->fileno = fileno;
- ipo->file_action = file_action;
- }
-
- queue_io_piece(td, ipo);
- }
-
- free(str);
- free(act);
- free(fname);
-
- if (writes && read_only) {
- log_err("fio: <%s> skips replay of %d writes due to"
- " read-only\n", td->o.name, writes);
- writes = 0;
- }
-
- if (!reads && !writes && !waits)
- return 1;
- else if (reads && !writes)
- td->o.td_ddir = TD_DDIR_READ;
- else if (!reads && writes)
- td->o.td_ddir = TD_DDIR_WRITE;
- else
- td->o.td_ddir = TD_DDIR_RW;
-
- return 0;