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