From: Christoph Hellwig <hch@lst.de>
To: Hannes Reinecke <hare@suse.de>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
Christoph Hellwig <hch@lst.de>,
James Bottomley <james.bottomley@hansenpartnership.com>,
linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.com>
Subject: Re: [PATCH] scsi: make 'state' device attribute pollable
Date: Wed, 9 Aug 2017 17:59:15 +0200 [thread overview]
Message-ID: <20170809155915.GA3141@lst.de> (raw)
In-Reply-To: <1502284158-50201-1-git-send-email-hare@suse.de>
On Wed, Aug 09, 2017 at 03:09:18PM +0200, Hannes Reinecke wrote:
> While the 'state' attribute can (and will) change occasionally,
> calling 'poll()' or 'select()' on it fails as sysfs is never
> notified that the state has changed.
> With this patch calling 'poll()' or 'select()' will work
> properly.
>
> Signed-off-by: Hannes Reinecke <hare@suse.com>
> ---
> drivers/scsi/scsi_lib.c | 7 +++++--
> drivers/scsi/scsi_transport_srp.c | 5 ++++-
> 2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 41c19c7..2101cfd 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -2654,6 +2654,7 @@ void scsi_exit_queue(void)
>
> }
> sdev->sdev_state = state;
> + sysfs_notify(&sdev->sdev_gendev.kobj, NULL, "state");
> return 0;
>
> illegal:
> @@ -3074,14 +3075,16 @@ int scsi_internal_device_unblock_nowait(struct scsi_device *sdev,
> * offlined states and goose the device queue if successful.
> */
> if ((sdev->sdev_state == SDEV_BLOCK) ||
> - (sdev->sdev_state == SDEV_TRANSPORT_OFFLINE))
> + (sdev->sdev_state == SDEV_TRANSPORT_OFFLINE)) {
> sdev->sdev_state = new_state;
> - else if (sdev->sdev_state == SDEV_CREATED_BLOCK) {
> + sysfs_notify(&sdev->sdev_gendev.kobj, NULL, "state");
> + } else if (sdev->sdev_state == SDEV_CREATED_BLOCK) {
> if (new_state == SDEV_TRANSPORT_OFFLINE ||
> new_state == SDEV_OFFLINE)
> sdev->sdev_state = new_state;
> else
> sdev->sdev_state = SDEV_CREATED;
> + sysfs_notify(&sdev->sdev_gendev.kobj, NULL, "state");
> } else if (sdev->sdev_state != SDEV_CANCEL &&
> sdev->sdev_state != SDEV_OFFLINE)
> return -EINVAL;
This would be a lot more readable using switch statements:
switch (sdev->sdev_state) {
case SDEV_BLOCK:
case SDEV_TRANSPORT_OFFLINE:
sdev->sdev_state = new_state;
sysfs_notify(&sdev->sdev_gendev.kobj, NULL, "state");
break;
case SDEV_CREATED_BLOCK:
switch (new_state) {
case SDEV_TRANSPORT_OFFLINE:
case SDEV_OFFLINE:
sdev->sdev_state = new_state;
break;
default:
sdev->sdev_state = SDEV_CREATED;
break;
}
sysfs_notify(&sdev->sdev_gendev.kobj, NULL, "state");
break;
case SDEV_CANCEL:
case SDEV_OFFLINE:
break;
default:
return -EINVAL;
}
Otherwise it looks fine to me.
prev parent reply other threads:[~2017-08-09 15:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-09 13:09 [PATCH] scsi: make 'state' device attribute pollable Hannes Reinecke
2017-08-09 15:59 ` Christoph Hellwig [this message]
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=20170809155915.GA3141@lst.de \
--to=hch@lst.de \
--cc=hare@suse.com \
--cc=hare@suse.de \
--cc=james.bottomley@hansenpartnership.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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.