diff options
author | davidxu <davidxu@FreeBSD.org> | 2012-02-01 02:53:06 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2012-02-01 02:53:06 +0000 |
commit | e9edcfe7c1220c2d1db1dbd43c113116d45be7fe (patch) | |
tree | 701c607f5cf534d8d2984fccfa40fe965a97b69b /sys/kern/vfs_aio.c | |
parent | 9b7841536b2b775fec0be57bf0940f72844e0f68 (diff) | |
download | FreeBSD-src-e9edcfe7c1220c2d1db1dbd43c113116d45be7fe.zip FreeBSD-src-e9edcfe7c1220c2d1db1dbd43c113116d45be7fe.tar.gz |
If multiple threads call kevent() to get AIO events on same kqueue fd,
it is possible that a single AIO event will be reported to multiple
threads, it is not threading friendly, and the existing API can not
control this behavior.
Allocate a kevent flags field sigev_notify_kevent_flags for AIO event
notification in sigevent, and allow user to pass EV_CLEAR, EV_DISPATCH
or EV_ONESHOT to AIO kernel code, user can control whether the event
should be cleared once it is retrieved by a thread. This change should
be comptaible with existing application, because the field should have
already been zero-filled, and no additional action will be taken by
kernel.
PR: kern/156567
Diffstat (limited to 'sys/kern/vfs_aio.c')
-rw-r--r-- | sys/kern/vfs_aio.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index 2d9994f..eaadf13 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -1524,6 +1524,7 @@ aio_aqueue(struct thread *td, struct aiocb *job, struct aioliojob *lj, int error; int fd, kqfd; int jid; + u_short evflags; if (p->p_aioinfo == NULL) aio_init_aioinfo(p); @@ -1646,10 +1647,15 @@ aio_aqueue(struct thread *td, struct aiocb *job, struct aioliojob *lj, if (aiocbe->uaiocb.aio_sigevent.sigev_notify != SIGEV_KEVENT) goto no_kqueue; + evflags = aiocbe->uaiocb.aio_sigevent.sigev_notify_kevent_flags; + if ((evflags & ~(EV_CLEAR | EV_DISPATCH | EV_ONESHOT)) != 0) { + error = EINVAL; + goto aqueue_fail; + } kqfd = aiocbe->uaiocb.aio_sigevent.sigev_notify_kqueue; kev.ident = (uintptr_t)aiocbe->uuaiocb; kev.filter = EVFILT_AIO; - kev.flags = EV_ADD | EV_ENABLE | EV_FLAG1; + kev.flags = EV_ADD | EV_ENABLE | EV_FLAG1 | evflags; kev.data = (intptr_t)aiocbe; kev.udata = aiocbe->uaiocb.aio_sigevent.sigev_value.sival_ptr; error = kqfd_register(kqfd, &kev, td, 1); |