Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 1 | /* |
| 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 Hoffmann | 526c523 | 2010-08-25 12:19:49 +0200 | [diff] [blame] | 19 | #include "qemu-config.h" |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 20 | |
| 21 | static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries = |
| 22 | QTAILQ_HEAD_INITIALIZER(fstype_entries); |
| 23 | |
| 24 | static FsTypeTable FsTypes[] = { |
Anthony Liguori | 9f10751 | 2010-04-29 17:44:44 +0530 | [diff] [blame] | 25 | { .name = "local", .ops = &local_ops}, |
Aneesh Kumar K.V | 5f54222 | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 26 | { .name = "handle", .ops = &handle_ops}, |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | int qemu_fsdev_add(QemuOpts *opts) |
| 30 | { |
| 31 | struct FsTypeListEntry *fsle; |
| 32 | int i; |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 33 | 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"); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 37 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 38 | if (!fsdev_id) { |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 39 | fprintf(stderr, "fsdev: No id specified\n"); |
| 40 | return -1; |
| 41 | } |
| 42 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 43 | if (fstype) { |
| 44 | for (i = 0; i < ARRAY_SIZE(FsTypes); i++) { |
| 45 | if (strcmp(FsTypes[i].name, fstype) == 0) { |
| 46 | break; |
| 47 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 48 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 49 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 50 | if (i == ARRAY_SIZE(FsTypes)) { |
| 51 | fprintf(stderr, "fsdev: fstype %s not found\n", fstype); |
| 52 | return -1; |
| 53 | } |
| 54 | } else { |
| 55 | fprintf(stderr, "fsdev: No fstype specified\n"); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 56 | return -1; |
| 57 | } |
| 58 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 59 | if (!sec_model) { |
Venkateswararao Jujjuri (JV) | 9ce56db | 2010-06-14 13:34:40 -0700 | [diff] [blame] | 60 | fprintf(stderr, "fsdev: No security_model specified.\n"); |
| 61 | return -1; |
| 62 | } |
| 63 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 64 | if (!path) { |
| 65 | fprintf(stderr, "fsdev: No path specified.\n"); |
| 66 | return -1; |
| 67 | } |
| 68 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 69 | fsle = g_malloc(sizeof(*fsle)); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 70 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 71 | fsle->fse.fsdev_id = g_strdup(fsdev_id); |
| 72 | fsle->fse.path = g_strdup(path); |
| 73 | fsle->fse.security_model = g_strdup(sec_model); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 74 | fsle->fse.ops = FsTypes[i].ops; |
| 75 | |
| 76 | QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next); |
| 77 | return 0; |
| 78 | |
| 79 | } |
| 80 | |
| 81 | FsTypeEntry *get_fsdev_fsentry(char *id) |
| 82 | { |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 83 | if (id) { |
| 84 | struct FsTypeListEntry *fsle; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 85 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 86 | QTAILQ_FOREACH(fsle, &fstype_entries, next) { |
| 87 | if (strcmp(fsle->fse.fsdev_id, id) == 0) { |
| 88 | return &fsle->fse; |
| 89 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | return NULL; |
| 93 | } |
Gerd Hoffmann | 526c523 | 2010-08-25 12:19:49 +0200 | [diff] [blame] | 94 | |
| 95 | static void fsdev_register_config(void) |
| 96 | { |
| 97 | qemu_add_opts(&qemu_fsdev_opts); |
| 98 | qemu_add_opts(&qemu_virtfs_opts); |
| 99 | } |
| 100 | machine_init(fsdev_register_config); |
| 101 | |