198fc1adaSDr. David Alan Gilbert /* 298fc1adaSDr. David Alan Gilbert * Vhost-user filesystem virtio device 398fc1adaSDr. David Alan Gilbert * 498fc1adaSDr. David Alan Gilbert * Copyright 2018-2019 Red Hat, Inc. 598fc1adaSDr. David Alan Gilbert * 698fc1adaSDr. David Alan Gilbert * Authors: 798fc1adaSDr. David Alan Gilbert * Stefan Hajnoczi <stefanha@redhat.com> 898fc1adaSDr. David Alan Gilbert * 998fc1adaSDr. David Alan Gilbert * This work is licensed under the terms of the GNU GPL, version 2 or 1098fc1adaSDr. David Alan Gilbert * (at your option) any later version. See the COPYING file in the 1198fc1adaSDr. David Alan Gilbert * top-level directory. 1298fc1adaSDr. David Alan Gilbert */ 1398fc1adaSDr. David Alan Gilbert 1498fc1adaSDr. David Alan Gilbert #include "qemu/osdep.h" 1598fc1adaSDr. David Alan Gilbert #include <sys/ioctl.h> 1698fc1adaSDr. David Alan Gilbert #include "standard-headers/linux/virtio_fs.h" 1798fc1adaSDr. David Alan Gilbert #include "qapi/error.h" 1898fc1adaSDr. David Alan Gilbert #include "hw/qdev-properties.h" 19ce35e229SEduardo Habkost #include "hw/qdev-properties-system.h" 2098fc1adaSDr. David Alan Gilbert #include "hw/virtio/virtio-bus.h" 2198fc1adaSDr. David Alan Gilbert #include "hw/virtio/virtio-access.h" 2298fc1adaSDr. David Alan Gilbert #include "qemu/error-report.h" 23b8f3e6a1SAlex Bennée #include "hw/virtio/vhost.h" 2498fc1adaSDr. David Alan Gilbert #include "hw/virtio/vhost-user-fs.h" 2598fc1adaSDr. David Alan Gilbert #include "monitor/monitor.h" 266da32fe5SLaszlo Ersek #include "sysemu/sysemu.h" 2798fc1adaSDr. David Alan Gilbert 28ace66791SAnton Kuchin static const int user_feature_bits[] = { 29ace66791SAnton Kuchin VIRTIO_F_VERSION_1, 30ace66791SAnton Kuchin VIRTIO_RING_F_INDIRECT_DESC, 31ace66791SAnton Kuchin VIRTIO_RING_F_EVENT_IDX, 32ace66791SAnton Kuchin VIRTIO_F_NOTIFY_ON_EMPTY, 33ace66791SAnton Kuchin VIRTIO_F_RING_PACKED, 34ace66791SAnton Kuchin VIRTIO_F_IOMMU_PLATFORM, 35562a7d23SStefano Garzarella VIRTIO_F_RING_RESET, 36ace66791SAnton Kuchin 37ace66791SAnton Kuchin VHOST_INVALID_FEATURE_BIT 38ace66791SAnton Kuchin }; 39ace66791SAnton Kuchin 4098fc1adaSDr. David Alan Gilbert static void vuf_get_config(VirtIODevice *vdev, uint8_t *config) 4198fc1adaSDr. David Alan Gilbert { 4298fc1adaSDr. David Alan Gilbert VHostUserFS *fs = VHOST_USER_FS(vdev); 4398fc1adaSDr. David Alan Gilbert struct virtio_fs_config fscfg = {}; 4498fc1adaSDr. David Alan Gilbert 4598fc1adaSDr. David Alan Gilbert memcpy((char *)fscfg.tag, fs->conf.tag, 4698fc1adaSDr. David Alan Gilbert MIN(strlen(fs->conf.tag) + 1, sizeof(fscfg.tag))); 4798fc1adaSDr. David Alan Gilbert 4898fc1adaSDr. David Alan Gilbert virtio_stl_p(vdev, &fscfg.num_request_queues, fs->conf.num_request_queues); 4998fc1adaSDr. David Alan Gilbert 5098fc1adaSDr. David Alan Gilbert memcpy(config, &fscfg, sizeof(fscfg)); 5198fc1adaSDr. David Alan Gilbert } 5298fc1adaSDr. David Alan Gilbert 5398fc1adaSDr. David Alan Gilbert static void vuf_start(VirtIODevice *vdev) 5498fc1adaSDr. David Alan Gilbert { 5598fc1adaSDr. David Alan Gilbert VHostUserFS *fs = VHOST_USER_FS(vdev); 5698fc1adaSDr. David Alan Gilbert BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); 5798fc1adaSDr. David Alan Gilbert VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); 5898fc1adaSDr. David Alan Gilbert int ret; 5998fc1adaSDr. David Alan Gilbert int i; 6098fc1adaSDr. David Alan Gilbert 6198fc1adaSDr. David Alan Gilbert if (!k->set_guest_notifiers) { 6298fc1adaSDr. David Alan Gilbert error_report("binding does not support guest notifiers"); 6398fc1adaSDr. David Alan Gilbert return; 6498fc1adaSDr. David Alan Gilbert } 6598fc1adaSDr. David Alan Gilbert 6698fc1adaSDr. David Alan Gilbert ret = vhost_dev_enable_notifiers(&fs->vhost_dev, vdev); 6798fc1adaSDr. David Alan Gilbert if (ret < 0) { 6898fc1adaSDr. David Alan Gilbert error_report("Error enabling host notifiers: %d", -ret); 6998fc1adaSDr. David Alan Gilbert return; 7098fc1adaSDr. David Alan Gilbert } 7198fc1adaSDr. David Alan Gilbert 7298fc1adaSDr. David Alan Gilbert ret = k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, true); 7398fc1adaSDr. David Alan Gilbert if (ret < 0) { 7498fc1adaSDr. David Alan Gilbert error_report("Error binding guest notifier: %d", -ret); 7598fc1adaSDr. David Alan Gilbert goto err_host_notifiers; 7698fc1adaSDr. David Alan Gilbert } 7798fc1adaSDr. David Alan Gilbert 7898fc1adaSDr. David Alan Gilbert fs->vhost_dev.acked_features = vdev->guest_features; 794daa5054SStefano Garzarella ret = vhost_dev_start(&fs->vhost_dev, vdev, true); 8098fc1adaSDr. David Alan Gilbert if (ret < 0) { 8198fc1adaSDr. David Alan Gilbert error_report("Error starting vhost: %d", -ret); 8298fc1adaSDr. David Alan Gilbert goto err_guest_notifiers; 8398fc1adaSDr. David Alan Gilbert } 8498fc1adaSDr. David Alan Gilbert 8598fc1adaSDr. David Alan Gilbert /* 8698fc1adaSDr. David Alan Gilbert * guest_notifier_mask/pending not used yet, so just unmask 8798fc1adaSDr. David Alan Gilbert * everything here. virtio-pci will do the right thing by 8898fc1adaSDr. David Alan Gilbert * enabling/disabling irqfd. 8998fc1adaSDr. David Alan Gilbert */ 9098fc1adaSDr. David Alan Gilbert for (i = 0; i < fs->vhost_dev.nvqs; i++) { 9198fc1adaSDr. David Alan Gilbert vhost_virtqueue_mask(&fs->vhost_dev, vdev, i, false); 9298fc1adaSDr. David Alan Gilbert } 9398fc1adaSDr. David Alan Gilbert 9498fc1adaSDr. David Alan Gilbert return; 9598fc1adaSDr. David Alan Gilbert 9698fc1adaSDr. David Alan Gilbert err_guest_notifiers: 9798fc1adaSDr. David Alan Gilbert k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false); 9898fc1adaSDr. David Alan Gilbert err_host_notifiers: 9998fc1adaSDr. David Alan Gilbert vhost_dev_disable_notifiers(&fs->vhost_dev, vdev); 10098fc1adaSDr. David Alan Gilbert } 10198fc1adaSDr. David Alan Gilbert 10298fc1adaSDr. David Alan Gilbert static void vuf_stop(VirtIODevice *vdev) 10398fc1adaSDr. David Alan Gilbert { 10498fc1adaSDr. David Alan Gilbert VHostUserFS *fs = VHOST_USER_FS(vdev); 10598fc1adaSDr. David Alan Gilbert BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); 10698fc1adaSDr. David Alan Gilbert VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); 10798fc1adaSDr. David Alan Gilbert int ret; 10898fc1adaSDr. David Alan Gilbert 10998fc1adaSDr. David Alan Gilbert if (!k->set_guest_notifiers) { 11098fc1adaSDr. David Alan Gilbert return; 11198fc1adaSDr. David Alan Gilbert } 11298fc1adaSDr. David Alan Gilbert 1134daa5054SStefano Garzarella vhost_dev_stop(&fs->vhost_dev, vdev, true); 11498fc1adaSDr. David Alan Gilbert 11598fc1adaSDr. David Alan Gilbert ret = k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false); 11698fc1adaSDr. David Alan Gilbert if (ret < 0) { 11798fc1adaSDr. David Alan Gilbert error_report("vhost guest notifier cleanup failed: %d", ret); 11898fc1adaSDr. David Alan Gilbert return; 11998fc1adaSDr. David Alan Gilbert } 12098fc1adaSDr. David Alan Gilbert 12198fc1adaSDr. David Alan Gilbert vhost_dev_disable_notifiers(&fs->vhost_dev, vdev); 12298fc1adaSDr. David Alan Gilbert } 12398fc1adaSDr. David Alan Gilbert 12498fc1adaSDr. David Alan Gilbert static void vuf_set_status(VirtIODevice *vdev, uint8_t status) 12598fc1adaSDr. David Alan Gilbert { 12698fc1adaSDr. David Alan Gilbert VHostUserFS *fs = VHOST_USER_FS(vdev); 127259d69c0SAlex Bennée bool should_start = virtio_device_should_start(vdev, status); 12898fc1adaSDr. David Alan Gilbert 129b8f3e6a1SAlex Bennée if (vhost_dev_is_started(&fs->vhost_dev) == should_start) { 13098fc1adaSDr. David Alan Gilbert return; 13198fc1adaSDr. David Alan Gilbert } 13298fc1adaSDr. David Alan Gilbert 13398fc1adaSDr. David Alan Gilbert if (should_start) { 13498fc1adaSDr. David Alan Gilbert vuf_start(vdev); 13598fc1adaSDr. David Alan Gilbert } else { 13698fc1adaSDr. David Alan Gilbert vuf_stop(vdev); 13798fc1adaSDr. David Alan Gilbert } 13898fc1adaSDr. David Alan Gilbert } 13998fc1adaSDr. David Alan Gilbert 14098fc1adaSDr. David Alan Gilbert static uint64_t vuf_get_features(VirtIODevice *vdev, 141ace66791SAnton Kuchin uint64_t features, 14298fc1adaSDr. David Alan Gilbert Error **errp) 14398fc1adaSDr. David Alan Gilbert { 144ace66791SAnton Kuchin VHostUserFS *fs = VHOST_USER_FS(vdev); 145ace66791SAnton Kuchin 146ace66791SAnton Kuchin return vhost_get_features(&fs->vhost_dev, user_feature_bits, features); 14798fc1adaSDr. David Alan Gilbert } 14898fc1adaSDr. David Alan Gilbert 14998fc1adaSDr. David Alan Gilbert static void vuf_handle_output(VirtIODevice *vdev, VirtQueue *vq) 15098fc1adaSDr. David Alan Gilbert { 15198fc1adaSDr. David Alan Gilbert /* 15298fc1adaSDr. David Alan Gilbert * Not normally called; it's the daemon that handles the queue; 15398fc1adaSDr. David Alan Gilbert * however virtio's cleanup path can call this. 15498fc1adaSDr. David Alan Gilbert */ 15598fc1adaSDr. David Alan Gilbert } 15698fc1adaSDr. David Alan Gilbert 15798fc1adaSDr. David Alan Gilbert static void vuf_guest_notifier_mask(VirtIODevice *vdev, int idx, 15898fc1adaSDr. David Alan Gilbert bool mask) 15998fc1adaSDr. David Alan Gilbert { 16098fc1adaSDr. David Alan Gilbert VHostUserFS *fs = VHOST_USER_FS(vdev); 16198fc1adaSDr. David Alan Gilbert 162544f0278SCindy Lu /* 163544f0278SCindy Lu * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 164544f0278SCindy Lu * as the Marco of configure interrupt's IDX, If this driver does not 165544f0278SCindy Lu * support, the function will return 166544f0278SCindy Lu */ 167544f0278SCindy Lu 168544f0278SCindy Lu if (idx == VIRTIO_CONFIG_IRQ_IDX) { 169544f0278SCindy Lu return; 170544f0278SCindy Lu } 17198fc1adaSDr. David Alan Gilbert vhost_virtqueue_mask(&fs->vhost_dev, vdev, idx, mask); 17298fc1adaSDr. David Alan Gilbert } 17398fc1adaSDr. David Alan Gilbert 17498fc1adaSDr. David Alan Gilbert static bool vuf_guest_notifier_pending(VirtIODevice *vdev, int idx) 17598fc1adaSDr. David Alan Gilbert { 17698fc1adaSDr. David Alan Gilbert VHostUserFS *fs = VHOST_USER_FS(vdev); 17798fc1adaSDr. David Alan Gilbert 178544f0278SCindy Lu /* 179544f0278SCindy Lu * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1 180544f0278SCindy Lu * as the Marco of configure interrupt's IDX, If this driver does not 181544f0278SCindy Lu * support, the function will return 182544f0278SCindy Lu */ 183544f0278SCindy Lu 184544f0278SCindy Lu if (idx == VIRTIO_CONFIG_IRQ_IDX) { 185544f0278SCindy Lu return false; 186544f0278SCindy Lu } 18798fc1adaSDr. David Alan Gilbert return vhost_virtqueue_pending(&fs->vhost_dev, idx); 18898fc1adaSDr. David Alan Gilbert } 18998fc1adaSDr. David Alan Gilbert 19098fc1adaSDr. David Alan Gilbert static void vuf_device_realize(DeviceState *dev, Error **errp) 19198fc1adaSDr. David Alan Gilbert { 19298fc1adaSDr. David Alan Gilbert VirtIODevice *vdev = VIRTIO_DEVICE(dev); 19398fc1adaSDr. David Alan Gilbert VHostUserFS *fs = VHOST_USER_FS(dev); 19498fc1adaSDr. David Alan Gilbert unsigned int i; 19598fc1adaSDr. David Alan Gilbert size_t len; 19698fc1adaSDr. David Alan Gilbert int ret; 19798fc1adaSDr. David Alan Gilbert 19898fc1adaSDr. David Alan Gilbert if (!fs->conf.chardev.chr) { 19998fc1adaSDr. David Alan Gilbert error_setg(errp, "missing chardev"); 20098fc1adaSDr. David Alan Gilbert return; 20198fc1adaSDr. David Alan Gilbert } 20298fc1adaSDr. David Alan Gilbert 20398fc1adaSDr. David Alan Gilbert if (!fs->conf.tag) { 20498fc1adaSDr. David Alan Gilbert error_setg(errp, "missing tag property"); 20598fc1adaSDr. David Alan Gilbert return; 20698fc1adaSDr. David Alan Gilbert } 20798fc1adaSDr. David Alan Gilbert len = strlen(fs->conf.tag); 20898fc1adaSDr. David Alan Gilbert if (len == 0) { 20998fc1adaSDr. David Alan Gilbert error_setg(errp, "tag property cannot be empty"); 21098fc1adaSDr. David Alan Gilbert return; 21198fc1adaSDr. David Alan Gilbert } 21298fc1adaSDr. David Alan Gilbert if (len > sizeof_field(struct virtio_fs_config, tag)) { 21398fc1adaSDr. David Alan Gilbert error_setg(errp, "tag property must be %zu bytes or less", 21498fc1adaSDr. David Alan Gilbert sizeof_field(struct virtio_fs_config, tag)); 21598fc1adaSDr. David Alan Gilbert return; 21698fc1adaSDr. David Alan Gilbert } 21798fc1adaSDr. David Alan Gilbert 21898fc1adaSDr. David Alan Gilbert if (fs->conf.num_request_queues == 0) { 21998fc1adaSDr. David Alan Gilbert error_setg(errp, "num-request-queues property must be larger than 0"); 22098fc1adaSDr. David Alan Gilbert return; 22198fc1adaSDr. David Alan Gilbert } 22298fc1adaSDr. David Alan Gilbert 22398fc1adaSDr. David Alan Gilbert if (!is_power_of_2(fs->conf.queue_size)) { 22498fc1adaSDr. David Alan Gilbert error_setg(errp, "queue-size property must be a power of 2"); 22598fc1adaSDr. David Alan Gilbert return; 22698fc1adaSDr. David Alan Gilbert } 22798fc1adaSDr. David Alan Gilbert 22898fc1adaSDr. David Alan Gilbert if (fs->conf.queue_size > VIRTQUEUE_MAX_SIZE) { 22998fc1adaSDr. David Alan Gilbert error_setg(errp, "queue-size property must be %u or smaller", 23098fc1adaSDr. David Alan Gilbert VIRTQUEUE_MAX_SIZE); 23198fc1adaSDr. David Alan Gilbert return; 23298fc1adaSDr. David Alan Gilbert } 23398fc1adaSDr. David Alan Gilbert 23498fc1adaSDr. David Alan Gilbert if (!vhost_user_init(&fs->vhost_user, &fs->conf.chardev, errp)) { 23598fc1adaSDr. David Alan Gilbert return; 23698fc1adaSDr. David Alan Gilbert } 23798fc1adaSDr. David Alan Gilbert 2383857cd5cSJonah Palmer virtio_init(vdev, VIRTIO_ID_FS, sizeof(struct virtio_fs_config)); 23998fc1adaSDr. David Alan Gilbert 24098fc1adaSDr. David Alan Gilbert /* Hiprio queue */ 2412e5bc659SPan Nengyuan fs->hiprio_vq = virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); 24298fc1adaSDr. David Alan Gilbert 24398fc1adaSDr. David Alan Gilbert /* Request queues */ 2442e5bc659SPan Nengyuan fs->req_vqs = g_new(VirtQueue *, fs->conf.num_request_queues); 24598fc1adaSDr. David Alan Gilbert for (i = 0; i < fs->conf.num_request_queues; i++) { 2462e5bc659SPan Nengyuan fs->req_vqs[i] = virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); 24798fc1adaSDr. David Alan Gilbert } 24898fc1adaSDr. David Alan Gilbert 24998fc1adaSDr. David Alan Gilbert /* 1 high prio queue, plus the number configured */ 25098fc1adaSDr. David Alan Gilbert fs->vhost_dev.nvqs = 1 + fs->conf.num_request_queues; 25198fc1adaSDr. David Alan Gilbert fs->vhost_dev.vqs = g_new0(struct vhost_virtqueue, fs->vhost_dev.nvqs); 25298fc1adaSDr. David Alan Gilbert ret = vhost_dev_init(&fs->vhost_dev, &fs->vhost_user, 253a6945f22SKevin Wolf VHOST_BACKEND_TYPE_USER, 0, errp); 25498fc1adaSDr. David Alan Gilbert if (ret < 0) { 25598fc1adaSDr. David Alan Gilbert goto err_virtio; 25698fc1adaSDr. David Alan Gilbert } 25798fc1adaSDr. David Alan Gilbert 25898fc1adaSDr. David Alan Gilbert return; 25998fc1adaSDr. David Alan Gilbert 26098fc1adaSDr. David Alan Gilbert err_virtio: 26198fc1adaSDr. David Alan Gilbert vhost_user_cleanup(&fs->vhost_user); 2622e5bc659SPan Nengyuan virtio_delete_queue(fs->hiprio_vq); 263ba07cf5dSPan Nengyuan for (i = 0; i < fs->conf.num_request_queues; i++) { 2642e5bc659SPan Nengyuan virtio_delete_queue(fs->req_vqs[i]); 265ba07cf5dSPan Nengyuan } 2662e5bc659SPan Nengyuan g_free(fs->req_vqs); 26798fc1adaSDr. David Alan Gilbert virtio_cleanup(vdev); 26898fc1adaSDr. David Alan Gilbert g_free(fs->vhost_dev.vqs); 26998fc1adaSDr. David Alan Gilbert return; 27098fc1adaSDr. David Alan Gilbert } 27198fc1adaSDr. David Alan Gilbert 272b69c3c21SMarkus Armbruster static void vuf_device_unrealize(DeviceState *dev) 27398fc1adaSDr. David Alan Gilbert { 27498fc1adaSDr. David Alan Gilbert VirtIODevice *vdev = VIRTIO_DEVICE(dev); 27598fc1adaSDr. David Alan Gilbert VHostUserFS *fs = VHOST_USER_FS(dev); 276*331acddcSAkihiko Odaki struct vhost_virtqueue *vhost_vqs = fs->vhost_dev.vqs; 277ba07cf5dSPan Nengyuan int i; 27898fc1adaSDr. David Alan Gilbert 27998fc1adaSDr. David Alan Gilbert /* This will stop vhost backend if appropriate. */ 28098fc1adaSDr. David Alan Gilbert vuf_set_status(vdev, 0); 28198fc1adaSDr. David Alan Gilbert 28298fc1adaSDr. David Alan Gilbert vhost_dev_cleanup(&fs->vhost_dev); 28398fc1adaSDr. David Alan Gilbert 28498fc1adaSDr. David Alan Gilbert vhost_user_cleanup(&fs->vhost_user); 28598fc1adaSDr. David Alan Gilbert 2862e5bc659SPan Nengyuan virtio_delete_queue(fs->hiprio_vq); 287ba07cf5dSPan Nengyuan for (i = 0; i < fs->conf.num_request_queues; i++) { 2882e5bc659SPan Nengyuan virtio_delete_queue(fs->req_vqs[i]); 289ba07cf5dSPan Nengyuan } 2902e5bc659SPan Nengyuan g_free(fs->req_vqs); 29198fc1adaSDr. David Alan Gilbert virtio_cleanup(vdev); 292*331acddcSAkihiko Odaki g_free(vhost_vqs); 29398fc1adaSDr. David Alan Gilbert } 29498fc1adaSDr. David Alan Gilbert 295c255488dSJonah Palmer static struct vhost_dev *vuf_get_vhost(VirtIODevice *vdev) 296c255488dSJonah Palmer { 297c255488dSJonah Palmer VHostUserFS *fs = VHOST_USER_FS(vdev); 298c255488dSJonah Palmer return &fs->vhost_dev; 299c255488dSJonah Palmer } 300c255488dSJonah Palmer 30198fc1adaSDr. David Alan Gilbert static const VMStateDescription vuf_vmstate = { 30298fc1adaSDr. David Alan Gilbert .name = "vhost-user-fs", 30398fc1adaSDr. David Alan Gilbert .unmigratable = 1, 30498fc1adaSDr. David Alan Gilbert }; 30598fc1adaSDr. David Alan Gilbert 30698fc1adaSDr. David Alan Gilbert static Property vuf_properties[] = { 30798fc1adaSDr. David Alan Gilbert DEFINE_PROP_CHR("chardev", VHostUserFS, conf.chardev), 30898fc1adaSDr. David Alan Gilbert DEFINE_PROP_STRING("tag", VHostUserFS, conf.tag), 30998fc1adaSDr. David Alan Gilbert DEFINE_PROP_UINT16("num-request-queues", VHostUserFS, 31098fc1adaSDr. David Alan Gilbert conf.num_request_queues, 1), 31198fc1adaSDr. David Alan Gilbert DEFINE_PROP_UINT16("queue-size", VHostUserFS, conf.queue_size, 128), 31298fc1adaSDr. David Alan Gilbert DEFINE_PROP_END_OF_LIST(), 31398fc1adaSDr. David Alan Gilbert }; 31498fc1adaSDr. David Alan Gilbert 3156da32fe5SLaszlo Ersek static void vuf_instance_init(Object *obj) 3166da32fe5SLaszlo Ersek { 3176da32fe5SLaszlo Ersek VHostUserFS *fs = VHOST_USER_FS(obj); 3186da32fe5SLaszlo Ersek 3196da32fe5SLaszlo Ersek device_add_bootindex_property(obj, &fs->bootindex, "bootindex", 3206da32fe5SLaszlo Ersek "/filesystem@0", DEVICE(obj)); 3216da32fe5SLaszlo Ersek } 3226da32fe5SLaszlo Ersek 32398fc1adaSDr. David Alan Gilbert static void vuf_class_init(ObjectClass *klass, void *data) 32498fc1adaSDr. David Alan Gilbert { 32598fc1adaSDr. David Alan Gilbert DeviceClass *dc = DEVICE_CLASS(klass); 32698fc1adaSDr. David Alan Gilbert VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); 32798fc1adaSDr. David Alan Gilbert 3284f67d30bSMarc-André Lureau device_class_set_props(dc, vuf_properties); 32998fc1adaSDr. David Alan Gilbert dc->vmsd = &vuf_vmstate; 33098fc1adaSDr. David Alan Gilbert set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); 33198fc1adaSDr. David Alan Gilbert vdc->realize = vuf_device_realize; 33298fc1adaSDr. David Alan Gilbert vdc->unrealize = vuf_device_unrealize; 33398fc1adaSDr. David Alan Gilbert vdc->get_features = vuf_get_features; 33498fc1adaSDr. David Alan Gilbert vdc->get_config = vuf_get_config; 33598fc1adaSDr. David Alan Gilbert vdc->set_status = vuf_set_status; 33698fc1adaSDr. David Alan Gilbert vdc->guest_notifier_mask = vuf_guest_notifier_mask; 33798fc1adaSDr. David Alan Gilbert vdc->guest_notifier_pending = vuf_guest_notifier_pending; 338c255488dSJonah Palmer vdc->get_vhost = vuf_get_vhost; 33998fc1adaSDr. David Alan Gilbert } 34098fc1adaSDr. David Alan Gilbert 34198fc1adaSDr. David Alan Gilbert static const TypeInfo vuf_info = { 34298fc1adaSDr. David Alan Gilbert .name = TYPE_VHOST_USER_FS, 34398fc1adaSDr. David Alan Gilbert .parent = TYPE_VIRTIO_DEVICE, 34498fc1adaSDr. David Alan Gilbert .instance_size = sizeof(VHostUserFS), 3456da32fe5SLaszlo Ersek .instance_init = vuf_instance_init, 34698fc1adaSDr. David Alan Gilbert .class_init = vuf_class_init, 34798fc1adaSDr. David Alan Gilbert }; 34898fc1adaSDr. David Alan Gilbert 34998fc1adaSDr. David Alan Gilbert static void vuf_register_types(void) 35098fc1adaSDr. David Alan Gilbert { 35198fc1adaSDr. David Alan Gilbert type_register_static(&vuf_info); 35298fc1adaSDr. David Alan Gilbert } 35398fc1adaSDr. David Alan Gilbert 35498fc1adaSDr. David Alan Gilbert type_init(vuf_register_types) 355