mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 15:53:54 -06:00
vhost-user: simplify vhost_user_init/vhost_user_cleanup
Take a VhostUserState* that can be pre-allocated, and initialize it with the associated chardev. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Tiwei Bie <tiwei.bie@intel.com> Message-Id: <20190308140454.32437-4-marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
482580a658
commit
0b99f22461
9 changed files with 33 additions and 66 deletions
|
@ -1750,17 +1750,24 @@ static bool vhost_user_mem_section_filter(struct vhost_dev *dev,
|
|||
return result;
|
||||
}
|
||||
|
||||
VhostUserState *vhost_user_init(void)
|
||||
bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp)
|
||||
{
|
||||
VhostUserState *user = g_new0(struct VhostUserState, 1);
|
||||
|
||||
return user;
|
||||
if (user->chr) {
|
||||
error_setg(errp, "Cannot initialize vhost-user state");
|
||||
return false;
|
||||
}
|
||||
user->chr = chr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void vhost_user_cleanup(VhostUserState *user)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!user->chr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < VIRTIO_QUEUE_MAX; i++) {
|
||||
if (user->notifier[i].addr) {
|
||||
object_unparent(OBJECT(&user->notifier[i].mr));
|
||||
|
@ -1768,6 +1775,7 @@ void vhost_user_cleanup(VhostUserState *user)
|
|||
user->notifier[i].addr = NULL;
|
||||
}
|
||||
}
|
||||
user->chr = NULL;
|
||||
}
|
||||
|
||||
const VhostOps user_ops = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue