qemu-fsdev.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <stdio.h>
  14. #include <string.h>
  15. #include "qemu-fsdev.h"
  16. #include "qemu/queue.h"
  17. #include "qemu/osdep.h"
  18. #include "qemu-common.h"
  19. #include "qemu/config-file.h"
  20. static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
  21. QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
  22. static FsDriverTable FsDrivers[] = {
  23. { .name = "local", .ops = &local_ops},
  24. #ifdef CONFIG_OPEN_BY_HANDLE
  25. { .name = "handle", .ops = &handle_ops},
  26. #endif
  27. { .name = "synth", .ops = &synth_ops},
  28. { .name = "proxy", .ops = &proxy_ops},
  29. };
  30. int qemu_fsdev_add(QemuOpts *opts)
  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. if (!fsdev_id) {
  39. fprintf(stderr, "fsdev: No id specified\n");
  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. fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
  50. return -1;
  51. }
  52. } else {
  53. fprintf(stderr, "fsdev: No fsdriver specified\n");
  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)) {
  71. g_free(fsle->fse.fsdev_id);
  72. g_free(fsle);
  73. return -1;
  74. }
  75. }
  76. QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
  77. return 0;
  78. }
  79. FsDriverEntry *get_fsdev_fsentry(char *id)
  80. {
  81. if (id) {
  82. struct FsDriverListEntry *fsle;
  83. QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
  84. if (strcmp(fsle->fse.fsdev_id, id) == 0) {
  85. return &fsle->fse;
  86. }
  87. }
  88. }
  89. return NULL;
  90. }