Message ID | 20200909122021.1055174-1-fengli@smartx.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | vhost-scsi: support inflight io track | expand |
On 09/09/20 14:20, Li Feng wrote: > Qemu will send GET_INFLIGHT_FD and SET_INFLIGH_FD to backend, and > the backend setup the inflight memory to track the io. > > Change-Id: I805d6189996f7a1b44c65f0b12ef7473b1789510 > Signed-off-by: Li Feng <fengli@smartx.com> > --- > hw/scsi/vhost-scsi-common.c | 27 +++++++++++++++++++++++++++ > include/hw/virtio/vhost-scsi-common.h | 2 ++ > 2 files changed, 29 insertions(+) > > diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c > index 8ec49d7fef..767f827e55 100644 > --- a/hw/scsi/vhost-scsi-common.c > +++ b/hw/scsi/vhost-scsi-common.c > @@ -32,6 +32,8 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) > BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); > VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); > > + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vsc; > + > if (!k->set_guest_notifiers) { > error_report("binding does not support guest notifiers"); > return -ENOSYS; > @@ -49,6 +51,23 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) > } > > vsc->dev.acked_features = vdev->guest_features; > + > + assert(vsc->inflight == NULL); > + vsc->inflight = g_new0(struct vhost_inflight, 1); > + ret = vhost_dev_get_inflight(&vsc->dev, > + vs->conf.virtqueue_size, > + vsc->inflight); > + if (ret < 0) { > + error_report("Error get inflight: %d", -ret); > + goto err_guest_notifiers; > + } > + > + ret = vhost_dev_set_inflight(&vsc->dev, vsc->inflight); > + if (ret < 0) { > + error_report("Error set inflight: %d", -ret); > + goto err_guest_notifiers; > + } > + > ret = vhost_dev_start(&vsc->dev, vdev); > if (ret < 0) { > error_report("Error start vhost dev"); > @@ -66,6 +85,9 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) > return ret; > > err_guest_notifiers: > + g_free(vsc->inflight); > + vsc->inflight = NULL; > + > k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false); > err_host_notifiers: > vhost_dev_disable_notifiers(&vsc->dev, vdev); > @@ -89,6 +111,11 @@ void vhost_scsi_common_stop(VHostSCSICommon *vsc) > } > assert(ret >= 0); > > + if (vsc->inflight) { > + vhost_dev_free_inflight(vsc->inflight); > + vsc->inflight = NULL; > + } > + > vhost_dev_disable_notifiers(&vsc->dev, vdev); > } > > diff --git a/include/hw/virtio/vhost-scsi-common.h b/include/hw/virtio/vhost-scsi-common.h > index 16bf1a73c1..6cd6431d67 100644 > --- a/include/hw/virtio/vhost-scsi-common.h > +++ b/include/hw/virtio/vhost-scsi-common.h > @@ -35,6 +35,8 @@ typedef struct VHostSCSICommon { > int lun; > uint64_t host_features; > bool migratable; > + > + struct vhost_inflight *inflight; > } VHostSCSICommon; > > int vhost_scsi_common_start(VHostSCSICommon *vsc); > Queued, thanks. Paolo
diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c index 8ec49d7fef..767f827e55 100644 --- a/hw/scsi/vhost-scsi-common.c +++ b/hw/scsi/vhost-scsi-common.c @@ -32,6 +32,8 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vsc; + if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); return -ENOSYS; @@ -49,6 +51,23 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) } vsc->dev.acked_features = vdev->guest_features; + + assert(vsc->inflight == NULL); + vsc->inflight = g_new0(struct vhost_inflight, 1); + ret = vhost_dev_get_inflight(&vsc->dev, + vs->conf.virtqueue_size, + vsc->inflight); + if (ret < 0) { + error_report("Error get inflight: %d", -ret); + goto err_guest_notifiers; + } + + ret = vhost_dev_set_inflight(&vsc->dev, vsc->inflight); + if (ret < 0) { + error_report("Error set inflight: %d", -ret); + goto err_guest_notifiers; + } + ret = vhost_dev_start(&vsc->dev, vdev); if (ret < 0) { error_report("Error start vhost dev"); @@ -66,6 +85,9 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) return ret; err_guest_notifiers: + g_free(vsc->inflight); + vsc->inflight = NULL; + k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false); err_host_notifiers: vhost_dev_disable_notifiers(&vsc->dev, vdev); @@ -89,6 +111,11 @@ void vhost_scsi_common_stop(VHostSCSICommon *vsc) } assert(ret >= 0); + if (vsc->inflight) { + vhost_dev_free_inflight(vsc->inflight); + vsc->inflight = NULL; + } + vhost_dev_disable_notifiers(&vsc->dev, vdev); } diff --git a/include/hw/virtio/vhost-scsi-common.h b/include/hw/virtio/vhost-scsi-common.h index 16bf1a73c1..6cd6431d67 100644 --- a/include/hw/virtio/vhost-scsi-common.h +++ b/include/hw/virtio/vhost-scsi-common.h @@ -35,6 +35,8 @@ typedef struct VHostSCSICommon { int lun; uint64_t host_features; bool migratable; + + struct vhost_inflight *inflight; } VHostSCSICommon; int vhost_scsi_common_start(VHostSCSICommon *vsc);
Qemu will send GET_INFLIGHT_FD and SET_INFLIGH_FD to backend, and the backend setup the inflight memory to track the io. Change-Id: I805d6189996f7a1b44c65f0b12ef7473b1789510 Signed-off-by: Li Feng <fengli@smartx.com> --- hw/scsi/vhost-scsi-common.c | 27 +++++++++++++++++++++++++++ include/hw/virtio/vhost-scsi-common.h | 2 ++ 2 files changed, 29 insertions(+)