flock on directory

From: Peter Blok <pblok_at_bsd4all.org>
Date: Tue, 26 Nov 2024 10:08:47 UTC
Hi,

I’m trying to run diskless. Both server and client are recent 14-stable. When running diskless NFSv3 locking doesn’t work, although everything is setup correctly. ( Will investigate later ). If I mount with nolockd everything looks ok - no messages.

I fixed NFSv4 as a client and it works, but atrun complains about not being able to flock with LOCK_EX /var/at/jobs, returning EINVAL According to the manpage this is correct, because the object is not a file.

    if ((spool = opendir(".")) == NULL)
        perr("cannot read %s", ATJOB_DIR);
 
    if (flock(dirfd(spool), LOCK_EX) == -1)
        perr("cannot lock %s", ATJOB_DIR);

On a zfs or ufs directory the flock works without returning EINVAL, which is not in line with the manpage.

What would be the approriate thing to change? Should NFS also allow a flock on a directory, or should we always return EINVAL on any directory on any file-system? The latter would probably cause some churn

Peter