From owner-freebsd-current Mon Dec 1 11:32:49 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id LAA06160 for current-outgoing; Mon, 1 Dec 1997 11:32:49 -0800 (PST) (envelope-from owner-freebsd-current) Received: from dyson.iquest.net (dyson.iquest.net [198.70.144.127]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id LAA06082 for ; Mon, 1 Dec 1997 11:32:05 -0800 (PST) (envelope-from toor@dyson.iquest.net) Received: (from root@localhost) by dyson.iquest.net (8.8.7/8.8.8) id OAA00376 for current@freebsd.org; Mon, 1 Dec 1997 14:26:34 -0500 (EST) (envelope-from toor) From: "John S. Dyson" Message-Id: <199712011926.OAA00376@dyson.iquest.net> Subject: FYI: usage of new AIO calls To: current@freebsd.org Date: Mon, 1 Dec 1997 14:26:34 -0500 (EST) X-Mailer: ELM [version 2.4ME+ PL31 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk For fun (and actually as a result of a comment by Justin Gibbs), I have put together a small program that could maybe be used for streaming tape drives using the new AIO code. Note that if you try this, it must be used only on current kernels on/after 19:00 GMT, Dec 1. This code is NOT pretty, but does show example usage. The code will likely have problems on SMP kernels (unless you are writing to a VCHR device.) -- John dyson@freebsd.org jdyson@nc.com #include #include #include #include #include #include #include #include #define NBUFS 16 #define BUFSZ (1024*64) struct aiocb *olist[NBUFS]; void *bufaddrs[NBUFS]; int activeflags[NBUFS]; int nactive; int eof; int main( int argc, char *argv[]) { int i; int fd1, fd2; off_t curptr; int nread; int rtval; int errval; if (argc != 2) { fprintf(stderr, "usage: fcp destfile"); exit(0); } fd1 = 0; fd2 = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666); if (fd2 == -1) { perror(argv[1]); exit(1); } for(i=0;i 0)) { if ((eof && (nactive > 0)) || (nactive == NBUFS)) { for (i = 0; i < NBUFS; i++ ) { if (activeflags[i]) { errval = aio_suspend(&olist[i], 1, NULL); if (errval) { perror("aio_suspend"); exit(1); } break; } } } if (nactive > 0) { for (i = 0; i < NBUFS; i++) { if (activeflags[i] == 0) continue; errval = aio_error(olist[i]); if (errval) { if (errval == EINPROGRESS) continue; perror("aio_error1"); exit(1); } activeflags[i] = 0; --nactive; rtval = aio_return(olist[i]); if (rtval != olist[i]->aio_nbytes) { perror("buffer not fully written"); exit(1); } } } for (i = 0; ((eof == 0) && (nactive < NBUFS) && (i < NBUFS)); i++) { if (activeflags[i] == 0) { nread = read( fd1, bufaddrs[i], BUFSZ); if (nread == 0) { eof = 1; break; } if (nread == -1) { perror("read"); exit(1); } olist[i]->aio_offset = curptr; curptr += nread; olist[i]->aio_nbytes = nread; olist[i]->aio_fildes = fd2; olist[i]->aio_buf = bufaddrs[i]; errval = aio_write(olist[i]); activeflags[i] = 1; nactive++; if (errval) { perror("aio_write"); exit(1); } } } } }