From nobody Wed Sep 06 21:56:33 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Rgx6B3Pf2z4sJ4b; Wed, 6 Sep 2023 21:56:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Rgx6B0SZFz3Zgd; Wed, 6 Sep 2023 21:56:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694037394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ftVxuJ/isWHQhCwuc0Zm11akAjAvrpPNJUUZQQo4HFU=; b=MRtzGtWcEfzX6FlQ3gBY6djWGJPFD3slfcIsS4std8N876bwEQ5EjlvfnGy8/hccixbRMZ pZkj3Hg821wyZ80elHfJWYnmcC1qcTU1NvUyDUJtCbcldud2dIgeUnQgA9dhOPOkskcS8v HgesZoUco3zfnaz7P1CtkQen1Tu2vSDy3/llPUFxXjUYdYa6Ji28RXRPINFPJGnVuc98iI GP6Ue1ItpjBlPbG6mtOc4EoPunWGXcxg0dmz07+N7kTHgCNJIl25BOS6yWy2sIZMN7bG8f VUZjfKOo/hOW28mrzFV5WFodhU987MsZCXqpc8ziMgm53n8FcuDuIYlsJzwpRQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694037394; a=rsa-sha256; cv=none; b=mgYtTdvfaAEmPNcrapBvrqu+pGoKDzTl4ZY/9zl0LyxtC4J4PpVG3GywXk5XbDZKPxV5WH +jbHnA2mLl2hvhtmlGJYxvSwVGT94K0+901Kra3OE3c7uQQKJk5wZ4dkypmxbZpYl15N+H 99g1OQyCsBwZ4WP9x5qzFo3aZmoRuSFGijLN2aYoaZvowxMwJqEUym4WwRpLatPyzWTcQe ZMV0jyjVY/7uv1XcaSARkKm5QcvuACuatZtDzpSG/PCedCsSN7MbiP8W5xEXdKd6SnjcuM tAZJWpkqd9yGJkHmFyq2l+R8h1VLiF3VgpX+4KAZCGY2hi63MGYVYf27ZhYMHQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694037394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ftVxuJ/isWHQhCwuc0Zm11akAjAvrpPNJUUZQQo4HFU=; b=sgQNajVlHP75ZtQ7TXVBEfeAlrAEsSmnemmwPc1f82pd3hVW8r5NHLGzR8dsBuWJZuM/x7 lJnsiuGwkPc6jjyCEuwZucw2Ta9NIfHKK/m3NGYhXayEVGqRO5fV87tt6mw3UVq08EpwQm FoMqhyJ5oAKGyDBiW+TN2FW84kOvex8gLyhTdOqIrW+yFk1Jgi9JRoL+VQRjsReyx2oyGz JGbdp7k677T1fo49sHKhSWGj/X618rB2H49gsSsm/oDX3Fz2cB2pZ6jkm0ITceno6RovPc yYog4ZuSFNTXwyq0Q/Xs0JapowTgyRhKqYXesuonTpRHjBwwFQJ+LKmnEHuJrA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Rgx696c0lzYkC; Wed, 6 Sep 2023 21:56:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 386LuXpc022468; Wed, 6 Sep 2023 21:56:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 386LuXvk022466; Wed, 6 Sep 2023 21:56:33 GMT (envelope-from git) Date: Wed, 6 Sep 2023 21:56:33 GMT Message-Id: <202309062156.386LuXvk022466@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 05bfa3e05896 - stable/13 - lio_listio(2): Allow LIO_READV and LIO_WRITEV. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 05bfa3e0589629bc88b8da31942252af8a559441 Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=05bfa3e0589629bc88b8da31942252af8a559441 commit 05bfa3e0589629bc88b8da31942252af8a559441 Author: Thomas Munro AuthorDate: 2021-08-22 09:48:59 +0000 Commit: John Baldwin CommitDate: 2023-09-06 21:56:09 +0000 lio_listio(2): Allow LIO_READV and LIO_WRITEV. Allow multiple vector IOs to be started with one system call. aio_readv() and aio_writev() already used these opcodes under the covers. This commit makes them available to user space. Being non-standard extensions, they're only visible if __BSD_VISIBLE is defined, like the functions. Reviewed by: asomers, kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D31627 (cherry picked from commit f30a1ae8d5290a52e898279bafc38556bf16bed8) --- lib/libc/sys/lio_listio.2 | 16 ++++++- sys/kern/vfs_aio.c | 4 ++ sys/sys/aio.h | 4 +- tests/sys/aio/lio_test.c | 109 ++++++++++++++++++++++++++++++++++++---------- usr.bin/truss/syscalls.c | 2 +- 5 files changed, 110 insertions(+), 25 deletions(-) diff --git a/lib/libc/sys/lio_listio.2 b/lib/libc/sys/lio_listio.2 index a477da7c6177..34d2490cca01 100644 --- a/lib/libc/sys/lio_listio.2 +++ b/lib/libc/sys/lio_listio.2 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 7, 2019 +.Dd August 22, 2021 .Dt LIO_LISTIO 2 .Os .Sh NAME @@ -64,11 +64,17 @@ The following operations are supported: .It Dv LIO_READ Read data as if by a call to .Xr aio_read 2 . +.It Dv LIO_READV +Read data as if by a call to +.Xr aio_readv 2 . .It Dv LIO_NOP No operation. .It Dv LIO_WRITE Write data as if by a call to .Xr aio_write 2 . +.It Dv LIO_WRITEV +Write data as if by a call to +.Xr aio_writev 2 . .El .Pp If the @@ -203,7 +209,9 @@ structure individually by calling .Sh SEE ALSO .Xr aio_error 2 , .Xr aio_read 2 , +.Xr aio_readv 2 , .Xr aio_write 2 , +.Xr aio_writev 2 , .Xr read 2 , .Xr write 2 , .Xr sigevent 3 , @@ -214,6 +222,12 @@ The .Fn lio_listio function is expected to conform to .St -p1003.1-2001 . +The +.Dv LIO_READV +and +.Dv LIO_WRITEV +operations are +.Fx extensions, and should not be used in portable code. .Sh HISTORY The .Fn lio_listio diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index bd739ebf7b54..02014ceefdf5 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -1419,6 +1419,8 @@ aiocb_copyin(struct aiocb *ujob, struct kaiocb *kjob, int type) error = copyin(ujob, kcb, sizeof(struct aiocb)); if (error) return (error); + if (type == LIO_NOP) + type = kcb->aio_lio_opcode; if (type & LIO_VECTORED) { /* malloc a uio and copy in the iovec */ error = copyinuio(__DEVOLATILE(struct iovec*, kcb->aio_iov), @@ -1557,8 +1559,10 @@ aio_aqueue(struct thread *td, struct aiocb *ujob, struct aioliojob *lj, if (type == LIO_NOP) { switch (job->uaiocb.aio_lio_opcode) { case LIO_WRITE: + case LIO_WRITEV: case LIO_NOP: case LIO_READ: + case LIO_READV: opcode = job->uaiocb.aio_lio_opcode; break; default: diff --git a/sys/sys/aio.h b/sys/sys/aio.h index d58ee5efd3d5..e9c5bdc63c87 100644 --- a/sys/sys/aio.h +++ b/sys/sys/aio.h @@ -41,10 +41,12 @@ #define LIO_NOP 0x0 #define LIO_WRITE 0x1 #define LIO_READ 0x2 -#if defined(_KERNEL) || defined(_WANT_ALL_LIO_OPCODES) +#if __BSD_VISIBLE #define LIO_VECTORED 0x4 #define LIO_WRITEV (LIO_WRITE | LIO_VECTORED) #define LIO_READV (LIO_READ | LIO_VECTORED) +#endif +#if defined(_KERNEL) || defined(_WANT_ALL_LIO_OPCODES) #define LIO_SYNC 0x8 #define LIO_DSYNC (0x10 | LIO_SYNC) #define LIO_MLOCK 0x20 diff --git a/tests/sys/aio/lio_test.c b/tests/sys/aio/lio_test.c index 94ce07086987..a04e54a39d9b 100644 --- a/tests/sys/aio/lio_test.c +++ b/tests/sys/aio/lio_test.c @@ -208,15 +208,96 @@ ATF_TC_BODY(lio_listio_empty_nowait_thread, tc) ATF_REQUIRE_EQ(0, sem_destroy(&completions)); } +/* + * A simple check that the allowed operations work. + */ +ATF_TC_WITHOUT_HEAD(lio_listio_opcodes); +ATF_TC_BODY(lio_listio_opcodes, tc) +{ + struct aiocb write_cb, read_cb, writev_cb, readv_cb; + struct aiocb *list[] = {&write_cb, &read_cb, &writev_cb, &readv_cb}; + struct iovec writev_iov[2]; + struct iovec readv_iov[2]; + char buffer[6]; + int fd; + + fd = open("testfile", O_CREAT | O_RDWR); + ATF_REQUIRE_MSG(fd >= 0, "open: %s", strerror(errno)); + + /* We start with numbers in a file and letters in memory... */ + ATF_CHECK_EQ(6, write(fd, "123456", 6)); + memcpy(buffer, "abcdef", 6); + + /* a -> 1 */ + bzero(&write_cb, sizeof(write_cb)); + write_cb.aio_sigevent.sigev_notify = SIGEV_NONE; + write_cb.aio_fildes = fd; + write_cb.aio_lio_opcode = LIO_WRITE; + write_cb.aio_buf = &buffer[0]; + write_cb.aio_nbytes = 1; + write_cb.aio_offset = 0; + + /* b <- 2 */ + bzero(&read_cb, sizeof(read_cb)); + read_cb.aio_sigevent.sigev_notify = SIGEV_NONE; + read_cb.aio_fildes = fd; + read_cb.aio_lio_opcode = LIO_READ; + read_cb.aio_buf = &buffer[1]; + read_cb.aio_nbytes = 1; + read_cb.aio_offset = 1; + + /* d -> 3, c -> 4 */ + writev_iov[0].iov_base = &buffer[3]; + writev_iov[0].iov_len = 1; + writev_iov[1].iov_base = &buffer[2]; + writev_iov[1].iov_len = 1; + bzero(&writev_cb, sizeof(writev_cb)); + writev_cb.aio_sigevent.sigev_notify = SIGEV_NONE; + writev_cb.aio_fildes = fd; + writev_cb.aio_lio_opcode = LIO_WRITEV; + writev_cb.aio_iov = &writev_iov; + writev_cb.aio_iovcnt = 2; + writev_cb.aio_offset = 2; + + /* f <- 5, e <- 6 */ + readv_iov[0].iov_base = &buffer[5]; + readv_iov[0].iov_len = 1; + readv_iov[1].iov_base = &buffer[4]; + readv_iov[1].iov_len = 1; + bzero(&readv_cb, sizeof(readv_cb)); + readv_cb.aio_sigevent.sigev_notify = SIGEV_NONE; + readv_cb.aio_fildes = fd; + readv_cb.aio_lio_opcode = LIO_READV; + readv_cb.aio_iov = &readv_iov; + readv_cb.aio_iovcnt = 2; + readv_cb.aio_offset = 4; + + ATF_CHECK_EQ(0, lio_listio(LIO_WAIT, list, nitems(list), NULL)); + ATF_CHECK_EQ(0, aio_error(&write_cb)); + ATF_CHECK_EQ(1, aio_return(&write_cb)); + ATF_CHECK_EQ(0, aio_error(&read_cb)); + ATF_CHECK_EQ(1, aio_return(&read_cb)); + ATF_CHECK_EQ(0, aio_error(&writev_cb)); + ATF_CHECK_EQ(2, aio_return(&writev_cb)); + ATF_CHECK_EQ(0, aio_error(&readv_cb)); + ATF_CHECK_EQ(2, aio_return(&readv_cb)); + + ATF_CHECK_EQ(0, memcmp(buffer, "a2cd65", 6)); + ATF_CHECK_EQ(6, pread(fd, buffer, 6, 0)); + ATF_CHECK_EQ(0, memcmp(buffer, "a2dc56", 6)); + + close(fd); +} + + /* * Only select opcodes are allowed with lio_listio */ ATF_TC_WITHOUT_HEAD(lio_listio_invalid_opcode); ATF_TC_BODY(lio_listio_invalid_opcode, tc) { - struct aiocb sync_cb, mlock_cb, writev_cb, readv_cb; - struct aiocb *list[] = {&sync_cb, &mlock_cb, &writev_cb, &readv_cb}; - struct iovec iov; + struct aiocb sync_cb, mlock_cb; + struct aiocb *list[] = {&sync_cb, &mlock_cb}; int fd; fd = open("testfile", O_CREAT | O_RDWR); @@ -229,30 +310,13 @@ ATF_TC_BODY(lio_listio_invalid_opcode, tc) bzero(&mlock_cb, sizeof(mlock_cb)); mlock_cb.aio_lio_opcode = LIO_MLOCK; - iov.iov_base = NULL; - iov.iov_len = 0; - - bzero(&readv_cb, sizeof(readv_cb)); - readv_cb.aio_fildes = fd; - readv_cb.aio_lio_opcode = LIO_READV; - readv_cb.aio_iov = &iov; - readv_cb.aio_iovcnt = 1; - - bzero(&writev_cb, sizeof(writev_cb)); - writev_cb.aio_fildes = fd; - writev_cb.aio_lio_opcode = LIO_WRITEV; - writev_cb.aio_iov = &iov; - writev_cb.aio_iovcnt = 1; - ATF_CHECK_ERRNO(EIO, lio_listio(LIO_WAIT, list, nitems(list), NULL)); ATF_CHECK_EQ(EINVAL, aio_error(&sync_cb)); ATF_CHECK_ERRNO(EINVAL, aio_return(&sync_cb) < 0); ATF_CHECK_EQ(EINVAL, aio_error(&mlock_cb)); ATF_CHECK_ERRNO(EINVAL, aio_return(&mlock_cb) < 0); - ATF_CHECK_EQ(EINVAL, aio_error(&readv_cb)); - ATF_CHECK_ERRNO(EINVAL, aio_return(&readv_cb) < 0); - ATF_CHECK_EQ(EINVAL, aio_error(&writev_cb)); - ATF_CHECK_ERRNO(EINVAL, aio_return(&writev_cb) < 0); + + close(fd); } @@ -265,6 +329,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, lio_listio_empty_nowait_signal); ATF_TP_ADD_TC(tp, lio_listio_empty_nowait_thread); ATF_TP_ADD_TC(tp, lio_listio_empty_wait); + ATF_TP_ADD_TC(tp, lio_listio_opcodes); ATF_TP_ADD_TC(tp, lio_listio_invalid_opcode); return (atf_no_error()); diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index fff62ce7911c..010308beae3e 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -763,7 +763,7 @@ static struct xlat lio_modes[] = { }; static struct xlat lio_opcodes[] = { - X(LIO_WRITE) X(LIO_READ) X(LIO_NOP) + X(LIO_WRITE) X(LIO_READ) X(LIO_READV) X(LIO_WRITEV) X(LIO_NOP) XEND };