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" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 16 | #include "qemu/queue.h" |
| 17 | #include "qemu/osdep.h" |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 18 | #include "qemu-common.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 19 | #include "qemu/config-file.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 | 77eec1b | 2011-12-04 22:35:27 +0530 | [diff] [blame] | 26 | #ifdef CONFIG_OPEN_BY_HANDLE |
Aneesh Kumar K.V | 5f54222 | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 27 | { .name = "handle", .ops = &handle_ops}, |
Aneesh Kumar K.V | 77eec1b | 2011-12-04 22:35:27 +0530 | [diff] [blame] | 28 | #endif |
Aneesh Kumar K.V | 9db221a | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 29 | { .name = "synth", .ops = &synth_ops}, |
M. Mohan Kumar | 4c793dd | 2011-12-14 13:49:28 +0530 | [diff] [blame] | 30 | { .name = "proxy", .ops = &proxy_ops}, |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | int qemu_fsdev_add(QemuOpts *opts) |
| 34 | { |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 35 | int i; |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 36 | struct FsDriverListEntry *fsle; |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 37 | const char *fsdev_id = qemu_opts_id(opts); |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 38 | const char *fsdriver = qemu_opt_get(opts, "fsdriver"); |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 39 | const char *writeout = qemu_opt_get(opts, "writeout"); |
M. Mohan Kumar | 2c74c2c | 2011-10-25 12:10:39 +0530 | [diff] [blame] | 40 | bool ro = qemu_opt_get_bool(opts, "readonly", 0); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 41 | |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 42 | if (!fsdev_id) { |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 43 | fprintf(stderr, "fsdev: No id specified\n"); |
| 44 | return -1; |
| 45 | } |
| 46 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 47 | if (fsdriver) { |
| 48 | for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) { |
| 49 | if (strcmp(FsDrivers[i].name, fsdriver) == 0) { |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 50 | break; |
| 51 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 52 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 53 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 54 | if (i == ARRAY_SIZE(FsDrivers)) { |
| 55 | fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver); |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 56 | return -1; |
| 57 | } |
| 58 | } else { |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 59 | fprintf(stderr, "fsdev: No fsdriver specified\n"); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 60 | return -1; |
| 61 | } |
| 62 | |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 63 | fsle = g_malloc0(sizeof(*fsle)); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 64 | fsle->fse.fsdev_id = g_strdup(fsdev_id); |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 65 | fsle->fse.ops = FsDrivers[i].ops; |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 66 | if (writeout) { |
| 67 | if (!strcmp(writeout, "immediate")) { |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 68 | fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT; |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 69 | } |
| 70 | } |
M. Mohan Kumar | 2c74c2c | 2011-10-25 12:10:39 +0530 | [diff] [blame] | 71 | if (ro) { |
| 72 | fsle->fse.export_flags |= V9FS_RDONLY; |
| 73 | } else { |
| 74 | fsle->fse.export_flags &= ~V9FS_RDONLY; |
| 75 | } |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 76 | |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 77 | if (fsle->fse.ops->parse_opts) { |
| 78 | if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) { |
Stefan Weil | b58c86e | 2013-06-16 12:02:40 +0200 | [diff] [blame] | 79 | g_free(fsle->fse.fsdev_id); |
| 80 | g_free(fsle); |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 81 | return -1; |
| 82 | } |
M. Mohan Kumar | d9b36a6 | 2011-10-14 12:59:37 +0530 | [diff] [blame] | 83 | } |
| 84 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 85 | QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 86 | return 0; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 87 | } |
| 88 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 89 | FsDriverEntry *get_fsdev_fsentry(char *id) |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 90 | { |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 91 | if (id) { |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 92 | struct FsDriverListEntry *fsle; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 93 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 94 | QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { |
Harsh Prateek Bora | 9f50689 | 2010-10-18 15:36:36 +0530 | [diff] [blame] | 95 | if (strcmp(fsle->fse.fsdev_id, id) == 0) { |
| 96 | return &fsle->fse; |
| 97 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | return NULL; |
| 101 | } |