Re: kern.maxlockf for byte range lock limit

2021-07-09 Thread David Holland
On Fri, Jul 09, 2021 at 03:27:57PM +, Emmanuel Dreyfus wrote:
 > I recently hit a bug where mariadb import failed befause of 
 > maxlocksperuid limit:a
 > http://mail-index.netbsd.org/netbsd-users/2021/07/09/msg027330.html
 > 
 > Attached is a patch that documents ENOMEM for fcntl() and flock()
 > and that adds a sysctl kern.maxlockf to make the limit configurable.

This was discussed somewhere briefly (probably on chat) a couple weeks
ago, with the conclusion that we should just make the limit something
like twice the maximum number of open files and forget about it. No
real need to add more knobs.

-- 
David A. Holland
dholl...@netbsd.org


re: kern.maxlockf for byte range lock limit

2021-07-09 Thread matthew green
> @@ -146,8 +146,10 @@
>  {
>   extern int kern_logsigexit; /* defined in kern/kern_sig.c */
>   extern fixpt_t ccpu;/* defined in kern/kern_synch.c */
>   extern int dumponpanic; /* defined in kern/subr_prf.c */
> + extern int maxlocksperuid;  /* defined in kern/vfs_lockf.c */
> +

this part is gross, please don't add more of this.

all of those variabes should be put in a header file so
that the declarations can't be different.  at the very
least, do that for your new one, even if you don't want
to fix the other 3 as well.

..or simply move the sysctl creation into the file that
owns that variable and you could avoid hard coding a
version number for it (not something we prefer since
the introduction of dynamic sysctl long ago.)


.mrg.


Re: Introduction to posix_spawn/chdir

2021-07-09 Thread Piyush Sachdeva
On Fri, Jun 25, 2021 at 9:03 PM Piyush Sachdeva
 wrote:
> Progress Update 2 (Week 3)
> Close to the end of Week 3, I would like to update that
> I have completed the code modifications that were required in the kernel 
> space.
> src/sys/kern/kern_exec.c , src/sys/kern/vfs_syscalls.c ,
> src/sys/sys/vfs_syscalls.h
>
> In the matter of organising my repository (pointed out by Christos Zoulas),
> I have mirrored The NetBSD source in my github repository as a separate 
> branch.
> However, I am using a main branch as a staging area for the TNF mirror,
> and will make commits to it once I can build the kernel and pass initial 
> tests.
> I hope this is alright.
> https://github.com/cosmologistPiyush/posix_spawn-chdir
>
> My plan for the coming weeks is to go through the atf(7) and mdoc(7) man 
> pages,
> in order to write test cases and document the work.
>

Progress Update 3 (week 5)
In the last two weeks, I worked on the test cases, documentation and
also tried to build the kernel.

The test cases have been completed, and the man page for
posix_spawn_file_actions_addchdir() is also near completion.
I did face a few minor build issues in my code, which I discussed on the irc.
But nothing major up till now.


It is my plan to try and have a successful build before the end of week 7.


Regards,
Piyush


kern.maxlockf for byte range lock limit

2021-07-09 Thread Emmanuel Dreyfus
Hello

I recently hit a bug where mariadb import failed befause of 
maxlocksperuid limit:a
http://mail-index.netbsd.org/netbsd-users/2021/07/09/msg027330.html

Attached is a patch that documents ENOMEM for fcntl() and flock()
and that adds a sysctl kern.maxlockf to make the limit configurable.

Opinions?

-- 
Emmanuel Dreyfus
m...@netbsd.org
Index: sys/sys/sysctl.h
===
RCS file: /cvsroot/src/sys/sys/sysctl.h,v
retrieving revision 1.233
diff -U4 -r1.233 sysctl.h
--- sys/sys/sysctl.h	13 Apr 2021 01:10:24 -	1.233
+++ sys/sys/sysctl.h	9 Jul 2021 14:29:32 -
@@ -274,8 +274,9 @@
 #define	KERN_SYSVIPC		82	/* node: SysV IPC parameters */
 #define	KERN_BOOTTIME		83	/* struct: time kernel was booted */
 #define	KERN_EVCNT		84	/* struct: evcnts */
 #define	KERN_SOFIXEDBUF		85	/* bool: fixed socket buffer sizes */
+#define	KERN_MAXLOCKF		86	/* int: max file locks per user */
 
 /*
  *  KERN_CLOCKRATE structure
  */
Index: sys/kern/init_sysctl.c
===
RCS file: /cvsroot/src/sys/kern/init_sysctl.c,v
retrieving revision 1.227
diff -U4 -r1.227 init_sysctl.c
--- sys/kern/init_sysctl.c	20 Sep 2020 12:51:57 -	1.227
+++ sys/kern/init_sysctl.c	9 Jul 2021 14:29:32 -
@@ -146,8 +146,10 @@
 {
 	extern int kern_logsigexit;	/* defined in kern/kern_sig.c */
 	extern fixpt_t ccpu;		/* defined in kern/kern_synch.c */
 	extern int dumponpanic;		/* defined in kern/subr_prf.c */
+	extern int maxlocksperuid;	/* defined in kern/vfs_lockf.c */
+
 	const struct sysctlnode *rnode;
 
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
@@ -587,8 +589,14 @@
 			CTLTYPE_INT, "messages",
 			SYSCTL_DESCR("Kernel message verbosity"),
 			sysctl_kern_messages, 0, NULL, 0,
 			CTL_KERN, CTL_CREATE, CTL_EOL);
+	sysctl_createv(clog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "maxlockf",
+		   SYSCTL_DESCR("File byte range lock limit per uid"),
+		   NULL, 0, , 0,
+		   CTL_KERN, KERN_MAXLOCKF, CTL_EOL);
 }
 
 SYSCTL_SETUP(sysctl_hw_misc_setup, "sysctl hw subtree misc setup")
 {
Index: lib/libc/sys/fcntl.2
===
RCS file: /cvsroot/src/lib/libc/sys/fcntl.2,v
retrieving revision 1.45
diff -U4 -r1.45 fcntl.2
--- lib/libc/sys/fcntl.2	27 Sep 2019 07:20:07 -	1.45
+++ lib/libc/sys/fcntl.2	9 Jul 2021 14:29:32 -
@@ -548,8 +548,19 @@
 .Fa cmd
 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 byte range lock limit for the current unprivilegied user 
+has been reached. It can be modifed using sysctl
+.Li kern.maxlockf .
 .It Bq Er ERANGE
 The argument
 .Fa cmd
 is
Index: lib/libc/sys/flock.2
===
RCS file: /cvsroot/src/lib/libc/sys/flock.2,v
retrieving revision 1.22
diff -U4 -r1.22 flock.2
--- lib/libc/sys/flock.2	15 Oct 2011 21:35:50 -	1.22
+++ lib/libc/sys/flock.2	9 Jul 2021 14:29:32 -
@@ -136,8 +136,12 @@
 .Dv LOCK_EX ,
 .Dv LOCK_SH ,
 or
 .Dv LOCK_UN .
+.It Bq Eq ENOMEM
+The file byte range lock limit for the current unprivilegied user 
+has been reached. It can be modifed using sysctl
+.Li kern.maxlockf .
 .It Bq Er EOPNOTSUPP
 The argument
 .Fa fd
 refers to an object other than a file.