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 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 21 | static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries = |
| 22 | QTAILQ_HEAD_INITIALIZER(fsdriver_entries); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 23 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 24 | static FsDriverTable FsDrivers[] = { |
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 | { |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 31 | struct FsDriverListEntry *fsle; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 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); |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 34 | const char *fsdriver = qemu_opt_get(opts, "fsdriver"); |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 35 | const char *path = qemu_opt_get(opts, "path"); |
| 36 | const char *sec_model = qemu_opt_get(opts, "security_model"); |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 37 | const char *writeout = qemu_opt_get(opts, "writeout"); |
| 38 | |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 39 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 40 | if (!fsdev_id) { |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 41 | fprintf(stderr, "fsdev: No id specified\n"); |
| 42 | return -1; |
| 43 | } |
| 44 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 45 | if (fsdriver) { |
| 46 | for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) { |
| 47 | if (strcmp(FsDrivers[i].name, fsdriver) == 0) { |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 48 | break; |
| 49 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 50 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 51 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 52 | if (i == ARRAY_SIZE(FsDrivers)) { |
| 53 | fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver); |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 54 | return -1; |
| 55 | } |
| 56 | } else { |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 57 | fprintf(stderr, "fsdev: No fsdriver specified\n"); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 58 | return -1; |
| 59 | } |
| 60 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 61 | if (!sec_model) { |
Venkateswararao Jujjuri (JV) | 9ce56db | 2010-06-14 13:34:40 -0700 | [diff] [blame] | 62 | fprintf(stderr, "fsdev: No security_model specified.\n"); |
| 63 | return -1; |
| 64 | } |
| 65 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 66 | if (!path) { |
| 67 | fprintf(stderr, "fsdev: No path specified.\n"); |
| 68 | return -1; |
| 69 | } |
| 70 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 71 | fsle = g_malloc(sizeof(*fsle)); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 72 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 73 | fsle->fse.fsdev_id = g_strdup(fsdev_id); |
| 74 | fsle->fse.path = g_strdup(path); |
| 75 | fsle->fse.security_model = g_strdup(sec_model); |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 76 | fsle->fse.ops = FsDrivers[i].ops; |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 77 | fsle->fse.export_flags = 0; |
| 78 | if (writeout) { |
| 79 | if (!strcmp(writeout, "immediate")) { |
| 80 | fsle->fse.export_flags = V9FS_IMMEDIATE_WRITEOUT; |
| 81 | } |
| 82 | } |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 83 | QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 84 | return 0; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 85 | } |
| 86 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 87 | FsDriverEntry *get_fsdev_fsentry(char *id) |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 88 | { |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 89 | if (id) { |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 90 | struct FsDriverListEntry *fsle; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 91 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame^] | 92 | QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 93 | if (strcmp(fsle->fse.fsdev_id, id) == 0) { |
| 94 | return &fsle->fse; |
| 95 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | return NULL; |
| 99 | } |
Gerd Hoffmann | 526c523 | 2010-08-25 12:19:49 +0200 | [diff] [blame] | 100 | |
| 101 | static void fsdev_register_config(void) |
| 102 | { |
| 103 | qemu_add_opts(&qemu_fsdev_opts); |
| 104 | qemu_add_opts(&qemu_virtfs_opts); |
| 105 | } |
| 106 | machine_init(fsdev_register_config); |
| 107 | |