[stgt] [PATCH] null backing store

Alexander Nezhinsky nezhinsky at gmail.com
Thu Oct 2 14:24:08 CEST 2008


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 at gmail.com>
---

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 at gmail.com>
+ *
+ * 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"
+
+#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)
+{
+}
+
+static int bs_null_cmd_done(struct scsi_cmd *cmd)
+{
+	return 0;
+}
+
+static struct backingstore_template null_bst = {
+	.bs_name		= "null",
+	.bs_datasize		= sizeof(struct bs_thread_info),
+	.bs_open		= bs_null_open,
+	.bs_close		= bs_null_close,
+	.bs_init		= bs_null_init,
+	.bs_exit		= bs_null_exit,
+	.bs_cmd_submit		= bs_null_cmd_submit,
+	.bs_cmd_done		= bs_null_cmd_done,
+};
+
+__attribute__((constructor)) static void bs_null_constructor(void)
+{
+	register_backingstore_template(&null_bst);
+}
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list