2
0

qmp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * QEMU Management Protocol
  3. *
  4. * Copyright IBM, Corp. 2011
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.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-common.h"
  14. #include "sysemu.h"
  15. #include "qmp-commands.h"
  16. #include "kvm.h"
  17. #include "arch_init.h"
  18. NameInfo *qmp_query_name(Error **errp)
  19. {
  20. NameInfo *info = g_malloc0(sizeof(*info));
  21. if (qemu_name) {
  22. info->has_name = true;
  23. info->name = g_strdup(qemu_name);
  24. }
  25. return info;
  26. }
  27. VersionInfo *qmp_query_version(Error **err)
  28. {
  29. VersionInfo *info = g_malloc0(sizeof(*info));
  30. const char *version = QEMU_VERSION;
  31. char *tmp;
  32. info->qemu.major = strtol(version, &tmp, 10);
  33. tmp++;
  34. info->qemu.minor = strtol(tmp, &tmp, 10);
  35. tmp++;
  36. info->qemu.micro = strtol(tmp, &tmp, 10);
  37. info->package = g_strdup(QEMU_PKGVERSION);
  38. return info;
  39. }
  40. KvmInfo *qmp_query_kvm(Error **errp)
  41. {
  42. KvmInfo *info = g_malloc0(sizeof(*info));
  43. info->enabled = kvm_enabled();
  44. info->present = kvm_available();
  45. return info;
  46. }
  47. UuidInfo *qmp_query_uuid(Error **errp)
  48. {
  49. UuidInfo *info = g_malloc0(sizeof(*info));
  50. char uuid[64];
  51. snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
  52. qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
  53. qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
  54. qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
  55. qemu_uuid[14], qemu_uuid[15]);
  56. info->UUID = g_strdup(uuid);
  57. return info;
  58. }
  59. void qmp_quit(Error **err)
  60. {
  61. no_shutdown = 0;
  62. qemu_system_shutdown_request();
  63. }
  64. void qmp_stop(Error **errp)
  65. {
  66. vm_stop(RUN_STATE_PAUSED);
  67. }
  68. void qmp_system_reset(Error **errp)
  69. {
  70. qemu_system_reset_request();
  71. }
  72. void qmp_system_powerdown(Error **erp)
  73. {
  74. qemu_system_powerdown_request();
  75. }
  76. void qmp_cpu(int64_t index, Error **errp)
  77. {
  78. /* Just do nothing */
  79. }
  80. #ifndef CONFIG_VNC
  81. /* If VNC support is enabled, the "true" query-vnc command is
  82. defined in the VNC subsystem */
  83. VncInfo *qmp_query_vnc(Error **errp)
  84. {
  85. error_set(errp, QERR_FEATURE_DISABLED, "vnc");
  86. return NULL;
  87. };
  88. #endif
  89. #ifndef CONFIG_SPICE
  90. /* If SPICE support is enabled, the "true" query-spice command is
  91. defined in the SPICE subsystem. Also note that we use a small
  92. trick to maintain query-spice's original behavior, which is not
  93. to be available in the namespace if SPICE is not compiled in */
  94. SpiceInfo *qmp_query_spice(Error **errp)
  95. {
  96. error_set(errp, QERR_COMMAND_NOT_FOUND, "query-spice");
  97. return NULL;
  98. };
  99. #endif