public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 2/8] log: Only check for FALLOC_FL_COLLAPSE_RANGE availability at runtime
Date: Wed, 6 Nov 2024 20:10:41 +0100	[thread overview]
Message-ID: <20241106201041.1e385fc0@elisabeth> (raw)
In-Reply-To: <20241106065421.2568179-3-david@gibson.dropbear.id.au>

On Wed,  6 Nov 2024 17:54:15 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> log.c has several #ifdefs on FALLOC_FL_COLLAPSE_RANGE that won't attempt
> to use it if not defined.  But even if the value is defined at compile
> time, it might not be available in the runtime kernel, so we need to check
> for errors from a fallocate() call and fall back to other methods.
> 
> Simplify this to only need the runtime check by using linux_dep.h to define
> FALLOC_FL_COLLAPSE_RANGE if it's not in the kernel headers.
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  Makefile    | 5 -----
>  linux_dep.h | 6 ++++++
>  log.c       | 9 +--------
>  3 files changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 56bf2e8..cb91535 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -59,11 +59,6 @@ ifeq ($(shell :|$(CC) -fstack-protector-strong -S -xc - -o - >/dev/null 2>&1; ec
>  	FLAGS += -fstack-protector-strong
>  endif
>  
> -C := \#define _GNU_SOURCE\n\#include <fcntl.h>\nint x = FALLOC_FL_COLLAPSE_RANGE;
> -ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?),0)
> -	EXTRA_SYSCALLS += fallocate
> -endif
> -
>  prefix		?= /usr/local
>  exec_prefix	?= $(prefix)
>  bindir		?= $(exec_prefix)/bin
> diff --git a/linux_dep.h b/linux_dep.h
> index 8921623..eae9c3c 100644
> --- a/linux_dep.h
> +++ b/linux_dep.h
> @@ -119,4 +119,10 @@ struct tcp_info_linux {
>  						 */
>  };
>  
> +#include <linux/falloc.h>
> +
> +#ifndef FALLOC_FL_COLLAPSE_RANGE
> +#define FALLOC_FL_COLLAPSE_RANGE	0x08
> +#endif
> +
>  #endif /* LINUX_DEP_H */
> diff --git a/log.c b/log.c
> index 19f1d98..3c1b39c 100644
> --- a/log.c
> +++ b/log.c
> @@ -92,7 +92,6 @@ const char *logfile_prefix[] = {
>  	"         ",		/* LOG_DEBUG */
>  };
>  
> -#ifdef FALLOC_FL_COLLAPSE_RANGE

This breaks the build on Alpine (and I suppose on Void Linux too, that
is, whenever we build against musl):

log.c: In function 'logfile_rotate':
log.c:207:28: error: 'FALLOC_FL_COLLAPSE_RANGE' undeclared (first use in this function)
  207 |         if (!fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, 0, log_cut_size))
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~
log.c:207:28: note: each undeclared identifier is reported only once for each function it appears in

and it's fixed by including linux_dep.h from log.c.

-- 
Stefano


  reply	other threads:[~2024-11-06 19:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-06  6:54 [PATCH 0/8] Avoid running cppcheck on system headers David Gibson
2024-11-06  6:54 ` [PATCH 1/8] linux_dep: Generalise tcp_info.h to handling Linux extension compatibility David Gibson
2024-11-06  6:54 ` [PATCH 2/8] log: Only check for FALLOC_FL_COLLAPSE_RANGE availability at runtime David Gibson
2024-11-06 19:10   ` Stefano Brivio [this message]
2024-11-06 20:54     ` David Gibson
2024-11-06  6:54 ` [PATCH 3/8] linux_dep: Move close_range() conditional handling to linux_dep.h David Gibson
2024-11-06 19:10   ` Stefano Brivio
2024-11-06 20:56     ` David Gibson
2024-11-06  6:54 ` [PATCH 4/8] linux_dep: Fix CLOSE_RANGE_UNSHARE availability handling David Gibson
2024-11-06 19:12   ` Stefano Brivio
2024-11-06 21:01     ` David Gibson
2024-11-07  7:03       ` Stefano Brivio
2024-11-06  6:54 ` [PATCH 5/8] ndp: Use const pointer for ndp_ns packet David Gibson
2024-11-06  6:54 ` [PATCH 6/8] udp: Don't dereference uflow before NULL check in udp_reply_sock_handler() David Gibson
2024-11-06  6:54 ` [PATCH 7/8] util: Work around cppcheck bug 6936 David Gibson
2024-11-06  6:54 ` [PATCH 8/8] cppcheck: Don't check the system headers David Gibson
2024-11-07 14:55 ` [PATCH 0/8] Avoid running cppcheck on " Stefano Brivio
2024-11-07 23:58   ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241106201041.1e385fc0@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).