]> git.proxmox.com Git - mirror_qemu.git/blob - fsdev/qemu-fsdev.c
hw/9pfs: Move opt validation to FsDriver callback
[mirror_qemu.git] / fsdev / qemu-fsdev.c
1 /*
2 * Virtio 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 <stdio.h>
14 #include <string.h>
15 #include "qemu-fsdev.h"
16 #include "qemu-queue.h"
17 #include "osdep.h"
18 #include "qemu-common.h"
19 #include "qemu-config.h"
20
21 static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
22 QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
23
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 };
31
32 int qemu_fsdev_add(QemuOpts *opts)
33 {
34 int i;
35 struct FsDriverListEntry *fsle;
36 const char *fsdev_id = qemu_opts_id(opts);
37 const char *fsdriver = qemu_opt_get(opts, "fsdriver");
38 const char *writeout = qemu_opt_get(opts, "writeout");
39 bool ro = qemu_opt_get_bool(opts, "readonly", 0);
40
41 if (!fsdev_id) {
42 fprintf(stderr, "fsdev: No id specified\n");
43 return -1;
44 }
45
46 if (fsdriver) {
47 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
48 if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
49 break;
50 }
51 }
52
53 if (i == ARRAY_SIZE(FsDrivers)) {
54 fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
55 return -1;
56 }
57 } else {
58 fprintf(stderr, "fsdev: No fsdriver specified\n");
59 return -1;
60 }
61
62 fsle = g_malloc0(sizeof(*fsle));
63 fsle->fse.fsdev_id = g_strdup(fsdev_id);
64 fsle->fse.ops = FsDrivers[i].ops;
65 if (writeout) {
66 if (!strcmp(writeout, "immediate")) {
67 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
68 }
69 }
70 if (ro) {
71 fsle->fse.export_flags |= V9FS_RDONLY;
72 } else {
73 fsle->fse.export_flags &= ~V9FS_RDONLY;
74 }
75
76 if (fsle->fse.ops->parse_opts) {
77 if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
78 return -1;
79 }
80 }
81
82 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
83 return 0;
84 }
85
86 FsDriverEntry *get_fsdev_fsentry(char *id)
87 {
88 if (id) {
89 struct FsDriverListEntry *fsle;
90
91 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
92 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
93 return &fsle->fse;
94 }
95 }
96 }
97 return NULL;
98 }
99
100 static void fsdev_register_config(void)
101 {
102 qemu_add_opts(&qemu_fsdev_opts);
103 qemu_add_opts(&qemu_virtfs_opts);
104 }
105 machine_init(fsdev_register_config);
106