mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 09:43:56 -06:00
system/runstate: add VM state change cb with return value
This patch adds the new VM state change cb type `VMChangeStateHandlerWithRet`, which has return value for `VMChangeStateEntry`. Thus, we can register a new VM state change cb with return value for device. Note that `VMChangeStateHandler` and `VMChangeStateHandlerWithRet` are mutually exclusive and cannot be provided at the same time. This patch is the pre patch for 'vhost-user: return failure if backend crashes when live migration', which makes the live migration aware of the loss of connection with the vhost-user backend and aborts the live migration. Virtio device will use VMChangeStateHandlerWithRet. Signed-off-by: Haoqian He <haoqian.he@smartx.com> Message-Id: <20250416024729.3289157-2-haoqian.he@smartx.com> Tested-by: Lei Yang <leiyang@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
8717987fb5
commit
e0f300b36d
8 changed files with 62 additions and 20 deletions
|
@ -1802,7 +1802,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
|
|||
* called after ->start_ioeventfd() has already set blk's AioContext.
|
||||
*/
|
||||
s->change =
|
||||
qdev_add_vm_change_state_handler(dev, virtio_blk_dma_restart_cb, s);
|
||||
qdev_add_vm_change_state_handler(dev, virtio_blk_dma_restart_cb, NULL, s);
|
||||
|
||||
blk_ram_registrar_init(&s->blk_ram_registrar, s->blk);
|
||||
blk_set_dev_ops(s->blk, &virtio_block_ops, s);
|
||||
|
|
|
@ -40,6 +40,7 @@ static int qdev_get_dev_tree_depth(DeviceState *dev)
|
|||
* qdev_add_vm_change_state_handler:
|
||||
* @dev: the device that owns this handler
|
||||
* @cb: the callback function to be invoked
|
||||
* @cb_ret: the callback function with return value to be invoked
|
||||
* @opaque: user data passed to the callback function
|
||||
*
|
||||
* This function works like qemu_add_vm_change_state_handler() except callbacks
|
||||
|
@ -50,25 +51,30 @@ static int qdev_get_dev_tree_depth(DeviceState *dev)
|
|||
* controller's callback is invoked before the children on its bus when the VM
|
||||
* starts running. The order is reversed when the VM stops running.
|
||||
*
|
||||
* Note that the parameter `cb` and `cb_ret` are mutually exclusive.
|
||||
*
|
||||
* Returns: an entry to be freed with qemu_del_vm_change_state_handler()
|
||||
*/
|
||||
VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
|
||||
VMChangeStateHandler *cb,
|
||||
VMChangeStateHandlerWithRet *cb_ret,
|
||||
void *opaque)
|
||||
{
|
||||
return qdev_add_vm_change_state_handler_full(dev, cb, NULL, opaque);
|
||||
assert(!cb || !cb_ret);
|
||||
return qdev_add_vm_change_state_handler_full(dev, cb, NULL, cb_ret, opaque);
|
||||
}
|
||||
|
||||
/*
|
||||
* Exactly like qdev_add_vm_change_state_handler() but passes a prepare_cb
|
||||
* argument too.
|
||||
* and the cb_ret arguments too.
|
||||
*/
|
||||
VMChangeStateEntry *qdev_add_vm_change_state_handler_full(
|
||||
DeviceState *dev, VMChangeStateHandler *cb,
|
||||
VMChangeStateHandler *prepare_cb, void *opaque)
|
||||
DeviceState *dev, VMChangeStateHandler *cb, VMChangeStateHandler *prepare_cb,
|
||||
VMChangeStateHandlerWithRet *cb_ret, void *opaque)
|
||||
{
|
||||
int depth = qdev_get_dev_tree_depth(dev);
|
||||
|
||||
return qemu_add_vm_change_state_handler_prio_full(cb, prepare_cb, opaque,
|
||||
depth);
|
||||
assert(!cb || !cb_ret);
|
||||
return qemu_add_vm_change_state_handler_prio_full(cb, prepare_cb, cb_ret,
|
||||
opaque, depth);
|
||||
}
|
||||
|
|
|
@ -400,7 +400,7 @@ static void scsi_qdev_realize(DeviceState *qdev, Error **errp)
|
|||
return;
|
||||
}
|
||||
dev->vmsentry = qdev_add_vm_change_state_handler(DEVICE(dev),
|
||||
scsi_dma_restart_cb, dev);
|
||||
scsi_dma_restart_cb, NULL, dev);
|
||||
}
|
||||
|
||||
static void scsi_qdev_unrealize(DeviceState *qdev)
|
||||
|
|
|
@ -1016,7 +1016,7 @@ static int vfio_migration_init(VFIODevice *vbasedev)
|
|||
vfio_vmstate_change_prepare :
|
||||
NULL;
|
||||
migration->vm_state = qdev_add_vm_change_state_handler_full(
|
||||
vbasedev->dev, vfio_vmstate_change, prepare_cb, vbasedev);
|
||||
vbasedev->dev, vfio_vmstate_change, prepare_cb, NULL, vbasedev);
|
||||
migration_add_notifier(&migration->migration_state,
|
||||
vfio_migration_state_notifier);
|
||||
|
||||
|
|
|
@ -3489,7 +3489,7 @@ void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size)
|
|||
vdev->config = NULL;
|
||||
}
|
||||
vdev->vmstate = qdev_add_vm_change_state_handler(DEVICE(vdev),
|
||||
virtio_vmstate_change, vdev);
|
||||
virtio_vmstate_change, NULL, vdev);
|
||||
vdev->device_endian = virtio_default_endian();
|
||||
vdev->use_guest_notifier_mask = true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue