qapi: make HMP-specific schema entries conditional on CONFIG_HMP
Make the 'readline' value of MonitorMode and the 'human-monitor-command' command conditional on CONFIG_HMP, so they are only available when HMP support is compiled in. Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-40-9227de146347@redhat.com>
Marc-André Lureau committed
Aug 28, 2026 at 16:04 UTC
2d6d5508bb1f2304fbc7cec8ed053f7c293fd972
4 files changed
+17
-2
monitor/monitor.c
+10
@@ -740,13 +740,22 @@ int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp)
740
ERRP_GUARD();
741
742
if (!opts->has_mode) {
743
+#ifdef CONFIG_HMP
744
opts->mode = allow_hmp ? MONITOR_MODE_READLINE : MONITOR_MODE_CONTROL;
745
+#else
746
+ if (allow_hmp) {
747
+ error_setg(errp, "HMP support is not built in this QEMU");
748
+ return -1;
749
+ }
750
+ opts->mode = MONITOR_MODE_CONTROL;
751
+#endif
752
}
753
754
switch (opts->mode) {
755
case MONITOR_MODE_CONTROL:
756
monitor_new_qmp(opts->id, opts->chardev, opts->pretty, errp);
757
break;
758
+#ifdef CONFIG_HMP
759
case MONITOR_MODE_READLINE:
760
if (!allow_hmp) {
761
error_setg(errp, "Only QMP is supported");
@@ -758,6 +767,7 @@ int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp)
767
}
768
monitor_new_hmp(opts->id, opts->chardev, true, errp);
769
break;
770
+#endif /* CONFIG_HMP */
771
default:
772
g_assert_not_reached();
773
}
monitor/qmp-cmds.c
+2
@@ -162,6 +162,7 @@ void qmp_add_client(const char *protocol, const char *fdname,
162
}
163
}
164
165
+#ifdef CONFIG_HMP
166
char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
167
int64_t cpu_index, Error **errp)
168
{
@@ -187,6 +188,7 @@ out:
188
object_unref(hmp);
189
return output;
190
}
191
+#endif /* CONFIG_HMP */
192
193
static void __attribute__((__constructor__)) monitor_init_qmp_commands(void)
194
{
qapi/control.json
+3
-1
@@ -186,7 +186,9 @@
186
#
187
# Since: 5.0
188
##
189
-{ 'enum': 'MonitorMode', 'data': [ 'readline', 'control' ] }
189
+{ 'enum': 'MonitorMode', 'data': [
190
+ { 'name': 'readline', 'if': 'CONFIG_HMP' },
191
+ 'control' ] }
192
193
##
194
# @MonitorOptions:
qapi/misc.json
+2
-1
@@ -247,7 +247,8 @@
247
{ 'command': 'human-monitor-command',
248
'data': {'command-line': 'str', '*cpu-index': 'int'},
249
'returns': 'str',
250
- 'features': [ 'savevm-monitor-nodes' ] }
250
+ 'features': [ 'savevm-monitor-nodes' ],
251
+ 'if': 'CONFIG_HMP' }
252
253
##
254
# @getfd: