History log of /openbsd-current/sys/kern/kern_acct.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.48 13-Apr-2024 jsg

correct indentation

no functional change, found by smatch warnings
ok miod@ bluhm@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.47 14-Aug-2022 jsg

remove unneeded includes in sys/kern
ok mpi@ miod@


Revision tags: OPENBSD_7_1_BASE
# 1.46 22-Feb-2022 deraadt

Since other exported commandnames were increased to 24 and graduated into
proper strings, adapt struct acct's ac_comm similarily. While here increase
ac_mem to 32-bits, increase ac_flag from 8 to 32 bits for future extensions,
add ac_pid for forensics, and reorder the structure to avoid compiler pads.
More work remains in the sa(8) command to use ac_pid better.
This is a flag day for the acct file format, new/old files/tools are incompatible.
ok bluhm millert


# 1.45 13-Dec-2021 deraadt

acct(4) ac_tty shouldn't need NODEV from sys/param.h (which is kernel API),
-1 is sufficient to indicate the process had no controlling tty, removing
one more sys/param.h include in our userland
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.44 29-Jan-2021 rob

Whitespace.


Revision tags: OPENBSD_6_8_BASE
# 1.43 26-Jul-2020 rob

Reference unveil(2) in system accounting and daily.8.
Reminder that unveil does not kill from brynet and gsoares.
Wording tweaks from jmc; feedback from deraadt.

ok jmc@, millert@, solene@, "fine with me" deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.42 22-Oct-2019 cheloha

struct proc: change ps_start from utc time to uptime

Allows us to determine how long a process has been running, even if the
UTC clock jumps.

With help from bluhm@ and millert@, who squashed several bugs.

ok bluhm@ millert@


Revision tags: OPENBSD_6_6_BASE
# 1.41 06-Oct-2019 beck

Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.

sweep tree to correct NDIINT op and flags ahead of time. document
the requirement. This allows KERNELPATH to be used to bypass
unveil for crash dumps with nosuidcoredump=2 or 3

ok visa@ deraadt@ florian@


# 1.40 15-Aug-2019 anton

Serialize access to the vnode pointers associated with acct(2) system
accounting. Prevents a race where the acct thread and the acct(2)
syscall both tries to close a vnode.

ok visa@

Reported-by: syzbot+bf2ac4d4fa9ee92903b8@syzkaller.appspotmail.com


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.47 14-Aug-2022 jsg

remove unneeded includes in sys/kern
ok mpi@ miod@


Revision tags: OPENBSD_7_1_BASE
# 1.46 22-Feb-2022 deraadt

Since other exported commandnames were increased to 24 and graduated into
proper strings, adapt struct acct's ac_comm similarily. While here increase
ac_mem to 32-bits, increase ac_flag from 8 to 32 bits for future extensions,
add ac_pid for forensics, and reorder the structure to avoid compiler pads.
More work remains in the sa(8) command to use ac_pid better.
This is a flag day for the acct file format, new/old files/tools are incompatible.
ok bluhm millert


# 1.45 13-Dec-2021 deraadt

acct(4) ac_tty shouldn't need NODEV from sys/param.h (which is kernel API),
-1 is sufficient to indicate the process had no controlling tty, removing
one more sys/param.h include in our userland
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.44 29-Jan-2021 rob

Whitespace.


Revision tags: OPENBSD_6_8_BASE
# 1.43 26-Jul-2020 rob

Reference unveil(2) in system accounting and daily.8.
Reminder that unveil does not kill from brynet and gsoares.
Wording tweaks from jmc; feedback from deraadt.

ok jmc@, millert@, solene@, "fine with me" deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.42 22-Oct-2019 cheloha

struct proc: change ps_start from utc time to uptime

Allows us to determine how long a process has been running, even if the
UTC clock jumps.

With help from bluhm@ and millert@, who squashed several bugs.

ok bluhm@ millert@


Revision tags: OPENBSD_6_6_BASE
# 1.41 06-Oct-2019 beck

Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.

sweep tree to correct NDIINT op and flags ahead of time. document
the requirement. This allows KERNELPATH to be used to bypass
unveil for crash dumps with nosuidcoredump=2 or 3

ok visa@ deraadt@ florian@


# 1.40 15-Aug-2019 anton

Serialize access to the vnode pointers associated with acct(2) system
accounting. Prevents a race where the acct thread and the acct(2)
syscall both tries to close a vnode.

ok visa@

Reported-by: syzbot+bf2ac4d4fa9ee92903b8@syzkaller.appspotmail.com


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.46 22-Feb-2022 deraadt

Since other exported commandnames were increased to 24 and graduated into
proper strings, adapt struct acct's ac_comm similarily. While here increase
ac_mem to 32-bits, increase ac_flag from 8 to 32 bits for future extensions,
add ac_pid for forensics, and reorder the structure to avoid compiler pads.
More work remains in the sa(8) command to use ac_pid better.
This is a flag day for the acct file format, new/old files/tools are incompatible.
ok bluhm millert


# 1.45 13-Dec-2021 deraadt

acct(4) ac_tty shouldn't need NODEV from sys/param.h (which is kernel API),
-1 is sufficient to indicate the process had no controlling tty, removing
one more sys/param.h include in our userland
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.44 29-Jan-2021 rob

Whitespace.


Revision tags: OPENBSD_6_8_BASE
# 1.43 26-Jul-2020 rob

Reference unveil(2) in system accounting and daily.8.
Reminder that unveil does not kill from brynet and gsoares.
Wording tweaks from jmc; feedback from deraadt.

ok jmc@, millert@, solene@, "fine with me" deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.42 22-Oct-2019 cheloha

struct proc: change ps_start from utc time to uptime

Allows us to determine how long a process has been running, even if the
UTC clock jumps.

With help from bluhm@ and millert@, who squashed several bugs.

ok bluhm@ millert@


Revision tags: OPENBSD_6_6_BASE
# 1.41 06-Oct-2019 beck

Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.

sweep tree to correct NDIINT op and flags ahead of time. document
the requirement. This allows KERNELPATH to be used to bypass
unveil for crash dumps with nosuidcoredump=2 or 3

ok visa@ deraadt@ florian@


# 1.40 15-Aug-2019 anton

Serialize access to the vnode pointers associated with acct(2) system
accounting. Prevents a race where the acct thread and the acct(2)
syscall both tries to close a vnode.

ok visa@

Reported-by: syzbot+bf2ac4d4fa9ee92903b8@syzkaller.appspotmail.com


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.45 13-Dec-2021 deraadt

acct(4) ac_tty shouldn't need NODEV from sys/param.h (which is kernel API),
-1 is sufficient to indicate the process had no controlling tty, removing
one more sys/param.h include in our userland
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.44 29-Jan-2021 rob

Whitespace.


Revision tags: OPENBSD_6_8_BASE
# 1.43 26-Jul-2020 rob

Reference unveil(2) in system accounting and daily.8.
Reminder that unveil does not kill from brynet and gsoares.
Wording tweaks from jmc; feedback from deraadt.

ok jmc@, millert@, solene@, "fine with me" deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.42 22-Oct-2019 cheloha

struct proc: change ps_start from utc time to uptime

Allows us to determine how long a process has been running, even if the
UTC clock jumps.

With help from bluhm@ and millert@, who squashed several bugs.

ok bluhm@ millert@


Revision tags: OPENBSD_6_6_BASE
# 1.41 06-Oct-2019 beck

Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.

sweep tree to correct NDIINT op and flags ahead of time. document
the requirement. This allows KERNELPATH to be used to bypass
unveil for crash dumps with nosuidcoredump=2 or 3

ok visa@ deraadt@ florian@


# 1.40 15-Aug-2019 anton

Serialize access to the vnode pointers associated with acct(2) system
accounting. Prevents a race where the acct thread and the acct(2)
syscall both tries to close a vnode.

ok visa@

Reported-by: syzbot+bf2ac4d4fa9ee92903b8@syzkaller.appspotmail.com


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.44 29-Jan-2021 rob

Whitespace.


Revision tags: OPENBSD_6_8_BASE
# 1.43 26-Jul-2020 rob

Reference unveil(2) in system accounting and daily.8.
Reminder that unveil does not kill from brynet and gsoares.
Wording tweaks from jmc; feedback from deraadt.

ok jmc@, millert@, solene@, "fine with me" deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.42 22-Oct-2019 cheloha

struct proc: change ps_start from utc time to uptime

Allows us to determine how long a process has been running, even if the
UTC clock jumps.

With help from bluhm@ and millert@, who squashed several bugs.

ok bluhm@ millert@


Revision tags: OPENBSD_6_6_BASE
# 1.41 06-Oct-2019 beck

Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.

sweep tree to correct NDIINT op and flags ahead of time. document
the requirement. This allows KERNELPATH to be used to bypass
unveil for crash dumps with nosuidcoredump=2 or 3

ok visa@ deraadt@ florian@


# 1.40 15-Aug-2019 anton

Serialize access to the vnode pointers associated with acct(2) system
accounting. Prevents a race where the acct thread and the acct(2)
syscall both tries to close a vnode.

ok visa@

Reported-by: syzbot+bf2ac4d4fa9ee92903b8@syzkaller.appspotmail.com


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.43 26-Jul-2020 rob

Reference unveil(2) in system accounting and daily.8.
Reminder that unveil does not kill from brynet and gsoares.
Wording tweaks from jmc; feedback from deraadt.

ok jmc@, millert@, solene@, "fine with me" deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.42 22-Oct-2019 cheloha

struct proc: change ps_start from utc time to uptime

Allows us to determine how long a process has been running, even if the
UTC clock jumps.

With help from bluhm@ and millert@, who squashed several bugs.

ok bluhm@ millert@


Revision tags: OPENBSD_6_6_BASE
# 1.41 06-Oct-2019 beck

Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.

sweep tree to correct NDIINT op and flags ahead of time. document
the requirement. This allows KERNELPATH to be used to bypass
unveil for crash dumps with nosuidcoredump=2 or 3

ok visa@ deraadt@ florian@


# 1.40 15-Aug-2019 anton

Serialize access to the vnode pointers associated with acct(2) system
accounting. Prevents a race where the acct thread and the acct(2)
syscall both tries to close a vnode.

ok visa@

Reported-by: syzbot+bf2ac4d4fa9ee92903b8@syzkaller.appspotmail.com


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.42 22-Oct-2019 cheloha

struct proc: change ps_start from utc time to uptime

Allows us to determine how long a process has been running, even if the
UTC clock jumps.

With help from bluhm@ and millert@, who squashed several bugs.

ok bluhm@ millert@


Revision tags: OPENBSD_6_6_BASE
# 1.41 06-Oct-2019 beck

Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.

sweep tree to correct NDIINT op and flags ahead of time. document
the requirement. This allows KERNELPATH to be used to bypass
unveil for crash dumps with nosuidcoredump=2 or 3

ok visa@ deraadt@ florian@


# 1.40 15-Aug-2019 anton

Serialize access to the vnode pointers associated with acct(2) system
accounting. Prevents a race where the acct thread and the acct(2)
syscall both tries to close a vnode.

ok visa@

Reported-by: syzbot+bf2ac4d4fa9ee92903b8@syzkaller.appspotmail.com


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.41 06-Oct-2019 beck

Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.

sweep tree to correct NDIINT op and flags ahead of time. document
the requirement. This allows KERNELPATH to be used to bypass
unveil for crash dumps with nosuidcoredump=2 or 3

ok visa@ deraadt@ florian@


# 1.40 15-Aug-2019 anton

Serialize access to the vnode pointers associated with acct(2) system
accounting. Prevents a race where the acct thread and the acct(2)
syscall both tries to close a vnode.

ok visa@

Reported-by: syzbot+bf2ac4d4fa9ee92903b8@syzkaller.appspotmail.com


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.40 15-Aug-2019 anton

Serialize access to the vnode pointers associated with acct(2) system
accounting. Prevents a race where the acct thread and the acct(2)
syscall both tries to close a vnode.

ok visa@

Reported-by: syzbot+bf2ac4d4fa9ee92903b8@syzkaller.appspotmail.com


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.39 03-Jul-2019 cheloha

Add tsleep_nsec(9), msleep_nsec(9), and rwsleep_nsec(9).

Equivalent to their unsuffixed counterparts except that (a) they take
a timeout in terms of nanoseconds, and (b) INFSLP, aka UINT64_MAX (not
zero) indicates that a timeout should not be set.

For now, zero nanoseconds is not a strictly valid invocation: we log a
warning on DIAGNOSTIC kernels if we see such a call. We still sleep
until the next tick in such a case, however. In the future this could
become some sort of poll... TBD.

To facilitate conversions to these interfaces: add inline conversion
functions to sys/time.h for turning your timeout into nanoseconds.

Also do a few easy conversions for warmup and to demonstrate how
further conversions should be done.

Lots of input from mpi@ and ratchov@. Additional input from tedu@,
deraadt@, mortimer@, millert@, and claudio@.

Partly inspired by FreeBSD r247787.

positive feedback from deraadt@, ok mpi@


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.38 01-Jun-2019 mpi

Revert to using the SCHED_LOCK() to protect time accounting.

It currently creates a lock ordering problem because SCHED_LOCK() is taken
by hardclock(). That means the "priorities" of a thread should be moved
out of the SCHED_LOCK() first in order to make progress.

Reported-by: syzbot+8e4863b3dde88eb706dc@syzkaller.appspotmail.com
via anton@ as well as by kettenis@


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.37 31-May-2019 mpi

Use a per-process mutex to protect time accounting instead of SCHED_LOCK().

Note that hardclock(9) still increments p_{u,s,i}ticks without holding a
lock.

ok visa@, cheloha@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.36 28-Apr-2018 visa

Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is always
curproc that does the locking or unlocking, so the proc parameter
is pointless and can be dropped.

OK mpi@, deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.35 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.34 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.33 21-Jan-2017 guenther

p_comm is the process's command and isn't per thread, so move it from
struct proc to struct process.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.32 19-Mar-2016 natano

Remove the unused flags argument from VOP_UNLOCK().

torture tested on amd64, i386 and macppc
ok beck mpi stefan
"the change looks right" deraadt


# 1.31 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.30 05-Dec-2015 tedu

remove stale lint annotations


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.29 10-Dec-2014 tedu

convert bcopy to memcpy. ok millert


Revision tags: OPENBSD_5_6_BASE
# 1.28 30-Mar-2014 guenther

Eliminates struct pcred by moving the real and saved ugids into
struct ucred; struct process then directly links to the ucred

Based on a discussion at c2k10 or so before noting that FreeBSD and
NetBSD did this too.

ok matthew@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.27 03-Jun-2013 guenther

Convert some internal APIs to use timespecs instead of timevals

ok matthew@ deraadt@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 08-Jul-2012 guenther

Use IO_NOLIMIT instead of munging the process's limits

ok beck@


# 1.25 12-Apr-2012 mikeb

move accounting flags to struct process; idea and ok guenther


# 1.24 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.23 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_7_BASE
# 1.22 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.21 12-Apr-2007 tedu

move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro


Revision tags: OPENBSD_4_1_BASE
# 1.20 16-Jan-2007 thib

Retire VOP_LEASE(); It was a bit for NQNFS and has
effectively been a no-op for quite some time now,
without promise for future usage.

ok pedro@
Testing by krw@ (earlier diff)
and Johan Mson Lindman (tybollt@solace.miun.se)


# 1.19 14-Nov-2006 jmc

grammar, spelling, and style fixes from bret lambert;
kern_descrip.c change ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 05-Jan-2006 tedu

if a kthread fails to call kthread_exit() but instead returns,
bad things happen. fix acct thread. from art


# 1.17 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.16 28-May-2005 marius

have vn_close() lock the vnode before calling VOP_CLOSE().

fix the acct_*() code so that we always have a proc to lock on.

ok pedro@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.15 24-Jun-2004 tholo

This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.

It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.

ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.14 27-May-2004 tedu

shutdown accounting before shutting down vfs. should prevent some panics.
ok david@ millert@ (iirc)


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.13 01-Sep-2003 henning

match syscallargs comments with reality
from Patrick Latifi <patrick.l@hermes.usherb.ca>
ok jason@ tedu@


# 1.12 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.11 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_BASE UBC_SYNC_A UBC_SYNC_B
# 1.10 02-Nov-2001 art

Move the accounting disk space watcher into a kernel thread.
Since we do filesystem operations, we need process context.

This should fix accounting on nfs.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.9 05-May-2000 art

Don't set filesize limit to infinity on exit.
This is only needed in accounting and has to be done carefully because
the limit structures are shared between processes.

Found by Denis A. Doroshenko, analysed by Hannah Schroeter.


# 1.8 23-Mar-2000 art

convert to new timeouts.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 28-Jul-1998 millert

branches: 1.7.8;
Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.6 17-May-1998 deraadt

for acct(), vn_open() with O_APPEND flag so that append-only files work;
problem pointed out by andrew@untraceable.net


Revision tags: OPENBSD_2_3_BASE
# 1.5 06-Nov-1997 csapuntz

Updates for VFS Lite 2 + soft update.


Revision tags: OPENBSD_2_2_BASE
# 1.4 06-Oct-1997 deraadt

back out vfs lite2 till after 2.2


# 1.3 06-Oct-1997 csapuntz

VFS Lite2 Changes


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision