From owner-p4-projects@FreeBSD.ORG Mon Sep 12 20:08:53 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 864D816A421; Mon, 12 Sep 2005 20:08:52 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4859116A41F for ; Mon, 12 Sep 2005 20:08:52 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 85F2B43D45 for ; Mon, 12 Sep 2005 20:08:51 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j8CK8pBT075454 for ; Mon, 12 Sep 2005 20:08:51 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j8CK8pJs075451 for perforce@freebsd.org; Mon, 12 Sep 2005 20:08:51 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Mon, 12 Sep 2005 20:08:51 GMT Message-Id: <200509122008.j8CK8pJs075451@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 83499 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Sep 2005 20:08:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=83499 Change 83499 by rwatson@rwatson_peppercorn on 2005/09/12 20:08:21 Integrate netsmp branch from FreeBSD CVS: - NMI fixen for amd64. - sound locking fixes. - kqueue fixes to return EINVAL rather than 1 (EPERM). - time_uptime() instead of time_second() - various fifofs fixes looped back - netgraph ng_ksocket event fix for ENOBUFS - more fifofs regression tests Affected files ... .. //depot/projects/netsmp/src/sys/dev/hwpmc/hwpmc_amd.c#4 integrate .. //depot/projects/netsmp/src/sys/dev/sound/isa/mss.c#5 integrate .. //depot/projects/netsmp/src/sys/dev/sound/pcm/dsp.c#5 integrate .. //depot/projects/netsmp/src/sys/dev/sound/pcm/sound.c#4 integrate .. //depot/projects/netsmp/src/sys/fs/fifofs/fifo_vnops.c#8 integrate .. //depot/projects/netsmp/src/sys/i386/i386/vm_machdep.c#2 integrate .. //depot/projects/netsmp/src/sys/kern/vfs_subr.c#9 integrate .. //depot/projects/netsmp/src/sys/net/if.c#15 integrate .. //depot/projects/netsmp/src/sys/netgraph/ng_socket.c#3 integrate .. //depot/projects/netsmp/src/tools/regression/fifo/fifo_io/fifo_io.c#2 integrate .. //depot/projects/netsmp/src/tools/regression/fifo/fifo_misc/Makefile#1 branch .. //depot/projects/netsmp/src/tools/regression/fifo/fifo_misc/fifo_misc.c#1 branch .. //depot/projects/netsmp/src/tools/regression/fifo/fifo_open/fifo_open.c#3 integrate .. //depot/projects/netsmp/src/tools/regression/sockets/shutdown/Makefile#1 branch .. //depot/projects/netsmp/src/tools/regression/sockets/shutdown/shutdown.c#1 branch Differences ... ==== //depot/projects/netsmp/src/sys/dev/hwpmc/hwpmc_amd.c#4 (text+ko) ==== @@ -26,7 +26,7 @@ */ #include -__FBSDID("$FreeBSD: src/sys/dev/hwpmc/hwpmc_amd.c,v 1.11 2005/08/27 16:07:12 jkoshy Exp $"); +__FBSDID("$FreeBSD: src/sys/dev/hwpmc/hwpmc_amd.c,v 1.12 2005/09/12 15:55:44 jkoshy Exp $"); /* Support for the AMD K7 and later processors */ @@ -693,9 +693,14 @@ * and which has a valid 'struct pmc' association * * If found, we call a helper to process the interrupt. + * + * If multiple PMCs interrupt at the same time, the AMD64 + * processor appears to deliver as many NMIs as there are + * outstanding PMC interrupts. Thus we need to only process + * one interrupt at a time. */ - for (i = 0; i < AMD_NPMCS-1; i++) { + for (i = 0; retval == 0 && i < AMD_NPMCS-1; i++) { ri = i + 1; /* row index; TSC is at ri == 0 */ @@ -712,6 +717,8 @@ continue; } + retval = 1; /* found an interrupting PMC */ + /* stop the PMC, reload count */ evsel = AMD_PMC_EVSEL_0 + i; perfctr = AMD_PMC_PERFCTR_0 + i; @@ -726,12 +733,10 @@ wrmsr(evsel, config & ~AMD_PMC_ENABLE); wrmsr(perfctr, AMD_RELOAD_COUNT_TO_PERFCTR_VALUE(v)); - /* restart if there was no error during logging */ + /* restart the counter if there was no error during logging */ error = pmc_process_interrupt(cpu, pm, eip, usermode); if (error == 0) wrmsr(evsel, config | AMD_PMC_ENABLE); - - retval = 1; /* found an interrupting PMC */ } atomic_add_int(retval ? &pmc_stats.pm_intr_processed : ==== //depot/projects/netsmp/src/sys/dev/sound/isa/mss.c#5 (text+ko) ==== @@ -29,7 +29,7 @@ #include -SND_DECLARE_FILE("$FreeBSD: src/sys/dev/sound/isa/mss.c,v 1.101 2005/09/12 04:12:50 imp Exp $"); +SND_DECLARE_FILE("$FreeBSD: src/sys/dev/sound/isa/mss.c,v 1.102 2005/09/12 13:40:10 nyan Exp $"); /* board-specific include files */ #include @@ -113,7 +113,9 @@ /* OPTi-specific functions */ static void opti_write(struct mss_info *mss, u_char reg, u_char data); +#ifndef PC98 static u_char opti_read(struct mss_info *mss, u_char reg); +#endif static int opti_init(device_t dev, struct mss_info *mss); /* io primitives */ @@ -2175,6 +2177,7 @@ } } +#ifndef PC98 u_char opti_read(struct mss_info *mss, u_char reg) { @@ -2198,6 +2201,7 @@ } return -1; } +#endif static device_method_t pnpmss_methods[] = { /* Device interface */ ==== //depot/projects/netsmp/src/sys/dev/sound/pcm/dsp.c#5 (text+ko) ==== @@ -29,7 +29,7 @@ #include -SND_DECLARE_FILE("$FreeBSD: src/sys/dev/sound/pcm/dsp.c,v 1.83 2005/09/10 17:51:38 netchild Exp $"); +SND_DECLARE_FILE("$FreeBSD: src/sys/dev/sound/pcm/dsp.c,v 1.84 2005/09/12 18:33:33 netchild Exp $"); #define OLDPCM_IOCTL @@ -329,7 +329,6 @@ s = spltty(); d = dsp_get_info(i_dev); - pcm_lock(d); rdch = i_dev->si_drv1; wrch = i_dev->si_drv2; @@ -351,6 +350,8 @@ */ if ((rdch || wrch) && refs == 0) { + pcm_lock(d); + if (pcm_getfakechan(d)) pcm_getfakechan(d)->flags = 0; @@ -382,8 +383,7 @@ chn_reset(wrch, 0); pcm_chnrelease(wrch); } - } else - pcm_unlock(d); + } splx(s); return 0; } ==== //depot/projects/netsmp/src/sys/dev/sound/pcm/sound.c#4 (text+ko) ==== @@ -32,7 +32,7 @@ #include "feeder_if.h" -SND_DECLARE_FILE("$FreeBSD: src/sys/dev/sound/pcm/sound.c,v 1.95 2005/09/10 18:10:31 netchild Exp $"); +SND_DECLARE_FILE("$FreeBSD: src/sys/dev/sound/pcm/sound.c,v 1.96 2005/09/12 18:33:33 netchild Exp $"); devclass_t pcm_devclass; @@ -166,8 +166,6 @@ struct snddev_channel *sce; int err; - snd_mtxassert(d->lock); - /* scan for a free channel */ SLIST_FOREACH(sce, &d->channels, link) { c = sce->channel; ==== //depot/projects/netsmp/src/sys/fs/fifofs/fifo_vnops.c#8 (text+ko) ==== @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)fifo_vnops.c 8.10 (Berkeley) 5/27/95 - * $FreeBSD: src/sys/fs/fifofs/fifo_vnops.c,v 1.119 2005/09/12 12:15:12 rwatson Exp $ + * $FreeBSD: src/sys/fs/fifofs/fifo_vnops.c,v 1.120 2005/09/12 18:07:49 rwatson Exp $ */ #include @@ -358,7 +358,7 @@ sb = &so->so_snd; break; default: - return (1); + return (EINVAL); } ap->a_kn->kn_hook = (caddr_t)so; @@ -625,7 +625,7 @@ sb = &so->so_snd; break; default: - return (1); + return (EINVAL); } kn->kn_hook = (caddr_t)so; ==== //depot/projects/netsmp/src/sys/i386/i386/vm_machdep.c#2 (text+ko) ==== @@ -41,13 +41,10 @@ */ #include -__FBSDID("$FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.259 2005/07/10 23:31:10 davidxu Exp $"); +__FBSDID("$FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.260 2005/09/12 13:50:56 nyan Exp $"); #include "opt_isa.h" #include "opt_npx.h" -#ifdef PC98 -#include "opt_pc98.h" -#endif #include "opt_reset.h" #include "opt_cpu.h" ==== //depot/projects/netsmp/src/sys/kern/vfs_subr.c#9 (text+ko) ==== @@ -39,7 +39,7 @@ */ #include -__FBSDID("$FreeBSD: src/sys/kern/vfs_subr.c,v 1.644 2005/09/12 08:46:07 phk Exp $"); +__FBSDID("$FreeBSD: src/sys/kern/vfs_subr.c,v 1.646 2005/09/12 19:22:37 rwatson Exp $"); #include "opt_ddb.h" #include "opt_mac.h" @@ -1585,7 +1585,7 @@ syncer_final_iter = 0; first_printf = 1; syncer_state = SYNCER_RUNNING; - starttime = time_second; + starttime = time_uptime; EVENTHANDLER_REGISTER(shutdown_pre_sync, syncer_shutdown, td->td_proc, SHUTDOWN_PRI_LAST); @@ -1600,14 +1600,14 @@ } net_worklist_len = syncer_worklist_len - sync_vnode_count; if (syncer_state != SYNCER_RUNNING && - starttime != time_second) { + starttime != time_uptime) { if (first_printf) { printf("\nSyncing disks, vnodes remaining..."); first_printf = 0; } printf("%d ", net_worklist_len); } - starttime = time_second; + starttime = time_uptime; /* * Push files whose dirty time has expired. Be careful @@ -1696,7 +1696,7 @@ if (syncer_state != SYNCER_RUNNING) tsleep(&dummychan, PPAUSE, "syncfnl", hz / SYNCER_SHUTDOWN_SPEEDUP); - else if (time_second == starttime) + else if (time_uptime == starttime) tsleep(&lbolt, PPAUSE, "syncer", 0); } } @@ -3763,7 +3763,7 @@ kn->kn_fop = &vfsvnode_filtops; break; default: - return (1); + return (EINVAL); } kn->kn_hook = (caddr_t)vp; ==== //depot/projects/netsmp/src/sys/net/if.c#15 (text+ko) ==== @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)if.c 8.5 (Berkeley) 1/9/95 - * $FreeBSD: src/sys/net/if.c,v 1.245 2005/09/04 17:32:47 sam Exp $ + * $FreeBSD: src/sys/net/if.c,v 1.246 2005/09/12 19:26:03 rwatson Exp $ */ #include "opt_compat.h" @@ -217,7 +217,7 @@ kn->kn_fop = &netdev_filtops; break; default: - return (1); + return (EINVAL); } idx = minor(dev); ==== //depot/projects/netsmp/src/sys/netgraph/ng_socket.c#3 (text+ko) ==== @@ -37,7 +37,7 @@ * * Author: Julian Elischer * - * $FreeBSD: src/sys/netgraph/ng_socket.c,v 1.68 2005/07/23 19:28:51 obrien Exp $ + * $FreeBSD: src/sys/netgraph/ng_socket.c,v 1.69 2005/09/12 14:11:11 glebius Exp $ * $Whistle: ng_socket.c,v 1.28 1999/11/01 09:24:52 julian Exp $ */ @@ -814,6 +814,7 @@ struct socket *const so = pcbp->ng_socket; struct mbuf *mdata; int msglen; + int error = 0; /* Copy the message itself into an mbuf chain */ msglen = sizeof(struct ng_mesg) + msg->header.arglen; @@ -833,10 +834,10 @@ (struct sockaddr *) addr, mdata, NULL) == 0) { TRAP_ERROR; m_freem(mdata); - return (ENOBUFS); + error = so->so_error = ENOBUFS; } sorwakeup(so); - return (0); + return (error); } /*************************************************************** ==== //depot/projects/netsmp/src/tools/regression/fifo/fifo_io/fifo_io.c#2 (text+ko) ==== @@ -23,11 +23,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/tools/regression/fifo/fifo_io/fifo_io.c,v 1.1 2005/09/12 09:42:29 rwatson Exp $ + * $FreeBSD: src/tools/regression/fifo/fifo_io/fifo_io.c,v 1.3 2005/09/12 17:05:48 rwatson Exp $ */ +#include +#include #include #include +#include #include #include @@ -107,6 +110,15 @@ (void)unlink(fifoname); } +static void +cleanfifokq(const char *fifoname, int fd1, int fd2, int fd3) +{ + + if (fd3 != -1) + close(fd3); + cleanfifo(fifoname, fd1, fd2); +} + static int openfifo(const char *fifoname, const char *testname, int *reader_fdp, int *writer_fdp) @@ -864,7 +876,7 @@ FD_SET(fd, &exceptfds); timeout.tv_sec = 0; timeout.tv_usec = 0; - if (select(1, &readfds, &writefds, &exceptfds, &timeout) < 0) { + if (select(fd+1, &readfds, &writefds, &exceptfds, &timeout) < 0) { warn("%s: select", testname); return (-1); } @@ -874,21 +886,105 @@ return (0); } +static int +kqueue_setup(int reader_fd, int writer_fd, int *kqueue_fdp, + const char *testname) +{ + struct kevent kevent_changelist[4], kevent_eventlist[4], *kp; + struct timespec timeout; + int i, kqueue_fd, ret; + + kqueue_fd = kqueue(); + if (kqueue_fd < 0) { + warn("%s: kevent_setup: kqueue", testname); + return (-1); + } + + timeout.tv_sec = 0; + timeout.tv_nsec = 0; + + /* + * Add events corresponding to read and write on both descriptors. + */ + bzero(&kevent_changelist, sizeof(kevent_changelist)); + EV_SET(&kevent_changelist[0], reader_fd, EVFILT_READ, EV_ADD, 0, 0, + 0); + EV_SET(&kevent_changelist[1], reader_fd, EVFILT_WRITE, EV_ADD, 0, 0, + 0); + EV_SET(&kevent_changelist[2], writer_fd, EVFILT_READ, EV_ADD, 0, 0, + 0); + EV_SET(&kevent_changelist[3], writer_fd, EVFILT_WRITE, EV_ADD, 0, 0, + 0); + + bzero(&kevent_eventlist, sizeof(kevent_eventlist)); + ret = kevent(kqueue_fd, kevent_changelist, 4, kevent_eventlist, 4, + &timeout); + if (ret < 0) { + warn("%s: kevent initial register", __func__); + cleanfifo("testfifo", reader_fd, writer_fd); + exit(-1); + } + + /* + * Verified that the events registered alright. + */ + for (i = 0; i < ret; i++) { + kp = &kevent_eventlist[i]; + if (kp->flags != EV_ERROR) + continue; + errno = kp->data; + err(-1, "%s: kevent register index %d", __func__, i); + } + + *kqueue_fdp = kqueue_fd; + + return (0); +} + +static int +kqueue_status(int kqueue_fd, int fd, int *readable, int *writable, + int *exception, const char *testname) +{ + struct kevent kevent_eventlist[4], *kp; + struct timespec timeout; + int i; + + timeout.tv_sec = 0; + timeout.tv_nsec = 0; + + if (kevent(kqueue_fd, NULL, 0, kevent_eventlist, 4, &timeout) < 0) { + warn("%s: kqueue_status: kevent", testname); + return (-1); + } + + *readable = *writable = *exception = 0; + for (i = 0; i < 4; i++) { + kp = &kevent_eventlist[i]; + if (kp->ident != (u_int)fd) + continue; + if (kp->filter == EVFILT_READ) + *readable = 1; + if (kp->filter == EVFILT_WRITE) + *writable = 1; + } + + return (0); +} + /* - * test_events() uses poll() and select() to query the status of fifo file - * descriptors and determine whether they match expected state based on - * earlier semantic tests: specifically, whether or not poll/select will - * correctly inform on readable/writable state following I/O. + * test_events() uses poll(), select(), and kevent() to query the status of + * fifo file descriptors and determine whether they match expected state + * based on earlier semantic tests: specifically, whether or not poll/select/ + * kevent will correctly inform on readable/writable state following I/O. * - * It would be nice to also test kqueue here, as well as the wakeup/sleep - * model of these calls. It would be nice to test status changes as a - * result of closing of one or another fifo endpoint. + * It would be nice to also test status changes as a result of closing of one + * or another fifo endpoint. */ static void test_events_outofbox(void) { int readable, writable, exception; - int reader_fd, writer_fd; + int kqueue_fd, reader_fd, writer_fd; makefifo("testfifo", __func__); if (openfifo("testfifo", __func__, &reader_fd, &writer_fd) @@ -898,6 +994,11 @@ exit(-1); } + if (kqueue_setup(reader_fd, writer_fd, &kqueue_fd, __func__) < 0) { + cleanfifo("testfifo", reader_fd, writer_fd); + exit(-1); + } + /* * Make sure that fresh, out-of-the-box fifo file descriptors have * good initial states. The reader_fd should have no active state, @@ -906,27 +1007,40 @@ */ if (poll_status(reader_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || writable || exception) { warnx("test_events_outofbox: reader_fd polls r:%d, w:%d, " "e:%d on create", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (select_status(reader_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || writable || exception) { warnx("test_events_outofbox: reader_fd selects r:%d, w:%d, " "e:%d on create", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (kqueue_status(kqueue_fd, reader_fd, &readable, &writable, + &exception, __func__) < 0) { + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (readable || writable || exception) { + warnx("test_events_outofbox: reader_fd kevent r:%d, w:%d, " + "e:%d on create", readable, writable, exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -936,38 +1050,51 @@ */ if (poll_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || !writable || exception) { warnx("test_events_outofbox: writer_fd polls r:%d, w:%d, " "e:%d on create", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (select_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || !writable || exception) { warnx("test_events_outofbox: writer_fd selects r:%d, w:%d, " "e:%d on create", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (kqueue_status(kqueue_fd, writer_fd, &readable, &writable, + &exception, __func__) < 0) { + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (readable || !writable || exception) { + warnx("test_events_outofbox: writer_fd kevent r:%d, w:%d, " + "e:%d on create", readable, writable, exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); } static void test_events_write_read_byte(void) { int readable, writable, exception; - int reader_fd, writer_fd; + int kqueue_fd, reader_fd, writer_fd; ssize_t len; u_char ch; @@ -979,6 +1106,11 @@ exit(-1); } + if (kqueue_setup(reader_fd, writer_fd, &kqueue_fd, __func__) < 0) { + cleanfifo("testfifo", reader_fd, writer_fd); + exit(-1); + } + /* * Write a byte to the fifo, and make sure that the read end becomes * readable, and that the write end remains writable (small write). @@ -987,33 +1119,46 @@ len = write(writer_fd, &ch, sizeof(ch)); if (len < 0) { warn("test_events_write_read_byte: write"); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (poll_status(reader_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (!readable || writable || exception) { warnx("test_events_write_read_byte: reader_fd polls r:%d, " "w:%d, e:%d after write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (select_status(reader_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (!readable || writable || exception) { warnx("test_events_write_read_byte: reader_fd selects r:%d, " "w:%d, e:%d after write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (kqueue_status(kqueue_fd, reader_fd, &readable, &writable, + &exception, __func__) < 0) { + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (!readable || writable || exception) { + warnx("test_events_write_read_byte: reader_fd kevent r:%d, " + "w:%d, e:%d after write", readable, writable, exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -1022,27 +1167,40 @@ */ if (poll_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || !writable || exception) { warnx("test_events_write_read_byte: writer_fd polls r:%d, " "w:%d, e:%d after write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (select_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || !writable || exception) { warnx("test_events_write_read_byte: writer_fd selects r:%d, " "w:%d, e:%d after write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (kqueue_status(kqueue_fd, writer_fd, &readable, &writable, + &exception, __func__) < 0) { + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (readable || !writable || exception) { + warnx("test_events_write_read_byte: writer_fd kevent r:%d, " + "w:%d, e:%d after write", readable, writable, exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -1053,33 +1211,49 @@ len = read(reader_fd, &ch, sizeof(ch)); if (len < 0) { warn("test_events_write_read_byte: read"); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (poll_status(reader_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || writable || exception) { warnx("test_events_write_read_byte: reader_fd polls r:%d, " - "w:%d, e:%d after write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + "w:%d, e:%d after write+read", readable, writable, + exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (select_status(reader_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || writable || exception) { warnx("test_events_write_read_byte: reader_fd selects r:%d, " - "w:%d, e:%d after write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + "w:%d, e:%d after write+read", readable, writable, + exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (kqueue_status(kqueue_fd, reader_fd, &readable, &writable, + &exception, __func__) < 0) { + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (readable || writable || exception) { + warnx("test_events_write_read_byte: reader_fd kevent r:%d, " + "w:%d, e:%d after write+read", readable, writable, + exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -1088,37 +1262,59 @@ */ if (poll_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || !writable || exception) { warnx("test_events_write_read_byte: writer_fd polls r:%d, " - "w:%d, e:%d after write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + "w:%d, e:%d after write+read", readable, writable, + exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (select_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (readable || !writable || exception) { warnx("test_events_write_read_byte: writer_fd selects r:%d, " - "w:%d, e:%d after write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + "w:%d, e:%d after write+read", readable, writable, + exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (kqueue_status(kqueue_fd, writer_fd, &readable, &writable, + &exception, __func__) < 0) { + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (readable || !writable || exception) { + warnx("test_events_write_read_byte: writer_fd kevent r:%d, " + "w:%d, e:%d after write+read", readable, writable, + exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } - cleanfifo("testfifo", reader_fd, writer_fd); + + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); } +/* + * Write a 512k buffer to the fifo in non-blocking mode, and make sure that + * the write end becomes un-writable as a result of a partial write that + * fills the fifo buffer. + */ static void test_events_partial_write(void) { int readable, writable, exception; - int reader_fd, writer_fd; + int kqueue_fd, reader_fd, writer_fd; u_char *buffer; ssize_t len; @@ -1130,20 +1326,20 @@ exit(-1); } - /* - * Write a 512k buffer to the fifo in non-blocking mode, and make - * sure that the write end becomes un-writable as a result of a - * partial write that fills the fifo buffer. - */ + if (kqueue_setup(reader_fd, writer_fd, &kqueue_fd, __func__) < 0) { + cleanfifo("testfifo", reader_fd, writer_fd); + exit(-1); + } + if (set_nonblocking(writer_fd, "test_events") < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } buffer = malloc(512*1024); if (buffer == NULL) { warn("test_events_partial_write: malloc"); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } bzero(buffer, 512*1024); @@ -1152,7 +1348,7 @@ if (len < 0) { warn("test_events_partial_write: write"); free(buffer); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -1160,7 +1356,7 @@ if (poll_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -1168,13 +1364,13 @@ warnx("test_events_partial_write: writer_fd polls r:%d, " "w:%d, e:%d after big write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (select_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -1182,12 +1378,26 @@ warnx("test_events_partial_write: writer_fd selects r:%d, " "w:%d, e:%d after big write", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (kqueue_status(kqueue_fd, writer_fd, &readable, &writable, + &exception, __func__) < 0) { + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (readable || writable || exception) { + warnx("test_events_partial_write: writer_fd kevent r:%d, " + "w:%d, e:%d after big write", readable, writable, + exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (drain_fd(reader_fd, "test_events") < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -1197,7 +1407,7 @@ */ if (poll_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -1205,13 +1415,13 @@ warnx("test_events_partial_write: writer_fd polls r:%d, " "w:%d, e:%d after big write + drain", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } if (select_status(writer_fd, &readable, &writable, &exception, __func__) < 0) { - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } @@ -1219,16 +1429,32 @@ warnx("test_events_partial_write: writer_fd selects r:%d, " "w:%d, e:%d after big write + drain", readable, writable, exception); - cleanfifo("testfifo", reader_fd, writer_fd); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (kqueue_status(kqueue_fd, writer_fd, &readable, &writable, + &exception, __func__) < 0) { + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); + exit(-1); + } + + if (readable || !writable || exception) { + warnx("test_events_partial_write: writer_fd kevent r:%d, " + "w:%d, e:%d after big write + drain", readable, writable, + exception); + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); exit(-1); } - cleanfifo("testfifo", reader_fd, writer_fd); + + cleanfifokq("testfifo", reader_fd, writer_fd, kqueue_fd); } + int main(int argc, char *argv[]) { - strcpy(temp_dir, "/tmp/fifo_create.XXXXXXXXXXX"); + strcpy(temp_dir, "/tmp/fifo_io.XXXXXXXXXXX"); if (mkdtemp(temp_dir) == NULL) err(-1, "mkdtemp"); atexit(atexit_temp_dir); ==== //depot/projects/netsmp/src/tools/regression/fifo/fifo_open/fifo_open.c#3 (text+ko) ==== >>> TRUNCATED FOR MAIL (1000 lines) <<<