linux-user: /proc/self/maps content
[qemu/ar7.git] / hw / virtio / vhost-backend.c
blobff4f2001bb719bb976e7cda8fb16faf89a7c59ce
1 /*
2 * vhost-backend
4 * Copyright (c) 2013 Virtual Open Systems Sarl.
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
9 */
11 #include "hw/virtio/vhost.h"
12 #include "hw/virtio/vhost-backend.h"
13 #include "qemu/error-report.h"
15 #include <sys/ioctl.h>
17 static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int request,
18 void *arg)
20 int fd = (uintptr_t) dev->opaque;
22 assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL);
24 return ioctl(fd, request, arg);
27 static int vhost_kernel_init(struct vhost_dev *dev, void *opaque)
29 assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL);
31 dev->opaque = opaque;
33 return 0;
36 static int vhost_kernel_cleanup(struct vhost_dev *dev)
38 int fd = (uintptr_t) dev->opaque;
40 assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL);
42 return close(fd);
45 static const VhostOps kernel_ops = {
46 .backend_type = VHOST_BACKEND_TYPE_KERNEL,
47 .vhost_call = vhost_kernel_call,
48 .vhost_backend_init = vhost_kernel_init,
49 .vhost_backend_cleanup = vhost_kernel_cleanup
52 int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type)
54 int r = 0;
56 switch (backend_type) {
57 case VHOST_BACKEND_TYPE_KERNEL:
58 dev->vhost_ops = &kernel_ops;
59 break;
60 case VHOST_BACKEND_TYPE_USER:
61 dev->vhost_ops = &user_ops;
62 break;
63 default:
64 error_report("Unknown vhost backend type\n");
65 r = -1;
68 return r;