block: add bdrv_co_discard and bdrv_aio_discard support
[qemu.git] / fsdev / qemu-fsdev.c
blob5977bcca4cf4e83a67ad90509d78824c1ac6d0fd
1 /*
2 * Virtio 9p
4 * Copyright IBM, Corp. 2010
6 * Authors:
7 * Gautham R Shenoy <ego@in.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
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"
21 static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
22 QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
24 static FsDriverTable FsDrivers[] = {
25 { .name = "local", .ops = &local_ops},
26 { .name = "handle", .ops = &handle_ops},
29 int qemu_fsdev_add(QemuOpts *opts)
31 struct FsDriverListEntry *fsle;
32 int i;
33 const char *fsdev_id = qemu_opts_id(opts);
34 const char *fsdriver = qemu_opt_get(opts, "fsdriver");
35 const char *path = qemu_opt_get(opts, "path");
36 const char *sec_model = qemu_opt_get(opts, "security_model");
37 const char *writeout = qemu_opt_get(opts, "writeout");
40 if (!fsdev_id) {
41 fprintf(stderr, "fsdev: No id specified\n");
42 return -1;
45 if (fsdriver) {
46 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
47 if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
48 break;
52 if (i == ARRAY_SIZE(FsDrivers)) {
53 fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
54 return -1;
56 } else {
57 fprintf(stderr, "fsdev: No fsdriver specified\n");
58 return -1;
61 if (!strcmp(fsdriver, "local") && !sec_model) {
62 fprintf(stderr, "security model not specified, "
63 "local fs needs security model\nvalid options are:"
64 "\tsecurity_model=[passthrough|mapped|none]\n");
65 return -1;
68 if (strcmp(fsdriver, "local") && sec_model) {
69 fprintf(stderr, "only local fs driver needs security model\n");
70 return -1;
73 if (!path) {
74 fprintf(stderr, "fsdev: No path specified.\n");
75 return -1;
78 fsle = g_malloc(sizeof(*fsle));
80 fsle->fse.fsdev_id = g_strdup(fsdev_id);
81 fsle->fse.path = g_strdup(path);
82 fsle->fse.ops = FsDrivers[i].ops;
83 fsle->fse.export_flags = 0;
84 if (writeout) {
85 if (!strcmp(writeout, "immediate")) {
86 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
90 if (strcmp(fsdriver, "local")) {
91 goto done;
94 if (!strcmp(sec_model, "passthrough")) {
95 fsle->fse.export_flags |= V9FS_SM_PASSTHROUGH;
96 } else if (!strcmp(sec_model, "mapped")) {
97 fsle->fse.export_flags |= V9FS_SM_MAPPED;
98 } else if (!strcmp(sec_model, "none")) {
99 fsle->fse.export_flags |= V9FS_SM_NONE;
100 } else {
101 fprintf(stderr, "Invalid security model %s specified, valid options are"
102 "\n\t [passthrough|mapped|none]\n", sec_model);
103 return -1;
105 done:
106 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
107 return 0;
110 FsDriverEntry *get_fsdev_fsentry(char *id)
112 if (id) {
113 struct FsDriverListEntry *fsle;
115 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
116 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
117 return &fsle->fse;
121 return NULL;
124 static void fsdev_register_config(void)
126 qemu_add_opts(&qemu_fsdev_opts);
127 qemu_add_opts(&qemu_virtfs_opts);
129 machine_init(fsdev_register_config);