From owner-svn-src-stable@FreeBSD.ORG  Fri Feb 26 00:12:48 2010
Return-Path: <owner-svn-src-stable@FreeBSD.ORG>
Delivered-To: svn-src-stable@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id C7703106566B;
	Fri, 26 Feb 2010 00:12:48 +0000 (UTC)
	(envelope-from jkim@FreeBSD.org)
Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c])
	by mx1.freebsd.org (Postfix) with ESMTP id 9B59B8FC08;
	Fri, 26 Feb 2010 00:12:48 +0000 (UTC)
Received: from svn.freebsd.org (localhost [127.0.0.1])
	by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o1Q0CmDh097536;
	Fri, 26 Feb 2010 00:12:48 GMT (envelope-from jkim@svn.freebsd.org)
Received: (from jkim@localhost)
	by svn.freebsd.org (8.14.3/8.14.3/Submit) id o1Q0Cmwb097533;
	Fri, 26 Feb 2010 00:12:48 GMT (envelope-from jkim@svn.freebsd.org)
Message-Id: <201002260012.o1Q0Cmwb097533@svn.freebsd.org>
From: Jung-uk Kim <jkim@FreeBSD.org>
Date: Fri, 26 Feb 2010 00:12:48 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
	svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
X-SVN-Group: stable-7
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Cc: 
Subject: svn commit: r204342 - stable/7/sys/net
X-BeenThere: svn-src-stable@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: SVN commit messages for all the -stable branches of the src tree
	<svn-src-stable.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-stable>, 
	<mailto:svn-src-stable-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-stable>
List-Post: <mailto:svn-src-stable@freebsd.org>
List-Help: <mailto:svn-src-stable-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-stable>,
	<mailto:svn-src-stable-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Feb 2010 00:12:48 -0000

Author: jkim
Date: Fri Feb 26 00:12:48 2010
New Revision: 204342
URL: http://svn.freebsd.org/changeset/base/204342

Log:
  MFC:	r204105
  
  Return partially filled buffer for non-blocking read(2)
  in non-immediate mode.
  
  PR:		kern/143855
  Submitted by:	Guy Harris (guy at alum dot mit dot edu)

Modified:
  stable/7/sys/net/bpf.c
Directory Properties:
  stable/7/sys/   (props changed)
  stable/7/sys/cddl/contrib/opensolaris/   (props changed)
  stable/7/sys/contrib/dev/acpica/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)

Modified: stable/7/sys/net/bpf.c
==============================================================================
--- stable/7/sys/net/bpf.c	Fri Feb 26 00:11:17 2010	(r204341)
+++ stable/7/sys/net/bpf.c	Fri Feb 26 00:12:48 2010	(r204342)
@@ -481,8 +481,9 @@ static	int
 bpfread(struct cdev *dev, struct uio *uio, int ioflag)
 {
 	struct bpf_d *d = dev->si_drv1;
-	int timed_out;
 	int error;
+	int non_block;
+	int timed_out;
 
 	/*
 	 * Restrict application to use a buffer the same size as
@@ -491,6 +492,8 @@ bpfread(struct cdev *dev, struct uio *ui
 	if (uio->uio_resid != d->bd_bufsize)
 		return (EINVAL);
 
+	non_block = ((ioflag & O_NONBLOCK) != 0);
+
 	BPFD_LOCK(d);
 	d->bd_pid = curthread->td_proc->p_pid;
 	if (d->bd_state == BPF_WAITING)
@@ -503,14 +506,20 @@ bpfread(struct cdev *dev, struct uio *ui
 	 * have arrived to fill the store buffer.
 	 */
 	while (d->bd_hbuf == NULL) {
-		if ((d->bd_immediate || timed_out) && d->bd_slen != 0) {
+		if (d->bd_slen != 0) {
 			/*
 			 * A packet(s) either arrived since the previous
 			 * read or arrived while we were asleep.
-			 * Rotate the buffers and return what's here.
 			 */
-			ROTATE_BUFFERS(d);
-			break;
+			if (d->bd_immediate || non_block || timed_out) {
+				/*
+				 * Rotate the buffers and return what's here
+				 * if we are in immediate mode, non-blocking
+				 * flag is set, or this descriptor timed out.
+				 */
+				ROTATE_BUFFERS(d);
+				break;
+			}
 		}
 
 		/*
@@ -524,7 +533,7 @@ bpfread(struct cdev *dev, struct uio *ui
 			return (ENXIO);
 		}
 
-		if (ioflag & O_NONBLOCK) {
+		if (non_block) {
 			BPFD_UNLOCK(d);
 			return (EWOULDBLOCK);
 		}