Skip to content

Commit

Permalink
scsi: make 'state' device attribute pollable
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Hannes Reinecke authored and Martin K. Petersen committed Aug 25, 2017
1 parent 8cd1ec7 commit 8a97712
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions drivers/scsi/scsi_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,7 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)

}
sdev->sdev_state = state;
sysfs_notify(&sdev->sdev_gendev.kobj, NULL, "state");
return 0;

illegal:
Expand Down Expand Up @@ -3077,13 +3078,15 @@ int scsi_internal_device_unblock_nowait(struct scsi_device *sdev,
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:
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");
break;
case SDEV_CANCEL:
case SDEV_OFFLINE:
Expand Down
5 changes: 4 additions & 1 deletion drivers/scsi/scsi_transport_srp.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,11 @@ int srp_reconnect_rport(struct srp_rport *rport)
*/
shost_for_each_device(sdev, shost) {
mutex_lock(&sdev->state_mutex);
if (sdev->sdev_state == SDEV_OFFLINE)
if (sdev->sdev_state == SDEV_OFFLINE) {
sdev->sdev_state = SDEV_RUNNING;
sysfs_notify(&sdev->sdev_gendev.kobj,
NULL, "state");
}
mutex_unlock(&sdev->state_mutex);
}
} else if (rport->state == SRP_RPORT_RUNNING) {
Expand Down

0 comments on commit 8a97712

Please sign in to comment.