Skip to contentSkip to conversation

scsi: fix bug scsi resp sense is 0 when expand disk

PATCH In review Jie Wang 1 participant 2 messages Jun 29, 2021 – Jul 1, 2021

lore
Share & tools
lore

Jie Wang

author
#0 lore raw

PATCH 1/1 scsi: fix bug scsi resp sense is 0 when expand disk

A large number of I/Os are delivered during disk capacity expansion. Many I/Os are extracted from the Vring ring, and each one registers reqops_unit_attention when new scsi req.
If the first registered req takes the ua, the ua is cleared and other registered req is return 0 sense.

Let's add req_has_ua to avoid this kind of thing.

---
 hw/scsi/scsi-bus.c     | 10 ++++++++--
 include/hw/scsi/scsi.h |  1 +
 2 files changed, 9 insertions(+), 2 deletions(-)
hw/scsi/scsi-bus.c +8 -2
index 2a0a98cac9..20ec4a5f74 100644
@@ -722,7 +722,13 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
           * If we already have a pending unit attention condition,
           * report this one before triggering another one.
           */
-         !(buf[0] == REQUEST_SENSE && d->sense_is_ua))) {
+         !(buf[0] == REQUEST_SENSE && d->sense_is_ua)) &&
+         /*
+          * If we already have a req register ua ops,
+          * other req can not register.
+          */
+         !d->req_has_ua) {
+        d->req_has_ua = true;
         ops = &reqops_unit_attention;
     } else if (lun != d->lun ||
                buf[0] == REPORT_LUNS ||
@@ -822,7 +828,7 @@ static void scsi_clear_unit_attention(SCSIRequest *req)
           ua->ascq == SENSE_CODE(REPORTED_LUNS_CHANGED).ascq)) {
         return;
     }
-
+    req->dev->req_has_ua = false;
     *ua = SENSE_CODE(NO_SENSE);
 }
 
include/hw/scsi/scsi.h +1 -0
index 0b726bc78c..3d0cda68f6 100644
@@ -74,6 +74,7 @@ struct SCSIDevice
     BlockConf conf;
     SCSISense unit_attention;
     bool sense_is_ua;
+    bool req_has_ua;
     uint8_t sense[SCSI_SENSE_BUF_SIZE];
     uint32_t sense_len;
     QTAILQ_HEAD(, SCSIRequest) requests;
Signature · 1 line
2.23.0
#1 lore raw

ping Re: [PATCH] scsi: fix bug scsi resp sense is 0 when expand disk

ping.

Quoted 56 lines · Jie Wang

A large number of I/Os are delivered during disk capacity expansion. Many I/Os are extracted from the Vring ring, and each one registers reqops_unit_attention when new scsi req.
If the first registered req takes the ua, the ua is cleared and other registered req is return 0 sense.

Let's add req_has_ua to avoid this kind of thing.

---
 hw/scsi/scsi-bus.c     | 10 ++++++++--
 include/hw/scsi/scsi.h |  1 +
 2 files changed, 9 insertions(+), 2 deletions(-)
hw/scsi/scsi-bus.c +8 -2
index 2a0a98cac9..20ec4a5f74 100644
@@ -722,7 +722,13 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
           * If we already have a pending unit attention condition,
           * report this one before triggering another one.
           */
-         !(buf[0] == REQUEST_SENSE && d->sense_is_ua))) {
+         !(buf[0] == REQUEST_SENSE && d->sense_is_ua)) &&
+         /*
+          * If we already have a req register ua ops,
+          * other req can not register.
+          */
+         !d->req_has_ua) {
+        d->req_has_ua = true;
         ops = &reqops_unit_attention;
     } else if (lun != d->lun ||
                buf[0] == REPORT_LUNS ||
@@ -822,7 +828,7 @@ static void scsi_clear_unit_attention(SCSIRequest *req)
           ua->ascq == SENSE_CODE(REPORTED_LUNS_CHANGED).ascq)) {
         return;
     }
-
+    req->dev->req_has_ua = false;
     *ua = SENSE_CODE(NO_SENSE);
 }
 
include/hw/scsi/scsi.h +1 -0
index 0b726bc78c..3d0cda68f6 100644
@@ -74,6 +74,7 @@ struct SCSIDevice
     BlockConf conf;
     SCSISense unit_attention;
     bool sense_is_ua;
+    bool req_has_ua;
     uint8_t sense[SCSI_SENSE_BUF_SIZE];
     uint32_t sense_len;
     QTAILQ_HEAD(, SCSIRequest) requests;