Statistics
| Branch: | Revision:

root / fsdev / qemu-fsdev.c @ 9f506893

History | View | Annotate | Download (2.3 kB)

1 74db920c Gautham R Shenoy
/*
2 74db920c Gautham R Shenoy
 * Virtio 9p
3 74db920c Gautham R Shenoy
 *
4 74db920c Gautham R Shenoy
 * Copyright IBM, Corp. 2010
5 74db920c Gautham R Shenoy
 *
6 74db920c Gautham R Shenoy
 * Authors:
7 74db920c Gautham R Shenoy
 *  Gautham R Shenoy <ego@in.ibm.com>
8 74db920c Gautham R Shenoy
 *
9 74db920c Gautham R Shenoy
 * This work is licensed under the terms of the GNU GPL, version 2.  See
10 74db920c Gautham R Shenoy
 * the COPYING file in the top-level directory.
11 74db920c Gautham R Shenoy
 *
12 74db920c Gautham R Shenoy
 */
13 74db920c Gautham R Shenoy
#include <stdio.h>
14 74db920c Gautham R Shenoy
#include <string.h>
15 74db920c Gautham R Shenoy
#include "qemu-fsdev.h"
16 74db920c Gautham R Shenoy
#include "qemu-queue.h"
17 74db920c Gautham R Shenoy
#include "osdep.h"
18 74db920c Gautham R Shenoy
#include "qemu-common.h"
19 526c5237 Gerd Hoffmann
#include "qemu-config.h"
20 74db920c Gautham R Shenoy
21 74db920c Gautham R Shenoy
static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries =
22 74db920c Gautham R Shenoy
    QTAILQ_HEAD_INITIALIZER(fstype_entries);
23 74db920c Gautham R Shenoy
24 74db920c Gautham R Shenoy
static FsTypeTable FsTypes[] = {
25 9f107513 Anthony Liguori
    { .name = "local", .ops = &local_ops},
26 74db920c Gautham R Shenoy
};
27 74db920c Gautham R Shenoy
28 74db920c Gautham R Shenoy
int qemu_fsdev_add(QemuOpts *opts)
29 74db920c Gautham R Shenoy
{
30 74db920c Gautham R Shenoy
    struct FsTypeListEntry *fsle;
31 74db920c Gautham R Shenoy
    int i;
32 9f506893 Harsh Prateek Bora
    const char *fsdev_id = qemu_opts_id(opts);
33 9f506893 Harsh Prateek Bora
    const char *fstype = qemu_opt_get(opts, "fstype");
34 9f506893 Harsh Prateek Bora
    const char *path = qemu_opt_get(opts, "path");
35 9f506893 Harsh Prateek Bora
    const char *sec_model = qemu_opt_get(opts, "security_model");
36 74db920c Gautham R Shenoy
37 9f506893 Harsh Prateek Bora
    if (!fsdev_id) {
38 74db920c Gautham R Shenoy
        fprintf(stderr, "fsdev: No id specified\n");
39 74db920c Gautham R Shenoy
        return -1;
40 74db920c Gautham R Shenoy
    }
41 74db920c Gautham R Shenoy
42 9f506893 Harsh Prateek Bora
    if (fstype) {
43 9f506893 Harsh Prateek Bora
        for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
44 9f506893 Harsh Prateek Bora
            if (strcmp(FsTypes[i].name, fstype) == 0) {
45 9f506893 Harsh Prateek Bora
                break;
46 9f506893 Harsh Prateek Bora
            }
47 74db920c Gautham R Shenoy
        }
48 74db920c Gautham R Shenoy
49 9f506893 Harsh Prateek Bora
        if (i == ARRAY_SIZE(FsTypes)) {
50 9f506893 Harsh Prateek Bora
            fprintf(stderr, "fsdev: fstype %s not found\n", fstype);
51 9f506893 Harsh Prateek Bora
            return -1;
52 9f506893 Harsh Prateek Bora
        }
53 9f506893 Harsh Prateek Bora
    } else {
54 9f506893 Harsh Prateek Bora
        fprintf(stderr, "fsdev: No fstype specified\n");
55 74db920c Gautham R Shenoy
        return -1;
56 74db920c Gautham R Shenoy
    }
57 74db920c Gautham R Shenoy
58 9f506893 Harsh Prateek Bora
    if (!sec_model) {
59 9ce56db6 Venkateswararao Jujjuri (JV)
        fprintf(stderr, "fsdev: No security_model specified.\n");
60 9ce56db6 Venkateswararao Jujjuri (JV)
        return -1;
61 9ce56db6 Venkateswararao Jujjuri (JV)
    }
62 9ce56db6 Venkateswararao Jujjuri (JV)
63 9f506893 Harsh Prateek Bora
    if (!path) {
64 9f506893 Harsh Prateek Bora
        fprintf(stderr, "fsdev: No path specified.\n");
65 9f506893 Harsh Prateek Bora
        return -1;
66 9f506893 Harsh Prateek Bora
    }
67 9f506893 Harsh Prateek Bora
68 74db920c Gautham R Shenoy
    fsle = qemu_malloc(sizeof(*fsle));
69 74db920c Gautham R Shenoy
70 9f506893 Harsh Prateek Bora
    fsle->fse.fsdev_id = qemu_strdup(fsdev_id);
71 9f506893 Harsh Prateek Bora
    fsle->fse.path = qemu_strdup(path);
72 9f506893 Harsh Prateek Bora
    fsle->fse.security_model = qemu_strdup(sec_model);
73 74db920c Gautham R Shenoy
    fsle->fse.ops = FsTypes[i].ops;
74 74db920c Gautham R Shenoy
75 74db920c Gautham R Shenoy
    QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
76 74db920c Gautham R Shenoy
    return 0;
77 74db920c Gautham R Shenoy
78 74db920c Gautham R Shenoy
}
79 74db920c Gautham R Shenoy
80 74db920c Gautham R Shenoy
FsTypeEntry *get_fsdev_fsentry(char *id)
81 74db920c Gautham R Shenoy
{
82 9f506893 Harsh Prateek Bora
    if (id) {
83 9f506893 Harsh Prateek Bora
        struct FsTypeListEntry *fsle;
84 74db920c Gautham R Shenoy
85 9f506893 Harsh Prateek Bora
        QTAILQ_FOREACH(fsle, &fstype_entries, next) {
86 9f506893 Harsh Prateek Bora
            if (strcmp(fsle->fse.fsdev_id, id) == 0) {
87 9f506893 Harsh Prateek Bora
                return &fsle->fse;
88 9f506893 Harsh Prateek Bora
            }
89 74db920c Gautham R Shenoy
        }
90 74db920c Gautham R Shenoy
    }
91 74db920c Gautham R Shenoy
    return NULL;
92 74db920c Gautham R Shenoy
}
93 526c5237 Gerd Hoffmann
94 526c5237 Gerd Hoffmann
static void fsdev_register_config(void)
95 526c5237 Gerd Hoffmann
{
96 526c5237 Gerd Hoffmann
    qemu_add_opts(&qemu_fsdev_opts);
97 526c5237 Gerd Hoffmann
    qemu_add_opts(&qemu_virtfs_opts);
98 526c5237 Gerd Hoffmann
}
99 526c5237 Gerd Hoffmann
machine_init(fsdev_register_config);