]> Git Repo - qemu.git/blob - fsdev/qemu-fsdev.c
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
[qemu.git] / fsdev / qemu-fsdev.c
1 /*
2  * Virtio 9p
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.
11  *
12  */
13 #include <stdio.h>
14 #include <string.h>
15 #include "qemu-fsdev.h"
16 #include "qemu/queue.h"
17 #include "qemu/osdep.h"
18 #include "qemu-common.h"
19 #include "qemu/config-file.h"
20 #include "qemu/error-report.h"
21
22 static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
23     QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
24
25 static FsDriverTable FsDrivers[] = {
26     { .name = "local", .ops = &local_ops},
27 #ifdef CONFIG_OPEN_BY_HANDLE
28     { .name = "handle", .ops = &handle_ops},
29 #endif
30     { .name = "synth", .ops = &synth_ops},
31     { .name = "proxy", .ops = &proxy_ops},
32 };
33
34 int qemu_fsdev_add(QemuOpts *opts)
35 {
36     int i;
37     struct FsDriverListEntry *fsle;
38     const char *fsdev_id = qemu_opts_id(opts);
39     const char *fsdriver = qemu_opt_get(opts, "fsdriver");
40     const char *writeout = qemu_opt_get(opts, "writeout");
41     bool ro = qemu_opt_get_bool(opts, "readonly", 0);
42
43     if (!fsdev_id) {
44         error_report("fsdev: No id specified");
45         return -1;
46     }
47
48     if (fsdriver) {
49         for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
50             if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
51                 break;
52             }
53         }
54
55         if (i == ARRAY_SIZE(FsDrivers)) {
56             error_report("fsdev: fsdriver %s not found", fsdriver);
57             return -1;
58         }
59     } else {
60         error_report("fsdev: No fsdriver specified");
61         return -1;
62     }
63
64     fsle = g_malloc0(sizeof(*fsle));
65     fsle->fse.fsdev_id = g_strdup(fsdev_id);
66     fsle->fse.ops = FsDrivers[i].ops;
67     if (writeout) {
68         if (!strcmp(writeout, "immediate")) {
69             fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
70         }
71     }
72     if (ro) {
73         fsle->fse.export_flags |= V9FS_RDONLY;
74     } else {
75         fsle->fse.export_flags &= ~V9FS_RDONLY;
76     }
77
78     if (fsle->fse.ops->parse_opts) {
79         if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
80             g_free(fsle->fse.fsdev_id);
81             g_free(fsle);
82             return -1;
83         }
84     }
85
86     QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
87     return 0;
88 }
89
90 FsDriverEntry *get_fsdev_fsentry(char *id)
91 {
92     if (id) {
93         struct FsDriverListEntry *fsle;
94
95         QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
96             if (strcmp(fsle->fse.fsdev_id, id) == 0) {
97                 return &fsle->fse;
98             }
99         }
100     }
101     return NULL;
102 }
This page took 0.031084 seconds and 4 git commands to generate.