X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=engines%2Fsg.c;h=8acbd50adbe0ccecb98c886ed718aa74941870a8;hb=92aef550de95c5b33c489cbabd2c1a70e59475b3;hp=ac1d999797a2bd1f5bc7622340b2a7773887a004;hpb=a3edaf76b30880c3bf4455c30614ce88cdbbe071;p=fio.git diff --git a/engines/sg.c b/engines/sg.c index ac1d9997..8acbd50a 100644 --- a/engines/sg.c +++ b/engines/sg.c @@ -62,7 +62,8 @@ static int pollin_events(struct pollfd *pfds, int fds) } static int fio_sgio_getevents(struct thread_data *td, unsigned int min, - unsigned int max, struct timespec fio_unused *t) + unsigned int max, + const struct timespec fio_unused *t) { struct sgio_data *sd = td->io_ops->data; int left = max, ret, r = 0; @@ -77,10 +78,11 @@ static int fio_sgio_getevents(struct thread_data *td, unsigned int min, /* * don't block for min events == 0 */ - if (!min) { - sd->fd_flags[i] = fcntl(f->fd, F_GETFL); - fcntl(f->fd, F_SETFL, sd->fd_flags[i] | O_NONBLOCK); - } + if (!min) + sd->fd_flags[i] = fio_set_fd_nonblocking(f->fd, "sg"); + else + sd->fd_flags[i] = -1; + sd->pfds[i].fd = f->fd; sd->pfds[i].events = POLLIN; } @@ -143,8 +145,13 @@ re_read: } if (!min) { - for_each_file(td, f, i) - fcntl(f->fd, F_SETFL, sd->fd_flags[i]); + for_each_file(td, f, i) { + if (sd->fd_flags[i] == -1) + continue; + + if (fcntl(f->fd, F_SETFL, sd->fd_flags[i]) < 0) + log_err("fio: sg failed to restore fcntl flags: %s\n", strerror(errno)); + } } return r; @@ -166,7 +173,7 @@ static int fio_sgio_ioctl_doio(struct thread_data *td, return FIO_Q_COMPLETED; } -static int fio_sgio_rw_doio(struct fio_file *f, struct io_u *io_u, int sync) +static int fio_sgio_rw_doio(struct fio_file *f, struct io_u *io_u, int do_sync) { struct sg_io_hdr *hdr = &io_u->hdr; int ret; @@ -175,7 +182,7 @@ static int fio_sgio_rw_doio(struct fio_file *f, struct io_u *io_u, int sync) if (ret < 0) return ret; - if (sync) { + if (do_sync) { ret = read(f->fd, hdr, sizeof(*hdr)); if (ret < 0) return ret; @@ -185,14 +192,14 @@ static int fio_sgio_rw_doio(struct fio_file *f, struct io_u *io_u, int sync) return FIO_Q_QUEUED; } -static int fio_sgio_doio(struct thread_data *td, struct io_u *io_u, int sync) +static int fio_sgio_doio(struct thread_data *td, struct io_u *io_u, int do_sync) { struct fio_file *f = io_u->file; if (f->filetype == FIO_TYPE_BD) return fio_sgio_ioctl_doio(td, f, io_u); - return fio_sgio_rw_doio(f, io_u, sync); + return fio_sgio_rw_doio(f, io_u, do_sync); } static int fio_sgio_prep(struct thread_data *td, struct io_u *io_u) @@ -361,6 +368,7 @@ static int fio_sgio_type_check(struct thread_data *td, struct fio_file *f) if (ret) return 1; } else { + td_verror(td, EINVAL, "wrong file type"); log_err("ioengine sg only works on block devices\n"); return 1; }