[Stgt-devel] [PATCH 3/6] iser rounding

Pete Wyckoff pw
Mon Dec 10 16:05:18 CET 2007


RDMA data packets are not padded up to 4 byte boundaries, unlike TCP.
Reasons for this can be found in doc/README.iser.  Add a transport
field to specify the padding amount, using 1 for RDMA to effectively
disable rounding.

Signed-off-by: Pete Wyckoff <pw at osc.edu>
---
 usr/iscsi/iscsi_tcp.c |    1 +
 usr/iscsi/iscsid.c    |   28 ++++++++++++++++------------
 usr/iscsi/transport.h |    1 +
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/usr/iscsi/iscsi_tcp.c b/usr/iscsi/iscsi_tcp.c
index 99db99d..68ec7c8 100644
--- a/usr/iscsi/iscsi_tcp.c
+++ b/usr/iscsi/iscsi_tcp.c
@@ -339,6 +339,7 @@ struct iscsi_transport iscsi_tcp = {
 	.name			= "iscsi",
 	.rdma			= 0,
 	.task_trans_len		= 0,
+	.data_padding		= PAD_WORD_LEN,
 	.ep_init		= iscsi_tcp_init,
 	.ep_login_complete	= iscsi_tcp_conn_login_complete,
 	.ep_task_init		= iscsi_tcp_task_init,
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index 3cb804e..defe3a7 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -1184,7 +1184,8 @@ static int iscsi_target_cmd_queue(struct iscsi_task *task)
 				uint32_t len;
 				void *buf;
 
-				len = roundup(in_length, 4);
+				len = roundup(in_length,
+					      conn->tp->data_padding);
 				buf = conn->tp->alloc_data_buf(conn, len);
 				if (!buf)
 					return -ENOMEM;
@@ -1442,9 +1443,9 @@ static int iscsi_scsi_cmd_rx_start(struct iscsi_connection *conn)
 	struct iscsi_task *task;
 	int ahs_len, imm_len, data_len, ext_len;
 
-	ahs_len = roundup(req->hlength * 4, 4);
-	imm_len = roundup(ntoh24(req->dlength), 4);
-	data_len = roundup(ntohl(req->data_length), 4);
+	ahs_len = req->hlength * 4;
+	imm_len = roundup(ntoh24(req->dlength), conn->tp->data_padding);
+	data_len = roundup(ntohl(req->data_length), conn->tp->data_padding);
 
 	dprintf("%u %x %d %d %d %x %x\n", conn->session->tsih,
 		req->cdb[0], ahs_len, imm_len, data_len,
@@ -1835,11 +1836,11 @@ again:
 			conn->rx_buffer = conn->req_buffer;
 			conn->req.ahs = conn->rx_buffer;
 			conn->req.data = conn->rx_buffer
-				+ roundup(conn->req.bhs.hlength * 4, 4);
+				+ conn->req.bhs.hlength * 4;
 		}
 		conn->req.ahssize = conn->req.bhs.hlength * 4;
 		conn->req.datasize = ntoh24(conn->req.bhs.dlength);
-		conn->rx_size = roundup(conn->req.ahssize, 4);
+		conn->rx_size = conn->req.ahssize;
 		if (conn->rx_size) {
 			conn->rx_buffer = conn->req.ahs;
 			conn->rx_iostate = IOSTATE_RX_AHS;
@@ -1878,8 +1879,7 @@ again:
 		crc = ~0;
 		crc = crc32c(crc, &conn->req.bhs, BHS_SIZE);
 		if (conn->req.ahssize)
-			crc = crc32c(crc, conn->req.ahs,
-				     roundup(conn->req.ahssize, 4));
+			crc = crc32c(crc, conn->req.ahs, conn->req.ahssize);
 		crc = ~crc;
 		if (*((uint32_t *)conn->rx_digest) != crc) {
 			eprintf("rx hdr digest error 0x%x calc 0x%x\n",
@@ -1888,7 +1888,8 @@ again:
 		}
 		conn->rx_iostate = IOSTATE_RX_INIT_DATA;
 	case IOSTATE_RX_INIT_DATA:
-		conn->rx_size = roundup(conn->req.datasize, 4);
+		conn->rx_size = roundup(conn->req.datasize,
+					conn->tp->data_padding);
 		if (conn->rx_size) {
 			conn->rx_iostate = IOSTATE_RX_DATA;
 			conn->rx_buffer = conn->req.data;
@@ -1911,7 +1912,9 @@ again:
 			break;
 	case IOSTATE_RX_CHECK_DDIGEST:
 		crc = ~0;
-		crc = crc32c(crc, conn->req.data, roundup(conn->req.datasize, 4));
+		crc = crc32c(crc, conn->req.data,
+			     roundup(conn->req.datasize,
+				     conn->tp->data_padding));
 		crc = ~crc;
 		conn->rx_iostate = IOSTATE_RX_END;
 		if (*((uint32_t *)conn->rx_digest) != crc) {
@@ -2033,7 +2036,7 @@ void iscsi_tx_handler(struct iscsi_connection *conn)
 			conn->tx_iostate = IOSTATE_TX_DATA;
 			conn->tx_buffer = conn->rsp.data;
 			conn->tx_size = conn->rsp.datasize;
-			pad = conn->tx_size & (PAD_WORD_LEN - 1);
+			pad = conn->tx_size & (conn->tp->data_padding - 1);
 			if (pad) {
 				pad = PAD_WORD_LEN - pad;
 				memset(conn->tx_buffer + conn->tx_size, 0, pad);
@@ -2053,7 +2056,8 @@ void iscsi_tx_handler(struct iscsi_connection *conn)
 	case IOSTATE_TX_INIT_DDIGEST:
 		crc = ~0;
 		crc = crc32c(crc, conn->rsp.data,
-			     roundup(conn->rsp.datasize, 4));
+			     roundup(conn->rsp.datasize,
+				     conn->tp->data_padding));
 		*(uint32_t *)conn->tx_digest = ~crc;
 		conn->tx_iostate = IOSTATE_TX_DDIGEST;
 		conn->tx_buffer = conn->tx_digest;
diff --git a/usr/iscsi/transport.h b/usr/iscsi/transport.h
index 38e28ae..58bb992 100644
--- a/usr/iscsi/transport.h
+++ b/usr/iscsi/transport.h
@@ -10,6 +10,7 @@ struct iscsi_transport {
 	const char *name;
 	int rdma;
 	int task_trans_len;
+	int data_padding;
 
 	int (*ep_init) (void);
 	int (*ep_login_complete)(struct iscsi_connection *conn);
-- 
1.5.3.4




More information about the stgt mailing list