diff mbox

[3/3] tcmu: remove cmd timeout code

Message ID 58BD9F70.1060409@redhat.com (mailing list archive)
State Superseded
Headers show

Commit Message

Mike Christie March 6, 2017, 5:42 p.m. UTC
On 03/01/2017 11:14 PM, Mike Christie wrote:
> This patch removes the tcmu the cmd timeout code. Like with the core
> target_core_tmr.c code, the kernel does not know the state of the command
> or implemenation details of the device, so it might not be safe to just
> return the command to the initiator for a possible retry.
> 
> Signed-off-by: Mike Christie <mchristi@redhat.com>
> ---
>  drivers/target/target_core_user.c | 83 +--------------------------------------
>  1 file changed, 1 insertion(+), 82 deletions(-)
> 
> diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
> index 266dc82..c621f1a 100644
> --- a/drivers/target/target_core_user.c
> +++ b/drivers/target/target_core_user.c
> @@ -129,11 +129,6 @@ struct tcmu_cmd {
>  	/* Can't use se_cmd when cleaning up expired cmds, because if
>  	   cmd has been completed then accessing se_cmd is off limits */
>  	DECLARE_BITMAP(data_bitmap, DATA_BLOCK_BITS);
> -
> -	unsigned long deadline;
> -

Hey Nick,

I missed deleting the timer_list struct which is now not used. The
attached version 2 of the patch fixes that.

Comments

Nicholas A. Bellinger March 8, 2017, 9:40 a.m. UTC | #1
On Mon, 2017-03-06 at 11:42 -0600, Mike Christie wrote:
> On 03/01/2017 11:14 PM, Mike Christie wrote:
> > This patch removes the tcmu the cmd timeout code. Like with the core
> > target_core_tmr.c code, the kernel does not know the state of the command
> > or implemenation details of the device, so it might not be safe to just
> > return the command to the initiator for a possible retry.
> > 
> > Signed-off-by: Mike Christie <mchristi@redhat.com>
> > ---
> >  drivers/target/target_core_user.c | 83 +--------------------------------------
> >  1 file changed, 1 insertion(+), 82 deletions(-)
> > 
> > diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
> > index 266dc82..c621f1a 100644
> > --- a/drivers/target/target_core_user.c
> > +++ b/drivers/target/target_core_user.c
> > @@ -129,11 +129,6 @@ struct tcmu_cmd {
> >  	/* Can't use se_cmd when cleaning up expired cmds, because if
> >  	   cmd has been completed then accessing se_cmd is off limits */
> >  	DECLARE_BITMAP(data_bitmap, DATA_BLOCK_BITS);
> > -
> > -	unsigned long deadline;
> > -
> 
> Hey Nick,
> 
> I missed deleting the timer_list struct which is now not used. The
> attached version 2 of the patch fixes that.

Updated version -v2 applied to target-pending/master.

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

From f2f61eef85cc45f01ea216807a28a3d04556e124 Mon Sep 17 00:00:00 2001
From: Mike Christie <mchristi@redhat.com>
Date: Mon, 6 Mar 2017 11:38:52 -0600
Subject: [PATCH] tcmu: remove cmd timeout code v2

This patch removes the tcmu the cmd timeout code. Like with the core
target_core_tmr.c code, the kernel does not know the state of the
command or implemenation details of the device, so it might not be safe to just
return the command to the initiator for a possible retry.

v2:
Remove unused timeout timer_list.

Signed-off-by: Mike Christie <mchristi@redhat.com>
---
 drivers/target/target_core_user.c | 85 +--------------------------------------
 1 file changed, 1 insertion(+), 84 deletions(-)

diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 266dc82..2b4e7e4 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -111,8 +111,6 @@  struct tcmu_dev {
 	struct idr commands;
 	spinlock_t commands_lock;
 
-	struct timer_list timeout;
-
 	char dev_config[TCMU_CONFIG_LEN];
 };
 
@@ -129,11 +127,6 @@  struct tcmu_cmd {
 	/* Can't use se_cmd when cleaning up expired cmds, because if
 	   cmd has been completed then accessing se_cmd is off limits */
 	DECLARE_BITMAP(data_bitmap, DATA_BLOCK_BITS);
-
-	unsigned long deadline;
-
-#define TCMU_CMD_BIT_EXPIRED 0
-	unsigned long flags;
 };
 
 static struct kmem_cache *tcmu_cmd_cache;
@@ -172,7 +165,6 @@  static struct tcmu_cmd *tcmu_alloc_cmd(struct se_cmd *se_cmd)
 
 	tcmu_cmd->se_cmd = se_cmd;
 	tcmu_cmd->tcmu_dev = udev;
-	tcmu_cmd->deadline = jiffies + msecs_to_jiffies(TCMU_TIME_OUT);
 
 	idr_preload(GFP_KERNEL);
 	spin_lock_irq(&udev->commands_lock);
@@ -526,9 +518,6 @@  tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
 	/* TODO: only if FLUSH and FUA? */
 	uio_event_notify(&udev->uio_info);
 
-	mod_timer(&udev->timeout,
-		round_jiffies_up(jiffies + msecs_to_jiffies(TCMU_TIME_OUT)));
-
 	return TCM_NO_SENSE;
 }
 
@@ -562,17 +551,6 @@  static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry *
 	struct se_cmd *se_cmd = cmd->se_cmd;
 	struct tcmu_dev *udev = cmd->tcmu_dev;
 
-	if (test_bit(TCMU_CMD_BIT_EXPIRED, &cmd->flags)) {
-		/*
-		 * cmd has been completed already from timeout, just reclaim
-		 * data area space and free cmd
-		 */
-		free_data_area(udev, cmd);
-
-		kmem_cache_free(tcmu_cmd_cache, cmd);
-		return;
-	}
-
 	if (entry->hdr.uflags & TCMU_UFLAG_UNKNOWN_OP) {
 		free_data_area(udev, cmd);
 		pr_warn("TCMU: Userspace set UNKNOWN_OP flag on se_cmd %p\n",
@@ -662,9 +640,6 @@  static unsigned int tcmu_handle_completions(struct tcmu_dev *udev)
 		handled++;
 	}
 
-	if (mb->cmd_tail == mb->cmd_head)
-		del_timer(&udev->timeout); /* no more pending cmds */
-
 	spin_unlock_irqrestore(&udev->cmdr_lock, flags);
 
 	wake_up(&udev->wait_cmdr);
@@ -672,43 +647,6 @@  static unsigned int tcmu_handle_completions(struct tcmu_dev *udev)
 	return handled;
 }
 
-static int tcmu_check_expired_cmd(int id, void *p, void *data)
-{
-	struct tcmu_cmd *cmd = p;
-
-	if (test_bit(TCMU_CMD_BIT_EXPIRED, &cmd->flags))
-		return 0;
-
-	if (!time_after(jiffies, cmd->deadline))
-		return 0;
-
-	set_bit(TCMU_CMD_BIT_EXPIRED, &cmd->flags);
-	target_complete_cmd(cmd->se_cmd, SAM_STAT_CHECK_CONDITION);
-	cmd->se_cmd = NULL;
-
-	return 0;
-}
-
-static void tcmu_device_timedout(unsigned long data)
-{
-	struct tcmu_dev *udev = (struct tcmu_dev *)data;
-	unsigned long flags;
-	int handled;
-
-	handled = tcmu_handle_completions(udev);
-
-	pr_warn("%d completions handled from timeout\n", handled);
-
-	spin_lock_irqsave(&udev->commands_lock, flags);
-	idr_for_each(&udev->commands, tcmu_check_expired_cmd, NULL);
-	spin_unlock_irqrestore(&udev->commands_lock, flags);
-
-	/*
-	 * We don't need to wakeup threads on wait_cmdr since they have their
-	 * own timeout.
-	 */
-}
-
 static int tcmu_attach_hba(struct se_hba *hba, u32 host_id)
 {
 	struct tcmu_hba *tcmu_hba;
@@ -751,9 +689,6 @@  static struct se_device *tcmu_alloc_device(struct se_hba *hba, const char *name)
 	idr_init(&udev->commands);
 	spin_lock_init(&udev->commands_lock);
 
-	setup_timer(&udev->timeout, tcmu_device_timedout,
-		(unsigned long)udev);
-
 	return &udev->se_dev;
 }
 
@@ -983,15 +918,6 @@  static int tcmu_configure_device(struct se_device *dev)
 	return ret;
 }
 
-static int tcmu_check_and_free_pending_cmd(struct tcmu_cmd *cmd)
-{
-	if (test_bit(TCMU_CMD_BIT_EXPIRED, &cmd->flags)) {
-		kmem_cache_free(tcmu_cmd_cache, cmd);
-		return 0;
-	}
-	return -EINVAL;
-}
-
 static void tcmu_dev_call_rcu(struct rcu_head *p)
 {
 	struct se_device *dev = container_of(p, struct se_device, rcu_head);
@@ -1003,23 +929,14 @@  static void tcmu_dev_call_rcu(struct rcu_head *p)
 static void tcmu_free_device(struct se_device *dev)
 {
 	struct tcmu_dev *udev = TCMU_DEV(dev);
-	struct tcmu_cmd *cmd;
-	bool all_expired = true;
-	int i;
-
-	del_timer_sync(&udev->timeout);
 
 	vfree(udev->mb_addr);
 
 	/* Upper layer should drain all requests before calling this */
 	spin_lock_irq(&udev->commands_lock);
-	idr_for_each_entry(&udev->commands, cmd, i) {
-		if (tcmu_check_and_free_pending_cmd(cmd) != 0)
-			all_expired = false;
-	}
+	WARN_ON(!idr_is_empty(&udev->commands));
 	idr_destroy(&udev->commands);
 	spin_unlock_irq(&udev->commands_lock);
-	WARN_ON(!all_expired);
 
 	/* Device was configured */
 	if (udev->uio_info.uio_dev) {
-- 
2.7.2