[stgt] [PATCH 1/1] null backing store

Alexander Nezhinsky nezhinsky at gmail.com
Wed Aug 27 18:39:05 CEST 2008


>From 75c9a58fd094360c59b1bcd3e05a429dd8f68f4d Mon Sep 17 00:00:00 2001
From: Alexander Nezhinsky <nezhinsky at gmail.com>
Date: Tue, 26 Aug 2008 17:23:37 +0300
Subject: [PATCH 1/1] null backing store

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.

Signed-off-by: Alexander Nezhinsky <nezhinsky at gmail.com>
---
 usr/Makefile  |    2 +-
 usr/bs_null.c |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+), 1 deletions(-)
 create mode 100644 usr/bs_null.c

diff --git a/usr/Makefile b/usr/Makefile
index 4245709..a089556 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..2e8a8d5
--- /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)
+
+static void bs_null_request(struct scsi_cmd *cmd)
+{
+	int result = SAM_STAT_GOOD;
+	uint16_t asc = 0;
+	uint8_t key = 0;
+	uint8_t scb_op = cmd->scb[0];
+
+	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);
+	}
+}
+
+static int bs_null_open(struct scsi_lu *lu, char *path,
+			int *fd, uint64_t *size)
+{
+	*size = NULL_BS_DEV_SIZE;
+	eprintf("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)
+{
+	struct bs_thread_info *info = BS_THREAD_I(lu);
+
+	return bs_thread_open(info, bs_null_request);
+}
+
+static void bs_null_exit(struct scsi_lu *lu)
+{
+	struct bs_thread_info *info = BS_THREAD_I(lu);
+
+	bs_thread_close(info);
+}
+
+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_thread_cmd_submit,
+	.bs_cmd_done		= bs_null_cmd_done,
+};
+
+__attribute__((constructor)) static void bs_null_constructor(void)
+{
+	register_backingstore_template(&null_bst);
+}
-- 
1.5.6.3

--
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