From: Jens Axboe Date: Wed, 30 Nov 2005 14:27:42 +0000 (+0100) Subject: [PATCH] fio: pin point where an error happened X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=b5a4be4878ab5e0588b11535c89e9715be69758b;p=disktools.git [PATCH] fio: pin point where an error happened --- diff --git a/fio.c b/fio.c index e1dd4c5..2f0a4ce 100644 --- a/fio.c +++ b/fio.c @@ -709,12 +709,12 @@ static void do_sync_verify(struct thread_data *td) if (!td->odirect) { if (!td->use_mmap) { if (fadvise(td->fd, td->file_offset, td->io_size, POSIX_FADV_DONTNEED) < 0) { - td->error = errno; + td_verror(td, errno); goto out; } } else { if (madvise(td->mmap, td->io_size, MADV_DONTNEED)) { - td->error = errno; + td_verror(td, errno); goto out; } } @@ -733,7 +733,7 @@ static void do_sync_verify(struct thread_data *td) if (td->cur_off != io_u->offset) { if (lseek(td->fd, io_u->offset, SEEK_SET) == -1) { - td->error = errno; + td_verror(td, errno); break; } } @@ -741,7 +741,7 @@ static void do_sync_verify(struct thread_data *td) ret = read(td->fd, io_u->buf, io_u->buflen); if (ret < (int) io_u->buflen) { if (ret == -1) { - td->error = errno; + td_verror(td, errno); break; } else if (!ret) break; @@ -784,7 +784,7 @@ static int __do_sync_rw(struct thread_data *td, struct io_u *io_u) { if (td->cur_off != io_u->offset) { if (lseek(td->fd, io_u->offset, SEEK_SET) == -1) { - td->error = errno; + td_verror(td, errno); return 1; } } @@ -826,7 +826,7 @@ static void do_sync_io(struct thread_data *td) if (ret < (int) io_u->buflen) { if (ret == -1) - td->error = errno; + td_verror(td, errno); break; } @@ -845,7 +845,7 @@ static void do_sync_io(struct thread_data *td) rate_throttle(td, usec, io_u->buflen); if (check_min_rate(td, &e)) { - td->error = ENODATA; + td_verror(td, ENODATA); break; } @@ -1017,7 +1017,7 @@ static void do_async_verify(struct thread_data *td) ret = io_u_queue(td, io_u); if (ret) { put_io_u(td, io_u); - td->error = ret; + td_verror(td, ret); break; } @@ -1031,7 +1031,7 @@ static void do_async_verify(struct thread_data *td) ret = io_u_getevents(td, 1, 1, NULL); if (ret != 1) { if (ret < 0) - td->error = ret; + td_verror(td, ret); break; } @@ -1079,7 +1079,7 @@ static void do_async_io(struct thread_data *td) ret = io_u_queue(td, io_u); if (ret) { put_io_u(td, io_u); - td->error = ret; + td_verror(td, ret); break; } @@ -1095,7 +1095,7 @@ static void do_async_io(struct thread_data *td) ret = io_u_getevents(td, min_evts, td->cur_depth, timeout); if (ret < 0) { - td->error = ret; + td_verror(td, ret); break; } else if (!ret) continue; @@ -1113,7 +1113,7 @@ static void do_async_io(struct thread_data *td) rate_throttle(td, usec, bytes_done); if (check_min_rate(td, &e)) { - td->error = ENODATA; + td_verror(td, ENODATA); break; } @@ -1146,7 +1146,7 @@ static void cleanup_aio(struct thread_data *td) static int init_aio(struct thread_data *td) { if (io_queue_init(td->aio_depth, &td->aio_ctx)) { - td->error = errno; + td_verror(td, errno); return 1; } @@ -1199,14 +1199,14 @@ static int init_io_u(struct thread_data *td) else if (td->mem_type == MEM_SHM) { td->shm_id = shmget(IPC_PRIVATE, td->orig_buffer_size, IPC_CREAT | 0600); if (td->shm_id < 0) { - td->error = errno; + td_verror(td, errno); perror("shmget"); return 1; } td->orig_buffer = shmat(td->shm_id, NULL, 0); if (td->orig_buffer == (void *) -1) { - td->error = errno; + td_verror(td, errno); perror("shmat"); td->orig_buffer = NULL; return 1; @@ -1214,7 +1214,7 @@ static int init_io_u(struct thread_data *td) } else if (td->mem_type == MEM_MMAP) { td->orig_buffer = mmap(NULL, td->orig_buffer_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (td->orig_buffer == MAP_FAILED) { - td->error = errno; + td_verror(td, errno); perror("mmap"); td->orig_buffer = NULL; return 1; @@ -1254,7 +1254,7 @@ static int create_file(struct thread_data *td, unsigned long long size, if (!size) { fprintf(stderr, "Need size for create\n"); - td->error = EINVAL; + td_verror(td, EINVAL); return 1; } @@ -1268,12 +1268,12 @@ static int create_file(struct thread_data *td, unsigned long long size, td->fd = open(td->file_name, O_WRONLY | oflags, 0644); if (td->fd < 0) { - td->error = errno; + td_verror(td, errno); return 1; } if (!extend && ftruncate(td->fd, td->file_size) == -1) { - td->error = errno; + td_verror(td, errno); return 1; } @@ -1294,9 +1294,9 @@ static int create_file(struct thread_data *td, unsigned long long size, continue; } else { if (r < 0) - td->error = errno; + td_verror(td, errno); else - td->error = EIO; + td_verror(td, EIO); break; } @@ -1318,7 +1318,7 @@ static int file_size(struct thread_data *td) struct stat st; if (fstat(td->fd, &st) == -1) { - td->error = errno; + td_verror(td, errno); return 1; } @@ -1333,7 +1333,7 @@ static int bdev_size(struct thread_data *td) size_t bytes; if (ioctl(td->fd, BLKGETSIZE64, &bytes) < 0) { - td->error = errno; + td_verror(td, errno); return 1; } @@ -1366,7 +1366,7 @@ static int get_file_size(struct thread_data *td) td->io_size = td->file_size - td->file_offset; if (td->io_size == 0) { fprintf(stderr, "Client%d: no io blocks\n", td->thread_number); - td->error = EINVAL; + td_verror(td, EINVAL); return 1; } @@ -1389,25 +1389,25 @@ static int setup_file_mmap(struct thread_data *td) td->mmap = mmap(NULL, td->file_size, flags, MAP_SHARED, td->fd, td->file_offset); if (td->mmap == MAP_FAILED) { td->mmap = NULL; - td->error = errno; + td_verror(td, errno); return 1; } if (td->invalidate_cache) { if (madvise(td->mmap, td->file_size, MADV_DONTNEED) < 0) { - td->error = errno; + td_verror(td, errno); return 1; } } if (td->sequential) { if (madvise(td->mmap, td->file_size, MADV_SEQUENTIAL) < 0) { - td->error = errno; + td_verror(td, errno); return 1; } } else { if (madvise(td->mmap, td->file_size, MADV_RANDOM) < 0) { - td->error = errno; + td_verror(td, errno); return 1; } } @@ -1419,19 +1419,19 @@ static int setup_file_plain(struct thread_data *td) { if (td->invalidate_cache) { if (fadvise(td->fd, td->file_offset, td->file_size, POSIX_FADV_DONTNEED) < 0) { - td->error = errno; + td_verror(td, errno); return 1; } } if (td->sequential) { if (fadvise(td->fd, td->file_offset, td->file_size, POSIX_FADV_SEQUENTIAL) < 0) { - td->error = errno; + td_verror(td, errno); return 1; } } else { if (fadvise(td->fd, td->file_offset, td->file_size, POSIX_FADV_RANDOM) < 0) { - td->error = errno; + td_verror(td, errno); return 1; } } @@ -1446,11 +1446,11 @@ static int setup_file(struct thread_data *td) if (stat(td->file_name, &st) == -1) { if (errno != ENOENT) { - td->error = errno; + td_verror(td, errno); return 1; } if (!td->create_file) { - td->error = ENOENT; + td_verror(td, ENOENT); return 1; } if (create_file(td, td->file_size, 0)) @@ -1483,7 +1483,7 @@ static int setup_file(struct thread_data *td) } if (td->fd == -1) { - td->error = errno; + td_verror(td, errno); return 1; } @@ -1769,7 +1769,7 @@ static void *thread_main(void *data) goto err; if (sched_setaffinity(td->pid, sizeof(td->cpumask), &td->cpumask) == -1) { - td->error = errno; + td_verror(td, errno); goto err; } @@ -1778,7 +1778,7 @@ static void *thread_main(void *data) if (td->ioprio) { if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) { - td->error = errno; + td_verror(td, errno); goto err; } } @@ -2201,8 +2201,10 @@ static void show_run_stats(void) td = &threads[i]; - if (td->error) + if (td->error) { + printf("Client%d: %s\n", td->thread_number, td->verror); continue; + } rs = &runstats[td->groupid]; diff --git a/fio.h b/fio.h index 81056a6..94165fc 100644 --- a/fio.h +++ b/fio.h @@ -66,6 +66,7 @@ struct group_run_stats { struct thread_data { char file_name[256]; char directory[256]; + char verror[256]; pthread_t thread; int thread_number; int groupid; @@ -169,6 +170,13 @@ struct thread_data { struct list_head io_hist_list; }; +#define td_verror(td, err) \ + do { \ + int e = (err); \ + (td)->error = e; \ + sprintf(td->verror, "file:%s:%d, error=%s", __FILE__, __LINE__, strerror(e)); \ + } while (0) + extern int parse_jobs_ini(char *); extern int parse_options(int, char **); extern void finish_log(struct thread_data *, struct io_log *, const char *);