blob: 266e442b871a3afdbeb88d9d77fa4e0442a44af9 [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.
11 *
12 */
Peter Maydellfbc04122016-01-26 18:17:10 +000013#include "qemu/osdep.h"
Gautham R Shenoy74db9202010-04-29 17:44:43 +053014#include "qemu-fsdev.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010015#include "qemu/queue.h"
Gautham R Shenoy74db9202010-04-29 17:44:43 +053016#include "qemu-common.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"
Gautham R Shenoy74db9202010-04-29 17:44:43 +053019
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053020static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
21 QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053022
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053023static FsDriverTable FsDrivers[] = {
Anthony Liguori9f107512010-04-29 17:44:44 +053024 { .name = "local", .ops = &local_ops},
Aneesh Kumar K.V77eec1b2011-12-04 22:35:27 +053025#ifdef CONFIG_OPEN_BY_HANDLE
Aneesh Kumar K.V5f542222011-08-02 11:35:54 +053026 { .name = "handle", .ops = &handle_ops},
Aneesh Kumar K.V77eec1b2011-12-04 22:35:27 +053027#endif
Aneesh Kumar K.V9db221a2011-10-25 12:10:40 +053028 { .name = "synth", .ops = &synth_ops},
M. Mohan Kumar4c793dd2011-12-14 13:49:28 +053029 { .name = "proxy", .ops = &proxy_ops},
Gautham R Shenoy74db9202010-04-29 17:44:43 +053030};
31
32int qemu_fsdev_add(QemuOpts *opts)
33{
Gautham R Shenoy74db9202010-04-29 17:44:43 +053034 int i;
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053035 struct FsDriverListEntry *fsle;
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");
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053038 const char *writeout = qemu_opt_get(opts, "writeout");
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053039 bool ro = qemu_opt_get_bool(opts, "readonly", 0);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053040
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053041 if (!fsdev_id) {
Greg Kurzea753f32016-01-22 15:12:18 +010042 error_report("fsdev: No id specified");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053043 return -1;
44 }
45
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053046 if (fsdriver) {
47 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
48 if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053049 break;
50 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053051 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053052
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053053 if (i == ARRAY_SIZE(FsDrivers)) {
Greg Kurzea753f32016-01-22 15:12:18 +010054 error_report("fsdev: fsdriver %s not found", fsdriver);
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053055 return -1;
56 }
57 } else {
Greg Kurzea753f32016-01-22 15:12:18 +010058 error_report("fsdev: No fsdriver specified");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053059 return -1;
60 }
61
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053062 fsle = g_malloc0(sizeof(*fsle));
Anthony Liguori7267c092011-08-20 22:09:37 -050063 fsle->fse.fsdev_id = g_strdup(fsdev_id);
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053064 fsle->fse.ops = FsDrivers[i].ops;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053065 if (writeout) {
66 if (!strcmp(writeout, "immediate")) {
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053067 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053068 }
69 }
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053070 if (ro) {
71 fsle->fse.export_flags |= V9FS_RDONLY;
72 } else {
73 fsle->fse.export_flags &= ~V9FS_RDONLY;
74 }
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053075
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053076 if (fsle->fse.ops->parse_opts) {
77 if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
Stefan Weilb58c86e2013-06-16 12:02:40 +020078 g_free(fsle->fse.fsdev_id);
79 g_free(fsle);
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053080 return -1;
81 }
M. Mohan Kumard9b36a62011-10-14 12:59:37 +053082 }
83
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053084 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053085 return 0;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053086}
87
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053088FsDriverEntry *get_fsdev_fsentry(char *id)
Gautham R Shenoy74db9202010-04-29 17:44:43 +053089{
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053090 if (id) {
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053091 struct FsDriverListEntry *fsle;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053092
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053093 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053094 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
95 return &fsle->fse;
96 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053097 }
98 }
99 return NULL;
100}