summaryrefslogtreecommitdiffstats
path: root/sys/kern/vfs_vnops.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Make fifo_kqfilter() honor FREAD|FWRITE just like fifo_poll() does.mpi2020-04-081-2/+2
| | | | | | | Prevent generating events that do not correspond to how the fifo has been opened. ok visa@, millert@
* In preparation for unlocking ioctl(2), grab the kernel lock as needed.anton2020-02-221-1/+3
| | | | ok kettenis@ mpi@ visa@
* Rework vn_ioctl() to only have a single point of return. This will makeanton2020-02-161-11/+13
| | | | | | | | it easier to grab the kernel lock once ioctl() is unlocked. Thanks to semarie@ who came up with an improved diff. ok mpi@ semarie@ visa@
* Constify instances of struct fileops.visa2020-01-051-2/+2
| | | | OK anton@, mpi@, bluhm@
* Convert infinite sleeps to tsleep_nsec(9).mpi2019-12-081-2/+2
| | | | ok visa@, jca@
* Change the EINVAL return code to a KASSERT if the namei structure isbeck2019-11-101-6/+3
| | | | | | initialized incorrectly for vn_open ok visa@ anton@
* Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.beck2019-10-061-5/+17
| | | | | | | | 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@
* When a thread tries to exclusively lock a vnode, the same thread mustanton2019-08-261-3/+17
| | | | | | | | | | | | ensure that any other thread currently trying to acquire the underlying vnode lock has observed that the same vnode is about to be exclusively locked. Such threads must then sleep until the exclusive lock has been released and then try to acquire the lock again. Otherwise, exclusive access to the vnode cannot be guaranteed. Thanks to naddy@ and visa@ for testing; ok visa@ Reported-by: syzbot+374d0e7e2400004957f7@syzkaller.appspotmail.com
* Revert unlock of lseek(2) since vn_lock() could end up calling tsleep()anton2019-08-131-3/+1
| | | | | | | which is not allowed without holding the kernel lock. Otherwise, wakeups could be lost. Reported-by: syzbot+57588681ca9e3e9ba926@syzkaller.appspotmail.com
* Unlock lseek(2) since the file offset is MP-safe by now. Callinganton2019-08-121-1/+3
| | | | | | | VOP_GETATTR() must still be serialized using the kernel lock since the underlying file system implementation is not MP-safe. no objection from deraadt@ and ok mpi@ visa@
* Allow concurrent reads of the f_offset field of struct file byanton2019-08-051-4/+12
| | | | | | | | | serializing both read/write operations using the existing file mutex. The vnode lock still grants exclusive write access to the offset; the mutex is only used to make the actual write atomic and prevent any concurrent reader from observing intermediate values. ok mpi@ visa@
* Grab the vnode lock earlier in vn_read() since it could end up sleeping,anton2019-07-231-10/+5
| | | | | | | allowing the file offset to change. This is part of the ongoing effort to protect the file offset using the vnode lock. ok mpi@ visa@
* Grab the vnode lock in vn_seek(). Consensus has emerged around using theanton2019-07-211-8/+16
| | | | | | | | existing vnode lock to protect writes to the f_offset field of struct file. As opposed of introducing a new lock which turned out to be harder than anticipated. ok mpi@ visa@
* Revert anton@ changes about read/write unlockingsolene2019-07-121-30/+24
| | | | | | https://marc.info/?l=openbsd-cvs&m=156277704122293&w=2 ok anton@
* Make read/write of the f_offset field belonging to struct file MP-safe;anton2019-07-101-24/+30
| | | | | | | | | | | | | | | | as part of the effort to unlock the kernel. Instead of relying on the vnode lock, introduce a dedicated lock per file. Exclusive write access is granted using the new foffset_enter and foffset_leave API. A convenience function foffset_get is also available for threads that only need to read the current offset. The lock acquisition order in vn_write has been changed to match the one in vn_read in order to avoid a potential deadlock. This change also gets rid of a documented race in vn_read(). Inspired by the FreeBSD implementation. With help and ok mpi@ visa@
* push the KERNEL_LOCK deeper on read(2) and write(2)semarie2019-06-221-5/+17
| | | | | | | | | | | unlocks read(2) and write(2) syscalls families, and push the KERNEL_LOCK deeper in the code path. KERNEL_LOCK is managed per file type in fileops handlers (fo_read, fo_write, and fo_close). read(2) and write(2) on socket are KERNEL_LOCK-free. initial work from mpi@ and ians@ ok mpi@ kettenis@ visa@ ians@
* Make resource limit access MP-safe. So far, the copy-on-write sharingvisa2019-06-211-2/+2
| | | | | | | | | | of resource limit structs has been done between processes. By applying copy-on-write also between threads, threads can read rlimits in a nearly lock-free manner. Inspired by code in DragonFly BSD and FreeBSD. OK mpi@, agreement from jmatthew@ and anton@
* Reorder checks in the read/write(2) family of syscalls to prepare makingmpi2018-08-201-15/+32
| | | | | | | | | | | | file operations mp-safe. This change makes it clear that `f_offset' is only accessed in vn_read() and vn_write(), which will help taking it out of the KERNEL_LOCK(). This refactoring uncovered a race in vn_read() which is now documented and will be addressed in a later diff. ok visa@
* Grab the KERNEL_LOCK() in MP-unsafe fo_close routines. This preventsvisa2018-08-151-3/+6
| | | | | | | a scenario where MP-unsafe code gets run without the kernel lock as a consequence of an unlocked system call. OK mpi@, kettenis@
* Add a new so_seek member to "struct file" such that we can have seekablekettenis2018-07-031-2/+44
| | | | | | | | | | | files that aren't vnodes. Move the vnode-specific code into its own function. Add an implementation for the "DMA buffers" that can be used by DRI3/prime code to find out the size of the graphics buffer. This implementation is very limited and only supports offset 0 and only for SEEK_SET and SEEK_END. This doesn't really make sense; implementing stat(2) would be a more obvious choice. But this is what Linux does. ok guenther@, visa@
* Avoid NULL pointer deref in vn_writechk() when calling ftruncate() on a fileanton2018-07-031-2/+2
| | | | | | descriptor belonging to a cloned device. ok kettenis@
* Make callers of VOP_CREATE(9) and VOP_MKNOD(9) responsible forvisa2018-06-071-1/+2
| | | | | | unlocking the directory vnode. OK mpi@, helg@
* Remove proc from the parameters of vn_lock(). The parameter isvisa2018-05-021-8/+6
| | | | | | unnecessary because curproc always does the locking. OK mpi@
* Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is alwaysvisa2018-04-281-6/+6
| | | | | | | curproc that does the locking or unlocking, so the proc parameter is pointless and can be dropped. OK mpi@, deraadt@
* Convert 'struct fileops' definitions to C99.mpi2018-04-101-4/+10
| | | | ok millert@, deraadt@, florian@
* Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.guenther2018-01-021-1/+2
| | | | ok millert@ sthen@
* Nuke trailing whitespacebeck2017-08-131-3/+3
|
* Drop a now unneeded variable initialization; spotted by bluhm@jca2016-09-301-2/+2
|
* Make read(2) return EISDIR on directories.jca2016-09-301-4/+6
| | | | | | | | | | | Years ago Theo made read(2) return 0 on directories, instead of dumping the directory content. Another behavior is allowed as an extension by POSIX, returning an EISDIR error, as used on a few other systems. This behavior is deemed more useful as it helps spotting errors. This implies that it might break some setups. Ports bulk builds by ajacoutot@ and naddy@, ok millert@ bluhm@ naddy@ deraadt@
* Remove the lockmgr() API. It is only used by filesystems, where it is anatano2016-06-191-4/+1
| | | | | | | | trivial change to use rrw locks instead. All it needs is LK_* defines for the RW_* flags. tested by naddy and sthen on package building infrastructure input and ok jmc mpi tedu
* Remove the unused flags argument from VOP_UNLOCK().natano2016-03-191-5/+5
| | | | | | torture tested on amd64, i386 and macppc ok beck mpi stefan "the change looks right" deraadt
* remove unnecessary casts where the incoming type is void *.tedu2016-01-061-7/+7
|
* Pass fflag to VOP_POLL so vfs fifo functions can get at the filemillert2015-05-011-2/+2
| | | | | | flags to check FREAD/FWRITE if needed. This will be used by fifo_poll to avoid checking the write end of the fifo when the fd is read-only. OK guenther@
* Remove some includes include-what-you-use claims don'tjsg2015-03-141-2/+1
| | | | | | | have any direct symbols used. Tested for indirect use by compiling amd64/i386/sparc64 kernels. ok tedu@ deraadt@
* primary change: move uvm_vnode out of vnode, keeping only a pointer.tedu2014-12-161-1/+2
| | | | | | objective: vnode.h doesn't include uvm_extern.h anymore. followup changes: include uvm_extern.h or lock.h where necessary. ok and help from deraadt
* include sys/unistd.h where needed instead of indirect reliance. ok jsgtedu2014-11-031-1/+2
|
* pass the size to free in some of the obvious casestedu2014-07-131-2/+2
|
* add a size argument to free. will be used soon, but for now default to 0.tedu2014-07-121-2/+2
| | | | after discussions with beck deraadt kettenis.
* decouple struct uvmexp into a new file, so that uvm_extern.h and sysctl.hderaadt2014-07-081-3/+1
| | | | | don't need to be married. ok guenther miod beck jsing kettenis
* Copy timespecs member by member in fo_stat callback functions, to avoidguenther2014-01-241-4/+8
| | | | | | | leaking values in the padding bytes on LP64. Also, vn_stat() was lacking the zero-fill to clean its padding. ok kettenis@ deraadt@ phessler@
* Correct the handling of I/O of >=2^32 bytes and the ktracing there ofguenther2013-09-141-2/+2
| | | | | | by using size_t/ssize_t instead of int/u_int to handle I/O lengths in uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero 'error' argument to ktrgenio() at the same time.
* Move FHASLOCK from f_flag to f_iflags, freeing up a bit for passingguenther2013-06-051-2/+2
| | | | | | O_* flags and eliminating an XXX comment. ok matthew@ deraadt@
* vrele() is a tricky beast. it can sleep if the refcount hits zero,tedu2013-03-301-3/+4
| | | | | | leaving us with a free type function that isn't atomic. deal with this by erasing any reachable pointers to the vnode first, then free it. ok deraadt guenther
* If the current offset is strictly less than the process filesizeguenther2012-07-111-1/+36
| | | | | | | rlimit, then a write that would take it over the limit should be clamped, making it a partial write. ok beck@
* When checking for offset wrap around in vn_read(), compare againstguenther2011-11-271-2/+2
| | | | | | LLONG_MAX instead of SSIZE_MAX ok deraadt@
* Make pwrite/pwritev ignore the O_APPEND flag.guenther2011-11-071-4/+9
| | | | | | | Detect attempts to wrap the file offset by reading past the max (except for character devices). ok matthew@, deraadt@
* Add support for the O_CLOEXEC and O_DIRECTORY flags introduced inmatthew2011-07-091-1/+5
| | | | | | POSIX Issue 7. Requested by oga@ (and maybe djm@); ok guenther@
* Minor turd polishing: hold the vnode lock in vn_rdwr() only whilematthew2011-07-061-5/+7
| | | | | | necessary. "ok ... wait wait WAIT!! ... oh, yeah, it's fine, ok" guenther@
* move the specfs code to a place people can see it; ok guenther thib krwderaadt2011-07-041-2/+2
|
* Correct the links between threads, processes, pgrps, and sessions,guenther2010-07-261-4/+5
| | | | | | | | | 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