blob: 8a4afbffbd3ff1f4d35b259e2d3a2d592575d914 [file] [log] [blame]
Gautham R Shenoy74db9202010-04-29 17:44:43 +05301/*
Greg Kurzaf8b38b2016-06-06 11:52:34 +02002 * 9p
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303 *
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.
Gautham R Shenoy74db9202010-04-29 17:44:43 +053011 */
Markus Armbrustere688df62018-02-01 12:18:31 +010012
Peter Maydellfbc04122016-01-26 18:17:10 +000013#include "qemu/osdep.h"
Markus Armbrustere688df62018-02-01 12:18:31 +010014#include "qapi/error.h"
Gautham R Shenoy74db9202010-04-29 17:44:43 +053015#include "qemu-fsdev.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010016#include "qemu/queue.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010017#include "qemu/config-file.h"
Greg Kurzea753f32016-01-22 15:12:18 +010018#include "qemu/error-report.h"
Markus Armbruster922a01a2018-02-01 12:18:46 +010019#include "qemu/option.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},
M. Mohan Kumar4c793dd2011-12-14 13:49:28 +053030 { .name = "proxy", .ops = &proxy_ops},
Gautham R Shenoy74db9202010-04-29 17:44:43 +053031};
32
33int qemu_fsdev_add(QemuOpts *opts)
34{
Gautham R Shenoy74db9202010-04-29 17:44:43 +053035 int i;
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053036 struct FsDriverListEntry *fsle;
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053037 const char *fsdev_id = qemu_opts_id(opts);
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053038 const char *fsdriver = qemu_opt_get(opts, "fsdriver");
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053039 const char *writeout = qemu_opt_get(opts, "writeout");
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053040 bool ro = qemu_opt_get_bool(opts, "readonly", 0);
Greg Kurz91cda4e2018-01-08 11:18:23 +010041 Error *local_err = NULL;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053042
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053043 if (!fsdev_id) {
Greg Kurzea753f32016-01-22 15:12:18 +010044 error_report("fsdev: No id specified");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053045 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)) {
Greg Kurzea753f32016-01-22 15:12:18 +010056 error_report("fsdev: fsdriver %s not found", fsdriver);
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053057 return -1;
58 }
59 } else {
Greg Kurzea753f32016-01-22 15:12:18 +010060 error_report("fsdev: No fsdriver specified");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053061 return -1;
62 }
63
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053064 fsle = g_malloc0(sizeof(*fsle));
Anthony Liguori7267c092011-08-20 22:09:37 -050065 fsle->fse.fsdev_id = g_strdup(fsdev_id);
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053066 fsle->fse.ops = FsDrivers[i].ops;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053067 if (writeout) {
68 if (!strcmp(writeout, "immediate")) {
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053069 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053070 }
71 }
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053072 if (ro) {
73 fsle->fse.export_flags |= V9FS_RDONLY;
74 } else {
75 fsle->fse.export_flags &= ~V9FS_RDONLY;
76 }
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053077
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053078 if (fsle->fse.ops->parse_opts) {
Greg Kurz91cda4e2018-01-08 11:18:23 +010079 if (fsle->fse.ops->parse_opts(opts, &fsle->fse, &local_err)) {
80 error_report_err(local_err);
Stefan Weilb58c86e2013-06-16 12:02:40 +020081 g_free(fsle->fse.fsdev_id);
82 g_free(fsle);
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053083 return -1;
84 }
M. Mohan Kumard9b36a62011-10-14 12:59:37 +053085 }
86
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053087 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053088 return 0;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053089}
90
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053091FsDriverEntry *get_fsdev_fsentry(char *id)
Gautham R Shenoy74db9202010-04-29 17:44:43 +053092{
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053093 if (id) {
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053094 struct FsDriverListEntry *fsle;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053095
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053096 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053097 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
98 return &fsle->fse;
99 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530100 }
101 }
102 return NULL;
103}