public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Christoph Hellwig <hch@lst.de>, linux-scsi@vger.kernel.org
Cc: Douglas Gilbert <dgilbert@interlog.com>, Robert Elliott <Elliott@hp.com>
Subject: Re: [PATCH 1/6] scsi: refactor scsi_reset_provider handling
Date: Tue, 28 Oct 2014 09:51:12 +0100	[thread overview]
Message-ID: <544F5900.6080406@acm.org> (raw)
In-Reply-To: <1414432746-12888-2-git-send-email-hch@lst.de>

On 10/27/14 18:59, Christoph Hellwig wrote:
> -/*
> - * Function:	scsi_reset_provider
> - *
> - * Purpose:	Send requested reset to a bus or device at any phase.
> - *
> - * Arguments:	device	- device to send reset to
> - *		flag - reset type (see scsi.h)
> - *
> - * Returns:	SUCCESS/FAILURE.
> - *
> - * Notes:	This is used by the SCSI Generic driver to provide
> - *		Bus/Device reset capability.
> +/**
> + * scsi_ioctl_reset: explicitly reset a host/bus/target/device
> + * @dev:	scsi_device to operate on
> + * @val:	reset type (see sg.h)
>    */
>   int
> -scsi_reset_provider(struct scsi_device *dev, int flag)
> +scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
>   {
>   	struct scsi_cmnd *scmd;
>   	struct Scsi_Host *shost = dev->host;
>   	struct request req;
>   	unsigned long flags;
> -	int rtn;
> +	int error = 0, rtn, val;
> +
> +	if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
> +		return -EACCES;
> +
> +	error = get_user(val, arg);
> +	if (error)
> +		return error;
>
>   	if (scsi_autopm_get_host(shost) < 0)
> -		return FAILED;
> +		return -EIO;
>
> -	if (!get_device(&dev->sdev_gendev)) {
> -		rtn = FAILED;
> +	error = -EIO;
> +	if (!get_device(&dev->sdev_gendev))
>   		goto out_put_autopm_host;
> -	}
>
>   	scmd = scsi_get_command(dev, GFP_KERNEL);
>   	if (!scmd) {
> -		rtn = FAILED;
>   		put_device(&dev->sdev_gendev);
>   		goto out_put_autopm_host;
>   	}
> @@ -2347,37 +2345,33 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
>   	shost->tmf_in_progress = 1;
>   	spin_unlock_irqrestore(shost->host_lock, flags);
>
> -	switch (flag) {
> -	case SCSI_TRY_RESET_DEVICE:
> +	error = 0;
> +	switch (val & ~SG_SCSI_RESET_NO_ESCALATE) {
> +	case SG_SCSI_RESET_NOTHING:
> +		break;
> +	case SG_SCSI_RESET_DEVICE:
>   		rtn = scsi_try_bus_device_reset(scmd);
> -		if (rtn == SUCCESS)
> +		if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
>   			break;
>   		/* FALLTHROUGH */
> -	case SCSI_TRY_RESET_TARGET:
> +	case SG_SCSI_RESET_TARGET:
>   		rtn = scsi_try_target_reset(scmd);
> -		if (rtn == SUCCESS)
> +		if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
>   			break;
>   		/* FALLTHROUGH */
> -	case SCSI_TRY_RESET_BUS:
> +	case SG_SCSI_RESET_BUS:
>   		rtn = scsi_try_bus_reset(scmd);
> -		if (rtn == SUCCESS)
> +		if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
>   			break;
>   		/* FALLTHROUGH */
> -	case SCSI_TRY_RESET_HOST:
> -	case SCSI_TRY_RESET_HOST | SCSI_TRY_RESET_NO_ESCALATE:
> +	case SG_SCSI_RESET_HOST:
>   		rtn = scsi_try_host_reset(scmd);
> -		break;
> -	case SCSI_TRY_RESET_DEVICE | SCSI_TRY_RESET_NO_ESCALATE:
> -		rtn = scsi_try_bus_device_reset(scmd);
> -		break;
> -	case SCSI_TRY_RESET_TARGET | SCSI_TRY_RESET_NO_ESCALATE:
> -		rtn = scsi_try_target_reset(scmd);
> -		break;
> -	case SCSI_TRY_RESET_BUS | SCSI_TRY_RESET_NO_ESCALATE:
> -		rtn = scsi_try_bus_reset(scmd);
> -		break;
> +		if (rtn == SUCCESS)
> +			break;
>   	default:
> -		rtn = FAILED;
> +		/* FALLTHROUGH */
> +		error = -EIO;
> +		break;
>   	}
>
>   	spin_lock_irqsave(shost->host_lock, flags);
> @@ -2399,9 +2393,9 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
>   	scsi_next_command(scmd);
>   out_put_autopm_host:
>   	scsi_autopm_put_host(shost);
> -	return rtn;
> +	return error;
>   }
> -EXPORT_SYMBOL(scsi_reset_provider);
> +EXPORT_SYMBOL(scsi_ioctl_reset);

This function returns 0 even if an action like SG_SCSI_RESET_BUS fails 
(rtn != SUCCESS) with the flag SCSI_TRY_RESET_NO_ESCALATE set. I think 
the current behavior is to return -EIO in that case. If this change was 
intended, please mention it in the patch description.

Bart.

  reply	other threads:[~2014-10-28  8:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-27 17:59 misc scsi ioctl updates Christoph Hellwig
2014-10-27 17:59 ` [PATCH 1/6] scsi: refactor scsi_reset_provider handling Christoph Hellwig
2014-10-28  8:51   ` Bart Van Assche [this message]
2014-10-28 17:36     ` Christoph Hellwig
2014-10-27 17:59 ` [PATCH 2/6] scsi: split scsi_nonblockable_ioctl Christoph Hellwig
2014-10-28  9:05   ` Bart Van Assche
2014-10-28 17:39     ` Christoph Hellwig
2014-10-29 10:55       ` Bart Van Assche
2014-10-29 18:41         ` Christoph Hellwig
2014-10-27 17:59 ` [PATCH 3/6] sd: fix up ->compat_ioctl Christoph Hellwig
2014-10-27 17:59 ` [PATCH 4/6] st: call scsi_set_medium_removal directly Christoph Hellwig
2014-10-27 17:59 ` [PATCH 5/6] osst: " Christoph Hellwig
2014-10-27 17:59 ` [PATCH 6/6] scsi: return EAGAIN when resetting a device under EH Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2014-10-30  9:27 misc scsi ioctl updates V2 Christoph Hellwig
2014-10-30  9:27 ` [PATCH 1/6] scsi: refactor scsi_reset_provider handling Christoph Hellwig
2014-10-30  9:38   ` Hannes Reinecke
2014-11-05 14:11   ` Hannes Reinecke
2014-11-05 14:25   ` Martin K. Petersen
2014-11-06 18:01   ` Elliott, Robert (Server Storage)

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=544F5900.6080406@acm.org \
    --to=bvanassche@acm.org \
    --cc=Elliott@hp.com \
    --cc=dgilbert@interlog.com \
    --cc=hch@lst.de \
    --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