From owner-svn-src-all@freebsd.org Fri Aug 3 14:01:33 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 60FAE106AB29; Fri, 3 Aug 2018 14:01:33 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1424882740; Fri, 3 Aug 2018 14:01:33 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CF698215AE; Fri, 3 Aug 2018 14:01:32 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w73E1WhV061065; Fri, 3 Aug 2018 14:01:32 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w73E1WJY061063; Fri, 3 Aug 2018 14:01:32 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201808031401.w73E1WJY061063@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Fri, 3 Aug 2018 14:01:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r337239 - in stable/11: sys/kern tests/sys/aio X-SVN-Group: stable-11 X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: in stable/11: sys/kern tests/sys/aio X-SVN-Commit-Revision: 337239 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2018 14:01:33 -0000 Author: asomers Date: Fri Aug 3 14:01:32 2018 New Revision: 337239 URL: https://svnweb.freebsd.org/changeset/base/337239 Log: MFC r332631: lio_listio: return EAGAIN instead of EIO when out of resources This behavior is already documented by the man page, and suggested by POSIX. Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D15099 Modified: stable/11/sys/kern/vfs_aio.c stable/11/tests/sys/aio/Makefile stable/11/tests/sys/aio/lio_test.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/vfs_aio.c ============================================================================== --- stable/11/sys/kern/vfs_aio.c Fri Aug 3 12:47:54 2018 (r337238) +++ stable/11/sys/kern/vfs_aio.c Fri Aug 3 14:01:32 2018 (r337239) @@ -2135,7 +2135,7 @@ kern_lio_listio(struct thread *td, int mode, struct ai struct aioliojob *lj; struct kevent kev; int error; - int nerror; + int nagain, nerror; int i; if ((mode != LIO_NOWAIT) && (mode != LIO_WAIT)) @@ -2204,12 +2204,15 @@ kern_lio_listio(struct thread *td, int mode, struct ai /* * Get pointers to the list of I/O requests. */ + nagain = 0; nerror = 0; for (i = 0; i < nent; i++) { job = acb_list[i]; if (job != NULL) { error = aio_aqueue(td, job, lj, LIO_NOP, ops); - if (error != 0) + if (error == EAGAIN) + nagain++; + else if (error != 0) nerror++; } } @@ -2256,7 +2259,10 @@ kern_lio_listio(struct thread *td, int mode, struct ai if (nerror) return (EIO); - return (error); + else if (nagain) + return (EAGAIN); + else + return (error); } /* syscall - list directed I/O (REALTIME) */ Modified: stable/11/tests/sys/aio/Makefile ============================================================================== --- stable/11/tests/sys/aio/Makefile Fri Aug 3 12:47:54 2018 (r337238) +++ stable/11/tests/sys/aio/Makefile Fri Aug 3 14:01:32 2018 (r337239) @@ -6,6 +6,8 @@ ATF_TESTS_C+= aio_test ATF_TESTS_C+= lio_test TEST_METADATA.aio_test+= timeout="30" TEST_METADATA.lio_test+= timeout="10" +# Some lio_test testcases involve system resource limitations, so cannot run concurrently +TEST_METADATA.lio_test+= is_exclusive=true PLAIN_TESTS_C+= aio_kqueue_test PLAIN_TESTS_C+= lio_kqueue_test Modified: stable/11/tests/sys/aio/lio_test.c ============================================================================== --- stable/11/tests/sys/aio/lio_test.c Fri Aug 3 12:47:54 2018 (r337238) +++ stable/11/tests/sys/aio/lio_test.c Fri Aug 3 14:01:32 2018 (r337239) @@ -30,10 +30,13 @@ #include #include +#include #include +#include #include +#include "local.h" #include "freebsd_test_suite/macros.h" static sem_t completions; @@ -51,6 +54,73 @@ thr_handler(union sigval sv __unused) ATF_REQUIRE_EQ(0, sem_post(&completions)); } +/* + * If lio_listio is unable to enqueue any requests at all, it should return + * EAGAIN. + */ +ATF_TC_WITHOUT_HEAD(lio_listio_eagain_kevent); +ATF_TC_BODY(lio_listio_eagain_kevent, tc) +{ + int fd, i, j, kq, max_queue_per_proc, ios_per_call; + size_t max_queue_per_proc_size; + struct aiocb *aiocbs[2]; + struct aiocb **list[2]; + struct sigevent sev[2]; + char *buffer; + const char *path="tempfile"; + void *udata[2]; + + ATF_REQUIRE_KERNEL_MODULE("aio"); + ATF_REQUIRE_UNSAFE_AIO(); + + max_queue_per_proc_size = sizeof(max_queue_per_proc); + ATF_REQUIRE_EQ(sysctlbyname("vfs.aio.max_aio_queue_per_proc", + &max_queue_per_proc, &max_queue_per_proc_size, NULL, 0), 0); + ios_per_call = max_queue_per_proc; + + fd = open(path, O_RDWR|O_CREAT, 0666); + ATF_REQUIRE(fd >= 0); + + kq = kqueue(); + ATF_REQUIRE(kq > 0); + + buffer = calloc(1, 4096); + ATF_REQUIRE(buffer != NULL); + + /* + * Call lio_listio twice, each with the maximum number of operations. + * The first call should succeed and the second should fail. + */ + for (i = 0; i < 2; i++) { + aiocbs[i] = calloc(ios_per_call, sizeof(struct aiocb)); + ATF_REQUIRE(aiocbs[i] != NULL); + list[i] = calloc(ios_per_call, sizeof(struct aiocb*)); + ATF_REQUIRE(list[i] != NULL); + udata[i] = (void*)((caddr_t)0xdead0000 + i); + sev[i].sigev_notify = SIGEV_KEVENT; + sev[i].sigev_notify_kqueue = kq; + sev[i].sigev_value.sival_ptr = udata[i]; + for (j = 0; j < ios_per_call; j++) { + aiocbs[i][j].aio_fildes = fd; + aiocbs[i][j].aio_offset = (i * ios_per_call + j) * 4096; + aiocbs[i][j].aio_buf = buffer; + aiocbs[i][j].aio_nbytes = 4096; + aiocbs[i][j].aio_lio_opcode = LIO_WRITE; + list[i][j] = &aiocbs[i][j]; + } + } + + ATF_REQUIRE_EQ(0, lio_listio(LIO_NOWAIT, list[0], ios_per_call, &sev[0])); + ATF_REQUIRE_EQ(-1, lio_listio(LIO_NOWAIT, list[1], ios_per_call, &sev[1])); + /* + * The second lio_listio call should fail with EAGAIN. Bad timing may + * mean that some requests did get enqueued, but the result should + * still be EAGAIN. + */ + ATF_REQUIRE_EQ(errno, EAGAIN); +} + + /* With LIO_WAIT, an empty lio_listio should return immediately */ ATF_TC_WITHOUT_HEAD(lio_listio_empty_wait); ATF_TC_BODY(lio_listio_empty_wait, tc) @@ -136,6 +206,7 @@ ATF_TC_BODY(lio_listio_empty_nowait_thread, tc) ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, lio_listio_eagain_kevent); ATF_TP_ADD_TC(tp, lio_listio_empty_nowait_kevent); ATF_TP_ADD_TC(tp, lio_listio_empty_nowait_signal); ATF_TP_ADD_TC(tp, lio_listio_empty_nowait_thread);