]> git.proxmox.com Git - mirror_qemu.git/blob - fsdev/qemu-fsdev.c
fsdev: Move some types definition to qemu-fsdev.c
[mirror_qemu.git] / fsdev / qemu-fsdev.c
1 /*
2 * 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 "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"
20
21 /*
22 * A table to store the various file systems and their callback operations.
23 * -----------------
24 * fstype | ops
25 * -----------------
26 * local | local_ops
27 * . |
28 * . |
29 * . |
30 * . |
31 * -----------------
32 * etc
33 */
34 typedef struct FsDriverTable {
35 const char *name;
36 FileOperations *ops;
37 } FsDriverTable;
38
39 typedef struct FsDriverListEntry {
40 FsDriverEntry fse;
41 QTAILQ_ENTRY(FsDriverListEntry) next;
42 } FsDriverListEntry;
43
44 static QTAILQ_HEAD(, FsDriverListEntry) fsdriver_entries =
45 QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
46
47 static FsDriverTable FsDrivers[] = {
48 { .name = "local", .ops = &local_ops},
49 { .name = "synth", .ops = &synth_ops},
50 { .name = "proxy", .ops = &proxy_ops},
51 };
52
53 int qemu_fsdev_add(QemuOpts *opts, Error **errp)
54 {
55 int i;
56 struct FsDriverListEntry *fsle;
57 const char *fsdev_id = qemu_opts_id(opts);
58 const char *fsdriver = qemu_opt_get(opts, "fsdriver");
59 const char *writeout = qemu_opt_get(opts, "writeout");
60 bool ro = qemu_opt_get_bool(opts, "readonly", 0);
61
62 if (!fsdev_id) {
63 error_setg(errp, "fsdev: No id specified");
64 return -1;
65 }
66
67 if (fsdriver) {
68 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
69 if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
70 break;
71 }
72 }
73
74 if (i == ARRAY_SIZE(FsDrivers)) {
75 error_setg(errp, "fsdev: fsdriver %s not found", fsdriver);
76 return -1;
77 }
78 } else {
79 error_setg(errp, "fsdev: No fsdriver specified");
80 return -1;
81 }
82
83 fsle = g_malloc0(sizeof(*fsle));
84 fsle->fse.fsdev_id = g_strdup(fsdev_id);
85 fsle->fse.ops = FsDrivers[i].ops;
86 if (writeout) {
87 if (!strcmp(writeout, "immediate")) {
88 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
89 }
90 }
91 if (ro) {
92 fsle->fse.export_flags |= V9FS_RDONLY;
93 } else {
94 fsle->fse.export_flags &= ~V9FS_RDONLY;
95 }
96
97 if (fsle->fse.ops->parse_opts) {
98 if (fsle->fse.ops->parse_opts(opts, &fsle->fse, errp)) {
99 g_free(fsle->fse.fsdev_id);
100 g_free(fsle);
101 return -1;
102 }
103 }
104
105 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
106 return 0;
107 }
108
109 FsDriverEntry *get_fsdev_fsentry(char *id)
110 {
111 if (id) {
112 struct FsDriverListEntry *fsle;
113
114 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
115 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
116 return &fsle->fse;
117 }
118 }
119 }
120 return NULL;
121 }