]>
Commit | Line | Data |
---|---|---|
74db920c GS |
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" | |
526c5237 | 19 | #include "qemu-config.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}, |
5f542225 | 26 | { .name = "handle", .ops = &handle_ops}, |
9db221ae | 27 | { .name = "synth", .ops = &synth_ops}, |
74db920c GS |
28 | }; |
29 | ||
30 | int qemu_fsdev_add(QemuOpts *opts) | |
31 | { | |
fbcbf101 | 32 | struct FsDriverListEntry *fsle; |
74db920c | 33 | int i; |
9f506893 | 34 | const char *fsdev_id = qemu_opts_id(opts); |
fbcbf101 | 35 | const char *fsdriver = qemu_opt_get(opts, "fsdriver"); |
9f506893 HPB |
36 | const char *path = qemu_opt_get(opts, "path"); |
37 | const char *sec_model = qemu_opt_get(opts, "security_model"); | |
d3ab98e6 | 38 | const char *writeout = qemu_opt_get(opts, "writeout"); |
2c74c2cb | 39 | bool ro = qemu_opt_get_bool(opts, "readonly", 0); |
74db920c | 40 | |
9f506893 | 41 | if (!fsdev_id) { |
74db920c GS |
42 | fprintf(stderr, "fsdev: No id specified\n"); |
43 | return -1; | |
44 | } | |
45 | ||
fbcbf101 AK |
46 | if (fsdriver) { |
47 | for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) { | |
48 | if (strcmp(FsDrivers[i].name, fsdriver) == 0) { | |
9f506893 HPB |
49 | break; |
50 | } | |
74db920c | 51 | } |
74db920c | 52 | |
fbcbf101 AK |
53 | if (i == ARRAY_SIZE(FsDrivers)) { |
54 | fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver); | |
9f506893 HPB |
55 | return -1; |
56 | } | |
57 | } else { | |
fbcbf101 | 58 | fprintf(stderr, "fsdev: No fsdriver specified\n"); |
74db920c GS |
59 | return -1; |
60 | } | |
61 | ||
d9b36a6e MK |
62 | if (!strcmp(fsdriver, "local") && !sec_model) { |
63 | fprintf(stderr, "security model not specified, " | |
64 | "local fs needs security model\nvalid options are:" | |
65 | "\tsecurity_model=[passthrough|mapped|none]\n"); | |
66 | return -1; | |
67 | } | |
68 | ||
69 | if (strcmp(fsdriver, "local") && sec_model) { | |
70 | fprintf(stderr, "only local fs driver needs security model\n"); | |
9ce56db6 VJ |
71 | return -1; |
72 | } | |
73 | ||
9f506893 HPB |
74 | if (!path) { |
75 | fprintf(stderr, "fsdev: No path specified.\n"); | |
76 | return -1; | |
77 | } | |
78 | ||
7267c094 | 79 | fsle = g_malloc(sizeof(*fsle)); |
74db920c | 80 | |
7267c094 AL |
81 | fsle->fse.fsdev_id = g_strdup(fsdev_id); |
82 | fsle->fse.path = g_strdup(path); | |
fbcbf101 | 83 | fsle->fse.ops = FsDrivers[i].ops; |
d3ab98e6 AK |
84 | fsle->fse.export_flags = 0; |
85 | if (writeout) { | |
86 | if (!strcmp(writeout, "immediate")) { | |
b97400ca | 87 | fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT; |
d3ab98e6 AK |
88 | } |
89 | } | |
2c74c2cb MK |
90 | if (ro) { |
91 | fsle->fse.export_flags |= V9FS_RDONLY; | |
92 | } else { | |
93 | fsle->fse.export_flags &= ~V9FS_RDONLY; | |
94 | } | |
b97400ca | 95 | |
d9b36a6e MK |
96 | if (strcmp(fsdriver, "local")) { |
97 | goto done; | |
98 | } | |
99 | ||
b97400ca AK |
100 | if (!strcmp(sec_model, "passthrough")) { |
101 | fsle->fse.export_flags |= V9FS_SM_PASSTHROUGH; | |
102 | } else if (!strcmp(sec_model, "mapped")) { | |
103 | fsle->fse.export_flags |= V9FS_SM_MAPPED; | |
104 | } else if (!strcmp(sec_model, "none")) { | |
105 | fsle->fse.export_flags |= V9FS_SM_NONE; | |
106 | } else { | |
d9b36a6e MK |
107 | fprintf(stderr, "Invalid security model %s specified, valid options are" |
108 | "\n\t [passthrough|mapped|none]\n", sec_model); | |
109 | return -1; | |
b97400ca | 110 | } |
d9b36a6e | 111 | done: |
fbcbf101 | 112 | QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next); |
74db920c | 113 | return 0; |
74db920c GS |
114 | } |
115 | ||
fbcbf101 | 116 | FsDriverEntry *get_fsdev_fsentry(char *id) |
74db920c | 117 | { |
9f506893 | 118 | if (id) { |
fbcbf101 | 119 | struct FsDriverListEntry *fsle; |
74db920c | 120 | |
fbcbf101 | 121 | QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { |
9f506893 HPB |
122 | if (strcmp(fsle->fse.fsdev_id, id) == 0) { |
123 | return &fsle->fse; | |
124 | } | |
74db920c GS |
125 | } |
126 | } | |
127 | return NULL; | |
128 | } | |
526c5237 GH |
129 | |
130 | static void fsdev_register_config(void) | |
131 | { | |
132 | qemu_add_opts(&qemu_fsdev_opts); | |
133 | qemu_add_opts(&qemu_virtfs_opts); | |
134 | } | |
135 | machine_init(fsdev_register_config); | |
136 |