lio_listio(2): add LIO_FOFFSET flag to ignore aiocb aio_offset

and use the current file offset instead.

Requested by:	Vinícius dos Santos Oliveira <vini.ipsmaker@gmail.com>
Reviewed by:	jhb
Discussed with:	asomers
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D43448
This commit is contained in:
Konstantin Belousov 2024-01-13 21:46:18 +02:00
parent c0b8047bdc
commit e4b7bbd6ab
3 changed files with 30 additions and 6 deletions

View file

@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.Dd August 22, 2021 .Dd January 13, 2024
.Dt LIO_LISTIO 2 .Dt LIO_LISTIO 2
.Os .Os
.Sh NAME .Sh NAME
@ -78,6 +78,19 @@ Write data as if by a call to
.El .El
.Pp .Pp
If the If the
.Dv LIO_READ ,
.Dv LIO_READV ,
.Dv LIO_WRITE ,
.Dv LIO_WRITEV
opcodes are or-ed with the
.Dv LIO_FOFFSET
flag, the corresponding read or write operation uses the current file
descriptor offset instead of
.Va aio_offset
from
.Vt aiocb .
.Pp
If the
.Fa mode .Fa mode
argument is argument is
.Dv LIO_WAIT , .Dv LIO_WAIT ,

View file

@ -229,6 +229,9 @@ typedef struct oaiocb {
#define KAIOCB_CLEARED 0x10 #define KAIOCB_CLEARED 0x10
#define KAIOCB_FINISHED 0x20 #define KAIOCB_FINISHED 0x20
/* ioflags */
#define KAIOCB_IO_FOFFSET 0x01
/* /*
* AIO process info * AIO process info
*/ */
@ -789,12 +792,14 @@ aio_process_rw(struct kaiocb *job)
if (job->uiop->uio_resid == 0) if (job->uiop->uio_resid == 0)
error = 0; error = 0;
else else
error = fo_read(fp, job->uiop, fp->f_cred, FOF_OFFSET, error = fo_read(fp, job->uiop, fp->f_cred,
td); (job->ioflags & KAIOCB_IO_FOFFSET) != 0 ? 0 :
FOF_OFFSET, td);
} else { } else {
if (fp->f_type == DTYPE_VNODE) if (fp->f_type == DTYPE_VNODE)
bwillwrite(); bwillwrite();
error = fo_write(fp, job->uiop, fp->f_cred, FOF_OFFSET, td); error = fo_write(fp, job->uiop, fp->f_cred, (job->ioflags &
KAIOCB_IO_FOFFSET) != 0 ? 0 : FOF_OFFSET, td);
} }
msgrcv_end = td->td_ru.ru_msgrcv; msgrcv_end = td->td_ru.ru_msgrcv;
msgsnd_end = td->td_ru.ru_msgsnd; msgsnd_end = td->td_ru.ru_msgsnd;
@ -1549,13 +1554,15 @@ aio_aqueue(struct thread *td, struct aiocb *ujob, struct aioliojob *lj,
/* Get the opcode. */ /* Get the opcode. */
if (type == LIO_NOP) { if (type == LIO_NOP) {
switch (job->uaiocb.aio_lio_opcode) { switch (job->uaiocb.aio_lio_opcode & ~LIO_FOFFSET) {
case LIO_WRITE: case LIO_WRITE:
case LIO_WRITEV: case LIO_WRITEV:
case LIO_NOP: case LIO_NOP:
case LIO_READ: case LIO_READ:
case LIO_READV: case LIO_READV:
opcode = job->uaiocb.aio_lio_opcode; opcode = job->uaiocb.aio_lio_opcode & ~LIO_FOFFSET;
if ((job->uaiocb.aio_lio_opcode & LIO_FOFFSET) != 0)
job->ioflags |= KAIOCB_IO_FOFFSET;
break; break;
default: default:
error = EINVAL; error = EINVAL;

View file

@ -51,6 +51,9 @@
#define LIO_DSYNC (0x10 | LIO_SYNC) #define LIO_DSYNC (0x10 | LIO_SYNC)
#define LIO_MLOCK 0x20 #define LIO_MLOCK 0x20
#endif #endif
#if __BSD_VISIBLE
#define LIO_FOFFSET 0x40
#endif
/* /*
* LIO modes * LIO modes
@ -129,6 +132,7 @@ struct kaiocb {
TAILQ_ENTRY(kaiocb) plist; /* (a) lists of pending / done jobs */ TAILQ_ENTRY(kaiocb) plist; /* (a) lists of pending / done jobs */
TAILQ_ENTRY(kaiocb) allist; /* (a) list of all jobs in proc */ TAILQ_ENTRY(kaiocb) allist; /* (a) list of all jobs in proc */
int jobflags; /* (a) job flags */ int jobflags; /* (a) job flags */
int ioflags; /* (*) io flags */
int inblock; /* (*) input blocks */ int inblock; /* (*) input blocks */
int outblock; /* (*) output blocks */ int outblock; /* (*) output blocks */
int msgsnd; /* (*) messages sent */ int msgsnd; /* (*) messages sent */