4 * Copyright IBM, Corp. 2010
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.
15 #include "qemu-fsdev.h"
16 #include "qemu/queue.h"
17 #include "qemu/osdep.h"
18 #include "qemu-common.h"
19 #include "qemu/config-file.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
},
29 { .name
= "synth", .ops
= &synth_ops
},
30 { .name
= "proxy", .ops
= &proxy_ops
},
33 int qemu_fsdev_add(QemuOpts
*opts
)
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);
43 fprintf(stderr
, "fsdev: No id specified\n");
48 for (i
= 0; i
< ARRAY_SIZE(FsDrivers
); i
++) {
49 if (strcmp(FsDrivers
[i
].name
, fsdriver
) == 0) {
54 if (i
== ARRAY_SIZE(FsDrivers
)) {
55 fprintf(stderr
, "fsdev: fsdriver %s not found\n", fsdriver
);
59 fprintf(stderr
, "fsdev: No fsdriver specified\n");
63 fsle
= g_malloc0(sizeof(*fsle
));
64 fsle
->fse
.fsdev_id
= g_strdup(fsdev_id
);
65 fsle
->fse
.ops
= FsDrivers
[i
].ops
;
67 if (!strcmp(writeout
, "immediate")) {
68 fsle
->fse
.export_flags
|= V9FS_IMMEDIATE_WRITEOUT
;
72 fsle
->fse
.export_flags
|= V9FS_RDONLY
;
74 fsle
->fse
.export_flags
&= ~V9FS_RDONLY
;
77 if (fsle
->fse
.ops
->parse_opts
) {
78 if (fsle
->fse
.ops
->parse_opts(opts
, &fsle
->fse
)) {
83 QTAILQ_INSERT_TAIL(&fsdriver_entries
, fsle
, next
);
87 FsDriverEntry
*get_fsdev_fsentry(char *id
)
90 struct FsDriverListEntry
*fsle
;
92 QTAILQ_FOREACH(fsle
, &fsdriver_entries
, next
) {
93 if (strcmp(fsle
->fse
.fsdev_id
, id
) == 0) {