blob: 5977bcca4cf4e83a67ad90509d78824c1ac6d0fd [file] [log] [blame]
Gautham R Shenoy74db9202010-04-29 17:44:43 +05301/*
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"
Gerd Hoffmann526c5232010-08-25 12:19:49 +020019#include "qemu-config.h"
Gautham R Shenoy74db9202010-04-29 17:44:43 +053020
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053021static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
22 QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053023
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053024static FsDriverTable FsDrivers[] = {
Anthony Liguori9f107512010-04-29 17:44:44 +053025 { .name = "local", .ops = &local_ops},
Aneesh Kumar K.V5f542222011-08-02 11:35:54 +053026 { .name = "handle", .ops = &handle_ops},
Gautham R Shenoy74db9202010-04-29 17:44:43 +053027};
28
29int qemu_fsdev_add(QemuOpts *opts)
30{
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053031 struct FsDriverListEntry *fsle;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053032 int i;
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053033 const char *fsdev_id = qemu_opts_id(opts);
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053034 const char *fsdriver = qemu_opt_get(opts, "fsdriver");
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053035 const char *path = qemu_opt_get(opts, "path");
36 const char *sec_model = qemu_opt_get(opts, "security_model");
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053037 const char *writeout = qemu_opt_get(opts, "writeout");
38
Gautham R Shenoy74db9202010-04-29 17:44:43 +053039
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053040 if (!fsdev_id) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +053041 fprintf(stderr, "fsdev: No id specified\n");
42 return -1;
43 }
44
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053045 if (fsdriver) {
46 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
47 if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053048 break;
49 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053050 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053051
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053052 if (i == ARRAY_SIZE(FsDrivers)) {
53 fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053054 return -1;
55 }
56 } else {
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053057 fprintf(stderr, "fsdev: No fsdriver specified\n");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053058 return -1;
59 }
60
M. Mohan Kumard9b36a62011-10-14 12:59:37 +053061 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;
66 }
67
68 if (strcmp(fsdriver, "local") && sec_model) {
69 fprintf(stderr, "only local fs driver needs security model\n");
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070070 return -1;
71 }
72
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053073 if (!path) {
74 fprintf(stderr, "fsdev: No path specified.\n");
75 return -1;
76 }
77
Anthony Liguori7267c092011-08-20 22:09:37 -050078 fsle = g_malloc(sizeof(*fsle));
Gautham R Shenoy74db9202010-04-29 17:44:43 +053079
Anthony Liguori7267c092011-08-20 22:09:37 -050080 fsle->fse.fsdev_id = g_strdup(fsdev_id);
81 fsle->fse.path = g_strdup(path);
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053082 fsle->fse.ops = FsDrivers[i].ops;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053083 fsle->fse.export_flags = 0;
84 if (writeout) {
85 if (!strcmp(writeout, "immediate")) {
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053086 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053087 }
88 }
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053089
M. Mohan Kumard9b36a62011-10-14 12:59:37 +053090 if (strcmp(fsdriver, "local")) {
91 goto done;
92 }
93
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053094 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 {
M. Mohan Kumard9b36a62011-10-14 12:59:37 +0530101 fprintf(stderr, "Invalid security model %s specified, valid options are"
102 "\n\t [passthrough|mapped|none]\n", sec_model);
103 return -1;
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +0530104 }
M. Mohan Kumard9b36a62011-10-14 12:59:37 +0530105done:
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +0530106 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530107 return 0;
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530108}
109
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +0530110FsDriverEntry *get_fsdev_fsentry(char *id)
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530111{
Harsh Prateek Bora9f506892010-10-18 15:36:36 +0530112 if (id) {
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +0530113 struct FsDriverListEntry *fsle;
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530114
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +0530115 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
Harsh Prateek Bora9f506892010-10-18 15:36:36 +0530116 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
117 return &fsle->fse;
118 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530119 }
120 }
121 return NULL;
122}
Gerd Hoffmann526c5232010-08-25 12:19:49 +0200123
124static void fsdev_register_config(void)
125{
126 qemu_add_opts(&qemu_fsdev_opts);
127 qemu_add_opts(&qemu_virtfs_opts);
128}
129machine_init(fsdev_register_config);
130