]> git.proxmox.com Git - qemu.git/blame - fsdev/qemu-fsdev.c
smc91c111: Fix receive starvation
[qemu.git] / fsdev / qemu-fsdev.c
CommitLineData
74db920c
GS
1/*
2 * Virtio 9p
3 *
4 * Copyright IBM, Corp. 2010
5 *
6 * Authors:
7 * Gautham R Shenoy <ego@in.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#include <stdio.h>
14#include <string.h>
15#include "qemu-fsdev.h"
1de7afc9
PB
16#include "qemu/queue.h"
17#include "qemu/osdep.h"
74db920c 18#include "qemu-common.h"
1de7afc9 19#include "qemu/config-file.h"
74db920c 20
fbcbf101
AK
21static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
22 QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
74db920c 23
fbcbf101 24static FsDriverTable FsDrivers[] = {
9f107513 25 { .name = "local", .ops = &local_ops},
77eec1b3 26#ifdef CONFIG_OPEN_BY_HANDLE
5f542225 27 { .name = "handle", .ops = &handle_ops},
77eec1b3 28#endif
9db221ae 29 { .name = "synth", .ops = &synth_ops},
4c793dda 30 { .name = "proxy", .ops = &proxy_ops},
74db920c
GS
31};
32
33int qemu_fsdev_add(QemuOpts *opts)
34{
74db920c 35 int i;
99519f0a 36 struct FsDriverListEntry *fsle;
9f506893 37 const char *fsdev_id = qemu_opts_id(opts);
fbcbf101 38 const char *fsdriver = qemu_opt_get(opts, "fsdriver");
d3ab98e6 39 const char *writeout = qemu_opt_get(opts, "writeout");
2c74c2cb 40 bool ro = qemu_opt_get_bool(opts, "readonly", 0);
74db920c 41
9f506893 42 if (!fsdev_id) {
74db920c
GS
43 fprintf(stderr, "fsdev: No id specified\n");
44 return -1;
45 }
46
fbcbf101
AK
47 if (fsdriver) {
48 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
49 if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
9f506893
HPB
50 break;
51 }
74db920c 52 }
74db920c 53
fbcbf101
AK
54 if (i == ARRAY_SIZE(FsDrivers)) {
55 fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
9f506893
HPB
56 return -1;
57 }
58 } else {
fbcbf101 59 fprintf(stderr, "fsdev: No fsdriver specified\n");
74db920c
GS
60 return -1;
61 }
62
99519f0a 63 fsle = g_malloc0(sizeof(*fsle));
7267c094 64 fsle->fse.fsdev_id = g_strdup(fsdev_id);
fbcbf101 65 fsle->fse.ops = FsDrivers[i].ops;
d3ab98e6
AK
66 if (writeout) {
67 if (!strcmp(writeout, "immediate")) {
b97400ca 68 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
d3ab98e6
AK
69 }
70 }
2c74c2cb
MK
71 if (ro) {
72 fsle->fse.export_flags |= V9FS_RDONLY;
73 } else {
74 fsle->fse.export_flags &= ~V9FS_RDONLY;
75 }
b97400ca 76
99519f0a
AK
77 if (fsle->fse.ops->parse_opts) {
78 if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
b58c86e1
SW
79 g_free(fsle->fse.fsdev_id);
80 g_free(fsle);
99519f0a
AK
81 return -1;
82 }
d9b36a6e
MK
83 }
84
fbcbf101 85 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
74db920c 86 return 0;
74db920c
GS
87}
88
fbcbf101 89FsDriverEntry *get_fsdev_fsentry(char *id)
74db920c 90{
9f506893 91 if (id) {
fbcbf101 92 struct FsDriverListEntry *fsle;
74db920c 93
fbcbf101 94 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
9f506893
HPB
95 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
96 return &fsle->fse;
97 }
74db920c
GS
98 }
99 }
100 return NULL;
101}