Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Implement eventfd_ioctl() and handle FIONBIO so tha...
details: https://anonhg.NetBSD.org/src/rev/11b3dd5b918e
branches: trunk
changeset: 361607:11b3dd5b918e
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Feb 17 16:28:29 2022 +0000
description:
Implement eventfd_ioctl() and handle FIONBIO so that fcntl(O_NONBLOCK)
works. While here, also implement FIONREAD and FIONWRITE, and document
why we don't implement FIONSPACE.
Also implement FIONBIO and FIONREAD for in timerfd_ioctl() (for the same
reason).
PR kern/56718
diffstat:
sys/kern/sys_eventfd.c | 39 ++++++++++++++++++++++++++++++++++++---
sys/kern/sys_timerfd.c | 13 +++++++++++--
2 files changed, 47 insertions(+), 5 deletions(-)
diffs (101 lines):
diff -r 32b2cbfd0a77 -r 11b3dd5b918e sys/kern/sys_eventfd.c
--- a/sys/kern/sys_eventfd.c Thu Feb 17 16:09:00 2022 +0000
+++ b/sys/kern/sys_eventfd.c Thu Feb 17 16:28:29 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_eventfd.c,v 1.8 2021/11/24 16:35:33 thorpej Exp $ */
+/* $NetBSD: sys_eventfd.c,v 1.9 2022/02/17 16:28:29 thorpej Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.8 2021/11/24 16:35:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.9 2022/02/17 16:28:29 thorpej Exp $");
/*
* eventfd
@@ -310,6 +310,39 @@
}
static int
+eventfd_ioctl(file_t * const fp, u_long const cmd, void * const data)
+{
+ struct eventfd * const efd = fp->f_eventfd;
+
+ switch (cmd) {
+ case FIONBIO:
+ return 0;
+
+ case FIONREAD:
+ mutex_enter(&efd->efd_lock);
+ *(int *)data = efd->efd_val != 0 ? sizeof(eventfd_t) : 0;
+ mutex_exit(&efd->efd_lock);
+ return 0;
+
+ case FIONWRITE:
+ *(int *)data = 0;
+ return 0;
+
+ case FIONSPACE:
+ /*
+ * FIONSPACE doesn't really work for eventfd, because the
+ * writability depends on the contents (value) being written.
+ */
+ break;
+
+ default:
+ break;
+ }
+
+ return EPASSTHROUGH;
+}
+
+static int
eventfd_fop_poll(file_t * const fp, int const events)
{
struct eventfd * const efd = fp->f_eventfd;
@@ -521,7 +554,7 @@
.fo_name = "eventfd",
.fo_read = eventfd_fop_read,
.fo_write = eventfd_fop_write,
- .fo_ioctl = fbadop_ioctl,
+ .fo_ioctl = eventfd_ioctl,
.fo_fcntl = fnullop_fcntl,
.fo_poll = eventfd_fop_poll,
.fo_stat = eventfd_fop_stat,
diff -r 32b2cbfd0a77 -r 11b3dd5b918e sys/kern/sys_timerfd.c
--- a/sys/kern/sys_timerfd.c Thu Feb 17 16:09:00 2022 +0000
+++ b/sys/kern/sys_timerfd.c Thu Feb 17 16:28:29 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_timerfd.c,v 1.7 2021/11/24 16:35:33 thorpej Exp $ */
+/* $NetBSD: sys_timerfd.c,v 1.8 2022/02/17 16:28:29 thorpej Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_timerfd.c,v 1.7 2021/11/24 16:35:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_timerfd.c,v 1.8 2022/02/17 16:28:29 thorpej Exp $");
/*
* timerfd
@@ -306,6 +306,15 @@
int error = 0;
switch (cmd) {
+ case FIONBIO:
+ break;
+
+ case FIONREAD:
+ itimer_lock();
+ *(int *)data = timerfd_is_readable(tfd) ? sizeof(uint64_t) : 0;
+ itimer_unlock();
+ break;
+
case TFD_IOC_SET_TICKS: {
const uint64_t * const new_ticksp = data;
if (*new_ticksp > INT_MAX) {
Home |
Main Index |
Thread Index |
Old Index