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