Skip to content

Commit d54c676

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: core: Fix the unit attention counter implementation
scsi_decide_disposition() may call scsi_check_sense(). scsi_decide_disposition() calls are not serialized. Hence, counter updates by scsi_check_sense() must be serialized. Hence this patch that makes the counters updated by scsi_check_sense() atomic. Cc: Kai Mäkisara <Kai.Makisara@kolumbus.fi> Fixes: a5d518c ("scsi: core: Add counters for New Media and Power On/Reset UNIT ATTENTIONs") Signed-off-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Ewan D. Milne <emilne@redhat.com> Link: https://patch.msgid.link/20251014220244.3689508-1-bvanassche@acm.org Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 35bc3c8 commit d54c676

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

drivers/scsi/scsi_error.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ enum scsi_disposition scsi_check_sense(struct scsi_cmnd *scmd)
554554
* happened, even if someone else gets the sense data.
555555
*/
556556
if (sshdr.asc == 0x28)
557-
scmd->device->ua_new_media_ctr++;
557+
atomic_inc(&sdev->ua_new_media_ctr);
558558
else if (sshdr.asc == 0x29)
559-
scmd->device->ua_por_ctr++;
559+
atomic_inc(&sdev->ua_por_ctr);
560560
}
561561

562562
if (scsi_sense_is_deferred(&sshdr))

include/scsi/scsi_device.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ struct scsi_device {
252252
unsigned int queue_stopped; /* request queue is quiesced */
253253
bool offline_already; /* Device offline message logged */
254254

255-
unsigned int ua_new_media_ctr; /* Counter for New Media UNIT ATTENTIONs */
256-
unsigned int ua_por_ctr; /* Counter for Power On / Reset UAs */
255+
atomic_t ua_new_media_ctr; /* Counter for New Media UNIT ATTENTIONs */
256+
atomic_t ua_por_ctr; /* Counter for Power On / Reset UAs */
257257

258258
atomic_t disk_events_disable_depth; /* disable depth for disk events */
259259

@@ -693,10 +693,8 @@ static inline int scsi_device_busy(struct scsi_device *sdev)
693693
}
694694

695695
/* Macros to access the UNIT ATTENTION counters */
696-
#define scsi_get_ua_new_media_ctr(sdev) \
697-
((const unsigned int)(sdev->ua_new_media_ctr))
698-
#define scsi_get_ua_por_ctr(sdev) \
699-
((const unsigned int)(sdev->ua_por_ctr))
696+
#define scsi_get_ua_new_media_ctr(sdev) atomic_read(&sdev->ua_new_media_ctr)
697+
#define scsi_get_ua_por_ctr(sdev) atomic_read(&sdev->ua_por_ctr)
700698

701699
#define MODULE_ALIAS_SCSI_DEVICE(type) \
702700
MODULE_ALIAS("scsi:t-" __stringify(type) "*")

0 commit comments

Comments
 (0)