git: f056e84e5b46 - main - virtio-scsi: handle device capacity change event
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 11 Jun 2026 13:07:05 UTC
The branch main has been updated by ray:
URL: https://cgit.FreeBSD.org/src/commit/?id=f056e84e5b46acd33c5e872f384683718313bad8
commit f056e84e5b46acd33c5e872f384683718313bad8
Author: Aleksandr Rybalko <ray@FreeBSD.org>
AuthorDate: 2026-05-26 14:49:21 +0000
Commit: Aleksandr Rybalko <ray@FreeBSD.org>
CommitDate: 2026-06-11 12:30:04 +0000
virtio-scsi: handle device capacity change event
This feature is utilized when updating storage capacity in capable hypervisors such as QEMU.
Reviewed by: imp
Approved by: imp(mentor)
Obtained from: Fudo Security
MFC after: 2 weeks
Sponsored by: Fudo Security
Differential Revision: https://reviews.freebsd.org/D57247
---
sys/dev/virtio/scsi/virtio_scsi.c | 24 ++++++++++++++++++++++++
sys/dev/virtio/scsi/virtio_scsi.h | 9 +++++++++
sys/dev/virtio/scsi/virtio_scsivar.h | 1 +
3 files changed, 34 insertions(+)
diff --git a/sys/dev/virtio/scsi/virtio_scsi.c b/sys/dev/virtio/scsi/virtio_scsi.c
index 857da56ba426..a61c92485ccc 100644
--- a/sys/dev/virtio/scsi/virtio_scsi.c
+++ b/sys/dev/virtio/scsi/virtio_scsi.c
@@ -1786,6 +1786,27 @@ vtscsi_transport_reset_event(struct vtscsi_softc *sc,
}
}
+static void
+vtscsi_param_change_event(struct vtscsi_softc *sc,
+ struct virtio_scsi_event *event)
+{
+ target_id_t target_id;
+ lun_id_t lun_id;
+
+ vtscsi_get_request_lun(event->lun, &target_id, &lun_id);
+
+ if (VIRTIO_SCSI_ASC(event->reason) == VIRTIO_SCSI_CAPACITY_CHNG_ASC &&
+ VIRTIO_SCSI_ASCQ(event->reason) == VIRTIO_SCSI_CAPACITY_CHNG_ASCQ) {
+ /* Disk capacity has changed. */
+ vtscsi_announce(sc, AC_INQ_CHANGED, target_id, lun_id);
+ } else {
+ device_printf(sc->vtscsi_dev,
+ "unhandled PARAM_CHANGE event. ASC: %02x, ASCQ: %02x\n",
+ VIRTIO_SCSI_ASC(event->reason),
+ VIRTIO_SCSI_ASCQ(event->reason));
+ }
+}
+
static void
vtscsi_handle_event(struct vtscsi_softc *sc, struct virtio_scsi_event *event)
{
@@ -1796,6 +1817,9 @@ vtscsi_handle_event(struct vtscsi_softc *sc, struct virtio_scsi_event *event)
case VIRTIO_SCSI_T_TRANSPORT_RESET:
vtscsi_transport_reset_event(sc, event);
break;
+ case VIRTIO_SCSI_T_PARAM_CHANGE:
+ vtscsi_param_change_event(sc, event);
+ break;
default:
device_printf(sc->vtscsi_dev,
"unhandled event: %d\n", event->event);
diff --git a/sys/dev/virtio/scsi/virtio_scsi.h b/sys/dev/virtio/scsi/virtio_scsi.h
index 02e13c6f81b7..66c72304f3f1 100644
--- a/sys/dev/virtio/scsi/virtio_scsi.h
+++ b/sys/dev/virtio/scsi/virtio_scsi.h
@@ -162,6 +162,15 @@ struct virtio_scsi_config {
#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
#define VIRTIO_SCSI_T_PARAM_CHANGE 3
+/*
+ * SCSI ASC/ASCQ Sense Codes
+ * https://www.t10.org/lists/asc-num.txt
+ */
+#define VIRTIO_SCSI_ASC(x) ((x) & 0xff)
+#define VIRTIO_SCSI_ASCQ(x) (((x) >> 8) & 0xff)
+#define VIRTIO_SCSI_CAPACITY_CHNG_ASC 0x2a
+#define VIRTIO_SCSI_CAPACITY_CHNG_ASCQ 0x09
+
/* Reasons of transport reset event */
#define VIRTIO_SCSI_EVT_RESET_HARD 0
#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
diff --git a/sys/dev/virtio/scsi/virtio_scsivar.h b/sys/dev/virtio/scsi/virtio_scsivar.h
index 85d2990d8bf4..b5f3c59727cc 100644
--- a/sys/dev/virtio/scsi/virtio_scsivar.h
+++ b/sys/dev/virtio/scsi/virtio_scsivar.h
@@ -139,6 +139,7 @@ struct vtscsi_request {
/* Features desired/implemented by this driver. */
#define VTSCSI_FEATURES \
(VIRTIO_SCSI_F_HOTPLUG | \
+ VIRTIO_SCSI_F_CHANGE | \
VIRTIO_RING_F_INDIRECT_DESC)
#define VTSCSI_MTX(_sc) &(_sc)->vtscsi_mtx