[ovs-dev] [PATCH] ofproto-dpif-xlate: Log flow in XLATE_REPORT().

Ben Pfaff blp at ovn.org
Thu Aug 11 18:04:04 UTC 2016


On Thu, Aug 04, 2016 at 02:58:38PM -0700, Joe Stringer wrote:
> To assist debugging pipelines when resubmit resource checks fail, print
> the base_flow from the translation context. This base flow can then be
> used from ofproto/trace to figure out which parts of the pipeline lead
> to this translation error.
> 
> As far as I can see, the "## __VA_ARGS__" trick is a GCC thing rather
> than part of the C standard, but it successfully compiles on GCC 6.1.1,
> Clang 3.8.1, and the compiler that Appveyor CI uses so it seems like it
> is widely supported.
> 
> Signed-off-by: Joe Stringer <joe at ovn.org>

It's a little extra-tricky.  Any change you'd instead be willing to use
ds_put_format() on the local 'ds' instead?  Something like this:

    struct ds ds = DS_EMPTY_INITIALIZER;
    flow_format(&ds, &ctx->base_flow);
    ds_put_cstr(&ds, ": ");
    ds_put_format(&ds, __VA_LIST__);

It might be slightly slower but this is not a fast path.

>  ofproto/ofproto-dpif-xlate.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
> index 393854e4bfc7..73ab3e558f9d 100644
> --- a/ofproto/ofproto-dpif-xlate.c
> +++ b/ofproto/ofproto-dpif-xlate.c
> @@ -627,13 +627,20 @@ xlate_report(struct xlate_ctx *ctx, const char *format, ...)
>  
>  static struct vlog_rate_limit error_report_rl = VLOG_RATE_LIMIT_INIT(1, 5);
>  
> -#define XLATE_REPORT_ERROR(CTX, ...)                    \
> -    do {                                                \
> -        if (OVS_UNLIKELY((CTX)->xin->report_hook)) {    \
> -            xlate_report(CTX, __VA_ARGS__);             \
> -        } else {                                        \
> -            VLOG_ERR_RL(&error_report_rl, __VA_ARGS__); \
> -        }                                               \
> +#define XLATE_REORDER(LAST, DUMMY, ...) __VA_ARGS__, LAST
> +#define XLATE_REPORT_ERROR(CTX, FMT, ...)                               \
> +    do {                                                                \
> +        if (OVS_UNLIKELY((CTX)->xin->report_hook)) {                    \
> +            xlate_report(CTX, FMT, ## __VA_ARGS__);                     \
> +        } else {                                                        \
> +            struct ds ds = DS_EMPTY_INITIALIZER;                        \
> +                                                                        \
> +            flow_format(&ds, &ctx->base_flow);                          \
> +            VLOG_ERR_RL(&error_report_rl,                               \
> +                        XLATE_REORDER(ds_cstr(&ds), dummy,              \
> +                                      FMT": %s", ## __VA_ARGS__));      \
> +            ds_destroy(&ds);                                            \
> +        }                                                               \
>      } while (0)
>  
>  static inline void
> -- 
> 2.9.2
> 



More information about the dev mailing list