binject: correctly retrieve block size of device
[fio.git] / engines / binject.c
index a1b0181ce7d2b48e7cf9b7fefbb4db8867a8d00c..3e95594006ca46604624d3638e67919025a1448d 100644 (file)
@@ -22,7 +22,6 @@ struct binject_data {
        struct io_u **events;
        struct pollfd *pfds;
        int *fd_flags;
-       unsigned int bs;
 };
 
 static void binject_buc_init(struct binject_data *bd, struct io_u *io_u)
@@ -161,11 +160,10 @@ static int fio_binject_doio(struct thread_data *td, struct io_u *io_u)
 static int fio_binject_prep(struct thread_data *td, struct io_u *io_u)
 {
        struct binject_data *bd = td->io_ops->data;
+       unsigned int bs = io_u->file->file_data;
        struct b_user_cmd *buc = &io_u->buc;
 
-       bd->bs = 512;
-
-       if (io_u->xfer_buflen & (bd->bs - 1)) {
+       if (io_u->xfer_buflen & (bs - 1)) {
                log_err("read/write not sector aligned\n");
                return EINVAL;
        }
@@ -212,6 +210,28 @@ static struct io_u *fio_binject_event(struct thread_data *td, int event)
        return bd->events[event];
 }
 
+static int fio_binject_open_file(struct thread_data *td, struct fio_file *f)
+{
+       unsigned int bs;
+       int ret;
+
+       ret = generic_open_file(td, f);
+       if (ret)
+               return 1;
+
+       if (f->filetype != FIO_TYPE_BD) {
+               log_err("fio: binject only works with block devices\n");
+               return 1;
+       }
+       if (ioctl(f->fd, BLKSSZGET, &bs) < 0) {
+               td_verror(td, errno, "BLKSSZGET");
+               return 1;
+       }
+
+       f->file_data = bs;
+       return 0;
+}
+
 static void fio_binject_cleanup(struct thread_data *td)
 {
        struct binject_data *bd = td->io_ops->data;
@@ -257,7 +277,7 @@ static struct ioengine_ops ioengine = {
        .getevents      = fio_binject_getevents,
        .event          = fio_binject_event,
        .cleanup        = fio_binject_cleanup,
-       .open_file      = generic_open_file,
+       .open_file      = fio_binject_open_file,
        .close_file     = generic_close_file,
        .get_file_size  = generic_get_file_size,
        .flags          = FIO_RAWIO,