2
0

qemu-fsdev.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "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. 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. if (!fsdev_id) {
  38. error_report("fsdev: No id specified");
  39. return -1;
  40. }
  41. if (fsdriver) {
  42. for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
  43. if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
  44. break;
  45. }
  46. }
  47. if (i == ARRAY_SIZE(FsDrivers)) {
  48. error_report("fsdev: fsdriver %s not found", fsdriver);
  49. return -1;
  50. }
  51. } else {
  52. error_report("fsdev: No fsdriver specified");
  53. return -1;
  54. }
  55. fsle = g_malloc0(sizeof(*fsle));
  56. fsle->fse.fsdev_id = g_strdup(fsdev_id);
  57. fsle->fse.ops = FsDrivers[i].ops;
  58. if (writeout) {
  59. if (!strcmp(writeout, "immediate")) {
  60. fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
  61. }
  62. }
  63. if (ro) {
  64. fsle->fse.export_flags |= V9FS_RDONLY;
  65. } else {
  66. fsle->fse.export_flags &= ~V9FS_RDONLY;
  67. }
  68. if (fsle->fse.ops->parse_opts) {
  69. if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
  70. g_free(fsle->fse.fsdev_id);
  71. g_free(fsle);
  72. return -1;
  73. }
  74. }
  75. QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
  76. return 0;
  77. }
  78. FsDriverEntry *get_fsdev_fsentry(char *id)
  79. {
  80. if (id) {
  81. struct FsDriverListEntry *fsle;
  82. QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
  83. if (strcmp(fsle->fse.fsdev_id, id) == 0) {
  84. return &fsle->fse;
  85. }
  86. }
  87. }
  88. return NULL;
  89. }