unsigned int bs;
};
+static inline void sgio_hdr_init(struct sgio_data *sd, struct sg_io_hdr *hdr,
+ struct io_u *io_u)
+{
+ memset(hdr, 0, sizeof(*hdr));
+ memset(sd->cdb, 0, sizeof(sd->cdb));
+
+ hdr->interface_id = 'S';
+ hdr->cmdp = sd->cdb;
+ hdr->cmd_len = sizeof(sd->cdb);
+
+ if (io_u) {
+ hdr->dxferp = io_u->buf;
+ hdr->dxfer_len = io_u->buflen;
+ }
+}
+
static int fio_sgio_sync(struct thread_data *td)
{
- /*
- * need to issue flush cache
- */
- return 0;
+ struct sgio_data *sd = td->io_data;
+ struct sg_io_hdr hdr;
+
+ sgio_hdr_init(sd, &hdr, NULL);
+ hdr.dxfer_direction = SG_DXFER_NONE;
+
+ hdr.cmdp[0] = 0x35;
+
+ return ioctl(td->fd, SG_IO, &hdr);
}
-static int fio_sgio_queue(struct thread_data *td, struct io_u *io_u)
+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_data;
- int nr_blocks, lba, ret;
+ int nr_blocks, lba;
if (io_u->buflen & (sd->bs - 1)) {
fprintf(stderr, "read/write not sector aligned\n");
return EINVAL;
}
- memset(hdr, 0, sizeof(*hdr));
- memset(sd->cdb, 0, sizeof(sd->cdb));
-
- hdr->interface_id = 'S';
- hdr->cmdp = sd->cdb;
- hdr->cmd_len = sizeof(sd->cdb);
- hdr->dxferp = io_u->buf;
- hdr->dxfer_len = io_u->buflen;
+ sgio_hdr_init(sd, hdr, io_u);
if (io_u->ddir == DDIR_READ) {
hdr->dxfer_direction = SG_DXFER_FROM_DEV;
hdr->cmdp[5] = lba & 0xff;
hdr->cmdp[7] = (nr_blocks >> 8) & 0xff;
hdr->cmdp[8] = nr_blocks & 0xff;
+ return 0;
+}
+
+static int fio_sgio_queue(struct thread_data *td, struct io_u *io_u)
+{
+ struct sg_io_hdr *hdr = &io_u->hdr;
+ struct sgio_data *sd = td->io_data;
+ int ret;
ret = ioctl(td->fd, SG_IO, hdr);
if (ret < 0)
sd = malloc(sizeof(*sd));
sd->bs = bs;
- td->io_prep = NULL;
+ td->io_prep = fio_sgio_prep;
td->io_queue = fio_sgio_queue;
td->io_getevents = fio_syncio_getevents;
td->io_event = fio_sgio_event;
td->io_cleanup = fio_syncio_cleanup;
td->io_sync = fio_sgio_sync;
+ /*
+ * we want to do it, regardless of whether odirect is set or not
+ */
+ td->override_sync = 1;
+
sd->last_io_u = NULL;
td->io_data = sd;
return 0;