summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-01-04 09:03:24 +0100
committerJeff Moyer <jmoyer@redhat.com>2018-01-16 19:26:04 -0500
commit5e664cabd2a8cedd31afa9afbec11218011f9387 (patch)
treee70ebeadc9447f8fa40df3758552581c2de7b37a
parent65d1bd45df08a73d22ff0d16264272d0207b8f8c (diff)
downloadlibaio-5e664cabd2a8cedd31afa9afbec11218011f9387.tar.gz
add support for io_pgetevents
This is ppoll/pselect equivalent for io_getevents. It atomically executes the following sequence: sigset_t origmask; pthread_sigmask(SIG_SETMASK, &sigmask, &origmask); ret = io_getevents(ctx, min_nr, nr, events, timeout); pthread_sigmask(SIG_SETMASK, &origmask, NULL); And thus allows to safely mix aio and signals, especially together with IO_CMD_POLL. See the pselect(2) man page for a more detailed explanation. Signed-off-by: Christoph Hellwig <hch@lst.de> [JEM: add sigset size parameter to io_pgetevents] Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
-rw-r--r--man/io_getevents.361
-rw-r--r--src/Makefile2
-rw-r--r--src/io_pgetevents.c56
-rw-r--r--src/libaio.h4
-rw-r--r--src/libaio.map5
-rw-r--r--src/syscall-i386.h1
-rw-r--r--src/syscall-x86_64.h1
7 files changed, 126 insertions, 4 deletions
diff --git a/man/io_getevents.3 b/man/io_getevents.3
index 8e9ddc8..5062daa 100644
--- a/man/io_getevents.3
+++ b/man/io_getevents.3
@@ -18,7 +18,7 @@
./"
.TH io_getevents 2 2002-09-03 "Linux 2.4" "Linux AIO"
.SH NAME
-io_getevents \- Read resulting events from io requests
+io_getevents, aio_pgetevents \- Read resulting events from io requests
.SH SYNOPSIS
.nf
.B #include <errno.h>
@@ -43,7 +43,7 @@ struct io_event {
};
.sp
.BI "int io_getevents(io_context_t " ctx ", long " nr ", struct io_event *" events "[], struct timespec *" timeout ");"
-
+.BI "int io_pgetevents(io_context_t " ctx ", long " nr ", struct io_event *" events "[], struct timespec *" timeout ", sigset_t *" sigmask ");"
.fi
.SH DESCRIPTION
Attempts to read up to nr events from
@@ -55,6 +55,60 @@ by when has elapsed, where when == NULL specifies an infinite
timeout. Note that the timeout pointed to by when is relative and
will be updated if not NULL and the operation blocks. Will fail
with ENOSYS if not implemented.
+.SS io_pgetevents()
+The relationship between
+.BR io_getevents ()
+and
+.BR io_pgetevents ()
+is analogous to the relationship between
+.BR select (2)
+and
+.BR pselect (2):
+similar
+.BR pselect (2),
+.BR pgetevents ()
+allows an application to safely wait until either an aio completion
+events happens or until a signal is caught.
+.PP
+The following
+.BR io_pgetevents ()
+call:
+call:
+.PP
+.in +4n
+.EX
+ret = io_pgetevents(ctx, min_nr, nr, events, timeout, sigmask);
+.EE
+.in
+.PP
+is equivalent to
+.I atomically
+executing the following calls:
+.PP
+.in +4n
+.EX
+sigset_t origmask;
+
+pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
+ret = io_getevents(ctx, min_nr, nr, events, timeout);
+pthread_sigmask(SIG_SETMASK, &origmask, NULL);
+.EE
+.in
+.PP
+See the description of
+.BR pselect (2)
+for an explanation of why
+.BR io_pgetevents ()
+is necessary.
+.PP
+If the
+.I sigmask
+argument is specified as NULL, then no signal mask manipulation is
+performed (and thus
+.BR io_pgetevents ()
+behaves the same as
+.BR io_getevents()
+) .
.SH ERRORS
.TP
.B EINVAL
@@ -76,4 +130,5 @@ if any of the memory specified to is invalid.
.BR io_queue_wait(3),
.BR io_set_callback(3),
.BR io_submit(3),
-.BR errno(3)
+.BR errno(3),
+.BR pselect(2)
diff --git a/src/Makefile b/src/Makefile
index eadb336..f5a57d3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -23,7 +23,7 @@ libaio_srcs += io_queue_wait.c io_queue_run.c
# real syscalls
libaio_srcs += io_getevents.c io_submit.c io_cancel.c
-libaio_srcs += io_setup.c io_destroy.c
+libaio_srcs += io_setup.c io_destroy.c io_pgetevents.c
# internal functions
libaio_srcs += raw_syscall.c
diff --git a/src/io_pgetevents.c b/src/io_pgetevents.c
new file mode 100644
index 0000000..e6b0614
--- /dev/null
+++ b/src/io_pgetevents.c
@@ -0,0 +1,56 @@
+/*
+ libaio Linux async I/O interface
+ Copyright 2018 Christoph Hellwig.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <libaio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <signal.h>
+#include "syscall.h"
+#include "aio_ring.h"
+
+#ifdef __NR_io_pgetevents
+io_syscall6(int, __io_pgetevents, io_pgetevents, io_context_t, ctx, long,
+ min_nr, long, nr, struct io_event *, events,
+ struct timespec *, timeout, void *, sigmask);
+
+int io_pgetevents(io_context_t ctx, long min_nr, long nr,
+ struct io_event *events, struct timespec *timeout,
+ sigset_t *sigmask)
+{
+ struct {
+ unsigned long ss;
+ unsigned long ss_len;
+ } data;
+
+ if (aio_ring_is_empty(ctx, timeout))
+ return 0;
+
+ data.ss = (unsigned long)sigmask;
+ data.ss_len = _NSIG / 8;
+ return __io_pgetevents(ctx, min_nr, nr, events, timeout, &data);
+}
+#else
+int io_pgetevents(io_context_t ctx, long min_nr, long nr,
+ struct io_event *events, struct timespec *timeout,
+ sigset_t *sigmask)
+
+{
+ return -ENOSYS;
+}
+#endif /* __NR_io_pgetevents */
diff --git a/src/libaio.h b/src/libaio.h
index a1a8fc4..f356c97 100644
--- a/src/libaio.h
+++ b/src/libaio.h
@@ -29,6 +29,7 @@ extern "C" {
#include <sys/types.h>
#include <string.h>
+#include <signal.h>
struct timespec;
struct sockaddr;
@@ -161,6 +162,9 @@ extern int io_destroy(io_context_t ctx);
extern int io_submit(io_context_t ctx, long nr, struct iocb *ios[]);
extern int io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt);
extern int io_getevents(io_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct timespec *timeout);
+extern int io_pgetevents(io_context_t ctx_id, long min_nr, long nr,
+ struct io_event *events, struct timespec *timeout,
+ sigset_t *sigmask);
static inline void io_set_callback(struct iocb *iocb, io_callback_t cb)
diff --git a/src/libaio.map b/src/libaio.map
index dc37725..ec9d13b 100644
--- a/src/libaio.map
+++ b/src/libaio.map
@@ -20,3 +20,8 @@ LIBAIO_0.4 {
io_getevents;
io_queue_wait;
} LIBAIO_0.1;
+
+LIBAIO_0.5 {
+ global:
+ io_pgetevents;
+} LIBAIO_0.4;
diff --git a/src/syscall-i386.h b/src/syscall-i386.h
index 266ed93..bc66bb1 100644
--- a/src/syscall-i386.h
+++ b/src/syscall-i386.h
@@ -3,3 +3,4 @@
#define __NR_io_getevents 247
#define __NR_io_submit 248
#define __NR_io_cancel 249
+#define __NR_io_pgetevents 385
diff --git a/src/syscall-x86_64.h b/src/syscall-x86_64.h
index 84b2639..0eccef3 100644
--- a/src/syscall-x86_64.h
+++ b/src/syscall-x86_64.h
@@ -3,3 +3,4 @@
#define __NR_io_getevents 208
#define __NR_io_submit 209
#define __NR_io_cancel 210
+#define __NR_io_pgetevents 333