blob: ad69b0ea4edba16a3a65986e70e29bef8b2e3ad8 [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"
19
20static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries =
21 QTAILQ_HEAD_INITIALIZER(fstype_entries);
22
23static FsTypeTable FsTypes[] = {
Anthony Liguori9f107512010-04-29 17:44:44 +053024 { .name = "local", .ops = &local_ops},
Gautham R Shenoy74db9202010-04-29 17:44:43 +053025};
26
27int qemu_fsdev_add(QemuOpts *opts)
28{
29 struct FsTypeListEntry *fsle;
30 int i;
31
32 if (qemu_opts_id(opts) == NULL) {
33 fprintf(stderr, "fsdev: No id specified\n");
34 return -1;
35 }
36
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070037 for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
Gautham R Shenoy74db9202010-04-29 17:44:43 +053038 if (strcmp(FsTypes[i].name, qemu_opt_get(opts, "fstype")) == 0) {
39 break;
40 }
41 }
42
43 if (i == ARRAY_SIZE(FsTypes)) {
44 fprintf(stderr, "fsdev: fstype %s not found\n",
45 qemu_opt_get(opts, "fstype"));
46 return -1;
47 }
48
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070049 if (qemu_opt_get(opts, "security_model") == NULL) {
50 fprintf(stderr, "fsdev: No security_model specified.\n");
51 return -1;
52 }
53
Gautham R Shenoy74db9202010-04-29 17:44:43 +053054 fsle = qemu_malloc(sizeof(*fsle));
55
56 fsle->fse.fsdev_id = qemu_strdup(qemu_opts_id(opts));
57 fsle->fse.path = qemu_strdup(qemu_opt_get(opts, "path"));
Venkateswararao Jujjuri (JV)9ce56db2010-06-14 13:34:40 -070058 fsle->fse.security_model = qemu_strdup(qemu_opt_get(opts,
59 "security_model"));
Gautham R Shenoy74db9202010-04-29 17:44:43 +053060 fsle->fse.ops = FsTypes[i].ops;
61
62 QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
63 return 0;
64
65}
66
67FsTypeEntry *get_fsdev_fsentry(char *id)
68{
69 struct FsTypeListEntry *fsle;
70
71 QTAILQ_FOREACH(fsle, &fstype_entries, next) {
72 if (strcmp(fsle->fse.fsdev_id, id) == 0) {
73 return &fsle->fse;
74 }
75 }
76 return NULL;
77}