blob: 6684f7ea90f886aac26902f507c1a8993bcc1f67 [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.V77eec1b2011-12-04 22:35:27 +053026#ifdef CONFIG_OPEN_BY_HANDLE
Aneesh Kumar K.V5f542222011-08-02 11:35:54 +053027 { .name = "handle", .ops = &handle_ops},
Aneesh Kumar K.V77eec1b2011-12-04 22:35:27 +053028#endif
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +053029 { .name = "synth", .ops = &synth_ops},
Gautham R Shenoy74db9202010-04-29 17:44:43 +053030};
31
32int qemu_fsdev_add(QemuOpts *opts)
33{
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053034 struct FsDriverListEntry *fsle;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053035 int i;
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053036 const char *fsdev_id = qemu_opts_id(opts);
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053037 const char *fsdriver = qemu_opt_get(opts, "fsdriver");
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053038 const char *path = qemu_opt_get(opts, "path");
39 const char *sec_model = qemu_opt_get(opts, "security_model");
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053040 const char *writeout = qemu_opt_get(opts, "writeout");
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053041 bool ro = qemu_opt_get_bool(opts, "readonly", 0);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053042
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053043 if (!fsdev_id) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +053044 fprintf(stderr, "fsdev: No id specified\n");
45 return -1;
46 }
47
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053048 if (fsdriver) {
49 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
50 if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053051 break;
52 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053053 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053054
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053055 if (i == ARRAY_SIZE(FsDrivers)) {
56 fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053057 return -1;
58 }
59 } else {
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053060 fprintf(stderr, "fsdev: No fsdriver specified\n");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053061 return -1;
62 }
63
M. Mohan Kumard9b36a62011-10-14 12:59:37 +053064 if (!strcmp(fsdriver, "local") && !sec_model) {
65 fprintf(stderr, "security model not specified, "
66 "local fs needs security model\nvalid options are:"
67 "\tsecurity_model=[passthrough|mapped|none]\n");
68 return -1;
69 }
70
71 if (strcmp(fsdriver, "local") && sec_model) {
72 fprintf(stderr, "only local fs driver needs security model\n");
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070073 return -1;
74 }
75
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053076 if (!path) {
77 fprintf(stderr, "fsdev: No path specified.\n");
78 return -1;
79 }
80
Anthony Liguori7267c092011-08-20 22:09:37 -050081 fsle = g_malloc(sizeof(*fsle));
Gautham R Shenoy74db9202010-04-29 17:44:43 +053082
Anthony Liguori7267c092011-08-20 22:09:37 -050083 fsle->fse.fsdev_id = g_strdup(fsdev_id);
84 fsle->fse.path = g_strdup(path);
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053085 fsle->fse.ops = FsDrivers[i].ops;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053086 fsle->fse.export_flags = 0;
87 if (writeout) {
88 if (!strcmp(writeout, "immediate")) {
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053089 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053090 }
91 }
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053092 if (ro) {
93 fsle->fse.export_flags |= V9FS_RDONLY;
94 } else {
95 fsle->fse.export_flags &= ~V9FS_RDONLY;
96 }
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053097
M. Mohan Kumard9b36a62011-10-14 12:59:37 +053098 if (strcmp(fsdriver, "local")) {
99 goto done;
100 }
101
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +0530102 if (!strcmp(sec_model, "passthrough")) {
103 fsle->fse.export_flags |= V9FS_SM_PASSTHROUGH;
104 } else if (!strcmp(sec_model, "mapped")) {
105 fsle->fse.export_flags |= V9FS_SM_MAPPED;
106 } else if (!strcmp(sec_model, "none")) {
107 fsle->fse.export_flags |= V9FS_SM_NONE;
108 } else {
M. Mohan Kumard9b36a62011-10-14 12:59:37 +0530109 fprintf(stderr, "Invalid security model %s specified, valid options are"
110 "\n\t [passthrough|mapped|none]\n", sec_model);
111 return -1;
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +0530112 }
M. Mohan Kumard9b36a62011-10-14 12:59:37 +0530113done:
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +0530114 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530115 return 0;
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530116}
117
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +0530118FsDriverEntry *get_fsdev_fsentry(char *id)
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530119{
Harsh Prateek Bora9f506892010-10-18 15:36:36 +0530120 if (id) {
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +0530121 struct FsDriverListEntry *fsle;
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530122
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +0530123 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
Harsh Prateek Bora9f506892010-10-18 15:36:36 +0530124 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
125 return &fsle->fse;
126 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530127 }
128 }
129 return NULL;
130}
Gerd Hoffmann526c5232010-08-25 12:19:49 +0200131
132static void fsdev_register_config(void)
133{
134 qemu_add_opts(&qemu_fsdev_opts);
135 qemu_add_opts(&qemu_virtfs_opts);
136}
137machine_init(fsdev_register_config);
138