qemu-fsdev.c 2.6 KB

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