]>
Commit | Line | Data |
---|---|---|
74db920c | 1 | /* |
af8b38b0 | 2 | * 9p |
74db920c GS |
3 | * |
4 | * Copyright IBM, Corp. 2010 | |
5 | * | |
6 | * Authors: | |
7 | * Gautham R Shenoy <[email protected]> | |
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 | |
fbcbf101 AK |
21 | static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries = |
22 | QTAILQ_HEAD_INITIALIZER(fsdriver_entries); | |
74db920c | 23 | |
fbcbf101 | 24 | static 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 | ||
33 | int 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); |
91cda4e8 | 41 | Error *local_err = NULL; |
74db920c | 42 | |
9f506893 | 43 | if (!fsdev_id) { |
ea753f32 | 44 | error_report("fsdev: No id specified"); |
74db920c GS |
45 | return -1; |
46 | } | |
47 | ||
fbcbf101 AK |
48 | if (fsdriver) { |
49 | for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) { | |
50 | if (strcmp(FsDrivers[i].name, fsdriver) == 0) { | |
9f506893 HPB |
51 | break; |
52 | } | |
74db920c | 53 | } |
74db920c | 54 | |
fbcbf101 | 55 | if (i == ARRAY_SIZE(FsDrivers)) { |
ea753f32 | 56 | error_report("fsdev: fsdriver %s not found", fsdriver); |
9f506893 HPB |
57 | return -1; |
58 | } | |
59 | } else { | |
ea753f32 | 60 | error_report("fsdev: No fsdriver specified"); |
74db920c GS |
61 | return -1; |
62 | } | |
63 | ||
99519f0a | 64 | fsle = g_malloc0(sizeof(*fsle)); |
7267c094 | 65 | fsle->fse.fsdev_id = g_strdup(fsdev_id); |
fbcbf101 | 66 | fsle->fse.ops = FsDrivers[i].ops; |
d3ab98e6 AK |
67 | if (writeout) { |
68 | if (!strcmp(writeout, "immediate")) { | |
b97400ca | 69 | fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT; |
d3ab98e6 AK |
70 | } |
71 | } | |
2c74c2cb MK |
72 | if (ro) { |
73 | fsle->fse.export_flags |= V9FS_RDONLY; | |
74 | } else { | |
75 | fsle->fse.export_flags &= ~V9FS_RDONLY; | |
76 | } | |
b97400ca | 77 | |
99519f0a | 78 | if (fsle->fse.ops->parse_opts) { |
91cda4e8 GK |
79 | if (fsle->fse.ops->parse_opts(opts, &fsle->fse, &local_err)) { |
80 | error_report_err(local_err); | |
b58c86e1 SW |
81 | g_free(fsle->fse.fsdev_id); |
82 | g_free(fsle); | |
99519f0a AK |
83 | return -1; |
84 | } | |
d9b36a6e MK |
85 | } |
86 | ||
fbcbf101 | 87 | QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next); |
74db920c | 88 | return 0; |
74db920c GS |
89 | } |
90 | ||
fbcbf101 | 91 | FsDriverEntry *get_fsdev_fsentry(char *id) |
74db920c | 92 | { |
9f506893 | 93 | if (id) { |
fbcbf101 | 94 | struct FsDriverListEntry *fsle; |
74db920c | 95 | |
fbcbf101 | 96 | QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { |
9f506893 HPB |
97 | if (strcmp(fsle->fse.fsdev_id, id) == 0) { |
98 | return &fsle->fse; | |
99 | } | |
74db920c GS |
100 | } |
101 | } | |
102 | return NULL; | |
103 | } |