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=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 AC4E8C282C7 for ; Thu, 31 Jan 2019 10:04:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B2C020B1F for ; Thu, 31 Jan 2019 10:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731957AbfAaKEJ (ORCPT ); Thu, 31 Jan 2019 05:04:09 -0500 Received: from www62.your-server.de ([213.133.104.62]:49634 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726316AbfAaKEI (ORCPT ); Thu, 31 Jan 2019 05:04:08 -0500 Received: from [78.46.172.3] (helo=sslproxy06.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1gp9CX-0002jS-56; Thu, 31 Jan 2019 11:04:05 +0100 Received: from [178.197.249.18] (helo=linux.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1gp9CW-000UHQ-Td; Thu, 31 Jan 2019 11:04:05 +0100 Subject: Re: [PATCH bpf-next v3 1/3] libbpf: move pr_*() functions to common header file To: Magnus Karlsson , bjorn.topel@intel.com, ast@kernel.org, netdev@vger.kernel.org, jakub.kicinski@netronome.com, bjorn.topel@gmail.com, qi.z.zhang@intel.com Cc: brouer@redhat.com References: <1548774737-16579-1-git-send-email-magnus.karlsson@intel.com> <1548774737-16579-2-git-send-email-magnus.karlsson@intel.com> From: Daniel Borkmann Message-ID: Date: Thu, 31 Jan 2019 11:04:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1548774737-16579-2-git-send-email-magnus.karlsson@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.2/25345/Thu Jan 31 07:13:04 2019) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. > @@ -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 */ >