[openib-general] [PATCH] iser: moved iSCSI controls to be sent in zero-copy + kzalloc-tions

Or Gerlitz ogerlitz at voltaire.com
Thu Jan 12 00:52:16 PST 2006


I just commited the patch below as r4957

moved iSCSI controls to be sent in zero-copy, removed iscsi_iser_conn->send_cache 
and associated fields & refrences. Moved kmalloc/memset-zero to kzalloc.

Signed-off-by: Or Gerlitz <ogerlitz.voltaire.com>


Index: iser_memory.h
===================================================================
--- iser_memory.h	(revision 4956)
+++ iser_memory.h	(revision 4957)
@@ -38,7 +38,7 @@
 #include "iser.h"
 
 /* regd_buf */
-struct iser_regd_buf *iser_regd_buf_alloc(struct iser_adaptor *p_iser_adaptor);
+struct iser_regd_buf *iser_regd_buf_alloc(void);
 
 struct iser_regd_buf *iser_regd_mem_alloc(struct iser_adaptor *p_iser_adaptor,
 					  kmem_cache_t *cache,
@@ -66,11 +66,6 @@ void iser_finalize_rdma_unaligned_sg(str
 unsigned int iser_data_buf_aligned_len(struct iser_data_buf *p_data,
 				      int skip);
 
-
-void iser_data_buf_memcpy(unsigned char *p_dst_buf,
-			  struct iser_data_buf *p_src_data,
-			  unsigned long *p_total_copied_sz);
-
 void iser_data_buf_dump(struct iser_data_buf *p_data);
 
 /* iser_page_vec */
Index: iscsi_iser.h
===================================================================
--- iscsi_iser.h	(revision 4956)
+++ iscsi_iser.h	(revision 4957)
@@ -141,7 +141,6 @@ struct iser_dto {
 
 enum iser_op_param_default {
 	defaultInitiatorRecvDataSegmentLength = 128,
-	defaultTargetRecvDataSegmentLength = 8 * 1024
 };
 
 struct iser_conn
@@ -177,10 +176,6 @@ struct iscsi_iser_conn
 	unsigned int postrecv_bsize;
 	char         postrecv_cn[32];
 
-	kmem_cache_t *send_cache;
-	unsigned int send_bsize;
-	char         send_cn[32];
-
 	atomic_t     post_recv_buf_count;
 	atomic_t     post_send_buf_count;
 
Index: iser_verbs.c
===================================================================
--- iser_verbs.c	(revision 4956)
+++ iser_verbs.c	(revision 4957)
@@ -246,10 +246,9 @@ struct iser_adaptor *iser_adaptor_find_b
 	}
 
 	if (p_adaptor == NULL) {
-		p_adaptor = kmalloc(sizeof *p_adaptor, GFP_ATOMIC);
+		p_adaptor = kzalloc(sizeof *p_adaptor, GFP_ATOMIC);
 		if (p_adaptor == NULL)
 			goto end;
-		memset(p_adaptor, 0, sizeof *p_adaptor);
 		ig.num_adaptors++;
 		/* assign this device to the adaptor */
 		p_adaptor->device = cma_id->device;
Index: iser_dto.c
===================================================================
--- iser_dto.c	(revision 4956)
+++ iser_dto.c	(revision 4957)
@@ -212,31 +212,3 @@ struct iser_dto *iser_dto_send_create(st
 	return p_send_dto;
 }
 
-/**
- * iser_dto_copy_send_data - Allocates a send-data buffer and copies
- *	there a PDU's data segment
- */
-int iser_dto_copy_send_data(struct iser_dto *p_send_dto,
-			    struct iser_data_buf *p_data)
-{
-	struct iscsi_iser_conn *p_iser_conn = p_send_dto->p_conn;
-	struct iser_regd_buf *p_regd_buf;
-	unsigned long total_data_sz;
-
-	p_regd_buf = iser_regd_mem_alloc(p_iser_conn->ib_conn->p_adaptor,
-					 p_iser_conn->send_cache,
-					 p_iser_conn->send_bsize);
-	if (p_regd_buf == NULL) {
-		iser_err("Failed to alloc send buffer\n");
-		return -ENOMEM;
-	}
-	iser_data_buf_memcpy(p_regd_buf->virt_addr, p_data, &total_data_sz);
-
-	/* DMA_MAP: safe to dma_map now - map and flush the cache */
-	iser_reg_single(p_iser_conn->ib_conn->p_adaptor,p_regd_buf, DMA_TO_DEVICE);
-
-	iser_dto_add_regd_buff(p_send_dto, p_regd_buf,
-			       USE_NO_OFFSET,
-			       USE_SIZE(total_data_sz));
-	return 0;
-}
Index: iser_dto.h
===================================================================
--- iser_dto.h	(revision 4956)
+++ iser_dto.h	(revision 4957)
@@ -61,7 +61,4 @@ struct iser_dto *iser_dto_send_create(st
 				      struct iscsi_hdr *p_hdr,
 				      unsigned char **p_header);
 
-int iser_dto_copy_send_data(struct iser_dto *p_send_dto,
-			    struct iser_data_buf *p_data);
-
 #endif				/* __ISER_DTO_H__ */
Index: iser_conn.c
===================================================================
--- iser_conn.c	(revision 4956)
+++ iser_conn.c	(revision 4957)
@@ -196,11 +196,9 @@ int iser_conn_bind(struct iscsi_iser_con
 	iscsi_conn->ib_conn       = p_iser_conn;
 
 	/* MERGE_ADDED_CHANGE moved here from ic_establish, before LOGIN sent */
-	iser_dbg("postrecv_cache = send_cache = ig.login_cache\n");
+	iser_dbg("postrecv_cache =  ig.login_cache\n");
 	iscsi_conn->postrecv_cache = ig.login_cache;
 	iscsi_conn->postrecv_bsize = ISER_LOGIN_PHASE_PDU_DATA_LEN;
-	iscsi_conn->send_cache	   = ig.login_cache;
-	iscsi_conn->send_bsize	   = ISER_LOGIN_PHASE_PDU_DATA_LEN;
 	sprintf(iscsi_conn->name,"%d.%d.%d.%d",
 		NIPQUAD(iscsi_conn->ib_conn->dst_addr));
 
@@ -220,17 +218,13 @@ int iser_conn_set_full_featured_mode(str
 	int initial_post_recv_bufs_num = ISER_INITIAL_POST_RECV + 2;
 
 	p_iser_conn->postrecv_cache = NULL;
-	p_iser_conn->send_cache = NULL;
 
 	iser_dbg("Initially post: %d\n", initial_post_recv_bufs_num);
 
 	sprintf(p_iser_conn->postrecv_cn,"prcv_%d.%d.%d.%d:%d",
 		NIPQUAD(p_iser_conn->ib_conn->dst_addr),p_iser_conn->ib_conn->dst_port);
 
-	sprintf(p_iser_conn->send_cn,"snd_%d.%d.%d.%d:%d",
-		NIPQUAD(p_iser_conn->ib_conn->dst_addr),p_iser_conn->ib_conn->dst_port);
-
-	/* Allocate recv & send-data buffers for the full-featured phase */
+	/* Allocate recv buffers for the full-featured phase */
 
 	/* FIXME should be a param eg p_iser_conn->initiator_max_recv_dsl; */
 	p_iser_conn->postrecv_bsize = defaultInitiatorRecvDataSegmentLength;
@@ -245,17 +239,7 @@ int iser_conn_set_full_featured_mode(str
 		goto ffeatured_mode_failure;
 	}
 
-	/* FIXME should be a param eg p_iser_conn->target_max_recv_dsl; */
-	p_iser_conn->send_bsize = (unsigned int)defaultTargetRecvDataSegmentLength;
-	p_iser_conn->send_cache =
-		kmem_cache_create(p_iser_conn->send_cn,
-				  p_iser_conn->send_bsize,
-				  0,SLAB_HWCACHE_ALIGN, NULL, NULL);
-	if (p_iser_conn->send_cache == NULL) {
-		iser_err("Failed to allocate send cache\n");
-		err =  -ENOMEM;
-		goto ffeatured_mode_failure;
-	}
+
 	/* Check that there is no posted recv or send buffers left - */
 	/* they must be consumed during the login phase */
 	if (atomic_read(&p_iser_conn->post_recv_buf_count) != 0)
@@ -278,10 +262,6 @@ int iser_conn_set_full_featured_mode(str
 	return 0;
 
 ffeatured_mode_failure:
-	if(p_iser_conn->send_cache) {
-		kmem_cache_destroy(p_iser_conn->send_cache);
-		p_iser_conn->send_cache = NULL;
-	}
 	if(p_iser_conn->postrecv_cache) {
 		kmem_cache_destroy(p_iser_conn->postrecv_cache);
 		p_iser_conn->postrecv_cache = NULL;
@@ -398,9 +378,6 @@ void iser_conn_release(struct iser_conn 
 
 		p_iscsi_conn = p_iser_conn->p_iscsi_conn;
 		if(p_iscsi_conn != NULL && p_iscsi_conn->ff_mode_enabled) {
-			if(kmem_cache_destroy(p_iscsi_conn->send_cache) != 0)
-				iser_err("send cache %s not empty, leak!\n",
-					 p_iscsi_conn->send_cn);
 			if(kmem_cache_destroy(p_iscsi_conn->postrecv_cache) != 0)
 				iser_err("postrecv cache %s not empty, leak!\n",
 					 p_iscsi_conn->postrecv_cn);
Index: iser_initiator.c
===================================================================
--- iser_initiator.c	(revision 4956)
+++ iser_initiator.c	(revision 4957)
@@ -72,7 +72,7 @@ static int iser_reg_rdma_mem(struct iscs
 		priv_flags |= IB_ACCESS_REMOTE_READ;
 
 	p_iser_task->rdma_regd[cmd_dir] = NULL;
-	p_regd_buf = iser_regd_buf_alloc(p_iser_adaptor);
+	p_regd_buf = iser_regd_buf_alloc();
 	if (p_regd_buf == NULL)
 		return -ENOMEM;
 
@@ -459,7 +459,8 @@ int iser_send_control(struct iscsi_iser_
 	unsigned long data_seg_len;
 	int err = 0;
 	unsigned char opcode;
-	struct iser_data_buf data_buf;
+	struct iser_regd_buf *p_regd_buf;
+	struct iser_adaptor *p_iser_adaptor;
 
 	if (atomic_read(&p_iser_conn->ib_conn->state) != ISER_CONN_UP) {
 		iser_err("Failed to send, conn: 0x%p is not up\n", p_iser_conn->ib_conn);
@@ -473,13 +474,16 @@ int iser_send_control(struct iscsi_iser_
 		err = -ENOMEM;
 		goto send_control_error;
 	}
+	p_iser_adaptor = p_iser_conn->ib_conn->p_adaptor;
 
 	/* DMA_MAP: safe to dma_map now - map and flush the cache */
-	iser_reg_single(p_iser_conn->ib_conn->p_adaptor,
-			p_send_dto->regd[0], DMA_TO_DEVICE);
+	iser_reg_single(p_iser_adaptor, p_send_dto->regd[0], DMA_TO_DEVICE);
 
 	itt = ntohl(p_mtask->hdr.itt);
 	opcode = p_mtask->hdr.opcode & ISCSI_OPCODE_MASK;
+
+	/* no need to copy when there's data b/c the mtask is not reallocated *
+	 * till the response related to this ITT is received	              */
 	switch (opcode) {
 
 	case ISCSI_OP_SCSI_TMFUNC:
@@ -490,11 +494,20 @@ int iser_send_control(struct iscsi_iser_
 	case ISCSI_OP_LOGOUT:
 		data_seg_len = ntoh24(p_mtask->hdr.dlength);
 		if (data_seg_len > 0) {
-			data_buf.p_buf = p_mtask->data;
-			data_buf.size  = p_mtask->data_count;
-			data_buf.type  = ISER_BUF_TYPE_SINGLE;
-			/* Allocate data regd buffer and copy the user data */
-			iser_dto_copy_send_data(p_send_dto, &data_buf);
+			p_regd_buf = iser_regd_buf_alloc();
+			if (p_regd_buf == NULL) {
+				iser_err("Failed to alloc regd buffer\n");
+				err = -ENOMEM;
+				goto send_control_error;
+			}
+			p_regd_buf->p_adaptor = p_iser_adaptor;
+			p_regd_buf->virt_addr = p_mtask->data;
+			p_regd_buf->data_size = p_mtask->data_count;
+			iser_reg_single(p_iser_adaptor, p_regd_buf,
+					DMA_TO_DEVICE);
+			iser_dto_add_regd_buff(p_send_dto, p_regd_buf,
+					       USE_NO_OFFSET,
+					       USE_SIZE(data_seg_len));
 		}
 		break;
 
@@ -537,7 +550,7 @@ void iser_rcv_dto_completion(struct iser
 	struct iscsi_iser_cmd_task *p_iser_task = NULL;
 	struct iscsi_hdr *p_hdr;
 	char   *rx_data;
-	int     rx_data_size,rc;
+	int     rc, rx_data_size = 0;
 	unsigned int itt;
 	unsigned char opcode;
 	int no_more_task_sends = 0;
Index: iser_memory.c
===================================================================
--- iser_memory.c	(revision 4956)
+++ iser_memory.c	(revision 4957)
@@ -59,7 +59,7 @@ iser_page_to_virt(struct page *page)
  *
  * returns the registered buffer descriptor
  */
-struct iser_regd_buf *iser_regd_buf_alloc(struct iser_adaptor *p_iser_adaptor)
+struct iser_regd_buf *iser_regd_buf_alloc(void)
 {
 	struct iser_regd_buf *p_regd_buf;
 
@@ -84,7 +84,7 @@ struct iser_regd_buf *iser_regd_mem_allo
 	struct iser_regd_buf *p_regd_buf;
 	void *data;
 
-	p_regd_buf = iser_regd_buf_alloc(p_iser_adaptor);
+	p_regd_buf = iser_regd_buf_alloc();
 	if (p_regd_buf != NULL) {
 		data = (void *) kmem_cache_alloc(cache,
 						 GFP_KERNEL | __GFP_NOFAIL);
@@ -505,44 +505,6 @@ unsigned int iser_data_buf_aligned_len(s
 	return ret_len;
 }
 
-/**
- * iser_data_buf_memcpy - Copies arbitrary data buffer to a
- * contiguous memory region
- */
-void iser_data_buf_memcpy(unsigned char *p_dst_buf,
-			  struct iser_data_buf *p_src_data,
-			  unsigned long *p_total_copied_sz)
-{
-	if (p_src_data->type == ISER_BUF_TYPE_SINGLE) {
-		iser_dbg(
-		       "copy SINGLE virt: 0x%p -> 0x%p, " "sz: %d\n",
-		       p_src_data->p_buf, p_dst_buf, p_src_data->size);
-		memcpy(p_dst_buf, p_src_data->p_buf, p_src_data->size);
-		if (p_total_copied_sz != NULL)
-			*p_total_copied_sz = p_src_data->size;
-	} else {
-		unsigned char *chunk_addr = 0;
-		unsigned int chunk_size = 0;
-		unsigned long total_sz = 0;
-		int i;
-
-		for (i = 0; i < p_src_data->size; i++) {
-			chunk_addr = (unsigned char *)
-			    iser_sg_entry_to_virt(p_src_data->p_buf, i);
-			chunk_size =
-			    iser_sg_entry_len(p_src_data->p_buf, i);
-			iser_dbg(
-			       "copy SG[%d]: 0x%p -> 0x%p, sz: %d\n",
-			       i, chunk_addr, p_dst_buf, chunk_size);
-			memcpy(p_dst_buf, chunk_addr, chunk_size);
-			p_dst_buf += chunk_size;
-			total_sz += chunk_size;
-		}
-		if (p_total_copied_sz != NULL)
-			*p_total_copied_sz = total_sz;
-	}
-}
-
 void iser_data_buf_dump(struct iser_data_buf *p_data)
 {
 	if (p_data->type == ISER_BUF_TYPE_SINGLE)
Index: iscsi_iser.c
===================================================================
--- iscsi_iser.c	(revision 4956)
+++ iscsi_iser.c	(revision 4957)
@@ -1101,11 +1101,10 @@ static iscsi_connh_t iscsi_iser_conn_cre
 	struct iscsi_iser_session *session = iscsi_ptr(sessionh);
 	struct iscsi_iser_conn *conn = NULL;
 
-	conn = kmalloc(sizeof *conn, GFP_KERNEL);
+	conn = kzalloc(sizeof *conn, GFP_KERNEL);
 	if (conn == NULL) {
 		goto conn_alloc_fail;
 	}
-	memset(conn, 0, sizeof(struct iscsi_iser_conn));
 
 	/* Init the connection */
 	conn->c_stage = ISCSI_CONN_INITIAL_STAGE;




More information about the general mailing list