Skip to contentSkip to conversation

tcm_fc: Review cleanups and LUN_RESET bugfix

PATCH In review Nicholas A. Bellinger 1 participant 5 messages May 27, 2011

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

cover tcm_fc: Review cleanups and LUN_RESET bugfix

From: Nicholas Bellinger <[email protected]>

Hi Christoph,

The following is short cleanup series for tcm_fc based upon your feedback this morning, and includes the outstanding LUN_RESET bugfix patch that did not make it in with the initial merge.

Kiran needs to review and test the second patch, but I think the conversion if pretty obvious.

These patches have been pushed in lio-core-2.6.git/master on .40-rc0, and this series applies on top of the latest linux-2.6.git/HEAD.

Thanks,

Nicholas Bellinger (3):
tcm_fc: Makefile cleanups
tcm_fc: Convert to wake_up_process and schedule_timeout_interruptible
tcm_fc: Fix ft_send_tm bug and drop ft_lookup_cmd_lun usage

 drivers/target/tcm_fc/Makefile   |   17 +++----------
 drivers/target/tcm_fc/tcm_fc.h   |    2 +-
 drivers/target/tcm_fc/tfc_cmd.c  |   46 ++++++++++----------------------------
 drivers/target/tcm_fc/tfc_conf.c |    4 +-
 4 files changed, 19 insertions(+), 50 deletions(-)
Signature · 1 line
1.7.5.3
#1 lore raw

PATCH 1/3 tcm_fc: Makefile cleanups

From: Nicholas Bellinger <[email protected]>

This patch removes the unnecessary EXTRA_CFLAGS includes, and drops the unused -DTCM_FC_DEBUG define.

---
 drivers/target/tcm_fc/Makefile |   17 ++++-------------
 1 files changed, 4 insertions(+), 13 deletions(-)
drivers/target/tcm_fc/Makefile +4 -13
index 7a5c2b6..20b14bb 100644
@@ -1,15 +1,6 @@
-EXTRA_CFLAGS += -I$(srctree)/drivers/target/ \
-		-I$(srctree)/drivers/scsi/ \
-		-I$(srctree)/include/scsi/ \
-		-I$(srctree)/drivers/target/tcm_fc/
-
-tcm_fc-y +=	tfc_cmd.o \
-		tfc_conf.o \
-		tfc_io.o \
-		tfc_sess.o
+tcm_fc-y +=		tfc_cmd.o \
+			tfc_conf.o \
+			tfc_io.o \
+			tfc_sess.o
 
 obj-$(CONFIG_TCM_FC)	+= tcm_fc.o
-
-ifdef CONFIGFS_TCM_FC_DEBUG
-EXTRA_CFLAGS	+= -DTCM_FC_DEBUG
-endif
Signature · 1 line
1.7.5.3
#2 lore raw

PATCH 2/3 tcm_fc: Convert to wake_up_process and schedule_timeout_interruptible

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

This patch converts ft_queue_cmd() to use wake_up_process() and ft_thread() to use schedule_timeout_interruptible(MAX_SCHEDULE_TIMEOUT) instead of wait_event_interruptible(). This fixes a potential race with the wait_event_interruptible() conditional with qobj->queue_cnt in ft_thread().

This patch also drops the unnecessary set_user_nice(current, -20) in ft_thread(), and drops extra () around two if (!(acl)) conditionals in tfc_conf.c.

---
 drivers/target/tcm_fc/tfc_cmd.c  |   17 ++++++++---------
 drivers/target/tcm_fc/tfc_conf.c |    4 ++--
 2 files changed, 10 insertions(+), 11 deletions(-)
drivers/target/tcm_fc/tfc_cmd.c +8 -9
index c056a11..b8345cc 100644
@@ -119,15 +119,17 @@ static int ft_get_lun_for_cmd(struct ft_cmd *cmd, u8 *lunp)
 
 static void ft_queue_cmd(struct ft_sess *sess, struct ft_cmd *cmd)
 {
-	struct se_queue_obj *qobj;
+	struct ft_tpg *tpg = sess->tport->tpg;
+	struct se_queue_obj *qobj = &tpg->qobj;
 	unsigned long flags;
 
 	qobj = &sess->tport->tpg->qobj;
 	spin_lock_irqsave(&qobj->cmd_queue_lock, flags);
 	list_add_tail(&cmd->se_req.qr_list, &qobj->qobj_list);
-	spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags);
 	atomic_inc(&qobj->queue_cnt);
-	wake_up_interruptible(&qobj->thread_wq);
+	spin_unlock_irqrestore(&qobj->cmd_queue_lock, flags);
+
+	wake_up_process(tpg->thread);
 }
 
 static struct ft_cmd *ft_dequeue_cmd(struct se_queue_obj *qobj)
@@ -695,15 +697,12 @@ int ft_thread(void *arg)
 	struct ft_tpg *tpg = arg;
 	struct se_queue_obj *qobj = &tpg->qobj;
 	struct ft_cmd *cmd;
-	int ret;
-
-	set_user_nice(current, -20);
 
 	while (!kthread_should_stop()) {
-		ret = wait_event_interruptible(qobj->thread_wq,
-			atomic_read(&qobj->queue_cnt) || kthread_should_stop());
-		if (ret < 0 || kthread_should_stop())
+		schedule_timeout_interruptible(MAX_SCHEDULE_TIMEOUT);
+		if (kthread_should_stop())
 			goto out;
+
 		cmd = ft_dequeue_cmd(qobj);
 		if (cmd)
 			ft_exec_req(cmd);
drivers/target/tcm_fc/tfc_conf.c +2 -2
index 84e868c..aa2f33f 100644
@@ -223,7 +223,7 @@ static struct se_node_acl *ft_add_acl(
 		return ERR_PTR(-EINVAL);
 
 	acl = kzalloc(sizeof(struct ft_node_acl), GFP_KERNEL);
-	if (!(acl))
+	if (!acl)
 		return ERR_PTR(-ENOMEM);
 	acl->node_auth.port_name = wwpn;
 
@@ -280,7 +280,7 @@ struct se_node_acl *ft_tpg_alloc_fabric_acl(struct se_portal_group *se_tpg)
 	struct ft_node_acl *acl;
 
 	acl = kzalloc(sizeof(*acl), GFP_KERNEL);
-	if (!(acl)) {
+	if (!acl) {
 		printk(KERN_ERR "Unable to allocate struct ft_node_acl\n");
 		return NULL;
 	}
Signature · 1 line
1.7.5.3
#3 lore raw

PATCH 3/3 tcm_fc: Fix ft_send_tm bug and drop ft_lookup_cmd_lun usage

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

This patch fixes a bug in ft_send_tm() that was incorrectly calling ft_lookup_cmd_lun() -> transport_lookup_cmd_lun(), instead of using transport_lookup_tmr_lun() for the proper struct se_lun lookup.

It also drops the now unnecessary ft_lookup_cmd_lun() code, and uses scsilun_to_int() directly ahead of direct transport_lookup_cmd_lun() and transport_lookup_tmr_lun() usage.

---
 drivers/target/tcm_fc/tcm_fc.h  |    2 +-
 drivers/target/tcm_fc/tfc_cmd.c |   29 ++++-------------------------
 2 files changed, 5 insertions(+), 26 deletions(-)
drivers/target/tcm_fc/tcm_fc.h +1 -1
index defff32..a0b4d5c 100644
@@ -144,7 +144,7 @@ enum ft_cmd_state {
  */
 struct ft_cmd {
 	enum ft_cmd_state state;
-	u16 lun;			/* LUN from request */
+	u32 lun;			/* LUN from request */
 	struct ft_sess *sess;		/* session held for cmd */
 	struct fc_seq *seq;		/* sequence in exchange mgr */
 	struct se_cmd se_cmd;		/* Local TCM I/O descriptor */
drivers/target/tcm_fc/tfc_cmd.c +4 -25
index b8345cc..09204f7 100644
@@ -94,29 +94,6 @@ void ft_dump_cmd(struct ft_cmd *cmd, const char *caller)
 		16, 4, cmd->cdb, MAX_COMMAND_SIZE, 0);
 }
 
-/*
- * Get LUN from CDB.
- */
-static int ft_get_lun_for_cmd(struct ft_cmd *cmd, u8 *lunp)
-{
-	u64 lun;
-
-	lun = lunp[1];
-	switch (lunp[0] >> 6) {
-	case 0:
-		break;
-	case 1:
-		lun |= (lunp[0] & 0x3f) << 8;
-		break;
-	default:
-		return -1;
-	}
-	if (lun >= TRANSPORT_MAX_LUNS_PER_TPG)
-		return -1;
-	cmd->lun = lun;
-	return transport_get_lun_for_cmd(&cmd->se_cmd, NULL, lun);
-}
-
 static void ft_queue_cmd(struct ft_sess *sess, struct ft_cmd *cmd)
 {
 	struct ft_tpg *tpg = sess->tport->tpg;
@@ -427,7 +404,8 @@ static void ft_send_tm(struct ft_cmd *cmd)
 	switch (fcp->fc_tm_flags) {
 	case FCP_TMF_LUN_RESET:
 		tm_func = TMR_LUN_RESET;
-		if (ft_get_lun_for_cmd(cmd, fcp->fc_lun) < 0) {
+		cmd->lun = scsilun_to_int((struct scsi_lun *)fcp->fc_lun);
+		if (transport_lookup_tmr_lun(&cmd->se_cmd, cmd->lun) < 0) {
 			ft_dump_cmd(cmd, __func__);
 			transport_send_check_condition_and_sense(&cmd->se_cmd,
 				cmd->se_cmd.scsi_sense_reason, 0);
@@ -637,7 +615,8 @@ static void ft_send_cmd(struct ft_cmd *cmd)
 
 	fc_seq_exch(cmd->seq)->lp->tt.seq_set_resp(cmd->seq, ft_recv_seq, cmd);
 
-	ret = ft_get_lun_for_cmd(cmd, fcp->fc_lun);
+	cmd->lun = scsilun_to_int((struct scsi_lun *)fcp->fc_lun);
+	ret = transport_lookup_cmd_lun(&cmd->se_cmd, cmd->lun);
 	if (ret < 0) {
 		ft_dump_cmd(cmd, __func__);
 		transport_send_check_condition_and_sense(&cmd->se_cmd,
Signature · 1 line
1.7.5.3
#4 lore raw

Re: [PATCH 3/3] tcm_fc: Fix ft_send_tm bug and drop ft_lookup_cmd_lun usage

Please disregard this patch, as it uses LIO v4.1 transport_lookup_*_lun() naming change instead of what's current in mainline..

Quoted 10 lines · Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

This patch fixes a bug in ft_send_tm() that was incorrectly calling ft_lookup_cmd_lun() -> transport_lookup_cmd_lun(), instead of using transport_lookup_tmr_lun() for the proper struct se_lun lookup.

It also drops the now unnecessary ft_lookup_cmd_lun() code, and uses scsilun_to_int() directly ahead of direct transport_lookup_cmd_lun() and transport_lookup_tmr_lun() usage.

Please disregard this patch and use PATCH-v2, as the rev below uses the target core v4.1 transport_lookup_*_lun() naming changes instead of what's currently in mainline target core.

Thanks,

--nab

Quoted 74 lines
---
 drivers/target/tcm_fc/tcm_fc.h  |    2 +-
 drivers/target/tcm_fc/tfc_cmd.c |   29 ++++-------------------------
 2 files changed, 5 insertions(+), 26 deletions(-)
drivers/target/tcm_fc/tcm_fc.h +1 -1
index defff32..a0b4d5c 100644
@@ -144,7 +144,7 @@ enum ft_cmd_state {
  */
 struct ft_cmd {
 	enum ft_cmd_state state;
-	u16 lun;			/* LUN from request */
+	u32 lun;			/* LUN from request */
 	struct ft_sess *sess;		/* session held for cmd */
 	struct fc_seq *seq;		/* sequence in exchange mgr */
 	struct se_cmd se_cmd;		/* Local TCM I/O descriptor */
drivers/target/tcm_fc/tfc_cmd.c +4 -25
index b8345cc..09204f7 100644
@@ -94,29 +94,6 @@ void ft_dump_cmd(struct ft_cmd *cmd, const char *caller)
 		16, 4, cmd->cdb, MAX_COMMAND_SIZE, 0);
 }
 
-/*
- * Get LUN from CDB.
- */
-static int ft_get_lun_for_cmd(struct ft_cmd *cmd, u8 *lunp)
-{
-	u64 lun;
-
-	lun = lunp[1];
-	switch (lunp[0] >> 6) {
-	case 0:
-		break;
-	case 1:
-		lun |= (lunp[0] & 0x3f) << 8;
-		break;
-	default:
-		return -1;
-	}
-	if (lun >= TRANSPORT_MAX_LUNS_PER_TPG)
-		return -1;
-	cmd->lun = lun;
-	return transport_get_lun_for_cmd(&cmd->se_cmd, NULL, lun);
-}
-
 static void ft_queue_cmd(struct ft_sess *sess, struct ft_cmd *cmd)
 {
 	struct ft_tpg *tpg = sess->tport->tpg;
@@ -427,7 +404,8 @@ static void ft_send_tm(struct ft_cmd *cmd)
 	switch (fcp->fc_tm_flags) {
 	case FCP_TMF_LUN_RESET:
 		tm_func = TMR_LUN_RESET;
-		if (ft_get_lun_for_cmd(cmd, fcp->fc_lun) < 0) {
+		cmd->lun = scsilun_to_int((struct scsi_lun *)fcp->fc_lun);
+		if (transport_lookup_tmr_lun(&cmd->se_cmd, cmd->lun) < 0) {
 			ft_dump_cmd(cmd, __func__);
 			transport_send_check_condition_and_sense(&cmd->se_cmd,
 				cmd->se_cmd.scsi_sense_reason, 0);
@@ -637,7 +615,8 @@ static void ft_send_cmd(struct ft_cmd *cmd)
 
 	fc_seq_exch(cmd->seq)->lp->tt.seq_set_resp(cmd->seq, ft_recv_seq, cmd);
 
-	ret = ft_get_lun_for_cmd(cmd, fcp->fc_lun);
+	cmd->lun = scsilun_to_int((struct scsi_lun *)fcp->fc_lun);
+	ret = transport_lookup_cmd_lun(&cmd->se_cmd, cmd->lun);
 	if (ret < 0) {
 		ft_dump_cmd(cmd, __func__);
 		transport_send_check_condition_and_sense(&cmd->se_cmd,