Manual page for fiologparser_hist.py and Makefile updates to install
[fio.git] / engines / sg.c
index c24b323fc5d609bcf984dc1095f98a75f71e6161..c1fe60200a7e4b11aade925393477283c0e95e39 100644 (file)
@@ -69,11 +69,40 @@ static int pollin_events(struct pollfd *pfds, int fds)
        return 0;
 }
 
+static int sg_fd_read(int fd, void *data, size_t size)
+{
+       int err = 0;
+
+       while (size) {
+               ssize_t ret;
+
+               ret = read(fd, data, size);
+               if (ret < 0) {
+                       if (errno == EAGAIN || errno == EINTR)
+                               continue;
+                       err = errno;
+                       break;
+               } else if (!ret)
+                       break;
+               else {
+                       data += ret;
+                       size -= ret;
+               }
+       }
+
+       if (err)
+               return err;
+       if (size)
+               return EAGAIN;
+
+       return 0;
+}
+
 static int fio_sgio_getevents(struct thread_data *td, unsigned int min,
                              unsigned int max,
                              const struct timespec fio_unused *t)
 {
-       struct sgio_data *sd = td->io_ops->data;
+       struct sgio_data *sd = td->io_ops_data;
        int left = max, eventNum, ret, r = 0;
        void *buf = sd->sgbuf;
        unsigned int i, events;
@@ -125,27 +154,20 @@ re_read:
                events = 0;
                for_each_file(td, f, i) {
                        for (eventNum = 0; eventNum < left; eventNum++) {
-                               ret = read(f->fd, p, sizeof(struct sg_io_hdr));
+                               ret = sg_fd_read(f->fd, p, sizeof(struct sg_io_hdr));
                                dprint(FD_IO, "sgio_getevents: ret: %d\n", ret);
-                               if (ret < 0) {
-                                       /*
-                                        *  not sure if EINTR is needed,
-                                        *  but seems like it should be.
-                                        */
-                                       if (errno == EAGAIN || errno == EINTR)
-                                               continue;
-                                       r = -errno;
-                                       td_verror(td, errno, "read");
+                               if (ret) {
+                                       r = -ret;
+                                       td_verror(td, r, "sg_read");
                                        break;
-                               } else if (ret) {
-                                       p += ret;
-                                       events += 1;  /* ret / sizeof(struct sg_io_hdr); */
-                                       dprint(FD_IO, "sgio_getevents: events: %d\n", events);
                                }
+                               p += sizeof(struct sg_io_hdr);
+                               events++;
+                               dprint(FD_IO, "sgio_getevents: events: %d\n", events);
                        }
                }
 
-               if (r < 0)
+               if (r < 0 && !events)
                        break;
                if (!events) {
                        usleep(1000);
@@ -185,7 +207,7 @@ re_read:
 static int fio_sgio_ioctl_doio(struct thread_data *td,
                               struct fio_file *f, struct io_u *io_u)
 {
-       struct sgio_data *sd = td->io_ops->data;
+       struct sgio_data *sd = td->io_ops_data;
        struct sg_io_hdr *hdr = &io_u->hdr;
        int ret;
 
@@ -246,7 +268,7 @@ static int fio_sgio_doio(struct thread_data *td, struct io_u *io_u, int do_sync)
 static int fio_sgio_prep(struct thread_data *td, struct io_u *io_u)
 {
        struct sg_io_hdr *hdr = &io_u->hdr;
-       struct sgio_data *sd = td->io_ops->data;
+       struct sgio_data *sd = td->io_ops_data;
        long long nr_blocks, lba;
 
        if (io_u->xfer_buflen & (sd->bs - 1)) {
@@ -344,7 +366,7 @@ static int fio_sgio_queue(struct thread_data *td, struct io_u *io_u)
 
 static struct io_u *fio_sgio_event(struct thread_data *td, int event)
 {
-       struct sgio_data *sd = td->io_ops->data;
+       struct sgio_data *sd = td->io_ops_data;
 
        return sd->events[event];
 }
@@ -441,7 +463,7 @@ static int fio_sgio_read_capacity(struct thread_data *td, unsigned int *bs,
 
 static void fio_sgio_cleanup(struct thread_data *td)
 {
-       struct sgio_data *sd = td->io_ops->data;
+       struct sgio_data *sd = td->io_ops_data;
 
        if (sd) {
                free(sd->events);
@@ -470,7 +492,7 @@ static int fio_sgio_init(struct thread_data *td)
        sd->sgbuf = malloc(sizeof(struct sg_io_hdr) * td->o.iodepth);
        memset(sd->sgbuf, 0, sizeof(struct sg_io_hdr) * td->o.iodepth);
        sd->type_checked = 0;
-       td->io_ops->data = sd;
+       td->io_ops_data = sd;
 
        /*
         * we want to do it, regardless of whether odirect is set or not
@@ -481,7 +503,7 @@ static int fio_sgio_init(struct thread_data *td)
 
 static int fio_sgio_type_check(struct thread_data *td, struct fio_file *f)
 {
-       struct sgio_data *sd = td->io_ops->data;
+       struct sgio_data *sd = td->io_ops_data;
        unsigned int bs = 0;
        unsigned long long max_lba = 0;
 
@@ -530,7 +552,7 @@ static int fio_sgio_type_check(struct thread_data *td, struct fio_file *f)
 
 static int fio_sgio_open(struct thread_data *td, struct fio_file *f)
 {
-       struct sgio_data *sd = td->io_ops->data;
+       struct sgio_data *sd = td->io_ops_data;
        int ret;
 
        ret = generic_open_file(td, f);