Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Tie the maximum file lock per unprivilegied uid to ...



details:   https://anonhg.NetBSD.org/src/rev/b7a27eaf19ca
branches:  trunk
changeset: 1022607:b7a27eaf19ca
user:      manu <manu%NetBSD.org@localhost>
date:      Tue Jul 27 09:32:55 2021 +0000

description:
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.

diffstat:

 lib/libc/sys/fcntl.2    |  13 ++++++++++++-
 lib/libc/sys/flock.2    |   6 +++++-
 share/man/man7/sysctl.7 |   7 ++++++-
 sys/kern/vfs_lockf.c    |   8 ++++----
 4 files changed, 27 insertions(+), 7 deletions(-)

diffs (104 lines):

diff -r 03c5b3c6762d -r b7a27eaf19ca lib/libc/sys/fcntl.2
--- a/lib/libc/sys/fcntl.2      Tue Jul 27 05:52:53 2021 +0000
+++ b/lib/libc/sys/fcntl.2      Tue Jul 27 09:32:55 2021 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: fcntl.2,v 1.45 2019/09/27 07:20:07 wiz Exp $
+.\"    $NetBSD: fcntl.2,v 1.46 2021/07/27 09:32:55 manu Exp $
 .\"
 .\" Copyright (c) 1983, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -549,6 +549,17 @@
 is
 .Dv F_GETPATH
 and insufficient memory is available.
+.Pp
+The argument
+.Fa cmd
+is
+.Dv F_GETLK ,
+.Dv F_SETLK ,
+or
+.Dv F_SETLKW ,
+and the file lock limit for the current unprivilegied user
+has been reached. It can be modifed using sysctl
+.Li kern.maxfiles .
 .It Bq Er ERANGE
 The argument
 .Fa cmd
diff -r 03c5b3c6762d -r b7a27eaf19ca lib/libc/sys/flock.2
--- a/lib/libc/sys/flock.2      Tue Jul 27 05:52:53 2021 +0000
+++ b/lib/libc/sys/flock.2      Tue Jul 27 09:32:55 2021 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: flock.2,v 1.22 2011/10/15 21:35:50 rmind Exp $
+.\"    $NetBSD: flock.2,v 1.23 2021/07/27 09:32:55 manu Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -137,6 +137,10 @@
 .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
diff -r 03c5b3c6762d -r b7a27eaf19ca share/man/man7/sysctl.7
--- a/share/man/man7/sysctl.7   Tue Jul 27 05:52:53 2021 +0000
+++ b/share/man/man7/sysctl.7   Tue Jul 27 09:32:55 2021 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sysctl.7,v 1.152 2021/07/13 16:56:43 nia Exp $
+.\"    $NetBSD: sysctl.7,v 1.153 2021/07/27 09:32:55 manu Exp $
 .\"
 .\" Copyright (c) 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -756,6 +756,11 @@
 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
diff -r 03c5b3c6762d -r b7a27eaf19ca sys/kern/vfs_lockf.c
--- a/sys/kern/vfs_lockf.c      Tue Jul 27 05:52:53 2021 +0000
+++ b/sys/kern/vfs_lockf.c      Tue Jul 27 09:32:55 2021 +0000
@@ -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.74 2021/07/27 09:32:55 manu 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.74 2021/07/27 09:32:55 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -123,7 +123,7 @@
  * 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 @@
        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;
        }



Home | Main Index | Thread Index | Old Index