[PATCH] RFC prevent tgtd from segfault when attempting to configure passthrough device

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

 



This was one way to resolve the segfault if .cmd_passthrough() is NULL


>From cd9c358476090d1a1758aba03157c30e60c53e57 Mon Sep 17 00:00:00 2001
From: Mark Harvey <markh794@xxxxxxxxx>
Date: Thu, 8 Jul 2010 06:48:02 +1000
Subject: Prevent segfault if passthrough params not correct.

If user neglects to supply '--device_type=pt' when creating a
passthrough device, tgtd would segfault due to .cmd_passthrough() being NULL

Signed-off-by: Mark Harvey <markh794@xxxxxxxxx>
---
 usr/bs_sg.c |    8 ++++++++
 usr/mmc.c   |    1 +
 usr/osd.c   |    1 +
 usr/sbc.c   |    1 +
 usr/scc.c   |    6 ++++++
 usr/smc.c   |    1 +
 usr/ssc.c   |    2 +-
 usr/tgtd.h  |    1 +
 8 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/usr/bs_sg.c b/usr/bs_sg.c
index bee6df5..9e519c0 100644
--- a/usr/bs_sg.c
+++ b/usr/bs_sg.c
@@ -89,6 +89,14 @@ static int graceful_write(int fd, void *p_write,
int to_write)
 	return 0;
 }

+/* Used by other target types to prevent segfault if .cmd_passthrough() null */
+int bs_sg_error(int host_no, struct scsi_cmd *cmd)
+{
+	eprintf("++++ Backing store incorrectly configured ++++\n");
+	eprintf("++++ Need to add \'--device-type=pt\'     ++++\n");
+	return -1;
+}
+
 static int bs_sg_rw(int host_no, struct scsi_cmd *cmd)
 {
 	int ret;
diff --git a/usr/mmc.c b/usr/mmc.c
index 0e34167..a8f6c03 100644
--- a/usr/mmc.c
+++ b/usr/mmc.c
@@ -2305,6 +2305,7 @@ static struct device_type_template mmc_template = {
 	.lu_online	= mmc_lu_online,
 	.lu_offline	= mmc_lu_offline,
 	.lu_exit	= spc_lu_exit,
+	.cmd_passthrough = bs_sg_error,
 	.ops		= {
 		{spc_test_unit,},
 		{spc_illegal_op,},
diff --git a/usr/osd.c b/usr/osd.c
index d81c6cf..22c7fc7 100644
--- a/usr/osd.c
+++ b/usr/osd.c
@@ -60,6 +60,7 @@ static struct device_type_template osd_template = {
 	.lu_online	= spc_lu_online,
 	.lu_offline	= spc_lu_offline,
 	.lu_exit	= spc_lu_exit,
+	.cmd_passthrough = bs_sg_error,
 	.ops		= {
 		/* 0x00 */
 		{spc_test_unit,},
diff --git a/usr/sbc.c b/usr/sbc.c
index a048d53..2798600 100644
--- a/usr/sbc.c
+++ b/usr/sbc.c
@@ -269,6 +269,7 @@ static struct device_type_template sbc_template = {
 	.lu_online	= spc_lu_online,
 	.lu_offline	= spc_lu_offline,
 	.lu_exit	= spc_lu_exit,
+	.cmd_passthrough = bs_sg_error,
 	.ops		= {
 		{spc_test_unit,},
 		{spc_illegal_op,},
diff --git a/usr/scc.c b/usr/scc.c
index 27bc07b..fe404df 100644
--- a/usr/scc.c
+++ b/usr/scc.c
@@ -52,6 +52,11 @@ static int scc_lu_init(struct scsi_lu *lu)
 	return 0;
 }

+static int scc_cmd_passthrough(int host_id, struct scsi_cmd *cmd)
+{
+	return -1;
+}
+
 static struct device_type_template scc_template = {
 	.type		= TYPE_RAID,
 	.lu_init	= scc_lu_init,
@@ -59,6 +64,7 @@ static struct device_type_template scc_template = {
 	.lu_online	= spc_lu_online,
 	.lu_offline	= spc_lu_offline,
 	.lu_exit	= spc_lu_exit,
+	.cmd_passthrough = scc_cmd_passthrough,
 	.ops		= {
 		{spc_test_unit,},
 		{spc_illegal_op,},
diff --git a/usr/smc.c b/usr/smc.c
index c0f25d6..1e76edf 100644
--- a/usr/smc.c
+++ b/usr/smc.c
@@ -787,6 +787,7 @@ struct device_type_template smc_template = {
 	.lu_online	= spc_lu_online,
 	.lu_offline	= spc_lu_offline,
 	.lu_config	= smc_lu_config,
+	.cmd_passthrough = bs_sg_error,
 	.ops	= {
 		{spc_test_unit,},
 		{spc_illegal_op,},
diff --git a/usr/ssc.c b/usr/ssc.c
index 84fa317..4adde2b 100644
--- a/usr/ssc.c
+++ b/usr/ssc.c
@@ -168,7 +168,7 @@ static struct device_type_template ssc_template = {
 	.lu_online	= spc_lu_online,
 	.lu_offline	= spc_lu_offline,
 	.lu_exit	= spc_lu_exit,
-
+	.cmd_passthrough = bs_sg_error,
 	.ops		= {
 		{spc_test_unit,},
 		{ssc_rw,},
diff --git a/usr/tgtd.h b/usr/tgtd.h
index 9c44994..5386438 100644
--- a/usr/tgtd.h
+++ b/usr/tgtd.h
@@ -349,4 +349,5 @@ int do_tgt_event_modify(int efd, struct list_head
*list, int fd, int events);

 int run_ext_program(const char *cmd,
 		    void (*callback)(void *data, int result), void *data);
+int bs_sg_error(int host_id, struct scsi_cmd *cmd);
 #endif
-- 
1.6.3.3
--
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