Re: [PATCH] null backing store

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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. 

Comparison with the thread-based implementation shows the impact of 
threading associated overhead on performance:
Read,  thread: 69kIOPS, non-thread:72kIOPS
Write, thread: 47kIOPS, non-thread:59kIOPS
In both Read and Write tests, CPU util. dropped from ~30% to ~10%
when switched to the non-thread based model.  

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..3fb4bf4 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -1,5 +1,7 @@
 mandir = /usr/share/man
 
+TGTD_OBJS += bs_null.o
+
 ifneq ($(IBMVIO),)
 CFLAGS += -DIBMVIO -DUSE_KERNEL
 TGTD_OBJS += $(addprefix ibmvio/, ibmvio.o)
diff --git a/usr/bs_null.c b/usr/bs_null.c
new file mode 100644
index 0000000..6de30d8
--- /dev/null
+++ b/usr/bs_null.c
@@ -0,0 +1,91 @@
+/*
+ * 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"
+
+#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_cmd_done(struct scsi_cmd *cmd)
+{
+	return 0;
+}
+
+static struct backingstore_template null_bst = {
+	.bs_name		= "null",
+	.bs_datasize		= 0,
+	.bs_open		= bs_null_open,
+	.bs_close		= bs_null_close,
+	.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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux