[Stgt-devel] [PATCH 04/20] iser bidi alloc read buf

FUJITA Tomonori tomof
Wed Nov 14 15:21:12 CET 2007


From: FUJITA Tomonori <tomof at acm.org>
Subject: Re: [Stgt-devel] [PATCH 04/20] iser bidi alloc read buf
Date: Mon, 12 Nov 2007 23:14:34 +0900

> On Tue, 16 Oct 2007 11:19:03 -0400
> Pete Wyckoff <pw at osc.edu> wrote:
> 
> > Allocate the read buffer for bidirectional commands in the transport to
> > pass down to devices.  A device can fill and return this buffer in
> > task->uaddr, and thus choose to do the read or write processing in any
> > order.  Unfortunately, this allocation can not be combined with the task
> > and task->data allocation as the bidi read size is not known until after
> > AHS processing.
> 
> I've been cleaning up the code in preparation for bidi. For exmaple,
> moving bidi stuff in iscsi_task (read_len, write_len, and
> data_direction) to scsi_cmd so that everyone can use bidi.
> 
> I'll add bidi support like this when I finish the preparation.

I merged this:

diff --git a/usr/iscsi/iscsi_tcp.c b/usr/iscsi/iscsi_tcp.c
index 9bcd6df..e227cb2 100644
--- a/usr/iscsi/iscsi_tcp.c
+++ b/usr/iscsi/iscsi_tcp.c
@@ -269,7 +269,8 @@ void *iscsi_tcp_alloc_data_buf(struct iscsi_connection *conn, size_t sz)
 
 void iscsi_tcp_free_data_buf(struct iscsi_connection *conn, void *buf)
 {
-	free(buf);
+	if (buf)
+		free(buf);
 }
 
 struct iscsi_transport iscsi_tcp = {
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index 1db41b7..8d8cdab 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -1000,10 +1000,10 @@ void iscsi_free_task(struct iscsi_task *task)
 {
 	struct iscsi_connection *conn = task->conn;
 
-	if (task->data)
-		conn->tp->free_data_buf(conn, task->data);
+	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);
-	/* from alloc */
 	conn_put(conn);
 }
 
@@ -1134,9 +1134,21 @@ static int iscsi_target_cmd_queue(struct iscsi_task *task)
 	if (dir == DATA_BIDIRECTIONAL && ahslen >= 8) {
 		struct iscsi_rlength_ahdr *ahs_bidi = (void *) ahs;
 		if (ahs_bidi->ahstype == ISCSI_AHSTYPE_RLENGTH) {
-			scsi_set_in_length(scmd, ntohl(ahs_bidi->read_length));
-			dprintf("bidi read len %u\n",
-				ntohl(ahs_bidi->read_length));
+			uint32_t in_length = ntohl(ahs_bidi->read_length);
+
+			dprintf("bidi read len %u\n", in_length);
+
+			if (in_length) {
+				void *buf;
+
+				in_length = roundup(in_length, 4);
+				buf = conn->tp->alloc_data_buf(conn, in_length);
+				if (!buf)
+					return -ENOMEM;
+
+				scsi_set_in_buffer(scmd, buf);
+				scsi_set_in_length(scmd, in_length);
+			}
 		}
 	}
 
-- 
1.5.3.4




More information about the stgt mailing list