summaryrefslogtreecommitdiffstats
path: root/hw/core/machine-qmp-cmds.c
diff options
context:
space:
mode:
authorPeter Maydell2021-01-28 23:43:18 +0100
committerPeter Maydell2021-01-28 23:43:18 +0100
commit7e7eb9f852a46b51a71ae9d82590b2e4d28827ee (patch)
treed63017ecda357d29659abe087aa6a09d808b06b5 /hw/core/machine-qmp-cmds.c
parentMerge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (diff)
parentqapi: More complex uses of QAPI_LIST_APPEND (diff)
downloadqemu-7e7eb9f852a46b51a71ae9d82590b2e4d28827ee.tar.gz
qemu-7e7eb9f852a46b51a71ae9d82590b2e4d28827ee.tar.xz
qemu-7e7eb9f852a46b51a71ae9d82590b2e4d28827ee.zip
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-01-28' into staging
QAPI patches patches for 2021-01-28 # gpg: Signature made Thu 28 Jan 2021 07:10:21 GMT # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2021-01-28: qapi: More complex uses of QAPI_LIST_APPEND qapi: Use QAPI_LIST_APPEND in trivial cases qapi: Introduce QAPI_LIST_APPEND qapi: A couple more QAPI_LIST_PREPEND() stragglers net: Clarify early exit condition Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/core/machine-qmp-cmds.c')
-rw-r--r--hw/core/machine-qmp-cmds.c127
1 files changed, 52 insertions, 75 deletions
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index affffe0c4a..44e979e503 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -28,11 +28,11 @@ CpuInfoList *qmp_query_cpus(Error **errp)
{
MachineState *ms = MACHINE(qdev_get_machine());
MachineClass *mc = MACHINE_GET_CLASS(ms);
- CpuInfoList *head = NULL, *cur_item = NULL;
+ CpuInfoList *head = NULL, **tail = &head;
CPUState *cpu;
CPU_FOREACH(cpu) {
- CpuInfoList *info;
+ CpuInfo *value;
#if defined(TARGET_I386)
X86CPU *x86_cpu = X86_CPU(cpu);
CPUX86State *env = &x86_cpu->env;
@@ -58,53 +58,46 @@ CpuInfoList *qmp_query_cpus(Error **errp)
cpu_synchronize_state(cpu);
- info = g_malloc0(sizeof(*info));
- info->value = g_malloc0(sizeof(*info->value));
- info->value->CPU = cpu->cpu_index;
- info->value->current = (cpu == first_cpu);
- info->value->halted = cpu->halted;
- info->value->qom_path = object_get_canonical_path(OBJECT(cpu));
- info->value->thread_id = cpu->thread_id;
+ value = g_malloc0(sizeof(*value));
+ value->CPU = cpu->cpu_index;
+ value->current = (cpu == first_cpu);
+ value->halted = cpu->halted;
+ value->qom_path = object_get_canonical_path(OBJECT(cpu));
+ value->thread_id = cpu->thread_id;
#if defined(TARGET_I386)
- info->value->arch = CPU_INFO_ARCH_X86;
- info->value->u.x86.pc = env->eip + env->segs[R_CS].base;
+ value->arch = CPU_INFO_ARCH_X86;
+ value->u.x86.pc = env->eip + env->segs[R_CS].base;
#elif defined(TARGET_PPC)
- info->value->arch = CPU_INFO_ARCH_PPC;
- info->value->u.ppc.nip = env->nip;
+ value->arch = CPU_INFO_ARCH_PPC;
+ value->u.ppc.nip = env->nip;
#elif defined(TARGET_SPARC)
- info->value->arch = CPU_INFO_ARCH_SPARC;
- info->value->u.q_sparc.pc = env->pc;
- info->value->u.q_sparc.npc = env->npc;
+ value->arch = CPU_INFO_ARCH_SPARC;
+ value->u.q_sparc.pc = env->pc;
+ value->u.q_sparc.npc = env->npc;
#elif defined(TARGET_MIPS)
- info->value->arch = CPU_INFO_ARCH_MIPS;
- info->value->u.q_mips.PC = env->active_tc.PC;
+ value->arch = CPU_INFO_ARCH_MIPS;
+ value->u.q_mips.PC = env->active_tc.PC;
#elif defined(TARGET_TRICORE)
- info->value->arch = CPU_INFO_ARCH_TRICORE;
- info->value->u.tricore.PC = env->PC;
+ value->arch = CPU_INFO_ARCH_TRICORE;
+ value->u.tricore.PC = env->PC;
#elif defined(TARGET_S390X)
- info->value->arch = CPU_INFO_ARCH_S390;
- info->value->u.s390.cpu_state = env->cpu_state;
+ value->arch = CPU_INFO_ARCH_S390;
+ value->u.s390.cpu_state = env->cpu_state;
#elif defined(TARGET_RISCV)
- info->value->arch = CPU_INFO_ARCH_RISCV;
- info->value->u.riscv.pc = env->pc;
+ value->arch = CPU_INFO_ARCH_RISCV;
+ value->u.riscv.pc = env->pc;
#else
- info->value->arch = CPU_INFO_ARCH_OTHER;
+ value->arch = CPU_INFO_ARCH_OTHER;
#endif
- info->value->has_props = !!mc->cpu_index_to_instance_props;
- if (info->value->has_props) {
+ value->has_props = !!mc->cpu_index_to_instance_props;
+ if (value->has_props) {
CpuInstanceProperties *props;
props = g_malloc0(sizeof(*props));
*props = mc->cpu_index_to_instance_props(ms, cpu->cpu_index);
- info->value->props = props;
+ value->props = props;
}
- /* XXX: waiting for the qapi to support GSList */
- if (!cur_item) {
- head = cur_item = info;
- } else {
- cur_item->next = info;
- cur_item = info;
- }
+ QAPI_LIST_APPEND(tail, value);
}
return head;
@@ -170,39 +163,33 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
{
MachineState *ms = MACHINE(qdev_get_machine());
MachineClass *mc = MACHINE_GET_CLASS(ms);
- CpuInfoFastList *head = NULL, *cur_item = NULL;
+ CpuInfoFastList *head = NULL, **tail = &head;
SysEmuTarget target = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME,
-1, &error_abort);
CPUState *cpu;
CPU_FOREACH(cpu) {
- CpuInfoFastList *info = g_malloc0(sizeof(*info));
- info->value = g_malloc0(sizeof(*info->value));
+ CpuInfoFast *value = g_malloc0(sizeof(*value));
- info->value->cpu_index = cpu->cpu_index;
- info->value->qom_path = object_get_canonical_path(OBJECT(cpu));
- info->value->thread_id = cpu->thread_id;
+ value->cpu_index = cpu->cpu_index;
+ value->qom_path = object_get_canonical_path(OBJECT(cpu));
+ value->thread_id = cpu->thread_id;
- info->value->has_props = !!mc->cpu_index_to_instance_props;
- if (info->value->has_props) {
+ value->has_props = !!mc->cpu_index_to_instance_props;
+ if (value->has_props) {
CpuInstanceProperties *props;
props = g_malloc0(sizeof(*props));
*props = mc->cpu_index_to_instance_props(ms, cpu->cpu_index);
- info->value->props = props;
+ value->props = props;
}
- info->value->arch = sysemu_target_to_cpuinfo_arch(target);
- info->value->target = target;
+ value->arch = sysemu_target_to_cpuinfo_arch(target);
+ value->target = target;
if (target == SYS_EMU_TARGET_S390X) {
- cpustate_to_cpuinfo_s390(&info->value->u.s390x, cpu);
+ cpustate_to_cpuinfo_s390(&value->u.s390x, cpu);
}
- if (!cur_item) {
- head = cur_item = info;
- } else {
- cur_item->next = info;
- cur_item = info;
- }
+ QAPI_LIST_APPEND(tail, value);
}
return head;
@@ -293,41 +280,31 @@ void qmp_set_numa_node(NumaOptions *cmd, Error **errp)
static int query_memdev(Object *obj, void *opaque)
{
MemdevList **list = opaque;
- MemdevList *m = NULL;
+ Memdev *m;
QObject *host_nodes;
Visitor *v;
if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
m = g_malloc0(sizeof(*m));
- m->value = g_malloc0(sizeof(*m->value));
-
- m->value->id = g_strdup(object_get_canonical_path_component(obj));
- m->value->has_id = !!m->value->id;
-
- m->value->size = object_property_get_uint(obj, "size",
- &error_abort);
- m->value->merge = object_property_get_bool(obj, "merge",
- &error_abort);
- m->value->dump = object_property_get_bool(obj, "dump",
- &error_abort);
- m->value->prealloc = object_property_get_bool(obj,
- "prealloc",
- &error_abort);
- m->value->policy = object_property_get_enum(obj,
- "policy",
- "HostMemPolicy",
- &error_abort);
+ m->id = g_strdup(object_get_canonical_path_component(obj));
+ m->has_id = !!m->id;
+
+ m->size = object_property_get_uint(obj, "size", &error_abort);
+ m->merge = object_property_get_bool(obj, "merge", &error_abort);
+ m->dump = object_property_get_bool(obj, "dump", &error_abort);
+ m->prealloc = object_property_get_bool(obj, "prealloc", &error_abort);
+ m->policy = object_property_get_enum(obj, "policy", "HostMemPolicy",
+ &error_abort);
host_nodes = object_property_get_qobject(obj,
"host-nodes",
&error_abort);
v = qobject_input_visitor_new(host_nodes);
- visit_type_uint16List(v, NULL, &m->value->host_nodes, &error_abort);
+ visit_type_uint16List(v, NULL, &m->host_nodes, &error_abort);
visit_free(v);
qobject_unref(host_nodes);
- m->next = *list;
- *list = m;
+ QAPI_LIST_PREPEND(*list, m);
}
return 0;