qemu-fsdev.c 2.4 KB

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