All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: James.Smart@Emulex.Com
Cc: linux-scsi@vger.kernel.org, andmike@us.ibm.com,
	James.Bottomley@SteelEye.com
Subject: Re: [PATCH] updated: suspending I/Os to a device
Date: Wed, 1 Sep 2004 20:44:35 +0100	[thread overview]
Message-ID: <20040901204435.A15362@infradead.org> (raw)
In-Reply-To: <0B1E13B586976742A7599D71A6AC733C02F19C@xbl3.ma.emulex.com>; from James.Smart@Emulex.Com on Wed, Sep 01, 2004 at 03:30:07PM -0400

> +	/* Check to see if the scsi lld put this device into blocked state. */
> +	if (unlikely(cmd->device->sdev_state == SDEV_BLOCK)) {
> +		/* in SDEV_BLOCK, the command is just put back on the device

Style nitpick: In Linux block coments start like this:

/*
 * foo, yodda, ..

 (same issue happens a few times in the patch)

> +		 * queue.  The suspend state has already blocked the queue so
> +		 * future requests should not occur until the device 
> +		 * transitions out of the suspend state.
> +		 */
> +		scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
> +		SCSI_LOG_MLQUEUE(3, printk("queuecommand : request to blocked device requeued\n"));

Please break lines after 80 characters or slightly before.

> +int
> +scsi_internal_device_block(struct scsi_device *sdev,
> +			     struct timer_list *timer, int timeout)
> +{
> +	request_queue_t *q = sdev->request_queue;
> +	unsigned long flags;
> +
> +	if (timer) {
> +		if (timeout < 0 || timeout > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
> +			return -EINVAL;
> +	}

...

> +
> +	/* The scsi lld is only allowed to block the device for the specified
> +	 * timeout. */
> +	if (timer) {
> +		init_timer(timer);
> +		timer->data = (unsigned long)sdev;

You should probably split this into two routines.   A core one that doesn't
take a timer as argument at all, and a wrapper that always does.

> +EXPORT_SYMBOL(scsi_internal_device_block);

the internal APIs should probably be exported _GPL to mark them as clearly
internal.

> +int
> +scsi_internal_device_unblock(struct scsi_device *sdev,
> +			     struct timer_list *timer)
> +{
> +	request_queue_t *q = sdev->request_queue; 
> +	int err;
> +	unsigned long flags;
> +	
> +	/* Stop the scsi device timer first. Take no action on the del_timer
> +	 * failure as the state machine state change will validate the
> +	 * transaction. */
> +	if (timer)
> +		del_timer_sync(timer);

Same core + timer wrapper issue I'd say.

In fact there's only a singel caller caring about the timer, it could be
moved to that one.

> +static void fc_timeout_blocked_tgt(unsigned long data)
> +{
> +	struct scsi_device *tgt_sdev = (struct scsi_device *)data;
> +	struct Scsi_Host *shost = tgt_sdev->host;
> +	struct scsi_device *sdev;
> +
> +	dev_printk(KERN_ERR, &tgt_sdev->sdev_gendev, 
> +		"blocked target time out: target resuming\n");
> +
> +	__shost_for_each_device(sdev, shost) {

You're missing some locking here.

> +	__shost_for_each_device(sdev, shost) {

Dito.

> +	if (timeout < 0 || timeout > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
> +			return -EINVAL;

double indentation.

> +	__shost_for_each_device(tmp_sdev, shost) {

missing locking again.

> +		if (tmp_sdev->id == sdev->id) {
> +			err = scsi_internal_device_block(tmp_sdev, NULL, 0);
> +			if (err)
> +				return err;
> +			else
> +				tgt_cnt++;

superflous else as you're returning early

> +int fc_target_unblock(struct scsi_device *sdev, struct timer_list *timer)
> +{
> +	struct Scsi_Host *shost = sdev->host;
> +	struct scsi_device *tmp_sdev;
> +	int err = 0;
> +
> +	/* Stop the target timer first. Take no action on the del_timer
> +	 * failure as the state machine state change will validate the
> +	 * transaction. */
> +	if (!timer)
> +		return -EINVAL;

Not needed.  IF the caller is broken no need to work around.

> +	/* Block each device matching the caller's target id. */
> +	__shost_for_each_device(tmp_sdev, shost) {

missing locking again.

> +int fc_host_block(struct Scsi_Host *shost, struct timer_list *timer)
> +{
> +	struct scsi_device *sdev, *tmp_sdev = NULL;
> +	int err = 0, timeout = -1;
> +
> +	if (!timer)
> +		return -EINVAL;

same API issue as above.  don't work around broken callers.

> +	/* Find the first device and validate the timeout value.  All devices
> +	 * managed by this host are timed using the transport 
> +	 * dev_loss_tmo timeout. */
> +	__shost_for_each_device(sdev, shost) {

missing locking again.

> +		tmp_sdev = sdev;
> +		timeout = fc_dev_loss_tmo(sdev);
> +		if (timeout < 0 || timeout > SCSI_DEVICE_BLOCK_MAX_TIMEOUT) {
> +			return -EINVAL;
> +		} else {
> +			break;
> +		}

superflous else, superflous braces

> +	__shost_for_each_device(sdev, shost) {

missing locking.

> +int fc_host_unblock(struct Scsi_Host *shost, struct timer_list *timer)
> +{
> +	struct scsi_device *sdev;
> +	int err = 0;
> +	
> +	/* Stop the host timer first. Take no action on the del_timer
> +	 * failure as the state machine state change will validate the
> +	 * transaction. */
> +	if (!timer)
> +		return -EINVAL;

broken caller workaround issue again.

> +	__shost_for_each_device(sdev, shost) {

missing locking.


Your probably want to invent some scheme to not duplicate the same
code for host/target/device each time.

  reply	other threads:[~2004-09-01 19:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-01 19:30 [PATCH] updated: suspending I/Os to a device James.Smart
2004-09-01 19:44 ` Christoph Hellwig [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-08-20 13:24 James.Smart
2004-08-19 18:24 James.Smart
2004-08-20  8:55 ` Mike Anderson
2004-08-20 13:48   ` Luben Tuikov
2004-08-19 17:24 James.Smart
2004-08-19 17:42 ` James Bottomley
2004-08-10 21:00 James.Smart
2004-08-11 22:11 ` Christoph Hellwig
2004-08-10 20:35 James.Smart
2004-08-10 20:50 ` Christoph Hellwig
2004-08-17  4:39 ` James Bottomley

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=20040901204435.A15362@infradead.org \
    --to=hch@infradead.org \
    --cc=James.Bottomley@SteelEye.com \
    --cc=James.Smart@Emulex.Com \
    --cc=andmike@us.ibm.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.