[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190607103154.GA22159@redhat.com>
Date: Fri, 7 Jun 2019 12:31:54 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: Andrew Morton <akpm@...ux-foundation.org>,
Benjamin LaHaise <bcrl@...ck.org>
Cc: Arnd Bergmann <arnd@...db.de>,
David Laight <David.Laight@...LAB.COM>,
Deepa Dinamani <deepa.kernel@...il.com>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Eric Wong <e@...24.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
linux-aio@...ck.org, linux-kernel@...r.kernel.org
Subject: [PATCH 1/2] aio: simplify the usage of restore_saved_sigmask_unless()
Move the signal_pending() check and restore_saved_sigmask_unless()
into do_io_getevents() and simplify the callers.
The only complication is that non-restartable io_getevents() and
io_getevents_time32() have to translate ERESTARTNOHAND into EINTR.
They do not need restore_saved_sigmask_unless(), but it is harmless
and WARN_ON(!TIF_SIGPENDING) will be usefule after the next patch.
Signed-off-by: Oleg Nesterov <oleg@...hat.com>
---
fs/aio.c | 34 ++++++++--------------------------
1 file changed, 8 insertions(+), 26 deletions(-)
diff --git a/fs/aio.c b/fs/aio.c
index 8200f97..944eef7 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -2034,6 +2034,7 @@ static long do_io_getevents(aio_context_t ctx_id,
{
ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX;
struct kioctx *ioctx = lookup_ioctx(ctx_id);
+ bool interrupted;
long ret = -EINVAL;
if (likely(ioctx)) {
@@ -2042,6 +2043,11 @@ static long do_io_getevents(aio_context_t ctx_id,
percpu_ref_put(&ioctx->users);
}
+ interrupted = signal_pending(current);
+ restore_saved_sigmask_unless(interrupted);
+ if (interrupted && !ret)
+ ret = -ERESTARTNOHAND;
+
return ret;
}
@@ -2072,7 +2078,7 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
return -EFAULT;
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
- if (!ret && signal_pending(current))
+ if (ret == -ERESTARTNOHAND)
ret = -EINTR;
return ret;
}
@@ -2094,7 +2100,6 @@ SYSCALL_DEFINE6(io_pgetevents,
{
struct __aio_sigset ksig = { NULL, };
struct timespec64 ts;
- bool interrupted;
int ret;
if (timeout && unlikely(get_timespec64(&ts, timeout)))
@@ -2109,11 +2114,6 @@ SYSCALL_DEFINE6(io_pgetevents,
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
- interrupted = signal_pending(current);
- restore_saved_sigmask_unless(interrupted);
- if (interrupted && !ret)
- ret = -ERESTARTNOHAND;
-
return ret;
}
@@ -2129,7 +2129,6 @@ SYSCALL_DEFINE6(io_pgetevents_time32,
{
struct __aio_sigset ksig = { NULL, };
struct timespec64 ts;
- bool interrupted;
int ret;
if (timeout && unlikely(get_old_timespec32(&ts, timeout)))
@@ -2145,11 +2144,6 @@ SYSCALL_DEFINE6(io_pgetevents_time32,
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
- interrupted = signal_pending(current);
- restore_saved_sigmask_unless(interrupted);
- if (interrupted && !ret)
- ret = -ERESTARTNOHAND;
-
return ret;
}
@@ -2170,7 +2164,7 @@ SYSCALL_DEFINE5(io_getevents_time32, __u32, ctx_id,
return -EFAULT;
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
- if (!ret && signal_pending(current))
+ if (ret == -ERESTARTNOHAND)
ret = -EINTR;
return ret;
}
@@ -2196,7 +2190,6 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,
{
struct __compat_aio_sigset ksig = { NULL, };
struct timespec64 t;
- bool interrupted;
int ret;
if (timeout && get_old_timespec32(&t, timeout))
@@ -2211,11 +2204,6 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
- interrupted = signal_pending(current);
- restore_saved_sigmask_unless(interrupted);
- if (interrupted && !ret)
- ret = -ERESTARTNOHAND;
-
return ret;
}
@@ -2231,7 +2219,6 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,
{
struct __compat_aio_sigset ksig = { NULL, };
struct timespec64 t;
- bool interrupted;
int ret;
if (timeout && get_timespec64(&t, timeout))
@@ -2246,11 +2233,6 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
- interrupted = signal_pending(current);
- restore_saved_sigmask_unless(interrupted);
- if (interrupted && !ret)
- ret = -ERESTARTNOHAND;
-
return ret;
}
#endif
--
2.5.0
Powered by blists - more mailing lists