Module Name:    src
Committed By:   martin
Date:           Tue Sep  7 17:12:21 UTC 2021

Modified Files:
        src/lib/libc/sys [netbsd-9]: fcntl.2 flock.2
        src/share/man/man7 [netbsd-9]: sysctl.7
        src/sys/kern [netbsd-9]: vfs_lockf.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1343):

        share/man/man7/sysctl.7: revision 1.153
        sys/kern/vfs_lockf.c: revision 1.74
        lib/libc/sys/fcntl.2: revision 1.46
        lib/libc/sys/flock.2: revision 1.23

Tie the maximum file lock per unprivilegied uid to kern.maxfiles

This makes the limit simple to raise at run time. While there, document
that fcntl(2) and flock(2) may return ENOMEM when this limit is reached.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.41.28.1 src/lib/libc/sys/fcntl.2
cvs rdiff -u -r1.22 -r1.22.44.1 src/lib/libc/sys/flock.2
cvs rdiff -u -r1.139.2.1 -r1.139.2.2 src/share/man/man7/sysctl.7
cvs rdiff -u -r1.73 -r1.73.60.1 src/sys/kern/vfs_lockf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/sys/fcntl.2
diff -u src/lib/libc/sys/fcntl.2:1.41 src/lib/libc/sys/fcntl.2:1.41.28.1
--- src/lib/libc/sys/fcntl.2:1.41	Sat Dec 28 20:03:22 2013
+++ src/lib/libc/sys/fcntl.2	Tue Sep  7 17:12:21 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fcntl.2,v 1.41 2013/12/28 20:03:22 dholland Exp $
+.\"	$NetBSD: fcntl.2,v 1.41.28.1 2021/09/07 17:12:21 martin Exp $
 .\"
 .\" Copyright (c) 1983, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -501,6 +501,10 @@ or
 .Dv F_SETLKW ,
 and satisfying the lock or unlock request would result in the
 number of locked regions in the system exceeding a system-imposed limit.
+.It Bq Er ENOMEM
+The file lock limit for the current unprivilegied user 
+has been reached. It can be modified using sysctl
+.Li kern.maxfiles .
 .It Bq Er ESRCH
 .Fa cmd
 is

Index: src/lib/libc/sys/flock.2
diff -u src/lib/libc/sys/flock.2:1.22 src/lib/libc/sys/flock.2:1.22.44.1
--- src/lib/libc/sys/flock.2:1.22	Sat Oct 15 21:35:50 2011
+++ src/lib/libc/sys/flock.2	Tue Sep  7 17:12:21 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: flock.2,v 1.22 2011/10/15 21:35:50 rmind Exp $
+.\"	$NetBSD: flock.2,v 1.22.44.1 2021/09/07 17:12:21 martin Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -137,6 +137,10 @@ does not include exactly one of
 .Dv LOCK_SH ,
 or
 .Dv LOCK_UN .
+.It Bq Eq ENOMEM
+The file lock limit for the current unprivilegied user 
+has been reached. It can be modifed using sysctl
+.Li kern.maxfiles .
 .It Bq Er EOPNOTSUPP
 The argument
 .Fa fd

Index: src/share/man/man7/sysctl.7
diff -u src/share/man/man7/sysctl.7:1.139.2.1 src/share/man/man7/sysctl.7:1.139.2.2
--- src/share/man/man7/sysctl.7:1.139.2.1	Mon Nov 18 19:45:00 2019
+++ src/share/man/man7/sysctl.7	Tue Sep  7 17:12:21 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sysctl.7,v 1.139.2.1 2019/11/18 19:45:00 martin Exp $
+.\"	$NetBSD: sysctl.7,v 1.139.2.2 2021/09/07 17:12:21 martin Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -736,6 +736,11 @@ Memory Mapped Files Option is available 
 otherwise\ 0.
 .It Li kern.maxfiles ( Dv KERN_MAXFILES )
 The maximum number of open files that may be open in the system.
+This also controls the maximum file locks per unprivilegied user 
+enforced by
+.Xr fnctl 2
+and 
+.Xr flock 2 .
 .It Li kern.maxpartitions ( Dv KERN_MAXPARTITIONS )
 The maximum number of partitions allowed per disk.
 .It Li kern.maxlwp

Index: src/sys/kern/vfs_lockf.c
diff -u src/sys/kern/vfs_lockf.c:1.73 src/sys/kern/vfs_lockf.c:1.73.60.1
--- src/sys/kern/vfs_lockf.c:1.73	Mon Jan 31 08:25:32 2011
+++ src/sys/kern/vfs_lockf.c	Tue Sep  7 17:12:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lockf.c,v 1.73 2011/01/31 08:25:32 dholland Exp $	*/
+/*	$NetBSD: vfs_lockf.c,v 1.73.60.1 2021/09/07 17:12:21 martin Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_lockf.c,v 1.73 2011/01/31 08:25:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lockf.c,v 1.73.60.1 2021/09/07 17:12:21 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -123,7 +123,7 @@ int	lockf_debug = 0;
  * so that the unlock can succeed.  If the unlocking causes too many splits,
  * however, you're totally cutoff.
  */
-int maxlocksperuid = 1024;
+#define MAXLOCKSPERUID (2 * maxfiles)
 
 #ifdef LOCKF_DEBUG
 /*
@@ -200,7 +200,7 @@ lf_alloc(int allowfail)
 	uip = uid_find(uid);
 	lcnt = atomic_inc_ulong_nv(&uip->ui_lockcnt);
 	if (uid && allowfail && lcnt >
-	    (allowfail == 1 ? maxlocksperuid : (maxlocksperuid * 2))) {
+	    (allowfail == 1 ? MAXLOCKSPERUID : (MAXLOCKSPERUID * 2))) {
 		atomic_dec_ulong(&uip->ui_lockcnt);
 		return NULL;
 	}

Reply via email to