Lines Matching +full:pre +full:- +full:processing

2  * vhost-user-blk host device
9 * Largely based on the "vhost-user-scsi.c" and "vhost-scsi.c" implemented by:
15 * See the COPYING.LIB file in the top-level directory.
21 #include "qemu/error-report.h"
23 #include "hw/qdev-core.h"
24 #include "hw/qdev-properties.h"
25 #include "hw/qdev-properties-system.h"
26 #include "hw/virtio/virtio-blk-common.h"
28 #include "hw/virtio/vhost-user-blk.h"
30 #include "hw/virtio/virtio-bus.h"
31 #include "hw/virtio/virtio-access.h"
66 virtio_stw_p(vdev, &s->blkcfg.num_queues, s->num_queues); in vhost_user_blk_update_config()
68 memcpy(config, &s->blkcfg, vdev->config_len); in vhost_user_blk_update_config()
77 if (blkcfg->wce == s->blkcfg.wce) { in vhost_user_blk_set_config()
81 ret = vhost_dev_set_config(&s->dev, &blkcfg->wce, in vhost_user_blk_set_config()
83 sizeof(blkcfg->wce), in vhost_user_blk_set_config()
90 s->blkcfg.wce = blkcfg->wce; in vhost_user_blk_set_config()
99 ret = vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, in vhost_user_blk_sync_config()
100 vdev->config_len, errp); in vhost_user_blk_sync_config()
105 memcpy(vdev->config, &s->blkcfg, vdev->config_len); in vhost_user_blk_sync_config()
116 if (!dev->started) { in vhost_user_blk_handle_config_change()
120 ret = vhost_user_blk_sync_config(DEVICE(dev->vdev), &local_err); in vhost_user_blk_handle_config_change()
140 if (!k->set_guest_notifiers) { in vhost_user_blk_start()
142 return -ENOSYS; in vhost_user_blk_start()
145 ret = vhost_dev_enable_notifiers(&s->dev, vdev); in vhost_user_blk_start()
147 error_setg_errno(errp, -ret, "Error enabling host notifiers"); in vhost_user_blk_start()
151 ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true); in vhost_user_blk_start()
153 error_setg_errno(errp, -ret, "Error binding guest notifier"); in vhost_user_blk_start()
157 s->dev.acked_features = vdev->guest_features; in vhost_user_blk_start()
159 ret = vhost_dev_prepare_inflight(&s->dev, vdev); in vhost_user_blk_start()
161 error_setg_errno(errp, -ret, "Error setting inflight format"); in vhost_user_blk_start()
165 if (!s->inflight->addr) { in vhost_user_blk_start()
166 ret = vhost_dev_get_inflight(&s->dev, s->queue_size, s->inflight); in vhost_user_blk_start()
168 error_setg_errno(errp, -ret, "Error getting inflight"); in vhost_user_blk_start()
173 ret = vhost_dev_set_inflight(&s->dev, s->inflight); in vhost_user_blk_start()
175 error_setg_errno(errp, -ret, "Error setting inflight"); in vhost_user_blk_start()
180 * everything here. virtio-pci will do the right thing by in vhost_user_blk_start()
183 for (i = 0; i < s->dev.nvqs; i++) { in vhost_user_blk_start()
184 vhost_virtqueue_mask(&s->dev, vdev, i, false); in vhost_user_blk_start()
187 s->dev.vq_index_end = s->dev.nvqs; in vhost_user_blk_start()
188 ret = vhost_dev_start(&s->dev, vdev, true); in vhost_user_blk_start()
190 error_setg_errno(errp, -ret, "Error starting vhost"); in vhost_user_blk_start()
193 s->started_vu = true; in vhost_user_blk_start()
198 for (i = 0; i < s->dev.nvqs; i++) { in vhost_user_blk_start()
199 vhost_virtqueue_mask(&s->dev, vdev, i, true); in vhost_user_blk_start()
201 k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); in vhost_user_blk_start()
203 vhost_dev_disable_notifiers(&s->dev, vdev); in vhost_user_blk_start()
214 if (!s->started_vu) { in vhost_user_blk_stop()
217 s->started_vu = false; in vhost_user_blk_stop()
219 if (!k->set_guest_notifiers) { in vhost_user_blk_stop()
223 ret = vhost_dev_stop(&s->dev, vdev, true); in vhost_user_blk_stop()
225 if (k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false) < 0) { in vhost_user_blk_stop()
227 return -1; in vhost_user_blk_stop()
230 vhost_dev_disable_notifiers(&s->dev, vdev); in vhost_user_blk_stop()
241 if (!s->connected) { in vhost_user_blk_set_status()
242 return -1; in vhost_user_blk_set_status()
245 if (vhost_dev_is_started(&s->dev) == should_start) { in vhost_user_blk_set_status()
252 error_reportf_err(local_err, "vhost-user-blk: vhost start failed: "); in vhost_user_blk_set_status()
253 qemu_chr_fe_disconnect(&s->chardev); in vhost_user_blk_set_status()
270 /* Turn on pre-defined features */ in vhost_user_blk_get_features()
279 if (s->num_queues > 1) { in vhost_user_blk_get_features()
283 return vhost_get_features(&s->dev, user_feature_bits, features); in vhost_user_blk_get_features()
292 if (!vdev->start_on_kick) { in vhost_user_blk_handle_output()
296 if (!s->connected) { in vhost_user_blk_handle_output()
300 if (vhost_dev_is_started(&s->dev)) { in vhost_user_blk_handle_output()
309 error_reportf_err(local_err, "vhost-user-blk: vhost start failed: "); in vhost_user_blk_handle_output()
310 qemu_chr_fe_disconnect(&s->chardev); in vhost_user_blk_handle_output()
314 /* Kick right away to begin processing requests already in vring */ in vhost_user_blk_handle_output()
315 for (i = 0; i < s->dev.nvqs; i++) { in vhost_user_blk_handle_output()
329 vhost_dev_free_inflight(s->inflight); in vhost_user_blk_reset()
338 if (s->connected) { in vhost_user_blk_connect()
342 s->dev.num_queues = s->num_queues; in vhost_user_blk_connect()
343 s->dev.nvqs = s->num_queues; in vhost_user_blk_connect()
344 s->dev.vqs = s->vhost_vqs; in vhost_user_blk_connect()
345 s->dev.vq_index = 0; in vhost_user_blk_connect()
346 s->dev.backend_features = 0; in vhost_user_blk_connect()
348 vhost_dev_set_config_notifier(&s->dev, &blk_ops); in vhost_user_blk_connect()
350 s->vhost_user.supports_config = true; in vhost_user_blk_connect()
351 ret = vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USER, 0, in vhost_user_blk_connect()
357 s->connected = true; in vhost_user_blk_connect()
360 if (virtio_device_started(vdev, vdev->status)) { in vhost_user_blk_connect()
372 if (!s->connected) { in vhost_user_blk_disconnect()
375 s->connected = false; in vhost_user_blk_disconnect()
379 vhost_dev_cleanup(&s->dev); in vhost_user_blk_disconnect()
382 /* Re-instate the event handler for new connections */ in vhost_user_blk_disconnect()
383 qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, in vhost_user_blk_disconnect()
398 qemu_chr_fe_disconnect(&s->chardev); in vhost_user_blk_event()
404 vhost_user_async_close(dev, &s->chardev, &s->dev, in vhost_user_blk_event()
420 s->connected = false; in vhost_user_blk_realize_connect()
422 ret = qemu_chr_fe_wait_connected(&s->chardev, errp); in vhost_user_blk_realize_connect()
429 qemu_chr_fe_disconnect(&s->chardev); in vhost_user_blk_realize_connect()
432 assert(s->connected); in vhost_user_blk_realize_connect()
434 ret = vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, in vhost_user_blk_realize_connect()
435 VIRTIO_DEVICE(s)->config_len, errp); in vhost_user_blk_realize_connect()
437 qemu_chr_fe_disconnect(&s->chardev); in vhost_user_blk_realize_connect()
438 vhost_dev_cleanup(&s->dev); in vhost_user_blk_realize_connect()
454 if (!s->chardev.chr) { in vhost_user_blk_device_realize()
459 if (s->num_queues == VHOST_USER_BLK_AUTO_NUM_QUEUES) { in vhost_user_blk_device_realize()
460 s->num_queues = 1; in vhost_user_blk_device_realize()
462 if (!s->num_queues || s->num_queues > VIRTIO_QUEUE_MAX) { in vhost_user_blk_device_realize()
467 if (!s->queue_size) { in vhost_user_blk_device_realize()
468 error_setg(errp, "queue size must be non-zero"); in vhost_user_blk_device_realize()
471 if (s->queue_size > VIRTQUEUE_MAX_SIZE) { in vhost_user_blk_device_realize()
477 if (!vhost_user_init(&s->vhost_user, &s->chardev, errp)) { in vhost_user_blk_device_realize()
482 vdev->host_features); in vhost_user_blk_device_realize()
485 s->virtqs = g_new(VirtQueue *, s->num_queues); in vhost_user_blk_device_realize()
486 for (i = 0; i < s->num_queues; i++) { in vhost_user_blk_device_realize()
487 s->virtqs[i] = virtio_add_queue(vdev, s->queue_size, in vhost_user_blk_device_realize()
491 s->inflight = g_new0(struct vhost_inflight, 1); in vhost_user_blk_device_realize()
492 s->vhost_vqs = g_new0(struct vhost_virtqueue, s->num_queues); in vhost_user_blk_device_realize()
503 } while (ret < 0 && retries--); in vhost_user_blk_device_realize()
510 qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, in vhost_user_blk_device_realize()
516 g_free(s->vhost_vqs); in vhost_user_blk_device_realize()
517 s->vhost_vqs = NULL; in vhost_user_blk_device_realize()
518 g_free(s->inflight); in vhost_user_blk_device_realize()
519 s->inflight = NULL; in vhost_user_blk_device_realize()
520 for (i = 0; i < s->num_queues; i++) { in vhost_user_blk_device_realize()
521 virtio_delete_queue(s->virtqs[i]); in vhost_user_blk_device_realize()
523 g_free(s->virtqs); in vhost_user_blk_device_realize()
525 vhost_user_cleanup(&s->vhost_user); in vhost_user_blk_device_realize()
535 qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, in vhost_user_blk_device_unrealize()
537 vhost_dev_cleanup(&s->dev); in vhost_user_blk_device_unrealize()
538 vhost_dev_free_inflight(s->inflight); in vhost_user_blk_device_unrealize()
539 g_free(s->vhost_vqs); in vhost_user_blk_device_unrealize()
540 s->vhost_vqs = NULL; in vhost_user_blk_device_unrealize()
541 g_free(s->inflight); in vhost_user_blk_device_unrealize()
542 s->inflight = NULL; in vhost_user_blk_device_unrealize()
544 for (i = 0; i < s->num_queues; i++) { in vhost_user_blk_device_unrealize()
545 virtio_delete_queue(s->virtqs[i]); in vhost_user_blk_device_unrealize()
547 g_free(s->virtqs); in vhost_user_blk_device_unrealize()
549 vhost_user_cleanup(&s->vhost_user); in vhost_user_blk_device_unrealize()
556 device_add_bootindex_property(obj, &s->bootindex, "bootindex", in vhost_user_blk_instance_init()
563 return &s->dev; in vhost_user_blk_get_vhost()
567 .name = "vhost-user-blk",
578 DEFINE_PROP_UINT16("num-queues", VHostUserBlk, num_queues,
580 DEFINE_PROP_UINT32("queue-size", VHostUserBlk, queue_size, 128),
581 DEFINE_PROP_BIT64("config-wce", VHostUserBlk, parent_obj.host_features,
585 DEFINE_PROP_BIT64("write-zeroes", VHostUserBlk, parent_obj.host_features,
595 dc->vmsd = &vmstate_vhost_user_blk; in vhost_user_blk_class_init()
596 dc->sync_config = vhost_user_blk_sync_config; in vhost_user_blk_class_init()
597 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); in vhost_user_blk_class_init()
598 vdc->realize = vhost_user_blk_device_realize; in vhost_user_blk_class_init()
599 vdc->unrealize = vhost_user_blk_device_unrealize; in vhost_user_blk_class_init()
600 vdc->get_config = vhost_user_blk_update_config; in vhost_user_blk_class_init()
601 vdc->set_config = vhost_user_blk_set_config; in vhost_user_blk_class_init()
602 vdc->get_features = vhost_user_blk_get_features; in vhost_user_blk_class_init()
603 vdc->set_status = vhost_user_blk_set_status; in vhost_user_blk_class_init()
604 vdc->reset = vhost_user_blk_reset; in vhost_user_blk_class_init()
605 vdc->get_vhost = vhost_user_blk_get_vhost; in vhost_user_blk_class_init()