Acked-by: Raphael Norwitz <[email protected]>

On Thu, Oct 16, 2025 at 7:49 AM Vladimir Sementsov-Ogievskiy
<[email protected]> wrote:
>
> Prepare for future backend-transfer migration of vhost-user-blk.
> Among other things we'll need to transfer the inflight region, let's
> prepare for this.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
> ---
>  hw/virtio/vhost.c         | 26 ++++++++++++++++++++++++++
>  include/hw/virtio/vhost.h |  5 +++++
>  2 files changed, 31 insertions(+)
>
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 3e5192ec23..63036f8214 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -1975,6 +1975,32 @@ void vhost_get_features_ex(struct vhost_dev *hdev,
>      }
>  }
>
> +static int vhost_inflight_backend_transfer_post_load(void *opaque,
> +                                                     int version_id)
> +{
> +    struct vhost_inflight *inflight = opaque;
> +
> +    inflight->addr = mmap(0, inflight->size, PROT_READ | PROT_WRITE,
> +                             MAP_SHARED, inflight->fd, inflight->offset);
> +    if (inflight->addr == MAP_FAILED) {
> +        return -EINVAL;
> +    }
> +
> +    return 0;
> +}
> +
> +const VMStateDescription vmstate_backend_transfer_vhost_inflight = {
> +    .name = "vhost-inflight",
> +    .post_load = vhost_inflight_backend_transfer_post_load,
> +    .fields = (const VMStateField[]) {
> +        VMSTATE_FD(fd, struct vhost_inflight),
> +        VMSTATE_UINT64(size, struct vhost_inflight),
> +        VMSTATE_UINT64(offset, struct vhost_inflight),
> +        VMSTATE_UINT16(queue_size, struct vhost_inflight),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
>  void vhost_ack_features_ex(struct vhost_dev *hdev, const int *feature_bits,
>                             const uint64_t *features)
>  {
> diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
> index af46d4b5f2..94a0c75fc8 100644
> --- a/include/hw/virtio/vhost.h
> +++ b/include/hw/virtio/vhost.h
> @@ -587,4 +587,9 @@ static inline int vhost_load_backend_state(struct 
> vhost_dev *dev, QEMUFile *f,
>  }
>  #endif
>
> +extern const VMStateDescription vmstate_backend_transfer_vhost_inflight;
> +#define VMSTATE_BACKEND_TRANSFER_VHOST_INFLIGHT(_field, _state) \
> +    VMSTATE_STRUCT_POINTER(_field, _state, vmstate_inflight, \
> +                           struct vhost_inflight)
> +
>  #endif
> --
> 2.48.1
>
>

Reply via email to