[Stgt-devel] [PATCH 10/20] iser connection transport data

FUJITA Tomonori tomof
Sat Nov 17 02:46:49 CET 2007


On Wed, 14 Nov 2007 14:05:03 -0500
Pete Wyckoff <pw at osc.edu> wrote:

> tomof at acm.org wrote on Wed, 14 Nov 2007 23:33 +0900:
> > Moving connection allocation to transport would work better for iSER?
> > 
> > This patch is against the lastest git tree
> > (09532079071d65ec62dae982324ab07a895e16f1).
> [..]
> > -struct tcp_conn_info {
> > +struct iscsi_tcp_connection {
> >  	int fd;
> > +
> > +	struct iscsi_connection iscsi_conn;
> >  };
> 
> Sure, good idea.  It will create a bit of churn against the later
> patches but easily fixed.  Note that iser adds a task->trans_data
> too; you could treat it similarly.

How about this?


diff --git a/usr/iscsi/iscsi_tcp.c b/usr/iscsi/iscsi_tcp.c
index 905ec4d..3cb5944 100644
--- a/usr/iscsi/iscsi_tcp.c
+++ b/usr/iscsi/iscsi_tcp.c
@@ -308,6 +308,21 @@ void iscsi_event_modify(struct iscsi_connection *conn, int events)
 		eprintf("tgt_event_modify failed\n");
 }
 
+struct iscsi_task *iscsi_tcp_alloc_task(struct iscsi_connection *conn,
+					size_t ext_len)
+{
+	struct iscsi_task *task;
+
+	task = malloc(sizeof(*task) + ext_len);
+	if (task)
+		memset(task, 0, sizeof(*task) + ext_len);
+	return task;
+}
+void iscsi_tcp_free_task(struct iscsi_task *task)
+{
+	free(task);
+}
+
 void *iscsi_tcp_alloc_data_buf(struct iscsi_connection *conn, size_t sz)
 {
 	return valloc(sz);
@@ -347,6 +362,8 @@ struct iscsi_transport iscsi_tcp = {
 	.ep_release		= iscsi_tcp_release,
 	.ep_show		= iscsi_tcp_show,
 	.ep_event_modify	= iscsi_event_modify,
+	.alloc_task		= iscsi_tcp_alloc_task,
+	.free_task		= iscsi_tcp_free_task,
 	.alloc_data_buf		= iscsi_tcp_alloc_data_buf,
 	.free_data_buf		= iscsi_tcp_free_data_buf,
 	.ep_getsockname		= iscsi_tcp_getsockname,
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index 27a9a3d..9872f1b 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -997,15 +997,14 @@ static struct iscsi_task *iscsi_alloc_task(struct iscsi_connection *conn,
 	struct iscsi_task *task;
 	void *buf;
 
-	task = malloc(sizeof(*task) + ext_len);
+	task = conn->tp->alloc_task(conn, ext_len);
 	if (!task)
 		return NULL;
-	memset(task, 0, sizeof(*task) + ext_len);
 
 	if (data_len) {
 		buf = conn->tp->alloc_data_buf(conn, data_len);
 		if (!buf) {
-			free(task);
+			conn->tp->free_task(task);
 			return NULL;
 		}
 		task->data = buf;
@@ -1027,7 +1026,7 @@ void iscsi_free_task(struct iscsi_task *task)
 	conn->tp->free_data_buf(conn, scsi_get_in_buffer(&task->scmd));
 	conn->tp->free_data_buf(conn, scsi_get_out_buffer(&task->scmd));
 
-	free(task);
+	conn->tp->free_task(task);
 	conn_put(conn);
 }
 
diff --git a/usr/iscsi/transport.h b/usr/iscsi/transport.h
index e1b514d..e4997c4 100644
--- a/usr/iscsi/transport.h
+++ b/usr/iscsi/transport.h
@@ -4,6 +4,7 @@
 #include <sys/socket.h>
 
 struct iscsi_connection;
+struct iscsi_task;
 
 struct iscsi_transport {
 	const char *name;
@@ -18,9 +19,10 @@ struct iscsi_transport {
 	void (*ep_write_end)(struct iscsi_connection *conn);
 	size_t (*ep_close)(struct iscsi_connection *conn);
 	void (*ep_release)(struct iscsi_connection *conn);
-
 	int (*ep_show)(struct iscsi_connection *conn, char *buf, int rest);
 	void (*ep_event_modify)(struct iscsi_connection *conn, int events);
+	struct iscsi_task *(*alloc_task)(struct iscsi_connection *conn, size_t ext_len);
+	void (*free_task)(struct iscsi_task *task);
 	void *(*alloc_data_buf)(struct iscsi_connection *conn, size_t sz);
 	void (*free_data_buf)(struct iscsi_connection *conn, void *buf);
 	int (*ep_getsockname)(struct iscsi_connection *conn,



More information about the stgt mailing list