Skip to contentSkip to conversation

fio: add sgv4 engine

PATCH New Douglas Gilbert 1 participant 1 message Jul 6, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fio: add sgv4 engine

With its existing sg engine the fio utility supports many block devices (e.g. like /dev/sdb) and SCSI Generic (sg) character devices (e.g. like /dev/sg2). In both cases it uses the sg version 3 interface based on interface structure: sg_io_hdr. The sg engine cannot use bsg devices (e.g. like /dev/bsg/0:0:0:2) because bsg uses the sg version 4 (sgv4) interface based on interface structure: sg_io_v4 .

This patch adds a new "sgv4" engine that can be used with bsg device nodes. Additionally a patchset has been sent to the linux scsi list titled "sg: add v4 interface" on 20190616. With that patchset (or a later one) applied the sg driver will accept the v4 interface (both sync and async).

This patch includes a minor clean-up of the existing sg engine to make it a bit more widely applicable. A variable is renamed to stress that it is using the sg v3 interface.

---

The sgv4 engine is a copy of the sg engine with the interface structure changed from struct sg_io_hdr to sg_io_v4 . The write()/read() async interface is replaced by ioctl(SG_IOSUBMIT) and ioctl(SG_IORECEIVE) calls. No capabilities have been added or removed. At the current time the bsg driver no longer supports an async interface (it was previousy based on write()/read() but that code has been removed).

 Makefile       |    2 +-
 engines/sg.c   |   22 +-
 engines/sgv4.c | 1316 ++++++++++++++++++++++++++++++++++++++++++++++++
 io_u.h         |    5 +-
 os/os-linux.h  |    2 +
 5 files changed, 1335 insertions(+), 12 deletions(-)
 create mode 100644 engines/sgv4.c
Makefile +1 -1
index d7e5fca7..8c7756fe 100644
@@ -157,7 +157,7 @@ endif
 
 ifeq ($(CONFIG_TARGET_OS), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c engines/sg.c \
-		oslib/linux-dev-lookup.c engines/io_uring.c
+		engines/sgv4.c oslib/linux-dev-lookup.c engines/io_uring.c
   LIBS += -lpthread -ldl
   LDFLAGS += -rdynamic
 endif
engines/sg.c +12 -10
index c46b9aba..3029c74e 100644
@@ -359,7 +359,7 @@ re_read:
 
 			if (hdr->info & SG_INFO_CHECK) {
 				/* record if an io error occurred, ignore resid */
-				memcpy(&io_u->hdr, hdr, sizeof(struct sg_io_hdr));
+				memcpy(&io_u->hdr3, hdr, sizeof(struct sg_io_hdr));
 				sd->events[i + trims]->error = EIO;
 			}
 
@@ -380,7 +380,7 @@ re_read:
 #endif
 					if (hdr->info & SG_INFO_CHECK) {
 						/* record if an io error occurred, ignore resid */
-						memcpy(&st->trim_io_us[j]->hdr, hdr, sizeof(struct sg_io_hdr));
+						memcpy(&st->trim_io_us[j]->hdr3, hdr, sizeof(struct sg_io_hdr));
 						sd->events[i + trims]->error = EIO;
 					}
 				}
@@ -408,7 +408,7 @@ static enum fio_q_status fio_sgio_ioctl_doio(struct thread_data *td,
 					     struct io_u *io_u)
 {
 	struct sgio_data *sd = td->io_ops_data;
-	struct sg_io_hdr *hdr = &io_u->hdr;
+	struct sg_io_hdr *hdr = &io_u->hdr3;
 	int ret;
 
 	sd->events[0] = io_u;
@@ -428,7 +428,7 @@ static enum fio_q_status fio_sgio_rw_doio(struct thread_data *td,
 					  struct fio_file *f,
 					  struct io_u *io_u, int do_sync)
 {
-	struct sg_io_hdr *hdr = &io_u->hdr;
+	struct sg_io_hdr *hdr = &io_u->hdr3;
 	int ret;
 
 	ret = write(f->fd, hdr, sizeof(*hdr));
@@ -504,7 +504,7 @@ static void fio_sgio_rw_lba(struct sg_io_hdr *hdr, unsigned long long lba,
 
 static int fio_sgio_prep(struct thread_data *td, struct io_u *io_u)
 {
-	struct sg_io_hdr *hdr = &io_u->hdr;
+	struct sg_io_hdr *hdr = &io_u->hdr3;
 	struct sg_options *o = td->eo;
 	struct sgio_data *sd = td->io_ops_data;
 	unsigned long long nr_blocks, lba;
@@ -623,7 +623,7 @@ static void fio_sgio_unmap_setup(struct sg_io_hdr *hdr, struct sgio_trim *st)
 static enum fio_q_status fio_sgio_queue(struct thread_data *td,
 					struct io_u *io_u)
 {
-	struct sg_io_hdr *hdr = &io_u->hdr;
+	struct sg_io_hdr *hdr = &io_u->hdr3;
 	struct sgio_data *sd = td->io_ops_data;
 	int ret, do_sync = 0;
 
@@ -642,7 +642,7 @@ static enum fio_q_status fio_sgio_queue(struct thread_data *td,
 			assert(st->unmap_range_count == 1);
 			assert(io_u == st->trim_io_us[0]);
 #endif
-			hdr = &io_u->hdr;
+			hdr = &io_u->hdr3;
 
 			fio_sgio_unmap_setup(hdr, st);
 
@@ -693,7 +693,7 @@ static int fio_sgio_commit(struct thread_data *td)
 
 	st = sd->trim_queues[sd->current_queue];
 	io_u = st->trim_io_us[0];
-	hdr = &io_u->hdr;
+	hdr = &io_u->hdr3;
 
 	fio_sgio_unmap_setup(hdr, st);
 
@@ -865,6 +865,7 @@ static int fio_sgio_init(struct thread_data *td)
 {
 	struct sgio_data *sd;
 	struct sgio_trim *st;
+	struct sg_io_hdr *h3p;
 	int i;
 
 	sd = calloc(1, sizeof(*sd));
@@ -880,12 +881,13 @@ static int fio_sgio_init(struct thread_data *td)
 #ifdef FIO_SGIO_DEBUG
 	sd->trim_queue_map = calloc(td->o.iodepth, sizeof(int));
 #endif
-	for (i = 0; i < td->o.iodepth; i++) {
+	for (i = 0, h3p = sd->sgbuf; i < td->o.iodepth; i++, ++h3p) {
 		sd->trim_queues[i] = calloc(1, sizeof(struct sgio_trim));
 		st = sd->trim_queues[i];
 		st->unmap_param = calloc(td->o.iodepth + 1, sizeof(char[16]));
 		st->unmap_range_count = 0;
 		st->trim_io_us = calloc(td->o.iodepth, sizeof(struct io_u *));
+		h3p->interface_id = 'S';
 	}
 
 	td->io_ops_data = sd;
@@ -974,7 +976,7 @@ static int fio_sgio_open(struct thread_data *td, struct fio_file *f)
  */
 static char *fio_sgio_errdetails(struct io_u *io_u)
 {
-	struct sg_io_hdr *hdr = &io_u->hdr;
+	struct sg_io_hdr *hdr = &io_u->hdr3;
 #define MAXERRDETAIL 1024
 #define MAXMSGCHUNK  128
 	char *msg, msgchunk[MAXMSGCHUNK];
engines/sgv4.c new file +1316 -0

1,316 lines not on this page · raw message

io_u.h +4 -1
index e75993bd..35a71b6f 100644
@@ -122,7 +122,10 @@ struct io_u {
 		os_aiocb_t aiocb;
 #endif
 #ifdef FIO_HAVE_SGIO
-		struct sg_io_hdr hdr;
+		struct sg_io_hdr hdr3;
+#endif
+#ifdef FIO_HAVE_SGV4IO
+		struct sg_io_v4 hdr4;
 #endif
 #ifdef CONFIG_GUASI
 		guasi_req_t greq;
os/os-linux.h +2 -0
index 36339ef3..33eb5fff 100644
@@ -17,6 +17,7 @@
 #include <linux/raw.h>
 #include <linux/major.h>
 #include <linux/fs.h>
+#include <linux/bsg.h>
 #include <scsi/sg.h>
 
 #ifdef ARCH_HAVE_CRC_CRYPTO
@@ -36,6 +37,7 @@
 #define FIO_HAVE_CPU_AFFINITY
 #define FIO_HAVE_DISK_UTIL
 #define FIO_HAVE_SGIO
+#define FIO_HAVE_SGV4IO
 #define FIO_HAVE_IOPRIO
 #define FIO_HAVE_IOPRIO_CLASS
 #define FIO_HAVE_IOSCHED_SWITCH
Signature · 1 line
2.17.1