[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Fri Mar 2 15:38:56 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/fc6cfb0dbf30
changeset: 378:fc6cfb0dbf30
user:      ray at terran.dlink.ua
date:      Fri Mar 02 17:07:09 2012 +0200
description:
Update to FreeBSD-HEAD @232391

diffstat:

 head/sys/kern/imgact_gzip.c   |   32 +--
 head/sys/kern/kern_conf.c     |   17 +-
 head/sys/kern/kern_ctf.c      |    4 +-
 head/sys/kern/kern_exit.c     |  124 ++++++++++----
 head/sys/kern/kern_fork.c     |   17 +-
 head/sys/kern/kern_gzio.c     |    6 +-
 head/sys/kern/kern_jail.c     |   94 ++++++++++-
 head/sys/kern/kern_kthread.c  |    9 +-
 head/sys/kern/kern_ktrace.c   |    4 +-
 head/sys/kern/kern_linker.c   |    7 +-
 head/sys/kern/kern_malloc.c   |    4 +-
 head/sys/kern/kern_proc.c     |   50 +++++-
 head/sys/kern/kern_tc.c       |    3 +-
 head/sys/kern/kern_umtx.c     |  363 +++++++++++++++++++++++++----------------
 head/sys/kern/link_elf.c      |    5 +-
 head/sys/kern/link_elf_obj.c  |    5 +-
 head/sys/kern/sched_ule.c     |  330 +++++++++++++++++++++-----------------
 head/sys/kern/subr_bus.c      |   12 +-
 head/sys/kern/subr_log.c      |   50 +++++-
 head/sys/kern/subr_mchain.c   |   86 ++++----
 head/sys/kern/subr_msgbuf.c   |   55 +++++-
 head/sys/kern/subr_syscall.c  |   29 +++-
 head/sys/kern/subr_uio.c      |   10 +-
 head/sys/kern/sys_generic.c   |   24 ++-
 head/sys/kern/sys_pipe.c      |  246 +++++++++++++++++++++------
 head/sys/kern/sys_process.c   |    7 +-
 head/sys/kern/sysv_shm.c      |   20 +-
 head/sys/kern/tty.c           |    6 +-
 head/sys/kern/tty_info.c      |    6 +-
 head/sys/kern/tty_ttydisc.c   |    9 +-
 head/sys/kern/uipc_domain.c   |    4 +-
 head/sys/kern/uipc_mbuf.c     |    5 +-
 head/sys/kern/uipc_socket.c   |   41 ++-
 head/sys/kern/uipc_syscalls.c |   31 +-
 head/sys/kern/uipc_usrreq.c   |   49 ++++-
 head/sys/kern/vfs_aio.c       |    3 +-
 head/sys/kern/vfs_bio.c       |   40 +--
 head/sys/kern/vfs_cache.c     |   20 +-
 head/sys/kern/vfs_cluster.c   |    4 +-
 head/sys/kern/vfs_default.c   |   29 +++-
 head/sys/kern/vfs_extattr.c   |    8 +-
 head/sys/kern/vfs_mount.c     |   10 +-
 head/sys/kern/vfs_mountroot.c |    7 +-
 head/sys/kern/vfs_subr.c      |   17 +-
 head/sys/kern/vfs_syscalls.c  |   22 +-
 head/sys/kern/vfs_vnops.c     |    6 +-
 head/sys/kern/vnode_if.src    |   22 ++-
 47 files changed, 1286 insertions(+), 666 deletions(-)

diffs (4616 lines):

diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/imgact_gzip.c
--- a/head/sys/kern/imgact_gzip.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/imgact_gzip.c	Fri Mar 02 17:07:09 2012 +0200
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/imgact_gzip.c 220373 2011-04-05 20:23:59Z trasz $");
+__FBSDID("$FreeBSD: head/sys/kern/imgact_gzip.c 231885 2012-02-17 23:47:16Z kib $");
 
 #include <sys/param.h>
 #include <sys/exec.h>
@@ -70,7 +70,7 @@
 exec_gzip_imgact(imgp)
 	struct image_params *imgp;
 {
-	int             error, error2 = 0;
+	int             error;
 	const u_char   *p = (const u_char *) imgp->image_header;
 	struct imgact_gzip igz;
 	struct inflate  infl;
@@ -136,22 +136,17 @@
 			VM_PROT_READ|VM_PROT_EXECUTE,0);
 	}
 
-	if (igz.inbuf) {
-		error2 =
-			vm_map_remove(kernel_map, (vm_offset_t) igz.inbuf,
-			    (vm_offset_t) igz.inbuf + PAGE_SIZE);
-	}
-	if (igz.error || error || error2) {
+	if (igz.inbuf)
+		kmem_free_wakeup(exec_map, (vm_offset_t)igz.inbuf, PAGE_SIZE);
+	if (igz.error || error) {
 		printf("Output=%lu ", igz.output);
-		printf("Inflate_error=%d igz.error=%d error2=%d where=%d\n",
-		       error, igz.error, error2, igz.where);
+		printf("Inflate_error=%d igz.error=%d where=%d\n",
+		       error, igz.error, igz.where);
 	}
 	if (igz.error)
 		return igz.error;
 	if (error)
 		return ENOEXEC;
-	if (error2)
-		return error2;
 	return 0;
 }
 
@@ -314,18 +309,11 @@
 	if (igz->inbuf && igz->idx < (igz->offset + PAGE_SIZE)) {
 		return igz->inbuf[(igz->idx++) - igz->offset];
 	}
-	if (igz->inbuf) {
-		error = vm_map_remove(kernel_map, (vm_offset_t) igz->inbuf,
-			    (vm_offset_t) igz->inbuf + PAGE_SIZE);
-		if (error) {
-			igz->where = __LINE__;
-			igz->error = error;
-			return GZ_EOF;
-		}
-	}
+	if (igz->inbuf)
+		kmem_free_wakeup(exec_map, (vm_offset_t)igz->inbuf, PAGE_SIZE);
 	igz->offset = igz->idx & ~PAGE_MASK;
 
-	error = vm_mmap(kernel_map,	/* map */
+	error = vm_mmap(exec_map,	/* map */
 			(vm_offset_t *) & igz->inbuf,	/* address */
 			PAGE_SIZE,	/* size */
 			VM_PROT_READ,	/* protection */
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_conf.c
--- a/head/sys/kern/kern_conf.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_conf.c	Fri Mar 02 17:07:09 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_conf.c 228804 2011-12-22 16:01:10Z jhb $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_conf.c 231386 2012-02-10 14:55:47Z ed $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -690,16 +690,15 @@
 
 	mtx_assert(&devmtx, MA_OWNED);
 
-	len = vsnrprintf(dev->__si_namebuf, sizeof(dev->__si_namebuf), 32,
-	    fmt, ap);
-	if (len > sizeof(dev->__si_namebuf) - 1)
+	len = vsnrprintf(dev->si_name, sizeof(dev->si_name), 32, fmt, ap);
+	if (len > sizeof(dev->si_name) - 1)
 		return (ENAMETOOLONG);
 
 	/* Strip leading slashes. */
-	for (from = dev->__si_namebuf; *from == '/'; from++)
+	for (from = dev->si_name; *from == '/'; from++)
 		;
 
-	for (to = dev->__si_namebuf; *from != '\0'; from++, to++) {
+	for (to = dev->si_name; *from != '\0'; from++, to++) {
 		/* Treat multiple sequential slashes as single. */
 		while (from[0] == '/' && from[1] == '/')
 			from++;
@@ -710,11 +709,11 @@
 	}
 	*to = '\0';
 
-	if (dev->__si_namebuf[0] == '\0')
+	if (dev->si_name[0] == '\0')
 		return (EINVAL);
 
 	/* Disallow "." and ".." components. */
-	for (s = dev->__si_namebuf;;) {
+	for (s = dev->si_name;;) {
 		for (q = s; *q != '/' && *q != '\0'; q++)
 			;
 		if (q - s == 1 && s[0] == '.')
@@ -726,7 +725,7 @@
 		s = q + 1;
 	}
 
-	if (devfs_dev_exists(dev->__si_namebuf) != 0)
+	if (devfs_dev_exists(dev->si_name) != 0)
 		return (EEXIST);
 
 	return (0);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_ctf.c
--- a/head/sys/kern/kern_ctf.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_ctf.c	Fri Mar 02 17:07:09 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/sys/kern/kern_ctf.c 227342 2011-11-08 15:17:54Z rstone $
+ * $FreeBSD: head/sys/kern/kern_ctf.c 231949 2012-02-21 01:05:12Z kib $
  */
 
 /*
@@ -68,7 +68,7 @@
 	int flags;
 	int i;
 	int nbytes;
-	int resid;
+	ssize_t resid;
 	int vfslocked;
 	size_t sz;
 	struct nameidata nd;
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_exit.c
--- a/head/sys/kern/kern_exit.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_exit.c	Fri Mar 02 17:07:09 2012 +0200
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_exit.c 225641 2011-09-17 19:55:32Z trasz $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_exit.c 232104 2012-02-24 11:02:35Z kib $");
 
 #include "opt_compat.h"
 #include "opt_kdtrace.h"
@@ -720,7 +720,6 @@
 	if (p->p_oppid && (t = pfind(p->p_oppid)) != NULL) {
 		PROC_LOCK(p);
 		proc_reparent(p, t);
-		p->p_pptr->p_dbg_child--;
 		p->p_oppid = 0;
 		PROC_UNLOCK(p);
 		pksignal(t, SIGCHLD, p->p_ksi);
@@ -739,6 +738,10 @@
 	LIST_REMOVE(p, p_list);	/* off zombproc */
 	sx_xunlock(&allproc_lock);
 	LIST_REMOVE(p, p_sibling);
+	if (p->p_flag & P_ORPHAN) {
+		LIST_REMOVE(p, p_orphan);
+		p->p_flag &= ~P_ORPHAN;
+	}
 	leavepgrp(p);
 #ifdef PROCDESC
 	if (p->p_procdesc != NULL)
@@ -803,12 +806,53 @@
 	sx_xunlock(&allproc_lock);
 }
 
+static int
+proc_to_reap(struct thread *td, struct proc *p, pid_t pid, int *status,
+    int options, struct rusage *rusage)
+{
+	struct proc *q;
+
+	q = td->td_proc;
+	PROC_LOCK(p);
+	if (pid != WAIT_ANY && p->p_pid != pid && p->p_pgid != -pid) {
+		PROC_UNLOCK(p);
+		return (0);
+	}
+	if (p_canwait(td, p)) {
+		PROC_UNLOCK(p);
+		return (0);
+	}
+
+	/*
+	 * This special case handles a kthread spawned by linux_clone
+	 * (see linux_misc.c).  The linux_wait4 and linux_waitpid
+	 * functions need to be able to distinguish between waiting
+	 * on a process and waiting on a thread.  It is a thread if
+	 * p_sigparent is not SIGCHLD, and the WLINUXCLONE option
+	 * signifies we want to wait for threads and not processes.
+	 */
+	if ((p->p_sigparent != SIGCHLD) ^
+	    ((options & WLINUXCLONE) != 0)) {
+		PROC_UNLOCK(p);
+		return (0);
+	}
+
+	PROC_SLOCK(p);
+	if (p->p_state == PRS_ZOMBIE) {
+		proc_reap(td, p, status, options, rusage);
+		return (-1);
+	}
+	PROC_SUNLOCK(p);
+	PROC_UNLOCK(p);
+	return (1);
+}
+
 int
 kern_wait(struct thread *td, pid_t pid, int *status, int options,
     struct rusage *rusage)
 {
 	struct proc *p, *q;
-	int error, nfound;
+	int error, nfound, ret;
 
 	AUDIT_ARG_PID(pid);
 	AUDIT_ARG_VALUE(options);
@@ -831,37 +875,16 @@
 	nfound = 0;
 	sx_xlock(&proctree_lock);
 	LIST_FOREACH(p, &q->p_children, p_sibling) {
+		ret = proc_to_reap(td, p, pid, status, options, rusage);
+		if (ret == 0)
+			continue;
+		else if (ret == 1)
+			nfound++;
+		else
+			return (0);
+
 		PROC_LOCK(p);
-		if (pid != WAIT_ANY &&
-		    p->p_pid != pid && p->p_pgid != -pid) {
-			PROC_UNLOCK(p);
-			continue;
-		}
-		if (p_canwait(td, p)) {
-			PROC_UNLOCK(p);
-			continue;
-		}
-
-		/*
-		 * This special case handles a kthread spawned by linux_clone
-		 * (see linux_misc.c).  The linux_wait4 and linux_waitpid
-		 * functions need to be able to distinguish between waiting
-		 * on a process and waiting on a thread.  It is a thread if
-		 * p_sigparent is not SIGCHLD, and the WLINUXCLONE option
-		 * signifies we want to wait for threads and not processes.
-		 */
-		if ((p->p_sigparent != SIGCHLD) ^
-		    ((options & WLINUXCLONE) != 0)) {
-			PROC_UNLOCK(p);
-			continue;
-		}
-
-		nfound++;
 		PROC_SLOCK(p);
-		if (p->p_state == PRS_ZOMBIE) {
-			proc_reap(td, p, status, options, rusage);
-			return (0);
-		}
 		if ((p->p_flag & P_STOPPED_SIG) &&
 		    (p->p_suspcount == p->p_numthreads) &&
 		    (p->p_flag & P_WAITED) == 0 &&
@@ -897,12 +920,31 @@
 		}
 		PROC_UNLOCK(p);
 	}
+
+	/*
+	 * Look in the orphans list too, to allow the parent to
+	 * collect it's child exit status even if child is being
+	 * debugged.
+	 *
+	 * Debugger detaches from the parent upon successful
+	 * switch-over from parent to child.  At this point due to
+	 * re-parenting the parent loses the child to debugger and a
+	 * wait4(2) call would report that it has no children to wait
+	 * for.  By maintaining a list of orphans we allow the parent
+	 * to successfully wait until the child becomes a zombie.
+	 */
+	LIST_FOREACH(p, &q->p_orphans, p_orphan) {
+		ret = proc_to_reap(td, p, pid, status, options, rusage);
+		if (ret == 0)
+			continue;
+		else if (ret == 1)
+			nfound++;
+		else
+			return (0);
+	}
 	if (nfound == 0) {
 		sx_xunlock(&proctree_lock);
-		if (td->td_proc->p_dbg_child)
-			return (0);
-		else
-			return (ECHILD);
+		return (ECHILD);
 	}
 	if (options & WNOHANG) {
 		sx_xunlock(&proctree_lock);
@@ -940,5 +982,15 @@
 	PROC_UNLOCK(child->p_pptr);
 	LIST_REMOVE(child, p_sibling);
 	LIST_INSERT_HEAD(&parent->p_children, child, p_sibling);
+
+	if (child->p_flag & P_ORPHAN) {
+		LIST_REMOVE(child, p_orphan);
+		child->p_flag &= ~P_ORPHAN;
+	}
+	if (child->p_flag & P_TRACED) {
+		LIST_INSERT_HEAD(&child->p_pptr->p_orphans, child, p_orphan);
+		child->p_flag |= P_ORPHAN;
+	}
+
 	child->p_pptr = parent;
 }
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_fork.c
--- a/head/sys/kern/kern_fork.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_fork.c	Fri Mar 02 17:07:09 2012 +0200
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_fork.c 225944 2011-10-03 17:40:55Z trasz $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_fork.c 232240 2012-02-27 21:10:10Z kib $");
 
 #include "opt_kdtrace.h"
 #include "opt_ktrace.h"
@@ -590,6 +590,7 @@
 	LIST_INSERT_AFTER(p1, p2, p_pglist);
 	PGRP_UNLOCK(p1->p_pgrp);
 	LIST_INIT(&p2->p_children);
+	LIST_INIT(&p2->p_orphans);
 
 	callout_init(&p2->p_itcallout, CALLOUT_MPSAFE);
 
@@ -707,6 +708,10 @@
 		_PHOLD(p2);
 		p2_held = 1;
 	}
+	if (flags & RFPPWAIT) {
+		td->td_pflags |= TDP_RFPPWAIT;
+		td->td_rfppwait_p = p2;
+	}
 	PROC_UNLOCK(p2);
 	if ((flags & RFSTOPPED) == 0) {
 		/*
@@ -739,14 +744,6 @@
 		cv_wait(&p2->p_dbgwait, &p2->p_mtx);
 	if (p2_held)
 		_PRELE(p2);
-
-	/*
-	 * Preserve synchronization semantics of vfork.  If waiting for
-	 * child to exec or exit, set P_PPWAIT on child, and sleep on our
-	 * proc (in case of exit).
-	 */
-	while (p2->p_flag & P_PPWAIT)
-		cv_wait(&p2->p_pwait, &p2->p_mtx);
 	PROC_UNLOCK(p2);
 }
 
@@ -1035,7 +1032,9 @@
 			p->p_oppid = p->p_pptr->p_pid;
 			proc_reparent(p, dbg);
 			sx_xunlock(&proctree_lock);
+			td->td_dbgflags |= TDB_CHILD;
 			ptracestop(td, SIGSTOP);
+			td->td_dbgflags &= ~TDB_CHILD;
 		} else {
 			/*
 			 * ... otherwise clear the request.
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_gzio.c
--- a/head/sys/kern/kern_gzio.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_gzio.c	Fri Mar 02 17:07:09 2012 +0200
@@ -12,7 +12,7 @@
  *
  */
 
-/* @(#) $FreeBSD$ */
+/* @(#) $FreeBSD: head/sys/kern/kern_gzio.c 231949 2012-02-21 01:05:12Z kib $ */
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -97,7 +97,7 @@
     gz_stream *s;
     char fmode[80]; /* copy of mode, without the compression level */
     char *m = fmode;
-    int resid;
+    ssize_t resid;
     int error;
     char buf[GZ_HEADER_LEN + 1];
 
@@ -342,7 +342,7 @@
 {
     uint32_t xx;
     off_t curoff = s->outoff;
-    int resid;
+    ssize_t resid;
 
 #if BYTE_ORDER == BIG_ENDIAN
     xx = bswap32(x);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_jail.c
--- a/head/sys/kern/kern_jail.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_jail.c	Fri Mar 02 17:07:09 2012 +0200
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_jail.c 230407 2012-01-21 00:06:21Z mm $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_jail.c 232278 2012-02-29 00:30:18Z mm $");
 
 #include "opt_compat.h"
 #include "opt_ddb.h"
@@ -103,6 +103,7 @@
 	.pr_uref	= 1,
 	.pr_path	= "/",
 	.pr_securelevel	= -1,
+	.pr_devfs_rsnum = 0,
 	.pr_childmax	= JAIL_MAX,
 	.pr_hostuuid	= DEFAULT_HOSTUUID,
 	.pr_children	= LIST_HEAD_INITIALIZER(prison0.pr_children),
@@ -200,6 +201,10 @@
 	"allow.mount",
 	"allow.quotas",
 	"allow.socket_af",
+	"allow.mount.devfs",
+	"allow.mount.nullfs",
+	"allow.mount.zfs",
+	"allow.mount.procfs",
 };
 const size_t pr_allow_names_size = sizeof(pr_allow_names);
 
@@ -211,13 +216,19 @@
 	"allow.nomount",
 	"allow.noquotas",
 	"allow.nosocket_af",
+	"allow.mount.nodevfs",
+	"allow.mount.nonullfs",
+	"allow.mount.nozfs",
+	"allow.mount.noprocfs",
 };
 const size_t pr_allow_nonames_size = sizeof(pr_allow_nonames);
 
 #define	JAIL_DEFAULT_ALLOW		PR_ALLOW_SET_HOSTNAME
 #define	JAIL_DEFAULT_ENFORCE_STATFS	2
+#define	JAIL_DEFAULT_DEVFS_RSNUM	0
 static unsigned jail_default_allow = JAIL_DEFAULT_ALLOW;
 static int jail_default_enforce_statfs = JAIL_DEFAULT_ENFORCE_STATFS;
+static int jail_default_devfs_rsnum = JAIL_DEFAULT_DEVFS_RSNUM;
 #if defined(INET) || defined(INET6)
 static unsigned jail_max_af_ips = 255;
 #endif
@@ -529,9 +540,9 @@
 	unsigned long hid;
 	size_t namelen, onamelen;
 	int created, cuflags, descend, enforce, error, errmsg_len, errmsg_pos;
-	int gotchildmax, gotenforce, gothid, gotslevel;
+	int gotchildmax, gotenforce, gothid, gotrsnum, gotslevel;
 	int fi, jid, jsys, len, level;
-	int childmax, slevel, vfslocked;
+	int childmax, rsnum, slevel, vfslocked;
 	int fullpath_disabled;
 #if defined(INET) || defined(INET6)
 	int ii, ij;
@@ -612,6 +623,14 @@
 	} else
 		gotenforce = 1;
 
+	error = vfs_copyopt(opts, "devfs_ruleset", &rsnum, sizeof(rsnum));
+	if (error == ENOENT)
+		gotrsnum = 0;
+	else if (error != 0)
+		goto done_free;
+	else
+		gotrsnum = 1;
+
 	pr_flags = ch_flags = 0;
 	for (fi = 0; fi < sizeof(pr_flag_names) / sizeof(pr_flag_names[0]);
 	    fi++) {
@@ -1268,6 +1287,7 @@
 		pr->pr_securelevel = ppr->pr_securelevel;
 		pr->pr_allow = JAIL_DEFAULT_ALLOW & ppr->pr_allow;
 		pr->pr_enforce_statfs = JAIL_DEFAULT_ENFORCE_STATFS;
+		pr->pr_devfs_rsnum = ppr->pr_devfs_rsnum;
 
 		LIST_INIT(&pr->pr_children);
 		mtx_init(&pr->pr_mtx, "jail mutex", NULL, MTX_DEF | MTX_DUPOK);
@@ -1346,6 +1366,25 @@
 			goto done_deref_locked;
 		}
 	}
+	if (gotrsnum) {
+		/*
+		 * devfs_rsnum is a uint16_t
+		 */
+		if (rsnum < 0 || rsnum > 65535) {
+			error = EINVAL;
+			goto done_deref_locked;
+		}
+		/*
+		 * Nested jails always inherit parent's devfs ruleset
+		 */
+		if (jailed(td->td_ucred)) {
+			if (rsnum > 0 && rsnum != ppr->pr_devfs_rsnum) {
+				error = EPERM;
+				goto done_deref_locked;
+			} else
+				rsnum = ppr->pr_devfs_rsnum;
+		}
+	}
 #ifdef INET
 	if (ip4s > 0) {
 		if (ppr->pr_flags & PR_IP4) {
@@ -1586,6 +1625,12 @@
 			if (tpr->pr_enforce_statfs < enforce)
 				tpr->pr_enforce_statfs = enforce;
 	}
+	if (gotrsnum) {
+		pr->pr_devfs_rsnum = rsnum;
+		/* Pass this restriction on to the children. */
+		FOREACH_PRISON_DESCENDANT_LOCKED(pr, tpr, descend)
+			tpr->pr_devfs_rsnum = rsnum;
+	}
 	if (name != NULL) {
 		if (ppr == &prison0)
 			strlcpy(pr->pr_name, name, sizeof(pr->pr_name));
@@ -2020,6 +2065,10 @@
 	    sizeof(pr->pr_enforce_statfs));
 	if (error != 0 && error != ENOENT)
 		goto done_deref;
+	error = vfs_setopt(opts, "devfs_ruleset", &pr->pr_devfs_rsnum,
+	    sizeof(pr->pr_devfs_rsnum));
+	if (error != 0 && error != ENOENT)
+		goto done_deref;
 	for (fi = 0; fi < sizeof(pr_flag_names) / sizeof(pr_flag_names[0]);
 	    fi++) {
 		if (pr_flag_names[fi] == NULL)
@@ -4151,6 +4200,22 @@
     CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
     NULL, PR_ALLOW_MOUNT, sysctl_jail_default_allow, "I",
     "Processes in jail can mount/unmount jail-friendly file systems");
+SYSCTL_PROC(_security_jail, OID_AUTO, mount_devfs_allowed,
+    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+    NULL, PR_ALLOW_MOUNT_DEVFS, sysctl_jail_default_allow, "I",
+    "Processes in jail can mount the devfs file system");
+SYSCTL_PROC(_security_jail, OID_AUTO, mount_nullfs_allowed,
+    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+    NULL, PR_ALLOW_MOUNT_NULLFS, sysctl_jail_default_allow, "I",
+    "Processes in jail can mount the nullfs file system");
+SYSCTL_PROC(_security_jail, OID_AUTO, mount_procfs_allowed,
+    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+    NULL, PR_ALLOW_MOUNT_PROCFS, sysctl_jail_default_allow, "I",
+    "Processes in jail can mount the procfs file system");
+SYSCTL_PROC(_security_jail, OID_AUTO, mount_zfs_allowed,
+    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+    NULL, PR_ALLOW_MOUNT_ZFS, sysctl_jail_default_allow, "I",
+    "Processes in jail can mount the zfs file system");
 
 static int
 sysctl_jail_default_level(SYSCTL_HANDLER_ARGS)
@@ -4173,6 +4238,12 @@
     sysctl_jail_default_level, "I",
     "Processes in jail cannot see all mounted file systems");
 
+SYSCTL_PROC(_security_jail, OID_AUTO, devfs_ruleset,
+    CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
+    &jail_default_devfs_rsnum, offsetof(struct prison, pr_devfs_rsnum),
+    sysctl_jail_default_level, "I",
+    "Ruleset for the devfs filesystem in jail");
+
 /*
  * Nodes to describe jail parameters.  Maximum length of string parameters
  * is returned in the string itself, and the other parameters exist merely
@@ -4221,6 +4292,8 @@
     "I", "Jail secure level");
 SYSCTL_JAIL_PARAM(, enforce_statfs, CTLTYPE_INT | CTLFLAG_RW,
     "I", "Jail cannot see all mounted file systems");
+SYSCTL_JAIL_PARAM(, devfs_ruleset, CTLTYPE_INT | CTLFLAG_RW,
+    "I", "Ruleset for in-jail devfs mounts");
 SYSCTL_JAIL_PARAM(, persist, CTLTYPE_INT | CTLFLAG_RW,
     "B", "Jail persistence");
 #ifdef VIMAGE
@@ -4277,13 +4350,23 @@
     "B", "Jail may create raw sockets");
 SYSCTL_JAIL_PARAM(_allow, chflags, CTLTYPE_INT | CTLFLAG_RW,
     "B", "Jail may alter system file flags");
-SYSCTL_JAIL_PARAM(_allow, mount, CTLTYPE_INT | CTLFLAG_RW,
-    "B", "Jail may mount/unmount jail-friendly file systems");
 SYSCTL_JAIL_PARAM(_allow, quotas, CTLTYPE_INT | CTLFLAG_RW,
     "B", "Jail may set file quotas");
 SYSCTL_JAIL_PARAM(_allow, socket_af, CTLTYPE_INT | CTLFLAG_RW,
     "B", "Jail may create sockets other than just UNIX/IPv4/IPv6/route");
 
+SYSCTL_JAIL_PARAM_SUBNODE(allow, mount, "Jail mount/unmount permission flags");
+SYSCTL_JAIL_PARAM(_allow_mount, , CTLTYPE_INT | CTLFLAG_RW,
+    "B", "Jail may mount/unmount jail-friendly file systems in general");
+SYSCTL_JAIL_PARAM(_allow_mount, devfs, CTLTYPE_INT | CTLFLAG_RW,
+    "B", "Jail may mount the devfs file system");
+SYSCTL_JAIL_PARAM(_allow_mount, nullfs, CTLTYPE_INT | CTLFLAG_RW,
+    "B", "Jail may mount the nullfs file system");
+SYSCTL_JAIL_PARAM(_allow_mount, procfs, CTLTYPE_INT | CTLFLAG_RW,
+    "B", "Jail may mount the procfs file system");
+SYSCTL_JAIL_PARAM(_allow_mount, zfs, CTLTYPE_INT | CTLFLAG_RW,
+    "B", "Jail may mount the zfs file system");
+
 void
 prison_racct_foreach(void (*callback)(struct racct *racct,
     void *arg2, void *arg3), void *arg2, void *arg3)
@@ -4413,6 +4496,7 @@
 #endif
 	db_printf(" root            = %p\n", pr->pr_root);
 	db_printf(" securelevel     = %d\n", pr->pr_securelevel);
+	db_printf(" devfs_rsnum     = %d\n", pr->pr_devfs_rsnum);
 	db_printf(" children.max    = %d\n", pr->pr_childmax);
 	db_printf(" children.cur    = %d\n", pr->pr_childcount);
 	db_printf(" child           = %p\n", LIST_FIRST(&pr->pr_children));
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_kthread.c
--- a/head/sys/kern/kern_kthread.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_kthread.c	Fri Mar 02 17:07:09 2012 +0200
@@ -25,10 +25,11 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_kthread.c 224987 2011-08-18 22:51:30Z jonathan $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_kthread.c 230984 2012-02-04 16:49:29Z rstone $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/cpuset.h>
 #include <sys/kthread.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
@@ -117,6 +118,9 @@
 
 	/* call the processes' main()... */
 	cpu_set_fork_handler(td, func, arg);
+
+	/* Avoid inheriting affinity from a random parent. */
+	cpuset_setthread(td->td_tid, cpuset_root);
 	thread_lock(td);
 	TD_SET_CAN_RUN(td);
 	sched_prio(td, PVM);
@@ -299,6 +303,9 @@
 
 	tidhash_add(newtd);
 
+	/* Avoid inheriting affinity from a random parent. */
+	cpuset_setthread(newtd->td_tid, cpuset_root);
+
 	/* Delay putting it on the run queue until now. */
 	if (!(flags & RFSTOPPED)) {
 		thread_lock(newtd);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_ktrace.c
--- a/head/sys/kern/kern_ktrace.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_ktrace.c	Fri Mar 02 17:07:09 2012 +0200
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_ktrace.c 228343 2011-12-08 03:20:38Z eadler $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_ktrace.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include "opt_ktrace.h"
 
@@ -684,7 +684,7 @@
 	}
 	uio->uio_offset = 0;
 	uio->uio_rw = UIO_WRITE;
-	datalen = imin(uio->uio_resid, ktr_geniosize);
+	datalen = MIN(uio->uio_resid, ktr_geniosize);
 	buf = malloc(datalen, M_KTRACE, M_WAITOK);
 	error = uiomove(buf, datalen, uio);
 	free(uio, M_IOV);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_linker.c
--- a/head/sys/kern/kern_linker.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_linker.c	Fri Mar 02 17:07:09 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_linker.c 229272 2012-01-02 12:12:10Z ed $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_linker.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include "opt_ddb.h"
 #include "opt_kld.h"
@@ -1748,7 +1748,8 @@
 	struct vattr vattr, mattr;
 	u_char *hints = NULL;
 	u_char *cp, *recptr, *bufend, *result, *best, *pathbuf, *sep;
-	int error, ival, bestver, *intp, reclen, found, flags, clen, blen;
+	int error, ival, bestver, *intp, found, flags, clen, blen;
+	ssize_t reclen;
 	int vfslocked = 0;
 
 	result = NULL;
@@ -1793,7 +1794,7 @@
 	VFS_UNLOCK_GIANT(vfslocked);
 	nd.ni_vp = NULL;
 	if (reclen != 0) {
-		printf("can't read %d\n", reclen);
+		printf("can't read %zd\n", reclen);
 		goto bad;
 	}
 	intp = (int *)hints;
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_malloc.c
--- a/head/sys/kern/kern_malloc.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_malloc.c	Fri Mar 02 17:07:09 2012 +0200
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_malloc.c 228324 2011-12-07 16:27:23Z alc $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_malloc.c 232356 2012-03-01 19:58:34Z jhb $");
 
 #include "opt_ddb.h"
 #include "opt_kdtrace.h"
@@ -418,7 +418,7 @@
 void *
 contigmalloc(unsigned long size, struct malloc_type *type, int flags,
     vm_paddr_t low, vm_paddr_t high, unsigned long alignment,
-    unsigned long boundary)
+    vm_paddr_t boundary)
 {
 	void *ret;
 
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_proc.c
--- a/head/sys/kern/kern_proc.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_proc.c	Fri Mar 02 17:07:09 2012 +0200
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_proc.c 230550 2012-01-25 20:15:58Z trociny $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_proc.c 232181 2012-02-26 14:25:48Z trociny $");
 
 #include "opt_compat.h"
 #include "opt_ddb.h"
@@ -60,6 +60,7 @@
 #include <sys/sched.h>
 #include <sys/smp.h>
 #include <sys/stack.h>
+#include <sys/stat.h>
 #include <sys/sysctl.h>
 #include <sys/filedesc.h>
 #include <sys/tty.h>
@@ -2471,6 +2472,49 @@
 	return (error);
 }
 
+/*
+ * This sysctl allows a process to retrieve or/and set umask of
+ * another process.
+ */
+static int
+sysctl_kern_proc_umask(SYSCTL_HANDLER_ARGS)
+{
+	int *name = (int *)arg1;
+	u_int namelen = arg2;
+	struct proc *p;
+	int error;
+	u_short fd_cmask;
+
+	if (namelen != 1)
+		return (EINVAL);
+
+	if (req->newptr != NULL && req->newlen != sizeof(fd_cmask))
+		return (EINVAL);
+
+	error = pget((pid_t)name[0], PGET_WANTREAD, &p);
+	if (error != 0)
+		return (error);
+
+	FILEDESC_SLOCK(p->p_fd);
+	fd_cmask = p->p_fd->fd_cmask;
+	FILEDESC_SUNLOCK(p->p_fd);
+	error = SYSCTL_OUT(req, &fd_cmask, sizeof(fd_cmask));
+	if (error != 0)
+		goto errout;
+
+	if (req->newptr != NULL) {
+		error = SYSCTL_IN(req, &fd_cmask, sizeof(fd_cmask));
+		if (error == 0) {
+			FILEDESC_XLOCK(p->p_fd);
+			p->p_fd->fd_cmask = fd_cmask & ALLPERMS;
+			FILEDESC_XUNLOCK(p->p_fd);
+		}
+	}
+errout:
+	PRELE(p);
+	return (error);
+}
+
 SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD,  0, "Process table");
 
 SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all, CTLFLAG_RD|CTLTYPE_STRUCT|
@@ -2572,3 +2616,7 @@
 static SYSCTL_NODE(_kern_proc, KERN_PROC_PS_STRINGS, ps_strings, CTLFLAG_RD |
 	CTLFLAG_MPSAFE, sysctl_kern_proc_ps_strings,
 	"Process ps_strings location");
+
+static SYSCTL_NODE(_kern_proc, KERN_PROC_UMASK, umask, CTLFLAG_RW |
+	CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, sysctl_kern_proc_umask,
+	"Process umask");
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_tc.c
--- a/head/sys/kern/kern_tc.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_tc.c	Fri Mar 02 17:07:09 2012 +0200
@@ -14,7 +14,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_tc.c 228856 2011-12-24 01:32:01Z lstewart $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_tc.c 231341 2012-02-10 06:30:52Z kevlo $");
 
 #include "opt_ntp.h"
 #include "opt_ffclock.h"
@@ -1085,6 +1085,7 @@
 		/* Boot time adjustment, for uptime/monotonic clocks. */
 		if (flags & FFCLOCK_UPTIME)
 			bintime_sub(bt, &ffclock_boottime);
+		break;
 #endif
 	default:
 		return (EINVAL);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/kern_umtx.c
--- a/head/sys/kern/kern_umtx.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/kern_umtx.c	Fri Mar 02 17:07:09 2012 +0200
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_umtx.c 230194 2012-01-16 04:39:10Z davidxu $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_umtx.c 232286 2012-02-29 02:01:48Z davidxu $");
 
 #include "opt_compat.h"
 #include <sys/param.h>
@@ -970,16 +970,24 @@
 }
 #endif
 
+static inline int 
+tstohz(const struct timespec *tsp)
+{
+	struct timeval tv;
+
+	TIMESPEC_TO_TIMEVAL(&tv, tsp);
+	return tvtohz(&tv);
+}
+
 /*
  * Fetch and compare value, sleep on the address if value is not changed.
  */
 static int
 do_wait(struct thread *td, void *addr, u_long id,
-	struct timespec *timeout, int compat32, int is_private)
+	struct _umtx_time *timeout, int compat32, int is_private)
 {
 	struct umtx_q *uq;
-	struct timespec ts, ts2, ts3;
-	struct timeval tv;
+	struct timespec ets, cts, tts;
 	u_long tmp;
 	int error = 0;
 
@@ -1005,12 +1013,22 @@
 		umtxq_remove(uq);
 		umtxq_unlock(&uq->uq_key);
 	} else {
-		getnanouptime(&ts);
-		timespecadd(&ts, timeout);
-		TIMESPEC_TO_TIMEVAL(&tv, timeout);
+		kern_clock_gettime(td, timeout->_clockid, &cts);
+		if ((timeout->_flags & UMTX_ABSTIME) == 0) {
+			ets = cts;
+			timespecadd(&ets, &timeout->_timeout);
+		} else {
+			ets = timeout->_timeout;
+		}
 		umtxq_lock(&uq->uq_key);
 		for (;;) {
-			error = umtxq_sleep(uq, "uwait", tvtohz(&tv));
+			if (timespeccmp(&cts, &ets, >=)) {
+				error = ETIMEDOUT;
+				break;
+			}
+			tts = ets;
+			timespecsub(&tts, &cts);
+			error = umtxq_sleep(uq, "uwait", tstohz(&tts));
 			if (!(uq->uq_flags & UQF_UMTXQ)) {
 				error = 0;
 				break;
@@ -1018,15 +1036,7 @@
 			if (error != ETIMEDOUT)
 				break;
 			umtxq_unlock(&uq->uq_key);
-			getnanouptime(&ts2);
-			if (timespeccmp(&ts2, &ts, >=)) {
-				error = ETIMEDOUT;
-				umtxq_lock(&uq->uq_key);
-				break;
-			}
-			ts3 = ts;
-			timespecsub(&ts3, &ts2);
-			TIMESPEC_TO_TIMEVAL(&tv, &ts3);
+			kern_clock_gettime(td, timeout->_clockid, &cts);
 			umtxq_lock(&uq->uq_key);
 		}
 		umtxq_remove(uq);
@@ -2207,10 +2217,9 @@
  */
 static int
 do_lock_umutex(struct thread *td, struct umutex *m,
-	struct timespec *timeout, int mode)
+	struct _umtx_time *timeout, int mode)
 {
-	struct timespec ts, ts2, ts3;
-	struct timeval tv;
+	struct timespec cts, ets, tts;
 	uint32_t flags;
 	int error;
 
@@ -2224,21 +2233,25 @@
 		if (error == EINTR && mode != _UMUTEX_WAIT)
 			error = ERESTART;
 	} else {
-		getnanouptime(&ts);
-		timespecadd(&ts, timeout);
-		TIMESPEC_TO_TIMEVAL(&tv, timeout);
+		kern_clock_gettime(td, timeout->_clockid, &cts);
+		if ((timeout->_flags & UMTX_ABSTIME) == 0) {
+			ets = cts;
+			timespecadd(&ets, &timeout->_timeout);
+			tts = timeout->_timeout;
+		} else {
+			ets = timeout->_timeout;
+			tts = timeout->_timeout;
+			timespecsub(&tts, &cts);
+		}
 		for (;;) {
-			error = _do_lock_umutex(td, m, flags, tvtohz(&tv), mode);
+			error = _do_lock_umutex(td, m, flags, tstohz(&tts), mode);
 			if (error != ETIMEDOUT)
 				break;
-			getnanouptime(&ts2);
-			if (timespeccmp(&ts2, &ts, >=)) {
-				error = ETIMEDOUT;
+			kern_clock_gettime(td, timeout->_clockid, &cts);
+			if (timespeccmp(&cts, &ets, >=))
 				break;
-			}
-			ts3 = ts;
-			timespecsub(&ts3, &ts2);
-			TIMESPEC_TO_TIMEVAL(&tv, &ts3);
+			tts = ets;
+			timespecsub(&tts, &cts);
 		}
 		/* Timed-locking is not restarted. */
 		if (error == ERESTART)
@@ -2276,7 +2289,6 @@
 	struct timespec *timeout, u_long wflags)
 {
 	struct umtx_q *uq;
-	struct timeval tv;
 	struct timespec cts, ets, tts;
 	uint32_t flags;
 	uint32_t clockid;
@@ -2332,9 +2344,8 @@
 				kern_clock_gettime(td, clockid, &cts);
 				timespecsub(&tts, &cts);
 			}
-			TIMESPEC_TO_TIMEVAL(&tv, &tts);
 			for (;;) {
-				error = umtxq_sleep(uq, "ucond", tvtohz(&tv));
+				error = umtxq_sleep(uq, "ucond", tstohz(&tts));
 				if (error != ETIMEDOUT)
 					break;
 				kern_clock_gettime(td, clockid, &cts);
@@ -2344,7 +2355,6 @@
 				}
 				tts = ets;
 				timespecsub(&tts, &cts);
-				TIMESPEC_TO_TIMEVAL(&tv, &tts);
 			}
 		}
 	}
@@ -2542,27 +2552,30 @@
 }
 
 static int
-do_rw_rdlock2(struct thread *td, void *obj, long val, struct timespec *timeout)
+do_rw_rdlock2(struct thread *td, void *obj, long val, struct _umtx_time *timeout)
 {
-	struct timespec ts, ts2, ts3;
-	struct timeval tv;
+	struct timespec cts, ets, tts;
 	int error;
 
-	getnanouptime(&ts);
-	timespecadd(&ts, timeout);
-	TIMESPEC_TO_TIMEVAL(&tv, timeout);
+	kern_clock_gettime(td, timeout->_clockid, &cts);
+	if ((timeout->_flags & UMTX_ABSTIME) == 0) {
+		ets = cts;
+		timespecadd(&ets, &timeout->_timeout);
+		tts = timeout->_timeout;
+	} else {
+		ets = timeout->_timeout;
+		tts = timeout->_timeout;
+		timespecsub(&tts, &cts);
+	}
 	for (;;) {
-		error = do_rw_rdlock(td, obj, val, tvtohz(&tv));
+		error = do_rw_rdlock(td, obj, val, tstohz(&tts));
 		if (error != ETIMEDOUT)
 			break;
-		getnanouptime(&ts2);
-		if (timespeccmp(&ts2, &ts, >=)) {
-			error = ETIMEDOUT;
+		kern_clock_gettime(td, timeout->_clockid, &cts);
+		if (timespeccmp(&cts, &ets, >=))
 			break;
-		}
-		ts3 = ts;
-		timespecsub(&ts3, &ts2);
-		TIMESPEC_TO_TIMEVAL(&tv, &ts3);
+		tts = ets;
+		timespecsub(&tts, &cts);
 	}
 	if (error == ERESTART)
 		error = EINTR;
@@ -2679,27 +2692,30 @@
 }
 
 static int
-do_rw_wrlock2(struct thread *td, void *obj, struct timespec *timeout)
+do_rw_wrlock2(struct thread *td, void *obj, struct _umtx_time *timeout)
 {
-	struct timespec ts, ts2, ts3;
-	struct timeval tv;
+	struct timespec cts, ets, tts;
 	int error;
 
-	getnanouptime(&ts);
-	timespecadd(&ts, timeout);
-	TIMESPEC_TO_TIMEVAL(&tv, timeout);
+	kern_clock_gettime(td, timeout->_clockid, &cts);
+	if ((timeout->_flags & UMTX_ABSTIME) == 0) {
+		ets = cts;
+		timespecadd(&ets, &timeout->_timeout);
+		tts = timeout->_timeout;
+	} else {
+		ets = timeout->_timeout;
+		tts = timeout->_timeout;
+		timespecsub(&tts, &cts);
+	}
 	for (;;) {
-		error = do_rw_wrlock(td, obj, tvtohz(&tv));
+		error = do_rw_wrlock(td, obj, tstohz(&tts));
 		if (error != ETIMEDOUT)
 			break;
-		getnanouptime(&ts2);
-		if (timespeccmp(&ts2, &ts, >=)) {
-			error = ETIMEDOUT;
+		kern_clock_gettime(td, timeout->_clockid, &cts);
+		if (timespeccmp(&cts, &ets, >=))
 			break;
-		}
-		ts3 = ts;
-		timespecsub(&ts3, &ts2);
-		TIMESPEC_TO_TIMEVAL(&tv, &ts3);
+		tts = ets;
+		timespecsub(&tts, &cts);
 	}
 	if (error == ERESTART)
 		error = EINTR;
@@ -2786,10 +2802,9 @@
 }
 
 static int
-do_sem_wait(struct thread *td, struct _usem *sem, struct timespec *timeout)
+do_sem_wait(struct thread *td, struct _usem *sem, struct _umtx_time *timeout)
 {
 	struct umtx_q *uq;
-	struct timeval tv;
 	struct timespec cts, ets, tts;
 	uint32_t flags, count;
 	int error;
@@ -2818,27 +2833,32 @@
 
 	umtxq_lock(&uq->uq_key);
 	umtxq_unbusy(&uq->uq_key);
-	umtxq_unlock(&uq->uq_key);
-
-	umtxq_lock(&uq->uq_key);
+
 	if (timeout == NULL) {
 		error = umtxq_sleep(uq, "usem", 0);
 	} else {
-		getnanouptime(&ets);
-		timespecadd(&ets, timeout);
-		TIMESPEC_TO_TIMEVAL(&tv, timeout);
+		umtxq_unlock(&uq->uq_key);
+		kern_clock_gettime(td, timeout->_clockid, &cts);
+		if ((timeout->_flags & UMTX_ABSTIME) == 0) {
+			ets = cts;
+			timespecadd(&ets, &timeout->_timeout);
+		} else {
+			ets = timeout->_timeout;
+		}
+		umtxq_lock(&uq->uq_key);
 		for (;;) {
-			error = umtxq_sleep(uq, "usem", tvtohz(&tv));
-			if (error != ETIMEDOUT)
-				break;
-			getnanouptime(&cts);
 			if (timespeccmp(&cts, &ets, >=)) {
 				error = ETIMEDOUT;
 				break;
 			}
 			tts = ets;
 			timespecsub(&tts, &cts);
-			TIMESPEC_TO_TIMEVAL(&tv, &tts);
+			error = umtxq_sleep(uq, "usem", tstohz(&tts));
+			if (error != ETIMEDOUT)
+				break;
+			umtxq_unlock(&uq->uq_key);
+			kern_clock_gettime(td, timeout->_clockid, &cts);
+			umtxq_lock(&uq->uq_key);
 		}
 	}
 
@@ -2912,6 +2932,25 @@
 	return (error);
 }
 
+static inline int
+umtx_copyin_umtx_time(const void *addr, size_t size, struct _umtx_time *tp)
+{
+	int error;
+	
+	if (size <= sizeof(struct timespec)) {
+		tp->_clockid = CLOCK_REALTIME;
+		tp->_flags = 0;
+		error = copyin(addr, &tp->_timeout, sizeof(struct timespec));
+	} else 
+		error = copyin(addr, tp, sizeof(struct _umtx_time));
+	if (error != 0)
+		return (error);
+	if (tp->_timeout.tv_sec < 0 ||
+	    tp->_timeout.tv_nsec >= 1000000000 || tp->_timeout.tv_nsec < 0)
+		return (EINVAL);
+	return (0);
+}
+
 static int
 __umtx_op_lock_umtx(struct thread *td, struct _umtx_op_args *uap)
 {
@@ -2939,52 +2978,55 @@
 static int
 __umtx_op_wait(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time timeout, *tm_p;
 	int error;
 
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time(
+		    uap->uaddr2, (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return do_wait(td, uap->obj, uap->val, ts, 0, 0);
+	return do_wait(td, uap->obj, uap->val, tm_p, 0, 0);
 }
 
 static int
 __umtx_op_wait_uint(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time timeout, *tm_p;
 	int error;
 
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time(
+		    uap->uaddr2, (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return do_wait(td, uap->obj, uap->val, ts, 1, 0);
+	return do_wait(td, uap->obj, uap->val, tm_p, 1, 0);
 }
 
 static int
 __umtx_op_wait_uint_private(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time *tm_p, timeout;
 	int error;
 
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time(
+		    uap->uaddr2, (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return do_wait(td, uap->obj, uap->val, ts, 1, 1);
+	return do_wait(td, uap->obj, uap->val, tm_p, 1, 1);
 }
 
 static int
@@ -3028,19 +3070,20 @@
 static int
 __umtx_op_lock_umutex(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time *tm_p, timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time(
+		    uap->uaddr2, (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return do_lock_umutex(td, uap->obj, ts, 0);
+	return do_lock_umutex(td, uap->obj, tm_p, 0);
 }
 
 static int
@@ -3052,19 +3095,20 @@
 static int
 __umtx_op_wait_umutex(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time *tm_p, timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time(
+		    uap->uaddr2, (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return do_lock_umutex(td, uap->obj, ts, _UMUTEX_WAIT);
+	return do_lock_umutex(td, uap->obj, tm_p, _UMUTEX_WAIT);
 }
 
 static int
@@ -3118,14 +3162,15 @@
 static int
 __umtx_op_rw_rdlock(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec timeout;
+	struct _umtx_time timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL) {
 		error = do_rw_rdlock(td, uap->obj, uap->val, 0);
 	} else {
-		error = umtx_copyin_timeout(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time(uap->uaddr2,
+		   (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
 		error = do_rw_rdlock2(td, uap->obj, uap->val, &timeout);
@@ -3136,14 +3181,15 @@
 static int
 __umtx_op_rw_wrlock(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec timeout;
+	struct _umtx_time timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL) {
 		error = do_rw_wrlock(td, uap->obj, 0);
 	} else {
-		error = umtx_copyin_timeout(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time(uap->uaddr2, 
+		   (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
 
@@ -3161,19 +3207,20 @@
 static int
 __umtx_op_sem_wait(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time *tm_p, timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time(
+		    uap->uaddr2, (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return (do_sem_wait(td, uap->obj, ts));
+	return (do_sem_wait(td, uap->obj, tm_p));
 }
 
 static int
@@ -3237,6 +3284,12 @@
 	uint32_t tv_nsec;
 };
 
+struct umtx_time32 {
+	struct	timespec32	timeout;
+	uint32_t		flags;
+	uint32_t		clockid;
+};
+
 static inline int
 umtx_copyin_timeout32(void *addr, struct timespec *tsp)
 {
@@ -3257,6 +3310,30 @@
 	return (error);
 }
 
+static inline int
+umtx_copyin_umtx_time32(const void *addr, size_t size, struct _umtx_time *tp)
+{
+	struct umtx_time32 t32;
+	int error;
+	
+	t32.clockid = CLOCK_REALTIME;
+	t32.flags   = 0;
+	if (size <= sizeof(struct timespec32))
+		error = copyin(addr, &t32.timeout, sizeof(struct timespec32));
+	else 
+		error = copyin(addr, &t32, sizeof(struct umtx_time32));
+	if (error != 0)
+		return (error);
+	if (t32.timeout.tv_sec < 0 ||
+	    t32.timeout.tv_nsec >= 1000000000 || t32.timeout.tv_nsec < 0)
+		return (EINVAL);
+	tp->_timeout.tv_sec = t32.timeout.tv_sec;
+	tp->_timeout.tv_nsec = t32.timeout.tv_nsec;
+	tp->_flags = t32.flags;
+	tp->_clockid = t32.clockid;
+	return (0);
+}
+
 static int
 __umtx_op_lock_umtx_compat32(struct thread *td, struct _umtx_op_args *uap)
 {
@@ -3284,54 +3361,57 @@
 static int
 __umtx_op_wait_compat32(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time *tm_p, timeout;
 	int error;
 
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout32(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time32(uap->uaddr2,
+			(size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return do_wait(td, uap->obj, uap->val, ts, 1, 0);
+	return do_wait(td, uap->obj, uap->val, tm_p, 1, 0);
 }
 
 static int
 __umtx_op_lock_umutex_compat32(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time *tm_p, timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout32(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time(uap->uaddr2,
+			    (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return do_lock_umutex(td, uap->obj, ts, 0);
+	return do_lock_umutex(td, uap->obj, tm_p, 0);
 }
 
 static int
 __umtx_op_wait_umutex_compat32(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time *tm_p, timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout32(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time32(uap->uaddr2, 
+		    (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return do_lock_umutex(td, uap->obj, ts, _UMUTEX_WAIT);
+	return do_lock_umutex(td, uap->obj, tm_p, _UMUTEX_WAIT);
 }
 
 static int
@@ -3355,14 +3435,15 @@
 static int
 __umtx_op_rw_rdlock_compat32(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec timeout;
+	struct _umtx_time timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL) {
 		error = do_rw_rdlock(td, uap->obj, uap->val, 0);
 	} else {
-		error = umtx_copyin_timeout32(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time32(uap->uaddr2,
+		    (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
 		error = do_rw_rdlock2(td, uap->obj, uap->val, &timeout);
@@ -3373,17 +3454,17 @@
 static int
 __umtx_op_rw_wrlock_compat32(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec timeout;
+	struct _umtx_time timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL) {
 		error = do_rw_wrlock(td, uap->obj, 0);
 	} else {
-		error = umtx_copyin_timeout32(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time32(uap->uaddr2,
+		    (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-
 		error = do_rw_wrlock2(td, uap->obj, &timeout);
 	}
 	return (error);
@@ -3392,36 +3473,38 @@
 static int
 __umtx_op_wait_uint_private_compat32(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time *tm_p, timeout;
 	int error;
 
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout32(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time32(
+		    uap->uaddr2, (size_t)uap->uaddr1,&timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return do_wait(td, uap->obj, uap->val, ts, 1, 1);
+	return do_wait(td, uap->obj, uap->val, tm_p, 1, 1);
 }
 
 static int
 __umtx_op_sem_wait_compat32(struct thread *td, struct _umtx_op_args *uap)
 {
-	struct timespec *ts, timeout;
+	struct _umtx_time *tm_p, timeout;
 	int error;
 
 	/* Allow a null timespec (wait forever). */
 	if (uap->uaddr2 == NULL)
-		ts = NULL;
+		tm_p = NULL;
 	else {
-		error = umtx_copyin_timeout32(uap->uaddr2, &timeout);
+		error = umtx_copyin_umtx_time32(uap->uaddr2,
+		    (size_t)uap->uaddr1, &timeout);
 		if (error != 0)
 			return (error);
-		ts = &timeout;
+		tm_p = &timeout;
 	}
-	return (do_sem_wait(td, uap->obj, ts));
+	return (do_sem_wait(td, uap->obj, tm_p));
 }
 
 static int
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/link_elf.c
--- a/head/sys/kern/link_elf.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/link_elf.c	Fri Mar 02 17:07:09 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/link_elf.c 223155 2011-06-16 17:41:21Z marcel $");
+__FBSDID("$FreeBSD: head/sys/kern/link_elf.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include "opt_ddb.h"
 #include "opt_gdb.h"
@@ -655,7 +655,8 @@
 	Elf_Addr base_vaddr;
 	Elf_Addr base_vlimit;
 	int error = 0;
-	int resid, flags;
+	ssize_t resid;
+	int flags;
 	elf_file_t ef;
 	linker_file_t lf;
 	Elf_Shdr *shdr;
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/link_elf_obj.c
--- a/head/sys/kern/link_elf_obj.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/link_elf_obj.c	Fri Mar 02 17:07:09 2012 +0200
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/link_elf_obj.c 230097 2012-01-14 00:36:07Z gonzo $");
+__FBSDID("$FreeBSD: head/sys/kern/link_elf_obj.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include "opt_ddb.h"
 
@@ -440,7 +440,8 @@
 	vm_offset_t mapbase;
 	size_t mapsize;
 	int error = 0;
-	int resid, flags;
+	ssize_t resid;
+	int flags;
 	elf_file_t ef;
 	linker_file_t lf;
 	int symtabindex;
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/sched_ule.c
--- a/head/sys/kern/sched_ule.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/sched_ule.c	Fri Mar 02 17:07:09 2012 +0200
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/sched_ule.c 229429 2012-01-03 21:03:28Z jhb $");
+__FBSDID("$FreeBSD: head/sys/kern/sched_ule.c 232207 2012-02-27 10:31:54Z mav $");
 
 #include "opt_hwpmc_hooks.h"
 #include "opt_kdtrace.h"
@@ -258,7 +258,6 @@
 static int rebalance = 1;
 static int balance_interval = 128;	/* Default set in sched_initticks(). */
 static int affinity;
-static int steal_htt = 1;
 static int steal_idle = 1;
 static int steal_thresh = 2;
 
@@ -268,6 +267,7 @@
 static struct tdq	tdq_cpu[MAXCPU];
 static struct tdq	*balance_tdq;
 static int balance_ticks;
+static DPCPU_DEFINE(uint32_t, randomval);
 
 #define	TDQ_SELF()	(&tdq_cpu[PCPU_GET(cpuid)])
 #define	TDQ_CPU(x)	(&tdq_cpu[(x)])
@@ -553,9 +553,11 @@
 #ifdef SMP
 struct cpu_search {
 	cpuset_t cs_mask;
-	u_int	cs_load;
-	u_int	cs_cpu;
-	int	cs_limit;	/* Min priority for low min load for high. */
+	u_int	cs_prefer;
+	int	cs_pri;		/* Min priority for low. */
+	int	cs_limit;	/* Max load for low, min load for high. */
+	int	cs_cpu;
+	int	cs_load;
 };
 
 #define	CPU_SEARCH_LOWEST	0x1
@@ -566,44 +568,14 @@
 	for ((cpu) = 0; (cpu) <= mp_maxid; (cpu)++)		\
 		if (CPU_ISSET(cpu, &mask))
 
-static __inline int cpu_search(struct cpu_group *cg, struct cpu_search *low,
+static __inline int cpu_search(const struct cpu_group *cg, struct cpu_search *low,
     struct cpu_search *high, const int match);
-int cpu_search_lowest(struct cpu_group *cg, struct cpu_search *low);
-int cpu_search_highest(struct cpu_group *cg, struct cpu_search *high);
-int cpu_search_both(struct cpu_group *cg, struct cpu_search *low,
+int cpu_search_lowest(const struct cpu_group *cg, struct cpu_search *low);
+int cpu_search_highest(const struct cpu_group *cg, struct cpu_search *high);
+int cpu_search_both(const struct cpu_group *cg, struct cpu_search *low,
     struct cpu_search *high);
 
 /*
- * This routine compares according to the match argument and should be
- * reduced in actual instantiations via constant propagation and dead code
- * elimination.
- */ 
-static __inline int
-cpu_compare(int cpu, struct cpu_search *low, struct cpu_search *high,
-    const int match)
-{
-	struct tdq *tdq;
-
-	tdq = TDQ_CPU(cpu);
-	if (match & CPU_SEARCH_LOWEST)
-		if (CPU_ISSET(cpu, &low->cs_mask) &&
-		    tdq->tdq_load < low->cs_load &&
-		    tdq->tdq_lowpri > low->cs_limit) {
-			low->cs_cpu = cpu;
-			low->cs_load = tdq->tdq_load;
-		}
-	if (match & CPU_SEARCH_HIGHEST)
-		if (CPU_ISSET(cpu, &high->cs_mask) &&
-		    tdq->tdq_load >= high->cs_limit && 
-		    tdq->tdq_load > high->cs_load &&
-		    tdq->tdq_transferable) {
-			high->cs_cpu = cpu;
-			high->cs_load = tdq->tdq_load;
-		}
-	return (tdq->tdq_load);
-}
-
-/*
  * Search the tree of cpu_groups for the lowest or highest loaded cpu
  * according to the match argument.  This routine actually compares the
  * load on all paths through the tree and finds the least loaded cpu on
@@ -615,33 +587,42 @@
  * also recursive to the depth of the tree.
  */
 static __inline int
-cpu_search(struct cpu_group *cg, struct cpu_search *low,
+cpu_search(const struct cpu_group *cg, struct cpu_search *low,
     struct cpu_search *high, const int match)
 {
-	int total;
+	struct cpu_search lgroup;
+	struct cpu_search hgroup;
+	cpuset_t cpumask;
+	struct cpu_group *child;
+	struct tdq *tdq;
+	int cpu, i, hload, lload, load, total, rnd;
 
 	total = 0;
-	if (cg->cg_children) {
-		struct cpu_search lgroup;
-		struct cpu_search hgroup;
-		struct cpu_group *child;
-		u_int lload;
-		int hload;
-		int load;
-		int i;
+	cpumask = cg->cg_mask;
+	if (match & CPU_SEARCH_LOWEST) {
+		lload = INT_MAX;
+		low->cs_load = INT_MAX;
+		lgroup = *low;
+	}
+	if (match & CPU_SEARCH_HIGHEST) {
+		hload = -1;
+		high->cs_load = -1;
+		hgroup = *high;
+	}
 
-		lload = -1;
-		hload = -1;
-		for (i = 0; i < cg->cg_children; i++) {
+	/* Iterate through the child CPU groups and then remaining CPUs. */
+	for (i = 0, cpu = 0; i <= cg->cg_children; ) {
+		if (i >= cg->cg_children) {
+			while (cpu <= mp_maxid && !CPU_ISSET(cpu, &cpumask))
+				cpu++;
+			if (cpu > mp_maxid)
+				break;
+			child = NULL;
+		} else
 			child = &cg->cg_child[i];
-			if (match & CPU_SEARCH_LOWEST) {
-				lgroup = *low;
-				lgroup.cs_load = -1;
-			}
-			if (match & CPU_SEARCH_HIGHEST) {
-				hgroup = *high;
-				lgroup.cs_load = 0;
-			}
+
+		if (child) {			/* Handle child CPU group. */
+			CPU_NAND(&cpumask, &child->cg_mask);
 			switch (match) {
 			case CPU_SEARCH_LOWEST:
 				load = cpu_search_lowest(child, &lgroup);
@@ -653,23 +634,52 @@
 				load = cpu_search_both(child, &lgroup, &hgroup);
 				break;
 			}
-			total += load;
-			if (match & CPU_SEARCH_LOWEST)
-				if (load < lload || low->cs_cpu == -1) {
-					*low = lgroup;
-					lload = load;
+		} else {			/* Handle child CPU. */
+			tdq = TDQ_CPU(cpu);
+			load = tdq->tdq_load * 256;
+			rnd = DPCPU_SET(randomval,
+			    DPCPU_GET(randomval) * 69069 + 5) >> 26;
+			if (match & CPU_SEARCH_LOWEST) {
+				if (cpu == low->cs_prefer)
+					load -= 64;
+				/* If that CPU is allowed and get data. */
+				if (CPU_ISSET(cpu, &lgroup.cs_mask) &&
+				    tdq->tdq_lowpri > lgroup.cs_pri &&
+				    tdq->tdq_load <= lgroup.cs_limit) {
+					lgroup.cs_cpu = cpu;
+					lgroup.cs_load = load - rnd;
 				}
-			if (match & CPU_SEARCH_HIGHEST) 
-				if (load > hload || high->cs_cpu == -1) {
-					hload = load;
-					*high = hgroup;
+			}
+			if (match & CPU_SEARCH_HIGHEST)
+				if (CPU_ISSET(cpu, &hgroup.cs_mask) &&
+				    tdq->tdq_load >= hgroup.cs_limit &&
+				    tdq->tdq_transferable) {
+					hgroup.cs_cpu = cpu;
+					hgroup.cs_load = load - rnd;
 				}
 		}
-	} else {
-		int cpu;
+		total += load;
 
-		CPUSET_FOREACH(cpu, cg->cg_mask)
-			total += cpu_compare(cpu, low, high, match);
+		/* We have info about child item. Compare it. */
+		if (match & CPU_SEARCH_LOWEST) {
+			if ((load < lload) ||
+			    (load == lload && lgroup.cs_load < low->cs_load)) {
+				lload = load;
+				low->cs_cpu = lgroup.cs_cpu;
+				low->cs_load = lgroup.cs_load;
+			}
+		}
+		if (match & CPU_SEARCH_HIGHEST)
+			if ((load > hload) ||
+			    (load == hload && hgroup.cs_load > high->cs_load)) {
+				hload = load;
+				high->cs_cpu = hgroup.cs_cpu;
+				high->cs_load = hgroup.cs_load;
+			}
+		if (child)
+			i++;
+		else
+			cpu++;
 	}
 	return (total);
 }
@@ -679,19 +689,19 @@
  * optimization.
  */
 int
-cpu_search_lowest(struct cpu_group *cg, struct cpu_search *low)
+cpu_search_lowest(const struct cpu_group *cg, struct cpu_search *low)
 {
 	return cpu_search(cg, low, NULL, CPU_SEARCH_LOWEST);
 }
 
 int
-cpu_search_highest(struct cpu_group *cg, struct cpu_search *high)
+cpu_search_highest(const struct cpu_group *cg, struct cpu_search *high)
 {
 	return cpu_search(cg, NULL, high, CPU_SEARCH_HIGHEST);
 }
 
 int
-cpu_search_both(struct cpu_group *cg, struct cpu_search *low,
+cpu_search_both(const struct cpu_group *cg, struct cpu_search *low,
     struct cpu_search *high)
 {
 	return cpu_search(cg, low, high, CPU_SEARCH_BOTH);
@@ -703,14 +713,16 @@
  * acceptable.
  */
 static inline int
-sched_lowest(struct cpu_group *cg, cpuset_t mask, int pri)
+sched_lowest(const struct cpu_group *cg, cpuset_t mask, int pri, int maxload,
+    int prefer)
 {
 	struct cpu_search low;
 
 	low.cs_cpu = -1;
-	low.cs_load = -1;
+	low.cs_prefer = prefer;
 	low.cs_mask = mask;
-	low.cs_limit = pri;
+	low.cs_pri = pri;
+	low.cs_limit = maxload;
 	cpu_search_lowest(cg, &low);
 	return low.cs_cpu;
 }
@@ -719,12 +731,11 @@
  * Find the cpu with the highest load via the highest loaded path.
  */
 static inline int
-sched_highest(struct cpu_group *cg, cpuset_t mask, int minload)
+sched_highest(const struct cpu_group *cg, cpuset_t mask, int minload)
 {
 	struct cpu_search high;
 
 	high.cs_cpu = -1;
-	high.cs_load = 0;
 	high.cs_mask = mask;
 	high.cs_limit = minload;
 	cpu_search_highest(cg, &high);
@@ -735,17 +746,17 @@
  * Simultaneously find the highest and lowest loaded cpu reachable via
  * cg.
  */
-static inline void 
-sched_both(struct cpu_group *cg, cpuset_t mask, int *lowcpu, int *highcpu)
+static inline void
+sched_both(const struct cpu_group *cg, cpuset_t mask, int *lowcpu, int *highcpu)
 {
 	struct cpu_search high;
 	struct cpu_search low;
 
 	low.cs_cpu = -1;
-	low.cs_limit = -1;
-	low.cs_load = -1;
+	low.cs_prefer = -1;
+	low.cs_pri = -1;
+	low.cs_limit = INT_MAX;
 	low.cs_mask = mask;
-	high.cs_load = 0;
 	high.cs_cpu = -1;
 	high.cs_limit = -1;
 	high.cs_mask = mask;
@@ -758,30 +769,45 @@
 static void
 sched_balance_group(struct cpu_group *cg)
 {
-	cpuset_t mask;
-	int high;
-	int low;
-	int i;
+	cpuset_t hmask, lmask;
+	int high, low, anylow;
 
-	CPU_FILL(&mask);
+	CPU_FILL(&hmask);
 	for (;;) {
-		sched_both(cg, mask, &low, &high);
-		if (low == high || low == -1 || high == -1)
+		high = sched_highest(cg, hmask, 1);
+		/* Stop if there is no more CPU with transferrable threads. */
+		if (high == -1)
 			break;
-		if (sched_balance_pair(TDQ_CPU(high), TDQ_CPU(low)))
+		CPU_CLR(high, &hmask);
+		CPU_COPY(&hmask, &lmask);
+		/* Stop if there is no more CPU left for low. */
+		if (CPU_EMPTY(&lmask))
 			break;
-		/*
-		 * If we failed to move any threads determine which cpu
-		 * to kick out of the set and try again.
-	 	 */
-		if (TDQ_CPU(high)->tdq_transferable == 0)
-			CPU_CLR(high, &mask);
-		else
-			CPU_CLR(low, &mask);
+		anylow = 1;
+nextlow:
+		low = sched_lowest(cg, lmask, -1,
+		    TDQ_CPU(high)->tdq_load - 1, high);
+		/* Stop if we looked well and found no less loaded CPU. */
+		if (anylow && low == -1)
+			break;
+		/* Go to next high if we found no less loaded CPU. */
+		if (low == -1)
+			continue;
+		/* Transfer thread from high to low. */
+		if (sched_balance_pair(TDQ_CPU(high), TDQ_CPU(low))) {
+			/* CPU that got thread can no longer be a donor. */
+			CPU_CLR(low, &hmask);
+		} else {
+			/*
+			 * If failed, then there is no threads on high
+			 * that can run on this low. Drop low from low
+			 * mask and look for different one.
+			 */
+			CPU_CLR(low, &lmask);
+			anylow = 0;
+			goto nextlow;
+		}
 	}
-
-	for (i = 0; i < cg->cg_children; i++)
-		sched_balance_group(&cg->cg_child[i]);
 }
 
 static void
@@ -834,32 +860,17 @@
 static int
 sched_balance_pair(struct tdq *high, struct tdq *low)
 {
-	int transferable;
-	int high_load;
-	int low_load;
 	int moved;
-	int move;
 	int cpu;
-	int diff;
-	int i;
 
 	tdq_lock_pair(high, low);
-	transferable = high->tdq_transferable;
-	high_load = high->tdq_load;
-	low_load = low->tdq_load;
 	moved = 0;
 	/*
 	 * Determine what the imbalance is and then adjust that to how many
 	 * threads we actually have to give up (transferable).
 	 */
-	if (transferable != 0) {
-		diff = high_load - low_load;
-		move = diff / 2;
-		if (diff & 0x1)
-			move++;
-		move = min(move, transferable);
-		for (i = 0; i < move; i++)
-			moved += tdq_move(high, low);
+	if (high->tdq_transferable != 0 && high->tdq_load > low->tdq_load &&
+	    (moved = tdq_move(high, low)) > 0) {
 		/*
 		 * In case the target isn't the current cpu IPI it to force a
 		 * reschedule with the new workload.
@@ -1003,8 +1014,7 @@
 {
 	struct rqbits *rqb;
 	struct rqhead *rqh;
-	struct thread *td;
-	int first;
+	struct thread *td, *first;
 	int bit;
 	int pri;
 	int i;
@@ -1012,7 +1022,7 @@
 	rqb = &rq->rq_status;
 	bit = start & (RQB_BPW -1);
 	pri = 0;
-	first = 0;
+	first = NULL;
 again:
 	for (i = RQB_WORD(start); i < RQB_LEN; bit = 0, i++) {
 		if (rqb->rqb_bits[i] == 0)
@@ -1031,7 +1041,7 @@
 			if (first && THREAD_CAN_MIGRATE(td) &&
 			    THREAD_CAN_SCHED(td, cpu))
 				return (td);
-			first = 1;
+			first = td;
 		}
 	}
 	if (start != 0) {
@@ -1039,6 +1049,9 @@
 		goto again;
 	}
 
+	if (first && THREAD_CAN_MIGRATE(first) &&
+	    THREAD_CAN_SCHED(first, cpu))
+		return (first);
 	return (NULL);
 }
 
@@ -1140,13 +1153,11 @@
 static int
 sched_pickcpu(struct thread *td, int flags)
 {
-	struct cpu_group *cg;
+	struct cpu_group *cg, *ccg;
 	struct td_sched *ts;
 	struct tdq *tdq;
 	cpuset_t mask;
-	int self;
-	int pri;
-	int cpu;
+	int cpu, pri, self;
 
 	self = PCPU_GET(cpuid);
 	ts = td->td_sched;
@@ -1161,45 +1172,70 @@
 	 * Prefer to run interrupt threads on the processors that generate
 	 * the interrupt.
 	 */
+	pri = td->td_priority;
 	if (td->td_priority <= PRI_MAX_ITHD && THREAD_CAN_SCHED(td, self) &&
 	    curthread->td_intr_nesting_level && ts->ts_cpu != self) {
 		SCHED_STAT_INC(pickcpu_intrbind);
 		ts->ts_cpu = self;
+		if (TDQ_CPU(self)->tdq_lowpri > pri) {
+			SCHED_STAT_INC(pickcpu_affinity);
+			return (ts->ts_cpu);
+		}
 	}
 	/*
 	 * If the thread can run on the last cpu and the affinity has not
 	 * expired or it is idle run it there.
 	 */
-	pri = td->td_priority;
 	tdq = TDQ_CPU(ts->ts_cpu);
-	if (THREAD_CAN_SCHED(td, ts->ts_cpu)) {
-		if (tdq->tdq_lowpri > PRI_MIN_IDLE) {
+	cg = tdq->tdq_cg;
+	if (THREAD_CAN_SCHED(td, ts->ts_cpu) &&
+	    tdq->tdq_lowpri >= PRI_MIN_IDLE &&
+	    SCHED_AFFINITY(ts, CG_SHARE_L2)) {
+		if (cg->cg_flags & CG_FLAG_THREAD) {
+			CPUSET_FOREACH(cpu, cg->cg_mask) {
+				if (TDQ_CPU(cpu)->tdq_lowpri < PRI_MIN_IDLE)
+					break;
+			}
+		} else
+			cpu = INT_MAX;
+		if (cpu > mp_maxid) {
 			SCHED_STAT_INC(pickcpu_idle_affinity);
 			return (ts->ts_cpu);
 		}
-		if (SCHED_AFFINITY(ts, CG_SHARE_L2) && tdq->tdq_lowpri > pri) {
-			SCHED_STAT_INC(pickcpu_affinity);
-			return (ts->ts_cpu);
-		}
 	}
 	/*
-	 * Search for the highest level in the tree that still has affinity.
+	 * Search for the last level cache CPU group in the tree.
+	 * Skip caches with expired affinity time and SMT groups.
+	 * Affinity to higher level caches will be handled less aggressively.
 	 */
-	cg = NULL;
-	for (cg = tdq->tdq_cg; cg != NULL; cg = cg->cg_parent)
-		if (SCHED_AFFINITY(ts, cg->cg_level))
-			break;
+	for (ccg = NULL; cg != NULL; cg = cg->cg_parent) {
+		if (cg->cg_flags & CG_FLAG_THREAD)
+			continue;
+		if (!SCHED_AFFINITY(ts, cg->cg_level))
+			continue;
+		ccg = cg;
+	}
+	if (ccg != NULL)
+		cg = ccg;
 	cpu = -1;
+	/* Search the group for the less loaded idle CPU we can run now. */
 	mask = td->td_cpuset->cs_mask;
-	if (cg)
-		cpu = sched_lowest(cg, mask, pri);
+	if (cg != NULL && cg != cpu_top &&
+	    CPU_CMP(&cg->cg_mask, &cpu_top->cg_mask) != 0)
+		cpu = sched_lowest(cg, mask, max(pri, PRI_MAX_TIMESHARE),
+		    INT_MAX, ts->ts_cpu);
+	/* Search globally for the less loaded CPU we can run now. */
 	if (cpu == -1)
-		cpu = sched_lowest(cpu_top, mask, -1);
+		cpu = sched_lowest(cpu_top, mask, pri, INT_MAX, ts->ts_cpu);
+	/* Search globally for the less loaded CPU. */
+	if (cpu == -1)
+		cpu = sched_lowest(cpu_top, mask, -1, INT_MAX, ts->ts_cpu);
 	/*
 	 * Compare the lowest loaded cpu to current cpu.
 	 */
 	if (THREAD_CAN_SCHED(td, self) && TDQ_CPU(self)->tdq_lowpri > pri &&
-	    TDQ_CPU(cpu)->tdq_lowpri < PRI_MIN_IDLE) {
+	    TDQ_CPU(cpu)->tdq_lowpri < PRI_MIN_IDLE &&
+	    TDQ_CPU(self)->tdq_load <= TDQ_CPU(cpu)->tdq_load + 1) {
 		SCHED_STAT_INC(pickcpu_local);
 		cpu = self;
 	} else
@@ -2750,8 +2786,6 @@
 SYSCTL_INT(_kern_sched, OID_AUTO, balance_interval, CTLFLAG_RW,
     &balance_interval, 0,
     "Average frequency in stathz ticks to run the long-term balancer");
-SYSCTL_INT(_kern_sched, OID_AUTO, steal_htt, CTLFLAG_RW, &steal_htt, 0,
-    "Steals work from another hyper-threaded core on idle");
 SYSCTL_INT(_kern_sched, OID_AUTO, steal_idle, CTLFLAG_RW, &steal_idle, 0,
     "Attempts to steal work from other cores before idling");
 SYSCTL_INT(_kern_sched, OID_AUTO, steal_thresh, CTLFLAG_RW, &steal_thresh, 0,
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/subr_bus.c
--- a/head/sys/kern/subr_bus.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/subr_bus.c	Fri Mar 02 17:07:09 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/subr_bus.c 230125 2012-01-15 07:09:18Z eadler $");
+__FBSDID("$FreeBSD: head/sys/kern/subr_bus.c 232265 2012-02-28 19:16:02Z jhb $");
 
 #include "opt_bus.h"
 
@@ -1229,7 +1229,6 @@
 			    dev->parent->devclass == busclass) {
 				if ((error = device_detach(dev)) != 0)
 					return (error);
-				(void)device_set_driver(dev, NULL);
 				BUS_PROBE_NOMATCH(dev->parent, dev);
 				devnomatch(dev);
 				dev->flags |= DF_DONENOMATCH;
@@ -2197,7 +2196,7 @@
 	/* XXX What happens if we rebid and got no best? */
 	if (best) {
 		/*
-		 * If this device was atached, and we were asked to
+		 * If this device was attached, and we were asked to
 		 * rescan, and it is a different driver, then we have
 		 * to detach the old driver and reattach this new one.
 		 * Note, we don't have to check for DF_REBID here
@@ -2704,6 +2703,7 @@
 		free(dev->softc, M_BUS_SC);
 		dev->softc = NULL;
 	}
+	device_set_desc(dev, NULL);
 	kobj_delete((kobj_t) dev, NULL);
 	dev->driver = driver;
 	if (driver) {
@@ -2832,9 +2832,8 @@
 	if ((error = DEVICE_ATTACH(dev)) != 0) {
 		printf("device_attach: %s%d attach returned %d\n",
 		    dev->driver->name, dev->unit, error);
-		/* Unset the class; set in device_probe_child */
-		if (dev->devclass == NULL)
-			(void)device_set_devclass(dev, NULL);
+		if (!(dev->flags & DF_FIXEDCLASS))
+			devclass_delete_device(dev->devclass, dev);
 		(void)device_set_driver(dev, NULL);
 		device_sysctl_fini(dev);
 		dev->state = DS_NOTPRESENT;
@@ -2889,7 +2888,6 @@
 
 	dev->state = DS_NOTPRESENT;
 	(void)device_set_driver(dev, NULL);
-	device_set_desc(dev, NULL);
 	device_sysctl_fini(dev);
 
 	return (0);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/subr_log.c
--- a/head/sys/kern/subr_log.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/subr_log.c	Fri Mar 02 17:07:09 2012 +0200
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/kern/subr_log.c 230866 2012-02-01 14:34:52Z kib $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -59,6 +59,7 @@
 static	d_read_t	logread;
 static	d_ioctl_t	logioctl;
 static	d_poll_t	logpoll;
+static	d_kqfilter_t	logkqfilter;
 
 static	void logtimeout(void *arg);
 
@@ -69,9 +70,20 @@
 	.d_read =	logread,
 	.d_ioctl =	logioctl,
 	.d_poll =	logpoll,
+	.d_kqfilter =	logkqfilter,
 	.d_name =	"log",
 };
 
+static int	logkqread(struct knote *note, long hint);
+static void	logkqdetach(struct knote *note);
+
+static struct filterops log_read_filterops = {
+	.f_isfd =	1,
+	.f_attach =	NULL,
+	.f_detach =	logkqdetach,
+	.f_event =	logkqread,
+};
+
 static struct logsoftc {
 	int	sc_state;		/* see above for possibilities */
 	struct	selinfo sc_selp;	/* process waiting on select call */
@@ -181,6 +193,40 @@
 	return (revents);
 }
 
+static int
+logkqfilter(struct cdev *dev, struct knote *kn)
+{
+
+	if (kn->kn_filter != EVFILT_READ)
+		return (EINVAL);
+
+	kn->kn_fop = &log_read_filterops;
+	kn->kn_hook = NULL;
+
+	mtx_lock(&msgbuf_lock);
+	knlist_add(&logsoftc.sc_selp.si_note, kn, 1);
+	mtx_unlock(&msgbuf_lock);
+	return (0);
+}
+
+static int
+logkqread(struct knote *kn, long hint)
+{
+
+	mtx_assert(&msgbuf_lock, MA_OWNED);
+	kn->kn_data = msgbuf_getcount(msgbufp);
+	return (kn->kn_data != 0);
+}
+
+static void
+logkqdetach(struct knote *kn)
+{
+
+	mtx_lock(&msgbuf_lock);
+	knlist_remove(&logsoftc.sc_selp.si_note, kn, 1);
+	mtx_unlock(&msgbuf_lock);
+}
+
 static void
 logtimeout(void *arg)
 {
@@ -198,6 +244,7 @@
 	}
 	msgbuftrigger = 0;
 	selwakeuppri(&logsoftc.sc_selp, LOG_RDPRI);
+	KNOTE_LOCKED(&logsoftc.sc_selp.si_note, 0);
 	if ((logsoftc.sc_state & LOG_ASYNC) && logsoftc.sc_sigio != NULL)
 		pgsigio(&logsoftc.sc_sigio, SIGIO, 0);
 	cv_broadcastpri(&log_wakeup, LOG_RDPRI);
@@ -256,6 +303,7 @@
 
 	cv_init(&log_wakeup, "klog");
 	callout_init_mtx(&logsoftc.sc_callout, &msgbuf_lock, 0);
+	knlist_init_mtx(&logsoftc.sc_selp.si_note, &msgbuf_lock);
 	make_dev_credf(MAKEDEV_ETERNAL, &log_cdevsw, 0, NULL, UID_ROOT,
 	    GID_WHEEL, 0600, "klog");
 }
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/subr_mchain.c
--- a/head/sys/kern/subr_mchain.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/subr_mchain.c	Fri Mar 02 17:07:09 2012 +0200
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/subr_mchain.c 230218 2012-01-16 14:54:48Z kevlo $");
+__FBSDID("$FreeBSD: head/sys/kern/subr_mchain.c 231060 2012-02-06 06:03:16Z kevlo $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -62,7 +62,7 @@
 	m = m_gethdr(M_WAIT, MT_DATA);
 	m->m_len = 0;
 	mb_initm(mbp, m);
-	return 0;
+	return (0);
 }
 
 void
@@ -89,13 +89,13 @@
 
 	m = mbp->mb_top;
 	mbp->mb_top = NULL;
-	return m;
+	return (m);
 }
 
 int
 mb_fixhdr(struct mbchain *mbp)
 {
-	return mbp->mb_top->m_pkthdr.len = m_fixhdr(mbp->mb_top);
+	return (mbp->mb_top->m_pkthdr.len = m_fixhdr(mbp->mb_top));
 }
 
 /*
@@ -124,70 +124,70 @@
 	mbp->mb_count += size;
 	bpos = mtod(m, caddr_t) + m->m_len;
 	m->m_len += size;
-	return bpos;
+	return (bpos);
 }
 
 int
 mb_put_padbyte(struct mbchain *mbp)
 {
 	caddr_t dst;
-	char x = 0;
+	uint8_t x = 0;
 
 	dst = mtod(mbp->mb_cur, caddr_t) + mbp->mb_cur->m_len;
 
-	/* only add padding if address is odd */
+	/* Only add padding if address is odd */
 	if ((unsigned long)dst & 1)
-		return mb_put_mem(mbp, (caddr_t)&x, 1, MB_MSYSTEM);
+		return (mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM));
 	else
-		return 0;
+		return (0);
 }
 
 int
 mb_put_uint8(struct mbchain *mbp, uint8_t x)
 {
-	return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
+	return (mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM));
 }
 
 int
 mb_put_uint16be(struct mbchain *mbp, uint16_t x)
 {
 	x = htobe16(x);
-	return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
+	return (mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM));
 }
 
 int
 mb_put_uint16le(struct mbchain *mbp, uint16_t x)
 {
 	x = htole16(x);
-	return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
+	return (mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM));
 }
 
 int
 mb_put_uint32be(struct mbchain *mbp, uint32_t x)
 {
 	x = htobe32(x);
-	return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
+	return (mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM));
 }
 
 int
 mb_put_uint32le(struct mbchain *mbp, uint32_t x)
 {
 	x = htole32(x);
-	return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
+	return (mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM));
 }
 
 int
 mb_put_int64be(struct mbchain *mbp, int64_t x)
 {
 	x = htobe64(x);
-	return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
+	return (mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM));
 }
 
 int
 mb_put_int64le(struct mbchain *mbp, int64_t x)
 {
 	x = htole64(x);
-	return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM);
+	return (mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM));
 }
 
 int
@@ -220,7 +220,7 @@
 			dstlen = mleft;
 			error = mbp->mb_copy(mbp, source, dst, &srclen, &dstlen);
 			if (error)
-				return error;
+				return (error);
 			break;
 		    case MB_MINLINE:
 			for (src = source, count = cplen; count; count--)
@@ -232,7 +232,7 @@
 		    case MB_MUSER:
 			error = copyin(source, dst, cplen);
 			if (error)
-				return error;
+				return (error);
 			break;
 		    case MB_MZERO:
 			bzero(dst, cplen);
@@ -246,7 +246,7 @@
 	}
 	mbp->mb_cur = m;
 	mbp->mb_mleft = mleft;
-	return 0;
+	return (0);
 }
 
 int
@@ -261,7 +261,7 @@
 	}
 	mbp->mb_mleft = M_TRAILINGSPACE(m);
 	mbp->mb_cur = m;
-	return 0;
+	return (0);
 }
 
 /*
@@ -277,7 +277,7 @@
 
 	while (size > 0 && uiop->uio_resid) {
 		if (uiop->uio_iovcnt <= 0 || uiop->uio_iov == NULL)
-			return EFBIG;
+			return (EFBIG);
 		left = uiop->uio_iov->iov_len;
 		if (left == 0) {
 			uiop->uio_iov++;
@@ -288,7 +288,7 @@
 			left = size;
 		error = mb_put_mem(mbp, uiop->uio_iov->iov_base, left, mtype);
 		if (error)
-			return error;
+			return (error);
 		uiop->uio_offset += left;
 		uiop->uio_resid -= left;
 		uiop->uio_iov->iov_base =
@@ -296,7 +296,7 @@
 		uiop->uio_iov->iov_len -= left;
 		size -= left;
 	}
-	return 0;
+	return (0);
 }
 
 /*
@@ -310,7 +310,7 @@
 	m = m_gethdr(M_WAIT, MT_DATA);
 	m->m_len = 0;
 	md_initm(mdp, m);
-	return 0;
+	return (0);
 }
 
 void
@@ -360,25 +360,25 @@
 	struct mbuf *m;
 
 	if (mdp->md_top == NULL)
-		return ENOENT;
+		return (ENOENT);
 	m = mdp->md_top->m_nextpkt;
 	md_done(mdp);
 	if (m == NULL)
-		return ENOENT;
+		return (ENOENT);
 	md_initm(mdp, m);
-	return 0;
+	return (0);
 }
 
 int
 md_get_uint8(struct mdchain *mdp, uint8_t *x)
 {
-	return md_get_mem(mdp, x, 1, MB_MINLINE);
+	return (md_get_mem(mdp, x, 1, MB_MINLINE));
 }
 
 int
 md_get_uint16(struct mdchain *mdp, uint16_t *x)
 {
-	return md_get_mem(mdp, (caddr_t)x, 2, MB_MINLINE);
+	return (md_get_mem(mdp, (caddr_t)x, 2, MB_MINLINE));
 }
 
 int
@@ -389,7 +389,7 @@
 
 	if (x != NULL)
 		*x = le16toh(v);
-	return error;
+	return (error);
 }
 
 int
@@ -400,13 +400,13 @@
 
 	if (x != NULL)
 		*x = be16toh(v);
-	return error;
+	return (error);
 }
 
 int
 md_get_uint32(struct mdchain *mdp, uint32_t *x)
 {
-	return md_get_mem(mdp, (caddr_t)x, 4, MB_MINLINE);
+	return (md_get_mem(mdp, (caddr_t)x, 4, MB_MINLINE));
 }
 
 int
@@ -418,7 +418,7 @@
 	error = md_get_uint32(mdp, &v);
 	if (x != NULL)
 		*x = be32toh(v);
-	return error;
+	return (error);
 }
 
 int
@@ -430,13 +430,13 @@
 	error = md_get_uint32(mdp, &v);
 	if (x != NULL)
 		*x = le32toh(v);
-	return error;
+	return (error);
 }
 
 int
 md_get_int64(struct mdchain *mdp, int64_t *x)
 {
-	return md_get_mem(mdp, (caddr_t)x, 8, MB_MINLINE);
+	return (md_get_mem(mdp, (caddr_t)x, 8, MB_MINLINE));
 }
 
 int
@@ -448,7 +448,7 @@
 	error = md_get_int64(mdp, &v);
 	if (x != NULL)
 		*x = be64toh(v);
-	return error;
+	return (error);
 }
 
 int
@@ -460,7 +460,7 @@
 	error = md_get_int64(mdp, &v);
 	if (x != NULL)
 		*x = le64toh(v);
-	return error;
+	return (error);
 }
 
 int
@@ -474,7 +474,7 @@
 	while (size > 0) {
 		if (m == NULL) {
 			MBERROR("incomplete copy\n");
-			return EBADRPC;
+			return (EBADRPC);
 		}
 		s = mdp->md_pos;
 		count = mtod(m, u_char*) + m->m_len - s;
@@ -506,7 +506,7 @@
 		}
 		target += count;
 	}
-	return 0;
+	return (0);
 }
 
 int
@@ -517,7 +517,7 @@
 	rm = m_copym(m, mdp->md_pos - mtod(m, u_char*), size, M_WAIT);
 	md_get_mem(mdp, NULL, size, MB_MZERO);
 	*ret = rm;
-	return 0;
+	return (0);
 }
 
 int
@@ -530,7 +530,7 @@
 	mtype = (uiop->uio_segflg == UIO_SYSSPACE) ? MB_MSYSTEM : MB_MUSER;
 	while (size > 0 && uiop->uio_resid) {
 		if (uiop->uio_iovcnt <= 0 || uiop->uio_iov == NULL)
-			return EFBIG;
+			return (EFBIG);
 		left = uiop->uio_iov->iov_len;
 		if (left == 0) {
 			uiop->uio_iov++;
@@ -542,7 +542,7 @@
 			left = size;
 		error = md_get_mem(mdp, uiocp, left, mtype);
 		if (error)
-			return error;
+			return (error);
 		uiop->uio_offset += left;
 		uiop->uio_resid -= left;
 		uiop->uio_iov->iov_base =
@@ -550,5 +550,5 @@
 		uiop->uio_iov->iov_len -= left;
 		size -= left;
 	}
-	return 0;
+	return (0);
 }
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/subr_msgbuf.c
--- a/head/sys/kern/subr_msgbuf.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/subr_msgbuf.c	Fri Mar 02 17:07:09 2012 +0200
@@ -22,7 +22,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/sys/kern/subr_msgbuf.c 222550 2011-05-31 22:39:32Z ken $
+ * $FreeBSD: head/sys/kern/subr_msgbuf.c 231814 2012-02-16 05:11:35Z eadler $
  */
 
 /*
@@ -32,8 +32,10 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/lock.h>
+#include <sys/kernel.h>
 #include <sys/mutex.h>
 #include <sys/msgbuf.h>
+#include <sys/sysctl.h>
 
 /*
  * Maximum number conversion buffer length: uintmax_t in base 2, plus <>
@@ -47,6 +49,14 @@
 static u_int msgbuf_cksum(struct msgbuf *mbp);
 
 /*
+ *
+ */
+static int msgbuf_show_timestamp = 0;
+SYSCTL_INT(_kern, OID_AUTO, msgbuf_show_timestamp, CTLFLAG_RW | CTLFLAG_TUN,
+    &msgbuf_show_timestamp, 0, "Show timestamp in msgbuf");
+TUNABLE_INT("kern.msgbuf_show_timestamp", &msgbuf_show_timestamp);
+
+/*
  * Initialize a message buffer of the specified size at the specified
  * location. This also zeros the buffer area.
  */
@@ -60,7 +70,7 @@
 	msgbuf_clear(mbp);
 	mbp->msg_magic = MSG_MAGIC;
 	mbp->msg_lastpri = -1;
-	mbp->msg_needsnl = 0;
+	mbp->msg_flags = 0;
 	bzero(&mbp->msg_lock, sizeof(mbp->msg_lock));
 	mtx_init(&mbp->msg_lock, "msgbuf", NULL, MTX_SPIN);
 }
@@ -95,7 +105,7 @@
 
 	mbp->msg_lastpri = -1;
 	/* Assume that the old message buffer didn't end in a newline. */
-	mbp->msg_needsnl = 1;
+	mbp->msg_flags |= MSGBUF_NEEDNL;
 	bzero(&mbp->msg_lock, sizeof(mbp->msg_lock));
 	mtx_init(&mbp->msg_lock, "msgbuf", NULL, MTX_SPIN);
 }
@@ -134,7 +144,7 @@
  * The caller should hold the message buffer spinlock.
  */
 static inline void
-msgbuf_do_addchar(struct msgbuf *mbp, u_int *seq, int c)
+__msgbuf_do_addchar(struct msgbuf * const mbp, u_int * const seq, const int c)
 {
 	u_int pos;
 
@@ -149,6 +159,33 @@
 	*seq = MSGBUF_SEQNORM(mbp, *seq + 1);
 }
 
+static inline void
+msgbuf_do_addchar(struct msgbuf * const mbp, u_int * const seq, const int c)
+{
+
+	if (msgbuf_show_timestamp &&
+	    (mbp->msg_flags & MSGBUF_NEXT_NEW_LINE) != 0) {
+		char buf[32];
+		char const *bufp;
+		struct timespec ts;
+		int err;
+
+		getnanouptime(&ts);
+		err = snprintf(buf, sizeof (buf), "[%jd.%ld] ",
+		    (intmax_t)ts.tv_sec, ts.tv_nsec / 1000);
+
+		for (bufp = buf; *bufp != '\0'; bufp++)
+			__msgbuf_do_addchar(mbp, seq, *bufp);
+
+		mbp->msg_flags &= ~MSGBUF_NEXT_NEW_LINE;
+	}
+
+	__msgbuf_do_addchar(mbp, seq, c);
+
+	if (c == '\n')
+		mbp->msg_flags |= MSGBUF_NEXT_NEW_LINE;
+}
+
 /*
  * Append a character to a message buffer.
  */
@@ -207,10 +244,10 @@
 	 * did not end with a newline.  If that is the case, we need to
 	 * insert a newline before this string.
 	 */
-	if (mbp->msg_lastpri != pri && mbp->msg_needsnl != 0) {
+	if (mbp->msg_lastpri != pri && (mbp->msg_flags & MSGBUF_NEEDNL) != 0) {
 
 		msgbuf_do_addchar(mbp, &seq, '\n');
-		mbp->msg_needsnl = 0;
+		mbp->msg_flags &= ~MSGBUF_NEEDNL;
 	}
 
 	for (i = 0; i < len; i++) {
@@ -219,7 +256,7 @@
 		 * (and therefore prefix_len != 0), then we need a priority
 		 * prefix for this line.
 		 */
-		if (mbp->msg_needsnl == 0 && prefix_len != 0) {
+		if ((mbp->msg_flags & MSGBUF_NEEDNL) == 0 && prefix_len != 0) {
 			int j;
 
 			for (j = 0; j < prefix_len; j++)
@@ -242,9 +279,9 @@
 		 * we need to insert a new prefix or insert a newline later.
 		 */
 		if (str[i] == '\n')
-			mbp->msg_needsnl = 0;
+			mbp->msg_flags &= ~MSGBUF_NEEDNL;
 		else
-			mbp->msg_needsnl = 1;
+			mbp->msg_flags |= MSGBUF_NEEDNL;
 
 		msgbuf_do_addchar(mbp, &seq, str[i]);
 	}
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/subr_syscall.c
--- a/head/sys/kern/subr_syscall.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/subr_syscall.c	Fri Mar 02 17:07:09 2012 +0200
@@ -42,7 +42,7 @@
 #include "opt_ktrace.h"
 #include "opt_kdtrace.h"
 
-__FBSDID("$FreeBSD: head/sys/kern/subr_syscall.c 230785 2012-01-30 20:00:29Z kib $");
+__FBSDID("$FreeBSD: head/sys/kern/subr_syscall.c 232240 2012-02-27 21:10:10Z kib $");
 
 #include <sys/capability.h>
 #include <sys/ktr.h>
@@ -85,7 +85,11 @@
 
 	if (error == 0) {
 		STOPEVENT(p, S_SCE, sa->narg);
-		PTRACESTOP_SC(p, td, S_PT_SCE);
+		if (p->p_flag & P_TRACED && p->p_stops & S_PT_SCE) {
+			PROC_LOCK(p);
+			ptracestop((td), SIGTRAP);
+			PROC_UNLOCK(p);
+		}
 		if (td->td_dbgflags & TDB_USERWR) {
 			/*
 			 * Reread syscall number and arguments if
@@ -161,7 +165,7 @@
 static inline void
 syscallret(struct thread *td, int error, struct syscall_args *sa __unused)
 {
-	struct proc *p;
+	struct proc *p, *p2;
 	int traced;
 
 	p = td->td_proc;
@@ -219,4 +223,23 @@
 		td->td_dbgflags &= ~(TDB_SCX | TDB_EXEC | TDB_FORK);
 		PROC_UNLOCK(p);
 	}
+
+	if (td->td_pflags & TDP_RFPPWAIT) {
+		/*
+		 * Preserve synchronization semantics of vfork.  If
+		 * waiting for child to exec or exit, fork set
+		 * P_PPWAIT on child, and there we sleep on our proc
+		 * (in case of exit).
+		 *
+		 * Do it after the ptracestop() above is finished, to
+		 * not block our debugger until child execs or exits
+		 * to finish vfork wait.
+		 */
+		td->td_pflags &= ~TDP_RFPPWAIT;
+		p2 = td->td_rfppwait_p;
+		PROC_LOCK(p2);
+		while (p2->p_flag & P_PPWAIT)
+			cv_wait(&p2->p_pwait, &p2->p_mtx);
+		PROC_UNLOCK(p2);
+	}
 }
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/subr_uio.c
--- a/head/sys/kern/subr_uio.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/subr_uio.c	Fri Mar 02 17:07:09 2012 +0200
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/subr_uio.c 227496 2011-11-14 07:12:10Z alfred $");
+__FBSDID("$FreeBSD: head/sys/kern/subr_uio.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include "opt_zero.h"
 
@@ -171,7 +171,7 @@
 {
 	struct thread *td;
 	struct iovec *iov;
-	u_int cnt;
+	size_t cnt;
 	int error, newflags, save;
 
 	td = curthread;
@@ -245,14 +245,14 @@
 int
 uiomove_frombuf(void *buf, int buflen, struct uio *uio)
 {
-	unsigned int offset, n;
+	size_t offset, n;
 
 	if (uio->uio_offset < 0 || uio->uio_resid < 0 ||
 	    (offset = uio->uio_offset) != uio->uio_offset)
 		return (EINVAL);
 	if (buflen <= 0 || offset >= buflen)
 		return (0);
-	if ((n = buflen - offset) > INT_MAX)
+	if ((n = buflen - offset) > IOSIZE_MAX)
 		return (EINVAL);
 	return (uiomove((char *)buf + offset, n, uio));
 }
@@ -479,7 +479,7 @@
 	uio->uio_offset = -1;
 	uio->uio_resid = 0;
 	for (i = 0; i < iovcnt; i++) {
-		if (iov->iov_len > INT_MAX - uio->uio_resid) {
+		if (iov->iov_len > IOSIZE_MAX - uio->uio_resid) {
 			free(uio, M_IOV);
 			return (EINVAL);
 		}
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/sys_generic.c
--- a/head/sys/kern/sys_generic.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/sys_generic.c	Fri Mar 02 17:07:09 2012 +0200
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/sys_generic.c 227485 2011-11-13 10:28:01Z kib $");
+__FBSDID("$FreeBSD: head/sys/kern/sys_generic.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include "opt_capsicum.h"
 #include "opt_compat.h"
@@ -74,6 +74,10 @@
 
 #include <security/audit/audit.h>
 
+int iosize_max_clamp = 1;
+SYSCTL_INT(_debug, OID_AUTO, iosize_max_clamp, CTLFLAG_RW, &iosize_max_clamp, 0,
+    "Clamp max i/o size to INT_MAX");
+
 static MALLOC_DEFINE(M_IOCTLOPS, "ioctlops", "ioctl data buffer");
 static MALLOC_DEFINE(M_SELECT, "select", "select() buffer");
 MALLOC_DEFINE(M_IOV, "iov", "large iov's");
@@ -145,7 +149,7 @@
 	struct iovec aiov;
 	int error;
 
-	if (uap->nbyte > INT_MAX)
+	if (uap->nbyte > IOSIZE_MAX)
 		return (EINVAL);
 	aiov.iov_base = uap->buf;
 	aiov.iov_len = uap->nbyte;
@@ -178,7 +182,7 @@
 	struct iovec aiov;
 	int error;
 
-	if (uap->nbyte > INT_MAX)
+	if (uap->nbyte > IOSIZE_MAX)
 		return (EINVAL);
 	aiov.iov_base = uap->buf;
 	aiov.iov_len = uap->nbyte;
@@ -334,7 +338,12 @@
 		ktrgenio(fd, UIO_READ, ktruio, error);
 	}
 #endif
+#if SSIZE_MAX > LONG_MAX
+	td->td_retval[1] = cnt >> (sizeof(register_t) * CHAR_BIT);
 	td->td_retval[0] = cnt;
+#else
+	td->td_retval[0] = cnt;
+#endif
 	return (error);
 }
 
@@ -354,7 +363,7 @@
 	struct iovec aiov;
 	int error;
 
-	if (uap->nbyte > INT_MAX)
+	if (uap->nbyte > IOSIZE_MAX)
 		return (EINVAL);
 	aiov.iov_base = (void *)(uintptr_t)uap->buf;
 	aiov.iov_len = uap->nbyte;
@@ -387,7 +396,7 @@
 	struct iovec aiov;
 	int error;
 
-	if (uap->nbyte > INT_MAX)
+	if (uap->nbyte > IOSIZE_MAX)
 		return (EINVAL);
 	aiov.iov_base = (void *)(uintptr_t)uap->buf;
 	aiov.iov_len = uap->nbyte;
@@ -546,7 +555,12 @@
 		ktrgenio(fd, UIO_WRITE, ktruio, error);
 	}
 #endif
+#if SSIZE_MAX > LONG_MAX
+	td->td_retval[1] = cnt >> (sizeof(register_t) * CHAR_BIT);
 	td->td_retval[0] = cnt;
+#else
+	td->td_retval[0] = cnt;
+#endif
 	return (error);
 }
 
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/sys_pipe.c
--- a/head/sys/kern/sys_pipe.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/sys_pipe.c	Fri Mar 02 17:07:09 2012 +0200
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 1996 John S. Dyson
+ * Copyright (c) 2012 Giovanni Trematerra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -89,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/sys_pipe.c 228510 2011-12-14 22:26:39Z jilles $");
+__FBSDID("$FreeBSD: head/sys/kern/sys_pipe.c 232271 2012-02-28 21:45:21Z dim $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -128,6 +129,8 @@
 #include <vm/vm_page.h>
 #include <vm/uma.h>
 
+#include <fs/fifofs/fifo.h>
+
 /*
  * Use this define if you want to disable *fancy* VM things.  Expect an
  * approx 30% decrease in transfer rate.  This could be useful for
@@ -135,6 +138,9 @@
  */
 /* #define PIPE_NODIRECT */
 
+#define PIPE_PEER(pipe)	\
+	(((pipe)->pipe_state & PIPE_NAMED) ? (pipe) : ((pipe)->pipe_peer))
+
 /*
  * interfaces to the outside world
  */
@@ -146,8 +152,10 @@
 static fo_kqfilter_t	pipe_kqfilter;
 static fo_stat_t	pipe_stat;
 static fo_close_t	pipe_close;
+static fo_chmod_t	pipe_chmod;
+static fo_chown_t	pipe_chown;
 
-static struct fileops pipeops = {
+struct fileops pipeops = {
 	.fo_read = pipe_read,
 	.fo_write = pipe_write,
 	.fo_truncate = pipe_truncate,
@@ -156,15 +164,22 @@
 	.fo_kqfilter = pipe_kqfilter,
 	.fo_stat = pipe_stat,
 	.fo_close = pipe_close,
-	.fo_chmod = invfo_chmod,
-	.fo_chown = invfo_chown,
+	.fo_chmod = pipe_chmod,
+	.fo_chown = pipe_chown,
 	.fo_flags = DFLAG_PASSABLE
 };
 
 static void	filt_pipedetach(struct knote *kn);
+static void	filt_pipedetach_notsup(struct knote *kn);
+static int	filt_pipenotsup(struct knote *kn, long hint);
 static int	filt_piperead(struct knote *kn, long hint);
 static int	filt_pipewrite(struct knote *kn, long hint);
 
+static struct filterops pipe_nfiltops = {
+	.f_isfd = 1,
+	.f_detach = filt_pipedetach_notsup,
+	.f_event = filt_pipenotsup
+};
 static struct filterops pipe_rfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_pipedetach,
@@ -208,6 +223,7 @@
 static void pipeclose(struct pipe *cpipe);
 static void pipe_free_kmem(struct pipe *cpipe);
 static int pipe_create(struct pipe *pipe, int backing);
+static int pipe_paircreate(struct thread *td, struct pipepair **p_pp);
 static __inline int pipelock(struct pipe *cpipe, int catch);
 static __inline void pipeunlock(struct pipe *cpipe);
 static __inline void pipeselwakeup(struct pipe *cpipe);
@@ -317,20 +333,14 @@
 	mtx_destroy(&pp->pp_mtx);
 }
 
-/*
- * The pipe system call for the DTYPE_PIPE type of pipes.  If we fail, let
- * the zone pick up the pieces via pipeclose().
- */
-int
-kern_pipe(struct thread *td, int fildes[2])
+static int
+pipe_paircreate(struct thread *td, struct pipepair **p_pp)
 {
-	struct filedesc *fdp = td->td_proc->p_fd;
-	struct file *rf, *wf;
 	struct pipepair *pp;
 	struct pipe *rpipe, *wpipe;
-	int fd, error;
+	int error;
 
-	pp = uma_zalloc(pipe_zone, M_WAITOK);
+	*p_pp = pp = uma_zalloc(pipe_zone, M_WAITOK);
 #ifdef MAC
 	/*
 	 * The MAC label is shared between the connected endpoints.  As a
@@ -356,7 +366,59 @@
 
 	rpipe->pipe_state |= PIPE_DIRECTOK;
 	wpipe->pipe_state |= PIPE_DIRECTOK;
+	return (0);
+}
 
+int
+pipe_named_ctor(struct pipe **ppipe, struct thread *td)
+{
+	struct pipepair *pp;
+	int error;
+
+	error = pipe_paircreate(td, &pp);
+	if (error != 0)
+		return (error);
+	pp->pp_rpipe.pipe_state |= PIPE_NAMED;
+	*ppipe = &pp->pp_rpipe;
+	return (0);
+}
+
+void
+pipe_dtor(struct pipe *dpipe)
+{
+	ino_t ino;
+
+	ino = dpipe->pipe_ino;
+	funsetown(&dpipe->pipe_sigio);
+	pipeclose(dpipe);
+	if (dpipe->pipe_state & PIPE_NAMED) {
+		dpipe = dpipe->pipe_peer;
+		funsetown(&dpipe->pipe_sigio);
+		pipeclose(dpipe);
+	}
+	if (ino != 0 && ino != (ino_t)-1)
+		free_unr(pipeino_unr, ino);
+}
+
+/*
+ * The pipe system call for the DTYPE_PIPE type of pipes.  If we fail, let
+ * the zone pick up the pieces via pipeclose().
+ */
+int
+kern_pipe(struct thread *td, int fildes[2])
+{
+	struct filedesc *fdp; 
+	struct file *rf, *wf;
+	struct pipe *rpipe, *wpipe;
+	struct pipepair *pp;
+	int fd, error;
+
+	fdp = td->td_proc->p_fd;
+	error = pipe_paircreate(td, &pp);
+	if (error != 0)
+		return (error);
+	rpipe = &pp->pp_rpipe;
+	wpipe = &pp->pp_wpipe;
 	error = falloc(td, &rf, &fd, 0);
 	if (error) {
 		pipeclose(rpipe);
@@ -582,11 +644,12 @@
 	struct thread *td;
 	int flags;
 {
-	struct pipe *rpipe = fp->f_data;
+	struct pipe *rpipe;
 	int error;
 	int nread = 0;
 	u_int size;
 
+	rpipe = fp->f_data;
 	PIPE_LOCK(rpipe);
 	++rpipe->pipe_busy;
 	error = pipelock(rpipe, 1);
@@ -617,7 +680,7 @@
 			size = rpipe->pipe_buffer.size - rpipe->pipe_buffer.out;
 			if (size > rpipe->pipe_buffer.cnt)
 				size = rpipe->pipe_buffer.cnt;
-			if (size > (u_int) uio->uio_resid)
+			if (size > uio->uio_resid)
 				size = (u_int) uio->uio_resid;
 
 			PIPE_UNLOCK(rpipe);
@@ -650,7 +713,7 @@
 		 */
 		} else if ((size = rpipe->pipe_map.cnt) &&
 			   (rpipe->pipe_state & PIPE_DIRECTW)) {
-			if (size > (u_int) uio->uio_resid)
+			if (size > uio->uio_resid)
 				size = (u_int) uio->uio_resid;
 
 			PIPE_UNLOCK(rpipe);
@@ -764,9 +827,10 @@
 	KASSERT(wpipe->pipe_state & PIPE_DIRECTW,
 		("Clone attempt on non-direct write pipe!"));
 
-	size = (u_int) uio->uio_iov->iov_len;
-	if (size > wpipe->pipe_buffer.size)
-		size = wpipe->pipe_buffer.size;
+	if (uio->uio_iov->iov_len > wpipe->pipe_buffer.size)
+                size = wpipe->pipe_buffer.size;
+	else
+                size = uio->uio_iov->iov_len;
 
 	if ((i = vm_fault_quick_hold_pages(&curproc->p_vmspace->vm_map,
 	    (vm_offset_t)uio->uio_iov->iov_base, size, VM_PROT_READ,
@@ -959,13 +1023,12 @@
 	struct thread *td;
 	int flags;
 {
-	int error = 0;
-	int desiredsize, orig_resid;
+	int error;
+	size_t desiredsize, orig_resid;
 	struct pipe *wpipe, *rpipe;
 
 	rpipe = fp->f_data;
-	wpipe = rpipe->pipe_peer;
-
+	wpipe = PIPE_PEER(rpipe);
 	PIPE_LOCK(rpipe);
 	error = pipelock(wpipe, 1);
 	if (error) {
@@ -1242,6 +1305,9 @@
 	struct thread *td;
 {
 
+	/* For named pipes call the vnode operation. */
+	if (fp->f_vnode != NULL)
+		return (vnops.fo_truncate(fp, length, active_cred, td));
 	return (EINVAL);
 }
 
@@ -1284,6 +1350,11 @@
 		break;
 
 	case FIONREAD:
+		if (!(fp->f_flag & FREAD)) {
+			*(int *)data = 0;
+			PIPE_UNLOCK(mpipe);
+			return (0);
+		}
 		if (mpipe->pipe_state & PIPE_DIRECTW)
 			*(int *)data = mpipe->pipe_map.cnt;
 		else
@@ -1326,26 +1397,28 @@
 	struct ucred *active_cred;
 	struct thread *td;
 {
-	struct pipe *rpipe = fp->f_data;
+	struct pipe *rpipe;
 	struct pipe *wpipe;
-	int revents = 0;
+	int levents, revents;
 #ifdef MAC
 	int error;
 #endif
 
-	wpipe = rpipe->pipe_peer;
+	revents = 0;
+	rpipe = fp->f_data;
+	wpipe = PIPE_PEER(rpipe);
 	PIPE_LOCK(rpipe);
 #ifdef MAC
 	error = mac_pipe_check_poll(active_cred, rpipe->pipe_pair);
 	if (error)
 		goto locked_error;
 #endif
-	if (events & (POLLIN | POLLRDNORM))
+	if (fp->f_flag & FREAD && events & (POLLIN | POLLRDNORM))
 		if ((rpipe->pipe_state & PIPE_DIRECTW) ||
 		    (rpipe->pipe_buffer.cnt > 0))
 			revents |= events & (POLLIN | POLLRDNORM);
 
-	if (events & (POLLOUT | POLLWRNORM))
+	if (fp->f_flag & FWRITE && events & (POLLOUT | POLLWRNORM))
 		if (wpipe->pipe_present != PIPE_ACTIVE ||
 		    (wpipe->pipe_state & PIPE_EOF) ||
 		    (((wpipe->pipe_state & PIPE_DIRECTW) == 0) &&
@@ -1353,6 +1426,12 @@
 			 wpipe->pipe_buffer.size == 0)))
 			revents |= events & (POLLOUT | POLLWRNORM);
 
+	levents = events &
+	    (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | POLLRDBAND);
+	if (rpipe->pipe_state & PIPE_NAMED && fp->f_flag & FREAD && levents &&
+	    fifo_iseof(fp))
+		events |= POLLINIGNEOF;
+
 	if ((events & POLLINIGNEOF) == 0) {
 		if (rpipe->pipe_state & PIPE_EOF) {
 			revents |= (events & (POLLIN | POLLRDNORM));
@@ -1363,13 +1442,13 @@
 	}
 
 	if (revents == 0) {
-		if (events & (POLLIN | POLLRDNORM)) {
+		if (fp->f_flag & FREAD && events & (POLLIN | POLLRDNORM)) {
 			selrecord(td, &rpipe->pipe_sel);
 			if (SEL_WAITING(&rpipe->pipe_sel))
 				rpipe->pipe_state |= PIPE_SEL;
 		}
 
-		if (events & (POLLOUT | POLLWRNORM)) {
+		if (fp->f_flag & FWRITE && events & (POLLOUT | POLLWRNORM)) {
 			selrecord(td, &wpipe->pipe_sel);
 			if (SEL_WAITING(&wpipe->pipe_sel))
 				wpipe->pipe_state |= PIPE_SEL;
@@ -1409,6 +1488,13 @@
 		return (error);
 	}
 #endif
+
+	/* For named pipes ask the underlying filesystem. */
+	if (pipe->pipe_state & PIPE_NAMED) {
+		PIPE_UNLOCK(pipe);
+		return (vnops.fo_stat(fp, ub, active_cred, td));
+	}
+
 	/*
 	 * Lazily allocate an inode number for the pipe.  Most pipe
 	 * users do not call fstat(2) on the pipe, which means that
@@ -1455,15 +1541,48 @@
 	struct file *fp;
 	struct thread *td;
 {
-	struct pipe *cpipe = fp->f_data;
 
+	if (fp->f_vnode != NULL) 
+		return vnops.fo_close(fp, td);
 	fp->f_ops = &badfileops;
+	pipe_dtor(fp->f_data);
 	fp->f_data = NULL;
-	funsetown(&cpipe->pipe_sigio);
-	pipeclose(cpipe);
 	return (0);
 }
 
+static int
+pipe_chmod(struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
+{
+	struct pipe *cpipe;
+	int error;
+
+	cpipe = fp->f_data;
+	if (cpipe->pipe_state & PIPE_NAMED)
+		error = vn_chmod(fp, mode, active_cred, td);
+	else
+		error = invfo_chmod(fp, mode, active_cred, td);
+	return (error);
+}
+
+static int
+pipe_chown(fp, uid, gid, active_cred, td)
+	struct file *fp;
+	uid_t uid;
+	gid_t gid;
+	struct ucred *active_cred;
+	struct thread *td;
+{
+	struct pipe *cpipe;
+	int error;
+
+	cpipe = fp->f_data;
+	if (cpipe->pipe_state & PIPE_NAMED)
+		error = vn_chown(fp, uid, gid, active_cred, td);
+	else
+		error = invfo_chown(fp, uid, gid, active_cred, td);
+	return (error);
+}
+
 static void
 pipe_free_kmem(cpipe)
 	struct pipe *cpipe;
@@ -1497,7 +1616,6 @@
 {
 	struct pipepair *pp;
 	struct pipe *ppipe;
-	ino_t ino;
 
 	KASSERT(cpipe != NULL, ("pipeclose: cpipe == NULL"));
 
@@ -1556,12 +1674,6 @@
 	knlist_destroy(&cpipe->pipe_sel.si_note);
 
 	/*
-	 * Postpone the destroy of the fake inode number allocated for
-	 * our end, until pipe mtx is unlocked.
-	 */
-	ino = cpipe->pipe_ino;
-
-	/*
 	 * If both endpoints are now closed, release the memory for the
 	 * pipe pair.  If not, unlock.
 	 */
@@ -1573,9 +1685,6 @@
 		uma_zfree(pipe_zone, cpipe->pipe_pair);
 	} else
 		PIPE_UNLOCK(cpipe);
-
-	if (ino != 0 && ino != (ino_t)-1)
-		free_unr(pipeino_unr, ino);
 }
 
 /*ARGSUSED*/
@@ -1584,7 +1693,20 @@
 {
 	struct pipe *cpipe;
 
-	cpipe = kn->kn_fp->f_data;
+	/*
+	 * If a filter is requested that is not supported by this file
+	 * descriptor, don't return an error, but also don't ever generate an
+	 * event.
+	 */
+	if ((kn->kn_filter == EVFILT_READ) && !(fp->f_flag & FREAD)) {
+		kn->kn_fop = &pipe_nfiltops;
+		return (0);
+	}
+	if ((kn->kn_filter == EVFILT_WRITE) && !(fp->f_flag & FWRITE)) {
+		kn->kn_fop = &pipe_nfiltops;
+		return (0);
+	}
+	cpipe = fp->f_data;
 	PIPE_LOCK(cpipe);
 	switch (kn->kn_filter) {
 	case EVFILT_READ:
@@ -1597,13 +1719,14 @@
 			PIPE_UNLOCK(cpipe);
 			return (EPIPE);
 		}
-		cpipe = cpipe->pipe_peer;
+		cpipe = PIPE_PEER(cpipe);
 		break;
 	default:
 		PIPE_UNLOCK(cpipe);
 		return (EINVAL);
 	}
 
+	kn->kn_hook = cpipe; 
 	knlist_add(&cpipe->pipe_sel.si_note, kn, 1);
 	PIPE_UNLOCK(cpipe);
 	return (0);
@@ -1612,11 +1735,9 @@
 static void
 filt_pipedetach(struct knote *kn)
 {
-	struct pipe *cpipe = (struct pipe *)kn->kn_fp->f_data;
+	struct pipe *cpipe = kn->kn_hook;
 
 	PIPE_LOCK(cpipe);
-	if (kn->kn_filter == EVFILT_WRITE)
-		cpipe = cpipe->pipe_peer;
 	knlist_remove(&cpipe->pipe_sel.si_note, kn, 1);
 	PIPE_UNLOCK(cpipe);
 }
@@ -1625,7 +1746,7 @@
 static int
 filt_piperead(struct knote *kn, long hint)
 {
-	struct pipe *rpipe = kn->kn_fp->f_data;
+	struct pipe *rpipe = kn->kn_hook;
 	struct pipe *wpipe = rpipe->pipe_peer;
 	int ret;
 
@@ -1650,15 +1771,15 @@
 static int
 filt_pipewrite(struct knote *kn, long hint)
 {
-	struct pipe *rpipe = kn->kn_fp->f_data;
-	struct pipe *wpipe = rpipe->pipe_peer;
-
-	PIPE_LOCK(rpipe);
+	struct pipe *wpipe;
+   
+	wpipe = 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(rpipe);
+		PIPE_UNLOCK(wpipe);
 		return (1);
 	}
 	kn->kn_data = (wpipe->pipe_buffer.size > 0) ?
@@ -1666,6 +1787,19 @@
 	if (wpipe->pipe_state & PIPE_DIRECTW)
 		kn->kn_data = 0;
 
-	PIPE_UNLOCK(rpipe);
+	PIPE_UNLOCK(wpipe);
 	return (kn->kn_data >= PIPE_BUF);
 }
+
+static void
+filt_pipedetach_notsup(struct knote *kn)
+{
+
+}
+
+static int
+filt_pipenotsup(struct knote *kn, long hint)
+{
+
+	return (0);
+}
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/sys_process.c
--- a/head/sys/kern/sys_process.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/sys_process.c	Fri Mar 02 17:07:09 2012 +0200
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/sys_process.c 225617 2011-09-16 13:58:51Z kmacy $");
+__FBSDID("$FreeBSD: head/sys/kern/sys_process.c 232048 2012-02-23 11:50:23Z kib $");
 
 #include "opt_compat.h"
 
@@ -841,8 +841,6 @@
 		p->p_flag |= P_TRACED;
 		p->p_oppid = p->p_pptr->p_pid;
 		if (p->p_pptr != td->td_proc) {
-			/* Remember that a child is being debugged(traced). */
-			p->p_pptr->p_dbg_child++;
 			proc_reparent(p, td->td_proc);
 		}
 		data = SIGSTOP;
@@ -931,7 +929,6 @@
 					PROC_UNLOCK(pp);
 				PROC_LOCK(p);
 				proc_reparent(p, pp);
-				p->p_pptr->p_dbg_child--;
 				if (pp == initproc)
 					p->p_sigparent = SIGCHLD;
 			}
@@ -1145,6 +1142,8 @@
 			pl->pl_flags |= PL_FLAG_FORKED;
 			pl->pl_child_pid = td2->td_dbg_forked;
 		}
+		if (td2->td_dbgflags & TDB_CHILD)
+			pl->pl_flags |= PL_FLAG_CHILD;
 		pl->pl_sigmask = td2->td_sigmask;
 		pl->pl_siglist = td2->td_siglist;
 		strcpy(pl->pl_tdname, td2->td_name);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/sysv_shm.c
--- a/head/sys/kern/sysv_shm.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/sysv_shm.c	Fri Mar 02 17:07:09 2012 +0200
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/sysv_shm.c 225617 2011-09-16 13:58:51Z kmacy $");
+__FBSDID("$FreeBSD: head/sys/kern/sysv_shm.c 231904 2012-02-19 00:28:49Z alc $");
 
 #include "opt_compat.h"
 #include "opt_sysvipc.h"
@@ -413,14 +413,12 @@
 	vm_object_reference(shmseg->object);
 	rv = vm_map_find(&p->p_vmspace->vm_map, shmseg->object,
 	    0, &attach_va, size, (flags & MAP_FIXED) ? VMFS_NO_SPACE :
-	    VMFS_ANY_SPACE, prot, prot, 0);
+	    VMFS_ANY_SPACE, prot, prot, MAP_INHERIT_SHARE);
 	if (rv != KERN_SUCCESS) {
 		vm_object_deallocate(shmseg->object);
 		error = ENOMEM;
 		goto done2;
 	}
-	vm_map_inherit(&p->p_vmspace->vm_map,
-		attach_va, attach_va + size, VM_INHERIT_SHARE);
 
 	shmmap_s->va = attach_va;
 	shmmap_s->shmid = shmid;
@@ -891,14 +889,14 @@
 		printf("kern.ipc.shmmaxpgs is now called kern.ipc.shmall!\n");
 #endif
 	TUNABLE_ULONG_FETCH("kern.ipc.shmall", &shminfo.shmall);
-
-	/* Initialize shmmax dealing with possible overflow. */
-	for (i = PAGE_SIZE; i > 0; i--) {
-		shminfo.shmmax = shminfo.shmall * i;
-		if (shminfo.shmmax >= shminfo.shmall)
-			break;
+	if (!TUNABLE_ULONG_FETCH("kern.ipc.shmmax", &shminfo.shmmax)) {
+		/* Initialize shmmax dealing with possible overflow. */
+		for (i = PAGE_SIZE; i > 0; i--) {
+			shminfo.shmmax = shminfo.shmall * i;
+			if (shminfo.shmmax >= shminfo.shmall)
+				break;
+		}
 	}
-
 	TUNABLE_ULONG_FETCH("kern.ipc.shmmin", &shminfo.shmmin);
 	TUNABLE_ULONG_FETCH("kern.ipc.shmmni", &shminfo.shmmni);
 	TUNABLE_ULONG_FETCH("kern.ipc.shmseg", &shminfo.shmseg);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/tty.c
--- a/head/sys/kern/tty.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/tty.c	Fri Mar 02 17:07:09 2012 +0200
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/tty.c 225617 2011-09-16 13:58:51Z kmacy $");
+__FBSDID("$FreeBSD: head/sys/kern/tty.c 232197 2012-02-26 20:56:49Z phk $");
 
 #include "opt_capsicum.h"
 #include "opt_compat.h"
@@ -1229,7 +1229,7 @@
 
 		/* Slave call-out devices. */
 		if (tp->t_flags & TF_INITLOCK) {
-			dev = make_dev_cred(&ttyil_cdevsw, 
+			dev = make_dev_cred(&ttyil_cdevsw,
 			    TTYUNIT_CALLOUT | TTYUNIT_INIT, cred,
 			    UID_UUCP, GID_DIALER, 0660, "cua%s.init", name);
 			dev_depends(tp->t_dev, dev);
@@ -1481,6 +1481,8 @@
 		 */
 		if ((t->c_cflag & CIGNORE) == 0 &&
 		    (tp->t_termios.c_cflag != t->c_cflag ||
+		    ((tp->t_termios.c_iflag ^ t->c_iflag) &
+		    (IXON|IXOFF|IXANY)) ||
 		    tp->t_termios.c_ispeed != t->c_ispeed ||
 		    tp->t_termios.c_ospeed != t->c_ospeed)) {
 			error = ttydevsw_param(tp, t);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/tty_info.c
--- a/head/sys/kern/tty_info.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/tty_info.c	Fri Mar 02 17:07:09 2012 +0200
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/kern/tty_info.c 231095 2012-02-06 18:15:46Z ed $");
 
 #include <sys/param.h>
 #include <sys/lock.h>
@@ -109,7 +109,7 @@
 
 	/*
 	 * Fetch running stats, pctcpu usage, and interruptable flag.
- 	 */
+	 */
 	thread_lock(td);
 	runa = TD_IS_RUNNING(td) | TD_ON_RUNQ(td);
 	slpa = td->td_flags & TDF_SINTR;
@@ -173,7 +173,7 @@
 	PROC_LOCK(p2);
 	runb = proc_sum(p2, &estb);
 	PROC_UNLOCK(p2);
-	
+
 	/*
 	 * see if at least one of them is runnable
 	 */
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/tty_ttydisc.c
--- a/head/sys/kern/tty_ttydisc.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/tty_ttydisc.c	Fri Mar 02 17:07:09 2012 +0200
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/tty_ttydisc.c 223575 2011-06-26 18:26:20Z ed $");
+__FBSDID("$FreeBSD: head/sys/kern/tty_ttydisc.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include <sys/param.h>
 #include <sys/fcntl.h>
@@ -180,7 +180,7 @@
 ttydisc_read_raw_no_timer(struct tty *tp, struct uio *uio, int ioflag)
 {
 	size_t vmin = tp->t_termios.c_cc[VMIN];
-	int oresid = uio->uio_resid;
+	ssize_t oresid = uio->uio_resid;
 	int error;
 
 	MPASS(tp->t_termios.c_cc[VTIME] == 0);
@@ -265,7 +265,7 @@
 ttydisc_read_raw_interbyte_timer(struct tty *tp, struct uio *uio, int ioflag)
 {
 	size_t vmin = tp->t_termios.c_cc[VMIN];
-	int oresid = uio->uio_resid;
+	ssize_t oresid = uio->uio_resid;
 	int error;
 
 	MPASS(tp->t_termios.c_cc[VMIN] != 0);
@@ -661,7 +661,6 @@
 	return ttydisc_echo_force(tp, c, quote);
 }
 
-
 static void
 ttydisc_reprint_char(void *d, char c, int quote)
 {
@@ -1174,7 +1173,7 @@
 ttydisc_getc_uio(struct tty *tp, struct uio *uio)
 {
 	int error = 0;
-	int obytes = uio->uio_resid;
+	ssize_t obytes = uio->uio_resid;
 	size_t len;
 	char buf[TTY_STACKBUF];
 
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/uipc_domain.c
--- a/head/sys/kern/uipc_domain.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/uipc_domain.c	Fri Mar 02 17:07:09 2012 +0200
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/kern/uipc_domain.c 232051 2012-02-23 17:47:19Z brueffer $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -220,7 +220,7 @@
 	domains = dp;
 
 	KASSERT(domain_init_status >= 1,
-	    ("attempt to net_add_domain(%s) before domaininit()",
+	    ("attempt to domain_add(%s) before domaininit()",
 	    dp->dom_name));
 #ifndef INVARIANTS
 	if (domain_init_status < 1)
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/uipc_mbuf.c
--- a/head/sys/kern/uipc_mbuf.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/uipc_mbuf.c	Fri Mar 02 17:07:09 2012 +0200
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/uipc_mbuf.c 230587 2012-01-26 16:35:09Z ken $");
+__FBSDID("$FreeBSD: head/sys/kern/uipc_mbuf.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include "opt_param.h"
 #include "opt_mbuf_stress_test.h"
@@ -1726,7 +1726,8 @@
 m_uiotombuf(struct uio *uio, int how, int len, int align, int flags)
 {
 	struct mbuf *m, *mb;
-	int error, length, total;
+	int error, length;
+	ssize_t total;
 	int progress = 0;
 
 	/*
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/uipc_socket.c
--- a/head/sys/kern/uipc_socket.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/uipc_socket.c	Fri Mar 02 17:07:09 2012 +0200
@@ -101,7 +101,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 227503 2011-11-14 18:21:27Z rmh $");
+__FBSDID("$FreeBSD: head/sys/kern/uipc_socket.c 232179 2012-02-26 13:55:43Z kib $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -392,6 +392,7 @@
 	so->so_type = type;
 	so->so_cred = crhold(cred);
 	if ((prp->pr_domain->dom_family == PF_INET) ||
+	    (prp->pr_domain->dom_family == PF_INET6) ||
 	    (prp->pr_domain->dom_family == PF_ROUTE))
 		so->so_fibnum = td->td_proc->p_fibnum;
 	else
@@ -886,7 +887,8 @@
     int flags)
 {
 	struct mbuf *m, **mp, *top;
-	long len, resid;
+	long len;
+	ssize_t resid;
 	int error;
 #ifdef ZERO_COPY_SOCKETS
 	int cow_send;
@@ -986,7 +988,8 @@
 sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio,
     struct mbuf *top, struct mbuf *control, int flags, struct thread *td)
 {
-	long space, resid;
+	long space;
+	ssize_t resid;
 	int clen = 0, error, dontroute;
 #ifdef ZERO_COPY_SOCKETS
 	int atomic = sosendallatonce(so) || top;
@@ -1158,7 +1161,8 @@
 sosend_generic(struct socket *so, struct sockaddr *addr, struct uio *uio,
     struct mbuf *top, struct mbuf *control, int flags, struct thread *td)
 {
-	long space, resid;
+	long space;
+	ssize_t resid;
 	int clen = 0, error, dontroute;
 	int atomic = sosendallatonce(so) || top;
 
@@ -1455,11 +1459,12 @@
     struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
 {
 	struct mbuf *m, **mp;
-	int flags, len, error, offset;
+	int flags, error, offset;
+	ssize_t len;
 	struct protosw *pr = so->so_proto;
 	struct mbuf *nextrecord;
 	int moff, type = 0;
-	int orig_resid = uio->uio_resid;
+	ssize_t orig_resid = uio->uio_resid;
 
 	mp = mp0;
 	if (psa != NULL)
@@ -2118,7 +2123,8 @@
     struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
 {
 	struct mbuf *m, *m2;
-	int flags, len, error;
+	int flags, error;
+	ssize_t len;
 	struct protosw *pr = so->so_proto;
 	struct mbuf *nextrecord;
 
@@ -2441,7 +2447,7 @@
 	CURVNET_SET(so->so_vnet);
 	error = 0;
 	if (sopt->sopt_level != SOL_SOCKET) {
-		if (so->so_proto && so->so_proto->pr_ctloutput) {
+		if (so->so_proto->pr_ctloutput != NULL) {
 			error = (*so->so_proto->pr_ctloutput)(so, sopt);
 			CURVNET_RESTORE();
 			return (error);
@@ -2498,12 +2504,12 @@
 		case SO_SETFIB:
 			error = sooptcopyin(sopt, &optval, sizeof optval,
 					    sizeof optval);
-			if (optval < 0 || optval > rt_numfibs) {
+			if (optval < 0 || optval >= rt_numfibs) {
 				error = EINVAL;
 				goto bad;
 			}
-			if (so->so_proto != NULL &&
-			   ((so->so_proto->pr_domain->dom_family == PF_INET) ||
+			if (((so->so_proto->pr_domain->dom_family == PF_INET) ||
+			   (so->so_proto->pr_domain->dom_family == PF_INET6) ||
 			   (so->so_proto->pr_domain->dom_family == PF_ROUTE))) {
 				so->so_fibnum = optval;
 				/* Note: ignore error */
@@ -2634,11 +2640,8 @@
 			error = ENOPROTOOPT;
 			break;
 		}
-		if (error == 0 && so->so_proto != NULL &&
-		    so->so_proto->pr_ctloutput != NULL) {
-			(void) ((*so->so_proto->pr_ctloutput)
-				  (so, sopt));
-		}
+		if (error == 0 && so->so_proto->pr_ctloutput != NULL)
+			(void)(*so->so_proto->pr_ctloutput)(so, sopt);
 	}
 bad:
 	CURVNET_RESTORE();
@@ -2688,7 +2691,7 @@
 	CURVNET_SET(so->so_vnet);
 	error = 0;
 	if (sopt->sopt_level != SOL_SOCKET) {
-		if (so->so_proto && so->so_proto->pr_ctloutput)
+		if (so->so_proto->pr_ctloutput != NULL)
 			error = (*so->so_proto->pr_ctloutput)(so, sopt);
 		else
 			error = ENOPROTOOPT;
@@ -2730,6 +2733,10 @@
 			optval = so->so_type;
 			goto integer;
 
+		case SO_PROTOCOL:
+			optval = so->so_proto->pr_protocol;
+			goto integer;
+
 		case SO_ERROR:
 			SOCK_LOCK(so);
 			optval = so->so_error;
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/uipc_syscalls.c
--- a/head/sys/kern/uipc_syscalls.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/uipc_syscalls.c	Fri Mar 02 17:07:09 2012 +0200
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/uipc_syscalls.c 225617 2011-09-16 13:58:51Z kmacy $");
+__FBSDID("$FreeBSD: head/sys/kern/uipc_syscalls.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include "opt_capsicum.h"
 #include "opt_inet.h"
@@ -756,8 +756,8 @@
 	struct uio auio;
 	struct iovec *iov;
 	struct socket *so;
-	int i;
-	int len, error;
+	int i, error;
+	ssize_t len;
 	cap_rights_t rights;
 #ifdef KTRACE
 	struct uio *ktruio = NULL;
@@ -956,7 +956,7 @@
 	struct uio auio;
 	struct iovec *iov;
 	int i;
-	socklen_t len;
+	ssize_t len;
 	int error;
 	struct mbuf *m, *control = 0;
 	caddr_t ctlbuf;
@@ -1007,19 +1007,19 @@
 	    (mp->msg_control || controlp) ? &control : (struct mbuf **)0,
 	    &mp->msg_flags);
 	if (error) {
-		if (auio.uio_resid != (int)len && (error == ERESTART ||
+		if (auio.uio_resid != len && (error == ERESTART ||
 		    error == EINTR || error == EWOULDBLOCK))
 			error = 0;
 	}
 #ifdef KTRACE
 	if (ktruio != NULL) {
-		ktruio->uio_resid = (int)len - auio.uio_resid;
+		ktruio->uio_resid = len - auio.uio_resid;
 		ktrgenio(s, UIO_READ, ktruio, error);
 	}
 #endif
 	if (error)
 		goto out;
-	td->td_retval[0] = (int)len - auio.uio_resid;
+	td->td_retval[0] = len - auio.uio_resid;
 	if (mp->msg_name) {
 		len = mp->msg_namelen;
 		if (len <= 0 || fromsa == 0)
@@ -2086,7 +2086,8 @@
 			else if (uap->flags & SF_NODISKIO)
 				error = EBUSY;
 			else {
-				int bsize, resid;
+				int bsize;
+				ssize_t resid;
 
 				/*
 				 * Ensure that our page is still around
@@ -2510,7 +2511,8 @@
 	struct sctp_sndrcvinfo sinfo, *u_sinfo = NULL;
 	struct socket *so;
 	struct file *fp = NULL;
-	int error=0, len, i;
+	int error=0, i;
+	ssize_t len;
 	struct sockaddr *to = NULL;
 #ifdef KTRACE
 	struct uio *ktruio = NULL;
@@ -2637,7 +2639,8 @@
 	struct file *fp = NULL;
 	struct sockaddr *fromsa;
 	int fromlen;
-	int len, i, msg_flags;
+	ssize_t len;
+	int i, msg_flags;
 	int error = 0;
 #ifdef KTRACE
 	struct uio *ktruio = NULL;
@@ -2711,7 +2714,7 @@
 		    (struct sctp_sndrcvinfo *)&sinfo, 1);
 	CURVNET_RESTORE();
 	if (error) {
-		if (auio.uio_resid != (int)len && (error == ERESTART ||
+		if (auio.uio_resid != len && (error == ERESTART ||
 		    error == EINTR || error == EWOULDBLOCK))
 			error = 0;
 	} else {
@@ -2720,13 +2723,13 @@
 	}
 #ifdef KTRACE
 	if (ktruio != NULL) {
-		ktruio->uio_resid = (int)len - auio.uio_resid;
+		ktruio->uio_resid = len - auio.uio_resid;
 		ktrgenio(uap->sd, UIO_READ, ktruio, error);
 	}
 #endif /* KTRACE */
 	if (error)
 		goto out;
-	td->td_retval[0] = (int)len - auio.uio_resid;
+	td->td_retval[0] = len - auio.uio_resid;
 
 	if (fromlen && uap->from) {
 		len = fromlen;
@@ -2734,7 +2737,7 @@
 			len = 0;
 		else {
 			len = MIN(len, fromsa->sa_len);
-			error = copyout(fromsa, uap->from, (unsigned)len);
+			error = copyout(fromsa, uap->from, (size_t)len);
 			if (error)
 				goto out;
 		}
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/uipc_usrreq.c
--- a/head/sys/kern/uipc_usrreq.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/uipc_usrreq.c	Fri Mar 02 17:07:09 2012 +0200
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/uipc_usrreq.c 227309 2011-11-07 15:43:11Z ed $");
+__FBSDID("$FreeBSD: head/sys/kern/uipc_usrreq.c 232317 2012-02-29 21:38:31Z trociny $");
 
 #include "opt_ddb.h"
 
@@ -542,7 +542,7 @@
 
 	UNP_LINK_WLOCK();
 	UNP_PCB_LOCK(unp);
-	vp->v_socket = unp->unp_socket;
+	VOP_UNP_BIND(vp, unp->unp_socket);
 	unp->unp_vnode = vp;
 	unp->unp_addr = soun;
 	unp->unp_flags &= ~UNP_BINDING;
@@ -638,7 +638,7 @@
 	 * XXXRW: Should assert vp->v_socket == so.
 	 */
 	if ((vp = unp->unp_vnode) != NULL) {
-		unp->unp_vnode->v_socket = NULL;
+		VOP_UNP_DETACH(vp);
 		unp->unp_vnode = NULL;
 	}
 	unp2 = unp->unp_conn;
@@ -1273,8 +1273,8 @@
 	UNP_PCB_UNLOCK(unp);
 
 	sa = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK);
-	NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | LOCKLEAF, UIO_SYSSPACE, buf,
-	    td);
+	NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | LOCKSHARED | LOCKLEAF,
+	    UIO_SYSSPACE, buf, td);
 	error = namei(&nd);
 	if (error)
 		vp = NULL;
@@ -1308,7 +1308,7 @@
 	 * and to protect simultaneous locking of multiple pcbs.
 	 */
 	UNP_LINK_WLOCK();
-	so2 = vp->v_socket;
+	VOP_UNP_CONNECT(vp, &so2);
 	if (so2 == NULL) {
 		error = ECONNREFUSED;
 		goto bad2;
@@ -2300,6 +2300,43 @@
 	}
 }
 
+/*
+ * A helper function called by VFS before socket-type vnode reclamation.
+ * For an active vnode it clears unp_vnode pointer and decrements unp_vnode
+ * use count.
+ */
+void
+vfs_unp_reclaim(struct vnode *vp)
+{
+	struct socket *so;
+	struct unpcb *unp;
+	int active;
+
+	ASSERT_VOP_ELOCKED(vp, "vfs_unp_reclaim");
+	KASSERT(vp->v_type == VSOCK,
+	    ("vfs_unp_reclaim: vp->v_type != VSOCK"));
+
+	active = 0;
+	UNP_LINK_WLOCK();
+	VOP_UNP_CONNECT(vp, &so);
+	if (so == NULL)
+		goto done;
+	unp = sotounpcb(so);
+	if (unp == NULL)
+		goto done;
+	UNP_PCB_LOCK(unp);
+	if (unp->unp_vnode == vp) {
+		VOP_UNP_DETACH(vp);
+		unp->unp_vnode = NULL;
+		active = 1;
+	}
+	UNP_PCB_UNLOCK(unp);
+done:
+	UNP_LINK_WUNLOCK();
+	if (active)
+		vunref(vp);
+}
+
 #ifdef DDB
 static void
 db_print_indent(int indent)
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_aio.c
--- a/head/sys/kern/vfs_aio.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_aio.c	Fri Mar 02 17:07:09 2012 +0200
@@ -19,7 +19,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_aio.c 230857 2012-02-01 02:53:06Z davidxu $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_aio.c 231006 2012-02-05 04:49:31Z davidxu $");
 
 #include "opt_compat.h"
 
@@ -2706,6 +2706,7 @@
 		break;
 	case SIGEV_KEVENT:
 		CP(*sig32, *sig, sigev_notify_kqueue);
+		CP(*sig32, *sig, sigev_notify_kevent_flags);
 		PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
 		break;
 	default:
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_bio.c
--- a/head/sys/kern/vfs_bio.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_bio.c	Fri Mar 02 17:07:09 2012 +0200
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_bio.c 228156 2011-11-30 17:39:00Z kib $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_bio.c 232351 2012-03-01 18:45:25Z mckusick $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -782,21 +782,6 @@
 	}
 }
 
-
-/*
- * Get a buffer with the specified data.  Look in the cache first.  We
- * must clear BIO_ERROR and B_INVAL prior to initiating I/O.  If B_CACHE
- * is set, the buffer is valid and we do not have to do anything ( see
- * getblk() ).  This is really just a special case of breadn().
- */
-int
-bread(struct vnode * vp, daddr_t blkno, int size, struct ucred * cred,
-    struct buf **bpp)
-{
-
-	return (breadn(vp, blkno, size, 0, 0, 0, cred, bpp));
-}
-
 /*
  * Attempt to initiate asynchronous I/O on read-ahead blocks.  We must
  * clear BIO_ERROR and B_INVAL prior to initiating I/O . If B_CACHE is set,
@@ -834,19 +819,28 @@
 }
 
 /*
- * Operates like bread, but also starts asynchronous I/O on
- * read-ahead blocks.
+ * Entry point for bread() and breadn() via #defines in sys/buf.h.
+ *
+ * Get a buffer with the specified data.  Look in the cache first.  We
+ * must clear BIO_ERROR and B_INVAL prior to initiating I/O.  If B_CACHE
+ * is set, the buffer is valid and we do not have to do anything, see
+ * getblk(). Also starts asynchronous I/O on read-ahead blocks.
  */
 int
-breadn(struct vnode * vp, daddr_t blkno, int size,
-    daddr_t * rablkno, int *rabsize,
-    int cnt, struct ucred * cred, struct buf **bpp)
+breadn_flags(struct vnode * vp, daddr_t blkno, int size,
+    daddr_t * rablkno, int *rabsize, int cnt,
+    struct ucred * cred, int flags, struct buf **bpp)
 {
 	struct buf *bp;
 	int rv = 0, readwait = 0;
 
 	CTR3(KTR_BUF, "breadn(%p, %jd, %d)", vp, blkno, size);
-	*bpp = bp = getblk(vp, blkno, size, 0, 0, 0);
+	/*
+	 * Can only return NULL if GB_LOCK_NOWAIT flag is specified.
+	 */
+	*bpp = bp = getblk(vp, blkno, size, 0, 0, flags);
+	if (bp == NULL)
+		return (EBUSY);
 
 	/* if not found in cache, do some I/O */
 	if ((bp->b_flags & B_CACHE) == 0) {
@@ -3062,7 +3056,7 @@
 
 				/*
 				 * We must allocate system pages since blocking
-				 * here could intefere with paging I/O, no
+				 * here could interfere with paging I/O, no
 				 * matter which process we are.
 				 *
 				 * We can only test VPO_BUSY here.  Blocking on
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_cache.c
--- a/head/sys/kern/vfs_cache.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_cache.c	Fri Mar 02 17:07:09 2012 +0200
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_cache.c 230552 2012-01-25 20:48:20Z kib $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_cache.c 232156 2012-02-25 12:06:40Z maxim $");
 
 #include "opt_kdtrace.h"
 #include "opt_ktrace.h"
@@ -369,7 +369,7 @@
 			maxlength = count;
 	}
 	n_nchash = nchash + 1;
-	pct = (used * 100 * 100) / n_nchash;
+	pct = (used * 100) / (n_nchash / 100);
 	error = SYSCTL_OUT(req, &n_nchash, sizeof(n_nchash));
 	if (error)
 		return (error);
@@ -386,7 +386,7 @@
 }
 SYSCTL_PROC(_debug_hashstat, OID_AUTO, nchash, CTLTYPE_INT|CTLFLAG_RD|
     CTLFLAG_MPSAFE, 0, 0, sysctl_debug_hashstat_nchash, "I",
-    "nchash chain lengths");
+    "nchash statistics (number of total/used buckets, maximum chain length, usage percentage)");
 #endif
 
 /*
@@ -456,7 +456,7 @@
  */
 
 int
-cache_lookup_times(dvp, vpp, cnp, tsp, ticksp)
+cache_lookup(dvp, vpp, cnp, tsp, ticksp)
 	struct vnode *dvp;
 	struct vnode **vpp;
 	struct componentname *cnp;
@@ -994,7 +994,7 @@
 	if (error)
 		return (error);
 
-	error = cache_lookup(dvp, vpp, cnp);
+	error = cache_lookup(dvp, vpp, cnp, NULL, NULL);
 	if (error == 0)
 		return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
 	if (error == -1)
@@ -1374,12 +1374,9 @@
 
 /* ABI compat shims for old kernel modules. */
 #undef cache_enter
-#undef cache_lookup
 
 void	cache_enter(struct vnode *dvp, struct vnode *vp,
 	    struct componentname *cnp);
-int	cache_lookup(struct vnode *dvp, struct vnode **vpp,
-	    struct componentname *cnp);
 
 void
 cache_enter(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
@@ -1388,13 +1385,6 @@
 	cache_enter_time(dvp, vp, cnp, NULL);
 }
 
-int
-cache_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
-{
-
-	return (cache_lookup_times(dvp, vpp, cnp, NULL, NULL));
-}
-
 /*
  * This function updates path string to vnode's full global path
  * and checks the size of the new path string against the pathlen argument.
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_cluster.c
--- a/head/sys/kern/vfs_cluster.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_cluster.c	Fri Mar 02 17:07:09 2012 +0200
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_cluster.c 231204 2012-02-08 15:07:19Z kib $");
 
 #include "opt_debug_cluster.h"
 
@@ -604,7 +604,7 @@
 	int async;
 
 	if (vp->v_type == VREG) {
-		async = vp->v_mount->mnt_kern_flag & MNTK_ASYNC;
+		async = DOINGASYNC(vp);
 		lblocksize = vp->v_mount->mnt_stat.f_iosize;
 	} else {
 		async = 0;
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_default.c
--- a/head/sys/kern/vfs_default.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_default.c	Fri Mar 02 17:07:09 2012 +0200
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_default.c 227697 2011-11-19 07:50:49Z kib $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_default.c 232317 2012-02-29 21:38:31Z trociny $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -123,6 +123,9 @@
 	.vop_unlock =		vop_stdunlock,
 	.vop_vptocnp =		vop_stdvptocnp,
 	.vop_vptofh =		vop_stdvptofh,
+	.vop_unp_bind =		vop_stdunp_bind,
+	.vop_unp_connect =	vop_stdunp_connect,
+	.vop_unp_detach =	vop_stdunp_detach,
 };
 
 /*
@@ -1037,6 +1040,30 @@
 	return (error);
 }
 
+int
+vop_stdunp_bind(struct vop_unp_bind_args *ap)
+{
+
+	ap->a_vp->v_socket = ap->a_socket;
+	return (0);
+}
+
+int
+vop_stdunp_connect(struct vop_unp_connect_args *ap)
+{
+
+	*ap->a_socket = ap->a_vp->v_socket;
+	return (0);
+}
+
+int
+vop_stdunp_detach(struct vop_unp_detach_args *ap)
+{
+
+	ap->a_vp->v_socket = NULL;
+	return (0);
+}
+
 /*
  * vfs default ops
  * used to fill the vfs function table to get reasonable default return values.
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_extattr.c
--- a/head/sys/kern/vfs_extattr.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_extattr.c	Fri Mar 02 17:07:09 2012 +0200
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_extattr.c 225617 2011-09-16 13:58:51Z kmacy $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_extattr.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -181,7 +181,7 @@
 	auio.uio_iov = &aiov;
 	auio.uio_iovcnt = 1;
 	auio.uio_offset = 0;
-	if (nbytes > INT_MAX) {
+	if (nbytes > IOSIZE_MAX) {
 		error = EINVAL;
 		goto done;
 	}
@@ -355,7 +355,7 @@
 		auio.uio_iov = &aiov;
 		auio.uio_iovcnt = 1;
 		auio.uio_offset = 0;
-		if (nbytes > INT_MAX) {
+		if (nbytes > IOSIZE_MAX) {
 			error = EINVAL;
 			goto done;
 		}
@@ -672,7 +672,7 @@
 		auio.uio_iov = &aiov;
 		auio.uio_iovcnt = 1;
 		auio.uio_offset = 0;
-		if (nbytes > INT_MAX) {
+		if (nbytes > IOSIZE_MAX) {
 			error = EINVAL;
 			goto done;
 		}
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_mount.c
--- a/head/sys/kern/vfs_mount.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_mount.c	Fri Mar 02 17:07:09 2012 +0200
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_mount.c 230249 2012-01-17 01:08:01Z mckusick $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_mount.c 231012 2012-02-05 10:59:50Z mm $");
 
 #include "opt_vfs_allow_nonmpsafe.h"
 
@@ -1039,6 +1039,7 @@
 	struct vfsconf *vfsp;
 	struct nameidata nd;
 	struct vnode *vp;
+	char *pathbuf;
 	int error;
 
 	/*
@@ -1102,12 +1103,15 @@
 	NDFREE(&nd, NDF_ONLY_PNBUF);
 	vp = nd.ni_vp;
 	if ((fsflags & MNT_UPDATE) == 0) {
-		error = vn_path_to_global_path(td, vp, fspath, MNAMELEN);
+		pathbuf = malloc(MNAMELEN, M_TEMP, M_WAITOK);
+		strcpy(pathbuf, fspath);
+		error = vn_path_to_global_path(td, vp, pathbuf, MNAMELEN);
 		/* debug.disablefullpath == 1 results in ENODEV */
 		if (error == 0 || error == ENODEV) {
-			error = vfs_domount_first(td, vfsp, fspath, vp,
+			error = vfs_domount_first(td, vfsp, pathbuf, vp,
 			    fsflags, optlist);
 		}
+		free(pathbuf, M_TEMP);
 	} else
 		error = vfs_domount_update(td, vp, fsflags, optlist);
 	mtx_unlock(&Giant);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_mountroot.c
--- a/head/sys/kern/vfs_mountroot.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_mountroot.c	Fri Mar 02 17:07:09 2012 +0200
@@ -38,7 +38,7 @@
 #include "opt_rootdevname.h"
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_mountroot.c 228634 2011-12-17 15:26:34Z avg $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_mountroot.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -871,9 +871,8 @@
 	static char buf[128];
 	struct nameidata nd;
 	off_t ofs;
-	int error, flags;
-	int len, resid;
-	int vfslocked;
+	ssize_t resid;
+	int error, flags, len, vfslocked;
 
 	NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE,
 	    "/.mount.conf", td);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_subr.c
--- a/head/sys/kern/vfs_subr.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_subr.c	Fri Mar 02 17:07:09 2012 +0200
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_subr.c 230553 2012-01-25 20:54:09Z kib $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_subr.c 232152 2012-02-25 10:15:41Z trociny $");
 
 #include "opt_ddb.h"
 #include "opt_watchdog.h"
@@ -2657,6 +2657,8 @@
 			vinactive(vp, td);
 		VI_UNLOCK(vp);
 	}
+	if (vp->v_type == VSOCK)
+		vfs_unp_reclaim(vp);
 	/*
 	 * Reclaim the vnode.
 	 */
@@ -3521,7 +3523,7 @@
 {
 	struct vnode *syncvp = ap->a_vp;
 	struct mount *mp = syncvp->v_mount;
-	int error;
+	int error, save;
 	struct bufobj *bo;
 
 	/*
@@ -3551,17 +3553,10 @@
 		vfs_unbusy(mp);
 		return (0);
 	}
-	MNT_ILOCK(mp);
-	mp->mnt_noasync++;
-	mp->mnt_kern_flag &= ~MNTK_ASYNC;
-	MNT_IUNLOCK(mp);
+	save = curthread_pflags_set(TDP_SYNCIO);
 	vfs_msync(mp, MNT_NOWAIT);
 	error = VFS_SYNC(mp, MNT_LAZY);
-	MNT_ILOCK(mp);
-	mp->mnt_noasync--;
-	if ((mp->mnt_flag & MNT_ASYNC) != 0 && mp->mnt_noasync == 0)
-		mp->mnt_kern_flag |= MNTK_ASYNC;
-	MNT_IUNLOCK(mp);
+	curthread_pflags_restore(save);
 	vn_finished_write(mp);
 	vfs_unbusy(mp);
 	return (error);
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_syscalls.c
--- a/head/sys/kern/vfs_syscalls.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_syscalls.c	Fri Mar 02 17:07:09 2012 +0200
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_syscalls.c 229828 2012-01-08 23:06:53Z kib $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_syscalls.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include "opt_capsicum.h"
 #include "opt_compat.h"
@@ -134,7 +134,7 @@
 	struct sync_args *uap;
 {
 	struct mount *mp, *nmp;
-	int vfslocked;
+	int save, vfslocked;
 
 	mtx_lock(&mountlist_mtx);
 	for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
@@ -145,18 +145,10 @@
 		vfslocked = VFS_LOCK_GIANT(mp);
 		if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
 		    vn_start_write(NULL, &mp, V_NOWAIT) == 0) {
-			MNT_ILOCK(mp);
-			mp->mnt_noasync++;
-			mp->mnt_kern_flag &= ~MNTK_ASYNC;
-			MNT_IUNLOCK(mp);
+			save = curthread_pflags_set(TDP_SYNCIO);
 			vfs_msync(mp, MNT_NOWAIT);
 			VFS_SYNC(mp, MNT_NOWAIT);
-			MNT_ILOCK(mp);
-			mp->mnt_noasync--;
-			if ((mp->mnt_flag & MNT_ASYNC) != 0 &&
-			    mp->mnt_noasync == 0)
-				mp->mnt_kern_flag |= MNTK_ASYNC;
-			MNT_IUNLOCK(mp);
+			curthread_pflags_restore(save);
 			vn_finished_write(mp);
 		}
 		VFS_UNLOCK_GIANT(vfslocked);
@@ -2700,7 +2692,7 @@
 	struct nameidata nd;
 	int vfslocked;
 
-	if (count > INT_MAX)
+	if (count > IOSIZE_MAX)
 		return (EINVAL);
 
 	NDINIT_AT(&nd, LOOKUP, NOFOLLOW | LOCKSHARED | LOCKLEAF | MPSAFE |
@@ -4161,7 +4153,8 @@
 	int error, eofflag;
 
 	AUDIT_ARG_FD(fd);
-	if (count > INT_MAX)
+	auio.uio_resid = count;
+	if (auio.uio_resid > IOSIZE_MAX)
 		return (EINVAL);
 	if ((error = getvnode(td->td_proc->p_fd, fd, CAP_READ | CAP_SEEK,
 	    &fp)) != 0)
@@ -4185,7 +4178,6 @@
 	auio.uio_rw = UIO_READ;
 	auio.uio_segflg = UIO_USERSPACE;
 	auio.uio_td = td;
-	auio.uio_resid = count;
 	vn_lock(vp, LK_SHARED | LK_RETRY);
 	AUDIT_ARG_VNODE1(vp);
 	loff = auio.uio_offset = fp->f_offset;
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vfs_vnops.c
--- a/head/sys/kern/vfs_vnops.c	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vfs_vnops.c	Fri Mar 02 17:07:09 2012 +0200
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_vnops.c 230782 2012-01-30 19:35:15Z jhb $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_vnops.c 231949 2012-02-21 01:05:12Z kib $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -373,7 +373,7 @@
 	int ioflg;
 	struct ucred *active_cred;
 	struct ucred *file_cred;
-	int *aresid;
+	ssize_t *aresid;
 	struct thread *td;
 {
 	struct uio auio;
@@ -470,7 +470,7 @@
 	struct thread *td;
 {
 	int error = 0;
-	int iaresid;
+	ssize_t iaresid;
 
 	VFS_ASSERT_GIANT(vp->v_mount);
 
diff -r 5e8cf18319c3 -r fc6cfb0dbf30 head/sys/kern/vnode_if.src
--- a/head/sys/kern/vnode_if.src	Fri Mar 02 17:06:43 2012 +0200
+++ b/head/sys/kern/vnode_if.src	Fri Mar 02 17:07:09 2012 +0200
@@ -27,7 +27,7 @@
 # SUCH DAMAGE.
 #
 #	@(#)vnode_if.src	8.12 (Berkeley) 5/14/95
-# $FreeBSD: head/sys/kern/vnode_if.src 229728 2012-01-06 20:06:45Z jhb $
+# $FreeBSD: head/sys/kern/vnode_if.src 232317 2012-02-29 21:38:31Z trociny $
 #
 
 #
@@ -640,6 +640,26 @@
 	IN int advice;
 };
 
+%% unp_bind	vp	E E E
+
+vop_unp_bind {
+	IN struct vnode *vp;
+	IN struct socket *socket;
+};
+
+%% unp_connect	vp	L L L
+
+vop_unp_connect {
+	IN struct vnode *vp;
+	OUT struct socket **socket;
+};
+
+%% unp_detach	vp	= = =
+
+vop_unp_detach {
+	IN struct vnode *vp;
+};
+
 # The VOPs below are spares at the end of the table to allow new VOPs to be
 # added in stable branches without breaking the KBI.  New VOPs in HEAD should
 # be added above these spares.  When merging a new VOP to a stable branch,


More information about the Zrouter-src-freebsd mailing list