qemu-fsdev.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "osdep.h"
  18. #include "qemu-common.h"
  19. #include "qemu-config.h"
  20. static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries =
  21. QTAILQ_HEAD_INITIALIZER(fstype_entries);
  22. static FsTypeTable FsTypes[] = {
  23. { .name = "local", .ops = &local_ops},
  24. { .name = "handle", .ops = &handle_ops},
  25. };
  26. int qemu_fsdev_add(QemuOpts *opts)
  27. {
  28. struct FsTypeListEntry *fsle;
  29. int i;
  30. const char *fsdev_id = qemu_opts_id(opts);
  31. const char *fstype = qemu_opt_get(opts, "fstype");
  32. const char *path = qemu_opt_get(opts, "path");
  33. const char *sec_model = qemu_opt_get(opts, "security_model");
  34. const char *writeout = qemu_opt_get(opts, "writeout");
  35. if (!fsdev_id) {
  36. fprintf(stderr, "fsdev: No id specified\n");
  37. return -1;
  38. }
  39. if (fstype) {
  40. for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
  41. if (strcmp(FsTypes[i].name, fstype) == 0) {
  42. break;
  43. }
  44. }
  45. if (i == ARRAY_SIZE(FsTypes)) {
  46. fprintf(stderr, "fsdev: fstype %s not found\n", fstype);
  47. return -1;
  48. }
  49. } else {
  50. fprintf(stderr, "fsdev: No fstype specified\n");
  51. return -1;
  52. }
  53. if (!sec_model) {
  54. fprintf(stderr, "fsdev: No security_model specified.\n");
  55. return -1;
  56. }
  57. if (!path) {
  58. fprintf(stderr, "fsdev: No path specified.\n");
  59. return -1;
  60. }
  61. fsle = g_malloc(sizeof(*fsle));
  62. fsle->fse.fsdev_id = g_strdup(fsdev_id);
  63. fsle->fse.path = g_strdup(path);
  64. fsle->fse.security_model = g_strdup(sec_model);
  65. fsle->fse.ops = FsTypes[i].ops;
  66. fsle->fse.export_flags = 0;
  67. if (writeout) {
  68. if (!strcmp(writeout, "immediate")) {
  69. fsle->fse.export_flags = V9FS_IMMEDIATE_WRITEOUT;
  70. }
  71. }
  72. QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
  73. return 0;
  74. }
  75. FsTypeEntry *get_fsdev_fsentry(char *id)
  76. {
  77. if (id) {
  78. struct FsTypeListEntry *fsle;
  79. QTAILQ_FOREACH(fsle, &fstype_entries, next) {
  80. if (strcmp(fsle->fse.fsdev_id, id) == 0) {
  81. return &fsle->fse;
  82. }
  83. }
  84. }
  85. return NULL;
  86. }
  87. static void fsdev_register_config(void)
  88. {
  89. qemu_add_opts(&qemu_fsdev_opts);
  90. qemu_add_opts(&qemu_virtfs_opts);
  91. }
  92. machine_init(fsdev_register_config);