Skip to content

Commit

Permalink
Add aio_writev and aio_readv
Browse files Browse the repository at this point in the history
POSIX AIO is great, but it lacks vectored I/O functions. This commit
fixes that shortcoming by adding aio_writev and aio_readv. They aren't
part of the standard, but they're an obvious extension. They work just
like their synchronous equivalents pwritev and preadv.

It isn't yet possible to use vectored aiocbs with lio_listio, but that
could be added in the future.

Reviewed by:    jhb, kib, bcr
Relnotes:       yes
Differential Revision: https://reviews.freebsd.org/D27743
  • Loading branch information
asomers committed Jan 3, 2021
1 parent 486580c commit 022ca2f
Show file tree
Hide file tree
Showing 17 changed files with 1,171 additions and 292 deletions.
2 changes: 2 additions & 0 deletions lib/libc/sys/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ MAN+= sctp_generic_recvmsg.2 \
write.2 \
_umtx_op.2

MLINKS+=aio_read.2 aio_readv.2
MLINKS+=aio_write.2 aio_writev.2
MLINKS+=accept.2 accept4.2
MLINKS+=access.2 eaccess.2 \
access.2 faccessat.2
Expand Down
2 changes: 2 additions & 0 deletions lib/libc/sys/Symbol.map
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ FBSD_1.5 {

FBSD_1.6 {
__sysctlbyname;
aio_readv;
aio_writev;
close_range;
copy_file_range;
fhlink;
Expand Down
6 changes: 5 additions & 1 deletion lib/libc/sys/aio_error.2
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd June 2, 1999
.Dd January 2, 2021
.Dt AIO_ERROR 2
.Os
.Sh NAME
Expand Down Expand Up @@ -52,7 +52,9 @@ is returned.
If the request has completed unsuccessfully the error
status is returned as described in
.Xr read 2 ,
.Xr readv 2 ,
.Xr write 2 ,
.Xr writev 2 ,
or
.Xr fsync 2 .
On failure,
Expand All @@ -76,9 +78,11 @@ does not reference an outstanding asynchronous I/O request.
.Sh SEE ALSO
.Xr aio_cancel 2 ,
.Xr aio_read 2 ,
.Xr aio_readv 2 ,
.Xr aio_return 2 ,
.Xr aio_suspend 2 ,
.Xr aio_write 2 ,
.Xr aio_writev 2 ,
.Xr fsync 2 ,
.Xr read 2 ,
.Xr write 2 ,
Expand Down
63 changes: 52 additions & 11 deletions lib/libc/sys/aio_read.2
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,55 @@
.\"
.\" $FreeBSD$
.\"
.Dd August 19, 2016
.Dd January 2, 2021
.Dt AIO_READ 2
.Os
.Sh NAME
.Nm aio_read
.Nm aio_read ,
.Nm aio_readv
.Nd asynchronous read from a file (REALTIME)
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In aio.h
.Ft int
.Fn aio_read "struct aiocb *iocb"
.In sys/uio.h
.Ft int
.Fn aio_readv "struct aiocb *iocb"
.Sh DESCRIPTION
The
.Fn aio_read
system call allows the calling process to read
.Fa iocb->aio_nbytes
and
.Fn aio_readv
system calls allow the calling process to read
from the descriptor
.Fa iocb->aio_fildes
beginning at the offset
.Fa iocb->aio_offset
into the buffer pointed to by
.Fa iocb->aio_buf .
The call returns immediately after the read request has
.Fa iocb->aio_offset .
.Fn aio_read
will read
.Fa iocb->aio_nbytes
from the buffer pointed to by
.Fa iocb->aio_buf ,
whereas
.Fn aio_readv
reads the data into the
.Fa iocb->aio_iovcnt
buffers specified by the members of the
.Fa iocb->aio_iov
array.
Both syscalls return immediately after the read request has
been enqueued to the descriptor; the read may or may not have
completed at the time the call returns.
.Pp
For
.Fn aio_readv
the
.Fa iovec
structure is defined in
.Xr readv 2 .
.Pp
If _POSIX_PRIORITIZED_IO is defined, and the descriptor supports it,
then the enqueued operation is submitted at a priority equal to that
of the calling process minus
Expand All @@ -61,7 +83,9 @@ The
argument
is ignored by the
.Fn aio_read
system call.
and
.Fn aio_readv
system calls.
.Pp
The
.Fa iocb
Expand Down Expand Up @@ -108,16 +132,22 @@ is past the offset maximum for
.Fa iocb->aio_fildes ,
no I/O will occur.
.Sh RETURN VALUES
.Rv -std aio_read
.Rv -std aio_read aio_readv
.Sh DIAGNOSTICS
None.
.Sh ERRORS
The
.Fn aio_read
system call will fail if:
and
.Fn aio_readv
system calls will fail if:
.Bl -tag -width Er
.It Bq Er EAGAIN
The request was not queued because of system resource limitations.
.It Bq Er EFAULT
Part of
.Fa aio_iov
points outside the process's allocated address space.
.It Bq Er EINVAL
The asynchronous notification method in
.Fa iocb->aio_sigevent.sigev_notify
Expand All @@ -130,10 +160,14 @@ are unsafe and unsafe asynchronous I/O operations are disabled.
.Pp
The following conditions may be synchronously detected when the
.Fn aio_read
or
.Fn aio_readv
system call is made, or asynchronously, at any time thereafter.
If they
are detected at call time,
.Fn aio_read
or
.Fn aio_readv
returns -1 and sets
.Va errno
appropriately; otherwise the
Expand Down Expand Up @@ -207,11 +241,18 @@ The
system call is expected to conform to the
.St -p1003.1
standard.
The
.Fn aio_readv
system call is a FreeBSD extension, and should not be used in portable code.
.Sh HISTORY
The
.Fn aio_read
system call first appeared in
.Fx 3.0 .
The
.Fn aio_readv
system call first appeared in
.Fx 13.0 .
.Sh AUTHORS
This
manual page was written by
Expand Down
4 changes: 3 additions & 1 deletion lib/libc/sys/aio_return.2
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd March 21, 2016
.Dd January 2, 2021
.Dt AIO_RETURN 2
.Os
.Sh NAME
Expand Down Expand Up @@ -55,7 +55,9 @@ returns something other than
If the asynchronous I/O request has completed, the status is returned
as described in
.Xr read 2 ,
.Xr readv 2 ,
.Xr write 2 ,
.Xr writev 2 ,
or
.Xr fsync 2 .
Otherwise,
Expand Down
63 changes: 52 additions & 11 deletions lib/libc/sys/aio_write.2
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,61 @@
.\"
.\" $FreeBSD$
.\"
.Dd August 19, 2016
.Dd January 2, 2021
.Dt AIO_WRITE 2
.Os
.Sh NAME
.Nm aio_write
.Nm aio_write ,
.Nm aio_writev
.Nd asynchronous write to a file (REALTIME)
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In aio.h
.Ft int
.Fn aio_write "struct aiocb *iocb"
.In sys/uio.h
.Ft int
.Fn aio_writev "struct aiocb *iocb"
.Sh DESCRIPTION
The
.Fn aio_write
system call allows the calling process to write
.Fa iocb->aio_nbytes
from the buffer pointed to by
.Fa iocb->aio_buf
and
.Fn aio_writev
system calls allow the calling process to write
to the descriptor
.Fa iocb->aio_fildes .
The call returns immediately after the write request has been enqueued
.Fn aio_write
will write
.Fa iocb->aio_nbytes
from the buffer pointed to by
.Fa iocb->aio_buf ,
whereas
.Fn aio_writev
gathers the data from the
.Fa iocb->aio_iovcnt
buffers specified by the members of the
.Fa iocb->aio_iov
array.
Both syscalls return immediately after the write request has been enqueued
to the descriptor; the write may or may not have completed at the time
the call returns.
If the request could not be enqueued, generally due
to invalid arguments, the call returns without having enqueued the
request.
.Pp
For
.Fn aio_writev
the
.Fa iovec
structure is defined in
.Xr writev 2 .
.Pp
If
.Dv O_APPEND
is set for
.Fa iocb->aio_fildes ,
.Fn aio_write
operations append to the file in the same order as the calls were
write operations append to the file in the same order as the calls were
made.
If
.Dv O_APPEND
Expand Down Expand Up @@ -103,6 +124,8 @@ The asynchronous I/O control buffer
.Fa iocb
should be zeroed before the
.Fn aio_write
or
.Fn aio_writev
system call to avoid passing bogus context information to the kernel.
.Pp
Modifications of the Asynchronous I/O Control Block structure or the
Expand All @@ -114,14 +137,20 @@ is past the offset maximum for
.Fa iocb->aio_fildes ,
no I/O will occur.
.Sh RETURN VALUES
.Rv -std aio_write
.Rv -std aio_write aio_writev
.Sh ERRORS
The
.Fn aio_write
system call will fail if:
and
.Fn aio_writev
system calls will fail if:
.Bl -tag -width Er
.It Bq Er EAGAIN
The request was not queued because of system resource limitations.
.It Bq Er EFAULT
Part of
.Fa aio_iov
points outside the process's allocated address space.
.It Bq Er EINVAL
The asynchronous notification method in
.Fa iocb->aio_sigevent.sigev_notify
Expand All @@ -134,10 +163,14 @@ are unsafe and unsafe asynchronous I/O operations are disabled.
.Pp
The following conditions may be synchronously detected when the
.Fn aio_write
or
.Fn aio_writev
system call is made, or asynchronously, at any time thereafter.
If they
are detected at call time,
.Fn aio_write
or
.Fn aio_writev
returns -1 and sets
.Va errno
appropriately; otherwise the
Expand Down Expand Up @@ -203,11 +236,19 @@ system call
is expected to conform to the
.St -p1003.1
standard.
.Pp
The
.Fn aio_writev
system call is a FreeBSD extension, and should not be used in portable code.
.Sh HISTORY
The
.Fn aio_write
system call first appeared in
.Fx 3.0 .
The
.Fn aio_writev
system call first appeared in
.Fx 13.0 .
.Sh AUTHORS
This manual page was written by
.An Wes Peters Aq Mt wes@softweyr.com .
Expand Down
4 changes: 3 additions & 1 deletion share/man/man4/aio.4
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd June 22, 2017
.Dd January 2, 2021
.Dt AIO 4
.Os
.Sh NAME
Expand Down Expand Up @@ -215,10 +215,12 @@ as described in
.Xr aio_cancel 2 ,
.Xr aio_error 2 ,
.Xr aio_read 2 ,
.Xr aio_readv 2 ,
.Xr aio_return 2 ,
.Xr aio_suspend 2 ,
.Xr aio_waitcomplete 2 ,
.Xr aio_write 2 ,
.Xr aio_writev 2 ,
.Xr lio_listio 2 ,
.Xr sigevent 3 ,
.Xr sysctl 8
Expand Down
2 changes: 2 additions & 0 deletions sys/bsm/audit_kevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@
#define AUE_REALPATHAT 43264 /* FreeBSD-specific. */
#define AUE_CLOSERANGE 43265 /* FreeBSD-specific. */
#define AUE_SPECIALFD 43266 /* FreeBSD-specific. */
#define AUE_AIO_WRITEV 43267 /* FreeBSD-specific. */
#define AUE_AIO_READV 43268 /* FreeBSD-specific. */

/*
* Darwin BSM uses a number of AUE_O_* definitions, which are aliased to the
Expand Down
2 changes: 1 addition & 1 deletion sys/compat/freebsd32/freebsd32_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
return (error);
}

static int
int
freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
{
struct iovec32 iov32;
Expand Down
2 changes: 2 additions & 0 deletions sys/compat/freebsd32/freebsd32_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ int freebsd32_copyout_strings(struct image_params *imgp,
uintptr_t *stack_base);
int freebsd32_copyiniov(struct iovec32 *iovp, u_int iovcnt,
struct iovec **iov, int error);
int freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt,
struct uio **uiop);
void freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32);

struct image_args;
Expand Down
Loading

0 comments on commit 022ca2f

Please sign in to comment.