Re: [PATCH v2 3/4] tools/nolibc: add support for fcntl()
From: Thomas Weißschuh
Date: Sat Dec 05 2026 - 09:57:02 EST
Hi!
On 2026-12-05 15:25:36+0100, Willy Tarreau wrote:
> On Wed, Dec 02, 2026 at 08:29:48AM +0100, Thomas Weißschuh wrote:
> > Add the fcntl() function.
> >
> > Special handling is necessary for 'struct flock'.
> > The definition from the UAPI headers is not large-file capable.
> > Provide a custom definition which is compatible with 'struct flock64'
> > on 32-bit systems and 'struct flock' on 64-bit ones.
> >
> > Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
> (...)
> > --- a/tools/include/nolibc/types.h
> > +++ b/tools/include/nolibc/types.h
> > @@ -32,6 +32,21 @@ struct timeval {
> > #include <linux/time.h>
> > #undef timeval
> >
> > +struct flock {
> > + short l_type;
> > + short l_whence;
> > + __kernel_loff_t l_start;
> > + __kernel_loff_t l_len;
> > + __kernel_pid_t l_pid;
> > +#if defined(__sparc__)
> > + short __pad;
> > +#endif
> > +};
>
> The commit message makes no mention of this pad and nothing here explains
> why it is necessary nor if other architectures might need it in the
> future. I suspect it might be that __kernel_pid_t would be 16-bit there,
> but I really don't know. I think a comment here in front of__pad to say
> why/when it's needed would help.
The pad member is necessary to match the UAPI definition. If we leave it
out the kernel will overwrite unrelated data. None of the existing
architectures will require this padding in the future as it would break
the ABI and I don't think new architectures will require it either.
As far as I can see this is unrelated to __kernel_pid_t.
I'll add a comment.
> Also I must confess I'm a bit confused because the same patch seems to mix
> fcntl() and flock(), and even _sys_fcntl() relies on flock definition.
> There might be a trick there but again it's not explained and the commit
> message only says that special handling is required for struct flock,
> which makes one wonder if this is a single feature or two distinct features
> with one depending on the other.
This is completely unrelated to flock().
> My impression is that this is mostly flock-centric and that it required to
> fix fcntl() first. If that is the case, I think that the fcntl() call should
> first do just that with a test on its own that for example does GETFD/SETFD
> or GETFL/SETFL, and another one specific to advisory locking because even
> the test_fcntl() function actually essentially tests locking from what I
> can see. This would also clarify small builds that drop CONFIG_FILE_LOCKING
> but which still have a properly working fcntl() implementation (which is
> already not trivial to get right especially in compat mode from what I seem
> to remember).
GETFD/GETFL are trivial and I did not deem it necessary to have a
testcase for them. My goal with the GETLK/SETLK test was not to verify
that the locking works but that the types line up correctly with what
the kernel expect. If we have a simpler fcntl() which does not handle
'struct flock' then that version is effectively broken if anyone uses
the locking operations. I can however split the commit up, the first
commit introduces the 64-bit 'struct flock' and the second adds fcntl().
Thomas