From owner-p4-projects@FreeBSD.ORG Tue Jun 16 12:14:49 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 65F2C106566B; Tue, 16 Jun 2009 12:14:49 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0BF771065673 for ; Tue, 16 Jun 2009 12:14:49 +0000 (UTC) (envelope-from zhaoshuai@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id EDB798FC0C for ; Tue, 16 Jun 2009 12:14:48 +0000 (UTC) (envelope-from zhaoshuai@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n5GCEmO9042771 for ; Tue, 16 Jun 2009 12:14:48 GMT (envelope-from zhaoshuai@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5GCEmQE042769 for perforce@freebsd.org; Tue, 16 Jun 2009 12:14:48 GMT (envelope-from zhaoshuai@FreeBSD.org) Date: Tue, 16 Jun 2009 12:14:48 GMT Message-Id: <200906161214.n5GCEmQE042769@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zhaoshuai@FreeBSD.org using -f From: Zhao Shuai To: Perforce Change Reviews Cc: Subject: PERFORCE change 164492 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: Tue, 16 Jun 2009 12:14:50 -0000 http://perforce.freebsd.org/chv.cgi?CH=164492 Change 164492 by zhaoshuai@zhaoshuai on 2009/06/16 12:14:45 fix fifo_kqfilter_f() Affected files ... .. //depot/projects/soc2009/fifo/sys/fs/fifofs/fifo_vnops.c#15 edit .. //depot/projects/soc2009/fifo/sys/kern/subr_pipe.c#6 edit Differences ... ==== //depot/projects/soc2009/fifo/sys/fs/fifofs/fifo_vnops.c#15 (text+ko) ==== @@ -91,9 +91,16 @@ static vop_pathconf_t fifo_pathconf; static vop_advlock_t fifo_advlock; +static void filt_fifodetach(struct knote *kn); +static int filt_fiforead(struct knote *kn, long hint); +static int filt_fifowrite(struct knote *kn, long hint); static void filt_fifodetach_notsup(struct knote *kn); static int filt_fifo_notsup(struct knote *kn, long hint); +static struct filterops fiforead_filtops = + { 1, NULL, filt_fifodetach, filt_fiforead }; +static struct filterops fifowrite_filtops = + { 1, NULL, filt_fifodetach, filt_fifowrite }; static struct filterops fifo_notsup_filtops = { 1, NULL, filt_fifodetach_notsup, filt_fifo_notsup }; @@ -503,6 +510,7 @@ fifo_kqfilter_f(struct file *fp, struct knote *kn) { struct fifoinfo *fip = fp->f_data; + struct pipe *rpipe = fip->fi_rpipe; /* * If a filter is requested that is not supported by this file @@ -520,18 +528,86 @@ switch (kn->kn_filter) { case EVFILT_READ: - return (generic_pipe_kqfilter(fip->fi_rpipe, kn)); - + kn->kn_fop = &fiforead_filtops; + break; case EVFILT_WRITE: - return (generic_pipe_kqfilter(fip->fi_wpipe, kn)); - + kn->kn_fop = &fifowrite_filtops; + PIPE_LOCK(rpipe); + if (rpipe->pipe_present != PIPE_ACTIVE) { + /* other end of pipe has been closed */ + PIPE_UNLOCK(rpipe); + return (EPIPE); + } + PIPE_UNLOCK(rpipe); + break; default: return (EINVAL); } + kn->kn_hook = (void *)rpipe; + + PIPE_LOCK(rpipe); + knlist_add(&rpipe->pipe_sel.si_note, kn, 1); + PIPE_UNLOCK(rpipe); + return (0); } +static void +filt_fifodetach(struct knote *kn) +{ + struct pipe *pipe = (struct pipe *)kn->kn_hook; + + PIPE_LOCK(pipe); + knlist_remove(&pipe->pipe_sel.si_note, kn, 1); + PIPE_UNLOCK(pipe); +} + +static int +filt_fiforead(struct knote *kn, long hint) +{ + struct pipe *rpipe = (struct pipe *)kn->kn_hook; + struct pipe *wpipe = rpipe->pipe_peer; + int ret; + + PIPE_LOCK(rpipe); + kn->kn_data = rpipe->pipe_buffer.cnt; + if ((kn->kn_data == 0) && (rpipe->pipe_state & PIPE_DIRECTW)) + kn->kn_data = rpipe->pipe_map.cnt; + + if ((rpipe->pipe_state & PIPE_EOF) || + wpipe->pipe_present != PIPE_ACTIVE || + (wpipe->pipe_state & PIPE_EOF)) { + kn->kn_flags |= EV_EOF; + PIPE_UNLOCK(rpipe); + return (1); + } + ret = kn->kn_data > 0; + PIPE_UNLOCK(rpipe); + return ret; +} + +static int +filt_fifowrite(struct knote *kn, long hint) +{ + struct pipe *wpipe = (struct pipe *)kn->kn_hook; + + PIPE_LOCK(wpipe); + if (wpipe->pipe_present != PIPE_ACTIVE || + (wpipe->pipe_state & PIPE_EOF)) { + kn->kn_data = 0; + kn->kn_flags |= EV_EOF; + PIPE_UNLOCK(wpipe); + return (1); + } + kn->kn_data = wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt; + if (wpipe->pipe_state & PIPE_DIRECTW) + kn->kn_data = 0; + + PIPE_UNLOCK(wpipe); + return (kn->kn_data >= PIPE_BUF); +} + static void filt_fifodetach_notsup(struct knote *kn) { ==== //depot/projects/soc2009/fifo/sys/kern/subr_pipe.c#6 (text+ko) ==== @@ -1378,7 +1378,7 @@ cpipe->pipe_present = PIPE_FINALIZED; knlist_destroy(&cpipe->pipe_sel.si_note); - /* XXX: is it OK to put is here? */ + /* XXX: is it OK to put it here? */ funsetown(&cpipe->pipe_sigio); /*