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

On Thu, Oct 16, 2025 at 7:47 AM Vladimir Sementsov-Ogievskiy
<[email protected]> wrote:
>
> Memory allocation and connecting of structures remain ins _init(),
> communication with backend goes to _connect().
>
> We need this for further support of backend-transfer migration of
> vhost-user-blk, as we'll need to postpone (or not do) initial
> communication to backend.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
> ---
>  hw/virtio/vhost-user.c | 32 ++++++++++++++++++++------------
>  1 file changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index e45b74eddd..c5cb5ed528 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -2270,21 +2270,12 @@ static int 
> vhost_user_postcopy_notifier(NotifierWithReturn *notifier,
>      return 0;
>  }
>
> -static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
> -                                   Error **errp)
> +static int vhost_user_backend_connect(struct vhost_dev *dev, Error **errp)
>  {
>      uint64_t features, ram_slots;
> -    struct vhost_user *u;
> -    VhostUserState *vus = (VhostUserState *) opaque;
> +    struct vhost_user *u = dev->opaque;
>      int err;
>
> -    assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
> -
> -    u = g_new0(struct vhost_user, 1);
> -    u->user = vus;
> -    u->dev = dev;
> -    dev->opaque = u;
> -
>      err = vhost_user_get_features(dev, &features);
>      if (err < 0) {
>          error_setg_errno(errp, -err, "vhost_backend_init failed");
> @@ -2292,7 +2283,7 @@ static int vhost_user_backend_init(struct vhost_dev 
> *dev, void *opaque,
>      }
>
>      if (virtio_has_feature(features, VHOST_USER_F_PROTOCOL_FEATURES)) {
> -        bool supports_f_config = vus->supports_config ||
> +        bool supports_f_config = u->user->supports_config ||
>              (dev->config_ops && dev->config_ops->vhost_dev_config_notifier);
>          uint64_t protocol_features;
>
> @@ -2408,6 +2399,22 @@ static int vhost_user_backend_init(struct vhost_dev 
> *dev, void *opaque,
>      return 0;
>  }
>
> +static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
> +                                   Error **errp)
> +{
> +    struct vhost_user *u;
> +    VhostUserState *vus = (VhostUserState *) opaque;
> +
> +    assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
> +
> +    u = g_new0(struct vhost_user, 1);
> +    u->user = vus;
> +    u->dev = dev;
> +    dev->opaque = u;
> +
> +    return 0;
> +}
> +
>  static int vhost_user_backend_cleanup(struct vhost_dev *dev)
>  {
>      struct vhost_user *u;
> @@ -3133,6 +3140,7 @@ void vhost_user_qmp_status(struct vhost_dev *dev, 
> VirtioStatus *status)
>  const VhostOps user_ops = {
>          .backend_type = VHOST_BACKEND_TYPE_USER,
>          .vhost_backend_init = vhost_user_backend_init,
> +        .vhost_backend_connect = vhost_user_backend_connect,
>          .vhost_backend_cleanup = vhost_user_backend_cleanup,
>          .vhost_backend_memslots_limit = vhost_user_memslots_limit,
>          .vhost_backend_no_private_memslots = vhost_user_no_private_memslots,
> --
> 2.48.1
>
>

Reply via email to