kernel - Implement POLLHUP for pipes and filesystem fifos (3) * Add an internal NOTE_HUPONLY flag to allow the poll() system call to tell the kevent system that EVFILT_READ should only trigger on a HUP and not trigger on read-data-present. * Linux does not trigger POLLHUP on a half-closed socket, make DFly have the same behavior. POLLHUP is only triggered on a fully-closed socket. * Fix bug where data-present on the pipe, socket, or fifo would trigger an EVFILT_READ event when only a HUP is being requested. This caused our poll() implementation to complain about spurious events (which then results in incorrect operation).
kernel - Implement POLLHUP for pipes and filesystem fifso * POLLHUP was implemented for sockets but not for pipes and filesystem fifos. * Implement the poll() bit for pipes and filesystem fifos as well. * Fixes Zig portability to dfly, and probably fixes other things. Reported-by: (bugs) mikdusan
kernel - Fix dangling ref on fifo vnode * Fix dangling refs on the fifo vnode which prevent unmount from succeeding. * Fix open/close races which can occur during fifo open and close due to blocking conditions. Use a lockmgr lock instead. * Retain use of vp->v_token to help interlock read, write, and ioctl operations. * This situation occurs when a filesystem fifo (aka via mkfifo) blocks on open() and is then interrupted.
kernel: Remove numerous #include <sys/thread2.h>. Most of them were added when we converted spl*() calls to crit_enter()/crit_exit(), almost 14 years ago. We can now remove a good chunk of them again for where crit_*() are no longer used. I had to adjust some files that were relying on thread2.h or headers that it includes coming in via other headers that it was removed from.
kernel - Rewrite vnode ref-counting code to improve performance * Rewrite the vnode ref-counting code and modify operation to not immediately VOP_INACTIVE a vnode when its refs drops to 0. By doing so we avoid cycling vnodes through exclusive locks when temporarily accessing them (such as in a path lookup). Shared locks can be used throughout. * Track active/inactive vnodes a bit differently, keep track of the number of vnodes that are still active but have zero refs, and rewrite the vnode freeing code to use the new statistics to deactivate cached vnodes.
kevent: Restore old EV_EOF semantics - EV_EOF should be set when the other side closed the connection, even if there are data pending in the read buffer (the old semantics). - EV_NODATA is added to indicate there are no more data pending in the buffer and EOF is detected (EV_EOF is also set in this situation). Kernel code now tests EV_NODATA instead of EV_EOF, since EV_NODATA delivers the information which was delivered by the EV_EOF before this commit. DragonFly-Bug: http://bugs.dragonflybsd.org/issue1998
network - MP socket free & abort interactions, so_state * Add so_refs and ref-count the socket structure to deal with MP races on sofree(). * Ref the socket structure for all soabort() operations (they are usually asynchronous). The netmsg_pru_abort() handler will sofree() the ref after calling the protocol stack's abort function. * Use atomic ops to set and clear bits in so_state, because it is modified by both the fronttend and the backend. * Remove numerous critical sections that are no longer effective. * Protect the accept queues with so_rcv.ssb_token. * Protect after-the-fact calls to soisdisconnected() with a soreference() to avoid use-after-free cases. * Wrap unix domain, mroute, div, raw, and key sockets/protocols with their own private tokens.
kernel - More kqueue work * Only set EV_EOF in the read filter after all pending data has been exhausted. * This also fixes a bug where the read filter was not setting data ready on EOF when data was pending in the buffer. * Fix bugs in the poll copyout handler. An EOF condition does not prevent other flags from getting set.
kernel - Make filters able to be marked MPSAFE * Change struct filterops f_isfd field to f_flags, taking FILTEROP_ISFD and/or FILTEROP_MPSAFE. * Convert all existing filter definitions to use new flags. * Create filter_attach/detach/event wrapper functions for calling through the struct filterops vector that grab the MPLOCK as necessary. * kern_event() uses kq->kq_count to determine whether or not to sleep, kqueue_scan() removes events from the TAILQ and can possibly sleep, releasing the global kq token, before updating kq->kq_count.
kernel - bring back reasonable fifo blocking semantics * Differentiate between a pipe that has not yet been connected to and one that all readers or writers have disconnected from for issuing an EOF. * Add soisreconnected/soisreconnecting to restore socket flags after a soisdisconnected when a fifo becomes reconnected.