#include "qapi/qmp/qerror.h"
#include "qapi/string-input-visitor.h"
#include "qapi/string-output-visitor.h"
-#include "qapi/util.h"
#include "qapi-visit.h"
#include "qom/object_interfaces.h"
#include "ui/console.h"
info->singlestep ? " (single step mode)" : "");
if (!info->running && info->status != RUN_STATE_PAUSED) {
- monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
+ monitor_printf(mon, " (%s)", RunState_str(info->status));
}
monitor_printf(mon, "\n");
monitor_printf(mon, "capabilities: ");
for (cap = caps; cap; cap = cap->next) {
monitor_printf(mon, "%s: %s ",
- MigrationCapability_lookup[cap->value->capability],
+ MigrationCapability_str(cap->value->capability),
cap->value->state ? "on" : "off");
}
monitor_printf(mon, "\n");
if (info->has_status) {
monitor_printf(mon, "Migration status: %s",
- MigrationStatus_lookup[info->status]);
+ MigrationStatus_str(info->status));
if (info->status == MIGRATION_STATUS_FAILED &&
info->has_error_desc) {
monitor_printf(mon, " (%s)\n", info->error_desc);
if (caps) {
for (cap = caps; cap; cap = cap->next) {
monitor_printf(mon, "%s: %s\n",
- MigrationCapability_lookup[cap->value->capability],
+ MigrationCapability_str(cap->value->capability),
cap->value->state ? "on" : "off");
}
}
if (params) {
assert(params->has_compress_level);
monitor_printf(mon, "%s: %" PRId64 "\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL],
+ MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
params->compress_level);
assert(params->has_compress_threads);
monitor_printf(mon, "%s: %" PRId64 "\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS],
+ MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
params->compress_threads);
assert(params->has_decompress_threads);
monitor_printf(mon, "%s: %" PRId64 "\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
+ MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
params->decompress_threads);
assert(params->has_cpu_throttle_initial);
monitor_printf(mon, "%s: %" PRId64 "\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL],
+ MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
params->cpu_throttle_initial);
assert(params->has_cpu_throttle_increment);
monitor_printf(mon, "%s: %" PRId64 "\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT],
+ MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
params->cpu_throttle_increment);
+ assert(params->has_tls_creds);
monitor_printf(mon, "%s: '%s'\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS],
- params->has_tls_creds ? params->tls_creds : "");
+ MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
+ params->tls_creds);
+ assert(params->has_tls_hostname);
monitor_printf(mon, "%s: '%s'\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME],
- params->has_tls_hostname ? params->tls_hostname : "");
+ MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
+ params->tls_hostname);
assert(params->has_max_bandwidth);
monitor_printf(mon, "%s: %" PRId64 " bytes/second\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_MAX_BANDWIDTH],
+ MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
params->max_bandwidth);
assert(params->has_downtime_limit);
monitor_printf(mon, "%s: %" PRId64 " milliseconds\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_DOWNTIME_LIMIT],
+ MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
params->downtime_limit);
assert(params->has_x_checkpoint_delay);
monitor_printf(mon, "%s: %" PRId64 "\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY],
+ MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
params->x_checkpoint_delay);
assert(params->has_block_incremental);
monitor_printf(mon, "%s: %s\n",
- MigrationParameter_lookup[MIGRATION_PARAMETER_BLOCK_INCREMENTAL],
- params->block_incremental ? "on" : "off");
+ MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
+ params->block_incremental ? "on" : "off");
}
qapi_free_MigrationParameters(params);
assert(!info || !info->has_inserted || info->inserted == inserted);
- if (info) {
+ if (info && *info->device) {
monitor_printf(mon, "%s", info->device);
if (inserted && inserted->has_node_name) {
monitor_printf(mon, " (%s)", inserted->node_name);
}
} else {
- assert(inserted);
+ assert(info || inserted);
monitor_printf(mon, "%s",
- inserted->has_node_name
- ? inserted->node_name
+ inserted && inserted->has_node_name ? inserted->node_name
+ : info && info->has_qdev ? info->qdev
: "<anonymous>");
}
}
if (info) {
+ if (info->has_qdev) {
+ monitor_printf(mon, " Attached to: %s\n", info->qdev);
+ }
if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
monitor_printf(mon, " I/O status: %s\n",
- BlockDeviceIoStatus_lookup[info->io_status]);
+ BlockDeviceIoStatus_str(info->io_status));
}
if (info->removable) {
if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
monitor_printf(mon, " Detect zeroes: %s\n",
- BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
+ BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
}
if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
qapi_free_BlockStatsList(stats_list);
}
+/* Helper for hmp_info_vnc_clients, _servers */
+static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
+ const char *name)
+{
+ monitor_printf(mon, " %s: %s:%s (%s%s)\n",
+ name,
+ info->host,
+ info->service,
+ NetworkAddressFamily_str(info->family),
+ info->websocket ? " (Websocket)" : "");
+}
+
+/* Helper displaying and auth and crypt info */
+static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
+ VncPrimaryAuth auth,
+ VncVencryptSubAuth *vencrypt)
+{
+ monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
+ VncPrimaryAuth_str(auth),
+ vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
+}
+
+static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
+{
+ while (client) {
+ VncClientInfo *cinfo = client->value;
+
+ hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
+ monitor_printf(mon, " x509_dname: %s\n",
+ cinfo->has_x509_dname ?
+ cinfo->x509_dname : "none");
+ monitor_printf(mon, " sasl_username: %s\n",
+ cinfo->has_sasl_username ?
+ cinfo->sasl_username : "none");
+
+ client = client->next;
+ }
+}
+
+static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
+{
+ while (server) {
+ VncServerInfo2 *sinfo = server->value;
+ hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
+ hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
+ sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
+ server = server->next;
+ }
+}
+
void hmp_info_vnc(Monitor *mon, const QDict *qdict)
{
- VncInfo *info;
+ VncInfo2List *info2l;
Error *err = NULL;
- VncClientInfoList *client;
- info = qmp_query_vnc(&err);
+ info2l = qmp_query_vnc_servers(&err);
if (err) {
error_report_err(err);
return;
}
-
- if (!info->enabled) {
- monitor_printf(mon, "Server: disabled\n");
- goto out;
- }
-
- monitor_printf(mon, "Server:\n");
- if (info->has_host && info->has_service) {
- monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
- }
- if (info->has_auth) {
- monitor_printf(mon, " auth: %s\n", info->auth);
+ if (!info2l) {
+ monitor_printf(mon, "None\n");
+ return;
}
- if (!info->has_clients || info->clients == NULL) {
- monitor_printf(mon, "Client: none\n");
- } else {
- for (client = info->clients; client; client = client->next) {
- monitor_printf(mon, "Client:\n");
- monitor_printf(mon, " address: %s:%s\n",
- client->value->host,
- client->value->service);
- monitor_printf(mon, " x509_dname: %s\n",
- client->value->x509_dname ?
- client->value->x509_dname : "none");
- monitor_printf(mon, " username: %s\n",
- client->value->has_sasl_username ?
- client->value->sasl_username : "none");
+ while (info2l) {
+ VncInfo2 *info = info2l->value;
+ monitor_printf(mon, "%s:\n", info->id);
+ hmp_info_vnc_servers(mon, info->server);
+ hmp_info_vnc_clients(mon, info->clients);
+ if (!info->server) {
+ /* The server entry displays its auth, we only
+ * need to display in the case of 'reverse' connections
+ * where there's no server.
+ */
+ hmp_info_vnc_authcrypt(mon, " ", info->auth,
+ info->has_vencrypt ? &info->vencrypt : NULL);
}
+ if (info->has_display) {
+ monitor_printf(mon, " Display: %s\n", info->display);
+ }
+ info2l = info2l->next;
}
-out:
- qapi_free_VncInfo(info);
+ qapi_free_VncInfo2List(info2l);
+
}
#ifdef CONFIG_SPICE
monitor_printf(mon, " auth: %s\n", info->auth);
monitor_printf(mon, " compiled: %s\n", info->compiled_version);
monitor_printf(mon, " mouse-mode: %s\n",
- SpiceQueryMouseMode_lookup[info->mouse_mode]);
+ SpiceQueryMouseMode_str(info->mouse_mode));
if (!info->has_channels || info->channels == NULL) {
monitor_printf(mon, "Channels: none\n");
for (info = info_list; info; info = info->next) {
TPMInfo *ti = info->value;
monitor_printf(mon, " tpm%d: model=%s\n",
- c, TpmModel_lookup[ti->model]);
+ c, TpmModel_str(ti->model));
monitor_printf(mon, " \\ %s: type=%s",
- ti->id, TpmTypeOptionsKind_lookup[ti->options->type]);
+ ti->id, TpmTypeOptionsKind_str(ti->options->type));
switch (ti->options->type) {
case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
bool state = qdict_get_bool(qdict, "state");
Error *err = NULL;
MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
- int i;
+ int val;
- for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
- if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
- caps->value = g_malloc0(sizeof(*caps->value));
- caps->value->capability = i;
- caps->value->state = state;
- caps->next = NULL;
- qmp_migrate_set_capabilities(caps, &err);
- break;
- }
+ val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
+ if (val < 0) {
+ goto end;
}
- if (i == MIGRATION_CAPABILITY__MAX) {
- error_setg(&err, QERR_INVALID_PARAMETER, cap);
- }
+ caps->value = g_malloc0(sizeof(*caps->value));
+ caps->value->capability = val;
+ caps->value->state = state;
+ caps->next = NULL;
+ qmp_migrate_set_capabilities(caps, &err);
+end:
qapi_free_MigrationCapabilityStatusList(caps);
if (err) {
const char *param = qdict_get_str(qdict, "parameter");
const char *valuestr = qdict_get_str(qdict, "value");
Visitor *v = string_input_visitor_new(valuestr);
+ MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
uint64_t valuebw = 0;
- int64_t valueint = 0;
- bool valuebool = false;
Error *err = NULL;
- bool use_int_value = false;
- int i, ret;
-
- for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
- if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
- MigrationParameters p = { 0 };
- switch (i) {
- case MIGRATION_PARAMETER_COMPRESS_LEVEL:
- p.has_compress_level = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_COMPRESS_THREADS:
- p.has_compress_threads = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
- p.has_decompress_threads = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
- p.has_cpu_throttle_initial = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
- p.has_cpu_throttle_increment = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_TLS_CREDS:
- p.has_tls_creds = true;
- p.tls_creds = (char *) valuestr;
- break;
- case MIGRATION_PARAMETER_TLS_HOSTNAME:
- p.has_tls_hostname = true;
- p.tls_hostname = (char *) valuestr;
- break;
- case MIGRATION_PARAMETER_MAX_BANDWIDTH:
- p.has_max_bandwidth = true;
- ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
- if (ret < 0 || valuebw > INT64_MAX
- || (size_t)valuebw != valuebw) {
- error_setg(&err, "Invalid size %s", valuestr);
- goto cleanup;
- }
- p.max_bandwidth = valuebw;
- break;
- case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
- p.has_downtime_limit = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
- p.has_x_checkpoint_delay = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
- p.has_block_incremental = true;
- visit_type_bool(v, param, &valuebool, &err);
- if (err) {
- goto cleanup;
- }
- p.block_incremental = valuebool;
- break;
- }
-
- if (use_int_value) {
- visit_type_int(v, param, &valueint, &err);
- if (err) {
- goto cleanup;
- }
- /* Set all integers; only one has_FOO will be set, and
- * the code ignores the remaining values */
- p.compress_level = valueint;
- p.compress_threads = valueint;
- p.decompress_threads = valueint;
- p.cpu_throttle_initial = valueint;
- p.cpu_throttle_increment = valueint;
- p.downtime_limit = valueint;
- p.x_checkpoint_delay = valueint;
- }
-
- qmp_migrate_set_parameters(&p, &err);
+ int val, ret;
+
+ val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
+ if (val < 0) {
+ goto cleanup;
+ }
+
+ switch (val) {
+ case MIGRATION_PARAMETER_COMPRESS_LEVEL:
+ p->has_compress_level = true;
+ visit_type_int(v, param, &p->compress_level, &err);
+ break;
+ case MIGRATION_PARAMETER_COMPRESS_THREADS:
+ p->has_compress_threads = true;
+ visit_type_int(v, param, &p->compress_threads, &err);
+ break;
+ case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
+ p->has_decompress_threads = true;
+ visit_type_int(v, param, &p->decompress_threads, &err);
+ break;
+ case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
+ p->has_cpu_throttle_initial = true;
+ visit_type_int(v, param, &p->cpu_throttle_initial, &err);
+ break;
+ case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
+ p->has_cpu_throttle_increment = true;
+ visit_type_int(v, param, &p->cpu_throttle_increment, &err);
+ break;
+ case MIGRATION_PARAMETER_TLS_CREDS:
+ p->has_tls_creds = true;
+ p->tls_creds = g_new0(StrOrNull, 1);
+ p->tls_creds->type = QTYPE_QSTRING;
+ visit_type_str(v, param, &p->tls_creds->u.s, &err);
+ break;
+ case MIGRATION_PARAMETER_TLS_HOSTNAME:
+ p->has_tls_hostname = true;
+ p->tls_hostname = g_new0(StrOrNull, 1);
+ p->tls_hostname->type = QTYPE_QSTRING;
+ visit_type_str(v, param, &p->tls_hostname->u.s, &err);
+ break;
+ case MIGRATION_PARAMETER_MAX_BANDWIDTH:
+ p->has_max_bandwidth = true;
+ /*
+ * Can't use visit_type_size() here, because it
+ * defaults to Bytes rather than Mebibytes.
+ */
+ ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
+ if (ret < 0 || valuebw > INT64_MAX
+ || (size_t)valuebw != valuebw) {
+ error_setg(&err, "Invalid size %s", valuestr);
break;
}
+ p->max_bandwidth = valuebw;
+ break;
+ case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
+ p->has_downtime_limit = true;
+ visit_type_int(v, param, &p->downtime_limit, &err);
+ break;
+ case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
+ p->has_x_checkpoint_delay = true;
+ visit_type_int(v, param, &p->x_checkpoint_delay, &err);
+ break;
+ case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
+ p->has_block_incremental = true;
+ visit_type_bool(v, param, &p->block_incremental, &err);
+ break;
+ default:
+ assert(0);
}
- if (i == MIGRATION_PARAMETER__MAX) {
- error_setg(&err, QERR_INVALID_PARAMETER, param);
+ if (err) {
+ goto cleanup;
}
+ qmp_migrate_set_parameters(p, &err);
+
cleanup:
+ qapi_free_MigrateSetParameters(p);
visit_free(v);
if (err) {
error_report_err(err);
} else {
if (read_only) {
read_only_mode =
- qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
- read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
+ qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
+ read_only,
BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
if (err) {
hmp_handle_error(mon, &err);
monitor_printf(mon, " prealloc: %s\n",
m->value->prealloc ? "true" : "false");
monitor_printf(mon, " policy: %s\n",
- HostMemPolicy_lookup[m->value->policy]);
+ HostMemPolicy_str(m->value->policy));
visit_complete(v, &str);
monitor_printf(mon, " host nodes: %s\n", str);
di = value->u.dimm.data;
monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
- MemoryDeviceInfoKind_lookup[value->type],
+ MemoryDeviceInfoKind_str(value->type),
di->id ? di->id : "");
monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
DumpQueryResult *result = qmp_query_dump(NULL);
assert(result && result->status < DUMP_STATUS__MAX);
- monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]);
+ monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
if (result->status == DUMP_STATUS_ACTIVE) {
float percent = 0;