root / fsdev / qemu-fsdev.c @ 7fc7e584
History | View | Annotate | Download (3.4 kB)
1 | 74db920c | Gautham R Shenoy | /*
|
---|---|---|---|
2 | 74db920c | Gautham R Shenoy | * Virtio 9p
|
3 | 74db920c | Gautham R Shenoy | *
|
4 | 74db920c | Gautham R Shenoy | * Copyright IBM, Corp. 2010
|
5 | 74db920c | Gautham R Shenoy | *
|
6 | 74db920c | Gautham R Shenoy | * Authors:
|
7 | 74db920c | Gautham R Shenoy | * Gautham R Shenoy <ego@in.ibm.com>
|
8 | 74db920c | Gautham R Shenoy | *
|
9 | 74db920c | Gautham R Shenoy | * This work is licensed under the terms of the GNU GPL, version 2. See
|
10 | 74db920c | Gautham R Shenoy | * the COPYING file in the top-level directory.
|
11 | 74db920c | Gautham R Shenoy | *
|
12 | 74db920c | Gautham R Shenoy | */
|
13 | 74db920c | Gautham R Shenoy | #include <stdio.h> |
14 | 74db920c | Gautham R Shenoy | #include <string.h> |
15 | 74db920c | Gautham R Shenoy | #include "qemu-fsdev.h" |
16 | 74db920c | Gautham R Shenoy | #include "qemu-queue.h" |
17 | 74db920c | Gautham R Shenoy | #include "osdep.h" |
18 | 74db920c | Gautham R Shenoy | #include "qemu-common.h" |
19 | 526c5237 | Gerd Hoffmann | #include "qemu-config.h" |
20 | 74db920c | Gautham R Shenoy | |
21 | fbcbf101 | Aneesh Kumar K.V | static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
|
22 | fbcbf101 | Aneesh Kumar K.V | QTAILQ_HEAD_INITIALIZER(fsdriver_entries); |
23 | 74db920c | Gautham R Shenoy | |
24 | fbcbf101 | Aneesh Kumar K.V | static FsDriverTable FsDrivers[] = {
|
25 | 9f107513 | Anthony Liguori | { .name = "local", .ops = &local_ops},
|
26 | 5f542225 | Aneesh Kumar K.V | { .name = "handle", .ops = &handle_ops},
|
27 | 74db920c | Gautham R Shenoy | }; |
28 | 74db920c | Gautham R Shenoy | |
29 | 74db920c | Gautham R Shenoy | int qemu_fsdev_add(QemuOpts *opts)
|
30 | 74db920c | Gautham R Shenoy | { |
31 | fbcbf101 | Aneesh Kumar K.V | struct FsDriverListEntry *fsle;
|
32 | 74db920c | Gautham R Shenoy | int i;
|
33 | 9f506893 | Harsh Prateek Bora | const char *fsdev_id = qemu_opts_id(opts); |
34 | fbcbf101 | Aneesh Kumar K.V | const char *fsdriver = qemu_opt_get(opts, "fsdriver"); |
35 | 9f506893 | Harsh Prateek Bora | const char *path = qemu_opt_get(opts, "path"); |
36 | 9f506893 | Harsh Prateek Bora | const char *sec_model = qemu_opt_get(opts, "security_model"); |
37 | d3ab98e6 | Aneesh Kumar K.V | const char *writeout = qemu_opt_get(opts, "writeout"); |
38 | d3ab98e6 | Aneesh Kumar K.V | |
39 | 74db920c | Gautham R Shenoy | |
40 | 9f506893 | Harsh Prateek Bora | if (!fsdev_id) {
|
41 | 74db920c | Gautham R Shenoy | fprintf(stderr, "fsdev: No id specified\n");
|
42 | 74db920c | Gautham R Shenoy | return -1; |
43 | 74db920c | Gautham R Shenoy | } |
44 | 74db920c | Gautham R Shenoy | |
45 | fbcbf101 | Aneesh Kumar K.V | if (fsdriver) {
|
46 | fbcbf101 | Aneesh Kumar K.V | for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) { |
47 | fbcbf101 | Aneesh Kumar K.V | if (strcmp(FsDrivers[i].name, fsdriver) == 0) { |
48 | 9f506893 | Harsh Prateek Bora | break;
|
49 | 9f506893 | Harsh Prateek Bora | } |
50 | 74db920c | Gautham R Shenoy | } |
51 | 74db920c | Gautham R Shenoy | |
52 | fbcbf101 | Aneesh Kumar K.V | if (i == ARRAY_SIZE(FsDrivers)) {
|
53 | fbcbf101 | Aneesh Kumar K.V | fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
|
54 | 9f506893 | Harsh Prateek Bora | return -1; |
55 | 9f506893 | Harsh Prateek Bora | } |
56 | 9f506893 | Harsh Prateek Bora | } else {
|
57 | fbcbf101 | Aneesh Kumar K.V | fprintf(stderr, "fsdev: No fsdriver specified\n");
|
58 | 74db920c | Gautham R Shenoy | return -1; |
59 | 74db920c | Gautham R Shenoy | } |
60 | 74db920c | Gautham R Shenoy | |
61 | d9b36a6e | M. Mohan Kumar | if (!strcmp(fsdriver, "local") && !sec_model) { |
62 | d9b36a6e | M. Mohan Kumar | fprintf(stderr, "security model not specified, "
|
63 | d9b36a6e | M. Mohan Kumar | "local fs needs security model\nvalid options are:"
|
64 | d9b36a6e | M. Mohan Kumar | "\tsecurity_model=[passthrough|mapped|none]\n");
|
65 | d9b36a6e | M. Mohan Kumar | return -1; |
66 | d9b36a6e | M. Mohan Kumar | } |
67 | d9b36a6e | M. Mohan Kumar | |
68 | d9b36a6e | M. Mohan Kumar | if (strcmp(fsdriver, "local") && sec_model) { |
69 | d9b36a6e | M. Mohan Kumar | fprintf(stderr, "only local fs driver needs security model\n");
|
70 | 9ce56db6 | Venkateswararao Jujjuri (JV) | return -1; |
71 | 9ce56db6 | Venkateswararao Jujjuri (JV) | } |
72 | 9ce56db6 | Venkateswararao Jujjuri (JV) | |
73 | 9f506893 | Harsh Prateek Bora | if (!path) {
|
74 | 9f506893 | Harsh Prateek Bora | fprintf(stderr, "fsdev: No path specified.\n");
|
75 | 9f506893 | Harsh Prateek Bora | return -1; |
76 | 9f506893 | Harsh Prateek Bora | } |
77 | 9f506893 | Harsh Prateek Bora | |
78 | 7267c094 | Anthony Liguori | fsle = g_malloc(sizeof(*fsle));
|
79 | 74db920c | Gautham R Shenoy | |
80 | 7267c094 | Anthony Liguori | fsle->fse.fsdev_id = g_strdup(fsdev_id); |
81 | 7267c094 | Anthony Liguori | fsle->fse.path = g_strdup(path); |
82 | fbcbf101 | Aneesh Kumar K.V | fsle->fse.ops = FsDrivers[i].ops; |
83 | d3ab98e6 | Aneesh Kumar K.V | fsle->fse.export_flags = 0;
|
84 | d3ab98e6 | Aneesh Kumar K.V | if (writeout) {
|
85 | d3ab98e6 | Aneesh Kumar K.V | if (!strcmp(writeout, "immediate")) { |
86 | b97400ca | Aneesh Kumar K.V | fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT; |
87 | d3ab98e6 | Aneesh Kumar K.V | } |
88 | d3ab98e6 | Aneesh Kumar K.V | } |
89 | b97400ca | Aneesh Kumar K.V | |
90 | d9b36a6e | M. Mohan Kumar | if (strcmp(fsdriver, "local")) { |
91 | d9b36a6e | M. Mohan Kumar | goto done;
|
92 | d9b36a6e | M. Mohan Kumar | } |
93 | d9b36a6e | M. Mohan Kumar | |
94 | b97400ca | Aneesh Kumar K.V | if (!strcmp(sec_model, "passthrough")) { |
95 | b97400ca | Aneesh Kumar K.V | fsle->fse.export_flags |= V9FS_SM_PASSTHROUGH; |
96 | b97400ca | Aneesh Kumar K.V | } else if (!strcmp(sec_model, "mapped")) { |
97 | b97400ca | Aneesh Kumar K.V | fsle->fse.export_flags |= V9FS_SM_MAPPED; |
98 | b97400ca | Aneesh Kumar K.V | } else if (!strcmp(sec_model, "none")) { |
99 | b97400ca | Aneesh Kumar K.V | fsle->fse.export_flags |= V9FS_SM_NONE; |
100 | b97400ca | Aneesh Kumar K.V | } else {
|
101 | d9b36a6e | M. Mohan Kumar | fprintf(stderr, "Invalid security model %s specified, valid options are"
|
102 | d9b36a6e | M. Mohan Kumar | "\n\t [passthrough|mapped|none]\n", sec_model);
|
103 | d9b36a6e | M. Mohan Kumar | return -1; |
104 | b97400ca | Aneesh Kumar K.V | } |
105 | d9b36a6e | M. Mohan Kumar | done:
|
106 | fbcbf101 | Aneesh Kumar K.V | QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next); |
107 | 74db920c | Gautham R Shenoy | return 0; |
108 | 74db920c | Gautham R Shenoy | } |
109 | 74db920c | Gautham R Shenoy | |
110 | fbcbf101 | Aneesh Kumar K.V | FsDriverEntry *get_fsdev_fsentry(char *id)
|
111 | 74db920c | Gautham R Shenoy | { |
112 | 9f506893 | Harsh Prateek Bora | if (id) {
|
113 | fbcbf101 | Aneesh Kumar K.V | struct FsDriverListEntry *fsle;
|
114 | 74db920c | Gautham R Shenoy | |
115 | fbcbf101 | Aneesh Kumar K.V | QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { |
116 | 9f506893 | Harsh Prateek Bora | if (strcmp(fsle->fse.fsdev_id, id) == 0) { |
117 | 9f506893 | Harsh Prateek Bora | return &fsle->fse;
|
118 | 9f506893 | Harsh Prateek Bora | } |
119 | 74db920c | Gautham R Shenoy | } |
120 | 74db920c | Gautham R Shenoy | } |
121 | 74db920c | Gautham R Shenoy | return NULL; |
122 | 74db920c | Gautham R Shenoy | } |
123 | 526c5237 | Gerd Hoffmann | |
124 | 526c5237 | Gerd Hoffmann | static void fsdev_register_config(void) |
125 | 526c5237 | Gerd Hoffmann | { |
126 | 526c5237 | Gerd Hoffmann | qemu_add_opts(&qemu_fsdev_opts); |
127 | 526c5237 | Gerd Hoffmann | qemu_add_opts(&qemu_virtfs_opts); |
128 | 526c5237 | Gerd Hoffmann | } |
129 | 526c5237 | Gerd Hoffmann | machine_init(fsdev_register_config); |