public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Tejun Heo <htejun@gmail.com>
Cc: James.Bottomley@steeleye.com, axboe@suse.de,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH scsi-misc-2.6 10/13] scsi: rewrite scsi_request_fn()
Date: Thu, 31 Mar 2005 12:14:16 +0100	[thread overview]
Message-ID: <20050331111416.GA14857@infradead.org> (raw)
In-Reply-To: <20050331090647.ED6FDDE0@htj.dyndns.org>


the changes look good to me (although I haven't tested any of your patches
yet), but the code flow is rather confusing.  What do you think about
the not even compile version of scsi_request_fn() below that should be
functionally identical to yours:


static void scsi_request_fn(struct request_queue *q)
{
	struct scsi_device *sdev = q->queuedata;
	struct Scsi_Host *shost = sdev->host;
	struct scsi_cmnd *cmd;
	struct request *req;
	enum scsi_device_state state;
	int ret = 0;

	/*
	 * FIXME: Once fire & forgetters are fixed, this and the
	 * unlock_irq/put_device/lock_irq dance at the end of this
	 * function can go away.
	 */
	get_device(&sdev->sdev_gendev);

	while ((req = elv_next_request(q))) {
		int is_special = (req->flags & REQ_SPECIAL), kill = 0;

		cmd = req->special;
		state = cmd->device->sdev_state;

		if (state == SDEV_BLOCK ||
		    (state == SDEV_QUIESCE && !is_special))
			goto out;
		else if (state == SDEV_OFFLINE || state == SDEV_DEL ||
			 (state == SDEV_CANCLE && !is_special)) {
			printk(KERN_ERR "scsi%d (%d:%d): "
					"rejecting I/O to %s\n",
					(state == SDEV_OFFLINE) ?
						"offline device" :
					 ((state == SDEV_DEL) ?
					  	"dead device" :
						"device being removed"));
			kill = 1;
		} else if (!scsi_dev_queue_ready(q, sdev))
			goto out;

		/* Start tag / remove from the request queue. */
		if (blk_queue_tagged(q)) {
			if (unlikely(blk_queue_start_tag(q, req)))
				BUG();
			cmd->tag = req->tag;
		} else
			blkdev_dequeue_request(req);

		sdev->device_busy++;

		/* Switch to host_lock. */
		spin_unlock(q->queue_lock);
		scsi_wait_reset(shost);
		spin_lock(shost->host_lock);

		if (kill || test_bit(SHOST_CANCEL, &shost->shost_state)) {
			SCSI_LOG_MLQUEUE(3,
				printk("%s: rejecting request\n", __FUNCTION__));
			shost->host_busy++;
			atomic_inc(&sdev->iorequest_cnt);
			cmd->result = DID_NO_CONNECT << 16;
			__scsi_done(cmd);
			goto relock;
		}
	
		if (!scsi_host_queue_ready(q, shost, sdev))
			goto requeue_out;

		if (sdev->single_lun) {
			struct scsi_target *target = scsi_target(sdev);
			if (target->starget_sdev_user &&
			    target->starget_sdev_user != sdev)
				goto requeue_out;
			target->starget_sdev_user = sdev;
		}

		shost->host_busy++;

		scsi_log_send(cmd);
		scsi_cmd_get_serial(shost, cmd);
		scsi_add_timer(cmd, cmd->timeout_per_command, scsi_times_out);

		cmd->state = SCSI_STATE_QUEUED;
		cmd->owner = SCSI_OWNER_LOWLEVEL;

		ret = shost->hostt->queuecommand(cmd, scsi_done);
		if (ret) {
			SCSI_LOG_MLQUEUE(3,
			    printk("%s: queuecommand deferred request (%d)\n",
				    __FUNCTION__, ret));

			/*
			 * Timer should be deleted while holding
			 * the host_lock.  Once it gets released, we
			 * don't know if cmd is still there or not.
			 */
			if (scsi_delete_timer(cmd)) {
				shost->host_busy--;
				goto block_requeue_out;
			}

			spin_unlock_irq(shost->host_lock);
			goto out_locked;
		}

		atomic_inc(&sdev->iorequest_cnt);

 relock:
		/* Switch back to queue_lock. */
		spin_unlock(shost->host_lock);
		spin_lock(q->queue_lock);

		/* The queue could have been plugged underneath us. */
		if (blk_queue_plugged(q))
			goto out;
	}

	goto out;

 block_requeue_out:
	if (ret == SCSI_MLQUEUE_DEVICE_BUSY)
		sdev->device_blocked = sdev->max_device_blocked;
	else
		shost->host_blocked = shost->max_host_blocked;
 requeue_out:
	/* Switch back to queue_lock */
	spin_unlock(shost->host_lock);
	spin_lock(q->queue_lock);

	cmd->state = SCSI_STATE_MLQUEUE;
	cmd->owner = SCSI_OWNER_MIDLEVEL;

	SCSI_LOG_MLQUEUE(3,
		printk("%s: requeueing request\n", __FUNCTION__));

	req->flags |= REQ_SOFTBARRIER;  /* Don't pass this request. */
	blk_requeue_request(q, req);
	if (--sdev->device_busy == 0)
		blk_plug_device(q);
 out:
	/*
	 * Must be careful here.  If we trigger the ->remove() function
	 * we cannot be holding the q lock
	 */
	spin_unlock_irq(q->queue_lock);
 out_locked:
	put_device(&sdev->sdev_gendev);
	spin_lock_irq(q->queue_lock);
}

  reply	other threads:[~2005-03-31 11:14 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-31  9:07 [PATCH scsi-misc-2.6 00/13] scsi: scsi_request_fn() rewrite & stuff Tejun Heo
2005-03-31  9:07 ` [PATCH scsi-misc-2.6 01/13] scsi: don't use blk_insert_request() for requeueing Tejun Heo
2005-03-31 10:12   ` Christoph Hellwig
2005-04-01  4:18     ` Tejun Heo
2005-03-31 17:53   ` James Bottomley
2005-04-01  5:01     ` Tejun Heo
2005-04-01 18:09       ` James Bottomley
2005-04-01 22:21         ` Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 02/13] scsi: don't turn on REQ_SPECIAL on sgtable allocation failure Tejun Heo
2005-03-31 17:53   ` James Bottomley
2005-04-01  5:14     ` Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 03/13] scsi: remove unused scsi_cmnd->internal_timeout field Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 04/13] scsi: remove meaningless volatile qualifiers from structure definitions Tejun Heo
2005-03-31 10:11   ` Christoph Hellwig
2005-04-01  5:15     ` Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 05/13] scsi: remove a timer race from scsi_queue_insert() and cleanup timer Tejun Heo
2005-03-31 10:13   ` Christoph Hellwig
2005-04-01  5:15     ` Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 06/13] scsi: remove meaningless scsi_cmnd->serial_number_at_timeout field Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 07/13] scsi: move error handling out of scsi_init_io() into scsi_prep_fn() Tejun Heo
2005-04-01 18:23   ` James Bottomley
2005-04-01 23:07     ` Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 08/13] scsi: move request preps in other places into prep_fn() Tejun Heo
2005-03-31 10:20   ` Christoph Hellwig
2005-04-01  5:20     ` Tejun Heo
2005-03-31 18:07   ` James Bottomley
2005-04-01  5:25     ` Tejun Heo
2005-04-04 18:39       ` James Bottomley
2005-04-05  6:19         ` Tejun Heo
2005-04-05 14:20           ` James Bottomley
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 09/13] scsi: in scsi_prep_fn(), remove bogus comments & clean up Tejun Heo
2005-03-31 10:22   ` Christoph Hellwig
2005-03-31 18:02   ` James Bottomley
2005-04-01  5:29     ` Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 10/13] scsi: rewrite scsi_request_fn() Tejun Heo
2005-03-31 11:14   ` Christoph Hellwig [this message]
2005-04-01  5:44     ` Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 11/13] scsi: add reprep arg to scsi_requeue_command() and make it public Tejun Heo
2005-03-31 10:32   ` Christoph Hellwig
2005-04-01  5:35     ` Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 12/13] scsi: replace scsi_queue_insert() with scsi_requeue_command() Tejun Heo
2005-03-31  9:08 ` [PATCH scsi-misc-2.6 13/13] scsi: consolidate scsi_cmd_retry() calls in scsi_error.c Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050331111416.GA14857@infradead.org \
    --to=hch@infradead.org \
    --cc=James.Bottomley@steeleye.com \
    --cc=axboe@suse.de \
    --cc=htejun@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox