root / fsdev / qemu-fsdev.c @ 1de7afc9
History | View | Annotate | Download (2.6 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 | 1de7afc9 | Paolo Bonzini | #include "qemu/queue.h" |
17 | 1de7afc9 | Paolo Bonzini | #include "qemu/osdep.h" |
18 | 74db920c | Gautham R Shenoy | #include "qemu-common.h" |
19 | 1de7afc9 | Paolo Bonzini | #include "qemu/config-file.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 | 77eec1b3 | Aneesh Kumar K.V | #ifdef CONFIG_OPEN_BY_HANDLE
|
27 | 5f542225 | Aneesh Kumar K.V | { .name = "handle", .ops = &handle_ops},
|
28 | 77eec1b3 | Aneesh Kumar K.V | #endif
|
29 | 9db221ae | Aneesh Kumar K.V | { .name = "synth", .ops = &synth_ops},
|
30 | 4c793dda | M. Mohan Kumar | { .name = "proxy", .ops = &proxy_ops},
|
31 | 74db920c | Gautham R Shenoy | }; |
32 | 74db920c | Gautham R Shenoy | |
33 | 74db920c | Gautham R Shenoy | int qemu_fsdev_add(QemuOpts *opts)
|
34 | 74db920c | Gautham R Shenoy | { |
35 | 74db920c | Gautham R Shenoy | int i;
|
36 | 99519f0a | Aneesh Kumar K.V | struct FsDriverListEntry *fsle;
|
37 | 9f506893 | Harsh Prateek Bora | const char *fsdev_id = qemu_opts_id(opts); |
38 | fbcbf101 | Aneesh Kumar K.V | const char *fsdriver = qemu_opt_get(opts, "fsdriver"); |
39 | d3ab98e6 | Aneesh Kumar K.V | const char *writeout = qemu_opt_get(opts, "writeout"); |
40 | 2c74c2cb | M. Mohan Kumar | bool ro = qemu_opt_get_bool(opts, "readonly", 0); |
41 | 74db920c | Gautham R Shenoy | |
42 | 9f506893 | Harsh Prateek Bora | if (!fsdev_id) {
|
43 | 74db920c | Gautham R Shenoy | fprintf(stderr, "fsdev: No id specified\n");
|
44 | 74db920c | Gautham R Shenoy | return -1; |
45 | 74db920c | Gautham R Shenoy | } |
46 | 74db920c | Gautham R Shenoy | |
47 | fbcbf101 | Aneesh Kumar K.V | if (fsdriver) {
|
48 | fbcbf101 | Aneesh Kumar K.V | for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) { |
49 | fbcbf101 | Aneesh Kumar K.V | if (strcmp(FsDrivers[i].name, fsdriver) == 0) { |
50 | 9f506893 | Harsh Prateek Bora | break;
|
51 | 9f506893 | Harsh Prateek Bora | } |
52 | 74db920c | Gautham R Shenoy | } |
53 | 74db920c | Gautham R Shenoy | |
54 | fbcbf101 | Aneesh Kumar K.V | if (i == ARRAY_SIZE(FsDrivers)) {
|
55 | fbcbf101 | Aneesh Kumar K.V | fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
|
56 | 9f506893 | Harsh Prateek Bora | return -1; |
57 | 9f506893 | Harsh Prateek Bora | } |
58 | 9f506893 | Harsh Prateek Bora | } else {
|
59 | fbcbf101 | Aneesh Kumar K.V | fprintf(stderr, "fsdev: No fsdriver specified\n");
|
60 | 74db920c | Gautham R Shenoy | return -1; |
61 | 74db920c | Gautham R Shenoy | } |
62 | 74db920c | Gautham R Shenoy | |
63 | 99519f0a | Aneesh Kumar K.V | fsle = g_malloc0(sizeof(*fsle));
|
64 | 7267c094 | Anthony Liguori | fsle->fse.fsdev_id = g_strdup(fsdev_id); |
65 | fbcbf101 | Aneesh Kumar K.V | fsle->fse.ops = FsDrivers[i].ops; |
66 | d3ab98e6 | Aneesh Kumar K.V | if (writeout) {
|
67 | d3ab98e6 | Aneesh Kumar K.V | if (!strcmp(writeout, "immediate")) { |
68 | b97400ca | Aneesh Kumar K.V | fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT; |
69 | d3ab98e6 | Aneesh Kumar K.V | } |
70 | d3ab98e6 | Aneesh Kumar K.V | } |
71 | 2c74c2cb | M. Mohan Kumar | if (ro) {
|
72 | 2c74c2cb | M. Mohan Kumar | fsle->fse.export_flags |= V9FS_RDONLY; |
73 | 2c74c2cb | M. Mohan Kumar | } else {
|
74 | 2c74c2cb | M. Mohan Kumar | fsle->fse.export_flags &= ~V9FS_RDONLY; |
75 | 2c74c2cb | M. Mohan Kumar | } |
76 | b97400ca | Aneesh Kumar K.V | |
77 | 99519f0a | Aneesh Kumar K.V | if (fsle->fse.ops->parse_opts) {
|
78 | 99519f0a | Aneesh Kumar K.V | if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
|
79 | 99519f0a | Aneesh Kumar K.V | return -1; |
80 | 99519f0a | Aneesh Kumar K.V | } |
81 | d9b36a6e | M. Mohan Kumar | } |
82 | d9b36a6e | M. Mohan Kumar | |
83 | fbcbf101 | Aneesh Kumar K.V | QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next); |
84 | 74db920c | Gautham R Shenoy | return 0; |
85 | 74db920c | Gautham R Shenoy | } |
86 | 74db920c | Gautham R Shenoy | |
87 | fbcbf101 | Aneesh Kumar K.V | FsDriverEntry *get_fsdev_fsentry(char *id)
|
88 | 74db920c | Gautham R Shenoy | { |
89 | 9f506893 | Harsh Prateek Bora | if (id) {
|
90 | fbcbf101 | Aneesh Kumar K.V | struct FsDriverListEntry *fsle;
|
91 | 74db920c | Gautham R Shenoy | |
92 | fbcbf101 | Aneesh Kumar K.V | QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { |
93 | 9f506893 | Harsh Prateek Bora | if (strcmp(fsle->fse.fsdev_id, id) == 0) { |
94 | 9f506893 | Harsh Prateek Bora | return &fsle->fse;
|
95 | 9f506893 | Harsh Prateek Bora | } |
96 | 74db920c | Gautham R Shenoy | } |
97 | 74db920c | Gautham R Shenoy | } |
98 | 74db920c | Gautham R Shenoy | return NULL; |
99 | 74db920c | Gautham R Shenoy | } |
100 | 526c5237 | Gerd Hoffmann | |
101 | 526c5237 | Gerd Hoffmann | static void fsdev_register_config(void) |
102 | 526c5237 | Gerd Hoffmann | { |
103 | 526c5237 | Gerd Hoffmann | qemu_add_opts(&qemu_fsdev_opts); |
104 | 526c5237 | Gerd Hoffmann | qemu_add_opts(&qemu_virtfs_opts); |
105 | 526c5237 | Gerd Hoffmann | } |
106 | 526c5237 | Gerd Hoffmann | machine_init(fsdev_register_config); |