blob: ccfec139ab2bf127b0f981d1f4631b5a8a21c594 [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"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010016#include "qemu/queue.h"
17#include "qemu/osdep.h"
Gautham R Shenoy74db9202010-04-29 17:44:43 +053018#include "qemu-common.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010019#include "qemu/config-file.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);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053041
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053042 if (!fsdev_id) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +053043 fprintf(stderr, "fsdev: No id specified\n");
44 return -1;
45 }
46
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053047 if (fsdriver) {
48 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
49 if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053050 break;
51 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053052 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053053
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053054 if (i == ARRAY_SIZE(FsDrivers)) {
55 fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053056 return -1;
57 }
58 } else {
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053059 fprintf(stderr, "fsdev: No fsdriver specified\n");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053060 return -1;
61 }
62
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053063 fsle = g_malloc0(sizeof(*fsle));
Anthony Liguori7267c092011-08-20 22:09:37 -050064 fsle->fse.fsdev_id = g_strdup(fsdev_id);
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053065 fsle->fse.ops = FsDrivers[i].ops;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053066 if (writeout) {
67 if (!strcmp(writeout, "immediate")) {
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053068 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053069 }
70 }
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053071 if (ro) {
72 fsle->fse.export_flags |= V9FS_RDONLY;
73 } else {
74 fsle->fse.export_flags &= ~V9FS_RDONLY;
75 }
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053076
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053077 if (fsle->fse.ops->parse_opts) {
78 if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
Stefan Weilb58c86e2013-06-16 12:02:40 +020079 g_free(fsle->fse.fsdev_id);
80 g_free(fsle);
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053081 return -1;
82 }
M. Mohan Kumard9b36a62011-10-14 12:59:37 +053083 }
84
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053085 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053086 return 0;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053087}
88
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053089FsDriverEntry *get_fsdev_fsentry(char *id)
Gautham R Shenoy74db9202010-04-29 17:44:43 +053090{
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053091 if (id) {
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053092 struct FsDriverListEntry *fsle;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053093
Aneesh Kumar K.Vfbcbf102011-10-13 12:28:04 +053094 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053095 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
96 return &fsle->fse;
97 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053098 }
99 }
100 return NULL;
101}