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 | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame^] | 19 | #include "hw/qdev.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 20 | |
| 21 | NameInfo *qmp_query_name(Error **errp) |
| 22 | { |
| 23 | NameInfo *info = g_malloc0(sizeof(*info)); |
| 24 | |
| 25 | if (qemu_name) { |
| 26 | info->has_name = true; |
| 27 | info->name = g_strdup(qemu_name); |
| 28 | } |
| 29 | |
| 30 | return info; |
| 31 | } |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 32 | |
| 33 | VersionInfo *qmp_query_version(Error **err) |
| 34 | { |
| 35 | VersionInfo *info = g_malloc0(sizeof(*info)); |
| 36 | const char *version = QEMU_VERSION; |
| 37 | char *tmp; |
| 38 | |
| 39 | info->qemu.major = strtol(version, &tmp, 10); |
| 40 | tmp++; |
| 41 | info->qemu.minor = strtol(tmp, &tmp, 10); |
| 42 | tmp++; |
| 43 | info->qemu.micro = strtol(tmp, &tmp, 10); |
| 44 | info->package = g_strdup(QEMU_PKGVERSION); |
| 45 | |
| 46 | return info; |
| 47 | } |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 48 | |
| 49 | KvmInfo *qmp_query_kvm(Error **errp) |
| 50 | { |
| 51 | KvmInfo *info = g_malloc0(sizeof(*info)); |
| 52 | |
| 53 | info->enabled = kvm_enabled(); |
| 54 | info->present = kvm_available(); |
| 55 | |
| 56 | return info; |
| 57 | } |
| 58 | |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 59 | UuidInfo *qmp_query_uuid(Error **errp) |
| 60 | { |
| 61 | UuidInfo *info = g_malloc0(sizeof(*info)); |
| 62 | char uuid[64]; |
| 63 | |
| 64 | snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1], |
| 65 | qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], |
| 66 | qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], |
| 67 | qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], |
| 68 | qemu_uuid[14], qemu_uuid[15]); |
| 69 | |
| 70 | info->UUID = g_strdup(uuid); |
| 71 | return info; |
| 72 | } |
| 73 | |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 74 | void qmp_quit(Error **err) |
| 75 | { |
| 76 | no_shutdown = 0; |
| 77 | qemu_system_shutdown_request(); |
| 78 | } |
| 79 | |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 80 | void qmp_stop(Error **errp) |
| 81 | { |
| 82 | vm_stop(RUN_STATE_PAUSED); |
| 83 | } |
| 84 | |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 85 | void qmp_system_reset(Error **errp) |
| 86 | { |
| 87 | qemu_system_reset_request(); |
| 88 | } |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 89 | |
| 90 | void qmp_system_powerdown(Error **erp) |
| 91 | { |
| 92 | qemu_system_powerdown_request(); |
| 93 | } |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 94 | |
| 95 | void qmp_cpu(int64_t index, Error **errp) |
| 96 | { |
| 97 | /* Just do nothing */ |
| 98 | } |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 99 | |
| 100 | #ifndef CONFIG_VNC |
| 101 | /* If VNC support is enabled, the "true" query-vnc command is |
| 102 | defined in the VNC subsystem */ |
| 103 | VncInfo *qmp_query_vnc(Error **errp) |
| 104 | { |
| 105 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); |
| 106 | return NULL; |
| 107 | }; |
| 108 | #endif |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 109 | |
| 110 | #ifndef CONFIG_SPICE |
| 111 | /* If SPICE support is enabled, the "true" query-spice command is |
| 112 | defined in the SPICE subsystem. Also note that we use a small |
| 113 | trick to maintain query-spice's original behavior, which is not |
| 114 | to be available in the namespace if SPICE is not compiled in */ |
| 115 | SpiceInfo *qmp_query_spice(Error **errp) |
| 116 | { |
| 117 | error_set(errp, QERR_COMMAND_NOT_FOUND, "query-spice"); |
| 118 | return NULL; |
| 119 | }; |
| 120 | #endif |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 121 | |
| 122 | static void iostatus_bdrv_it(void *opaque, BlockDriverState *bs) |
| 123 | { |
| 124 | bdrv_iostatus_reset(bs); |
| 125 | } |
| 126 | |
| 127 | static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs) |
| 128 | { |
| 129 | Error **err = opaque; |
| 130 | |
| 131 | if (!error_is_set(err) && bdrv_key_required(bs)) { |
| 132 | error_set(err, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs)); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | void qmp_cont(Error **errp) |
| 137 | { |
| 138 | Error *local_err = NULL; |
| 139 | |
| 140 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
| 141 | error_set(errp, QERR_MIGRATION_EXPECTED); |
| 142 | return; |
| 143 | } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) || |
| 144 | runstate_check(RUN_STATE_SHUTDOWN)) { |
| 145 | error_set(errp, QERR_RESET_REQUIRED); |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | bdrv_iterate(iostatus_bdrv_it, NULL); |
| 150 | bdrv_iterate(encrypted_bdrv_it, &local_err); |
| 151 | if (local_err) { |
| 152 | error_propagate(errp, local_err); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | vm_start(); |
| 157 | } |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame^] | 158 | |
| 159 | DevicePropertyInfoList *qmp_qom_list(const char *path, Error **errp) |
| 160 | { |
| 161 | DeviceState *dev; |
| 162 | bool ambiguous = false; |
| 163 | DevicePropertyInfoList *props = NULL; |
| 164 | DeviceProperty *prop; |
| 165 | |
| 166 | dev = qdev_resolve_path(path, &ambiguous); |
| 167 | if (dev == NULL) { |
| 168 | error_set(errp, QERR_DEVICE_NOT_FOUND, path); |
| 169 | return NULL; |
| 170 | } |
| 171 | |
| 172 | QTAILQ_FOREACH(prop, &dev->properties, node) { |
| 173 | DevicePropertyInfoList *entry = g_malloc0(sizeof(*entry)); |
| 174 | |
| 175 | entry->value = g_malloc0(sizeof(DevicePropertyInfo)); |
| 176 | entry->next = props; |
| 177 | props = entry; |
| 178 | |
| 179 | entry->value->name = g_strdup(prop->name); |
| 180 | entry->value->type = g_strdup(prop->type); |
| 181 | } |
| 182 | |
| 183 | return props; |
| 184 | } |