The upcoming CPR support for vhost-vsock defers the full vhost_dev_init() to .post_load(). On an incoming CPR .realize() only sets up the backend, so we need a way to tell a fully initialized vhost device from a partially initialized one.
Add an explicit 'bool initialized' field, set once vhost_dev_init() succeeds, and cleared only in vhost_dev_cleanup() (by memset(0)). Also add a public vhost_dev_is_initialized() helper. Suggested-by: Stefano Garzarella <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Andrey Drobyshev <[email protected]> --- hw/virtio/vhost.c | 2 ++ include/hw/virtio/vhost.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 56fa4345886..c01ccc800cb 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1834,6 +1834,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, goto fail; } + hdev->initialized = true; + trace_vhost_dev_init_out(hdev); return 0; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 8127a9a5a2c..73ea130d7ee 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -109,6 +109,8 @@ struct vhost_dev { uint64_t backend_cap; /* @started: is the vhost device started? */ bool started; + /* @initialized: has the full vhost_dev_init() completed? */ + bool initialized; bool log_enabled; uint64_t log_size; Error *migration_blocker; @@ -248,6 +250,18 @@ static inline bool vhost_dev_is_started(struct vhost_dev *hdev) return hdev->started; } +/** + * vhost_dev_is_initialized() - report init status of vhost device + * @hdev: common vhost_dev structure + * + * Return true if the full vhost_dev_init() has completed successfully + * (and vhost_dev_cleanup() has not run since). + */ +static inline bool vhost_dev_is_initialized(struct vhost_dev *hdev) +{ + return hdev->initialized; +} + static inline int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable) { if (!hdev->vhost_ops->vhost_set_vring_enable) { -- 2.47.1
