uapi/virtio_scsi: allow overriding CDB/SENSE size
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/4 virtio-scsi: drop duplicate CDB/SENSE SIZE
This is duplicated from the kernel header,
drop our copy.
--- include/hw/virtio/virtio-scsi.h | 2 -- 1 file changed, 2 deletions(-)
include/hw/virtio/virtio-scsi.h +0 -2
@@ -30,8 +30,6 @@ OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)#define VIRTIO_SCSI_VQ_SIZE 128 -#define VIRTIO_SCSI_CDB_SIZE 32 -#define VIRTIO_SCSI_SENSE_SIZE 96#define VIRTIO_SCSI_MAX_CHANNEL 0#define VIRTIO_SCSI_MAX_TARGET 255#define VIRTIO_SCSI_MAX_LUN 16383
Signature · 1 line
MST
PATCH 2/4 uapi/virtio_scsi: allow overriding CDB/SENSE size
In reply to a message not in the archiveQEMU wants to use virtio scsi structures with
a different VIRTIO_SCSI_CDB_SIZE/VIRTIO_SCSI_SENSE_SIZE, let's add ifdefs to allow overriding them.
Keep the old defines under new names:
VIRTIO_SCSI_CDB_DEFAULT_SIZE/VIRTIO_SCSI_SENSE_DEFAULT_SIZE, since that's what these values really are:
defaults for cdb/sense size fields.
--- include/standard-headers/linux/virtio_scsi.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
include/standard-headers/linux/virtio_scsi.h +10 -2
@@ -29,8 +29,16 @@#include "standard-headers/linux/virtio_types.h" -#define VIRTIO_SCSI_CDB_SIZE 32 -#define VIRTIO_SCSI_SENSE_SIZE 96 +/* Default values of the CDB and sense data size configuration fields */ +#define VIRTIO_SCSI_CDB_DEFAULT_SIZE 32 +#define VIRTIO_SCSI_SENSE_DEFAULT_SIZE 96 + +#ifndef VIRTIO_SCSI_CDB_SIZE +#define VIRTIO_SCSI_CDB_SIZE VIRTIO_SCSI_CDB_DEFAULT_SIZE +#endif +#ifndef VIRTIO_SCSI_SENSE_SIZE +#define VIRTIO_SCSI_SENSE_SIZE VIRTIO_SCSI_SENSE_DEFAULT_SIZE +#endif /* SCSI command request, followed by data-out */ struct virtio_scsi_cmd_req {
Signature · 1 line
MST
PATCH 3/4 virtio-scsi: fix cdb/sense size
In reply to a message not in the archiveCommit "virtio-scsi: use standard-headers" added cdb and sense into req/rep structures, which breaks uses of sizeof for these structures, since qemu adds its own arrays on top.
To fix, redefine CDB/sense field size to 0.
--- include/hw/virtio/virtio-scsi.h | 3 +++ hw/scsi/virtio-scsi.c | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-)
include/hw/virtio/virtio-scsi.h +3 -0
@@ -14,6 +14,9 @@#ifndef _QEMU_VIRTIO_SCSI_H#define _QEMU_VIRTIO_SCSI_H +/* Override CDB/sense data size: they are dynamic (guest controlled) in QEMU */ +#define VIRTIO_SCSI_CDB_SIZE 0 +#define VIRTIO_SCSI_SENSE_SIZE 0#include "standard-headers/linux/virtio_scsi.h" #include "hw/virtio/virtio.h" #include "hw/pci/pci.h"
hw/scsi/virtio-scsi.c +5 -5
@@ -476,7 +476,7 @@ static int virtio_scsi_parse_cdb(SCSIDevice *dev, SCSICommand *cmd,VirtIOSCSIReq *req = hba_private;if (cmd->len ==0 ) { - cmd->len =MIN (VIRTIO_SCSI_CDB_SIZE ,SCSI_CMD_BUF_SIZE ); + cmd->len =MIN (VIRTIO_SCSI_CDB_DEFAULT_SIZE ,SCSI_CMD_BUF_SIZE );memcpy (cmd->buf, buf, cmd->len); }
@@ -642,8 +642,8 @@ static void virtio_scsi_reset(VirtIODevice *vdev)qbus_reset_all (&s->bus.qbus); s->resetting--; - vs->sense_size =VIRTIO_SCSI_SENSE_SIZE ; - vs->cdb_size =VIRTIO_SCSI_CDB_SIZE ; + vs->sense_size =VIRTIO_SCSI_SENSE_DEFAULT_SIZE ; + vs->cdb_size =VIRTIO_SCSI_CDB_DEFAULT_SIZE ; s->events_dropped = false; }
@@ -830,8 +830,8 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,return ; } s->cmd_vqs = g_new0(VirtQueue *, s->conf.num_queues); - s->sense_size =VIRTIO_SCSI_SENSE_SIZE ; - s->cdb_size =VIRTIO_SCSI_CDB_SIZE ; + s->sense_size =VIRTIO_SCSI_SENSE_DEFAULT_SIZE ; + s->cdb_size =VIRTIO_SCSI_CDB_DEFAULT_SIZE ; s->ctrl_vq =virtio_add_queue (vdev,VIRTIO_SCSI_VQ_SIZE , ctrl);
Signature · 1 line
MST
PATCH 4/4 virtio-scsi: clean out duplicate cdb field
In reply to a message not in the archivecdb is now part of cmd, drop it from req. There's also nothing to check using build assert now.
--- include/hw/virtio/virtio-scsi.h | 7 +------ hw/scsi/virtio-scsi.c | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-)
include/hw/virtio/virtio-scsi.h +1 -6
@@ -109,8 +109,7 @@ typedef struct VirtIOSCSIReq {/* Note: * - fields before elem are initialized by virtio_scsi_init_req; * - elem is uninitialized at the time of allocation. -* - fields after elem (except the ending cdb[]) are zeroed by -* virtio_scsi_init_req. +* - fields after elem are zeroed by virtio_scsi_init_req. * */ VirtQueueElement elem;
@@ -137,16 +136,12 @@ typedef struct VirtIOSCSIReq {union {struct {VirtIOSCSICmdReq cmd; -uint8_t cdb[]; } QEMU_PACKED;VirtIOSCSICtrlTMFReq tmf;VirtIOSCSICtrlANReq an; } req; } VirtIOSCSIReq; -QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cdb) != - offsetof(VirtIOSCSIReq, req.cmd) + sizeof(VirtIOSCSICmdReq)); -#define DEFINE_VIRTIO_SCSI_PROPERTIES (_state, _conf_field) \ DEFINE_PROP_UINT32("num_queues", _state, _conf_field.num_queues, 1), \ DEFINE_PROP_UINT32("max_sectors", _state, _conf_field.max_sectors, 0xFFFF),\
hw/scsi/virtio-scsi.c +1 -1
@@ -544,7 +544,7 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req) } req->sreq =scsi_req_new (d, req->req.cmd.tag,virtio_scsi_get_lun (req->req.cmd.lun), - req->req.cdb, req); + req->req.cmd.cdb, req); if (req->sreq->cmd.mode != SCSI_XFER_NONE && (req->sreq->cmd.mode != req->mode ||
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH 4/4] virtio-scsi: clean out duplicate cdb field
Quoted 4 lines · Michael S. Tsirkin
struct {
VirtIOSCSICmdReq cmd;
- uint8_t cdb[];
} QEMU_PACKED;Just:
VirtIOSCSICmdReq cmd;
without the wrapping struct.
With this change series
Quoted 8 lines
VirtIOSCSICtrlTMFReq tmf; VirtIOSCSICtrlANReq an; } req;} VirtIOSCSIReq;
include/hw/virtio/virtio-scsi.h +0
-3-QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cdb) != - offsetof(VirtIOSCSIReq, req.cmd) + sizeof(VirtIOSCSICmdReq)); -