scsi: pollable 'state' attribute
v2 cover scsi: pollable 'state' attribute
Hi all,
here's a small patchset to make the 'state' device attribute pollable. It was supposed to be a small patch, but then hch suggested a rework.
So there you go.
Changes to v2:
- Removed duplicate case value found by kbuild robot
- Dropped state update patch
Hannes Reinecke (2):
scsi_lib: rework scsi_internal_device_unblock_nowait()
scsi: make 'state' device attribute pollable
drivers/scsi/scsi_lib.c | 20 ++++++++++++++------ drivers/scsi/scsi_transport_srp.c | 5 ++++- 2 files changed, 18 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.5.6
PATCH v2 1/2 scsi_lib: rework scsi_internal_device_unblock_nowait()
Rework scsi_internal_device_unblock_nowait() into using a switch statement.
No functional changes.
--- drivers/scsi/scsi_lib.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/scsi/scsi_lib.c +11 -6
@@ -3074,19 +3074,24 @@ int scsi_internal_device_unblock_nowait(struct scsi_device *sdev,* Try to transition the scsi device to SDEV_RUNNING or one of the * offlined states and goose the device queue if successful. */ -if ((sdev->sdev_state ==SDEV_BLOCK ) || - (sdev->sdev_state ==SDEV_TRANSPORT_OFFLINE )) +switch (sdev->sdev_state) { +case SDEV_BLOCK : +case SDEV_TRANSPORT_OFFLINE : sdev->sdev_state = new_state; -else if (sdev->sdev_state ==SDEV_CREATED_BLOCK ) { +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 ; - }else if (sdev->sdev_state !=SDEV_CANCEL && - sdev->sdev_state !=SDEV_OFFLINE ) +break ; +case SDEV_CANCEL : +case SDEV_OFFLINE : +break ; +default :return -EINVAL ; - + }scsi_start_queue (sdev);return 0 ;
Signature · 1 line
1.8.5.6
PATCH v2 2/2 scsi: make 'state' device attribute pollable
In reply to Hannes ReineckeWhile 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.
--- drivers/scsi/scsi_lib.c | 3 +++ drivers/scsi/scsi_transport_srp.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +3 -0
@@ -2655,6 +2655,7 @@ void scsi_exit_queue(void) } sdev->sdev_state = state; +sysfs_notify (&sdev->sdev_gendev.kobj,NULL ,"state" );return 0 ; illegal:
@@ -3078,6 +3079,7 @@ 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 ||
@@ -3085,6 +3087,7 @@ int scsi_internal_device_unblock_nowait(struct scsi_device *sdev, 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 :
drivers/scsi/scsi_transport_srp.c +4 -1
@@ -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 ) {
Signature · 1 line
1.8.5.6
Martin K. Petersen
AppliedHannes,
Quoted 2 lines
here's a small patchset to make the 'state' device attribute pollable. It was supposed to be a small patch, but then hch suggested a rework.
Applied to 4.14/scsi-queue. Thank you!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering