git: 2d05c4f018fa - stable/13 - linux(4): Add linux_epoll_pwait_ts() helper for future use.

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Fri, 17 Jun 2022 19:39:25 UTC
The branch stable/13 has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=2d05c4f018fa4514c3ee5391802ce9eadcc5e140

commit 2d05c4f018fa4514c3ee5391802ce9eadcc5e140
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2022-04-26 16:35:56 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-06-17 19:34:04 +0000

    linux(4): Add linux_epoll_pwait_ts() helper for future use.
    
    MFC after:      2 weeks
    
    (cherry picked from commit 27a25179c8356d58b5df6303d850050122f020c6)
---
 sys/compat/linux/linux_event.c | 43 +++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/sys/compat/linux/linux_event.c b/sys/compat/linux/linux_event.c
index 44b1a1526e3c..661e68ce4289 100644
--- a/sys/compat/linux/linux_event.c
+++ b/sys/compat/linux/linux_event.c
@@ -421,15 +421,15 @@ leave1:
 /*
  * Wait for a filter to be triggered on the epoll file descriptor.
  */
+
 static int
-linux_epoll_wait_common(struct thread *td, int epfd, struct epoll_event *events,
-    int maxevents, int timeout, sigset_t *uset)
+linux_epoll_wait_ts(struct thread *td, int epfd, struct epoll_event *events,
+    int maxevents, struct timespec *tsp, sigset_t *uset)
 {
 	struct epoll_copyout_args coargs;
 	struct kevent_copyops k_ops = { &coargs,
 					epoll_kev_copyout,
 					NULL};
-	struct timespec ts, *tsp;
 	cap_rights_t rights;
 	struct file *epfp;
 	sigset_t omask;
@@ -467,20 +467,6 @@ linux_epoll_wait_common(struct thread *td, int epfd, struct epoll_event *events,
 	coargs.count = 0;
 	coargs.error = 0;
 
-	/*
-	 * Linux epoll_wait(2) man page states that timeout of -1 causes caller
-	 * to block indefinitely. Real implementation does it if any negative
-	 * timeout value is passed.
-	 */
-	if (timeout >= 0) {
-		/* Convert from milliseconds to timespec. */
-		ts.tv_sec = timeout / 1000;
-		ts.tv_nsec = (timeout % 1000) * 1000000;
-		tsp = &ts;
-	} else {
-		tsp = NULL;
-	}
-
 	error = kern_kevent_fp(td, epfp, 0, maxevents, &k_ops, tsp);
 	if (error == 0 && coargs.error != 0)
 		error = coargs.error;
@@ -500,6 +486,29 @@ leave:
 	return (error);
 }
 
+static int
+linux_epoll_wait_common(struct thread *td, int epfd, struct epoll_event *events,
+    int maxevents, int timeout, sigset_t *uset)
+{
+	struct timespec ts, *tsp;
+
+	/*
+	 * Linux epoll_wait(2) man page states that timeout of -1 causes caller
+	 * to block indefinitely. Real implementation does it if any negative
+	 * timeout value is passed.
+	 */
+	if (timeout >= 0) {
+		/* Convert from milliseconds to timespec. */
+		ts.tv_sec = timeout / 1000;
+		ts.tv_nsec = (timeout % 1000) * 1000000;
+		tsp = &ts;
+	} else {
+		tsp = NULL;
+	}
+	return (linux_epoll_wait_ts(td, epfd, events, maxevents, tsp, uset));
+
+}
+
 #ifdef LINUX_LEGACY_SYSCALLS
 int
 linux_epoll_wait(struct thread *td, struct linux_epoll_wait_args *args)