svn commit: r341376 - in stable/12/sys: compat/linux kern sys
Mark Johnston
markj at FreeBSD.org
Sat Dec 1 17:48:30 UTC 2018
Author: markj
Date: Sat Dec 1 17:48:28 2018
New Revision: 341376
URL: https://svnweb.freebsd.org/changeset/base/341376
Log:
MFC r340861, r340900:
Minor kevent(2) cleanups.
Modified:
stable/12/sys/compat/linux/linux_event.c
stable/12/sys/kern/kern_event.c
stable/12/sys/kern/vfs_aio.c
stable/12/sys/sys/event.h
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/sys/compat/linux/linux_event.c
==============================================================================
--- stable/12/sys/compat/linux/linux_event.c Sat Dec 1 16:50:12 2018 (r341375)
+++ stable/12/sys/compat/linux/linux_event.c Sat Dec 1 17:48:28 2018 (r341376)
@@ -504,7 +504,7 @@ linux_epoll_ctl(struct thread *td, struct linux_epoll_
* and the EV_ADD flag is not set.
*/
kev[0].flags &= ~EV_ADD;
- error = kqfd_register(args->epfd, &kev[0], td, 1);
+ error = kqfd_register(args->epfd, &kev[0], td, M_WAITOK);
if (error != ENOENT) {
error = EEXIST;
goto leave0;
Modified: stable/12/sys/kern/kern_event.c
==============================================================================
--- stable/12/sys/kern/kern_event.c Sat Dec 1 16:50:12 2018 (r341375)
+++ stable/12/sys/kern/kern_event.c Sat Dec 1 17:48:28 2018 (r341376)
@@ -102,13 +102,13 @@ TASKQUEUE_DEFINE_THREAD(kqueue_ctx);
static int kevent_copyout(void *arg, struct kevent *kevp, int count);
static int kevent_copyin(void *arg, struct kevent *kevp, int count);
static int kqueue_register(struct kqueue *kq, struct kevent *kev,
- struct thread *td, int waitok);
+ struct thread *td, int mflag);
static int kqueue_acquire(struct file *fp, struct kqueue **kqp);
static void kqueue_release(struct kqueue *kq, int locked);
static void kqueue_destroy(struct kqueue *kq);
static void kqueue_drain(struct kqueue *kq, struct thread *td);
static int kqueue_expand(struct kqueue *kq, struct filterops *fops,
- uintptr_t ident, int waitok);
+ uintptr_t ident, int mflag);
static void kqueue_task(void *arg, int pending);
static int kqueue_scan(struct kqueue *kq, int maxevents,
struct kevent_copyops *k_ops,
@@ -150,7 +150,7 @@ static void knote_drop_detached(struct knote *kn, str
static void knote_enqueue(struct knote *kn);
static void knote_dequeue(struct knote *kn);
static void knote_init(void);
-static struct knote *knote_alloc(int waitok);
+static struct knote *knote_alloc(int mflag);
static void knote_free(struct knote *kn);
static void filt_kqdetach(struct knote *kn);
@@ -582,7 +582,7 @@ knote_fork(struct knlist *list, int pid)
kev.fflags = kn->kn_sfflags;
kev.data = kn->kn_id; /* parent */
kev.udata = kn->kn_kevent.udata;/* preserve udata */
- error = kqueue_register(kq, &kev, NULL, 0);
+ error = kqueue_register(kq, &kev, NULL, M_NOWAIT);
if (error)
kn->kn_fflags |= NOTE_TRACKERR;
@@ -596,7 +596,7 @@ knote_fork(struct knlist *list, int pid)
kev.fflags = kn->kn_sfflags;
kev.data = kn->kn_id; /* parent */
kev.udata = kn->kn_kevent.udata;/* preserve udata */
- error = kqueue_register(kq, &kev, NULL, 0);
+ error = kqueue_register(kq, &kev, NULL, M_NOWAIT);
if (error)
kn->kn_fflags |= NOTE_TRACKERR;
if (kn->kn_fop->f_event(kn, NOTE_FORK))
@@ -1229,7 +1229,7 @@ kqueue_kevent(struct kqueue *kq, struct thread *td, in
if (!kevp->filter)
continue;
kevp->flags &= ~EV_SYSFLAGS;
- error = kqueue_register(kq, kevp, td, 1);
+ error = kqueue_register(kq, kevp, td, M_WAITOK);
if (error || (kevp->flags & EV_RECEIPT)) {
if (nevents == 0)
return (error);
@@ -1370,12 +1370,11 @@ kqueue_fo_release(int filt)
}
/*
- * A ref to kq (obtained via kqueue_acquire) must be held. waitok will
- * influence if memory allocation should wait. Make sure it is 0 if you
- * hold any mutexes.
+ * A ref to kq (obtained via kqueue_acquire) must be held.
*/
static int
-kqueue_register(struct kqueue *kq, struct kevent *kev, struct thread *td, int waitok)
+kqueue_register(struct kqueue *kq, struct kevent *kev, struct thread *td,
+ int mflag)
{
struct filterops *fops;
struct file *fp;
@@ -1405,7 +1404,7 @@ kqueue_register(struct kqueue *kq, struct kevent *kev,
* allocation failures are handled in the loop, only
* if the spare knote appears to be actually required.
*/
- tkn = knote_alloc(waitok);
+ tkn = knote_alloc(mflag);
} else {
tkn = NULL;
}
@@ -1421,11 +1420,11 @@ findkn:
goto done;
if ((kev->flags & EV_ADD) == EV_ADD && kqueue_expand(kq, fops,
- kev->ident, 0) != 0) {
+ kev->ident, M_NOWAIT) != 0) {
/* try again */
fdrop(fp, td);
fp = NULL;
- error = kqueue_expand(kq, fops, kev->ident, waitok);
+ error = kqueue_expand(kq, fops, kev->ident, mflag);
if (error)
goto done;
goto findkn;
@@ -1462,7 +1461,7 @@ findkn:
}
} else {
if ((kev->flags & EV_ADD) == EV_ADD) {
- error = kqueue_expand(kq, fops, kev->ident, waitok);
+ error = kqueue_expand(kq, fops, kev->ident, mflag);
if (error != 0)
goto done;
}
@@ -1690,19 +1689,14 @@ kqueue_schedtask(struct kqueue *kq)
* Expand the kq to make sure we have storage for fops/ident pair.
*
* Return 0 on success (or no work necessary), return errno on failure.
- *
- * Not calling hashinit w/ waitok (proper malloc flag) should be safe.
- * If kqueue_register is called from a non-fd context, there usually/should
- * be no locks held.
*/
static int
kqueue_expand(struct kqueue *kq, struct filterops *fops, uintptr_t ident,
- int waitok)
+ int mflag)
{
struct klist *list, *tmp_knhash, *to_free;
u_long tmp_knhashmask;
int error, fd, size;
- int mflag = waitok ? M_WAITOK : M_NOWAIT;
KQ_NOTOWNED(kq);
@@ -1740,8 +1734,9 @@ kqueue_expand(struct kqueue *kq, struct filterops *fop
}
} else {
if (kq->kq_knhashmask == 0) {
- tmp_knhash = hashinit(KN_HASHSIZE, M_KQUEUE,
- &tmp_knhashmask);
+ tmp_knhash = hashinit_flags(KN_HASHSIZE, M_KQUEUE,
+ &tmp_knhashmask, (mflag & M_WAITOK) != 0 ?
+ HASH_WAITOK : HASH_NOWAIT);
if (tmp_knhash == NULL)
return (ENOMEM);
KQ_LOCK(kq);
@@ -1830,7 +1825,7 @@ kqueue_scan(struct kqueue *kq, int maxevents, struct k
asbt = -1;
} else
asbt = 0;
- marker = knote_alloc(1);
+ marker = knote_alloc(M_WAITOK);
marker->kn_status = KN_MARKER;
KQ_LOCK(kq);
@@ -2706,11 +2701,10 @@ knote_init(void)
SYSINIT(knote, SI_SUB_PSEUDO, SI_ORDER_ANY, knote_init, NULL);
static struct knote *
-knote_alloc(int waitok)
+knote_alloc(int mflag)
{
- return (uma_zalloc(knote_zone, (waitok ? M_WAITOK : M_NOWAIT) |
- M_ZERO));
+ return (uma_zalloc(knote_zone, mflag | M_ZERO));
}
static void
@@ -2724,7 +2718,7 @@ knote_free(struct knote *kn)
* Register the kev w/ the kq specified by fd.
*/
int
-kqfd_register(int fd, struct kevent *kev, struct thread *td, int waitok)
+kqfd_register(int fd, struct kevent *kev, struct thread *td, int mflag)
{
struct kqueue *kq;
struct file *fp;
@@ -2737,7 +2731,7 @@ kqfd_register(int fd, struct kevent *kev, struct threa
if ((error = kqueue_acquire(fp, &kq)) != 0)
goto noacquire;
- error = kqueue_register(kq, kev, td, waitok);
+ error = kqueue_register(kq, kev, td, mflag);
kqueue_release(kq, 0);
noacquire:
Modified: stable/12/sys/kern/vfs_aio.c
==============================================================================
--- stable/12/sys/kern/vfs_aio.c Sat Dec 1 16:50:12 2018 (r341375)
+++ stable/12/sys/kern/vfs_aio.c Sat Dec 1 17:48:28 2018 (r341376)
@@ -1595,7 +1595,7 @@ aio_aqueue(struct thread *td, struct aiocb *ujob, stru
kev.flags = EV_ADD | EV_ENABLE | EV_FLAG1 | evflags;
kev.data = (intptr_t)job;
kev.udata = job->uaiocb.aio_sigevent.sigev_value.sival_ptr;
- error = kqfd_register(kqfd, &kev, td, 1);
+ error = kqfd_register(kqfd, &kev, td, M_WAITOK);
if (error)
goto aqueue_fail;
@@ -2164,7 +2164,8 @@ kern_lio_listio(struct thread *td, int mode, struct ai
/* pass user defined sigval data */
kev.udata = lj->lioj_signal.sigev_value.sival_ptr;
error = kqfd_register(
- lj->lioj_signal.sigev_notify_kqueue, &kev, td, 1);
+ lj->lioj_signal.sigev_notify_kqueue, &kev, td,
+ M_WAITOK);
if (error) {
uma_zfree(aiolio_zone, lj);
return (error);
Modified: stable/12/sys/sys/event.h
==============================================================================
--- stable/12/sys/sys/event.h Sat Dec 1 16:50:12 2018 (r341375)
+++ stable/12/sys/sys/event.h Sat Dec 1 17:48:28 2018 (r341376)
@@ -348,7 +348,7 @@ void knlist_cleardel(struct knlist *knl, struct thread
knlist_cleardel((knl), (td), (islocked), 1)
void knote_fdclose(struct thread *p, int fd);
int kqfd_register(int fd, struct kevent *kev, struct thread *p,
- int waitok);
+ int mflag);
int kqueue_add_filteropts(int filt, struct filterops *filtops);
int kqueue_del_filteropts(int filt);
More information about the svn-src-all
mailing list