From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 948D9C282C7 for ; Thu, 31 Jan 2019 10:43:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 57F22218AC for ; Thu, 31 Jan 2019 10:43:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S3VZeWNy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732040AbfAaKnG (ORCPT ); Thu, 31 Jan 2019 05:43:06 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:54314 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726221AbfAaKnF (ORCPT ); Thu, 31 Jan 2019 05:43:05 -0500 Received: by mail-it1-f194.google.com with SMTP id i145so3011220ita.4 for ; Thu, 31 Jan 2019 02:43:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=x6xTFoEggP5JWmHVEwar64xb9OWkwC7DquX0wwwlm3Q=; b=S3VZeWNyMijzNmvXVlTVsXgvWKIeE4ydFzUnEWDJa9PLqBqOzFoKo9Lv/x+gVXC646 XBOS1rwfgsd+S/M3kMl6E2bx/IgK5LvBW3uGYuRTJUvmACCNWWydemBA2l5wJAW7Ap+o xWwyplb+Nq+41K8xxfPrKycH5B9X3DKJSRqRxHUXvIJVt9Z6Z9UHFglYu3I4XDoxgr8g 9ffYixQ7IeRHDgjgJfbZ3TLD+dB8lEvAH425RxcsUEVOjqLoqngQybCPhlinakijbWSZ jmV/zcg0VnndogVwTAmIWPxlG2NmvKikwcjJRiQJDDCZ6xCIVbiHeBOVm47r2sik7h9Z Uhdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=x6xTFoEggP5JWmHVEwar64xb9OWkwC7DquX0wwwlm3Q=; b=LOwCusCJX5qNK9q6D+6EXtie3Rup0y/XO29FrQ3uYT7j9CJSuvQmK1wOzB//kF8EDF vc49/wGm65ISYf/oEzIGZOnjKfaRTZTWAR86Daq+BxV8h0s98QuYrURFfqhPrm8Auama xjXK+Mk7uRo8HrXuOnZkJX0+NCLH25pq/Zm1M5n/g1hkysoED6A+i1cUoaa6stLgsaFp 3OX8aJpJZgdLBqVUtqZRYkmLLwb4xc6lEiJ6lXzZ68NN6e0RlW1chTH0uy4UY9SVgQlo 8x3NZXu1NKPuE1goq5Iqhu+ITGGw212+VqLVbIsb71l4hnnAc2rNs9SZ0067hetbFQT8 +3Kw== X-Gm-Message-State: AHQUAuYhKw4HCqQ/ot5ufuA8InHaGP/E6TwA/4cFbIgp2Lr+IB7etCMQ MAgn2jipDMu5TglpvkcRaoH5T76Bcu5chRdM0AU= X-Google-Smtp-Source: ALg8bN7cKw8sv/NgysUx3G4BVOIIUPXVVmYWl5XZjc79IMhYR8wr5Pu3LnzBb2aaDWxg6MOmT5b3hmGJmyfnjppuLKs= X-Received: by 2002:a24:7284:: with SMTP id x126mr17960706itc.15.1548931384477; Thu, 31 Jan 2019 02:43:04 -0800 (PST) MIME-Version: 1.0 References: <1548774737-16579-1-git-send-email-magnus.karlsson@intel.com> <1548774737-16579-2-git-send-email-magnus.karlsson@intel.com> In-Reply-To: From: Magnus Karlsson Date: Thu, 31 Jan 2019 11:42:52 +0100 Message-ID: Subject: Re: [PATCH bpf-next v3 1/3] libbpf: move pr_*() functions to common header file To: Daniel Borkmann Cc: Magnus Karlsson , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , ast@kernel.org, Network Development , Jakub Kicinski , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , "Zhang, Qi Z" , Jesper Dangaard Brouer Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, Jan 31, 2019 at 11:07 AM Daniel Borkmann wrote: > > On 01/29/2019 04:12 PM, Magnus Karlsson wrote: > > Move the pr_*() functions in libbpf.c to a common header file called > > libbpf_internal.h. This so that the later libbpf AF_XDP helper library > > code in xsk.c can use these printing functions too. > > > > Signed-off-by: Magnus Karlsson > > --- > > tools/lib/bpf/libbpf.c | 30 +----------------------------- > > tools/lib/bpf/libbpf_internal.h | 41 +++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 42 insertions(+), 29 deletions(-) > > create mode 100644 tools/lib/bpf/libbpf_internal.h > > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > > index 2ccde17..1d7fe26 100644 > > --- a/tools/lib/bpf/libbpf.c > > +++ b/tools/lib/bpf/libbpf.c > > @@ -39,6 +39,7 @@ > > #include > > > > #include "libbpf.h" > > +#include "libbpf_internal.h" > > #include "bpf.h" > > #include "btf.h" > > #include "str_error.h" > > @@ -51,34 +52,6 @@ > > #define BPF_FS_MAGIC 0xcafe4a11 > > #endif > > > > -#define __printf(a, b) __attribute__((format(printf, a, b))) > > - > > -__printf(1, 2) > > -static int __base_pr(const char *format, ...) > > -{ > > - va_list args; > > - int err; > > - > > - va_start(args, format); > > - err = vfprintf(stderr, format, args); > > - va_end(args); > > - return err; > > -} > > - > > -static __printf(1, 2) libbpf_print_fn_t __pr_warning = __base_pr; > > -static __printf(1, 2) libbpf_print_fn_t __pr_info = __base_pr; > > -static __printf(1, 2) libbpf_print_fn_t __pr_debug; > > - > > -#define __pr(func, fmt, ...) \ > > -do { \ > > - if ((func)) \ > > - (func)("libbpf: " fmt, ##__VA_ARGS__); \ > > -} while (0) > > - > > -#define pr_warning(fmt, ...) __pr(__pr_warning, fmt, ##__VA_ARGS__) > > -#define pr_info(fmt, ...) __pr(__pr_info, fmt, ##__VA_ARGS__) > > -#define pr_debug(fmt, ...) __pr(__pr_debug, fmt, ##__VA_ARGS__) > > - > > void libbpf_set_print(libbpf_print_fn_t warn, > > libbpf_print_fn_t info, > > libbpf_print_fn_t debug) > > @@ -96,7 +69,6 @@ void libbpf_set_print(libbpf_print_fn_t warn, > > goto out; \ > > } while(0) > > > > - > > /* Copied from tools/perf/util/util.h */ > > #ifndef zfree > > # define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) > > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h > > new file mode 100644 > > index 0000000..951c078 > > --- /dev/null > > +++ b/tools/lib/bpf/libbpf_internal.h > > Just really minor nit: lets name the header utils.h or such. It would also make > sense to move the zfree() and zclose() to this and make use of it. Will fix. Thanks: Magnus > > @@ -0,0 +1,41 @@ > > +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ > > + > > +/* > > + * Common internal libbpf functions and definitions. > > + * > > + * Copyright (C) 2013-2015 Alexei Starovoitov > > + * Copyright (C) 2015 Wang Nan > > + * Copyright (C) 2015 Huawei Inc. > > + */ > > +#ifndef __LIBBPF_LIBBPF_INTERNAL_H > > +#define __LIBBPF_LIBBPF_INTERNAL_H > > + > > +#define __printf(a, b) __attribute__((format(printf, a, b))) > > + > > +__printf(1, 2) > > +static int __base_pr(const char *format, ...) > > +{ > > + va_list args; > > + int err; > > + > > + va_start(args, format); > > + err = vfprintf(stderr, format, args); > > + va_end(args); > > + return err; > > +} > > + > > +static __maybe_unused __printf(1, 2) libbpf_print_fn_t __pr_warning = __base_pr; > > +static __maybe_unused __printf(1, 2) libbpf_print_fn_t __pr_info = __base_pr; > > +static __maybe_unused __printf(1, 2) libbpf_print_fn_t __pr_debug; > > + > > +#define __pr(func, fmt, ...) \ > > +do { \ > > + if ((func)) \ > > + (func)("libbpf: " fmt, ##__VA_ARGS__); \ > > +} while (0) > > + > > +#define pr_warning(fmt, ...) __pr(__pr_warning, fmt, ##__VA_ARGS__) > > +#define pr_info(fmt, ...) __pr(__pr_info, fmt, ##__VA_ARGS__) > > +#define pr_debug(fmt, ...) __pr(__pr_debug, fmt, ##__VA_ARGS__) > > + > > +#endif /* __LIBBPF_LIBBPF_INTERNAL_H */ > > >