]> git.proxmox.com Git - mirror_qemu.git/blame - hw/9pfs/virtio-9p-device.c
virtio: remove the function pointer.
[mirror_qemu.git] / hw / 9pfs / virtio-9p-device.c
CommitLineData
f4f61d27
AK
1/*
2 * Virtio 9p backend
3 *
4 * Copyright IBM, Corp. 2010
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
0d09e41a 14#include "hw/virtio/virtio.h"
93b48c20 15#include "hw/virtio/virtio-9p.h"
0d09e41a 16#include "hw/i386/pc.h"
1de7afc9 17#include "qemu/sockets.h"
f4f61d27
AK
18#include "virtio-9p.h"
19#include "fsdev/qemu-fsdev.h"
20#include "virtio-9p-xattr.h"
39c0564e 21#include "virtio-9p-coth.h"
f4f61d27
AK
22
23static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)
24{
25 features |= 1 << VIRTIO_9P_MOUNT_TAG;
26 return features;
27}
28
f4f61d27
AK
29static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config)
30{
e9a0152b 31 int len;
f4f61d27 32 struct virtio_9p_config *cfg;
13daf6ca 33 V9fsState *s = VIRTIO_9P(vdev);
f4f61d27 34
e9a0152b
AK
35 len = strlen(s->tag);
36 cfg = g_malloc0(sizeof(struct virtio_9p_config) + len);
37 stw_raw(&cfg->tag_len, len);
38 /* We don't copy the terminating null to config space */
39 memcpy(cfg->tag, s->tag, len);
f4f61d27 40 memcpy(config, cfg, s->config_size);
7267c094 41 g_free(cfg);
f4f61d27
AK
42}
43
e8111e50 44static int virtio_9p_device_init(VirtIODevice *vdev)
0174fe73 45{
e8111e50 46 V9fsState *s = VIRTIO_9P(vdev);
f4f61d27
AK
47 int i, len;
48 struct stat stat;
fbcbf101 49 FsDriverEntry *fse;
7cca27df 50 V9fsPath path;
f4f61d27 51
e8111e50
FK
52 virtio_init(VIRTIO_DEVICE(s), "virtio-9p", VIRTIO_ID_9P,
53 sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
e7303c43 54
f4f61d27
AK
55 /* initialize pdu allocator */
56 QLIST_INIT(&s->free_list);
bccacf6c 57 QLIST_INIT(&s->active_list);
f4f61d27
AK
58 for (i = 0; i < (MAX_REQ - 1); i++) {
59 QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next);
60 }
61
e8111e50 62 s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
f4f61d27 63
e8111e50 64 fse = get_fsdev_fsentry(s->fsconf.fsdev_id);
f4f61d27
AK
65
66 if (!fse) {
67 /* We don't have a fsdev identified by fsdev_id */
68 fprintf(stderr, "Virtio-9p device couldn't find fsdev with the "
e8111e50
FK
69 "id = %s\n",
70 s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL");
71 return -1;
f4f61d27
AK
72 }
73
e8111e50 74 if (!s->fsconf.tag) {
99519f0a
AK
75 /* we haven't specified a mount_tag */
76 fprintf(stderr, "fsdev with id %s needs mount_tag arguments\n",
e8111e50
FK
77 s->fsconf.fsdev_id);
78 return -1;
f4f61d27
AK
79 }
80
b97400ca 81 s->ctx.export_flags = fse->export_flags;
c64f50d1 82 s->ctx.fs_root = g_strdup(fse->path);
b97400ca 83 s->ctx.exops.get_st_gen = NULL;
e8111e50 84 len = strlen(s->fsconf.tag);
e9a0152b 85 if (len > MAX_TAG_LEN - 1) {
a2f507d9 86 fprintf(stderr, "mount tag '%s' (%d bytes) is longer than "
e8111e50
FK
87 "maximum (%d bytes)", s->fsconf.tag, len, MAX_TAG_LEN - 1);
88 return -1;
f4f61d27 89 }
e9a0152b 90
e8111e50 91 s->tag = strdup(s->fsconf.tag);
f4f61d27
AK
92 s->ctx.uid = -1;
93
94 s->ops = fse->ops;
e9a0152b 95 s->config_size = sizeof(struct virtio_9p_config) + len;
9e5b2247 96 s->fid_list = NULL;
02cb7f3a 97 qemu_co_rwlock_init(&s->rename_lock);
f4f61d27 98
0174fe73
AK
99 if (s->ops->init(&s->ctx) < 0) {
100 fprintf(stderr, "Virtio-9p Failed to initialize fs-driver with id:%s"
e8111e50
FK
101 " and export path:%s\n", s->fsconf.fsdev_id, s->ctx.fs_root);
102 return -1;
0174fe73 103 }
39c0564e
VJ
104 if (v9fs_init_worker_threads() < 0) {
105 fprintf(stderr, "worker thread initialization failed\n");
e8111e50 106 return -1;
39c0564e 107 }
7cca27df
MK
108
109 /*
110 * Check details of export path, We need to use fs driver
111 * call back to do that. Since we are in the init path, we don't
112 * use co-routines here.
113 */
114 v9fs_path_init(&path);
115 if (s->ops->name_to_path(&s->ctx, NULL, "/", &path) < 0) {
116 fprintf(stderr,
117 "error in converting name to path %s", strerror(errno));
e8111e50 118 return -1;
7cca27df
MK
119 }
120 if (s->ops->lstat(&s->ctx, &path, &stat)) {
121 fprintf(stderr, "share path %s does not exist\n", fse->path);
e8111e50 122 return -1;
7cca27df
MK
123 } else if (!S_ISDIR(stat.st_mode)) {
124 fprintf(stderr, "share path %s is not a directory\n", fse->path);
e8111e50 125 return -1;
7cca27df
MK
126 }
127 v9fs_path_free(&path);
128
e8111e50 129 return 0;
e7303c43
FK
130}
131
132/* virtio-9p device */
133
e7303c43
FK
134static Property virtio_9p_properties[] = {
135 DEFINE_VIRTIO_9P_PROPERTIES(V9fsState, fsconf),
136 DEFINE_PROP_END_OF_LIST(),
137};
138
139static void virtio_9p_class_init(ObjectClass *klass, void *data)
140{
141 DeviceClass *dc = DEVICE_CLASS(klass);
142 VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
143 dc->props = virtio_9p_properties;
144 vdc->init = virtio_9p_device_init;
145 vdc->get_features = virtio_9p_get_features;
146 vdc->get_config = virtio_9p_get_config;
147}
148
149static const TypeInfo virtio_device_info = {
150 .name = TYPE_VIRTIO_9P,
151 .parent = TYPE_VIRTIO_DEVICE,
152 .instance_size = sizeof(V9fsState),
153 .class_init = virtio_9p_class_init,
154};
155
156static void virtio_9p_register_types(void)
157{
158 type_register_static(&virtio_device_info);
159}
160
161type_init(virtio_9p_register_types)