From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2216E2882B7 for ; Sat, 2 May 2026 03:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777690818; cv=none; b=WYWCvS4kpFlLgf89Hcj4lg6IrM8N5aitLMXN6f/hcJvllyEGDEWO3OVOFVEBK/Cws6+PrmOQ1xFjAZOQmwxhLOcvAZ1tpI/0H+pBDin+mjsCysk5+8OTglw0gfn2JQ+/I5KBYT7qQlovjQ1+32WvdyuMxsWKQjT9wjO6sd0T/X0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777690818; c=relaxed/simple; bh=+gxVmyx7gt7FyTUAj00uPIOLxl/e1IPPElfYuZRc0yg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AAj9ytU0kebUHhSD26BynYLbMZmDkL2iRAC2s9U7gcxXnN6yMWpJg2NfMGxuUiaxokkjZXaimbgR4ocQO6/URdCfuauMfHSbt1NzPkHly27MvgFZUAUftUOupuFNQuqaFs9cWLcWMhvz9lmUb+V91KxhDTWGLs8ANqd6BfY7Erw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=fCmj9WiL; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="fCmj9WiL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1777690813; bh=uzH38PGr5vRTbwuwxn90zAdSiHVDIP/AViN4yLcxIHk=; h=From:Message-ID:From; b=fCmj9WiLtqdI+4KoGSuFWEB7AHT8J2HRlhLok4zKnfN2mPhFA3WU6iWnRZA5IL88U fZmXS1aTitXdT/SVWiVCEKkUOkqaTdmdqZG+lLPPyLRq6kWzofotrUa0p+sKBK8SPW LdNQUblVc4YwDIDK1pyInaZ1oKGKetO4M9LdObyM= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id E4D70C0AB2; Sat, 02 May 2026 05:00:13 +0200 (CEST) Date: Sat, 2 May 2026 05:00:06 +0200 From: Willy Tarreau To: David Laight Cc: Daniel Palmer , linux@weissschuh.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate() Message-ID: References: <20260430164125.1106350-1-daniel@thingy.jp> <20260430164125.1106350-2-daniel@thingy.jp> <20260501091831.7abc39f1@pumpkin> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260501091831.7abc39f1@pumpkin> On Fri, May 01, 2026 at 09:18:31AM +0100, David Laight wrote: > On Fri, 1 May 2026 01:41:24 +0900 > Daniel Palmer wrote: > > > Add fallocate(). > > > > Some special care is needed to put the offset and size > > into the syscall parameters for 32bit machines, x32, > > and mipsn32. > > > > For x32 we can just check if the kernel long size is the > > same as off_t and use the same path as x86_64. > > > > For mipsn32 we override the generic version and provide > > one that does the right thing. > > > > Signed-off-by: Daniel Palmer > > --- > > tools/include/nolibc/arch-mips.h | 11 +++++++++++ > > tools/include/nolibc/fcntl.h | 33 ++++++++++++++++++++++++++++++++ > > tools/include/nolibc/sys.h | 8 ++++++++ > > 3 files changed, 52 insertions(+) > > > > diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h > > index 1400653c76c1..e4e42f2bcaf4 100644 > > --- a/tools/include/nolibc/arch-mips.h > > +++ b/tools/include/nolibc/arch-mips.h > > @@ -6,6 +6,7 @@ > > > > #ifndef _NOLIBC_ARCH_MIPS_H > > #define _NOLIBC_ARCH_MIPS_H > > +#include > > > > #include "compiler.h" > > #include "crt.h" > > @@ -256,6 +257,16 @@ > > _arg4 ? -_num : _num; \ > > }) > > > > +/* The generic version of this will split offset and size for _ABIN32, > > + * override it and do the right thing here. > > + */ > > +static __attribute__((unused)) > > +int _sys_fallocate(int fd, int mode, off_t offset, off_t size) > > +{ > > + return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size); > > +} > > +#define _sys_fallocate _sys_fallocate > > + > > #endif /* _ABIO32 */ > > > > #ifndef NOLIBC_NO_RUNTIME > > diff --git a/tools/include/nolibc/fcntl.h b/tools/include/nolibc/fcntl.h > > index 014910a8e928..dbc99188a49e 100644 > > --- a/tools/include/nolibc/fcntl.h > > +++ b/tools/include/nolibc/fcntl.h > > @@ -14,6 +14,9 @@ > > #include "types.h" > > #include "sys.h" > > > > +/* For fallocate() modes */ > > +#include > > + > > /* > > * int openat(int dirfd, const char *path, int flags[, mode_t mode]); > > */ > > @@ -80,4 +83,34 @@ int creat(const char *path, mode_t mode) > > return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode); > > } > > > > +/* > > + * int fallocate(int fd, int mode, off_t offset, off_t size); > > + */ > > + > > +#if !defined(_sys_fallocate) > > +static __attribute__((unused)) > > +int _sys_fallocate(int fd, int mode, off_t offset, off_t size) > > +{ > > + /* > > + * For 32 bit machines __kernel_long_t will be 4, off_t will be 8 > > + * and we need to split offset and size, for 64 machines we can use > > + * the values as-is. > > + */ > > + const bool offsetsz_two_args = sizeof(__kernel_long_t) != sizeof(off_t); > > I don't think you care about the size of off_t. > Were it to be 4 the code would be badly wrong. > > > + > > + if (offsetsz_two_args) > > + return __nolibc_syscall6(__NR_fallocate, fd, mode, > > + __NOLIBC_LLARGPART(offset, 0), __NOLIBC_LLARGPART(offset, 1), > > + __NOLIBC_LLARGPART(size, 0), __NOLIBC_LLARGPART(size, 1)); > > + else > > + return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size); > > +} > > The above might be more readable as: > if (sizeof(__kernel_long_t) == 8) > /* 64 bit, values fit in single arguments */ > return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size); > > /* 32 bit, values need splitting, order depends on endianness */ > /* This test for endianness doesn't rely on any pre-processor defines */ > if (({union {int x; char c;} u; u.x = 1; u.c;})) > /* Little endian */ > return __nolibc_syscall6(__NR_fallocate, fd, mode, > offset, offset >> 32, size, size >> 32); > /* Big endian */ > return __nolibc_syscall6(__NR_fallocate, fd, mode, > offset >> 32, offset, size >> 32, size); Honestly David, I find Daniel's version way more readable :-) Precisely because the repeated variations are abstracted with this more readable macro. If it was used only once I could possibly agree. Even the endianness test is hard to read, better rely on __BYTE_ORDER__ for this. Cheers, Willy