Re: [PATCH v2 4/5] qapi: Implement deprecated-input={reject,crash} for enum values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Oct 09, 2021 at 02:09:43PM +0200, Markus Armbruster wrote:
> This copies the code implementing the policy from qapi/qmp-dispatch.c
> to qapi/qobject-input-visitor.c.  Tolerable, but if we acquire more
> copes, we should look into factoring them out.

copies

> 
> Signed-off-by: Markus Armbruster <armbru@xxxxxxxxxx>
> ---
>  docs/devel/qapi-code-gen.rst |  6 ++++--
>  qapi/compat.json             |  3 ++-
>  include/qapi/util.h          |  6 +++++-
>  qapi/qapi-visit-core.c       | 18 +++++++++++++++---
>  scripts/qapi/types.py        | 17 ++++++++++++++++-
>  5 files changed, 42 insertions(+), 8 deletions(-)
> 
> diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
> index 00334e9fb8..006a6f4a9a 100644
> --- a/docs/devel/qapi-code-gen.rst
> +++ b/docs/devel/qapi-code-gen.rst
> @@ -708,8 +708,10 @@ QEMU shows a certain behaviour.
>  Special features
>  ~~~~~~~~~~~~~~~~
>  
> -Feature "deprecated" marks a command, event, or struct member as
> -deprecated.  It is not supported elsewhere so far.
> +Feature "deprecated" marks a command, event, struct or enum member as

Do we want the comma before the conjunction?  (I've seen style guides
that recommend it, and style guides that discourage it; while I tend
to write by the former style, I usually don't care about the latter.
Rather, switching styles mid-patch caught my attention).

> +deprecated.  It is not supported elsewhere so far.  Interfaces so
> +marked may be withdrawn in future releases in accordance with QEMU's
> +deprecation policy.
>  
>  
> +++ b/qapi/qapi-visit-core.c
> @@ -393,7 +393,7 @@ static bool input_type_enum(Visitor *v, const char *name, int *obj,
>                              const QEnumLookup *lookup, Error **errp)
>  {
>      int64_t value;
> -    char *enum_str;
> +    g_autofree char *enum_str = NULL;

Nice change while touching the code.  Is it worth mentioning in the
commit message?

>  
>      if (!visit_type_str(v, name, &enum_str, errp)) {
>          return false;
> @@ -402,11 +402,23 @@ static bool input_type_enum(Visitor *v, const char *name, int *obj,
>      value = qapi_enum_parse(lookup, enum_str, -1, NULL);
>      if (value < 0) {
>          error_setg(errp, QERR_INVALID_PARAMETER, enum_str);
> -        g_free(enum_str);
>          return false;
>      }
>  
> -    g_free(enum_str);
> +    if (lookup->flags && (lookup->flags[value] & QAPI_ENUM_DEPRECATED)) {
> +        switch (v->compat_policy.deprecated_input) {
> +        case COMPAT_POLICY_INPUT_ACCEPT:
> +            break;
> +        case COMPAT_POLICY_INPUT_REJECT:
> +            error_setg(errp, "Deprecated value '%s' disabled by policy",
> +                       enum_str);
> +            return false;
> +        case COMPAT_POLICY_INPUT_CRASH:
> +        default:
> +            abort();
> +        }
> +    }
> +
>      *obj = value;
>      return true;
>  }

Grammar fixes are minor, so:

Reviewed-by: Eric Blake <eblake@xxxxxxxxxx>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux