On Thu, 02 Oct 2008 15:24:08 +0300 Alexander Nezhinsky <nezhinsky@xxxxxxxxx> wrote: > Implements a NULL I/O backing store, which shortcuts all scsi commands > and returns a success status without actually performing them. > Useful for performance measurements, by eliminating or significantly > reducing I/O side bottleneck. Not based on bs_threads, commands > are handled immediately from the context they are submitted from. > To add a device backed by this, "-E null" should be used with tgtadm, > also a dummy device name (any string) should be supplied, > because bs_null does not use any real devices but the current > code won't admit a null-string device name. > > Signed-off-by: Alexander Nezhinsky <nezhinsky@xxxxxxxxx> > --- > > diff --git a/usr/Makefile b/usr/Makefile > index 82ddf07..23215ef 100644 > --- a/usr/Makefile > +++ b/usr/Makefile > @@ -11,7 +11,7 @@ CFLAGS += -DISCSI > TGTD_OBJS += $(addprefix iscsi/, conn.o param.o session.o \ > iscsid.o target.o chap.o transport.o iscsi_tcp.o \ > isns.o libcrc32c.o) > -TGTD_OBJS += bs_rdwr.o bs_aio.o > +TGTD_OBJS += bs_rdwr.o bs_aio.o bs_null.o > > LIBS += -lcrypto > ifneq ($(ISCSI_RDMA),) > diff --git a/usr/bs_null.c b/usr/bs_null.c > new file mode 100644 > index 0000000..bb93d38 > --- /dev/null > +++ b/usr/bs_null.c > @@ -0,0 +1,103 @@ > +/* > + * NULL I/O backing store routine > + * > + * Copyright (C) 2008 Alexander Nezhinsky <nezhinskyf@xxxxxxxxx> > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License as > + * published by the Free Software Foundation, version 2 of the > + * License. > + * > + * This program is distributed in the hope that it will be useful, but > + * WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA > + * 02110-1301 USA > + */ > + > +#include <errno.h> > +#include <inttypes.h> > +#include <stdio.h> > +#include <stdlib.h> > + > +#include "list.h" > +#include "tgtd.h" > +#include "scsi.h" > +#include "bs_thread.h" No need to include bs_thread.h. > +#define NULL_BS_DEV_SIZE (1ULL << 40) > + > +int bs_null_cmd_submit(struct scsi_cmd *cmd) > +{ > + int result = SAM_STAT_GOOD; > + uint16_t asc = 0; > + uint8_t key = 0; > + uint8_t scb_op = cmd->scb[0]; > + > + set_cmd_async(cmd); > + > + if (scb_op == SYNCHRONIZE_CACHE || scb_op == SYNCHRONIZE_CACHE_16) { > + if (cmd->scb[1] & 0x2) { > + result = SAM_STAT_CHECK_CONDITION; > + key = ILLEGAL_REQUEST; > + asc = ASC_INVALID_FIELD_IN_CDB; > + } > + } > + > + scsi_set_result(cmd, result); > + > + if (result != SAM_STAT_GOOD) { > + eprintf("io error %p %x %" PRIu64 ", %m\n", > + cmd, scb_op, cmd->offset); > + sense_data_build(cmd, key, asc); > + } > + > + cmd->scsi_cmd_done(cmd, scsi_get_result(cmd)); > + return 0; > +} > + > +static int bs_null_open(struct scsi_lu *lu, char *path, > + int *fd, uint64_t *size) > +{ > + *size = NULL_BS_DEV_SIZE; > + dprintf("NULL backing store open, size: %" PRIu64 "\n", *size); > + return 0; > +} > + > +static void bs_null_close(struct scsi_lu *lu) > +{ > +} > + > +static int bs_null_init(struct scsi_lu *lu) > +{ > + return 0; > +} > + > +static void bs_null_exit(struct scsi_lu *lu) > +{ > +} No need to define bs_init and bs_exit. -- To unsubscribe from this list: send the line "unsubscribe stgt" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html