"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "hw/block/vhost-user-blk.c" between
qemu-6.0.0-rc1.tar.xz and qemu-6.0.0-rc2.tar.xz

About: QEMU is a generic machine/processor emulator and virtualizer. Release candidate.

vhost-user-blk.c  (qemu-6.0.0-rc1.tar.xz):vhost-user-blk.c  (qemu-6.0.0-rc2.tar.xz)
skipping to change at line 365 skipping to change at line 365
if (!s->connected) { if (!s->connected) {
return; return;
} }
s->connected = false; s->connected = false;
vhost_user_blk_stop(vdev); vhost_user_blk_stop(vdev);
vhost_dev_cleanup(&s->dev); vhost_dev_cleanup(&s->dev);
} }
static void vhost_user_blk_event(void *opaque, QEMUChrEvent event); static void vhost_user_blk_event(void *opaque, QEMUChrEvent event,
bool realized);
static void vhost_user_blk_event_realize(void *opaque, QEMUChrEvent event)
{
vhost_user_blk_event(opaque, event, false);
}
static void vhost_user_blk_event_oper(void *opaque, QEMUChrEvent event)
{
vhost_user_blk_event(opaque, event, true);
}
static void vhost_user_blk_chr_closed_bh(void *opaque) static void vhost_user_blk_chr_closed_bh(void *opaque)
{ {
DeviceState *dev = opaque; DeviceState *dev = opaque;
VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VHostUserBlk *s = VHOST_USER_BLK(vdev); VHostUserBlk *s = VHOST_USER_BLK(vdev);
vhost_user_blk_disconnect(dev); vhost_user_blk_disconnect(dev);
qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL,
NULL, opaque, NULL, true); vhost_user_blk_event_oper, NULL, opaque, NULL, true);
} }
static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) static void vhost_user_blk_event(void *opaque, QEMUChrEvent event,
bool realized)
{ {
DeviceState *dev = opaque; DeviceState *dev = opaque;
VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VHostUserBlk *s = VHOST_USER_BLK(vdev); VHostUserBlk *s = VHOST_USER_BLK(vdev);
switch (event) { switch (event) {
case CHR_EVENT_OPENED: case CHR_EVENT_OPENED:
if (vhost_user_blk_connect(dev) < 0) { if (vhost_user_blk_connect(dev) < 0) {
qemu_chr_fe_disconnect(&s->chardev); qemu_chr_fe_disconnect(&s->chardev);
return; return;
} }
break; break;
case CHR_EVENT_CLOSED: case CHR_EVENT_CLOSED:
/* /*
* A close event may happen during a read/write, but vhost * Closing the connection should happen differently on device
* code assumes the vhost_dev remains setup, so delay the * initialization and operation stages.
* stop & clear. There are two possible paths to hit this * On initalization, we want to re-start vhost_dev initialization
* disconnect event: * from the very beginning right away when the connection is closed,
* 1. When VM is in the RUN_STATE_PRELAUNCH state. The * so we clean up vhost_dev on each connection closing.
* vhost_user_blk_device_realize() is a caller. * On operation, we want to postpone vhost_dev cleanup to let the
* 2. In tha main loop phase after VM start. * other code perform its own cleanup sequence using vhost_dev data
* * (e.g. vhost_dev_set_log).
* For p2 the disconnect event will be delayed. We can't
* do the same for p1, because we are not running the loop
* at this moment. So just skip this step and perform
* disconnect in the caller function.
*
* TODO: maybe it is a good idea to make the same fix
* for other vhost-user devices.
*/ */
if (runstate_is_running()) { if (realized && !runstate_check(RUN_STATE_SHUTDOWN)) {
/*
* A close event may happen during a read/write, but vhost
* code assumes the vhost_dev remains setup, so delay the
* stop & clear.
*/
AioContext *ctx = qemu_get_current_aio_context(); AioContext *ctx = qemu_get_current_aio_context();
qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, NULL, qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, NULL,
NULL, NULL, false); NULL, NULL, false);
aio_bh_schedule_oneshot(ctx, vhost_user_blk_chr_closed_bh, opaque); aio_bh_schedule_oneshot(ctx, vhost_user_blk_chr_closed_bh, opaque);
}
/* /*
* Move vhost device to the stopped state. The vhost-user device * Move vhost device to the stopped state. The vhost-user device
* will be clean up and disconnected in BH. This can be useful in * will be clean up and disconnected in BH. This can be useful in
* the vhost migration code. If disconnect was caught there is an * the vhost migration code. If disconnect was caught there is an
* option for the general vhost code to get the dev state without * option for the general vhost code to get the dev state without
* knowing its type (in this case vhost-user). * knowing its type (in this case vhost-user).
*/ */
s->dev.started = false; s->dev.started = false;
} else {
vhost_user_blk_disconnect(dev);
}
break; break;
case CHR_EVENT_BREAK: case CHR_EVENT_BREAK:
case CHR_EVENT_MUX_IN: case CHR_EVENT_MUX_IN:
case CHR_EVENT_MUX_OUT: case CHR_EVENT_MUX_OUT:
/* Ignore */ /* Ignore */
break; break;
} }
} }
static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
skipping to change at line 476 skipping to change at line 488
s->virtqs = g_new(VirtQueue *, s->num_queues); s->virtqs = g_new(VirtQueue *, s->num_queues);
for (i = 0; i < s->num_queues; i++) { for (i = 0; i < s->num_queues; i++) {
s->virtqs[i] = virtio_add_queue(vdev, s->queue_size, s->virtqs[i] = virtio_add_queue(vdev, s->queue_size,
vhost_user_blk_handle_output); vhost_user_blk_handle_output);
} }
s->inflight = g_new0(struct vhost_inflight, 1); s->inflight = g_new0(struct vhost_inflight, 1);
s->vhost_vqs = g_new0(struct vhost_virtqueue, s->num_queues); s->vhost_vqs = g_new0(struct vhost_virtqueue, s->num_queues);
s->connected = false; s->connected = false;
qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL,
NULL, (void *)dev, NULL, true); vhost_user_blk_event_realize, NULL, (void *)dev,
NULL, true);
reconnect: reconnect:
if (qemu_chr_fe_wait_connected(&s->chardev, &err) < 0) { if (qemu_chr_fe_wait_connected(&s->chardev, &err) < 0) {
error_report_err(err); error_report_err(err);
goto virtio_err; goto virtio_err;
} }
/* check whether vhost_user_blk_connect() failed or not */ /* check whether vhost_user_blk_connect() failed or not */
if (!s->connected) { if (!s->connected) {
goto reconnect; goto reconnect;
} }
ret = vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, ret = vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg,
sizeof(struct virtio_blk_config)); sizeof(struct virtio_blk_config));
if (ret < 0) { if (ret < 0) {
error_report("vhost-user-blk: get block config failed"); error_report("vhost-user-blk: get block config failed");
goto reconnect; goto reconnect;
} }
/* we're fully initialized, now we can operate, so change the handler */
qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL,
vhost_user_blk_event_oper, NULL, (void *)dev,
NULL, true);
return; return;
virtio_err: virtio_err:
g_free(s->vhost_vqs); g_free(s->vhost_vqs);
s->vhost_vqs = NULL; s->vhost_vqs = NULL;
g_free(s->inflight); g_free(s->inflight);
s->inflight = NULL; s->inflight = NULL;
for (i = 0; i < s->num_queues; i++) { for (i = 0; i < s->num_queues; i++) {
virtio_delete_queue(s->virtqs[i]); virtio_delete_queue(s->virtqs[i]);
} }
 End of changes. 9 change blocks. 
31 lines changed or deleted 48 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)