On 9/7/26 5:56 PM, Stefano Garzarella wrote:
> On Thu, Aug 20, 2026 at 02:39:53PM +0300, Andrey Drobyshev wrote:
>> Wrap the set_owner/reset_owner backend ops in dev-level helpers, matching
>> other vhost_dev_* wrappers, so device code can take or release ownership
>> without reaching into vhost_ops directly.  vhost_dev_init() now uses
>> vhost_dev_set_owner(). Both return -ENOSYS if the backend has no such op.
>>
>> No functional change.  These are used by the following vhost-vsock patch to
>> hand a device between owners during CPR.
>>
>> Signed-off-by: Andrey Drobyshev <[email protected]>
>> ---
>> hw/virtio/vhost.c         | 20 +++++++++++++++++++-
>> include/hw/virtio/vhost.h | 13 +++++++++++++
>> 2 files changed, 32 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
>> index 2bb9a23fee4..ea17bf01080 100644
>> --- a/hw/virtio/vhost.c
>> +++ b/hw/virtio/vhost.c
>> @@ -1690,6 +1690,24 @@ int vhost_dev_init_backend(struct vhost_dev *hdev, 
>> void *opaque,
>>     return 0;
>> }
>>
>> +int vhost_dev_set_owner(struct vhost_dev *hdev)
>> +{
>> +    assert(hdev->vhost_ops);
>> +    if (!hdev->vhost_ops->vhost_set_owner) {
>> +        return -ENOSYS;
>> +    }
>> +    return hdev->vhost_ops->vhost_set_owner(hdev);
>> +}
>> +
>> +int vhost_dev_reset_owner(struct vhost_dev *hdev)
>> +{
>> +    assert(hdev->vhost_ops);
>> +    if (!hdev->vhost_ops->vhost_reset_owner) {
>> +        return -ENOSYS;
>> +    }
>> +    return hdev->vhost_ops->vhost_reset_owner(hdev);
>> +}
>> +
>> int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
>>                    VhostBackendType backend_type, uint32_t busyloop_timeout,
>>                    Error **errp)
>> @@ -1707,7 +1725,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void 
>> *opaque,
>>         goto fail;
>>     }
>>
>> -    r = hdev->vhost_ops->vhost_set_owner(hdev);
>> +    r = vhost_dev_set_owner(hdev);
>>     if (r < 0) {
>>         error_setg_errno(errp, -r, "vhost_set_owner failed");
>>         goto fail;
>> diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
>> index 9b98d34dd04..44e65968d9b 100644
>> --- a/include/hw/virtio/vhost.h
>> +++ b/include/hw/virtio/vhost.h
>> @@ -178,6 +178,19 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
>> int vhost_dev_init_backend(struct vhost_dev *hdev, void *opaque,
>>                            VhostBackendType backend_type, Error **errp);
>>
>> +/**
>> + * vhost_dev_set_owner() / vhost_dev_reset_owner() - take / release 
>> ownership
> 
> I'm not sure this is a common practice in kernel-doc format.
> I think we should add 2 differnt blocks, one for each function.
> 
> Stefano

Agreed, will do.

Andrey
>> + * @hdev: the common vhost_dev structure
>> + *
>> + * Take (VHOST_SET_OWNER) or release (VHOST_RESET_OWNER) ownership of a
>> + * device that has already been set up.  Used to hand a device over during
>> + * CPR.  Returns -ENOSYS if the backend has no such op.
>> + *
>> + * Return: 0 on success, negative errno on failure.
>> + */
>> +int vhost_dev_set_owner(struct vhost_dev *hdev);
>> +int vhost_dev_reset_owner(struct vhost_dev *hdev);
>> +
>> /**
>>  * vhost_dev_cleanup() - tear down and cleanup vhost interface
>>  * @hdev: the common vhost_dev structure
>> -- 
>> 2.47.1
>>
> 


Reply via email to