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