qemu-options: New -compat to set policy for deprecated interfaces

New option -compat lets you configure what to do when deprecated
interfaces get used.  This is intended for testing users of the
management interfaces.  It is experimental.

-compat deprecated-input=<input-policy> configures what to do when
deprecated input is received.  Input policy can be "accept" (accept
silently), or "reject" (reject the request with an error).

-compat deprecated-output=<out-policy> configures what to do when
deprecated output is sent.  Output policy can be "accept" (pass on
unchanged), or "hide" (filter out the deprecated parts).

Default is "accept".  Policies other than "accept" are implemented
later in this series.

For now, -compat covers only syntactic aspects of QMP, i.e. stuff
tagged with feature 'deprecated'.  We may want to extend it to cover
semantic aspects, CLI, and experimental features.

Note that there is no good way for management application to detect
presence of -compat: it's not visible output of query-qmp-schema or
query-command-line-options.  Tolerable, because it's meant for
testing.  If running with -compat fails, skip the test.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210318155519.1224118-3-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2021-03-18 16:55:10 +01:00
parent b1eee9bb6d
commit 6dd75472d5
7 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,20 @@
/*
* Policy for handling "funny" management interfaces
*
* Copyright (C) 2020 Red Hat, Inc.
*
* Authors:
* Markus Armbruster <armbru@redhat.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or
* later. See the COPYING file in the top-level directory.
*/
#ifndef QAPI_COMPAT_POLICY_H
#define QAPI_COMPAT_POLICY_H
#include "qapi/qapi-types-compat.h"
extern CompatPolicy compat_policy;
#endif

51
qapi/compat.json Normal file
View File

@ -0,0 +1,51 @@
# -*- Mode: Python -*-
##
# = Compatibility policy
##
##
# @CompatPolicyInput:
#
# Policy for handling "funny" input.
#
# @accept: Accept silently
# @reject: Reject with an error
#
# Since: 6.0
##
{ 'enum': 'CompatPolicyInput',
'data': [ 'accept', 'reject' ] }
##
# @CompatPolicyOutput:
#
# Policy for handling "funny" output.
#
# @accept: Pass on unchanged
# @hide: Filter out
#
# Since: 6.0
##
{ 'enum': 'CompatPolicyOutput',
'data': [ 'accept', 'hide' ] }
##
# @CompatPolicy:
#
# Policy for handling deprecated management interfaces.
#
# This is intended for testing users of the management interfaces.
#
# Limitation: covers only syntactic aspects of QMP, i.e. stuff tagged
# with feature 'deprecated'. We may want to extend it to cover
# semantic aspects, CLI, and experimental features.
#
# @deprecated-input: how to handle deprecated input (default 'accept')
# @deprecated-output: how to handle deprecated output (default 'accept')
#
# Since: 6.0
##
{ 'struct': 'CompatPolicy',
'data': { '*deprecated-input': 'CompatPolicyInput',
'*deprecated-output': 'CompatPolicyOutput' } }

View File

@ -25,6 +25,7 @@ qapi_all_modules = [
'block-export', 'block-export',
'char', 'char',
'common', 'common',
'compat',
'control', 'control',
'crypto', 'crypto',
'dump', 'dump',

View File

@ -79,6 +79,7 @@
{ 'include': 'migration.json' } { 'include': 'migration.json' }
{ 'include': 'transaction.json' } { 'include': 'transaction.json' }
{ 'include': 'trace.json' } { 'include': 'trace.json' }
{ 'include': 'compat.json' }
{ 'include': 'control.json' } { 'include': 'control.json' }
{ 'include': 'introspect.json' } { 'include': 'introspect.json' }
{ 'include': 'qom.json' } { 'include': 'qom.json' }

View File

@ -14,6 +14,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "block/aio.h" #include "block/aio.h"
#include "qapi/compat-policy.h"
#include "qapi/error.h" #include "qapi/error.h"
#include "qapi/qmp/dispatch.h" #include "qapi/qmp/dispatch.h"
#include "qapi/qmp/qdict.h" #include "qapi/qmp/qdict.h"
@ -23,6 +24,8 @@
#include "qemu/coroutine.h" #include "qemu/coroutine.h"
#include "qemu/main-loop.h" #include "qemu/main-loop.h"
CompatPolicy compat_policy;
static QDict *qmp_dispatch_check_obj(QDict *dict, bool allow_oob, static QDict *qmp_dispatch_check_obj(QDict *dict, bool allow_oob,
Error **errp) Error **errp)
{ {

View File

@ -3507,6 +3507,26 @@ DEFHEADING()
DEFHEADING(Debug/Expert options:) DEFHEADING(Debug/Expert options:)
DEF("compat", HAS_ARG, QEMU_OPTION_compat,
"-compat [deprecated-input=accept|reject][,deprecated-output=accept|hide]\n"
" Policy for handling deprecated management interfaces\n",
QEMU_ARCH_ALL)
SRST
``-compat [deprecated-input=@var{input-policy}][,deprecated-output=@var{output-policy}]``
Set policy for handling deprecated management interfaces (experimental):
``deprecated-input=accept`` (default)
Accept deprecated commands and arguments
``deprecated-input=reject``
Reject deprecated commands and arguments
``deprecated-output=accept`` (default)
Emit deprecated command results and events
``deprecated-output=hide``
Suppress deprecated command results and events
Limitation: covers only syntactic aspects of QMP.
ERST
DEF("fw_cfg", HAS_ARG, QEMU_OPTION_fwcfg, DEF("fw_cfg", HAS_ARG, QEMU_OPTION_fwcfg,
"-fw_cfg [name=]<name>,file=<file>\n" "-fw_cfg [name=]<name>,file=<file>\n"
" add named fw_cfg entry with contents from file\n" " add named fw_cfg entry with contents from file\n"

View File

@ -29,6 +29,7 @@
#include "exec/cpu-common.h" #include "exec/cpu-common.h"
#include "hw/boards.h" #include "hw/boards.h"
#include "hw/qdev-properties.h" #include "hw/qdev-properties.h"
#include "qapi/compat-policy.h"
#include "qapi/error.h" #include "qapi/error.h"
#include "qapi/qmp/qdict.h" #include "qapi/qmp/qdict.h"
#include "qapi/qmp/qjson.h" #include "qapi/qmp/qjson.h"
@ -114,6 +115,7 @@
#include "sysemu/replay.h" #include "sysemu/replay.h"
#include "qapi/qapi-events-run-state.h" #include "qapi/qapi-events-run-state.h"
#include "qapi/qapi-visit-block-core.h" #include "qapi/qapi-visit-block-core.h"
#include "qapi/qapi-visit-compat.h"
#include "qapi/qapi-visit-ui.h" #include "qapi/qapi-visit-ui.h"
#include "qapi/qapi-commands-block-core.h" #include "qapi/qapi-commands-block-core.h"
#include "qapi/qapi-commands-migration.h" #include "qapi/qapi-commands-migration.h"
@ -3458,6 +3460,21 @@ void qemu_init(int argc, char **argv, char **envp)
enable_mlock = qemu_opt_get_bool(opts, "mem-lock", false); enable_mlock = qemu_opt_get_bool(opts, "mem-lock", false);
enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", false); enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", false);
break; break;
case QEMU_OPTION_compat:
{
CompatPolicy *opts;
Visitor *v;
v = qobject_input_visitor_new_str(optarg, NULL,
&error_fatal);
visit_type_CompatPolicy(v, NULL, &opts, &error_fatal);
QAPI_CLONE_MEMBERS(CompatPolicy, &compat_policy, opts);
qapi_free_CompatPolicy(opts);
visit_free(v);
break;
}
case QEMU_OPTION_msg: case QEMU_OPTION_msg:
opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg, opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg,
false); false);