2 * Copyright (c) 2004 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Regression test to do some very basic AIO exercising on several types of
31 * file descriptors. Currently, the tests consist of initializing a fixed
32 * size buffer with pseudo-random data, writing it to one fd using AIO, then
33 * reading it from a second descriptor using AIO. For some targets, the same
34 * fd is used for write and read (i.e., file, md device), but for others the
35 * operation is performed on a peer (pty, socket, fifo, etc). For each file
36 * descriptor type, several completion methods are tested. This test program
37 * does not attempt to exercise error cases or more subtle asynchronous
38 * behavior, just make sure that the basic operations work on some basic object
42 #include <sys/param.h>
43 #include <sys/module.h>
44 #include <sys/resource.h>
45 #include <sys/socket.h>
47 #include <sys/mdioctl.h>
55 #include <semaphore.h>
65 #include "freebsd_test_suite/macros.h"
69 * GLOBAL_MAX sets the largest usable buffer size to be read and written, as
70 * it sizes ac_buffer in the aio_context structure. It is also the default
71 * size for file I/O. For other types, we use smaller blocks or we risk
72 * blocking (and we run in a single process/thread so that would be bad).
74 #define GLOBAL_MAX 16384
76 #define BUFFER_MAX GLOBAL_MAX
79 * A completion function will block until the aio has completed, then return
80 * the result of the aio. errno will be set appropriately.
82 typedef ssize_t (*completion)(struct aiocb*);
85 int ac_read_fd, ac_write_fd;
87 char ac_buffer[GLOBAL_MAX];
92 static sem_t completions;
96 * Fill a buffer given a seed that can be fed into srandom() to initialize
97 * the PRNG in a repeatable manner.
100 aio_fill_buffer(char *buffer, int len, long seed)
106 for (i = 0; i < len; i++) {
107 ch = random() & 0xff;
113 * Test that a buffer matches a given seed. See aio_fill_buffer(). Return
114 * (1) on a match, (0) on a mismatch.
117 aio_test_buffer(char *buffer, int len, long seed)
123 for (i = 0; i < len; i++) {
124 ch = random() & 0xff;
132 * Initialize a testing context given the file descriptors provided by the
136 aio_context_init(struct aio_context *ac, int read_fd,
137 int write_fd, int buflen)
140 ATF_REQUIRE_MSG(buflen <= BUFFER_MAX,
141 "aio_context_init: buffer too large (%d > %d)",
143 bzero(ac, sizeof(*ac));
144 ac->ac_read_fd = read_fd;
145 ac->ac_write_fd = write_fd;
146 ac->ac_buflen = buflen;
148 ac->ac_seed = random();
149 aio_fill_buffer(ac->ac_buffer, buflen, ac->ac_seed);
150 ATF_REQUIRE_MSG(aio_test_buffer(ac->ac_buffer, buflen,
151 ac->ac_seed) != 0, "aio_test_buffer: internal error");
155 poll(struct aiocb *aio)
159 while ((error = aio_error(aio)) == EINPROGRESS)
164 return (aio_return(aio));
168 sigusr1_handler(int sig __unused)
170 ATF_REQUIRE_EQ(0, sem_post(&completions));
174 thr_handler(union sigval sv __unused)
176 ATF_REQUIRE_EQ(0, sem_post(&completions));
180 poll_signaled(struct aiocb *aio)
184 ATF_REQUIRE_EQ(0, sem_wait(&completions));
185 error = aio_error(aio);
191 return (aio_return(aio));
198 * Setup a signal handler for signal delivery tests
199 * This isn't thread safe, but it's ok since ATF runs each testcase in a
202 static struct sigevent*
205 static struct sigevent sev;
207 ATF_REQUIRE_EQ(0, sem_init(&completions, false, 0));
208 sev.sigev_notify = SIGEV_SIGNAL;
209 sev.sigev_signo = SIGUSR1;
210 ATF_REQUIRE(SIG_ERR != signal(SIGUSR1, sigusr1_handler));
215 * Setup a thread for thread delivery tests
216 * This isn't thread safe, but it's ok since ATF runs each testcase in a
219 static struct sigevent*
222 static struct sigevent sev;
224 ATF_REQUIRE_EQ(0, sem_init(&completions, false, 0));
225 sev.sigev_notify = SIGEV_THREAD;
226 sev.sigev_notify_function = thr_handler;
227 sev.sigev_notify_attributes = NULL;
232 suspend(struct aiocb *aio)
234 const struct aiocb *const iocbs[] = {aio};
237 error = aio_suspend(iocbs, 1, NULL);
239 return (aio_return(aio));
245 waitcomplete(struct aiocb *aio)
250 ret = aio_waitcomplete(&aiop, NULL);
251 ATF_REQUIRE_EQ(aio, aiop);
256 * Perform a simple write test of our initialized data buffer to the provided
260 aio_write_test(struct aio_context *ac, completion comp, struct sigevent *sev)
265 bzero(&aio, sizeof(aio));
266 aio.aio_buf = ac->ac_buffer;
267 aio.aio_nbytes = ac->ac_buflen;
268 aio.aio_fildes = ac->ac_write_fd;
271 aio.aio_sigevent = *sev;
273 if (aio_write(&aio) < 0)
274 atf_tc_fail("aio_write failed: %s", strerror(errno));
278 atf_tc_fail("aio failed: %s", strerror(errno));
280 if (len != ac->ac_buflen)
281 atf_tc_fail("aio short write (%jd)", (intmax_t)len);
285 * Perform a vectored I/O test of our initialized data buffer to the provided
288 * To vectorize the linear buffer, chop it up into two pieces of dissimilar
289 * size, and swap their offsets.
292 aio_writev_test(struct aio_context *ac, completion comp, struct sigevent *sev)
299 bzero(&aio, sizeof(aio));
301 aio.aio_fildes = ac->ac_write_fd;
303 len0 = ac->ac_buflen * 3 / 4;
304 len1 = ac->ac_buflen / 4;
305 iov[0].iov_base = ac->ac_buffer + len1;
306 iov[0].iov_len = len0;
307 iov[1].iov_base = ac->ac_buffer;
308 iov[1].iov_len = len1;
312 aio.aio_sigevent = *sev;
314 if (aio_writev(&aio) < 0)
315 atf_tc_fail("aio_writev failed: %s", strerror(errno));
319 atf_tc_fail("aio failed: %s", strerror(errno));
321 if (len != ac->ac_buflen)
322 atf_tc_fail("aio short write (%jd)", (intmax_t)len);
326 * Perform a simple read test of our initialized data buffer from the
327 * provided file descriptor.
330 aio_read_test(struct aio_context *ac, completion comp, struct sigevent *sev)
335 bzero(ac->ac_buffer, ac->ac_buflen);
336 bzero(&aio, sizeof(aio));
337 aio.aio_buf = ac->ac_buffer;
338 aio.aio_nbytes = ac->ac_buflen;
339 aio.aio_fildes = ac->ac_read_fd;
342 aio.aio_sigevent = *sev;
344 if (aio_read(&aio) < 0)
345 atf_tc_fail("aio_read failed: %s", strerror(errno));
349 atf_tc_fail("aio failed: %s", strerror(errno));
351 ATF_REQUIRE_EQ_MSG(len, ac->ac_buflen,
352 "aio short read (%jd)", (intmax_t)len);
354 if (aio_test_buffer(ac->ac_buffer, ac->ac_buflen, ac->ac_seed) == 0)
355 atf_tc_fail("buffer mismatched");
359 aio_readv_test(struct aio_context *ac, completion comp, struct sigevent *sev)
366 bzero(ac->ac_buffer, ac->ac_buflen);
367 bzero(&aio, sizeof(aio));
368 aio.aio_fildes = ac->ac_read_fd;
370 len0 = ac->ac_buflen * 3 / 4;
371 len1 = ac->ac_buflen / 4;
372 iov[0].iov_base = ac->ac_buffer + len1;
373 iov[0].iov_len = len0;
374 iov[1].iov_base = ac->ac_buffer;
375 iov[1].iov_len = len1;
379 aio.aio_sigevent = *sev;
381 if (aio_readv(&aio) < 0)
382 atf_tc_fail("aio_read failed: %s", strerror(errno));
386 atf_tc_fail("aio failed: %s", strerror(errno));
388 ATF_REQUIRE_EQ_MSG(len, ac->ac_buflen,
389 "aio short read (%jd)", (intmax_t)len);
391 if (aio_test_buffer(ac->ac_buffer, ac->ac_buflen, ac->ac_seed) == 0)
392 atf_tc_fail("buffer mismatched");
396 * Series of type-specific tests for AIO. For now, we just make sure we can
397 * issue a write and then a read to each type. We assume that once a write
398 * is issued, a read can follow.
402 * Test with a classic file. Assumes we can create a moderate size temporary
405 #define FILE_LEN GLOBAL_MAX
406 #define FILE_PATHNAME "testfile"
409 aio_file_test(completion comp, struct sigevent *sev, bool vectored)
411 struct aio_context ac;
414 ATF_REQUIRE_KERNEL_MODULE("aio");
415 ATF_REQUIRE_UNSAFE_AIO();
417 fd = open(FILE_PATHNAME, O_RDWR | O_CREAT, 0600);
418 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
420 aio_context_init(&ac, fd, fd, FILE_LEN);
422 aio_writev_test(&ac, comp, sev);
423 aio_readv_test(&ac, comp, sev);
425 aio_write_test(&ac, comp, sev);
426 aio_read_test(&ac, comp, sev);
431 ATF_TC_WITHOUT_HEAD(file_poll);
432 ATF_TC_BODY(file_poll, tc)
434 aio_file_test(poll, NULL, false);
437 ATF_TC_WITHOUT_HEAD(file_signal);
438 ATF_TC_BODY(file_signal, tc)
440 aio_file_test(poll_signaled, setup_signal(), false);
443 ATF_TC_WITHOUT_HEAD(file_suspend);
444 ATF_TC_BODY(file_suspend, tc)
446 aio_file_test(suspend, NULL, false);
449 ATF_TC_WITHOUT_HEAD(file_thread);
450 ATF_TC_BODY(file_thread, tc)
452 aio_file_test(poll_signaled, setup_thread(), false);
455 ATF_TC_WITHOUT_HEAD(file_waitcomplete);
456 ATF_TC_BODY(file_waitcomplete, tc)
458 aio_file_test(waitcomplete, NULL, false);
462 #define FIFO_PATHNAME "testfifo"
465 aio_fifo_test(completion comp, struct sigevent *sev)
467 int error, read_fd = -1, write_fd = -1;
468 struct aio_context ac;
470 ATF_REQUIRE_KERNEL_MODULE("aio");
471 ATF_REQUIRE_UNSAFE_AIO();
473 ATF_REQUIRE_MSG(mkfifo(FIFO_PATHNAME, 0600) != -1,
474 "mkfifo failed: %s", strerror(errno));
476 read_fd = open(FIFO_PATHNAME, O_RDONLY | O_NONBLOCK);
480 atf_tc_fail("read_fd open failed: %s",
484 write_fd = open(FIFO_PATHNAME, O_WRONLY);
485 if (write_fd == -1) {
488 atf_tc_fail("write_fd open failed: %s",
492 aio_context_init(&ac, read_fd, write_fd, FIFO_LEN);
493 aio_write_test(&ac, comp, sev);
494 aio_read_test(&ac, comp, sev);
500 ATF_TC_WITHOUT_HEAD(fifo_poll);
501 ATF_TC_BODY(fifo_poll, tc)
503 aio_fifo_test(poll, NULL);
506 ATF_TC_WITHOUT_HEAD(fifo_signal);
507 ATF_TC_BODY(fifo_signal, tc)
509 aio_fifo_test(poll_signaled, setup_signal());
512 ATF_TC_WITHOUT_HEAD(fifo_suspend);
513 ATF_TC_BODY(fifo_suspend, tc)
515 aio_fifo_test(suspend, NULL);
518 ATF_TC_WITHOUT_HEAD(fifo_thread);
519 ATF_TC_BODY(fifo_thread, tc)
521 aio_fifo_test(poll_signaled, setup_thread());
524 ATF_TC_WITHOUT_HEAD(fifo_waitcomplete);
525 ATF_TC_BODY(fifo_waitcomplete, tc)
527 aio_fifo_test(waitcomplete, NULL);
530 #define UNIX_SOCKETPAIR_LEN 256
532 aio_unix_socketpair_test(completion comp, struct sigevent *sev, bool vectored)
534 struct aio_context ac;
535 struct rusage ru_before, ru_after;
538 ATF_REQUIRE_KERNEL_MODULE("aio");
540 ATF_REQUIRE_MSG(socketpair(PF_UNIX, SOCK_STREAM, 0, sockets) != -1,
541 "socketpair failed: %s", strerror(errno));
543 aio_context_init(&ac, sockets[0], sockets[1], UNIX_SOCKETPAIR_LEN);
544 ATF_REQUIRE_MSG(getrusage(RUSAGE_SELF, &ru_before) != -1,
545 "getrusage failed: %s", strerror(errno));
547 aio_writev_test(&ac, comp, sev);
548 aio_readv_test(&ac, comp, sev);
550 aio_write_test(&ac, comp, sev);
551 aio_read_test(&ac, comp, sev);
553 ATF_REQUIRE_MSG(getrusage(RUSAGE_SELF, &ru_after) != -1,
554 "getrusage failed: %s", strerror(errno));
555 ATF_REQUIRE(ru_after.ru_msgsnd == ru_before.ru_msgsnd + 1);
556 ATF_REQUIRE(ru_after.ru_msgrcv == ru_before.ru_msgrcv + 1);
562 ATF_TC_WITHOUT_HEAD(socket_poll);
563 ATF_TC_BODY(socket_poll, tc)
565 aio_unix_socketpair_test(poll, NULL, false);
568 ATF_TC_WITHOUT_HEAD(socket_signal);
569 ATF_TC_BODY(socket_signal, tc)
571 aio_unix_socketpair_test(poll_signaled, setup_signal(), false);
574 ATF_TC_WITHOUT_HEAD(socket_suspend);
575 ATF_TC_BODY(socket_suspend, tc)
577 aio_unix_socketpair_test(suspend, NULL, false);
580 ATF_TC_WITHOUT_HEAD(socket_thread);
581 ATF_TC_BODY(socket_thread, tc)
583 aio_unix_socketpair_test(poll_signaled, setup_thread(), false);
586 ATF_TC_WITHOUT_HEAD(socket_waitcomplete);
587 ATF_TC_BODY(socket_waitcomplete, tc)
589 aio_unix_socketpair_test(waitcomplete, NULL, false);
599 aio_pty_test(completion comp, struct sigevent *sev)
601 struct aio_context ac;
602 int read_fd, write_fd;
606 ATF_REQUIRE_KERNEL_MODULE("aio");
607 ATF_REQUIRE_UNSAFE_AIO();
609 ATF_REQUIRE_MSG(openpty(&read_fd, &write_fd, NULL, NULL, NULL) == 0,
610 "openpty failed: %s", strerror(errno));
613 if (tcgetattr(write_fd, &ts) < 0) {
616 atf_tc_fail("tcgetattr failed: %s", strerror(errno));
619 if (tcsetattr(write_fd, TCSANOW, &ts) < 0) {
622 atf_tc_fail("tcsetattr failed: %s", strerror(errno));
624 aio_context_init(&ac, read_fd, write_fd, PTY_LEN);
626 aio_write_test(&ac, comp, sev);
627 aio_read_test(&ac, comp, sev);
633 ATF_TC_WITHOUT_HEAD(pty_poll);
634 ATF_TC_BODY(pty_poll, tc)
636 aio_pty_test(poll, NULL);
639 ATF_TC_WITHOUT_HEAD(pty_signal);
640 ATF_TC_BODY(pty_signal, tc)
642 aio_pty_test(poll_signaled, setup_signal());
645 ATF_TC_WITHOUT_HEAD(pty_suspend);
646 ATF_TC_BODY(pty_suspend, tc)
648 aio_pty_test(suspend, NULL);
651 ATF_TC_WITHOUT_HEAD(pty_thread);
652 ATF_TC_BODY(pty_thread, tc)
654 aio_pty_test(poll_signaled, setup_thread());
657 ATF_TC_WITHOUT_HEAD(pty_waitcomplete);
658 ATF_TC_BODY(pty_waitcomplete, tc)
660 aio_pty_test(waitcomplete, NULL);
665 aio_pipe_test(completion comp, struct sigevent *sev)
667 struct aio_context ac;
670 ATF_REQUIRE_KERNEL_MODULE("aio");
671 ATF_REQUIRE_UNSAFE_AIO();
673 ATF_REQUIRE_MSG(pipe(pipes) != -1,
674 "pipe failed: %s", strerror(errno));
676 aio_context_init(&ac, pipes[0], pipes[1], PIPE_LEN);
677 aio_write_test(&ac, comp, sev);
678 aio_read_test(&ac, comp, sev);
684 ATF_TC_WITHOUT_HEAD(pipe_poll);
685 ATF_TC_BODY(pipe_poll, tc)
687 aio_pipe_test(poll, NULL);
690 ATF_TC_WITHOUT_HEAD(pipe_signal);
691 ATF_TC_BODY(pipe_signal, tc)
693 aio_pipe_test(poll_signaled, setup_signal());
696 ATF_TC_WITHOUT_HEAD(pipe_suspend);
697 ATF_TC_BODY(pipe_suspend, tc)
699 aio_pipe_test(suspend, NULL);
702 ATF_TC_WITHOUT_HEAD(pipe_thread);
703 ATF_TC_BODY(pipe_thread, tc)
705 aio_pipe_test(poll_signaled, setup_thread());
708 ATF_TC_WITHOUT_HEAD(pipe_waitcomplete);
709 ATF_TC_BODY(pipe_waitcomplete, tc)
711 aio_pipe_test(waitcomplete, NULL);
714 #define MD_LEN GLOBAL_MAX
715 #define MDUNIT_LINK "mdunit_link"
720 int error, fd, mdctl_fd, unit;
721 char pathname[PATH_MAX];
722 struct md_ioctl mdio;
725 ATF_REQUIRE_KERNEL_MODULE("aio");
727 mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0);
728 ATF_REQUIRE_MSG(mdctl_fd != -1,
729 "opening /dev/%s failed: %s", MDCTL_NAME, strerror(errno));
731 bzero(&mdio, sizeof(mdio));
732 mdio.md_version = MDIOVERSION;
733 mdio.md_type = MD_MALLOC;
734 mdio.md_options = MD_AUTOUNIT | MD_COMPRESS;
735 mdio.md_mediasize = GLOBAL_MAX;
736 mdio.md_sectorsize = 512;
737 strlcpy(buf, __func__, sizeof(buf));
740 if (ioctl(mdctl_fd, MDIOCATTACH, &mdio) < 0) {
743 atf_tc_fail("ioctl MDIOCATTACH failed: %s", strerror(errno));
747 /* Store the md unit number in a symlink for future cleanup */
749 snprintf(buf, sizeof(buf), "%d", unit);
750 ATF_REQUIRE_EQ(0, symlink(buf, MDUNIT_LINK));
751 snprintf(pathname, PATH_MAX, "/dev/md%d", unit);
752 fd = open(pathname, O_RDWR);
753 ATF_REQUIRE_MSG(fd != -1,
754 "opening %s failed: %s", pathname, strerror(errno));
762 struct md_ioctl mdio;
763 int mdctl_fd, n, unit;
766 mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0);
768 fprintf(stderr, "opening /dev/%s failed: %s\n", MDCTL_NAME,
772 n = readlink(MDUNIT_LINK, buf, sizeof(buf) - 1);
775 if (sscanf(buf, "%d", &unit) == 1 && unit >= 0) {
776 bzero(&mdio, sizeof(mdio));
777 mdio.md_version = MDIOVERSION;
779 if (ioctl(mdctl_fd, MDIOCDETACH, &mdio) == -1) {
781 "ioctl MDIOCDETACH unit %d failed: %s\n",
782 unit, strerror(errno));
791 aio_md_test(completion comp, struct sigevent *sev, bool vectored)
793 struct aio_context ac;
797 aio_context_init(&ac, fd, fd, MD_LEN);
799 aio_writev_test(&ac, comp, sev);
800 aio_readv_test(&ac, comp, sev);
802 aio_write_test(&ac, comp, sev);
803 aio_read_test(&ac, comp, sev);
809 ATF_TC_WITH_CLEANUP(md_poll);
810 ATF_TC_HEAD(md_poll, tc)
813 atf_tc_set_md_var(tc, "require.user", "root");
815 ATF_TC_BODY(md_poll, tc)
817 aio_md_test(poll, NULL, false);
819 ATF_TC_CLEANUP(md_poll, tc)
824 ATF_TC_WITH_CLEANUP(md_signal);
825 ATF_TC_HEAD(md_signal, tc)
828 atf_tc_set_md_var(tc, "require.user", "root");
830 ATF_TC_BODY(md_signal, tc)
832 aio_md_test(poll_signaled, setup_signal(), false);
834 ATF_TC_CLEANUP(md_signal, tc)
839 ATF_TC_WITH_CLEANUP(md_suspend);
840 ATF_TC_HEAD(md_suspend, tc)
843 atf_tc_set_md_var(tc, "require.user", "root");
845 ATF_TC_BODY(md_suspend, tc)
847 aio_md_test(suspend, NULL, false);
849 ATF_TC_CLEANUP(md_suspend, tc)
854 ATF_TC_WITH_CLEANUP(md_thread);
855 ATF_TC_HEAD(md_thread, tc)
858 atf_tc_set_md_var(tc, "require.user", "root");
860 ATF_TC_BODY(md_thread, tc)
862 aio_md_test(poll_signaled, setup_thread(), false);
864 ATF_TC_CLEANUP(md_thread, tc)
869 ATF_TC_WITH_CLEANUP(md_waitcomplete);
870 ATF_TC_HEAD(md_waitcomplete, tc)
873 atf_tc_set_md_var(tc, "require.user", "root");
875 ATF_TC_BODY(md_waitcomplete, tc)
877 aio_md_test(waitcomplete, NULL, false);
879 ATF_TC_CLEANUP(md_waitcomplete, tc)
884 #define ZVOL_VDEV_PATHNAME "test_vdev"
885 #define POOL_SIZE (1 << 28) /* 256 MB */
886 #define ZVOL_SIZE "64m"
887 #define POOL_NAME "aio_testpool"
888 #define ZVOL_NAME "aio_testvol"
901 ATF_REQUIRE_KERNEL_MODULE("aio");
902 ATF_REQUIRE_KERNEL_MODULE("zfs");
904 fd = open(ZVOL_VDEV_PATHNAME, O_RDWR | O_CREAT, 0600);
905 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
906 ATF_REQUIRE_EQ_MSG(0,
907 ftruncate(fd, POOL_SIZE), "ftruncate failed: %s", strerror(errno));
911 pidfile = fopen("pidfile", "w");
912 ATF_REQUIRE_MSG(NULL != pidfile, "fopen: %s", strerror(errno));
913 fprintf(pidfile, "%d", pid);
916 snprintf(pool_name, sizeof(pool_name), POOL_NAME ".%d", pid);
917 snprintf(zvol_name, sizeof(zvol_name), "%s/" ZVOL_NAME, pool_name);
918 snprintf(cmd, sizeof(cmd), "zpool create %s $PWD/" ZVOL_VDEV_PATHNAME,
920 ATF_REQUIRE_EQ_MSG(0, system(cmd),
921 "zpool create failed: %s", strerror(errno));
922 snprintf(cmd, sizeof(cmd),
923 "zfs create -o volblocksize=8192 -o volmode=dev -V "
924 ZVOL_SIZE " %s", zvol_name);
925 ATF_REQUIRE_EQ_MSG(0, system(cmd),
926 "zfs create failed: %s", strerror(errno));
928 snprintf(devname, sizeof(devname), "/dev/zvol/%s", zvol_name);
930 fd = open(devname, O_RDWR);
931 } while (fd == -1 && errno == EINTR) ;
932 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
937 aio_zvol_cleanup(void)
943 pidfile = fopen("pidfile", "r");
944 if (pidfile == NULL && errno == ENOENT) {
945 /* Setup probably failed */
948 ATF_REQUIRE_MSG(NULL != pidfile, "fopen: %s", strerror(errno));
949 ATF_REQUIRE_EQ(1, fscanf(pidfile, "%d", &testpid));
952 snprintf(cmd, sizeof(cmd), "zpool destroy " POOL_NAME ".%d", testpid);
957 ATF_TC_WITHOUT_HEAD(aio_large_read_test);
958 ATF_TC_BODY(aio_large_read_test, tc)
960 struct aiocb cb, *cbp;
968 ATF_REQUIRE_KERNEL_MODULE("aio");
969 ATF_REQUIRE_UNSAFE_AIO();
972 len = sizeof(clamped);
973 if (sysctlbyname("debug.iosize_max_clamp", &clamped, &len, NULL, 0) ==
975 atf_libc_error(errno, "Failed to read debug.iosize_max_clamp");
978 /* Determine the maximum supported read(2) size. */
985 fd = open(FILE_PATHNAME, O_RDWR | O_CREAT, 0600);
986 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
988 unlink(FILE_PATHNAME);
990 memset(&cb, 0, sizeof(cb));
994 if (aio_read(&cb) == -1)
995 atf_tc_fail("aio_read() of maximum read size failed: %s",
998 nread = aio_waitcomplete(&cbp, NULL);
1000 atf_tc_fail("aio_waitcomplete() failed: %s", strerror(errno));
1002 atf_tc_fail("aio_read() from empty file returned data: %zd",
1005 memset(&cb, 0, sizeof(cb));
1006 cb.aio_nbytes = len + 1;
1009 if (aio_read(&cb) == -1) {
1010 if (errno == EINVAL)
1012 atf_tc_fail("aio_read() of too large read size failed: %s",
1016 nread = aio_waitcomplete(&cbp, NULL);
1018 if (errno == EINVAL)
1020 atf_tc_fail("aio_waitcomplete() failed: %s", strerror(errno));
1022 atf_tc_fail("aio_read() of too large read size returned: %zd", nread);
1029 * This tests for a bug where arriving socket data can wakeup multiple
1030 * AIO read requests resulting in an uncancellable request.
1032 ATF_TC_WITHOUT_HEAD(aio_socket_two_reads);
1033 ATF_TC_BODY(aio_socket_two_reads, tc)
1044 ATF_REQUIRE_KERNEL_MODULE("aio");
1045 #if __FreeBSD_version < 1100101
1046 aft_tc_skip("kernel version %d is too old (%d required)",
1047 __FreeBSD_version, 1100101);
1050 ATF_REQUIRE(socketpair(PF_UNIX, SOCK_STREAM, 0, s) != -1);
1052 /* Queue two read requests. */
1053 memset(&ioreq, 0, sizeof(ioreq));
1054 for (i = 0; i < nitems(ioreq); i++) {
1055 ioreq[i].iocb.aio_nbytes = sizeof(ioreq[i].buffer);
1056 ioreq[i].iocb.aio_fildes = s[0];
1057 ioreq[i].iocb.aio_buf = ioreq[i].buffer;
1058 ATF_REQUIRE(aio_read(&ioreq[i].iocb) == 0);
1061 /* Send a single byte. This should complete one request. */
1063 ATF_REQUIRE(write(s[1], &c, sizeof(c)) == 1);
1065 ATF_REQUIRE(aio_waitcomplete(&iocb, NULL) == 1);
1067 /* Determine which request completed and verify the data was read. */
1068 if (iocb == &ioreq[0].iocb)
1072 ATF_REQUIRE(ioreq[i].buffer[0] == c);
1077 * Try to cancel the other request. On broken systems this
1078 * will fail and the process will hang on exit.
1080 ATF_REQUIRE(aio_error(&ioreq[i].iocb) == EINPROGRESS);
1081 ATF_REQUIRE(aio_cancel(s[0], &ioreq[i].iocb) == AIO_CANCELED);
1088 aio_socket_blocking_short_write_test(bool vectored)
1090 struct aiocb iocb, *iocbp;
1091 struct iovec iov[2];
1094 int buffer_size, sb_size;
1098 ATF_REQUIRE_KERNEL_MODULE("aio");
1100 ATF_REQUIRE(socketpair(PF_UNIX, SOCK_STREAM, 0, s) != -1);
1102 len = sizeof(sb_size);
1103 ATF_REQUIRE(getsockopt(s[0], SOL_SOCKET, SO_RCVBUF, &sb_size, &len) !=
1105 ATF_REQUIRE(len == sizeof(sb_size));
1106 buffer_size = sb_size;
1108 ATF_REQUIRE(getsockopt(s[1], SOL_SOCKET, SO_SNDBUF, &sb_size, &len) !=
1110 ATF_REQUIRE(len == sizeof(sb_size));
1111 if (sb_size > buffer_size)
1112 buffer_size = sb_size;
1115 * Use twice the size of the MAX(receive buffer, send buffer)
1116 * to ensure that the write is split up into multiple writes
1121 buffer[0] = malloc(buffer_size);
1122 ATF_REQUIRE(buffer[0] != NULL);
1123 buffer[1] = malloc(buffer_size);
1124 ATF_REQUIRE(buffer[1] != NULL);
1127 aio_fill_buffer(buffer[1], buffer_size, random());
1129 memset(&iocb, 0, sizeof(iocb));
1130 iocb.aio_fildes = s[1];
1132 iov[0].iov_base = buffer[1];
1133 iov[0].iov_len = buffer_size / 2 + 1;
1134 iov[1].iov_base = buffer[1] + buffer_size / 2 + 1;
1135 iov[1].iov_len = buffer_size / 2 - 1;
1137 iocb.aio_iovcnt = 2;
1138 r = aio_writev(&iocb);
1139 ATF_CHECK_EQ_MSG(0, r, "aio_writev returned %zd", r);
1141 iocb.aio_buf = buffer[1];
1142 iocb.aio_nbytes = buffer_size;
1143 r = aio_write(&iocb);
1144 ATF_CHECK_EQ_MSG(0, r, "aio_writev returned %zd", r);
1147 done = recv(s[0], buffer[0], buffer_size, MSG_WAITALL);
1148 ATF_REQUIRE(done == buffer_size);
1150 done = aio_waitcomplete(&iocbp, NULL);
1151 ATF_REQUIRE(iocbp == &iocb);
1152 ATF_REQUIRE(done == buffer_size);
1154 ATF_REQUIRE(memcmp(buffer[0], buffer[1], buffer_size) == 0);
1161 * This test ensures that aio_write() on a blocking socket of a "large"
1162 * buffer does not return a short completion.
1164 ATF_TC_WITHOUT_HEAD(aio_socket_blocking_short_write);
1165 ATF_TC_BODY(aio_socket_blocking_short_write, tc)
1167 aio_socket_blocking_short_write_test(false);
1171 * Like aio_socket_blocking_short_write, but also tests that partially
1172 * completed vectored sends can be retried correctly.
1174 ATF_TC_WITHOUT_HEAD(aio_socket_blocking_short_write_vectored);
1175 ATF_TC_BODY(aio_socket_blocking_short_write_vectored, tc)
1177 aio_socket_blocking_short_write_test(true);
1181 * This test verifies that cancelling a partially completed socket write
1182 * returns a short write rather than ECANCELED.
1184 ATF_TC_WITHOUT_HEAD(aio_socket_short_write_cancel);
1185 ATF_TC_BODY(aio_socket_short_write_cancel, tc)
1187 struct aiocb iocb, *iocbp;
1190 int buffer_size, sb_size;
1194 ATF_REQUIRE_KERNEL_MODULE("aio");
1196 ATF_REQUIRE(socketpair(PF_UNIX, SOCK_STREAM, 0, s) != -1);
1198 len = sizeof(sb_size);
1199 ATF_REQUIRE(getsockopt(s[0], SOL_SOCKET, SO_RCVBUF, &sb_size, &len) !=
1201 ATF_REQUIRE(len == sizeof(sb_size));
1202 buffer_size = sb_size;
1204 ATF_REQUIRE(getsockopt(s[1], SOL_SOCKET, SO_SNDBUF, &sb_size, &len) !=
1206 ATF_REQUIRE(len == sizeof(sb_size));
1207 if (sb_size > buffer_size)
1208 buffer_size = sb_size;
1211 * Use three times the size of the MAX(receive buffer, send
1212 * buffer) for the write to ensure that the write is split up
1213 * into multiple writes internally. The recv() ensures that
1214 * the write has partially completed, but a remaining size of
1215 * two buffers should ensure that the write has not completed
1216 * fully when it is cancelled.
1218 buffer[0] = malloc(buffer_size);
1219 ATF_REQUIRE(buffer[0] != NULL);
1220 buffer[1] = malloc(buffer_size * 3);
1221 ATF_REQUIRE(buffer[1] != NULL);
1224 aio_fill_buffer(buffer[1], buffer_size * 3, random());
1226 memset(&iocb, 0, sizeof(iocb));
1227 iocb.aio_fildes = s[1];
1228 iocb.aio_buf = buffer[1];
1229 iocb.aio_nbytes = buffer_size * 3;
1230 ATF_REQUIRE(aio_write(&iocb) == 0);
1232 done = recv(s[0], buffer[0], buffer_size, MSG_WAITALL);
1233 ATF_REQUIRE(done == buffer_size);
1235 ATF_REQUIRE(aio_error(&iocb) == EINPROGRESS);
1236 ATF_REQUIRE(aio_cancel(s[1], &iocb) == AIO_NOTCANCELED);
1238 done = aio_waitcomplete(&iocbp, NULL);
1239 ATF_REQUIRE(iocbp == &iocb);
1240 ATF_REQUIRE(done >= buffer_size && done <= buffer_size * 2);
1242 ATF_REQUIRE(memcmp(buffer[0], buffer[1], buffer_size) == 0);
1249 * test aio_fsync's behavior with bad inputs
1251 ATF_TC_WITHOUT_HEAD(aio_fsync_errors);
1252 ATF_TC_BODY(aio_fsync_errors, tc)
1257 ATF_REQUIRE_KERNEL_MODULE("aio");
1258 ATF_REQUIRE_UNSAFE_AIO();
1260 fd = open(FILE_PATHNAME, O_RDWR | O_CREAT, 0600);
1261 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
1262 unlink(FILE_PATHNAME);
1264 /* aio_fsync should return EINVAL unless op is O_SYNC or O_DSYNC */
1265 memset(&iocb, 0, sizeof(iocb));
1266 iocb.aio_fildes = fd;
1267 ATF_CHECK_EQ(-1, aio_fsync(666, &iocb));
1268 ATF_CHECK_EQ(EINVAL, errno);
1270 /* aio_fsync should return EBADF if fd is not a valid descriptor */
1271 memset(&iocb, 0, sizeof(iocb));
1272 iocb.aio_fildes = 666;
1273 ATF_CHECK_EQ(-1, aio_fsync(O_SYNC, &iocb));
1274 ATF_CHECK_EQ(EBADF, errno);
1276 /* aio_fsync should return EINVAL if sigev_notify is invalid */
1277 memset(&iocb, 0, sizeof(iocb));
1278 iocb.aio_fildes = fd;
1279 iocb.aio_sigevent.sigev_notify = 666;
1280 ATF_CHECK_EQ(-1, aio_fsync(666, &iocb));
1281 ATF_CHECK_EQ(EINVAL, errno);
1285 * This test just performs a basic test of aio_fsync().
1288 aio_fsync_test(int op)
1290 struct aiocb synccb, *iocbp;
1301 ATF_REQUIRE_KERNEL_MODULE("aio");
1302 ATF_REQUIRE_UNSAFE_AIO();
1304 fd = open(FILE_PATHNAME, O_RDWR | O_CREAT, 0600);
1305 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
1306 unlink(FILE_PATHNAME);
1308 ATF_REQUIRE(fstat(fd, &sb) == 0);
1309 ATF_REQUIRE(sb.st_blksize != 0);
1310 ATF_REQUIRE(ftruncate(fd, sb.st_blksize * nitems(buffers)) == 0);
1313 * Queue several asynchronous write requests. Hopefully this
1314 * forces the aio_fsync() request to be deferred. There is no
1315 * reliable way to guarantee that however.
1318 for (i = 0; i < nitems(buffers); i++) {
1319 buffers[i].done = false;
1320 memset(&buffers[i].iocb, 0, sizeof(buffers[i].iocb));
1321 buffers[i].buffer = malloc(sb.st_blksize);
1322 aio_fill_buffer(buffers[i].buffer, sb.st_blksize, random());
1323 buffers[i].iocb.aio_fildes = fd;
1324 buffers[i].iocb.aio_buf = buffers[i].buffer;
1325 buffers[i].iocb.aio_nbytes = sb.st_blksize;
1326 buffers[i].iocb.aio_offset = sb.st_blksize * i;
1327 ATF_REQUIRE(aio_write(&buffers[i].iocb) == 0);
1330 /* Queue the aio_fsync request. */
1331 memset(&synccb, 0, sizeof(synccb));
1332 synccb.aio_fildes = fd;
1333 ATF_REQUIRE(aio_fsync(op, &synccb) == 0);
1335 /* Wait for requests to complete. */
1338 rval = aio_waitcomplete(&iocbp, NULL);
1339 ATF_REQUIRE(iocbp != NULL);
1340 if (iocbp == &synccb) {
1341 ATF_REQUIRE(rval == 0);
1345 for (i = 0; i < nitems(buffers); i++) {
1346 if (iocbp == &buffers[i].iocb) {
1347 ATF_REQUIRE(buffers[i].done == false);
1348 ATF_REQUIRE(rval == sb.st_blksize);
1349 buffers[i].done = true;
1354 ATF_REQUIRE_MSG(false, "unmatched AIO request");
1357 for (i = 0; i < nitems(buffers); i++)
1358 ATF_REQUIRE_MSG(buffers[i].done,
1359 "AIO request %u did not complete", i);
1364 ATF_TC_WITHOUT_HEAD(aio_fsync_sync_test);
1365 ATF_TC_BODY(aio_fsync_sync_test, tc)
1367 aio_fsync_test(O_SYNC);
1370 ATF_TC_WITHOUT_HEAD(aio_fsync_dsync_test);
1371 ATF_TC_BODY(aio_fsync_dsync_test, tc)
1373 aio_fsync_test(O_DSYNC);
1377 * We shouldn't be able to DoS the system by setting iov_len to an insane
1380 ATF_TC_WITHOUT_HEAD(aio_writev_dos_iov_len);
1381 ATF_TC_BODY(aio_writev_dos_iov_len, tc)
1384 const struct aiocb *const iocbs[] = {&aio};
1385 const char *wbuf = "Hello, world!";
1386 struct iovec iov[1];
1390 ATF_REQUIRE_KERNEL_MODULE("aio");
1391 ATF_REQUIRE_UNSAFE_AIO();
1393 fd = open("testfile", O_RDWR | O_CREAT, 0600);
1394 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
1397 iov[0].iov_base = __DECONST(void*, wbuf);
1398 iov[0].iov_len = 1 << 30;
1399 bzero(&aio, sizeof(aio));
1400 aio.aio_fildes = fd;
1405 r = aio_writev(&aio);
1406 ATF_CHECK_EQ_MSG(0, r, "aio_writev returned %zd", r);
1407 ATF_REQUIRE_EQ(0, aio_suspend(iocbs, 1, NULL));
1408 r = aio_return(&aio);
1409 ATF_CHECK_EQ_MSG(-1, r, "aio_return returned %zd", r);
1410 ATF_CHECK_MSG(errno == EFAULT || errno == EINVAL,
1411 "aio_writev: %s", strerror(errno));
1417 * We shouldn't be able to DoS the system by setting aio_iovcnt to an insane
1420 ATF_TC_WITHOUT_HEAD(aio_writev_dos_iovcnt);
1421 ATF_TC_BODY(aio_writev_dos_iovcnt, tc)
1424 const char *wbuf = "Hello, world!";
1425 struct iovec iov[1];
1429 ATF_REQUIRE_KERNEL_MODULE("aio");
1430 ATF_REQUIRE_UNSAFE_AIO();
1432 fd = open("testfile", O_RDWR | O_CREAT, 0600);
1433 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
1436 iov[0].iov_base = __DECONST(void*, wbuf);
1437 iov[0].iov_len = len;
1438 bzero(&aio, sizeof(aio));
1439 aio.aio_fildes = fd;
1442 aio.aio_iovcnt = 1 << 30;
1444 ATF_REQUIRE_EQ(-1, aio_writev(&aio));
1445 ATF_CHECK_EQ(EINVAL, errno);
1450 ATF_TC_WITH_CLEANUP(aio_writev_efault);
1451 ATF_TC_HEAD(aio_writev_efault, tc)
1453 atf_tc_set_md_var(tc, "descr",
1454 "Vectored AIO should gracefully handle invalid addresses");
1455 atf_tc_set_md_var(tc, "require.user", "root");
1457 ATF_TC_BODY(aio_writev_efault, tc)
1462 struct iovec iov[2];
1466 ATF_REQUIRE_KERNEL_MODULE("aio");
1467 ATF_REQUIRE_UNSAFE_AIO();
1469 fd = aio_md_setup();
1473 buffer = malloc(buflen);
1474 aio_fill_buffer(buffer, buflen, seed);
1475 iov[0].iov_base = buffer;
1476 iov[0].iov_len = buflen;
1477 iov[1].iov_base = (void*)-1; /* Invalid! */
1478 iov[1].iov_len = buflen;
1479 bzero(&aio, sizeof(aio));
1480 aio.aio_fildes = fd;
1483 aio.aio_iovcnt = nitems(iov);
1485 ATF_REQUIRE_EQ(-1, aio_writev(&aio));
1486 ATF_CHECK_EQ(EFAULT, errno);
1490 ATF_TC_CLEANUP(aio_writev_efault, tc)
1495 ATF_TC_WITHOUT_HEAD(aio_writev_empty_file_poll);
1496 ATF_TC_BODY(aio_writev_empty_file_poll, tc)
1501 ATF_REQUIRE_KERNEL_MODULE("aio");
1502 ATF_REQUIRE_UNSAFE_AIO();
1504 fd = open("testfile", O_RDWR | O_CREAT, 0600);
1505 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
1507 bzero(&aio, sizeof(aio));
1508 aio.aio_fildes = fd;
1512 ATF_REQUIRE_EQ(0, aio_writev(&aio));
1513 ATF_REQUIRE_EQ(0, suspend(&aio));
1518 ATF_TC_WITHOUT_HEAD(aio_writev_empty_file_signal);
1519 ATF_TC_BODY(aio_writev_empty_file_signal, tc)
1524 ATF_REQUIRE_KERNEL_MODULE("aio");
1525 ATF_REQUIRE_UNSAFE_AIO();
1527 fd = open("testfile", O_RDWR | O_CREAT, 0600);
1528 ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
1530 bzero(&aio, sizeof(aio));
1531 aio.aio_fildes = fd;
1534 aio.aio_sigevent = *setup_signal();
1536 ATF_REQUIRE_EQ(0, aio_writev(&aio));
1537 ATF_REQUIRE_EQ(0, poll_signaled(&aio));
1542 // aio_writev and aio_readv should still work even if the iovcnt is greater
1543 // than the number of buffered AIO operations permitted per process.
1544 ATF_TC_WITH_CLEANUP(vectored_big_iovcnt);
1545 ATF_TC_HEAD(vectored_big_iovcnt, tc)
1547 atf_tc_set_md_var(tc, "descr",
1548 "Vectored AIO should still work even if the iovcnt is greater than "
1549 "the number of buffered AIO operations permitted by the process");
1550 atf_tc_set_md_var(tc, "require.user", "root");
1552 ATF_TC_BODY(vectored_big_iovcnt, tc)
1556 ssize_t len, buflen;
1558 const char *oid = "vfs.aio.max_buf_aio";
1562 ssize_t sysctl_len = sizeof(max_buf_aio);
1564 ATF_REQUIRE_KERNEL_MODULE("aio");
1565 ATF_REQUIRE_UNSAFE_AIO();
1567 if (sysctlbyname(oid, &max_buf_aio, &sysctl_len, NULL, 0) == -1)
1568 atf_libc_error(errno, "Failed to read %s", oid);
1571 buflen = 512 * (max_buf_aio + 1);
1572 buffer = malloc(buflen);
1573 aio_fill_buffer(buffer, buflen, seed);
1574 iov = calloc(max_buf_aio + 1, sizeof(struct iovec));
1576 fd = aio_md_setup();
1578 bzero(&aio, sizeof(aio));
1579 aio.aio_fildes = fd;
1581 for (i = 0; i < max_buf_aio + 1; i++) {
1582 iov[i].iov_base = &buffer[i * 512];
1583 iov[i].iov_len = 512;
1586 aio.aio_iovcnt = max_buf_aio + 1;
1588 if (aio_writev(&aio) < 0)
1589 atf_tc_fail("aio_writev failed: %s", strerror(errno));
1593 atf_tc_fail("aio failed: %s", strerror(errno));
1596 atf_tc_fail("aio short write (%jd)", (intmax_t)len);
1598 bzero(&aio, sizeof(aio));
1599 aio.aio_fildes = fd;
1602 aio.aio_iovcnt = max_buf_aio + 1;
1604 if (aio_readv(&aio) < 0)
1605 atf_tc_fail("aio_readv failed: %s", strerror(errno));
1609 atf_tc_fail("aio failed: %s", strerror(errno));
1612 atf_tc_fail("aio short read (%jd)", (intmax_t)len);
1614 if (aio_test_buffer(buffer, buflen, seed) == 0)
1615 atf_tc_fail("buffer mismatched");
1619 ATF_TC_CLEANUP(vectored_big_iovcnt, tc)
1624 ATF_TC_WITHOUT_HEAD(vectored_file_poll);
1625 ATF_TC_BODY(vectored_file_poll, tc)
1627 aio_file_test(poll, NULL, true);
1630 ATF_TC_WITH_CLEANUP(vectored_md_poll);
1631 ATF_TC_HEAD(vectored_md_poll, tc)
1633 atf_tc_set_md_var(tc, "require.user", "root");
1635 ATF_TC_BODY(vectored_md_poll, tc)
1637 aio_md_test(poll, NULL, true);
1639 ATF_TC_CLEANUP(vectored_md_poll, tc)
1644 ATF_TC_WITHOUT_HEAD(vectored_socket_poll);
1645 ATF_TC_BODY(vectored_socket_poll, tc)
1647 aio_unix_socketpair_test(poll, NULL, true);
1650 // aio_writev and aio_readv should still work even if the iov contains elements
1651 // that aren't a multiple of the device's sector size, and even if the total
1652 // amount if I/O _is_ a multiple of the device's sector size.
1653 ATF_TC_WITH_CLEANUP(vectored_unaligned);
1654 ATF_TC_HEAD(vectored_unaligned, tc)
1656 atf_tc_set_md_var(tc, "descr",
1657 "Vectored AIO should still work even if the iov contains elements "
1658 "that aren't a multiple of the sector size.");
1659 atf_tc_set_md_var(tc, "require.user", "root");
1661 ATF_TC_BODY(vectored_unaligned, tc)
1663 struct aio_context ac;
1665 struct iovec iov[3];
1666 ssize_t len, total_len;
1669 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
1670 atf_tc_skip("https://bugs.freebsd.org/258766");
1672 ATF_REQUIRE_KERNEL_MODULE("aio");
1673 ATF_REQUIRE_UNSAFE_AIO();
1676 * Use a zvol with volmode=dev, so it will allow .d_write with
1677 * unaligned uio. geom devices use physio, which doesn't allow that.
1679 fd = aio_zvol_setup();
1680 aio_context_init(&ac, fd, fd, FILE_LEN);
1682 /* Break the buffer into 3 parts:
1683 * * A 4kB part, aligned to 4kB
1684 * * Two other parts that add up to 4kB:
1688 iov[0].iov_base = ac.ac_buffer;
1689 iov[0].iov_len = 4096;
1690 iov[1].iov_base = (void*)((uintptr_t)iov[0].iov_base + iov[0].iov_len);
1691 iov[1].iov_len = 256;
1692 iov[2].iov_base = (void*)((uintptr_t)iov[1].iov_base + iov[1].iov_len);
1693 iov[2].iov_len = 4096 - iov[1].iov_len;
1694 total_len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
1695 bzero(&aio, sizeof(aio));
1696 aio.aio_fildes = ac.ac_write_fd;
1701 if (aio_writev(&aio) < 0)
1702 atf_tc_fail("aio_writev failed: %s", strerror(errno));
1706 atf_tc_fail("aio failed: %s", strerror(errno));
1708 if (len != total_len)
1709 atf_tc_fail("aio short write (%jd)", (intmax_t)len);
1711 bzero(&aio, sizeof(aio));
1712 aio.aio_fildes = ac.ac_read_fd;
1717 if (aio_readv(&aio) < 0)
1718 atf_tc_fail("aio_readv failed: %s", strerror(errno));
1721 ATF_REQUIRE_MSG(aio_test_buffer(ac.ac_buffer, total_len,
1722 ac.ac_seed) != 0, "aio_test_buffer: internal error");
1726 ATF_TC_CLEANUP(vectored_unaligned, tc)
1732 aio_zvol_test(completion comp, struct sigevent *sev, bool vectored)
1734 struct aio_context ac;
1737 fd = aio_zvol_setup();
1738 aio_context_init(&ac, fd, fd, MD_LEN);
1740 aio_writev_test(&ac, comp, sev);
1741 aio_readv_test(&ac, comp, sev);
1743 aio_write_test(&ac, comp, sev);
1744 aio_read_test(&ac, comp, sev);
1751 * Note that unlike md, the zvol is not a geom device, does not allow unmapped
1752 * buffers, and does not use physio.
1754 ATF_TC_WITH_CLEANUP(vectored_zvol_poll);
1755 ATF_TC_HEAD(vectored_zvol_poll, tc)
1757 atf_tc_set_md_var(tc, "require.user", "root");
1759 ATF_TC_BODY(vectored_zvol_poll, tc)
1761 if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
1762 atf_tc_skip("https://bugs.freebsd.org/258766");
1763 aio_zvol_test(poll, NULL, true);
1765 ATF_TC_CLEANUP(vectored_zvol_poll, tc)
1773 ATF_TP_ADD_TC(tp, file_poll);
1774 ATF_TP_ADD_TC(tp, file_signal);
1775 ATF_TP_ADD_TC(tp, file_suspend);
1776 ATF_TP_ADD_TC(tp, file_thread);
1777 ATF_TP_ADD_TC(tp, file_waitcomplete);
1778 ATF_TP_ADD_TC(tp, fifo_poll);
1779 ATF_TP_ADD_TC(tp, fifo_signal);
1780 ATF_TP_ADD_TC(tp, fifo_suspend);
1781 ATF_TP_ADD_TC(tp, fifo_thread);
1782 ATF_TP_ADD_TC(tp, fifo_waitcomplete);
1783 ATF_TP_ADD_TC(tp, socket_poll);
1784 ATF_TP_ADD_TC(tp, socket_signal);
1785 ATF_TP_ADD_TC(tp, socket_suspend);
1786 ATF_TP_ADD_TC(tp, socket_thread);
1787 ATF_TP_ADD_TC(tp, socket_waitcomplete);
1788 ATF_TP_ADD_TC(tp, pty_poll);
1789 ATF_TP_ADD_TC(tp, pty_signal);
1790 ATF_TP_ADD_TC(tp, pty_suspend);
1791 ATF_TP_ADD_TC(tp, pty_thread);
1792 ATF_TP_ADD_TC(tp, pty_waitcomplete);
1793 ATF_TP_ADD_TC(tp, pipe_poll);
1794 ATF_TP_ADD_TC(tp, pipe_signal);
1795 ATF_TP_ADD_TC(tp, pipe_suspend);
1796 ATF_TP_ADD_TC(tp, pipe_thread);
1797 ATF_TP_ADD_TC(tp, pipe_waitcomplete);
1798 ATF_TP_ADD_TC(tp, md_poll);
1799 ATF_TP_ADD_TC(tp, md_signal);
1800 ATF_TP_ADD_TC(tp, md_suspend);
1801 ATF_TP_ADD_TC(tp, md_thread);
1802 ATF_TP_ADD_TC(tp, md_waitcomplete);
1803 ATF_TP_ADD_TC(tp, aio_fsync_errors);
1804 ATF_TP_ADD_TC(tp, aio_fsync_sync_test);
1805 ATF_TP_ADD_TC(tp, aio_fsync_dsync_test);
1806 ATF_TP_ADD_TC(tp, aio_large_read_test);
1807 ATF_TP_ADD_TC(tp, aio_socket_two_reads);
1808 ATF_TP_ADD_TC(tp, aio_socket_blocking_short_write);
1809 ATF_TP_ADD_TC(tp, aio_socket_blocking_short_write_vectored);
1810 ATF_TP_ADD_TC(tp, aio_socket_short_write_cancel);
1811 ATF_TP_ADD_TC(tp, aio_writev_dos_iov_len);
1812 ATF_TP_ADD_TC(tp, aio_writev_dos_iovcnt);
1813 ATF_TP_ADD_TC(tp, aio_writev_efault);
1814 ATF_TP_ADD_TC(tp, aio_writev_empty_file_poll);
1815 ATF_TP_ADD_TC(tp, aio_writev_empty_file_signal);
1816 ATF_TP_ADD_TC(tp, vectored_big_iovcnt);
1817 ATF_TP_ADD_TC(tp, vectored_file_poll);
1818 ATF_TP_ADD_TC(tp, vectored_md_poll);
1819 ATF_TP_ADD_TC(tp, vectored_zvol_poll);
1820 ATF_TP_ADD_TC(tp, vectored_unaligned);
1821 ATF_TP_ADD_TC(tp, vectored_socket_poll);
1823 return (atf_no_error());