Skip to contentSkip to conversation

lio-target: Convert to use libcrypto crc32c

PATCH In review Nicholas A. Bellinger 1 participant 1 message Sep 11, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lio-target: Convert to use libcrypto crc32c

From: Nicholas Bellinger <[email protected]>

This patch converts the LIO-Target fabric module to use the libcrypto API for handling crc32c calculations when HeaderDigest=CRC32C and/or DataDigest=CRC32C are enabled. This includes the removal of the legacy internal slicing by 1x code in iscsi_crc.c, and includes the addition of the following structure members to struct iscsi_conn:

	struct hash_desc	conn_rx_hash;
	struct hash_desc	conn_tx_hash;

These are used in iSCSI RX and TX thread connection context for preforming crypto_hash_*() calls to validate an incoming CRC32C checksum, or attaching an outgoing CRC32C checksum.

On the setup side, this patch updates iscsi_target_login.c:iscsi_login_init_conn() to add the necessary crypto_alloc_hash() calls for conn_rx_hash and conn_tx_hash. On the shutdown side, the necessary crypto_free_hash() calls have been added to the login exception path in iscsi_target_login.c:iscsi_target_login_thread(), and in the normal iSCSI connection shutdown patch in iscsi_target.c:iscsi_close_connection().

This main changes on the I/O side involve the conversion of the legacy do_crc() calls in iscsi_target.c to use crypto_hash_init(), crypto_hash_update() and crypto_hash_final(). On the RX side for struct iscsi_cmd->conn_rx_hash this includes the following:

*) iscsi_handle_data_out() - iSCSI WRITE payload *) iscsi_handle_nop_out() - NopOut payload *) iscsi_handle_text_cmd() - Text payload
*) iscsi_handle_immediate_data() - iSCSI WRITE payload *) iscsi_target_rx_thread() - 48 byte iSCSI PDU

and on the TX side for struct iscsi_cmd->conn_tx_hash:

*) iscsi_send_async_msg() - Async Msg header digest
*) iscsi_send_conn_drop_async_message() - Async Msg header digest *) iscsi_send_data_in() - DataIN header digest and iSCSI READ payload *) iscsi_send_logout_response() - Logout response header digest *) iscsi_send_unsolicited_nopin() - NopIN header digest *) iscsi_send_nopin_response() - NopIN header digest
*) iscsi_send_r2t() - R2T header digest
*) iscsi_send_status() - iSCSI status and SCSI sense payload *) iscsi_send_task_mgt_rsp() - iSCSI TMR header digest
*) iscsi_send_text_rsp() - iSCSI text response and payload *) iscsi_send_reject() - iSCSI reject header digest and payload

So far this has been tested with HeaderDigest=CRC32C and DataDigest=CRC32C on v2.6.36-rc3 in x86 KVM guest running with an Open-iSCSI initiator.

---
 drivers/target/lio-target/Kbuild               |    1 -
 drivers/target/lio-target/iscsi_crc.c          |  171 -------------
 drivers/target/lio-target/iscsi_crc.h          |    9 -
 drivers/target/lio-target/iscsi_target.c       |  302 ++++++++++++++++++------
 drivers/target/lio-target/iscsi_target_core.h  |    3 +
 drivers/target/lio-target/iscsi_target_erl1.c  |    1 -
 drivers/target/lio-target/iscsi_target_erl2.c  |    1 -
 drivers/target/lio-target/iscsi_target_login.c |   35 +++-
 drivers/target/lio-target/iscsi_target_nego.c  |    1 -
 drivers/target/lio-target/iscsi_target_tmr.c   |    1 -
 10 files changed, 268 insertions(+), 257 deletions(-)
 delete mode 100644 drivers/target/lio-target/iscsi_crc.c
 delete mode 100644 drivers/target/lio-target/iscsi_crc.h
drivers/target/lio-target/Kbuild +0 -1
index 04c9290..0e9cdd9 100644
@@ -3,7 +3,6 @@ EXTRA_CFLAGS += -I$(srctree)/drivers/target/ -I$(srctree)/include/scsi/ -I$(srct
 EXTRA_CFLAGS+=-D_TARGET -DPYX_ISCSI_VENDOR='"Linux-iSCSI.org"'
 
 iscsi_target_mod-objs		:=	iscsi_auth_chap.o \
-				   	iscsi_crc.o \
 					iscsi_debug_opcodes.o \
 					iscsi_parameters.o \
 					iscsi_seq_and_pdu_list.o \
drivers/target/lio-target/iscsi_crc.c deleted +0 -171

171 lines not on this page · raw message

drivers/target/lio-target/iscsi_crc.h deleted +0 -9
deleted file mode 100644
index f97570b..0000000
@@ -1,9 +0,0 @@
-#ifndef _ISCSI_CRC_H_
-#define _ISCSI_CRC_H_
-
-/*	calculate a 32-bit crc	*/
-/*	if restart has 0x01 set, initialize the accumulator */
-/*	if restart has 0x02 set, save result in network byte order */
-extern void do_crc(__u8 *data, __u32 len, int restart, __u32 *result);
-
-#endif /*** _ISCSI_CRC_H_ ***/
drivers/target/lio-target/iscsi_target.c +232 -70

592 lines not on this page · raw message

drivers/target/lio-target/iscsi_target_core.h +3 -0
index 7fa24b1..586e14e 100644
@@ -583,6 +583,9 @@ struct iscsi_conn {
 	spinlock_t		nopin_timer_lock;
 	spinlock_t		response_queue_lock;
 	spinlock_t		state_lock;
+	/* libcrypto RX and TX contexts for crc32c */
+	struct hash_desc	conn_rx_hash;
+	struct hash_desc	conn_tx_hash;
 	/* list_head of struct iscsi_cmd for this connection */
 	struct list_head	conn_cmd_list;
 	struct list_head	immed_queue_list;
drivers/target/lio-target/iscsi_target_erl1.c +0 -1
index 6de09e1..1c3b8b9 100644
@@ -38,7 +38,6 @@
 
 #include <iscsi_protocol.h>
 #include <iscsi_debug_opcodes.h>
-#include <iscsi_crc.h>
 #include <iscsi_debug.h>
 
 #include <target/target_core_base.h>
drivers/target/lio-target/iscsi_target_erl2.c +0 -1
index 86200be..0cebd4d 100644
@@ -38,7 +38,6 @@
 
 #include <iscsi_protocol.h>
 #include <iscsi_debug_opcodes.h>
-#include <iscsi_crc.h>
 #include <iscsi_debug.h>
 #include <iscsi_target_core.h>
 #include <target/target_core_base.h>
drivers/target/lio-target/iscsi_target_login.c +33 -2
index 25b9345..a51296d 100644
@@ -33,6 +33,7 @@
 #include <linux/smp_lock.h>
 #include <linux/in.h>
 #include <linux/inet.h>
+#include <linux/crypto.h>
 #include <net/sock.h>
 #include <net/tcp.h>
 #include <net/ipv6.h>
@@ -57,7 +58,7 @@
  *
  *
  */
-static void iscsi_login_init_conn(struct iscsi_conn *conn)
+static int iscsi_login_init_conn(struct iscsi_conn *conn)
 {
 	INIT_LIST_HEAD(&conn->conn_list);
 	INIT_LIST_HEAD(&conn->conn_cmd_list);
@@ -78,6 +79,27 @@ static void iscsi_login_init_conn(struct iscsi_conn *conn)
 	spin_lock_init(&conn->nopin_timer_lock);
 	spin_lock_init(&conn->response_queue_lock);
 	spin_lock_init(&conn->state_lock);
+	/*
+	 * Setup the RX and TX libcrypto contexts
+	 */
+	conn->conn_rx_hash.flags = 0;
+	conn->conn_rx_hash.tfm = crypto_alloc_hash("crc32c", 0,
+						CRYPTO_ALG_ASYNC);
+	if (IS_ERR(conn->conn_rx_hash.tfm)) {
+		printk(KERN_ERR "crypto_alloc_hash() failed for conn_rx_tfm\n");
+		return -ENOMEM;
+	}
+
+	conn->conn_tx_hash.flags = 0;
+	conn->conn_tx_hash.tfm = crypto_alloc_hash("crc32c", 0,
+						CRYPTO_ALG_ASYNC);
+	if (IS_ERR(conn->conn_tx_hash.tfm)) {	
+		printk(KERN_ERR "crypto_alloc_hash() failed for conn_tx_tfm\n");
+		crypto_free_hash(conn->conn_rx_hash.tfm);
+		return -ENOMEM;
+	}
+
+	return 0;
 }
 
 /*	iscsi_login_check_initiator_version():
@@ -1062,7 +1084,11 @@ get_new_sock:
 			" struct iscsi_conn_ops.\n");
 		goto new_sess_out;
 	}
-	iscsi_login_init_conn(conn);
+	/*
+	 * Perform the remaining iSCSI connection initialization items..
+	 */
+	if (iscsi_login_init_conn(conn) < 0)
+		goto new_sess_out;
 
 	memset(buffer, 0, ISCSI_HDR_LEN);
 	memset(&iov, 0, sizeof(struct iovec));
@@ -1282,6 +1308,11 @@ old_sess_out:
 		iscsi_dec_session_usage_count(SESS(conn));
 	}
 
+	if (conn->conn_rx_hash.tfm)
+		crypto_free_hash(conn->conn_rx_hash.tfm);
+	if (conn->conn_tx_hash.tfm)
+		crypto_free_hash(conn->conn_tx_hash.tfm);
+
 	kfree(conn->conn_ops);
 
 	if (conn->param_list) {
drivers/target/lio-target/iscsi_target_nego.c +0 -1
index c963ea9..8f28993 100644
@@ -49,7 +49,6 @@
 #include <iscsi_target.h>
 #include <iscsi_auth_kernel.h>
 #include <iscsi_parameters.h>
-#include <iscsi_crc.h>
 
 #define MAX_LOGIN_PDUS	7
 
drivers/target/lio-target/iscsi_target_tmr.c +0 -1
index 8a62939..4ab46bb 100644
@@ -34,7 +34,6 @@
 #include <iscsi_debug.h>
 #include <iscsi_protocol.h>
 #include <iscsi_debug_opcodes.h>
-#include <iscsi_crc.h>
 #include <iscsi_debug.h>
 #include <iscsi_target_core.h>
 #include <target/target_core_base.h>
Signature · 1 line
1.5.6.5