hw/arm/virt: Add virt-3.1 machine type
[qemu/ar7.git] / fsdev / qemu-fsdev.c
blob8a4afbffbd3ff1f4d35b259e2d3a2d592575d914
1 /*
2 * 9p
4 * Copyright IBM, Corp. 2010
6 * Authors:
7 * Gautham R Shenoy <ego@in.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "qemu-fsdev.h"
16 #include "qemu/queue.h"
17 #include "qemu/config-file.h"
18 #include "qemu/error-report.h"
19 #include "qemu/option.h"
21 static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
22 QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
24 static FsDriverTable FsDrivers[] = {
25 { .name = "local", .ops = &local_ops},
26 #ifdef CONFIG_OPEN_BY_HANDLE
27 { .name = "handle", .ops = &handle_ops},
28 #endif
29 { .name = "synth", .ops = &synth_ops},
30 { .name = "proxy", .ops = &proxy_ops},
33 int qemu_fsdev_add(QemuOpts *opts)
35 int i;
36 struct FsDriverListEntry *fsle;
37 const char *fsdev_id = qemu_opts_id(opts);
38 const char *fsdriver = qemu_opt_get(opts, "fsdriver");
39 const char *writeout = qemu_opt_get(opts, "writeout");
40 bool ro = qemu_opt_get_bool(opts, "readonly", 0);
41 Error *local_err = NULL;
43 if (!fsdev_id) {
44 error_report("fsdev: No id specified");
45 return -1;
48 if (fsdriver) {
49 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
50 if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
51 break;
55 if (i == ARRAY_SIZE(FsDrivers)) {
56 error_report("fsdev: fsdriver %s not found", fsdriver);
57 return -1;
59 } else {
60 error_report("fsdev: No fsdriver specified");
61 return -1;
64 fsle = g_malloc0(sizeof(*fsle));
65 fsle->fse.fsdev_id = g_strdup(fsdev_id);
66 fsle->fse.ops = FsDrivers[i].ops;
67 if (writeout) {
68 if (!strcmp(writeout, "immediate")) {
69 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
72 if (ro) {
73 fsle->fse.export_flags |= V9FS_RDONLY;
74 } else {
75 fsle->fse.export_flags &= ~V9FS_RDONLY;
78 if (fsle->fse.ops->parse_opts) {
79 if (fsle->fse.ops->parse_opts(opts, &fsle->fse, &local_err)) {
80 error_report_err(local_err);
81 g_free(fsle->fse.fsdev_id);
82 g_free(fsle);
83 return -1;
87 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
88 return 0;
91 FsDriverEntry *get_fsdev_fsentry(char *id)
93 if (id) {
94 struct FsDriverListEntry *fsle;
96 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
97 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
98 return &fsle->fse;
102 return NULL;