blob: 280b8f57b9dce28063d745b8ab9e5c15ce88577e [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;
32
33 if (qemu_opts_id(opts) == NULL) {
34 fprintf(stderr, "fsdev: No id specified\n");
35 return -1;
36 }
37
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070038 for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +053039 if (strcmp(FsTypes[i].name, qemu_opt_get(opts, "fstype")) == 0) {
40 break;
41 }
42 }
43
44 if (i == ARRAY_SIZE(FsTypes)) {
45 fprintf(stderr, "fsdev: fstype %s not found\n",
46 qemu_opt_get(opts, "fstype"));
47 return -1;
48 }
49
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070050 if (qemu_opt_get(opts, "security_model") == NULL) {
51 fprintf(stderr, "fsdev: No security_model specified.\n");
52 return -1;
53 }
54
Gautham R Shenoy74db9202010-04-29 17:44:43 +053055 fsle = qemu_malloc(sizeof(*fsle));
56
57 fsle->fse.fsdev_id = qemu_strdup(qemu_opts_id(opts));
58 fsle->fse.path = qemu_strdup(qemu_opt_get(opts, "path"));
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070059 fsle->fse.security_model = qemu_strdup(qemu_opt_get(opts,
60 "security_model"));
Gautham R Shenoy74db9202010-04-29 17:44:43 +053061 fsle->fse.ops = FsTypes[i].ops;
62
63 QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
64 return 0;
65
66}
67
68FsTypeEntry *get_fsdev_fsentry(char *id)
69{
70 struct FsTypeListEntry *fsle;
71
72 QTAILQ_FOREACH(fsle, &fstype_entries, next) {
73 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
74 return &fsle->fse;
75 }
76 }
77 return NULL;
78}
Gerd Hoffmann526c5232010-08-25 12:19:49 +020079
80static void fsdev_register_config(void)
81{
82 qemu_add_opts(&qemu_fsdev_opts);
83 qemu_add_opts(&qemu_virtfs_opts);
84}
85machine_init(fsdev_register_config);
86