blob: 946bad79989034d085c00a5eb173ec63da314ea5 [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
21static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries =
22 QTAILQ_HEAD_INITIALIZER(fstype_entries);
23
24static FsTypeTable FsTypes[] = {
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{
31 struct FsTypeListEntry *fsle;
32 int i;
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053033 const char *fsdev_id = qemu_opts_id(opts);
34 const char *fstype = qemu_opt_get(opts, "fstype");
35 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
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053045 if (fstype) {
46 for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
47 if (strcmp(FsTypes[i].name, fstype) == 0) {
48 break;
49 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053050 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053051
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053052 if (i == ARRAY_SIZE(FsTypes)) {
53 fprintf(stderr, "fsdev: fstype %s not found\n", fstype);
54 return -1;
55 }
56 } else {
57 fprintf(stderr, "fsdev: No fstype specified\n");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053058 return -1;
59 }
60
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053061 if (!sec_model) {
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070062 fprintf(stderr, "fsdev: No security_model specified.\n");
63 return -1;
64 }
65
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053066 if (!path) {
67 fprintf(stderr, "fsdev: No path specified.\n");
68 return -1;
69 }
70
Anthony Liguori7267c092011-08-20 22:09:37 -050071 fsle = g_malloc(sizeof(*fsle));
Gautham R Shenoy74db9202010-04-29 17:44:43 +053072
Anthony Liguori7267c092011-08-20 22:09:37 -050073 fsle->fse.fsdev_id = g_strdup(fsdev_id);
74 fsle->fse.path = g_strdup(path);
75 fsle->fse.security_model = g_strdup(sec_model);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053076 fsle->fse.ops = FsTypes[i].ops;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053077 fsle->fse.export_flags = 0;
78 if (writeout) {
79 if (!strcmp(writeout, "immediate")) {
80 fsle->fse.export_flags = V9FS_IMMEDIATE_WRITEOUT;
81 }
82 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053083 QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
84 return 0;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053085}
86
87FsTypeEntry *get_fsdev_fsentry(char *id)
88{
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053089 if (id) {
90 struct FsTypeListEntry *fsle;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053091
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053092 QTAILQ_FOREACH(fsle, &fstype_entries, next) {
93 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
94 return &fsle->fse;
95 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053096 }
97 }
98 return NULL;
99}
Gerd Hoffmann526c5232010-08-25 12:19:49 +0200100
101static void fsdev_register_config(void)
102{
103 qemu_add_opts(&qemu_fsdev_opts);
104 qemu_add_opts(&qemu_virtfs_opts);
105}
106machine_init(fsdev_register_config);
107