blob: 0b332907bdad073c1f22dd533bdd6dced8dc4f8b [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},
Gautham R Shenoy74db9202010-04-29 17:44:43 +053026};
27
28int qemu_fsdev_add(QemuOpts *opts)
29{
30 struct FsTypeListEntry *fsle;
31 int i;
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053032 const char *fsdev_id = qemu_opts_id(opts);
33 const char *fstype = qemu_opt_get(opts, "fstype");
34 const char *path = qemu_opt_get(opts, "path");
35 const char *sec_model = qemu_opt_get(opts, "security_model");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053036
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053037 if (!fsdev_id) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +053038 fprintf(stderr, "fsdev: No id specified\n");
39 return -1;
40 }
41
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053042 if (fstype) {
43 for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
44 if (strcmp(FsTypes[i].name, fstype) == 0) {
45 break;
46 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053047 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053048
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053049 if (i == ARRAY_SIZE(FsTypes)) {
50 fprintf(stderr, "fsdev: fstype %s not found\n", fstype);
51 return -1;
52 }
53 } else {
54 fprintf(stderr, "fsdev: No fstype specified\n");
Gautham R Shenoy74db9202010-04-29 17:44:43 +053055 return -1;
56 }
57
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053058 if (!sec_model) {
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070059 fprintf(stderr, "fsdev: No security_model specified.\n");
60 return -1;
61 }
62
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053063 if (!path) {
64 fprintf(stderr, "fsdev: No path specified.\n");
65 return -1;
66 }
67
Gautham R Shenoy74db9202010-04-29 17:44:43 +053068 fsle = qemu_malloc(sizeof(*fsle));
69
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053070 fsle->fse.fsdev_id = qemu_strdup(fsdev_id);
71 fsle->fse.path = qemu_strdup(path);
72 fsle->fse.security_model = qemu_strdup(sec_model);
Gautham R Shenoy74db9202010-04-29 17:44:43 +053073 fsle->fse.ops = FsTypes[i].ops;
74
75 QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
76 return 0;
77
78}
79
80FsTypeEntry *get_fsdev_fsentry(char *id)
81{
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053082 if (id) {
83 struct FsTypeListEntry *fsle;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053084
Harsh Prateek Bora9f506892010-10-18 15:36:36 +053085 QTAILQ_FOREACH(fsle, &fstype_entries, next) {
86 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
87 return &fsle->fse;
88 }
Gautham R Shenoy74db9202010-04-29 17:44:43 +053089 }
90 }
91 return NULL;
92}
Gerd Hoffmann526c5232010-08-25 12:19:49 +020093
94static void fsdev_register_config(void)
95{
96 qemu_add_opts(&qemu_fsdev_opts);
97 qemu_add_opts(&qemu_virtfs_opts);
98}
99machine_init(fsdev_register_config);
100