qmp: Disable query-cpu-* commands when they're unavailable
PATCH 1/1 qmp: Disable query-cpu-* commands when they're unavailable
Instead of requiring clients to actually call the query-cpu-* commands to find out if they are implemented, remove them from the output of "query-commands", so clients know they are not available.
This is implemented by adding a new arch-specific hook:arch_init_qmp_commands(), that can enable the available QMP commands (which are now disabled by default).
--- include/sysemu/arch_init.h | 1 + qmp.c | 1 + stubs/Makefile.objs | 1 + stubs/arch-qmp-commands-init.c | 7 +++++++ target-arm/monitor.c | 7 +++++++ target-i386/cpu.c | 6 ++++++ target-ppc/monitor.c | 7 +++++++ target-s390x/cpu_models.c | 9 +++++++++ vl.c | 10 ++++++++++ 9 files changed, 49 insertions(+) create mode 100644 stubs/arch-qmp-commands-init.c
include/sysemu/arch_init.h +1 -0
@@ -34,6 +34,7 @@ void audio_init(void);int kvm_available (void );int xen_available (void ); +void arch_qmp_commands_init (void );CpuDefinitionInfoList *arch_query_cpu_definitions (Error **errp); CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type, CpuModelInfo *mode,
qmp.c +1 -0
@@ -31,6 +31,7 @@#include "qom/qom-qobject.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qobject.h" +#include "qapi/qmp/dispatch.h" #include "qapi/qmp-input-visitor.h" #include "hw/boards.h" #include "qom/object_interfaces.h"
stubs/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ +stub-obj-y += arch-qmp-commands-init.o stub-obj-y += arch-query-cpu-def.o stub-obj-y += arch-query-cpu-model-expansion.o stub-obj-y += arch-query-cpu-model-comparison.o
stubs/arch-qmp-commands-init.c new file +7 -0
@@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "sysemu/arch_init.h" + +void arch_qmp_commands_init (void ) +{ +}
target-arm/monitor.c +7 -0
@@ -21,6 +21,8 @@*/ #include "qemu/osdep.h" #include "qmp-commands.h" +#include "qapi/qmp/dispatch.h" +#include "sysemu/arch_init.h" #include "hw/boards.h" #include "kvm_arm.h"
@@ -81,3 +83,8 @@ GICCapabilityList *qmp_query_gic_capabilities(Error **errp)return head; } + +void arch_qmp_commands_init (void ) +{ +qmp_enable_command ("query-cpu-model-definitions" ); +}
target-i386/cpu.c +6 -0
@@ -29,6 +29,7 @@#include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/qmp/qerror.h" +#include "qapi/qmp/dispatch.h" #include "qapi-types.h" #include "qapi-visit.h"
@@ -3565,3 +3566,8 @@ static void x86_cpu_register_types(void) }type_init (x86_cpu_register_types) + +void arch_qmp_commands_init(void) +{ +qmp_enable_command ("query-cpu-model-definitions" ); +}
target-ppc/monitor.c +7 -0
@@ -25,6 +25,8 @@#include "cpu.h" #include "monitor/monitor.h" #include "monitor/hmp-target.h" +#include "qapi/qmp/dispatch.h" +#include "sysemu/arch_init.h" #include "hmp.h" static target_long monitor_get_ccr (const struct MonitorDef *md,int val)
@@ -145,3 +147,8 @@ int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)return -EINVAL ; } + +void arch_qmp_commands_init (void ) +{ +qmp_enable_command ("query-cpu-model-definitions" ); +}
target-s390x/cpu_models.c +9 -0
@@ -19,6 +19,7 @@#include "qapi/qmp/qerror.h" #include "qapi/qmp-input-visitor.h" #include "qapi/qmp/qbool.h" +#include "qapi/qmp/dispatch.h" #ifndef CONFIG_USER_ONLY #include "sysemu/arch_init.h" #endif
@@ -589,6 +590,14 @@ CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *infoa,cpu_info_from_model (baseline_info->model, &model, true); return baseline_info; } + +void arch_qmp_commands_init (void ) +{ +qmp_enable_command ("query-cpu-model-expansion" ); +qmp_enable_command ("query-cpu-model-baseline" ); +qmp_enable_command ("query-cpu-model-comparison" ); +qmp_enable_command ("query-cpu-model-definitions" ); +}#endif static void check_consistency (const S390CPUModel *model)
vl.c +10 -0
@@ -92,6 +92,7 @@ int main(int argc, char **argv)#include "sysemu/cpus.h" #include "sysemu/kvm.h" #include "qapi/qmp/qjson.h" +#include "qapi/qmp/dispatch.h" #include "qemu/option.h" #include "qemu/config-file.h" #include "qemu-options.h"
@@ -3031,6 +3032,15 @@ int main(int argc, char **argv, char **envp)module_call_init (MODULE_INIT_QOM );module_call_init (MODULE_INIT_QAPI ); +/* These commands are unavailable by default. Architectures that +* support them should enable them in arch_qmp_commands_init() +*/ +qmp_disable_command ("query-cpu-model-expansion" ); +qmp_disable_command ("query-cpu-model-baseline" ); +qmp_disable_command ("query-cpu-model-comparison" ); +qmp_disable_command ("query-cpu-model-definitions" ); +arch_qmp_commands_init (); +qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);qemu_add_drive_opts (&qemu_common_drive_opts);
Signature · 1 line
2.7.4
Quoted 10 lines · Eduardo Habkost
Instead of requiring clients to actually call the query-cpu-* commands to find out if they are implemented, remove them from the output of "query-commands", so clients know they are not available.
This is implemented by adding a new arch-specific hook:
arch_init_qmp_commands(), that can enable the available QMP commands (which are now disabled by default).Signed-off-by Eduardo Habkost <[email protected]>
Eric Blake just pointed me to qmp_unregister_commands_hack(). I will try to move the query-cpu-* rules there, in v2.
Signature · 1 line
Eduardo