1 /* 2 * 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 "qemu/osdep.h" 14 #include "qemu-fsdev.h" 15 #include "qemu/queue.h" 16 #include "qemu-common.h" 17 #include "qemu/config-file.h" 18 #include "qemu/error-report.h" 19 20 static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries = 21 QTAILQ_HEAD_INITIALIZER(fsdriver_entries); 22 23 static FsDriverTable FsDrivers[] = { 24 { .name = "local", .ops = &local_ops}, 25 #ifdef CONFIG_OPEN_BY_HANDLE 26 { .name = "handle", .ops = &handle_ops}, 27 #endif 28 { .name = "synth", .ops = &synth_ops}, 29 { .name = "proxy", .ops = &proxy_ops}, 30 }; 31 32 int qemu_fsdev_add(QemuOpts *opts) 33 { 34 int i; 35 struct FsDriverListEntry *fsle; 36 const char *fsdev_id = qemu_opts_id(opts); 37 const char *fsdriver = qemu_opt_get(opts, "fsdriver"); 38 const char *writeout = qemu_opt_get(opts, "writeout"); 39 bool ro = qemu_opt_get_bool(opts, "readonly", 0); 40 Error *local_err = NULL; 41 42 if (!fsdev_id) { 43 error_report("fsdev: No id specified"); 44 return -1; 45 } 46 47 if (fsdriver) { 48 for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) { 49 if (strcmp(FsDrivers[i].name, fsdriver) == 0) { 50 break; 51 } 52 } 53 54 if (i == ARRAY_SIZE(FsDrivers)) { 55 error_report("fsdev: fsdriver %s not found", fsdriver); 56 return -1; 57 } 58 } else { 59 error_report("fsdev: No fsdriver specified"); 60 return -1; 61 } 62 63 fsle = g_malloc0(sizeof(*fsle)); 64 fsle->fse.fsdev_id = g_strdup(fsdev_id); 65 fsle->fse.ops = FsDrivers[i].ops; 66 if (writeout) { 67 if (!strcmp(writeout, "immediate")) { 68 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT; 69 } 70 } 71 if (ro) { 72 fsle->fse.export_flags |= V9FS_RDONLY; 73 } else { 74 fsle->fse.export_flags &= ~V9FS_RDONLY; 75 } 76 77 if (fsle->fse.ops->parse_opts) { 78 if (fsle->fse.ops->parse_opts(opts, &fsle->fse, &local_err)) { 79 error_report_err(local_err); 80 g_free(fsle->fse.fsdev_id); 81 g_free(fsle); 82 return -1; 83 } 84 } 85 86 QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next); 87 return 0; 88 } 89 90 FsDriverEntry *get_fsdev_fsentry(char *id) 91 { 92 if (id) { 93 struct FsDriverListEntry *fsle; 94 95 QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { 96 if (strcmp(fsle->fse.fsdev_id, id) == 0) { 97 return &fsle->fse; 98 } 99 } 100 } 101 return NULL; 102 } 103