mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-05 12:56:08 +00:00
fifos: delegate unhandled kqueue filters to underlying filesystem
This gives the vfs layer a chance to provide handling for EVFILT_VNODE, for instance. Change pipe_specops to use the default vop_kqfilter to accommodate fifoops that don't specify the method (i.e. all in-tree). Based on a patch by Jan Kokemüller. PR: 225934 Reviewed by: kib, markj (both pre-KASSERT) Differential Revision: https://reviews.freebsd.org/D32271
This commit is contained in:
parent
fc22fe5c74
commit
7259ca3104
@ -83,7 +83,6 @@ struct vop_vector fifo_specops = {
|
||||
.vop_create = VOP_PANIC,
|
||||
.vop_getattr = VOP_EBADF,
|
||||
.vop_ioctl = VOP_PANIC,
|
||||
.vop_kqfilter = VOP_PANIC,
|
||||
.vop_link = VOP_PANIC,
|
||||
.vop_mkdir = VOP_PANIC,
|
||||
.vop_mknod = VOP_PANIC,
|
||||
|
@ -1751,6 +1751,10 @@ pipe_kqfilter(struct file *fp, struct knote *kn)
|
||||
cpipe = PIPE_PEER(cpipe);
|
||||
break;
|
||||
default:
|
||||
if ((cpipe->pipe_type & PIPE_TYPE_NAMED) != 0) {
|
||||
PIPE_UNLOCK(cpipe);
|
||||
return (vnops.fo_kqfilter(fp, kn));
|
||||
}
|
||||
PIPE_UNLOCK(cpipe);
|
||||
return (EINVAL);
|
||||
}
|
||||
|
@ -6172,6 +6172,9 @@ vfs_kqfilter(struct vop_kqfilter_args *ap)
|
||||
struct knote *kn = ap->a_kn;
|
||||
struct knlist *knl;
|
||||
|
||||
KASSERT(vp->v_type != VFIFO || (kn->kn_filter != EVFILT_READ &&
|
||||
kn->kn_filter != EVFILT_WRITE),
|
||||
("READ/WRITE filter on a FIFO leaked through"));
|
||||
switch (kn->kn_filter) {
|
||||
case EVFILT_READ:
|
||||
kn->kn_fop = &vfsread_filtops;
|
||||
|
@ -36,6 +36,8 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/event.h>
|
||||
|
@ -64,6 +64,64 @@ test_kevent_vnode_note_delete(void)
|
||||
success();
|
||||
}
|
||||
|
||||
static void
|
||||
test_kevent_vnode_note_delete_fifo(void)
|
||||
{
|
||||
const char *test_id = "kevent(EVFILT_VNODE, NOTE_DELETE, FIFO)";
|
||||
const char *fifo_path = "./kqueue-fifo.tmp";
|
||||
struct kevent kev;
|
||||
int fd;
|
||||
pid_t pid;
|
||||
|
||||
test_begin(test_id);
|
||||
|
||||
if (mkfifo(fifo_path, 0600) != 0)
|
||||
err(1, "mkfifo");
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1)
|
||||
err(1, "fork");
|
||||
|
||||
if (pid == 0) {
|
||||
char buf[4];
|
||||
|
||||
fd = open(fifo_path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
_exit(1);
|
||||
|
||||
while (read(fd, buf, sizeof(buf)) != 0) {
|
||||
}
|
||||
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
if (waitpid(pid, NULL, WNOHANG) == pid) {
|
||||
unlink(fifo_path);
|
||||
err(1, "open");
|
||||
}
|
||||
|
||||
fd = open(fifo_path, O_WRONLY);
|
||||
if (fd < 0) {
|
||||
unlink(fifo_path);
|
||||
err(1, "open");
|
||||
}
|
||||
|
||||
EV_SET(&kev, fd, EVFILT_VNODE, EV_ADD | EV_ONESHOT, NOTE_DELETE, 0, NULL);
|
||||
if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) {
|
||||
unlink(fifo_path);
|
||||
err(1, "%s", test_id);
|
||||
}
|
||||
|
||||
if (unlink(fifo_path) < 0)
|
||||
err(1, "unlink");
|
||||
|
||||
kevent_cmp(&kev, kevent_get(kqfd));
|
||||
close(fd);
|
||||
|
||||
success();
|
||||
}
|
||||
|
||||
static void
|
||||
test_kevent_vnode_note_write(void)
|
||||
{
|
||||
@ -261,5 +319,6 @@ test_evfilt_vnode(void)
|
||||
test_kevent_vnode_note_attrib();
|
||||
test_kevent_vnode_note_rename();
|
||||
test_kevent_vnode_note_delete();
|
||||
test_kevent_vnode_note_delete_fifo();
|
||||
close(kqfd);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user