]>
Commit | Line | Data |
---|---|---|
74db920c | 1 | /* |
af8b38b0 | 2 | * 9p |
74db920c GS |
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. | |
74db920c | 11 | */ |
e688df6b | 12 | |
fbc04127 | 13 | #include "qemu/osdep.h" |
e688df6b | 14 | #include "qapi/error.h" |
74db920c | 15 | #include "qemu-fsdev.h" |
1de7afc9 | 16 | #include "qemu/queue.h" |
1de7afc9 | 17 | #include "qemu/config-file.h" |
ea753f32 | 18 | #include "qemu/error-report.h" |
922a01a0 | 19 | #include "qemu/option.h" |
74db920c | 20 | |
20232435 GK |
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; | |
aee7f3ec | 37 | const char **opts; |
20232435 GK |
38 | } FsDriverTable; |
39 | ||
40 | typedef struct FsDriverListEntry { | |
41 | FsDriverEntry fse; | |
42 | QTAILQ_ENTRY(FsDriverListEntry) next; | |
43 | } FsDriverListEntry; | |
44 | ||
b58deb34 | 45 | static QTAILQ_HEAD(, FsDriverListEntry) fsdriver_entries = |
fbcbf101 | 46 | QTAILQ_HEAD_INITIALIZER(fsdriver_entries); |
74db920c | 47 | |
aee7f3ec GK |
48 | #define COMMON_FS_DRIVER_OPTIONS "id", "fsdriver", "readonly" |
49 | ||
fbcbf101 | 50 | static FsDriverTable FsDrivers[] = { |
aee7f3ec GK |
51 | { |
52 | .name = "local", | |
53 | .ops = &local_ops, | |
54 | .opts = (const char * []) { | |
55 | COMMON_FS_DRIVER_OPTIONS, | |
56 | "security_model", | |
57 | "path", | |
58 | "writeout", | |
59 | "fmode", | |
60 | "dmode", | |
1a6ed33c | 61 | "multidevs", |
aee7f3ec GK |
62 | "throttling.bps-total", |
63 | "throttling.bps-read", | |
64 | "throttling.bps-write", | |
65 | "throttling.iops-total", | |
66 | "throttling.iops-read", | |
67 | "throttling.iops-write", | |
68 | "throttling.bps-total-max", | |
69 | "throttling.bps-read-max", | |
70 | "throttling.bps-write-max", | |
71 | "throttling.iops-total-max", | |
72 | "throttling.iops-read-max", | |
73 | "throttling.iops-write-max", | |
74 | "throttling.bps-total-max-length", | |
75 | "throttling.bps-read-max-length", | |
76 | "throttling.bps-write-max-length", | |
77 | "throttling.iops-total-max-length", | |
78 | "throttling.iops-read-max-length", | |
79 | "throttling.iops-write-max-length", | |
80 | "throttling.iops-size", | |
81 | }, | |
82 | }, | |
83 | { | |
84 | .name = "synth", | |
85 | .ops = &synth_ops, | |
86 | .opts = (const char * []) { | |
87 | COMMON_FS_DRIVER_OPTIONS, | |
88 | }, | |
89 | }, | |
90 | { | |
91 | .name = "proxy", | |
92 | .ops = &proxy_ops, | |
93 | .opts = (const char * []) { | |
94 | COMMON_FS_DRIVER_OPTIONS, | |
95 | "socket", | |
96 | "sock_fd", | |
97 | "writeout", | |
98 | }, | |
99 | }, | |
74db920c GS |
100 | }; |
101 | ||
aee7f3ec GK |
102 | static int validate_opt(void *opaque, const char *name, const char *value, |
103 | Error **errp) | |
104 | { | |
105 | FsDriverTable *drv = opaque; | |
106 | const char **opt; | |
107 | ||
108 | for (opt = drv->opts; *opt; opt++) { | |
109 | if (!strcmp(*opt, name)) { | |
110 | return 0; | |
111 | } | |
112 | } | |
113 | ||
114 | error_setg(errp, "'%s' is invalid for fsdriver '%s'", name, drv->name); | |
115 | return -1; | |
116 | } | |
117 | ||
b836723d | 118 | int qemu_fsdev_add(QemuOpts *opts, Error **errp) |
74db920c | 119 | { |
74db920c | 120 | int i; |
99519f0a | 121 | struct FsDriverListEntry *fsle; |
9f506893 | 122 | const char *fsdev_id = qemu_opts_id(opts); |
fbcbf101 | 123 | const char *fsdriver = qemu_opt_get(opts, "fsdriver"); |
d3ab98e6 | 124 | const char *writeout = qemu_opt_get(opts, "writeout"); |
2c74c2cb | 125 | bool ro = qemu_opt_get_bool(opts, "readonly", 0); |
74db920c | 126 | |
9f506893 | 127 | if (!fsdev_id) { |
b836723d | 128 | error_setg(errp, "fsdev: No id specified"); |
74db920c GS |
129 | return -1; |
130 | } | |
131 | ||
fbcbf101 AK |
132 | if (fsdriver) { |
133 | for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) { | |
134 | if (strcmp(FsDrivers[i].name, fsdriver) == 0) { | |
9f506893 HPB |
135 | break; |
136 | } | |
74db920c | 137 | } |
74db920c | 138 | |
fbcbf101 | 139 | if (i == ARRAY_SIZE(FsDrivers)) { |
b836723d | 140 | error_setg(errp, "fsdev: fsdriver %s not found", fsdriver); |
9f506893 HPB |
141 | return -1; |
142 | } | |
143 | } else { | |
b836723d | 144 | error_setg(errp, "fsdev: No fsdriver specified"); |
74db920c GS |
145 | return -1; |
146 | } | |
147 | ||
aee7f3ec GK |
148 | if (qemu_opt_foreach(opts, validate_opt, &FsDrivers[i], errp)) { |
149 | return -1; | |
150 | } | |
151 | ||
99519f0a | 152 | fsle = g_malloc0(sizeof(*fsle)); |
7267c094 | 153 | fsle->fse.fsdev_id = g_strdup(fsdev_id); |
fbcbf101 | 154 | fsle->fse.ops = FsDrivers[i].ops; |
d3ab98e6 AK |
155 | if (writeout) { |
156 | if (!strcmp(writeout, "immediate")) { | |
b97400ca | 157 | fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT; |
d3ab98e6 AK |
158 | } |
159 | } | |
2c74c2cb MK |
160 | if (ro) { |
161 | fsle->fse.export_flags |= V9FS_RDONLY; | |
162 | } else { | |
163 | fsle->fse.export_flags &= ~V9FS_RDONLY; | |
164 | } | |
b97400ca | 165 | |
99519f0a | 166 | if (fsle->fse.ops->parse_opts) { |
b836723d | 167 | if (fsle->fse.ops->parse_opts(opts, &fsle->fse, errp)) { |
b58c86e1 SW |
168 | g_free(fsle->fse.fsdev_id); |
169 | g_free(fsle); | |
99519f0a AK |
170 | return -1; |
171 | } | |
d9b36a6e MK |
172 | } |
173 | ||
fbcbf101 | 174 | QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next); |
74db920c | 175 | return 0; |
74db920c GS |
176 | } |
177 | ||
fbcbf101 | 178 | FsDriverEntry *get_fsdev_fsentry(char *id) |
74db920c | 179 | { |
9f506893 | 180 | if (id) { |
fbcbf101 | 181 | struct FsDriverListEntry *fsle; |
74db920c | 182 | |
fbcbf101 | 183 | QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { |
9f506893 HPB |
184 | if (strcmp(fsle->fse.fsdev_id, id) == 0) { |
185 | return &fsle->fse; | |
186 | } | |
74db920c GS |
187 | } |
188 | } | |
189 | return NULL; | |
190 | } |