From owner-svn-src-stable-10@freebsd.org Sun Sep 6 09:41:09 2015 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8F73B9CB1D5; Sun, 6 Sep 2015 09:41:09 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7C2251054; Sun, 6 Sep 2015 09:41:09 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t869f9qs063937; Sun, 6 Sep 2015 09:41:09 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t869f90O063936; Sun, 6 Sep 2015 09:41:09 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201509060941.t869f90O063936@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sun, 6 Sep 2015 09:41:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287498 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Sep 2015 09:41:09 -0000 Author: mav Date: Sun Sep 6 09:41:08 2015 New Revision: 287498 URL: https://svnweb.freebsd.org/changeset/base/287498 Log: MFC r287432: Fix copy-paste bug introduced in r275458. Modified: stable/10/sys/cam/ctl/ctl.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl.c ============================================================================== --- stable/10/sys/cam/ctl/ctl.c Sun Sep 6 05:50:51 2015 (r287497) +++ stable/10/sys/cam/ctl/ctl.c Sun Sep 6 09:41:08 2015 (r287498) @@ -9473,7 +9473,7 @@ ctl_report_luns(struct ctl_scsiio *ctsio */ if (request_lun != NULL) { mtx_lock(&lun->lun_lock); - ctl_clr_ua(lun, initidx, CTL_UA_RES_RELEASE); + ctl_clr_ua(lun, initidx, CTL_UA_LUN_CHANGE); mtx_unlock(&lun->lun_lock); } } From owner-svn-src-stable-10@freebsd.org Sun Sep 6 17:32:35 2015 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2D71B9CB27D; Sun, 6 Sep 2015 17:32:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 19FA0145D; Sun, 6 Sep 2015 17:32:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t86HWYha058474; Sun, 6 Sep 2015 17:32:34 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t86HWYP6058471; Sun, 6 Sep 2015 17:32:34 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201509061732.t86HWYP6058471@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 6 Sep 2015 17:32:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287507 - in stable/10/sys: kern sys X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Sep 2015 17:32:35 -0000 Author: kib Date: Sun Sep 6 17:32:33 2015 New Revision: 287507 URL: https://svnweb.freebsd.org/changeset/base/287507 Log: MFC r287309: Remove single-use macros obfuscating malloc(9) and free(9) calls. Style. Modified: stable/10/sys/kern/ksched.c stable/10/sys/sys/posix4.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/ksched.c ============================================================================== --- stable/10/sys/kern/ksched.c Sun Sep 6 16:17:14 2015 (r287506) +++ stable/10/sys/kern/ksched.c Sun Sep 6 17:32:33 2015 (r287507) @@ -30,8 +30,7 @@ * SUCH DAMAGE. */ -/* ksched: Soft real time scheduling based on "rtprio". - */ +/* ksched: Soft real time scheduling based on "rtprio". */ #include __FBSDID("$FreeBSD$"); @@ -51,8 +50,7 @@ __FBSDID("$FreeBSD$"); FEATURE(kposix_priority_scheduling, "POSIX P1003.1B realtime extensions"); -/* ksched: Real-time extension to support POSIX priority scheduling. - */ +/* ksched: Real-time extension to support POSIX priority scheduling. */ struct ksched { struct timespec rr_interval; @@ -61,21 +59,21 @@ struct ksched { int ksched_attach(struct ksched **p) { - struct ksched *ksched= p31b_malloc(sizeof(*ksched)); + struct ksched *ksched; + ksched = malloc(sizeof(*ksched), M_P31B, M_WAITOK); ksched->rr_interval.tv_sec = 0; ksched->rr_interval.tv_nsec = 1000000000L / hz * sched_rr_interval(); - *p = ksched; - return 0; + return (0); } int ksched_detach(struct ksched *ks) { - p31b_free(ks); - return 0; + free(ks, M_P31B); + return (0); } /* @@ -108,47 +106,39 @@ static __inline int getscheduler(struct ksched *ksched, struct thread *td, int *policy) { struct rtprio rtp; - int e = 0; + int e; + e = 0; pri_to_rtp(td, &rtp); - switch (rtp.type) - { - case RTP_PRIO_FIFO: + switch (rtp.type) { + case RTP_PRIO_FIFO: *policy = SCHED_FIFO; break; - - case RTP_PRIO_REALTIME: + case RTP_PRIO_REALTIME: *policy = SCHED_RR; break; - - default: + default: *policy = SCHED_OTHER; break; } - - return e; + return (e); } int ksched_setparam(struct ksched *ksched, struct thread *td, const struct sched_param *param) { - int policy; - int e; + int e, policy; e = getscheduler(ksched, td, &policy); - if (e == 0) - { - e = ksched_setscheduler(ksched, td, policy, param); - } - - return e; + e = ksched_setscheduler(ksched, td, policy, param); + return (e); } int -ksched_getparam(struct ksched *ksched, - struct thread *td, struct sched_param *param) +ksched_getparam(struct ksched *ksched, struct thread *td, + struct sched_param *param) { struct rtprio rtp; @@ -159,13 +149,14 @@ ksched_getparam(struct ksched *ksched, if (PRI_MIN_TIMESHARE < rtp.prio) /* * The interactive score has it to min realtime - * so we must show max (64 most likely + * so we must show max (64 most likely). */ - param->sched_priority = (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE); + param->sched_priority = PRI_MAX_TIMESHARE - + PRI_MIN_TIMESHARE; else param->sched_priority = tsprio_to_p4prio(rtp.prio); } - return 0; + return (0); } /* @@ -176,117 +167,106 @@ ksched_getparam(struct ksched *ksched, * */ int -ksched_setscheduler(struct ksched *ksched, - struct thread *td, int policy, const struct sched_param *param) +ksched_setscheduler(struct ksched *ksched, struct thread *td, int policy, + const struct sched_param *param) { - int e = 0; struct rtprio rtp; + int e; - switch(policy) - { - case SCHED_RR: - case SCHED_FIFO: - + e = 0; + switch(policy) { + case SCHED_RR: + case SCHED_FIFO: if (param->sched_priority >= P1B_PRIO_MIN && - param->sched_priority <= P1B_PRIO_MAX) - { + param->sched_priority <= P1B_PRIO_MAX) { rtp.prio = p4prio_to_rtpprio(param->sched_priority); - rtp.type = (policy == SCHED_FIFO) - ? RTP_PRIO_FIFO : RTP_PRIO_REALTIME; - + rtp.type = (policy == SCHED_FIFO) ? RTP_PRIO_FIFO : + RTP_PRIO_REALTIME; rtp_to_pri(&rtp, td); - } - else + } else { e = EPERM; - - + } break; - - case SCHED_OTHER: - if (param->sched_priority >= 0 && - param->sched_priority <= (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE)) { + case SCHED_OTHER: + if (param->sched_priority >= 0 && param->sched_priority <= + (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE)) { rtp.type = RTP_PRIO_NORMAL; rtp.prio = p4prio_to_tsprio(param->sched_priority); rtp_to_pri(&rtp, td); - } else + } else { e = EINVAL; - + } + break; + default: + e = EINVAL; break; - - default: - e = EINVAL; - break; } - - return e; + return (e); } int ksched_getscheduler(struct ksched *ksched, struct thread *td, int *policy) { - return getscheduler(ksched, td, policy); + + return (getscheduler(ksched, td, policy)); } -/* ksched_yield: Yield the CPU. - */ +/* ksched_yield: Yield the CPU. */ int ksched_yield(struct ksched *ksched) { + sched_relinquish(curthread); - return 0; + return (0); } int ksched_get_priority_max(struct ksched *ksched, int policy, int *prio) { - int e = 0; + int e; - switch (policy) - { - case SCHED_FIFO: - case SCHED_RR: + e = 0; + switch (policy) { + case SCHED_FIFO: + case SCHED_RR: *prio = RTP_PRIO_MAX; break; - - case SCHED_OTHER: + case SCHED_OTHER: *prio = PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE; break; - - default: + default: e = EINVAL; + break; } - - return e; + return (e); } int ksched_get_priority_min(struct ksched *ksched, int policy, int *prio) { - int e = 0; + int e; - switch (policy) - { - case SCHED_FIFO: - case SCHED_RR: + e = 0; + switch (policy) { + case SCHED_FIFO: + case SCHED_RR: *prio = P1B_PRIO_MIN; break; - - case SCHED_OTHER: + case SCHED_OTHER: *prio = 0; break; - - default: + default: e = EINVAL; + break; } - - return e; + return (e); } int -ksched_rr_get_interval(struct ksched *ksched, - struct thread *td, struct timespec *timespec) +ksched_rr_get_interval(struct ksched *ksched, struct thread *td, + struct timespec *timespec) { - *timespec = ksched->rr_interval; - return 0; + *timespec = ksched->rr_interval; + return (0); } Modified: stable/10/sys/sys/posix4.h ============================================================================== --- stable/10/sys/sys/posix4.h Sun Sep 6 16:17:14 2015 (r287506) +++ stable/10/sys/sys/posix4.h Sun Sep 6 17:32:33 2015 (r287507) @@ -56,9 +56,6 @@ int sys_ ## SC (struct thread *td, struc MALLOC_DECLARE(M_P31B); -#define p31b_malloc(SIZE) malloc((SIZE), M_P31B, M_WAITOK) -#define p31b_free(P) free((P), M_P31B) - int p31b_proc(struct proc *, pid_t, struct proc **); void p31b_setcfg(int, int); From owner-svn-src-stable-10@freebsd.org Sun Sep 6 17:36:10 2015 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 403BE9CB455; Sun, 6 Sep 2015 17:36:10 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3056017A6; Sun, 6 Sep 2015 17:36:10 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t86HaApX058708; Sun, 6 Sep 2015 17:36:10 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t86HaAtA058707; Sun, 6 Sep 2015 17:36:10 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201509061736.t86HaAtA058707@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 6 Sep 2015 17:36:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287508 - stable/10/sys/kern X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Sep 2015 17:36:10 -0000 Author: kib Date: Sun Sep 6 17:36:09 2015 New Revision: 287508 URL: https://svnweb.freebsd.org/changeset/base/287508 Log: MFC r287310: Use P1B_PRIO_MAX to designate max posix priority for the RR/FIFO scheduler types. Modified: stable/10/sys/kern/ksched.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/ksched.c ============================================================================== --- stable/10/sys/kern/ksched.c Sun Sep 6 17:32:33 2015 (r287507) +++ stable/10/sys/kern/ksched.c Sun Sep 6 17:36:09 2015 (r287508) @@ -229,7 +229,7 @@ ksched_get_priority_max(struct ksched *k switch (policy) { case SCHED_FIFO: case SCHED_RR: - *prio = RTP_PRIO_MAX; + *prio = P1B_PRIO_MAX; break; case SCHED_OTHER: *prio = PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE; From owner-svn-src-stable-10@freebsd.org Tue Sep 8 00:34:39 2015 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 048B39CBA64; Tue, 8 Sep 2015 00:34:39 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E8DBE1639; Tue, 8 Sep 2015 00:34:38 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t880Ycuc068764; Tue, 8 Sep 2015 00:34:38 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t880Ycmp068763; Tue, 8 Sep 2015 00:34:38 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201509080034.t880Ycmp068763@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Tue, 8 Sep 2015 00:34:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287545 - stable/10/contrib/tzdata X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Sep 2015 00:34:39 -0000 Author: delphij Date: Tue Sep 8 00:34:38 2015 New Revision: 287545 URL: https://svnweb.freebsd.org/changeset/base/287545 Log: MFC r287020: MFV r287019: leapseconds from tzdata2015f. Modified: stable/10/contrib/tzdata/leapseconds Directory Properties: stable/10/ (props changed) Modified: stable/10/contrib/tzdata/leapseconds ============================================================================== --- stable/10/contrib/tzdata/leapseconds Tue Sep 8 00:30:10 2015 (r287544) +++ stable/10/contrib/tzdata/leapseconds Tue Sep 8 00:34:38 2015 (r287545) @@ -1,14 +1,20 @@ -#
-# This file is in the public domain, so clarified as of
-# 2009-05-17 by Arthur David Olson.
+# Allowance for leap seconds added to each time zone file.
 
-# Allowance for leapseconds added to each timezone file.
+# This file is in the public domain.
 
-# The International Earth Rotation Service periodically uses leap seconds
-# to keep UTC to within 0.9 s of UT1
+# This file is generated automatically from the data in the public-domain
+# leap-seconds.list file available from most NIST time servers.
+# If the URL  does not work,
+# you should be able to pick up leap-seconds.list from a secondary NIST server.
+# For more about leap-seconds.list, please see
+# The NTP Timescale and Leap Seconds
+# http://www.eecis.udel.edu/~mills/leap.html
+
+# The International Earth Rotation and Reference Systems Service
+# periodically uses leap seconds to keep UTC to within 0.9 s of UT1
 # (which measures the true angular orientation of the earth in space); see
 # Terry J Quinn, The BIPM and the accurate measure of time,
-# Proc IEEE 79, 7 (July 1991), 894-905.
+# Proc IEEE 79, 7 (July 1991), 894-905 .
 # There were no leap seconds before 1972, because the official mechanism
 # accounting for the discrepancy between atomic time and the earth's rotation
 # did not exist until the early 1970s.
@@ -19,8 +25,8 @@
 # or
 #	Leap	YEAR	MON	DAY	23:59:59	-	R/S
 
-# If the leapsecond is Rolling (R) the given time is local time
-# If the leapsecond is Stationary (S) the given time is UTC
+# If the leapsecond is Rolling (R) the given time is local time.
+# If the leapsecond is Stationary (S) the given time is UTC.
 
 # Leap	YEAR	MONTH	DAY	HH:MM:SS	CORR	R/S
 Leap	1972	Jun	30	23:59:60	+	S
@@ -48,53 +54,7 @@ Leap	1998	Dec	31	23:59:60	+	S
 Leap	2005	Dec	31	23:59:60	+	S
 Leap	2008	Dec	31	23:59:60	+	S
 Leap	2012	Jun	30	23:59:60	+	S
+Leap	2015	Jun	30	23:59:60	+	S
 
-# INTERNATIONAL EARTH ROTATION AND REFERENCE SYSTEMS SERVICE (IERS)
-#
-# SERVICE INTERNATIONAL DE LA ROTATION TERRESTRE ET DES SYSTEMES DE REFERENCE
-#
-#
-# SERVICE DE LA ROTATION TERRESTRE
-# OBSERVATOIRE DE PARIS
-# 61, Av. de l'Observatoire 75014 PARIS (France)
-# Tel.      : 33 (0) 1 40 51 22 26
-# FAX       : 33 (0) 1 40 51 22 91
-# e-mail    : (E-Mail Removed)
-# http://hpiers.obspm.fr/eop-pc
-#
-# Paris, 5 January 2012
-#
-#
-# Bulletin C 43
-#
-# To authorities responsible
-# for the measurement and
-# distribution of time
-#
-#
-# UTC TIME STEP
-# on the 1st of July 2012
-#
-#
-# A positive leap second will be introduced at the end of June 2012.
-# The sequence of dates of the UTC second markers will be:
-#
-#                          2012 June 30,     23h 59m 59s
-#                          2012 June 30,     23h 59m 60s
-#                          2012 July  1,      0h  0m  0s
-#
-# The difference between UTC and the International Atomic Time TAI is:
-#
-# from 2009 January 1, 0h UTC, to 2012 July 1  0h UTC  : UTC-TAI = - 34s
-# from 2012 July 1,    0h UTC, until further notice    : UTC-TAI = - 35s
-#
-# Leap seconds can be introduced in UTC at the end of the months of December
-# or June, depending on the evolution of UT1-TAI. Bulletin C is mailed every
-# six months, either to announce a time step in UTC or to confirm that there
-# will be no time step at the next possible date.
-#
-#
-# Daniel GAMBIS
-# Head
-# Earth Orientation Center of IERS
-# Observatoire de Paris, France
+#	Updated through IERS Bulletin C50
+#	File expires on:  28 June 2016

From owner-svn-src-stable-10@freebsd.org  Tue Sep  8 00:43:41 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id D08C49CBFA5;
 Tue,  8 Sep 2015 00:43:41 +0000 (UTC)
 (envelope-from delphij@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id C12FD1BA7;
 Tue,  8 Sep 2015 00:43:41 +0000 (UTC)
 (envelope-from delphij@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t880hfud073064;
 Tue, 8 Sep 2015 00:43:41 GMT (envelope-from delphij@FreeBSD.org)
Received: (from delphij@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t880hfvN073063;
 Tue, 8 Sep 2015 00:43:41 GMT (envelope-from delphij@FreeBSD.org)
Message-Id: <201509080043.t880hfvN073063@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: delphij set sender to
 delphij@FreeBSD.org using -f
From: Xin LI 
Date: Tue, 8 Sep 2015 00:43:41 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287546 - stable/10/share/zoneinfo
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Tue, 08 Sep 2015 00:43:41 -0000

Author: delphij
Date: Tue Sep  8 00:43:40 2015
New Revision: 287546
URL: https://svnweb.freebsd.org/changeset/base/287546

Log:
  MFC r287021:
  
  Fix build when LEAPSECONDS is enabled.

Modified:
  stable/10/share/zoneinfo/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/share/zoneinfo/Makefile
==============================================================================
--- stable/10/share/zoneinfo/Makefile	Tue Sep  8 00:34:38 2015	(r287545)
+++ stable/10/share/zoneinfo/Makefile	Tue Sep  8 00:43:40 2015	(r287546)
@@ -34,7 +34,7 @@ CONTRIBDIR=	${.CURDIR}/../../contrib/tzd
 .PATH:		${CONTRIBDIR}
 
 .if defined(LEAPSECONDS)
-LEAPFILE=	-L leapseconds
+LEAPFILE=	-L ${CONTRIBDIR}leapseconds
 .else
 LEAPFILE=
 .endif

From owner-svn-src-stable-10@freebsd.org  Tue Sep  8 01:44:38 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9A5D09CDD80;
 Tue,  8 Sep 2015 01:44:38 +0000 (UTC)
 (envelope-from delphij@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 8AE0A1246;
 Tue,  8 Sep 2015 01:44:38 +0000 (UTC)
 (envelope-from delphij@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t881icqS099535;
 Tue, 8 Sep 2015 01:44:38 GMT (envelope-from delphij@FreeBSD.org)
Received: (from delphij@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t881icZO099534;
 Tue, 8 Sep 2015 01:44:38 GMT (envelope-from delphij@FreeBSD.org)
Message-Id: <201509080144.t881icZO099534@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: delphij set sender to
 delphij@FreeBSD.org using -f
From: Xin LI 
Date: Tue, 8 Sep 2015 01:44:38 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287547 - stable/10/lib/libc/posix1e
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Tue, 08 Sep 2015 01:44:38 -0000

Author: delphij
Date: Tue Sep  8 01:44:37 2015
New Revision: 287547
URL: https://svnweb.freebsd.org/changeset/base/287547

Log:
  MFC r287093:
  
  Instead of doing an no-op (|= 0), actually clear the flags in
  acl_clear_flags_np.
  
  Reported by:	Pascal Drecker 

Modified:
  stable/10/lib/libc/posix1e/acl_flag.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/posix1e/acl_flag.c
==============================================================================
--- stable/10/lib/libc/posix1e/acl_flag.c	Tue Sep  8 00:43:40 2015	(r287546)
+++ stable/10/lib/libc/posix1e/acl_flag.c	Tue Sep  8 01:44:37 2015	(r287547)
@@ -71,7 +71,7 @@ acl_clear_flags_np(acl_flagset_t flagset
 		return (-1);
 	}
 
-	*flagset_d |= 0;
+	*flagset_d = 0;
 
 	return (0);
 }

From owner-svn-src-stable-10@freebsd.org  Tue Sep  8 02:02:09 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id A7D869CC613;
 Tue,  8 Sep 2015 02:02:09 +0000 (UTC)
 (envelope-from delphij@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 9843A1D1C;
 Tue,  8 Sep 2015 02:02:09 +0000 (UTC)
 (envelope-from delphij@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t88229mL008266;
 Tue, 8 Sep 2015 02:02:09 GMT (envelope-from delphij@FreeBSD.org)
Received: (from delphij@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t882292L008265;
 Tue, 8 Sep 2015 02:02:09 GMT (envelope-from delphij@FreeBSD.org)
Message-Id: <201509080202.t882292L008265@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: delphij set sender to
 delphij@FreeBSD.org using -f
From: Xin LI 
Date: Tue, 8 Sep 2015 02:02:09 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287549 - stable/10/usr.bin/at
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Tue, 08 Sep 2015 02:02:09 -0000

Author: delphij
Date: Tue Sep  8 02:02:08 2015
New Revision: 287549
URL: https://svnweb.freebsd.org/changeset/base/287549

Log:
  MFC r287123:
  
  Finish r89633 and completely remove the remaining of VERSION.
  
  PR:		bin/202308
  Submitted by:	John Hein 

Modified:
  stable/10/usr.bin/at/Makefile.inc
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.bin/at/Makefile.inc
==============================================================================
--- stable/10/usr.bin/at/Makefile.inc	Tue Sep  8 01:46:52 2015	(r287548)
+++ stable/10/usr.bin/at/Makefile.inc	Tue Sep  8 02:02:08 2015	(r287549)
@@ -1,4 +1,5 @@
-VERSION= 2.9
+# $FreeBSD$
+
 LOCKFILE = .lockfile
 ATSPOOL_DIR=/var/at/spool
 ATJOB_DIR=/var/at/jobs
@@ -13,7 +14,7 @@ PERM_PATH=/var/at
 CFLAGS += -DATJOB_DIR=\"$(ATJOB_DIR)/\" \
 	-DLFILE=\"$(ATJOB_DIR)/$(LOCKFILE)\" \
 	-DLOADAVG_MX=$(LOADAVG_MX) -DATSPOOL_DIR=\"$(ATSPOOL_DIR)\" \
-	-DVERSION=\"$(VERSION)\" -DDAEMON_UID=$(DAEMON_UID) -DDAEMON_GID=$(DAEMON_GID) \
+	-DDAEMON_UID=$(DAEMON_UID) -DDAEMON_GID=$(DAEMON_GID) \
 	-DDEFAULT_BATCH_QUEUE=\'$(DEFAULT_BATCH_QUEUE)\' \
 	-DDEFAULT_AT_QUEUE=\'$(DEFAULT_AT_QUEUE)\' -DPERM_PATH=\"$(PERM_PATH)/\"
 

From owner-svn-src-stable-10@freebsd.org  Tue Sep  8 07:15:11 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69552A0099C;
 Tue,  8 Sep 2015 07:15:11 +0000 (UTC) (envelope-from kib@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 590D01EB1;
 Tue,  8 Sep 2015 07:15:11 +0000 (UTC) (envelope-from kib@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t887FBgV045432;
 Tue, 8 Sep 2015 07:15:11 GMT (envelope-from kib@FreeBSD.org)
Received: (from kib@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t887FAEQ045430;
 Tue, 8 Sep 2015 07:15:10 GMT (envelope-from kib@FreeBSD.org)
Message-Id: <201509080715.t887FAEQ045430@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org
 using -f
From: Konstantin Belousov 
Date: Tue, 8 Sep 2015 07:15:10 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287551 - in stable/10:
 contrib/netbsd-tests/lib/libc/gen/posix_spawn lib/libc/tests/gen/posix_spawn
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Tue, 08 Sep 2015 07:15:11 -0000

Author: kib
Date: Tue Sep  8 07:15:10 2015
New Revision: 287551
URL: https://svnweb.freebsd.org/changeset/base/287551

Log:
  MFC r287360:
  Fix t_spawnattr test for attributes handling by posix_spawn(3).
  Connect it to the build.

Modified:
  stable/10/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c
  stable/10/lib/libc/tests/gen/posix_spawn/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c
==============================================================================
--- stable/10/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c	Tue Sep  8 04:18:57 2015	(r287550)
+++ stable/10/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c	Tue Sep  8 07:15:10 2015	(r287551)
@@ -30,6 +30,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -42,51 +43,56 @@
 #include 
 #include 
 
-#define MAX(a, b)	(a) > (b) ? (a) : (b)
-#define MIN(a, b)	(a) > (b) ? (b) : (a)
-
 static int get_different_scheduler(void);
-static int get_different_priority(void);
+static int get_different_priority(int scheduler);
+
+static const int schedulers[] = {
+	SCHED_OTHER,
+	SCHED_FIFO,
+	SCHED_RR
+};
 
 static int
-get_different_scheduler()
+get_different_scheduler(void)
 {
-	int scheduler, max, min, new;
-
-	max = MAX(MAX(SCHED_FIFO, SCHED_OTHER), SCHED_RR);
-	min = MIN(MIN(SCHED_FIFO, SCHED_OTHER), SCHED_RR);
+	u_int i;
+	int scheduler;
 
 	/* get current schedule policy */
 	scheduler = sched_getscheduler(0);
+	for (i = 0; i < nitems(schedulers); i++) {
+		if (schedulers[i] == scheduler)
+			break;
+	}
+	ATF_REQUIRE_MSG(i < nitems(schedulers),
+	    "Unknown current scheduler %d", scheduler);
 					
 	/* new scheduler */
-	new = (scheduler + 1);
-	if (new > max)
-		new = min;
-								
-	return new;
+	i++;
+	if (i >= nitems(schedulers))
+		i = 0;
+	return schedulers[i];
 }
 
 static int
-get_different_priority()
+get_different_priority(int scheduler)
 {
-	int scheduler, max, min, new, priority;
+	int max, min, new, priority;
 	struct sched_param param;
 
-	/* get current schedule policy */
-	scheduler = sched_getscheduler(0);
-
 	max = sched_get_priority_max(scheduler);
 	min = sched_get_priority_min(scheduler);
 
 	sched_getparam(0, ¶m);
 	priority = param.sched_priority;
 	
-	/* new schedule policy */
-	new = (priority + 1);
+	/*
+	 * Change numerical value of the priority, to ensure that it
+	 * was set for the spawned child.
+	 */
+	new = priority + 1;
 	if (new > max)
 		new = min;
-	
 	return new;
 }
 
@@ -119,16 +125,15 @@ ATF_TC_BODY(t_spawnattr, tc)
 	posix_spawnattr_init(&attr);
 
 	scheduler = get_different_scheduler();
-	priority = get_different_priority();
+	priority = get_different_priority(scheduler);
 	sp.sched_priority = priority;
 	
 	sigemptyset(&sig);
 	sigaddset(&sig, SIGUSR1);
 
-	posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDULER | 
-		POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETPGROUP |
-		POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF |
-		POSIX_SPAWN_SETSIGDEF); 
+	posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDULER |
+	    POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETPGROUP |
+	    POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF);
 	posix_spawnattr_setpgroup(&attr, 0);
 	posix_spawnattr_setschedparam(&attr, &sp);
 	posix_spawnattr_setschedpolicy(&attr, scheduler);

Modified: stable/10/lib/libc/tests/gen/posix_spawn/Makefile
==============================================================================
--- stable/10/lib/libc/tests/gen/posix_spawn/Makefile	Tue Sep  8 04:18:57 2015	(r287550)
+++ stable/10/lib/libc/tests/gen/posix_spawn/Makefile	Tue Sep  8 07:15:10 2015	(r287551)
@@ -10,9 +10,9 @@ TESTSDIR=	${TESTSBASE}/lib/libc/gen/posi
 
 BINDIR=		${TESTSDIR}
 
-# TODO: t_spawnattr (fix from pho@ needs additional review)
 NETBSD_ATF_TESTS_C=	fileactions_test
 NETBSD_ATF_TESTS_C+=	spawn_test
+NETBSD_ATF_TESTS_C+=	spawnattr_test
 
 PROGS=		h_fileactions
 PROGS+=		h_spawn

From owner-svn-src-stable-10@freebsd.org  Tue Sep  8 12:00:14 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8F82CA00A69;
 Tue,  8 Sep 2015 12:00:14 +0000 (UTC)
 (envelope-from andrew@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 7F9341006;
 Tue,  8 Sep 2015 12:00:14 +0000 (UTC)
 (envelope-from andrew@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t88C0EWp062226;
 Tue, 8 Sep 2015 12:00:14 GMT (envelope-from andrew@FreeBSD.org)
Received: (from andrew@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t88C0E1D062225;
 Tue, 8 Sep 2015 12:00:14 GMT (envelope-from andrew@FreeBSD.org)
Message-Id: <201509081200.t88C0E1D062225@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: andrew set sender to
 andrew@FreeBSD.org using -f
From: Andrew Turner 
Date: Tue, 8 Sep 2015 12:00:14 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287560 - stable/10/libexec/rtld-elf
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Tue, 08 Sep 2015 12:00:14 -0000

Author: andrew
Date: Tue Sep  8 12:00:13 2015
New Revision: 287560
URL: https://svnweb.freebsd.org/changeset/base/287560

Log:
  MFC r287369:
  Ensure we use calculate_first_tls_offset, even if the main program doesn't
  have TLS program header. This is needed on architectures with Variant I
  tls, that is arm, arm64, mips, and powerpc. These place the thread control
  block at the start of the buffer and, without this, this data may be
  trashed.
  
  This appears to not be an issue on mips or powerpc as they include a second
  adjustment to move the thread local data, however this is on arm64 (with a
  future change to fix placing this data), and should be on arm. I am unable
  to trigger this on arm, even after changing the code to move the data
  around to make it more likely to be hit. This is most likely because my
  tests didn't use the variable in offset 0.
  
  Reviewed by:	kib
  MFC after:	1 week
  Sponsored by:	ABT Systems Ltd

Modified:
  stable/10/libexec/rtld-elf/rtld.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/libexec/rtld-elf/rtld.c
==============================================================================
--- stable/10/libexec/rtld-elf/rtld.c	Tue Sep  8 08:54:40 2015	(r287559)
+++ stable/10/libexec/rtld-elf/rtld.c	Tue Sep  8 12:00:13 2015	(r287560)
@@ -4532,7 +4532,7 @@ allocate_tls_offset(Obj_Entry *obj)
 	return true;
     }
 
-    if (obj->tlsindex == 1)
+    if (tls_last_offset == 0)
 	off = calculate_first_tls_offset(obj->tlssize, obj->tlsalign);
     else
 	off = calculate_tls_offset(tls_last_offset, tls_last_size,

From owner-svn-src-stable-10@freebsd.org  Tue Sep  8 17:20:13 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4CA459CC627;
 Tue,  8 Sep 2015 17:20:13 +0000 (UTC)
 (envelope-from sbruno@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 20A3B1613;
 Tue,  8 Sep 2015 17:20:13 +0000 (UTC)
 (envelope-from sbruno@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t88HKDIC098501;
 Tue, 8 Sep 2015 17:20:13 GMT (envelope-from sbruno@FreeBSD.org)
Received: (from sbruno@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t88HKCH0098500;
 Tue, 8 Sep 2015 17:20:12 GMT (envelope-from sbruno@FreeBSD.org)
Message-Id: <201509081720.t88HKCH0098500@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: sbruno set sender to
 sbruno@FreeBSD.org using -f
From: Sean Bruno 
Date: Tue, 8 Sep 2015 17:20:12 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287566 - stable/10/sys/dev/ciss
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Tue, 08 Sep 2015 17:20:13 -0000

Author: sbruno
Date: Tue Sep  8 17:20:12 2015
New Revision: 287566
URL: https://svnweb.freebsd.org/changeset/base/287566

Log:
  MFC r287437
  
  r249170 was just plain wrong.  The effect of the change is to always
  delete a logic volume on status change which is NOT what we want here.
  
  The original code is correct in that when the volume changes status
  the driver will only delete the volume if the status is one of the
  fatal errors.  A drive failure in a mirrored volume is NOT a situtation
  where the volume should dissapear.
  
  Reported on freebsd-scsi@:
  https://lists.freebsd.org/pipermail/freebsd-scsi/2015-September/006800.html

Modified:
  stable/10/sys/dev/ciss/ciss.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/ciss/ciss.c
==============================================================================
--- stable/10/sys/dev/ciss/ciss.c	Tue Sep  8 16:06:04 2015	(r287565)
+++ stable/10/sys/dev/ciss/ciss.c	Tue Sep  8 17:20:12 2015	(r287566)
@@ -4018,8 +4018,7 @@ static void
 ciss_notify_logical(struct ciss_softc *sc, struct ciss_notify *cn)
 {
     struct ciss_ldrive	*ld;
-    int			bus, target;
-    int			rescan_ld;
+    int			ostatus, bus, target;
 
     debug_called(2);
 
@@ -4042,6 +4041,7 @@ ciss_notify_logical(struct ciss_softc *s
 	    /*
 	     * Update our idea of the drive's status.
 	     */
+	    ostatus = ciss_decode_ldrive_status(cn->data.logical_status.previous_state);
 	    ld->cl_status = ciss_decode_ldrive_status(cn->data.logical_status.new_state);
 	    if (ld->cl_lstatus != NULL)
 		ld->cl_lstatus->status = cn->data.logical_status.new_state;
@@ -4049,9 +4049,7 @@ ciss_notify_logical(struct ciss_softc *s
 	    /*
 	     * Have CAM rescan the drive if its status has changed.
 	     */
-            rescan_ld = (cn->data.logical_status.previous_state !=
-                         cn->data.logical_status.new_state) ? 1 : 0;
-	    if (rescan_ld) {
+	    if (ostatus != ld->cl_status) {
 		ld->cl_update = 1;
 		ciss_notify_rescan_logical(sc);
 	    }

From owner-svn-src-stable-10@freebsd.org  Tue Sep  8 17:54:32 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id EA79FA00AA8;
 Tue,  8 Sep 2015 17:54:32 +0000 (UTC)
 (envelope-from rodrigc@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id C0FAD12DC;
 Tue,  8 Sep 2015 17:54:32 +0000 (UTC)
 (envelope-from rodrigc@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t88HsWqI015216;
 Tue, 8 Sep 2015 17:54:32 GMT (envelope-from rodrigc@FreeBSD.org)
Received: (from rodrigc@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t88HsWwt015214;
 Tue, 8 Sep 2015 17:54:32 GMT (envelope-from rodrigc@FreeBSD.org)
Message-Id: <201509081754.t88HsWwt015214@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: rodrigc set sender to
 rodrigc@FreeBSD.org using -f
From: Craig Rodrigues 
Date: Tue, 8 Sep 2015 17:54:32 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287568 - stable/10/contrib/netbsd-tests/lib/libc/locale
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Tue, 08 Sep 2015 17:54:33 -0000

Author: rodrigc
Date: Tue Sep  8 17:54:31 2015
New Revision: 287568
URL: https://svnweb.freebsd.org/changeset/base/287568

Log:
  Merge r286649:
  
  Fix and re-enable UTF-8 tests.
  
  X-Merge with: r287393

Modified:
  stable/10/contrib/netbsd-tests/lib/libc/locale/t_mbrtowc.c
  stable/10/contrib/netbsd-tests/lib/libc/locale/t_mbstowcs.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/contrib/netbsd-tests/lib/libc/locale/t_mbrtowc.c
==============================================================================
--- stable/10/contrib/netbsd-tests/lib/libc/locale/t_mbrtowc.c	Tue Sep  8 17:47:56 2015	(r287567)
+++ stable/10/contrib/netbsd-tests/lib/libc/locale/t_mbrtowc.c	Tue Sep  8 17:54:31 2015	(r287568)
@@ -88,13 +88,11 @@ static struct test {
 }, {
 	"en_US.UTF-8",
 	"[\001\177][\302\200\337\277][\340\240\200\357\277\277][\360\220\200"
-	"\200\367\277\277\277][\370\210\200\200\200\373\277\277\277\277][\374"
-	"\204\200\200\200\200\375\277\277\277\277\277]",
+	"\200\364\217\277\277]",
 	{ 0x5b, 0x01, 0x7f, 0x5d, 0x5b, 0x80, 0x7ff, 0x5d, 0x5b, 0x800, 0xffff,
-	  0x5d, 0x5b, 0x10000, 0x1fffff, 0x5d, 0x5b, 0x200000, 0x3ffffff, 0x5d,
-	  0x5b, 0x4000000, 0x7fffffff, 0x5d },
-	{ 1, 1, 1, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1, 1, 5, 5, 1, 1, 6, 6, 1 },
-	24
+	  0x5d, 0x5b, 0x10000, 0x10ffff, 0x5d },
+	{ 1, 1, 1, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1 },
+	16
 }, {
 	"ja_JP.ISO2022-JP2",
 	"\033$BF|K\1348l\033(BA\033$B$\"\033(BB\033$B$$\033(B",

Modified: stable/10/contrib/netbsd-tests/lib/libc/locale/t_mbstowcs.c
==============================================================================
--- stable/10/contrib/netbsd-tests/lib/libc/locale/t_mbstowcs.c	Tue Sep  8 17:47:56 2015	(r287567)
+++ stable/10/contrib/netbsd-tests/lib/libc/locale/t_mbstowcs.c	Tue Sep  8 17:54:31 2015	(r287568)
@@ -82,12 +82,10 @@ static struct test {
 {
 	"en_US.UTF-8",
 	"[\001\177][\302\200\337\277][\340\240\200\357\277\277][\360\220\200"
-	"\200\367\277\277\277][\370\210\200\200\200\373\277\277\277\277][\374"
-	"\204\200\200\200\200\375\277\277\277\277\277]",
+	"\200\364\217\277\277]",
 	{
 		0x5B, 0x01, 0x7F, 0x5D, 0x5B, 0x80, 0x07FF, 0x5D, 0x5B, 0x0800,
-		0xFFFF, 0x5D, 0x5B, 0x10000, 0x1FFFFF, 0x5D, 0x5B, 0x200000,
-		0x3FFFFFF, 0x5D, 0x5B, 0x4000000, 0x7FFFFFFF, 0x5D, 0x0A
+		0xFFFF, 0x5D, 0x5B, 0x10000, 0x10FFFF, 0x5D, 0x0A
 	},
 	{	 1, -1, -1,  1,  1, -1, -1,  1,  1, -1, -1,  1,  1, -1, -1,
 		 1,  1, -1, -1,  1,  1, -1, -1,  1, -1

From owner-svn-src-stable-10@freebsd.org  Tue Sep  8 18:37:17 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id A2C01A00325;
 Tue,  8 Sep 2015 18:37:17 +0000 (UTC) (envelope-from imp@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 9367A11A2;
 Tue,  8 Sep 2015 18:37:17 +0000 (UTC) (envelope-from imp@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t88IbHrD032285;
 Tue, 8 Sep 2015 18:37:17 GMT (envelope-from imp@FreeBSD.org)
Received: (from imp@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t88IbHgk032284;
 Tue, 8 Sep 2015 18:37:17 GMT (envelope-from imp@FreeBSD.org)
Message-Id: <201509081837.t88IbHgk032284@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org
 using -f
From: Warner Losh 
Date: Tue, 8 Sep 2015 18:37:17 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287569 - stable/10/sys/geom
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Tue, 08 Sep 2015 18:37:17 -0000

Author: imp
Date: Tue Sep  8 18:37:16 2015
New Revision: 287569
URL: https://svnweb.freebsd.org/changeset/base/287569

Log:
  MFC: r287405:
  
  Make out of memory behavior less pathological.

Modified:
  stable/10/sys/geom/geom_io.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/geom/geom_io.c
==============================================================================
--- stable/10/sys/geom/geom_io.c	Tue Sep  8 17:54:31 2015	(r287568)
+++ stable/10/sys/geom/geom_io.c	Tue Sep  8 18:37:16 2015	(r287569)
@@ -71,7 +71,17 @@ static struct g_bioq g_bio_run_down;
 static struct g_bioq g_bio_run_up;
 static struct g_bioq g_bio_run_task;
 
-static u_int pace;
+/*
+ * Pace is a hint that we've had some trouble recently allocating
+ * bios, so we should back off trying to send I/O down the stack
+ * a bit to let the problem resolve. When pacing, we also turn
+ * off direct dispatch to also reduce memory pressure from I/Os
+ * there, at the expxense of some added latency while the memory
+ * pressures exist. See g_io_schedule_down() for more details
+ * and limitations.
+ */
+static volatile u_int pace;
+
 static uma_zone_t	biozone;
 
 /*
@@ -521,7 +531,8 @@ g_io_request(struct bio *bp, struct g_co
 	    (pp->flags & G_PF_DIRECT_RECEIVE) != 0 &&
 	    !g_is_geom_thread(curthread) &&
 	    ((pp->flags & G_PF_ACCEPT_UNMAPPED) != 0 ||
-	    (bp->bio_flags & BIO_UNMAPPED) == 0 || THREAD_CAN_SLEEP());
+	    (bp->bio_flags & BIO_UNMAPPED) == 0 || THREAD_CAN_SLEEP()) &&
+	    pace == 0;
 	if (direct) {
 		/* Block direct execution if less then half of stack left. */
 		size_t	st, su;
@@ -688,7 +699,7 @@ g_io_deliver(struct bio *bp, int error)
 	bp->bio_driver2 = NULL;
 	bp->bio_pflags = 0;
 	g_io_request(bp, cp);
-	pace++;
+	pace = 1;
 	return;
 }
 
@@ -777,10 +788,33 @@ g_io_schedule_down(struct thread *tp __u
 		}
 		CTR0(KTR_GEOM, "g_down has work to do");
 		g_bioq_unlock(&g_bio_run_down);
-		if (pace > 0) {
-			CTR1(KTR_GEOM, "g_down pacing self (pace %d)", pace);
-			pause("g_down", hz/10);
-			pace--;
+		if (pace != 0) {
+			/*
+			 * There has been at least one memory allocation
+			 * failure since the last I/O completed. Pause 1ms to
+			 * give the system a chance to free up memory. We only
+			 * do this once because a large number of allocations
+			 * can fail in the direct dispatch case and there's no
+			 * relationship between the number of these failures and
+			 * the length of the outage. If there's still an outage,
+			 * we'll pause again and again until it's
+			 * resolved. Older versions paused longer and once per
+			 * allocation failure. This was OK for a single threaded
+			 * g_down, but with direct dispatch would lead to max of
+			 * 10 IOPs for minutes at a time when transient memory
+			 * issues prevented allocation for a batch of requests
+			 * from the upper layers.
+			 *
+			 * XXX This pacing is really lame. It needs to be solved
+			 * by other methods. This is OK only because the worst
+			 * case scenario is so rare. In the worst case scenario
+			 * all memory is tied up waiting for I/O to complete
+			 * which can never happen since we can't allocate bios
+			 * for that I/O.
+			 */
+			CTR0(KTR_GEOM, "g_down pacing self");
+			pause("g_down", min(hz/1000, 1));
+			pace = 0;
 		}
 		CTR2(KTR_GEOM, "g_down processing bp %p provider %s", bp,
 		    bp->bio_to->name);

From owner-svn-src-stable-10@freebsd.org  Wed Sep  9 08:40:18 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id ACDFBA0004B;
 Wed,  9 Sep 2015 08:40:18 +0000 (UTC) (envelope-from hrs@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 9D6111163;
 Wed,  9 Sep 2015 08:40:18 +0000 (UTC) (envelope-from hrs@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t898eIG9079708;
 Wed, 9 Sep 2015 08:40:18 GMT (envelope-from hrs@FreeBSD.org)
Received: (from hrs@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t898eILL079707;
 Wed, 9 Sep 2015 08:40:18 GMT (envelope-from hrs@FreeBSD.org)
Message-Id: <201509090840.t898eILL079707@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org
 using -f
From: Hiroki Sato 
Date: Wed, 9 Sep 2015 08:40:18 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287593 - stable/10/usr.bin/netstat
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Wed, 09 Sep 2015 08:40:18 -0000

Author: hrs
Date: Wed Sep  9 08:40:17 2015
New Revision: 287593
URL: https://svnweb.freebsd.org/changeset/base/287593

Log:
  MFC r287406:
  
  Divide statistics in the number of packets with 1000 instead of 1024
  in human-readable form.
  
  PR:	183598

Modified:
  stable/10/usr.bin/netstat/if.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.bin/netstat/if.c
==============================================================================
--- stable/10/usr.bin/netstat/if.c	Wed Sep  9 07:04:00 2015	(r287592)
+++ stable/10/usr.bin/netstat/if.c	Wed Sep  9 08:40:17 2015	(r287593)
@@ -165,7 +165,8 @@ pfsync_stats(u_long off, const char *nam
  * Display a formatted value, or a '-' in the same space.
  */
 static void
-show_stat(const char *fmt, int width, u_long value, short showvalue)
+show_stat(const char *fmt, int width, u_long value, short showvalue,
+    int div1000)
 {
 	const char *lsep, *rsep;
 	char newfmt[32];
@@ -192,7 +193,8 @@ show_stat(const char *fmt, int width, u_
 
 		/* Format in human readable form. */
 		humanize_number(buf, sizeof(buf), (int64_t)value, "",
-		    HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
+		    HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL | \
+		    ((div1000) ? HN_DIVISOR_1000 : 0));
 		sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep);
 		printf(newfmt, buf);
 	} else {
@@ -287,7 +289,7 @@ intpr(int interval, void (*pfunc)(char *
 			printf("%-5.5s", ifa->ifa_name);
 
 #define IFA_MTU(ifa)	(((struct if_data *)(ifa)->ifa_data)->ifi_mtu)
-		show_stat("lu", 6, IFA_MTU(ifa), IFA_MTU(ifa));
+		show_stat("lu", 6, IFA_MTU(ifa), IFA_MTU(ifa), 0);
 #undef IFA_MTU
 
 		switch (ifa->ifa_addr->sa_family) {
@@ -373,18 +375,18 @@ intpr(int interval, void (*pfunc)(char *
 		}
 
 #define	IFA_STAT(s)	(((struct if_data *)ifa->ifa_data)->ifi_ ## s)
-		show_stat("lu", 8, IFA_STAT(ipackets), link|network);
-		show_stat("lu", 5, IFA_STAT(ierrors), link);
-		show_stat("lu", 5, IFA_STAT(iqdrops), link);
+		show_stat("lu", 8, IFA_STAT(ipackets), link|network, 1);
+		show_stat("lu", 5, IFA_STAT(ierrors), link, 1);
+		show_stat("lu", 5, IFA_STAT(iqdrops), link, 1);
 		if (bflag)
-			show_stat("lu", 10, IFA_STAT(ibytes), link|network);
-		show_stat("lu", 8, IFA_STAT(opackets), link|network);
-		show_stat("lu", 5, IFA_STAT(oerrors), link);
+			show_stat("lu", 10, IFA_STAT(ibytes), link|network, 0);
+		show_stat("lu", 8, IFA_STAT(opackets), link|network, 1);
+		show_stat("lu", 5, IFA_STAT(oerrors), link, 1);
 		if (bflag)
-			show_stat("lu", 10, IFA_STAT(obytes), link|network);
-		show_stat("NRSlu", 5, IFA_STAT(collisions), link);
+			show_stat("lu", 10, IFA_STAT(obytes), link|network, 0);
+		show_stat("NRSlu", 5, IFA_STAT(collisions), link, 1);
 		if (dflag)
-			show_stat("LSlu", 5, IFA_STAT(oqdrops), link);
+			show_stat("LSlu", 5, IFA_STAT(oqdrops), link, 1);
 		putchar('\n');
 
 		if (!aflag)
@@ -569,16 +571,16 @@ loop:
 
 	fill_iftot(new);
 
-	show_stat("lu", 10, new->ift_ip - old->ift_ip, 1);
-	show_stat("lu", 5, new->ift_ie - old->ift_ie, 1);
-	show_stat("lu", 5, new->ift_id - old->ift_id, 1);
-	show_stat("lu", 10, new->ift_ib - old->ift_ib, 1);
-	show_stat("lu", 10, new->ift_op - old->ift_op, 1);
-	show_stat("lu", 5, new->ift_oe - old->ift_oe, 1);
-	show_stat("lu", 10, new->ift_ob - old->ift_ob, 1);
-	show_stat("NRSlu", 5, new->ift_co - old->ift_co, 1);
+	show_stat("lu", 10, new->ift_ip - old->ift_ip, 1, 1);
+	show_stat("lu", 5, new->ift_ie - old->ift_ie, 1, 1);
+	show_stat("lu", 5, new->ift_id - old->ift_id, 1, 1);
+	show_stat("lu", 10, new->ift_ib - old->ift_ib, 1, 0);
+	show_stat("lu", 10, new->ift_op - old->ift_op, 1, 1);
+	show_stat("lu", 5, new->ift_oe - old->ift_oe, 1, 1);
+	show_stat("lu", 10, new->ift_ob - old->ift_ob, 1, 0);
+	show_stat("NRSlu", 5, new->ift_co - old->ift_co, 1, 1);
 	if (dflag)
-		show_stat("LSlu", 5, new->ift_od - old->ift_od, 1);
+		show_stat("LSlu", 5, new->ift_od - old->ift_od, 1, 1);
 	putchar('\n');
 	fflush(stdout);
 

From owner-svn-src-stable-10@freebsd.org  Wed Sep  9 08:52:40 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id CFF74A007C2;
 Wed,  9 Sep 2015 08:52:40 +0000 (UTC) (envelope-from hrs@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id B456F1B48;
 Wed,  9 Sep 2015 08:52:40 +0000 (UTC) (envelope-from hrs@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t898qeg5087536;
 Wed, 9 Sep 2015 08:52:40 GMT (envelope-from hrs@FreeBSD.org)
Received: (from hrs@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t898qeJ9087535;
 Wed, 9 Sep 2015 08:52:40 GMT (envelope-from hrs@FreeBSD.org)
Message-Id: <201509090852.t898qeJ9087535@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org
 using -f
From: Hiroki Sato 
Date: Wed, 9 Sep 2015 08:52:40 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287594 - stable/10/sys/net
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Wed, 09 Sep 2015 08:52:40 -0000

Author: hrs
Date: Wed Sep  9 08:52:39 2015
New Revision: 287594
URL: https://svnweb.freebsd.org/changeset/base/287594

Log:
  MFC r272889 and r287402:
  
  - Virtualize if_epair(4).  An if_xname check for both "a" and "b" interfaces
    is added to return EEXIST when only "b" interface exists---this can happen
    when epairb is moved to a vnet jail and then "ifconfig epair create"
    is invoked there.
  
  - Fix a panic which was reproducible by an infinite loop of
    "ifconfig epair0 create && ifconfig epair0a destroy".
    This was caused by an uninitialized function pointer in
    softc->media.

Modified:
  stable/10/sys/net/if_epair.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/net/if_epair.c
==============================================================================
--- stable/10/sys/net/if_epair.c	Wed Sep  9 08:40:17 2015	(r287593)
+++ stable/10/sys/net/if_epair.c	Wed Sep  9 08:52:39 2015	(r287594)
@@ -100,7 +100,7 @@ static int epair_clone_destroy(struct if
 
 static const char epairname[] = "epair";
 
-/* Netisr realted definitions and sysctl. */
+/* Netisr related definitions and sysctl. */
 static struct netisr_handler epair_nh = {
 	.nh_name	= epairname,
 	.nh_proto	= NETISR_EPAIR,
@@ -171,7 +171,8 @@ STAILQ_HEAD(eid_list, epair_ifp_drain);
 static MALLOC_DEFINE(M_EPAIR, epairname,
     "Pair of virtual cross-over connected Ethernet-like interfaces");
 
-static struct if_clone *epair_cloner;
+static VNET_DEFINE(struct if_clone *, epair_cloner);
+#define	V_epair_cloner	VNET(epair_cloner)
 
 /*
  * DPCPU area and functions.
@@ -759,10 +760,17 @@ epair_clone_create(struct if_clone *ifc,
 		ifc_free_unit(ifc, unit);
 		return (ENOSPC);
 	}
-	*dp = 'a';
+	*dp = 'b';
 	/* Must not change dp so we can replace 'a' by 'b' later. */
 	*(dp+1) = '\0';
 
+	/* Check if 'a' and 'b' interfaces already exist. */ 
+	if (ifunit(name) != NULL)
+		return (EEXIST);
+	*dp = 'a';
+	if (ifunit(name) != NULL)
+		return (EEXIST);
+
 	/* Allocate memory for both [ab] interfaces */
 	sca = malloc(sizeof(struct epair_softc), M_EPAIR, M_WAITOK | M_ZERO);
 	EPAIR_REFCOUNT_INIT(&sca->refcount, 1);
@@ -800,6 +808,14 @@ epair_clone_create(struct if_clone *ifc,
 	    netisr_get_cpuid(sca->ifp->if_index % netisr_get_cpucount());
 	scb->cpuid =
 	    netisr_get_cpuid(scb->ifp->if_index % netisr_get_cpucount());
+
+	/* Initialise pseudo media types. */
+	ifmedia_init(&sca->media, 0, epair_media_change, epair_media_status);
+	ifmedia_add(&sca->media, IFM_ETHER | IFM_10G_T, 0, NULL);
+	ifmedia_set(&sca->media, IFM_ETHER | IFM_10G_T);
+	ifmedia_init(&scb->media, 0, epair_media_change, epair_media_status);
+	ifmedia_add(&scb->media, IFM_ETHER | IFM_10G_T, 0, NULL);
+	ifmedia_set(&scb->media, IFM_ETHER | IFM_10G_T);
 	
 	/* Finish initialization of interface a. */
 	ifp = sca->ifp;
@@ -858,14 +874,6 @@ epair_clone_create(struct if_clone *ifc,
 	strlcpy(name, sca->ifp->if_xname, len);
 	DPRINTF("name='%s/%db' created sca=%p scb=%p\n", name, unit, sca, scb);
 
-	/* Initialise pseudo media types. */
-	ifmedia_init(&sca->media, 0, epair_media_change, epair_media_status);
-	ifmedia_add(&sca->media, IFM_ETHER | IFM_10G_T, 0, NULL);
-	ifmedia_set(&sca->media, IFM_ETHER | IFM_10G_T);
-	ifmedia_init(&scb->media, 0, epair_media_change, epair_media_status);
-	ifmedia_add(&scb->media, IFM_ETHER | IFM_10G_T, 0, NULL);
-	ifmedia_set(&scb->media, IFM_ETHER | IFM_10G_T);
-
 	/* Tell the world, that we are ready to rock. */
 	sca->ifp->if_drv_flags |= IFF_DRV_RUNNING;
 	scb->ifp->if_drv_flags |= IFF_DRV_RUNNING;
@@ -943,6 +951,25 @@ epair_clone_destroy(struct if_clone *ifc
 	return (0);
 }
 
+static void
+vnet_epair_init(const void *unused __unused)
+{
+
+	V_epair_cloner = if_clone_advanced(epairname, 0,
+	    epair_clone_match, epair_clone_create, epair_clone_destroy);
+}
+VNET_SYSINIT(vnet_epair_init, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY,
+    vnet_epair_init, NULL);
+
+static void
+vnet_epair_uninit(const void *unused __unused)
+{
+
+	if_clone_detach(V_epair_cloner);
+}
+VNET_SYSUNINIT(vnet_epair_uninit, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY,
+    vnet_epair_uninit, NULL);
+
 static int
 epair_modevent(module_t mod, int type, void *data)
 {
@@ -956,13 +983,10 @@ epair_modevent(module_t mod, int type, v
 		if (TUNABLE_INT_FETCH("net.link.epair.netisr_maxqlen", &qlimit))
 		    epair_nh.nh_qlimit = qlimit;
 		netisr_register(&epair_nh);
-		epair_cloner = if_clone_advanced(epairname, 0,
-		    epair_clone_match, epair_clone_create, epair_clone_destroy);
 		if (bootverbose)
 			printf("%s initialized.\n", epairname);
 		break;
 	case MOD_UNLOAD:
-		if_clone_detach(epair_cloner);
 		netisr_unregister(&epair_nh);
 		epair_dpcpu_detach();
 		if (bootverbose)

From owner-svn-src-stable-10@freebsd.org  Wed Sep  9 17:15:14 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id A9FDDA01D2F;
 Wed,  9 Sep 2015 17:15:14 +0000 (UTC)
 (envelope-from bdrewery@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 99F28116A;
 Wed,  9 Sep 2015 17:15:14 +0000 (UTC)
 (envelope-from bdrewery@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t89HFEmo099633;
 Wed, 9 Sep 2015 17:15:14 GMT (envelope-from bdrewery@FreeBSD.org)
Received: (from bdrewery@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t89HFDYv099630;
 Wed, 9 Sep 2015 17:15:13 GMT (envelope-from bdrewery@FreeBSD.org)
Message-Id: <201509091715.t89HFDYv099630@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to
 bdrewery@FreeBSD.org using -f
From: Bryan Drewery 
Date: Wed, 9 Sep 2015 17:15:13 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287598 - stable/10/sys/dev/filemon
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Wed, 09 Sep 2015 17:15:14 -0000

Author: bdrewery
Date: Wed Sep  9 17:15:13 2015
New Revision: 287598
URL: https://svnweb.freebsd.org/changeset/base/287598

Log:
  MFC r287151,r287152,r287153,r287155:
  
    r287151:
      Move common locking for filemon_inuse and struct filemon* to
      filemon_pid_check().
    r287152:
      Remove unneeded inuse list locking in filemon_comment().
    r287153:
      Avoid taking proctree_lock and searching parents in wrappers if not needed.
    r287155:
      Fix filemon locking races.
  
   Relnotes:	yes (race fixes)
   Sponsored by:	EMC / Isilon Storage Division

Modified:
  stable/10/sys/dev/filemon/filemon.c
  stable/10/sys/dev/filemon/filemon_lock.c
  stable/10/sys/dev/filemon/filemon_wrapper.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/filemon/filemon.c
==============================================================================
--- stable/10/sys/dev/filemon/filemon.c	Wed Sep  9 13:24:39 2015	(r287597)
+++ stable/10/sys/dev/filemon/filemon.c	Wed Sep  9 17:15:13 2015	(r287598)
@@ -1,6 +1,7 @@
 /*-
  * Copyright (c) 2011, David E. O'Brien.
  * Copyright (c) 2009-2011, Juniper Networks, Inc.
+ * Copyright (c) 2015, EMC Corp.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -39,12 +40,14 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -85,12 +88,8 @@ MALLOC_DEFINE(M_FILEMON, "filemon", "Fil
 
 struct filemon {
 	TAILQ_ENTRY(filemon) link;	/* Link into the in-use list. */
-	struct mtx	mtx;		/* Lock mutex for this filemon. */
-	struct cv	cv;		/* Lock condition variable for this
-					   filemon. */
+	struct sx	lock;		/* Lock mutex for this filemon. */
 	struct file	*fp;		/* Output file pointer. */
-	struct thread	*locker;	/* Ptr to the thread locking this
-					   filemon. */
 	pid_t		pid;		/* The process ID being monitored. */
 	char		fname1[MAXPATHLEN]; /* Temporary filename buffer. */
 	char		fname2[MAXPATHLEN]; /* Temporary filename buffer. */
@@ -99,11 +98,7 @@ struct filemon {
 
 static TAILQ_HEAD(, filemon) filemons_inuse = TAILQ_HEAD_INITIALIZER(filemons_inuse);
 static TAILQ_HEAD(, filemon) filemons_free = TAILQ_HEAD_INITIALIZER(filemons_free);
-static int n_readers = 0;
-static struct mtx access_mtx;
-static struct cv access_cv;
-static struct thread *access_owner = NULL;
-static struct thread *access_requester = NULL;
+static struct sx access_lock;
 
 static struct cdev *filemon_dev;
 
@@ -203,8 +198,7 @@ filemon_open(struct cdev *dev, int oflag
 
 		filemon->fp = NULL;
 
-		mtx_init(&filemon->mtx, "filemon", "filemon", MTX_DEF);
-		cv_init(&filemon->cv, "filemon");
+		sx_init(&filemon->lock, "filemon");
 	}
 
 	filemon->pid = curproc->p_pid;
@@ -234,8 +228,7 @@ filemon_close(struct cdev *dev __unused,
 static void
 filemon_load(void *dummy __unused)
 {
-	mtx_init(&access_mtx, "filemon", "filemon", MTX_DEF);
-	cv_init(&access_cv, "filemon");
+	sx_init(&access_lock, "filemons_inuse");
 
 	/* Install the syscall wrappers. */
 	filemon_wrapper_install();
@@ -270,14 +263,12 @@ filemon_unload(void)
 		filemon_lock_write();
 		while ((filemon = TAILQ_FIRST(&filemons_free)) != NULL) {
 			TAILQ_REMOVE(&filemons_free, filemon, link);
-			mtx_destroy(&filemon->mtx);
-			cv_destroy(&filemon->cv);
+			sx_destroy(&filemon->lock);
 			free(filemon, M_FILEMON);
 		}
 		filemon_unlock_write();
 
-		mtx_destroy(&access_mtx);
-		cv_destroy(&access_cv);
+		sx_destroy(&access_lock);
 	}
 
 	return (error);

Modified: stable/10/sys/dev/filemon/filemon_lock.c
==============================================================================
--- stable/10/sys/dev/filemon/filemon_lock.c	Wed Sep  9 13:24:39 2015	(r287597)
+++ stable/10/sys/dev/filemon/filemon_lock.c	Wed Sep  9 17:15:13 2015	(r287598)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2009-2011, Juniper Networks, Inc.
+ * Copyright (c) 2015, EMC Corp.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,96 +28,44 @@
 #include 
 __FBSDID("$FreeBSD$");
 
-static void
+static __inline void
 filemon_filemon_lock(struct filemon *filemon)
 {
-	mtx_lock(&filemon->mtx);
 
-	while (filemon->locker != NULL && filemon->locker != curthread)
-		cv_wait(&filemon->cv, &filemon->mtx);
-
-	filemon->locker = curthread;
-
-	mtx_unlock(&filemon->mtx);
+	sx_xlock(&filemon->lock);
 }
 
-static void
+static __inline void
 filemon_filemon_unlock(struct filemon *filemon)
 {
-	mtx_lock(&filemon->mtx);
-
-	if (filemon->locker == curthread)
-		filemon->locker = NULL;
 
-	/* Wake up threads waiting. */
-	cv_broadcast(&filemon->cv);
-
-	mtx_unlock(&filemon->mtx);
+	sx_xunlock(&filemon->lock);
 }
 
-static void
+static __inline void
 filemon_lock_read(void)
 {
-	mtx_lock(&access_mtx);
-
-	while (access_owner != NULL || access_requester != NULL)
-		cv_wait(&access_cv, &access_mtx);
-
-	n_readers++;
 
-	/* Wake up threads waiting. */
-	cv_broadcast(&access_cv);
-
-	mtx_unlock(&access_mtx);
+	sx_slock(&access_lock);
 }
 
-static void
+static __inline void
 filemon_unlock_read(void)
 {
-	mtx_lock(&access_mtx);
-
-	if (n_readers > 0)
-		n_readers--;
-
-	/* Wake up a thread waiting. */
-	cv_broadcast(&access_cv);
 
-	mtx_unlock(&access_mtx);
+	sx_sunlock(&access_lock);
 }
 
-static void
+static __inline void
 filemon_lock_write(void)
 {
-	mtx_lock(&access_mtx);
 
-	while (access_owner != curthread) {
-		if (access_owner == NULL &&
-		    (access_requester == NULL ||
-		    access_requester == curthread)) {
-			access_owner = curthread;
-			access_requester = NULL;
-		} else {
-			if (access_requester == NULL)
-				access_requester = curthread;
-
-			cv_wait(&access_cv, &access_mtx);
-		}
-	}
-
-	mtx_unlock(&access_mtx);
+	sx_xlock(&access_lock);
 }
 
-static void
+static __inline void
 filemon_unlock_write(void)
 {
-	mtx_lock(&access_mtx);
-
-	/* Sanity check that the current thread actually has the write lock. */
-	if (access_owner == curthread)
-		access_owner = NULL;
-
-	/* Wake up a thread waiting. */
-	cv_broadcast(&access_cv);
 
-	mtx_unlock(&access_mtx);
+	sx_xunlock(&access_lock);
 }

Modified: stable/10/sys/dev/filemon/filemon_wrapper.c
==============================================================================
--- stable/10/sys/dev/filemon/filemon_wrapper.c	Wed Sep  9 13:24:39 2015	(r287597)
+++ stable/10/sys/dev/filemon/filemon_wrapper.c	Wed Sep  9 17:15:13 2015	(r287598)
@@ -1,6 +1,7 @@
 /*-
  * Copyright (c) 2011, David E. O'Brien.
  * Copyright (c) 2009-2011, Juniper Networks, Inc.
+ * Copyright (c) 2015, EMC Corp.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -86,17 +87,25 @@ filemon_pid_check(struct proc *p)
 {
 	struct filemon *filemon;
 
+	filemon_lock_read();
+	if (TAILQ_EMPTY(&filemons_inuse)) {
+		filemon_unlock_read();
+		return (NULL);
+	}
 	sx_slock(&proctree_lock);
 	while (p != initproc) {
 		TAILQ_FOREACH(filemon, &filemons_inuse, link) {
 			if (p->p_pid == filemon->pid) {
 				sx_sunlock(&proctree_lock);
+				filemon_filemon_lock(filemon);
+				filemon_unlock_read();
 				return (filemon);
 			}
 		}
 		p = proc_realparent(p);
 	}
 	sx_sunlock(&proctree_lock);
+	filemon_unlock_read();
 	return (NULL);
 }
 
@@ -109,9 +118,6 @@ filemon_comment(struct filemon *filemon)
 	/* Load timestamp before locking.  Less accurate but less contention. */
 	getmicrotime(&now);
 
-	/* Grab a read lock on the filemon inuse list. */
-	filemon_lock_read();
-
 	/* Lock the found filemon structure. */
 	filemon_filemon_lock(filemon);
 
@@ -124,9 +130,6 @@ filemon_comment(struct filemon *filemon)
 
 	/* Unlock the found filemon structure. */
 	filemon_filemon_unlock(filemon);
-
-	/* Release the read lock. */
-	filemon_unlock_read();
 }
 
 static int
@@ -138,13 +141,7 @@ filemon_wrapper_chdir(struct thread *td,
 	struct filemon *filemon;
 
 	if ((ret = sys_chdir(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->path, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 
@@ -157,9 +154,6 @@ filemon_wrapper_chdir(struct thread *td,
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -177,13 +171,7 @@ filemon_wrapper_execve(struct thread *td
 	copyinstr(uap->fname, fname, sizeof(fname), &done);
 
 	if ((ret = sys_execve(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			len = snprintf(filemon->msgbufr,
 			    sizeof(filemon->msgbufr), "E %d %s\n",
 			    curproc->p_pid, fname);
@@ -193,9 +181,6 @@ filemon_wrapper_execve(struct thread *td
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -215,13 +200,7 @@ filemon_wrapper_freebsd32_execve(struct 
 	copyinstr(uap->fname, fname, sizeof(fname), &done);
 
 	if ((ret = freebsd32_execve(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			len = snprintf(filemon->msgbufr,
 			    sizeof(filemon->msgbufr), "E %d %s\n",
 			    curproc->p_pid, fname);
@@ -231,9 +210,6 @@ filemon_wrapper_freebsd32_execve(struct 
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -248,13 +224,7 @@ filemon_wrapper_fork(struct thread *td, 
 	struct filemon *filemon;
 
 	if ((ret = sys_fork(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			len = snprintf(filemon->msgbufr,
 			    sizeof(filemon->msgbufr), "F %d %ld\n",
 			    curproc->p_pid, (long)curthread->td_retval[0]);
@@ -264,9 +234,6 @@ filemon_wrapper_fork(struct thread *td, 
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -281,13 +248,7 @@ filemon_wrapper_open(struct thread *td, 
 	struct filemon *filemon;
 
 	if ((ret = sys_open(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->path, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 
@@ -313,9 +274,6 @@ filemon_wrapper_open(struct thread *td, 
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -330,13 +288,7 @@ filemon_wrapper_openat(struct thread *td
 	struct filemon *filemon;
 
 	if ((ret = sys_openat(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->path, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 
@@ -375,9 +327,6 @@ filemon_wrapper_openat(struct thread *td
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -392,13 +341,7 @@ filemon_wrapper_rename(struct thread *td
 	struct filemon *filemon;
 
 	if ((ret = sys_rename(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->from, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 			copyinstr(uap->to, filemon->fname2,
@@ -413,9 +356,6 @@ filemon_wrapper_rename(struct thread *td
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -430,13 +370,7 @@ filemon_wrapper_link(struct thread *td, 
 	struct filemon *filemon;
 
 	if ((ret = sys_link(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->path, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 			copyinstr(uap->link, filemon->fname2,
@@ -451,9 +385,6 @@ filemon_wrapper_link(struct thread *td, 
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -468,13 +399,7 @@ filemon_wrapper_symlink(struct thread *t
 	struct filemon *filemon;
 
 	if ((ret = sys_symlink(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->path, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 			copyinstr(uap->link, filemon->fname2,
@@ -489,9 +414,6 @@ filemon_wrapper_symlink(struct thread *t
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -507,13 +429,7 @@ filemon_wrapper_linkat(struct thread *td
 	struct filemon *filemon;
 
 	if ((ret = sys_linkat(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->path1, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 			copyinstr(uap->path2, filemon->fname2,
@@ -528,9 +444,6 @@ filemon_wrapper_linkat(struct thread *td
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -546,13 +459,7 @@ filemon_wrapper_stat(struct thread *td, 
 	struct filemon *filemon;
 
 	if ((ret = sys_stat(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->path, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 
@@ -565,9 +472,6 @@ filemon_wrapper_stat(struct thread *td, 
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -584,13 +488,7 @@ filemon_wrapper_freebsd32_stat(struct th
 	struct filemon *filemon;
 
 	if ((ret = freebsd32_stat(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->path, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 
@@ -603,9 +501,6 @@ filemon_wrapper_freebsd32_stat(struct th
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -622,13 +517,7 @@ filemon_wrapper_sys_exit(struct thread *
 	/* Get timestamp before locking. */
 	getmicrotime(&now);
 
-	/* Grab a read lock on the filemon inuse list. */
-	filemon_lock_read();
-
 	if ((filemon = filemon_pid_check(curproc)) != NULL) {
-		/* Lock the found filemon structure. */
-		filemon_filemon_lock(filemon);
-
 		len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr),
 		    "X %d %d\n", curproc->p_pid, uap->rval);
 
@@ -649,9 +538,6 @@ filemon_wrapper_sys_exit(struct thread *
 		filemon_filemon_unlock(filemon);
 	}
 
-	/* Release the read lock. */
-	filemon_unlock_read();
-
 	sys_sys_exit(td, uap);
 }
 
@@ -664,13 +550,7 @@ filemon_wrapper_unlink(struct thread *td
 	struct filemon *filemon;
 
 	if ((ret = sys_unlink(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			copyinstr(uap->path, filemon->fname1,
 			    sizeof(filemon->fname1), &done);
 
@@ -683,9 +563,6 @@ filemon_wrapper_unlink(struct thread *td
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);
@@ -699,13 +576,7 @@ filemon_wrapper_vfork(struct thread *td,
 	struct filemon *filemon;
 
 	if ((ret = sys_vfork(td, uap)) == 0) {
-		/* Grab a read lock on the filemon inuse list. */
-		filemon_lock_read();
-
 		if ((filemon = filemon_pid_check(curproc)) != NULL) {
-			/* Lock the found filemon structure. */
-			filemon_filemon_lock(filemon);
-
 			len = snprintf(filemon->msgbufr,
 			    sizeof(filemon->msgbufr), "F %d %ld\n",
 			    curproc->p_pid, (long)curthread->td_retval[0]);
@@ -715,9 +586,6 @@ filemon_wrapper_vfork(struct thread *td,
 			/* Unlock the found filemon structure. */
 			filemon_filemon_unlock(filemon);
 		}
-
-		/* Release the read lock. */
-		filemon_unlock_read();
 	}
 
 	return (ret);

From owner-svn-src-stable-10@freebsd.org  Wed Sep  9 23:39:32 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB1ECA005F9;
 Wed,  9 Sep 2015 23:39:32 +0000 (UTC) (envelope-from jhb@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id B9AAD1357;
 Wed,  9 Sep 2015 23:39:32 +0000 (UTC) (envelope-from jhb@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t89NdWdE058429;
 Wed, 9 Sep 2015 23:39:32 GMT (envelope-from jhb@FreeBSD.org)
Received: (from jhb@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t89NdV7S058424;
 Wed, 9 Sep 2015 23:39:31 GMT (envelope-from jhb@FreeBSD.org)
Message-Id: <201509092339.t89NdV7S058424@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org
 using -f
From: John Baldwin 
Date: Wed, 9 Sep 2015 23:39:31 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287604 - in stable/10: sys/fs/procfs sys/kern
 tests/sys/kern
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Wed, 09 Sep 2015 23:39:32 -0000

Author: jhb
Date: Wed Sep  9 23:39:30 2015
New Revision: 287604
URL: https://svnweb.freebsd.org/changeset/base/287604

Log:
  MFC 283281,283282,283562,283647,283836,284000,286158:
  Various fixes to orphan handling which also fix issues with following
  forks.
  
  283281:
  Always set p_oppid when attaching to an existing process via procfs
  tracing.  This matches the behavior of ptrace(PT_ATTACH).  Also,
  the procfs detach request assumes p_oppid is always set.
  
  283282:
  Only reparent a traced process to its old parent if the tracing process is
  not the old parent. Otherwise, proc_reap() will leave the zombie in place
  resulting in the process' status being returned twice to its parent.
  
  Add test cases for PT_TRACE_ME and PT_ATTACH which are fixed by
  this change.
  
  283562:
  Do not allow a process to reap an orphan (a child currently being
  traced by another process such as a debugger). The parent process does
  need to check for matching orphan pids to avoid returning ECHILD if an
  orphan has exited, but it should not return the exited status for the
  child until after the debugger has detached from the orphan process
  either explicitly or implicitly via wait().
  
  Add two tests for for this case: one where the debugger is the direct
  child (thus the parent has a non-empty children list) and one where
  the debugger is not a direct child (so the only "child" of the parent
  is the orphan).
  
  283647:
  Tweak the description of when waitpid() doesn't return any status for a
  non-blocking wait to avoid the word "empty".
  
  283836:
  Consistently only use one end of the pipe in the parent and debugger
  processes and do not rely on EOF due to a close() in the debugger.
  
  284000:
  Add a CHILD_REQUIRE macro similar to ATF_REQUIRE for use in child processes
  of the main test process.
  
  286158:
  Clear P_TRACED before reparenting a detached process back to its
  original parent. Otherwise the debugee will be set as an orphan of
  the debugger.
  
  Add tests for tracing forks via PT_FOLLOW_FORK.

Added:
  stable/10/tests/sys/kern/ptrace_test.c
     - copied, changed from r283282, head/tests/sys/kern/ptrace_test.c
Modified:
  stable/10/sys/fs/procfs/procfs_ctl.c
  stable/10/sys/kern/kern_exit.c
  stable/10/sys/kern/sys_process.c
  stable/10/tests/sys/kern/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/fs/procfs/procfs_ctl.c
==============================================================================
--- stable/10/sys/fs/procfs/procfs_ctl.c	Wed Sep  9 23:05:52 2015	(r287603)
+++ stable/10/sys/fs/procfs/procfs_ctl.c	Wed Sep  9 23:39:30 2015	(r287604)
@@ -143,8 +143,8 @@ procfs_control(struct thread *td, struct
 		p->p_flag |= P_TRACED;
 		faultin(p);
 		p->p_xstat = 0;		/* XXX ? */
+		p->p_oppid = p->p_pptr->p_pid;
 		if (p->p_pptr != td->td_proc) {
-			p->p_oppid = p->p_pptr->p_pid;
 			proc_reparent(p, td->td_proc);
 		}
 		kern_psignal(p, SIGSTOP);

Modified: stable/10/sys/kern/kern_exit.c
==============================================================================
--- stable/10/sys/kern/kern_exit.c	Wed Sep  9 23:05:52 2015	(r287603)
+++ stable/10/sys/kern/kern_exit.c	Wed Sep  9 23:39:30 2015	(r287604)
@@ -857,13 +857,13 @@ proc_reap(struct thread *td, struct proc
 	PROC_LOCK(q);
 	sigqueue_take(p->p_ksi);
 	PROC_UNLOCK(q);
-	PROC_UNLOCK(p);
 
 	/*
 	 * If we got the child via a ptrace 'attach', we need to give it back
 	 * to the old parent.
 	 */
-	if (p->p_oppid != 0) {
+	if (p->p_oppid != 0 && p->p_oppid != p->p_pptr->p_pid) {
+		PROC_UNLOCK(p);
 		t = proc_realparent(p);
 		PROC_LOCK(t);
 		PROC_LOCK(p);
@@ -880,6 +880,8 @@ proc_reap(struct thread *td, struct proc
 		sx_xunlock(&proctree_lock);
 		return;
 	}
+	p->p_oppid = 0;
+	PROC_UNLOCK(p);
 
 	/*
 	 * Remove other references to this process to ensure we have an
@@ -962,7 +964,8 @@ proc_reap(struct thread *td, struct proc
 
 static int
 proc_to_reap(struct thread *td, struct proc *p, idtype_t idtype, id_t id,
-    int *status, int options, struct __wrusage *wrusage, siginfo_t *siginfo)
+    int *status, int options, struct __wrusage *wrusage, siginfo_t *siginfo,
+    int check_only)
 {
 	struct rusage *rup;
 
@@ -1098,7 +1101,7 @@ proc_to_reap(struct thread *td, struct p
 		calccru(p, &rup->ru_utime, &rup->ru_stime);
 	}
 
-	if (p->p_state == PRS_ZOMBIE) {
+	if (p->p_state == PRS_ZOMBIE && !check_only) {
 		proc_reap(td, p, status, options);
 		return (-1);
 	}
@@ -1192,7 +1195,7 @@ loop:
 	sx_xlock(&proctree_lock);
 	LIST_FOREACH(p, &q->p_children, p_sibling) {
 		ret = proc_to_reap(td, p, idtype, id, status, options,
-		    wrusage, siginfo);
+		    wrusage, siginfo, 0);
 		if (ret == 0)
 			continue;
 		else if (ret == 1)
@@ -1294,15 +1297,17 @@ loop:
 	 * 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, idtype, id, status, options,
-		    wrusage, siginfo);
-		if (ret == 0)
-			continue;
-		else if (ret == 1)
-			nfound++;
-		else
-			return (0);
+	if (nfound == 0) {
+		LIST_FOREACH(p, &q->p_orphans, p_orphan) {
+			ret = proc_to_reap(td, p, idtype, id, NULL, options,
+			    NULL, NULL, 1);
+			if (ret != 0) {
+				KASSERT(ret != -1, ("reaped an orphan (pid %d)",
+				    (int)td->td_retval[0]));
+				nfound++;
+				break;
+			}
+		}
 	}
 	if (nfound == 0) {
 		sx_xunlock(&proctree_lock);

Modified: stable/10/sys/kern/sys_process.c
==============================================================================
--- stable/10/sys/kern/sys_process.c	Wed Sep  9 23:05:52 2015	(r287603)
+++ stable/10/sys/kern/sys_process.c	Wed Sep  9 23:39:30 2015	(r287604)
@@ -946,7 +946,15 @@ kern_ptrace(struct thread *td, int req, 
 			}
 			break;
 		case PT_DETACH:
-			/* reset process parent */
+			/*
+			 * Reset the process parent.
+			 *
+			 * NB: This clears P_TRACED before reparenting
+			 * a detached process back to its original
+			 * parent.  Otherwise the debugee will be set
+			 * as an orphan of the debugger.
+			 */
+			p->p_flag &= ~(P_TRACED | P_WAITED | P_FOLLOWFORK);
 			if (p->p_oppid != p->p_pptr->p_pid) {
 				PROC_LOCK(p->p_pptr);
 				sigqueue_take(p->p_ksi);
@@ -962,7 +970,6 @@ kern_ptrace(struct thread *td, int req, 
 			} else
 				CTR1(KTR_PTRACE, "PT_DETACH: pid %d", p->p_pid);
 			p->p_oppid = 0;
-			p->p_flag &= ~(P_TRACED | P_WAITED | P_FOLLOWFORK);
 			p->p_stops = 0;
 
 			/* should we send SIGCHLD? */

Modified: stable/10/tests/sys/kern/Makefile
==============================================================================
--- stable/10/tests/sys/kern/Makefile	Wed Sep  9 23:05:52 2015	(r287603)
+++ stable/10/tests/sys/kern/Makefile	Wed Sep  9 23:39:30 2015	(r287604)
@@ -3,6 +3,7 @@
 TESTSDIR=	${TESTSBASE}/sys/kern
 
 ATF_TESTS_C+=	kern_descrip_test
+ATF_TESTS_C+=	ptrace_test
 ATF_TESTS_C+=	unix_seqpacket_test
 TEST_METADATA.unix_seqpacket_test+=	timeout="15"
 

Copied and modified: stable/10/tests/sys/kern/ptrace_test.c (from r283282, head/tests/sys/kern/ptrace_test.c)
==============================================================================
--- head/tests/sys/kern/ptrace_test.c	Fri May 22 11:04:54 2015	(r283282, copy source)
+++ stable/10/tests/sys/kern/ptrace_test.c	Wed Sep  9 23:39:30 2015	(r287604)
@@ -29,14 +29,90 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
 /*
+ * A variant of ATF_REQUIRE that is suitable for use in child
+ * processes.  This only works if the parent process is tripped up by
+ * the early exit and fails some requirement itself.
+ */
+#define	CHILD_REQUIRE(exp) do {						\
+		if (!(exp))						\
+			child_fail_require(__FILE__, __LINE__,		\
+			    #exp " not met");				\
+	} while (0)
+
+static __dead2 void
+child_fail_require(const char *file, int line, const char *str)
+{
+	char buf[128];
+
+	snprintf(buf, sizeof(buf), "%s:%d: %s\n", file, line, str);
+	write(2, buf, strlen(buf));
+	_exit(32);
+}
+
+static void
+trace_me(void)
+{
+
+	/* Attach the parent process as a tracer of this process. */
+	CHILD_REQUIRE(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+	/* Trigger a stop. */
+	raise(SIGSTOP);
+}
+
+static void
+attach_child(pid_t pid)
+{
+	pid_t wpid;
+	int status;
+
+	ATF_REQUIRE(ptrace(PT_ATTACH, pid, NULL, 0) == 0);
+
+	wpid = waitpid(pid, &status, 0);
+	ATF_REQUIRE(wpid == pid);
+	ATF_REQUIRE(WIFSTOPPED(status));
+	ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+}
+
+static void
+wait_for_zombie(pid_t pid)
+{
+
+	/*
+	 * Wait for a process to exit.  This is kind of gross, but
+	 * there is not a better way.
+	 */
+	for (;;) {
+		struct kinfo_proc kp;
+		size_t len;
+		int mib[4];
+
+		mib[0] = CTL_KERN;
+		mib[1] = KERN_PROC;
+		mib[2] = KERN_PROC_PID;
+		mib[3] = pid;
+		len = sizeof(kp);
+		if (sysctl(mib, nitems(mib), &kp, &len, NULL, 0) == -1) {
+			/* The KERN_PROC_PID sysctl fails for zombies. */
+			ATF_REQUIRE(errno == ESRCH);
+			break;
+		}
+		usleep(5000);
+	}
+}
+
+/*
  * Verify that a parent debugger process "sees" the exit of a debugged
  * process exactly once when attached via PT_TRACE_ME.
  */
@@ -49,10 +125,7 @@ ATF_TC_BODY(ptrace__parent_wait_after_tr
 	ATF_REQUIRE((child = fork()) != -1);
 	if (child == 0) {
 		/* Child process. */
-		ATF_REQUIRE(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
-		/* Trigger a stop. */
-		raise(SIGSTOP);
+		trace_me();
 
 		exit(1);
 	}
@@ -98,7 +171,7 @@ ATF_TC_BODY(ptrace__parent_wait_after_at
 		close(cpipe[0]);
 
 		/* Wait for the parent to attach. */
-		ATF_REQUIRE(read(cpipe[1], &c, sizeof(c)) == 0);
+		CHILD_REQUIRE(read(cpipe[1], &c, sizeof(c)) == 0);
 
 		exit(1);
 	}
@@ -107,13 +180,7 @@ ATF_TC_BODY(ptrace__parent_wait_after_at
 	/* Parent process. */
 
 	/* Attach to the child process. */
-	ATF_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) == 0);
-
-	/* The first wait() should report the SIGSTOP from PT_ATTACH. */
-	wpid = waitpid(child, &status, 0);
-	ATF_REQUIRE(wpid == child);
-	ATF_REQUIRE(WIFSTOPPED(status));
-	ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+	attach_child(child);
 
 	/* Continue the child ignoring the SIGSTOP. */
 	ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
@@ -133,11 +200,687 @@ ATF_TC_BODY(ptrace__parent_wait_after_at
 	ATF_REQUIRE(errno == ECHILD);
 }
 
+/*
+ * Verify that a parent process "sees" the exit of a debugged process only
+ * after the debugger has seen it.
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__parent_sees_exit_after_child_debugger);
+ATF_TC_BODY(ptrace__parent_sees_exit_after_child_debugger, tc)
+{
+	pid_t child, debugger, wpid;
+	int cpipe[2], dpipe[2], status;
+	char c;
+
+	ATF_REQUIRE(pipe(cpipe) == 0);
+	ATF_REQUIRE((child = fork()) != -1);
+
+	if (child == 0) {
+		/* Child process. */
+		close(cpipe[0]);
+
+		/* Wait for parent to be ready. */
+		CHILD_REQUIRE(read(cpipe[1], &c, sizeof(c)) == sizeof(c));
+
+		exit(1);
+	}
+	close(cpipe[1]);
+
+	ATF_REQUIRE(pipe(dpipe) == 0);
+	ATF_REQUIRE((debugger = fork()) != -1);
+
+	if (debugger == 0) {
+		/* Debugger process. */
+		close(dpipe[0]);
+
+		CHILD_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
+
+		wpid = waitpid(child, &status, 0);
+		CHILD_REQUIRE(wpid == child);
+		CHILD_REQUIRE(WIFSTOPPED(status));
+		CHILD_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+
+		CHILD_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
+
+		/* Signal parent that debugger is attached. */
+		CHILD_REQUIRE(write(dpipe[1], &c, sizeof(c)) == sizeof(c));
+
+		/* Wait for parent's failed wait. */
+		CHILD_REQUIRE(read(dpipe[1], &c, sizeof(c)) == 0);
+
+		wpid = waitpid(child, &status, 0);
+		CHILD_REQUIRE(wpid == child);
+		CHILD_REQUIRE(WIFEXITED(status));
+		CHILD_REQUIRE(WEXITSTATUS(status) == 1);
+
+		exit(0);
+	}
+	close(dpipe[1]);
+
+	/* Parent process. */
+
+	/* Wait for the debugger to attach to the child. */
+	ATF_REQUIRE(read(dpipe[0], &c, sizeof(c)) == sizeof(c));
+
+	/* Release the child. */
+	ATF_REQUIRE(write(cpipe[0], &c, sizeof(c)) == sizeof(c));
+	ATF_REQUIRE(read(cpipe[0], &c, sizeof(c)) == 0);
+	close(cpipe[0]);
+
+	wait_for_zombie(child);
+
+	/*
+	 * This wait should return a pid of 0 to indicate no status to
+	 * report.  The parent should see the child as non-exited
+	 * until the debugger sees the exit.
+	 */
+	wpid = waitpid(child, &status, WNOHANG);
+	ATF_REQUIRE(wpid == 0);
+
+	/* Signal the debugger to wait for the child. */
+	close(dpipe[0]);
+
+	/* Wait for the debugger. */
+	wpid = waitpid(debugger, &status, 0);
+	ATF_REQUIRE(wpid == debugger);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 0);
+
+	/* The child process should now be ready. */
+	wpid = waitpid(child, &status, WNOHANG);
+	ATF_REQUIRE(wpid == child);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 1);
+}
+
+/*
+ * Verify that a parent process "sees" the exit of a debugged process
+ * only after a non-direct-child debugger has seen it.  In particular,
+ * various wait() calls in the parent must avoid failing with ESRCH by
+ * checking the parent's orphan list for the debugee.
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__parent_sees_exit_after_unrelated_debugger);
+ATF_TC_BODY(ptrace__parent_sees_exit_after_unrelated_debugger, tc)
+{
+	pid_t child, debugger, fpid, wpid;
+	int cpipe[2], dpipe[2], status;
+	char c;
+
+	ATF_REQUIRE(pipe(cpipe) == 0);
+	ATF_REQUIRE((child = fork()) != -1);
+
+	if (child == 0) {
+		/* Child process. */
+		close(cpipe[0]);
+
+		/* Wait for parent to be ready. */
+		CHILD_REQUIRE(read(cpipe[1], &c, sizeof(c)) == sizeof(c));
+
+		exit(1);
+	}
+	close(cpipe[1]);
+
+	ATF_REQUIRE(pipe(dpipe) == 0);
+	ATF_REQUIRE((debugger = fork()) != -1);
+
+	if (debugger == 0) {
+		/* Debugger parent. */
+
+		/*
+		 * Fork again and drop the debugger parent so that the
+		 * debugger is not a child of the main parent.
+		 */
+		CHILD_REQUIRE((fpid = fork()) != -1);
+		if (fpid != 0)
+			exit(2);
+
+		/* Debugger process. */
+		close(dpipe[0]);
+
+		CHILD_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
+
+		wpid = waitpid(child, &status, 0);
+		CHILD_REQUIRE(wpid == child);
+		CHILD_REQUIRE(WIFSTOPPED(status));
+		CHILD_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+
+		CHILD_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
+
+		/* Signal parent that debugger is attached. */
+		CHILD_REQUIRE(write(dpipe[1], &c, sizeof(c)) == sizeof(c));
+
+		/* Wait for parent's failed wait. */
+		CHILD_REQUIRE(read(dpipe[1], &c, sizeof(c)) == sizeof(c));
+
+		wpid = waitpid(child, &status, 0);
+		CHILD_REQUIRE(wpid == child);
+		CHILD_REQUIRE(WIFEXITED(status));
+		CHILD_REQUIRE(WEXITSTATUS(status) == 1);
+
+		exit(0);
+	}
+	close(dpipe[1]);
+
+	/* Parent process. */
+
+	/* Wait for the debugger parent process to exit. */
+	wpid = waitpid(debugger, &status, 0);
+	ATF_REQUIRE(wpid == debugger);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 2);
+
+	/* A WNOHANG wait here should see the non-exited child. */
+	wpid = waitpid(child, &status, WNOHANG);
+	ATF_REQUIRE(wpid == 0);
+
+	/* Wait for the debugger to attach to the child. */
+	ATF_REQUIRE(read(dpipe[0], &c, sizeof(c)) == sizeof(c));
+
+	/* Release the child. */
+	ATF_REQUIRE(write(cpipe[0], &c, sizeof(c)) == sizeof(c));
+	ATF_REQUIRE(read(cpipe[0], &c, sizeof(c)) == 0);
+	close(cpipe[0]);
+
+	wait_for_zombie(child);
+
+	/*
+	 * This wait should return a pid of 0 to indicate no status to
+	 * report.  The parent should see the child as non-exited
+	 * until the debugger sees the exit.
+	 */
+	wpid = waitpid(child, &status, WNOHANG);
+	ATF_REQUIRE(wpid == 0);
+
+	/* Signal the debugger to wait for the child. */
+	ATF_REQUIRE(write(dpipe[0], &c, sizeof(c)) == sizeof(c));
+
+	/* Wait for the debugger. */
+	ATF_REQUIRE(read(dpipe[0], &c, sizeof(c)) == 0);
+	close(dpipe[0]);
+
+	/* The child process should now be ready. */
+	wpid = waitpid(child, &status, WNOHANG);
+	ATF_REQUIRE(wpid == child);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 1);
+}
+
+/*
+ * The parent process should always act the same regardless of how the
+ * debugger is attached to it.
+ */
+static __dead2 void
+follow_fork_parent(void)
+{
+	pid_t fpid, wpid;
+	int status;
+
+	CHILD_REQUIRE((fpid = fork()) != -1);
+
+	if (fpid == 0)
+		/* Child */
+		exit(2);
+
+	wpid = waitpid(fpid, &status, 0);
+	CHILD_REQUIRE(wpid == fpid);
+	CHILD_REQUIRE(WIFEXITED(status));
+	CHILD_REQUIRE(WEXITSTATUS(status) == 2);
+
+	exit(1);
+}
+
+/*
+ * Helper routine for follow fork tests.  This waits for two stops
+ * that report both "sides" of a fork.  It returns the pid of the new
+ * child process.
+ */
+static pid_t
+handle_fork_events(pid_t parent)
+{
+	struct ptrace_lwpinfo pl;
+	bool fork_reported[2];
+	pid_t child, wpid;
+	int i, status;
+
+	fork_reported[0] = false;
+	fork_reported[1] = false;
+	child = -1;
+	
+	/*
+	 * Each process should report a fork event.  The parent should
+	 * report a PL_FLAG_FORKED event, and the child should report
+	 * a PL_FLAG_CHILD event.
+	 */
+	for (i = 0; i < 2; i++) {
+		wpid = wait(&status);
+		ATF_REQUIRE(wpid > 0);
+		ATF_REQUIRE(WIFSTOPPED(status));
+
+		ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
+		    sizeof(pl)) != -1);
+		ATF_REQUIRE((pl.pl_flags & (PL_FLAG_FORKED | PL_FLAG_CHILD)) !=
+		    0);
+		ATF_REQUIRE((pl.pl_flags & (PL_FLAG_FORKED | PL_FLAG_CHILD)) !=
+		    (PL_FLAG_FORKED | PL_FLAG_CHILD));
+		if (pl.pl_flags & PL_FLAG_CHILD) {
+			ATF_REQUIRE(wpid != parent);
+			ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+			ATF_REQUIRE(!fork_reported[1]);
+			if (child == -1)
+				child = wpid;
+			else
+				ATF_REQUIRE(child == wpid);
+			fork_reported[1] = true;
+		} else {
+			ATF_REQUIRE(wpid == parent);
+			ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
+			ATF_REQUIRE(!fork_reported[0]);
+			if (child == -1)
+				child = pl.pl_child_pid;
+			else
+				ATF_REQUIRE(child == pl.pl_child_pid);
+			fork_reported[0] = true;
+		}
+	}
+
+	return (child);
+}
+
+/*
+ * Verify that a new child process is stopped after a followed fork and
+ * that the traced parent sees the exit of the child after the debugger
+ * when both processes remain attached to the debugger.
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_both_attached);
+ATF_TC_BODY(ptrace__follow_fork_both_attached, tc)
+{
+	pid_t children[0], fpid, wpid;
+	int status;
+
+	ATF_REQUIRE((fpid = fork()) != -1);
+	if (fpid == 0) {
+		trace_me();
+		follow_fork_parent();
+	}
+
+	/* Parent process. */
+	children[0] = fpid;
+
+	/* The first wait() should report the stop from SIGSTOP. */
+	wpid = waitpid(children[0], &status, 0);
+	ATF_REQUIRE(wpid == children[0]);
+	ATF_REQUIRE(WIFSTOPPED(status));
+	ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+
+	ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
+
+	/* Continue the child ignoring the SIGSTOP. */
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+
+	children[1] = handle_fork_events(children[0]);
+	ATF_REQUIRE(children[1] > 0);
+
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
+
+	/*
+	 * The child can't exit until the grandchild reports status, so the
+	 * grandchild should report its exit first to the debugger.
+	 */
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == children[1]);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 2);
+
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == children[0]);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 1);
+
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == -1);
+	ATF_REQUIRE(errno == ECHILD);
+}
+
+/*
+ * Verify that a new child process is stopped after a followed fork
+ * and that the traced parent sees the exit of the child when the new
+ * child process is detached after it reports its fork.
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_child_detached);
+ATF_TC_BODY(ptrace__follow_fork_child_detached, tc)
+{
+	pid_t children[0], fpid, wpid;
+	int status;
+
+	ATF_REQUIRE((fpid = fork()) != -1);
+	if (fpid == 0) {
+		trace_me();
+		follow_fork_parent();
+	}
+
+	/* Parent process. */
+	children[0] = fpid;
+
+	/* The first wait() should report the stop from SIGSTOP. */
+	wpid = waitpid(children[0], &status, 0);
+	ATF_REQUIRE(wpid == children[0]);
+	ATF_REQUIRE(WIFSTOPPED(status));
+	ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+
+	ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
+
+	/* Continue the child ignoring the SIGSTOP. */
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+
+	children[1] = handle_fork_events(children[0]);
+	ATF_REQUIRE(children[1] > 0);
+
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+	ATF_REQUIRE(ptrace(PT_DETACH, children[1], (caddr_t)1, 0) != -1);
+
+	/*
+	 * Should not see any status from the grandchild now, only the
+	 * child.
+	 */
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == children[0]);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 1);
+
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == -1);
+	ATF_REQUIRE(errno == ECHILD);
+}
+
+/*
+ * Verify that a new child process is stopped after a followed fork
+ * and that the traced parent sees the exit of the child when the
+ * traced parent is detached after the fork.
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_parent_detached);
+ATF_TC_BODY(ptrace__follow_fork_parent_detached, tc)
+{
+	pid_t children[0], fpid, wpid;
+	int status;
+
+	ATF_REQUIRE((fpid = fork()) != -1);
+	if (fpid == 0) {
+		trace_me();
+		follow_fork_parent();
+	}
+
+	/* Parent process. */
+	children[0] = fpid;
+
+	/* The first wait() should report the stop from SIGSTOP. */
+	wpid = waitpid(children[0], &status, 0);
+	ATF_REQUIRE(wpid == children[0]);
+	ATF_REQUIRE(WIFSTOPPED(status));
+	ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+
+	ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
+
+	/* Continue the child ignoring the SIGSTOP. */
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+
+	children[1] = handle_fork_events(children[0]);
+	ATF_REQUIRE(children[1] > 0);
+
+	ATF_REQUIRE(ptrace(PT_DETACH, children[0], (caddr_t)1, 0) != -1);
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
+
+	/*
+	 * The child can't exit until the grandchild reports status, so the
+	 * grandchild should report its exit first to the debugger.
+	 *
+	 * Even though the child process is detached, it is still a
+	 * child of the debugger, so it will still report it's exit
+	 * after the grandchild.
+	 */
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == children[1]);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 2);
+
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == children[0]);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 1);
+
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == -1);
+	ATF_REQUIRE(errno == ECHILD);
+}
+
+static void
+attach_fork_parent(int cpipe[2])
+{
+	pid_t fpid;
+
+	close(cpipe[0]);
+
+	/* Double-fork to disassociate from the debugger. */
+	CHILD_REQUIRE((fpid = fork()) != -1);
+	if (fpid != 0)
+		exit(3);
+	
+	/* Send the pid of the disassociated child to the debugger. */
+	fpid = getpid();
+	CHILD_REQUIRE(write(cpipe[1], &fpid, sizeof(fpid)) == sizeof(fpid));
+
+	/* Wait for the debugger to attach. */
+	CHILD_REQUIRE(read(cpipe[1], &fpid, sizeof(fpid)) == 0);
+}
+
+/*
+ * Verify that a new child process is stopped after a followed fork and
+ * that the traced parent sees the exit of the child after the debugger
+ * when both processes remain attached to the debugger.  In this test
+ * the parent that forks is not a direct child of the debugger.
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_both_attached_unrelated_debugger);
+ATF_TC_BODY(ptrace__follow_fork_both_attached_unrelated_debugger, tc)
+{
+	pid_t children[0], fpid, wpid;
+	int cpipe[2], status;
+
+	ATF_REQUIRE(pipe(cpipe) == 0);
+	ATF_REQUIRE((fpid = fork()) != -1);
+	if (fpid == 0) {
+		attach_fork_parent(cpipe);
+		follow_fork_parent();
+	}
+
+	/* Parent process. */
+	close(cpipe[1]);
+
+	/* Wait for the direct child to exit. */
+	wpid = waitpid(fpid, &status, 0);
+	ATF_REQUIRE(wpid == fpid);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 3);
+
+	/* Read the pid of the fork parent. */
+	ATF_REQUIRE(read(cpipe[0], &children[0], sizeof(children[0])) ==
+	    sizeof(children[0]));
+
+	/* Attach to the fork parent. */
+	attach_child(children[0]);
+
+	ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
+
+	/* Continue the fork parent ignoring the SIGSTOP. */
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+
+	/* Signal the fork parent to continue. */
+	close(cpipe[0]);
+
+	children[1] = handle_fork_events(children[0]);
+	ATF_REQUIRE(children[1] > 0);
+
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
+
+	/*
+	 * The fork parent can't exit until the child reports status,
+	 * so the child should report its exit first to the debugger.
+	 */
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == children[1]);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 2);
+
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == children[0]);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 1);
+
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == -1);
+	ATF_REQUIRE(errno == ECHILD);
+}
+
+/*
+ * Verify that a new child process is stopped after a followed fork
+ * and that the traced parent sees the exit of the child when the new
+ * child process is detached after it reports its fork.  In this test
+ * the parent that forks is not a direct child of the debugger.
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_child_detached_unrelated_debugger);
+ATF_TC_BODY(ptrace__follow_fork_child_detached_unrelated_debugger, tc)
+{
+	pid_t children[0], fpid, wpid;
+	int cpipe[2], status;
+
+	ATF_REQUIRE(pipe(cpipe) == 0);
+	ATF_REQUIRE((fpid = fork()) != -1);
+	if (fpid == 0) {
+		attach_fork_parent(cpipe);
+		follow_fork_parent();
+	}
+
+	/* Parent process. */
+	close(cpipe[1]);
+
+	/* Wait for the direct child to exit. */
+	wpid = waitpid(fpid, &status, 0);
+	ATF_REQUIRE(wpid == fpid);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 3);
+
+	/* Read the pid of the fork parent. */
+	ATF_REQUIRE(read(cpipe[0], &children[0], sizeof(children[0])) ==
+	    sizeof(children[0]));
+
+	/* Attach to the fork parent. */
+	attach_child(children[0]);
+
+	ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
+
+	/* Continue the fork parent ignoring the SIGSTOP. */
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+
+	/* Signal the fork parent to continue. */
+	close(cpipe[0]);
+
+	children[1] = handle_fork_events(children[0]);
+	ATF_REQUIRE(children[1] > 0);
+
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+	ATF_REQUIRE(ptrace(PT_DETACH, children[1], (caddr_t)1, 0) != -1);
+
+	/*
+	 * Should not see any status from the child now, only the fork
+	 * parent.
+	 */
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == children[0]);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 1);
+
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == -1);
+	ATF_REQUIRE(errno == ECHILD);
+}
+
+/*
+ * Verify that a new child process is stopped after a followed fork
+ * and that the traced parent sees the exit of the child when the
+ * traced parent is detached after the fork.  In this test the parent
+ * that forks is not a direct child of the debugger.
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__follow_fork_parent_detached_unrelated_debugger);
+ATF_TC_BODY(ptrace__follow_fork_parent_detached_unrelated_debugger, tc)
+{
+	pid_t children[0], fpid, wpid;
+	int cpipe[2], status;
+
+	ATF_REQUIRE(pipe(cpipe) == 0);
+	ATF_REQUIRE((fpid = fork()) != -1);
+	if (fpid == 0) {
+		attach_fork_parent(cpipe);
+		follow_fork_parent();
+	}
+
+	/* Parent process. */
+	close(cpipe[1]);
+
+	/* Wait for the direct child to exit. */
+	wpid = waitpid(fpid, &status, 0);
+	ATF_REQUIRE(wpid == fpid);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 3);
+
+	/* Read the pid of the fork parent. */
+	ATF_REQUIRE(read(cpipe[0], &children[0], sizeof(children[0])) ==
+	    sizeof(children[0]));
+
+	/* Attach to the fork parent. */
+	attach_child(children[0]);
+
+	ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
+
+	/* Continue the fork parent ignoring the SIGSTOP. */
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
+
+	/* Signal the fork parent to continue. */
+	close(cpipe[0]);
+
+	children[1] = handle_fork_events(children[0]);
+	ATF_REQUIRE(children[1] > 0);
+
+	ATF_REQUIRE(ptrace(PT_DETACH, children[0], (caddr_t)1, 0) != -1);
+	ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
+
+	/*
+	 * Should not see any status from the fork parent now, only
+	 * the child.
+	 */
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == children[1]);
+	ATF_REQUIRE(WIFEXITED(status));
+	ATF_REQUIRE(WEXITSTATUS(status) == 2);
+
+	wpid = wait(&status);
+	ATF_REQUIRE(wpid == -1);
+	ATF_REQUIRE(errno == ECHILD);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
 	ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_trace_me);
 	ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_attach);
+	ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_child_debugger);
+	ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_unrelated_debugger);
+	ATF_TP_ADD_TC(tp, ptrace__follow_fork_both_attached);
+	ATF_TP_ADD_TC(tp, ptrace__follow_fork_child_detached);
+	ATF_TP_ADD_TC(tp, ptrace__follow_fork_parent_detached);
+	ATF_TP_ADD_TC(tp, ptrace__follow_fork_both_attached_unrelated_debugger);
+	ATF_TP_ADD_TC(tp,
+	    ptrace__follow_fork_child_detached_unrelated_debugger);
+	ATF_TP_ADD_TC(tp,
+	    ptrace__follow_fork_parent_detached_unrelated_debugger);
 
 	return (atf_no_error());
 }

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 00:20:16 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id A9357A0139F;
 Fri, 11 Sep 2015 00:20:16 +0000 (UTC) (envelope-from jhb@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 98B6319C0;
 Fri, 11 Sep 2015 00:20:16 +0000 (UTC) (envelope-from jhb@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8B0KGAL082687;
 Fri, 11 Sep 2015 00:20:16 GMT (envelope-from jhb@FreeBSD.org)
Received: (from jhb@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8B0KGZU082685;
 Fri, 11 Sep 2015 00:20:16 GMT (envelope-from jhb@FreeBSD.org)
Message-Id: <201509110020.t8B0KGZU082685@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org
 using -f
From: John Baldwin 
Date: Fri, 11 Sep 2015 00:20:16 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287637 - in stable: 10/sys/ofed/include/linux
 9/sys/ofed/include/linux
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 00:20:16 -0000

Author: jhb
Date: Fri Sep 11 00:20:15 2015
New Revision: 287637
URL: https://svnweb.freebsd.org/changeset/base/287637

Log:
  MFC 287440:
  Currently the Linux character device mmap handling only supports mmap
  operations that map a single page that has an associated vm_page_t.
  This does not permit mapping larger regions (such as a PCI memory
  BAR) and it does not permit mapping addresses beyond the top of RAM
  (such as a 64-bit BAR located above the top of RAM).
  
  Instead of using a single OBJT_DEVICE object and passing the physaddr via
  the offset as a hack, create a new sglist and OBJT_SG object for each
  mmap request. The requested memory attribute is applied to the object
  thus affecting all pages mapped by the request.
  
  Sponsored by:	Chelsio

Modified:
  stable/10/sys/ofed/include/linux/linux_compat.c
  stable/10/sys/ofed/include/linux/mm.h
Directory Properties:
  stable/10/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/9/sys/ofed/include/linux/linux_compat.c
  stable/9/sys/ofed/include/linux/mm.h
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/10/sys/ofed/include/linux/linux_compat.c
==============================================================================
--- stable/10/sys/ofed/include/linux/linux_compat.c	Fri Sep 11 00:19:49 2015	(r287636)
+++ stable/10/sys/ofed/include/linux/linux_compat.c	Fri Sep 11 00:20:15 2015	(r287637)
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -414,16 +415,6 @@ linux_dev_poll(struct cdev *dev, int eve
 }
 
 static int
-linux_dev_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
-    int nprot, vm_memattr_t *memattr)
-{
-
-	/* XXX memattr not honored. */
-	*paddr = offset;
-	return (0);
-}
-
-static int
 linux_dev_mmap_single(struct cdev *dev, vm_ooffset_t *offset,
     vm_size_t size, struct vm_object **object, int nprot)
 {
@@ -431,36 +422,41 @@ linux_dev_mmap_single(struct cdev *dev, 
 	struct linux_file *filp;
 	struct file *file;
 	struct vm_area_struct vma;
-	vm_paddr_t paddr;
-	vm_page_t m;
 	int error;
 
 	file = curthread->td_fpop;
 	ldev = dev->si_drv1;
 	if (ldev == NULL)
 		return (ENODEV);
-	if (size != PAGE_SIZE)
-		return (EINVAL);
 	if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
 		return (error);
 	filp->f_flags = file->f_flag;
 	vma.vm_start = 0;
-	vma.vm_end = PAGE_SIZE;
+	vma.vm_end = size;
 	vma.vm_pgoff = *offset / PAGE_SIZE;
 	vma.vm_pfn = 0;
 	vma.vm_page_prot = 0;
 	if (filp->f_op->mmap) {
 		error = -filp->f_op->mmap(filp, &vma);
 		if (error == 0) {
-			paddr = (vm_paddr_t)vma.vm_pfn << PAGE_SHIFT;
-			*offset = paddr;
-			m = PHYS_TO_VM_PAGE(paddr);
-			*object = vm_pager_allocate(OBJT_DEVICE, dev,
-			    PAGE_SIZE, nprot, *offset, curthread->td_ucred);
-		        if (*object == NULL)
-               			 return (EINVAL);
-			if (vma.vm_page_prot != VM_MEMATTR_DEFAULT)
-				pmap_page_set_memattr(m, vma.vm_page_prot);
+			struct sglist *sg;
+
+			sg = sglist_alloc(1, M_WAITOK);
+			sglist_append_phys(sg,
+			    (vm_paddr_t)vma.vm_pfn << PAGE_SHIFT, vma.vm_len);
+			*object = vm_pager_allocate(OBJT_SG, sg, vma.vm_len,
+			    nprot, 0, curthread->td_ucred);
+		        if (*object == NULL) {
+				sglist_free(sg);
+				return (EINVAL);
+			}
+			*offset = 0;
+			if (vma.vm_page_prot != VM_MEMATTR_DEFAULT) {
+				VM_OBJECT_WLOCK(*object);
+				vm_object_set_memattr(*object,
+				    vma.vm_page_prot);
+				VM_OBJECT_WUNLOCK(*object);
+			}
 		}
 	} else
 		error = ENODEV;
@@ -477,7 +473,6 @@ struct cdevsw linuxcdevsw = {
 	.d_write = linux_dev_write,
 	.d_ioctl = linux_dev_ioctl,
 	.d_mmap_single = linux_dev_mmap_single,
-	.d_mmap = linux_dev_mmap,
 	.d_poll = linux_dev_poll,
 };
 

Modified: stable/10/sys/ofed/include/linux/mm.h
==============================================================================
--- stable/10/sys/ofed/include/linux/mm.h	Fri Sep 11 00:19:49 2015	(r287636)
+++ stable/10/sys/ofed/include/linux/mm.h	Fri Sep 11 00:20:15 2015	(r287637)
@@ -40,6 +40,7 @@ struct vm_area_struct {
 	vm_offset_t	vm_end;
 	vm_offset_t	vm_pgoff;
 	vm_paddr_t	vm_pfn;		/* PFN For mmap. */
+	vm_size_t	vm_len;		/* length for mmap. */
 	vm_memattr_t	vm_page_prot;
 };
 
@@ -78,6 +79,7 @@ io_remap_pfn_range(struct vm_area_struct
 {
 	vma->vm_page_prot = prot;
 	vma->vm_pfn = pfn;
+	vma->vm_len = size;
 
 	return (0);
 }

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 02:53:23 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 22BD1A02180;
 Fri, 11 Sep 2015 02:53:23 +0000 (UTC)
 (envelope-from markj@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 12BA71120;
 Fri, 11 Sep 2015 02:53:23 +0000 (UTC)
 (envelope-from markj@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8B2rM27054934;
 Fri, 11 Sep 2015 02:53:22 GMT (envelope-from markj@FreeBSD.org)
Received: (from markj@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8B2rMp7054933;
 Fri, 11 Sep 2015 02:53:22 GMT (envelope-from markj@FreeBSD.org)
Message-Id: <201509110253.t8B2rMp7054933@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: markj set sender to
 markj@FreeBSD.org using -f
From: Mark Johnston 
Date: Fri, 11 Sep 2015 02:53:22 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287639 - stable/10/cddl/contrib/opensolaris/tools/ctf/cvt
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 02:53:23 -0000

Author: markj
Date: Fri Sep 11 02:53:22 2015
New Revision: 287639
URL: https://svnweb.freebsd.org/changeset/base/287639

Log:
  MFC r274569, r276848, r287234:
  Only compare visitation counters if they've both been set for the current
  type graph walk.

Modified:
  stable/10/cddl/contrib/opensolaris/tools/ctf/cvt/merge.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/cddl/contrib/opensolaris/tools/ctf/cvt/merge.c
==============================================================================
--- stable/10/cddl/contrib/opensolaris/tools/ctf/cvt/merge.c	Fri Sep 11 00:38:58 2015	(r287638)
+++ stable/10/cddl/contrib/opensolaris/tools/ctf/cvt/merge.c	Fri Sep 11 02:53:22 2015	(r287639)
@@ -357,7 +357,7 @@ equiv_node(tdesc_t *ctdp, tdesc_t *mtdp,
 	int (*equiv)(tdesc_t *, tdesc_t *, equiv_data_t *);
 	int mapping;
 
-	if (ctdp->t_emark > ed->ed_clear_mark ||
+	if (ctdp->t_emark > ed->ed_clear_mark &&
 	    mtdp->t_emark > ed->ed_clear_mark)
 		return (ctdp->t_emark == mtdp->t_emark);
 

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 10:45:29 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id D7744A015ED;
 Fri, 11 Sep 2015 10:45:29 +0000 (UTC)
 (envelope-from garga@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id AD9E515C3;
 Fri, 11 Sep 2015 10:45:29 +0000 (UTC)
 (envelope-from garga@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BAjTDW079710;
 Fri, 11 Sep 2015 10:45:29 GMT (envelope-from garga@FreeBSD.org)
Received: (from garga@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BAjTqj079707;
 Fri, 11 Sep 2015 10:45:29 GMT (envelope-from garga@FreeBSD.org)
Message-Id: <201509111045.t8BAjTqj079707@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: garga set sender to
 garga@FreeBSD.org using -f
From: Renato Botelho 
Date: Fri, 11 Sep 2015 10:45:29 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287655 - in stable/10/sys/dev/usb: . serial
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 10:45:29 -0000

Author: garga (ports committer)
Date: Fri Sep 11 10:45:28 2015
New Revision: 287655
URL: https://svnweb.freebsd.org/changeset/base/287655

Log:
  MFC r287574:
  
  - Fix Sierra MC7354 ID from a bad copy/paste, correct ID is 68C0
  
  MFC r287575:
  
  - Remove duplicate entry for Sierra Wireless Aircard 875
  
  Approved by:	loos
  Obtained from:	pfSense (r287574)
  Sponsored by:	Rubicon Communications (Netgate)

Modified:
  stable/10/sys/dev/usb/serial/u3g.c
  stable/10/sys/dev/usb/usbdevs
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/usb/serial/u3g.c
==============================================================================
--- stable/10/sys/dev/usb/serial/u3g.c	Fri Sep 11 09:15:27 2015	(r287654)
+++ stable/10/sys/dev/usb/serial/u3g.c	Fri Sep 11 10:45:28 2015	(r287655)
@@ -492,6 +492,7 @@ static const STRUCT_USB_HOST_ID u3g_devs
 	U3G_DEV(SIERRA, AC595U, 0),
 	U3G_DEV(SIERRA, AC313U, 0),
 	U3G_DEV(SIERRA, AC597E, 0),
+	U3G_DEV(SIERRA, AC875, 0),
 	U3G_DEV(SIERRA, AC875E, 0),
 	U3G_DEV(SIERRA, AC875U, 0),
 	U3G_DEV(SIERRA, AC875U_2, 0),
@@ -506,7 +507,6 @@ static const STRUCT_USB_HOST_ID u3g_devs
 	U3G_DEV(SIERRA, AC885U, 0),
 	U3G_DEV(SIERRA, AIRCARD580, 0),
 	U3G_DEV(SIERRA, AIRCARD595, 0),
-	U3G_DEV(SIERRA, AIRCARD875, 0),
 	U3G_DEV(SIERRA, C22, 0),
 	U3G_DEV(SIERRA, C597, 0),
 	U3G_DEV(SIERRA, C888, 0),

Modified: stable/10/sys/dev/usb/usbdevs
==============================================================================
--- stable/10/sys/dev/usb/usbdevs	Fri Sep 11 09:15:27 2015	(r287654)
+++ stable/10/sys/dev/usb/usbdevs	Fri Sep 11 10:45:28 2015	(r287655)
@@ -4009,8 +4009,7 @@ product SIERRA C22		0x6891	C22
 product SIERRA E6892		0x6892	E6892
 product SIERRA E6893		0x6893	E6893
 product SIERRA MC8700		0x68A3	MC8700
-product SIERRA MC7354		0x6820	MC7354
-product SIERRA AIRCARD875	0x6820	Aircard 875 HSDPA
+product SIERRA MC7354		0x68C0	MC7354
 product SIERRA AC313U		0x68aa	Sierra Wireless AirCard 313U
 product SIERRA TRUINSTALL	0x0fff	Aircard Tru Installer
 

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 12:34:24 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5AE13A0119B;
 Fri, 11 Sep 2015 12:34:24 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 4B2841A8A;
 Fri, 11 Sep 2015 12:34:24 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BCYOrj029090;
 Fri, 11 Sep 2015 12:34:24 GMT (envelope-from avg@FreeBSD.org)
Received: (from avg@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BCYOl9029089;
 Fri, 11 Sep 2015 12:34:24 GMT (envelope-from avg@FreeBSD.org)
Message-Id: <201509111234.t8BCYOl9029089@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org
 using -f
From: Andriy Gapon 
Date: Fri, 11 Sep 2015 12:34:24 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287656 -
 stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 12:34:24 -0000

Author: avg
Date: Fri Sep 11 12:34:23 2015
New Revision: 287656
URL: https://svnweb.freebsd.org/changeset/base/287656

Log:
  MFC r284513: l2arc: pass correct size to trim requests

Modified:
  stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
==============================================================================
--- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c	Fri Sep 11 10:45:28 2015	(r287655)
+++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c	Fri Sep 11 12:34:23 2015	(r287656)
@@ -1823,7 +1823,7 @@ arc_hdr_destroy(arc_buf_hdr_t *hdr)
 
 		if (l2hdr != NULL) {
 			trim_map_free(l2hdr->b_dev->l2ad_vdev, l2hdr->b_daddr,
-			    hdr->b_size, 0);
+			    l2hdr->b_asize, 0);
 			list_remove(l2hdr->b_dev->l2ad_buflist, hdr);
 			arc_buf_l2_cdata_free(hdr);
 			ARCSTAT_INCR(arcstat_l2_size, -hdr->b_size);
@@ -3822,7 +3822,7 @@ arc_release(arc_buf_t *buf, void *tag)
 		vdev_space_update(l2hdr->b_dev->l2ad_vdev,
 		    -l2hdr->b_asize, 0, 0);
 		trim_map_free(l2hdr->b_dev->l2ad_vdev, l2hdr->b_daddr,
-		    hdr->b_size, 0);
+		    l2hdr->b_asize, 0);
 		kmem_free(l2hdr, sizeof (l2arc_buf_hdr_t));
 		ARCSTAT_INCR(arcstat_l2_size, -buf_size);
 		mutex_exit(&l2arc_buflist_mtx);
@@ -4761,7 +4761,7 @@ l2arc_write_done(zio_t *zio)
 			bytes_dropped += abl2->b_asize;
 			hdr->b_l2hdr = NULL;
 			trim_map_free(abl2->b_dev->l2ad_vdev, abl2->b_daddr,
-			    hdr->b_size, 0);
+			    abl2->b_asize, 0);
 			kmem_free(abl2, sizeof (l2arc_buf_hdr_t));
 			ARCSTAT_INCR(arcstat_l2_size, -hdr->b_size);
 		}

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 12:37:51 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id ED820A013D3;
 Fri, 11 Sep 2015 12:37:51 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id C3B1A1D70;
 Fri, 11 Sep 2015 12:37:51 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BCbpWr029354;
 Fri, 11 Sep 2015 12:37:51 GMT (envelope-from avg@FreeBSD.org)
Received: (from avg@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BCbpOU029353;
 Fri, 11 Sep 2015 12:37:51 GMT (envelope-from avg@FreeBSD.org)
Message-Id: <201509111237.t8BCbpOU029353@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org
 using -f
From: Andriy Gapon 
Date: Fri, 11 Sep 2015 12:37:51 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287658 -
 stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 12:37:52 -0000

Author: avg
Date: Fri Sep 11 12:37:50 2015
New Revision: 287658
URL: https://svnweb.freebsd.org/changeset/base/287658

Log:
  MFC r286985: try to fix lor between z_teardown_lock and spa_namespace_lock

Modified:
  stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c

Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c
==============================================================================
--- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c	Fri Sep 11 12:34:56 2015	(r287657)
+++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c	Fri Sep 11 12:37:50 2015	(r287658)
@@ -466,6 +466,19 @@ zfs_register_callbacks(vfs_t *vfsp)
 	}
 
 	/*
+	 * We need to enter pool configuration here, so that we can use
+	 * dsl_prop_get_int_ds() to handle the special nbmand property below.
+	 * dsl_prop_get_integer() can not be used, because it has to acquire
+	 * spa_namespace_lock and we can not do that because we already hold
+	 * z_teardown_lock.  The problem is that spa_config_sync() is called
+	 * with spa_namespace_lock held and the function calls ZFS vnode
+	 * operations to write the cache file and thus z_teardown_lock is
+	 * acquired after spa_namespace_lock.
+	 */
+	ds = dmu_objset_ds(os);
+	dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
+
+	/*
 	 * nbmand is a special property.  It can only be changed at
 	 * mount time.
 	 *
@@ -476,14 +489,9 @@ zfs_register_callbacks(vfs_t *vfsp)
 		nbmand = B_FALSE;
 	} else if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) {
 		nbmand = B_TRUE;
-	} else {
-		char osname[MAXNAMELEN];
-
-		dmu_objset_name(os, osname);
-		if (error = dsl_prop_get_integer(osname, "nbmand", &nbmand,
-		    NULL)) {
-			return (error);
-		}
+	} else if (error = dsl_prop_get_int_ds(ds, "nbmand", &nbmand) != 0) {
+		dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
+		return (error);
 	}
 
 	/*
@@ -493,8 +501,6 @@ zfs_register_callbacks(vfs_t *vfsp)
 	 * the first prop_register(), but I guess I like to go
 	 * overboard...
 	 */
-	ds = dmu_objset_ds(os);
-	dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
 	error = dsl_prop_register(ds,
 	    zfs_prop_to_name(ZFS_PROP_ATIME), atime_changed_cb, zfsvfs);
 	error = error ? error : dsl_prop_register(ds,

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 12:39:14 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 56836A014F2;
 Fri, 11 Sep 2015 12:39:14 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 1FD791089;
 Fri, 11 Sep 2015 12:39:14 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BCdDU0029626;
 Fri, 11 Sep 2015 12:39:13 GMT (envelope-from avg@FreeBSD.org)
Received: (from avg@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BCdDbb029625;
 Fri, 11 Sep 2015 12:39:13 GMT (envelope-from avg@FreeBSD.org)
Message-Id: <201509111239.t8BCdDbb029625@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org
 using -f
From: Andriy Gapon 
Date: Fri, 11 Sep 2015 12:39:13 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287660 - stable/10
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 12:39:14 -0000

Author: avg
Date: Fri Sep 11 12:39:13 2015
New Revision: 287660
URL: https://svnweb.freebsd.org/changeset/base/287660

Log:
  MFC r286985: try to fix lor between z_teardown_lock and spa_namespace_lock

Modified:
Directory Properties:
  stable/10/   (props changed)

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 12:41:59 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id EFD35A0178F;
 Fri, 11 Sep 2015 12:41:59 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id DFFF41593;
 Fri, 11 Sep 2015 12:41:59 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BCfxR5033547;
 Fri, 11 Sep 2015 12:41:59 GMT (envelope-from avg@FreeBSD.org)
Received: (from avg@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BCfxO3033546;
 Fri, 11 Sep 2015 12:41:59 GMT (envelope-from avg@FreeBSD.org)
Message-Id: <201509111241.t8BCfxO3033546@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org
 using -f
From: Andriy Gapon 
Date: Fri, 11 Sep 2015 12:41:59 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287661 -
 stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 12:42:00 -0000

Author: avg
Date: Fri Sep 11 12:41:59 2015
New Revision: 287661
URL: https://svnweb.freebsd.org/changeset/base/287661

Log:
  MFC r285021: zfs_mount(MS_REMOUNT): protect zfs_(un)register_callbacks calls

Modified:
  stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c
==============================================================================
--- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c	Fri Sep 11 12:39:13 2015	(r287660)
+++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c	Fri Sep 11 12:41:59 2015	(r287661)
@@ -1706,9 +1706,19 @@ zfs_mount(vfs_t *vfsp)
 	 * according to those options set in the current VFS options.
 	 */
 	if (vfsp->vfs_flag & MS_REMOUNT) {
-		/* refresh mount options */
-		zfs_unregister_callbacks(vfsp->vfs_data);
+		zfsvfs_t *zfsvfs = vfsp->vfs_data;
+
+		/*
+		 * Refresh mount options with z_teardown_lock blocking I/O while
+		 * the filesystem is in an inconsistent state.
+		 * The lock also serializes this code with filesystem
+		 * manipulations between entry to zfs_suspend_fs() and return
+		 * from zfs_resume_fs().
+		 */
+		rrm_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
+		zfs_unregister_callbacks(zfsvfs);
 		error = zfs_register_callbacks(vfsp);
+		rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
 		goto out;
 	}
 

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 12:45:57 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9B75FA01A2B;
 Fri, 11 Sep 2015 12:45:57 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 8C2971C86;
 Fri, 11 Sep 2015 12:45:57 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BCjv13034083;
 Fri, 11 Sep 2015 12:45:57 GMT (envelope-from avg@FreeBSD.org)
Received: (from avg@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BCjvLN034082;
 Fri, 11 Sep 2015 12:45:57 GMT (envelope-from avg@FreeBSD.org)
Message-Id: <201509111245.t8BCjvLN034082@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org
 using -f
From: Andriy Gapon 
Date: Fri, 11 Sep 2015 12:45:57 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287663 - stable/10/sys/kern
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 12:45:57 -0000

Author: avg
Date: Fri Sep 11 12:45:56 2015
New Revision: 287663
URL: https://svnweb.freebsd.org/changeset/base/287663

Log:
  MFC r287354: callout_reset: fix a reversed check for cc_exec_cancel
  
  Relnotes:	potential erratum

Modified:
  stable/10/sys/kern/kern_timeout.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_timeout.c
==============================================================================
--- stable/10/sys/kern/kern_timeout.c	Fri Sep 11 12:43:31 2015	(r287662)
+++ stable/10/sys/kern/kern_timeout.c	Fri Sep 11 12:45:56 2015	(r287663)
@@ -1001,7 +1001,7 @@ callout_reset_sbt_on(struct callout *c, 
 		 * currently in progress.  If there is a lock then we
 		 * can cancel the callout if it has not really started.
 		 */
-		if (c->c_lock != NULL && cc_exec_cancel(cc, direct))
+		if (c->c_lock != NULL && !cc_exec_cancel(cc, direct))
 			cancelled = cc_exec_cancel(cc, direct) = true;
 		if (cc_exec_waiting(cc, direct)) {
 			/*

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 12:58:42 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA7F2A02033;
 Fri, 11 Sep 2015 12:58:42 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 8E6F614C6;
 Fri, 11 Sep 2015 12:58:42 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BCwgm4038521;
 Fri, 11 Sep 2015 12:58:42 GMT (envelope-from avg@FreeBSD.org)
Received: (from avg@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BCwgw5038520;
 Fri, 11 Sep 2015 12:58:42 GMT (envelope-from avg@FreeBSD.org)
Message-Id: <201509111258.t8BCwgw5038520@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org
 using -f
From: Andriy Gapon 
Date: Fri, 11 Sep 2015 12:58:42 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287665 -
 stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 12:58:42 -0000

Author: avg
Date: Fri Sep 11 12:58:41 2015
New Revision: 287665
URL: https://svnweb.freebsd.org/changeset/base/287665

Log:
  MFC r287099: account for ashift when gathering buffers to be written to l2arc device
  
  The change differs from that in head because of other changes that have not
  been MFC-ed yet.

Modified:
  stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
==============================================================================
--- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c	Fri Sep 11 12:50:52 2015	(r287664)
+++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c	Fri Sep 11 12:58:41 2015	(r287665)
@@ -5062,8 +5062,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 {
 	arc_buf_hdr_t *hdr, *hdr_prev, *head;
 	list_t *list;
-	uint64_t write_asize, write_psize, write_sz, headroom,
-	    buf_compress_minsz;
+	uint64_t write_asize, write_sz, headroom, buf_compress_minsz;
 	void *buf_data;
 	kmutex_t *list_lock;
 	boolean_t full;
@@ -5079,7 +5078,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 	*headroom_boost = B_FALSE;
 
 	pio = NULL;
-	write_sz = write_asize = write_psize = 0;
+	write_sz = write_asize = 0;
 	full = B_FALSE;
 	head = kmem_cache_alloc(hdr_cache, KM_PUSHPAGE);
 	head->b_flags |= ARC_FLAG_L2_WRITE_HEAD;
@@ -5122,6 +5121,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 			l2arc_buf_hdr_t *l2hdr;
 			kmutex_t *hash_lock;
 			uint64_t buf_sz;
+			uint64_t buf_a_sz;
 
 			if (arc_warm == B_FALSE)
 				hdr_prev = list_next(list, hdr);
@@ -5153,7 +5153,15 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 				continue;
 			}
 
-			if ((write_sz + hdr->b_size) > target_sz) {
+			/*
+			 * Assume that the buffer is not going to be compressed
+			 * and could take more space on disk because of a larger
+			 * disk block size.
+			 */
+			buf_sz = hdr->b_size;
+			buf_a_sz = vdev_psize_to_asize(dev->l2ad_vdev, buf_sz);
+
+			if ((write_asize + buf_a_sz) > target_sz) {
 				full = B_TRUE;
 				mutex_exit(hash_lock);
 				ARCSTAT_BUMP(arcstat_l2_write_full);
@@ -5196,7 +5204,6 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 			l2hdr->b_asize = hdr->b_size;
 			l2hdr->b_tmp_cdata = hdr->b_buf->b_data;
 
-			buf_sz = hdr->b_size;
 			hdr->b_l2hdr = l2hdr;
 
 			list_insert_head(dev->l2ad_buflist, hdr);
@@ -5211,6 +5218,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 			mutex_exit(hash_lock);
 
 			write_sz += buf_sz;
+			write_asize += buf_a_sz;
 		}
 
 		mutex_exit(list_lock);
@@ -5228,6 +5236,19 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 	}
 
 	/*
+	 * Note that elsewhere in this file arcstat_l2_asize
+	 * and the used space on l2ad_vdev are updated using b_asize,
+	 * which is not necessarily rounded up to the device block size.
+	 * Too keep accounting consistent we do the same here as well:
+	 * stats_size accumulates the sum of b_asize of the written buffers,
+	 * while write_asize accumulates the sum of b_asize rounded up
+	 * to the device block size.
+	 * The latter sum is used only to validate the corectness of the code.
+	 */
+	uint64_t stats_size = 0;
+	write_asize = 0;
+
+	/*
 	 * Now start writing the buffers. We're starting at the write head
 	 * and work backwards, retracing the course of the buffer selector
 	 * loop above.
@@ -5275,7 +5296,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 
 		/* Compression may have squashed the buffer to zero length. */
 		if (buf_sz != 0) {
-			uint64_t buf_p_sz;
+			uint64_t buf_a_sz;
 
 			wzio = zio_write_phys(pio, dev->l2ad_vdev,
 			    dev->l2ad_hand, buf_sz, buf_data, ZIO_CHECKSUM_OFF,
@@ -5286,13 +5307,13 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 			    zio_t *, wzio);
 			(void) zio_nowait(wzio);
 
-			write_asize += buf_sz;
+			stats_size += buf_sz;
 			/*
 			 * Keep the clock hand suitably device-aligned.
 			 */
-			buf_p_sz = vdev_psize_to_asize(dev->l2ad_vdev, buf_sz);
-			write_psize += buf_p_sz;
-			dev->l2ad_hand += buf_p_sz;
+			buf_a_sz = vdev_psize_to_asize(dev->l2ad_vdev, buf_sz);
+			write_asize += buf_a_sz;
+			dev->l2ad_hand += buf_a_sz;
 		}
 	}
 
@@ -5302,8 +5323,8 @@ l2arc_write_buffers(spa_t *spa, l2arc_de
 	ARCSTAT_BUMP(arcstat_l2_writes_sent);
 	ARCSTAT_INCR(arcstat_l2_write_bytes, write_asize);
 	ARCSTAT_INCR(arcstat_l2_size, write_sz);
-	ARCSTAT_INCR(arcstat_l2_asize, write_asize);
-	vdev_space_update(dev->l2ad_vdev, write_psize, 0, 0);
+	ARCSTAT_INCR(arcstat_l2_asize, stats_size);
+	vdev_space_update(dev->l2ad_vdev, stats_size, 0, 0);
 
 	/*
 	 * Bump device hand to the device start if it is approaching the end.

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 13:32:20 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 374D1A02F49;
 Fri, 11 Sep 2015 13:32:20 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 27A3317AA;
 Fri, 11 Sep 2015 13:32:20 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BDWKfZ054738;
 Fri, 11 Sep 2015 13:32:20 GMT (envelope-from avg@FreeBSD.org)
Received: (from avg@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BDWKC6054737;
 Fri, 11 Sep 2015 13:32:20 GMT (envelope-from avg@FreeBSD.org)
Message-Id: <201509111332.t8BDWKC6054737@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org
 using -f
From: Andriy Gapon 
Date: Fri, 11 Sep 2015 13:32:20 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287667 -
 stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 13:32:20 -0000

Author: avg
Date: Fri Sep 11 13:32:19 2015
New Revision: 287667
URL: https://svnweb.freebsd.org/changeset/base/287667

Log:
  MFC r287100: spa_import_rootpool: prevent lock and resource leak
  
  PR:		198563

Modified:
  stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c
==============================================================================
--- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c	Fri Sep 11 12:59:16 2015	(r287666)
+++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c	Fri Sep 11 13:32:19 2015	(r287667)
@@ -4129,6 +4129,8 @@ spa_import_rootpool(const char *name)
 		    &spa->spa_ubsync.ub_version) != 0)
 			spa->spa_ubsync.ub_version = SPA_VERSION_INITIAL;
 	} else if ((spa = spa_lookup(name)) == NULL) {
+		mutex_exit(&spa_namespace_lock);
+		nvlist_free(config);
 		cmn_err(CE_NOTE, "Cannot find the pool label for '%s'",
 		    name);
 		return (EIO);

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 16:59:04 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id EB952A01962;
 Fri, 11 Sep 2015 16:59:04 +0000 (UTC)
 (envelope-from jimharris@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id DC174118B;
 Fri, 11 Sep 2015 16:59:04 +0000 (UTC)
 (envelope-from jimharris@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BGx4vh039091;
 Fri, 11 Sep 2015 16:59:04 GMT (envelope-from jimharris@FreeBSD.org)
Received: (from jimharris@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BGx4B0039090;
 Fri, 11 Sep 2015 16:59:04 GMT (envelope-from jimharris@FreeBSD.org)
Message-Id: <201509111659.t8BGx4B0039090@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: jimharris set sender to
 jimharris@FreeBSD.org using -f
From: Jim Harris 
Date: Fri, 11 Sep 2015 16:59:04 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287676 - stable/10/sys/dev/nvme
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 16:59:05 -0000

Author: jimharris
Date: Fri Sep 11 16:59:04 2015
New Revision: 287676
URL: https://svnweb.freebsd.org/changeset/base/287676

Log:
  MFC r286043:
  
    nvme: do not notify a consumer about failures that occur during initialization
  
  Sponsored by:	Intel

Modified:
  stable/10/sys/dev/nvme/nvme.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/nvme/nvme.c
==============================================================================
--- stable/10/sys/dev/nvme/nvme.c	Fri Sep 11 16:52:13 2015	(r287675)
+++ stable/10/sys/dev/nvme/nvme.c	Fri Sep 11 16:59:04 2015	(r287676)
@@ -390,6 +390,15 @@ nvme_notify_fail_consumers(struct nvme_c
 	struct nvme_consumer	*cons;
 	uint32_t		i;
 
+	/*
+	 * This controller failed during initialization (i.e. IDENTIFY
+	 *  command failed or timed out).  Do not notify any nvme
+	 *  consumers of the failure here, since the consumer does not
+	 *  even know about the controller yet.
+	 */
+	if (!ctrlr->is_initialized)
+		return;
+
 	for (i = 0; i < NVME_MAX_CONSUMERS; i++) {
 		cons = &nvme_consumer[i];
 		if (cons->id != INVALID_CONSUMER_ID && cons->fail_fn != NULL)

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 17:01:02 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id CBA00A01B44;
 Fri, 11 Sep 2015 17:01:02 +0000 (UTC)
 (envelope-from jimharris@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id BC5631650;
 Fri, 11 Sep 2015 17:01:02 +0000 (UTC)
 (envelope-from jimharris@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BH1202039374;
 Fri, 11 Sep 2015 17:01:02 GMT (envelope-from jimharris@FreeBSD.org)
Received: (from jimharris@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BH12Sm039373;
 Fri, 11 Sep 2015 17:01:02 GMT (envelope-from jimharris@FreeBSD.org)
Message-Id: <201509111701.t8BH12Sm039373@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: jimharris set sender to
 jimharris@FreeBSD.org using -f
From: Jim Harris 
Date: Fri, 11 Sep 2015 17:01:02 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287677 - stable/10/sys/dev/isci
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 17:01:02 -0000

Author: jimharris
Date: Fri Sep 11 17:01:01 2015
New Revision: 287677
URL: https://svnweb.freebsd.org/changeset/base/287677

Log:
  MFC r287563:
  
    isci: explicitly enable/disable PCI busmaster
  
    BIOS always enables PCI busmaster on the isci device, which effectively
    worked around this omission.  But when passing the isci device through
    to a guest VM, the hypervisor will disable busmaster and isci will not
    work without calling pci_enable_busmaster().
  
  Sponsored by:	Intel

Modified:
  stable/10/sys/dev/isci/isci.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/isci/isci.c
==============================================================================
--- stable/10/sys/dev/isci/isci.c	Fri Sep 11 16:59:04 2015	(r287676)
+++ stable/10/sys/dev/isci/isci.c	Fri Sep 11 17:01:01 2015	(r287677)
@@ -163,6 +163,7 @@ isci_attach(device_t device)
 
 	g_isci = isci;
 	isci->device = device;
+	pci_enable_busmaster(device);
 
 	isci_allocate_pci_memory(isci);
 
@@ -272,6 +273,7 @@ isci_detach(device_t device)
 
 		pci_release_msi(device);
 	}
+	pci_disable_busmaster(device);
 
 	return (0);
 }

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 17:06:58 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 56B84A01F04;
 Fri, 11 Sep 2015 17:06:58 +0000 (UTC)
 (envelope-from jimharris@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 474CA1BDD;
 Fri, 11 Sep 2015 17:06:58 +0000 (UTC)
 (envelope-from jimharris@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BH6w8I043254;
 Fri, 11 Sep 2015 17:06:58 GMT (envelope-from jimharris@FreeBSD.org)
Received: (from jimharris@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BH6wTi043253;
 Fri, 11 Sep 2015 17:06:58 GMT (envelope-from jimharris@FreeBSD.org)
Message-Id: <201509111706.t8BH6wTi043253@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: jimharris set sender to
 jimharris@FreeBSD.org using -f
From: Jim Harris 
Date: Fri, 11 Sep 2015 17:06:58 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287678 - stable/10/sys/dev/isci
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 17:06:58 -0000

Author: jimharris
Date: Fri Sep 11 17:06:57 2015
New Revision: 287678
URL: https://svnweb.freebsd.org/changeset/base/287678

Log:
  MFC r287564:
  
    isci: check return value of pci_alloc_msix()
  
    Certain VM guest types (VMware, Xen) do not support MSI, so pci_alloc_msix()
    always fails.  isci(4) was not properly detecting the allocation failure,
    and would try to proceed with MSIx resource initialization rather than
    reverting to INTx.
  
  Sponsored by:	Intel

Modified:
  stable/10/sys/dev/isci/isci_interrupt.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/isci/isci_interrupt.c
==============================================================================
--- stable/10/sys/dev/isci/isci_interrupt.c	Fri Sep 11 17:01:01 2015	(r287677)
+++ stable/10/sys/dev/isci/isci_interrupt.c	Fri Sep 11 17:06:57 2015	(r287678)
@@ -136,8 +136,8 @@ isci_interrupt_setup(struct isci_softc *
 	    pci_msix_count(isci->device) >= max_msix_messages) {
 
 		isci->num_interrupts = max_msix_messages;
-		pci_alloc_msix(isci->device, &isci->num_interrupts);
-		if (isci->num_interrupts == max_msix_messages)
+		if (pci_alloc_msix(isci->device, &isci->num_interrupts) == 0 &&
+		    isci->num_interrupts == max_msix_messages)
 			use_msix = TRUE;
 	}
 

From owner-svn-src-stable-10@freebsd.org  Fri Sep 11 17:19:25 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 43061A02599;
 Fri, 11 Sep 2015 17:19:25 +0000 (UTC) (envelope-from kp@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 1B5A813C6;
 Fri, 11 Sep 2015 17:19:25 +0000 (UTC) (envelope-from kp@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8BHJOo7047562;
 Fri, 11 Sep 2015 17:19:24 GMT (envelope-from kp@FreeBSD.org)
Received: (from kp@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8BHJOYD047561;
 Fri, 11 Sep 2015 17:19:24 GMT (envelope-from kp@FreeBSD.org)
Message-Id: <201509111719.t8BHJOYD047561@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: kp set sender to kp@FreeBSD.org
 using -f
From: Kristof Provost 
Date: Fri, 11 Sep 2015 17:19:24 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287680 - stable/10/sys/netpfil/pf
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Fri, 11 Sep 2015 17:19:25 -0000

Author: kp
Date: Fri Sep 11 17:19:24 2015
New Revision: 287680
URL: https://svnweb.freebsd.org/changeset/base/287680

Log:
  MFC r287376
  
  pf: Fix misdetection of forwarding when net.link.bridge.pfil_bridge is set
  
  If net.link.bridge.pfil_bridge is set we can end up thinking we're forwarding
  in pf_test6() because the rcvif and the ifp (output interface) are different.
  In that case we're bridging though, and the rcvif the the bridge member on
  which the packet was received and ifp is the bridge itself.
  If we'd set dir to PF_FWD we'd end up calling ip6_forward() which is
  incorrect.
  
  Instead check if the rcvif is a member of the ifp bridge. (In other words, the
  if_bridge is the ifp's softc). If that's the case we're not forwarding but
  bridging.
  
  PR:   202351

Modified:
  stable/10/sys/netpfil/pf/pf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/netpfil/pf/pf.c
==============================================================================
--- stable/10/sys/netpfil/pf/pf.c	Fri Sep 11 17:14:58 2015	(r287679)
+++ stable/10/sys/netpfil/pf/pf.c	Fri Sep 11 17:19:24 2015	(r287680)
@@ -6082,7 +6082,17 @@ pf_test6(int dir, struct ifnet *ifp, str
 
 	M_ASSERTPKTHDR(m);
 
-	if (dir == PF_OUT && m->m_pkthdr.rcvif && ifp != m->m_pkthdr.rcvif)
+	/* Detect packet forwarding.
+	 * If the input interface is different from the output interface we're
+	 * forwarding.
+	 * We do need to be careful about bridges. If the
+	 * net.link.bridge.pfil_bridge sysctl is set we can be filtering on a
+	 * bridge, so if the input interface is a bridge member and the output
+	 * interface is its bridge we're not actually forwarding but bridging.
+	 */
+	if (dir == PF_OUT && m->m_pkthdr.rcvif && ifp != m->m_pkthdr.rcvif
+	    && (m->m_pkthdr.rcvif->if_bridge == NULL
+	        || m->m_pkthdr.rcvif->if_bridge != ifp->if_softc))
 		fwdir = PF_FWD;
 
 	if (!V_pf_status.running)

From owner-svn-src-stable-10@freebsd.org  Sat Sep 12 02:36:18 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id C849CA02B54;
 Sat, 12 Sep 2015 02:36:18 +0000 (UTC) (envelope-from cy@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id B967E177E;
 Sat, 12 Sep 2015 02:36:18 +0000 (UTC) (envelope-from cy@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8C2aIx7083717;
 Sat, 12 Sep 2015 02:36:18 GMT (envelope-from cy@FreeBSD.org)
Received: (from cy@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8C2aIKK083716;
 Sat, 12 Sep 2015 02:36:18 GMT (envelope-from cy@FreeBSD.org)
Message-Id: <201509120236.t8C2aIKK083716@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: cy set sender to cy@FreeBSD.org
 using -f
From: Cy Schubert 
Date: Sat, 12 Sep 2015 02:36:18 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287700 - stable/10/usr.sbin/ntp
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Sat, 12 Sep 2015 02:36:18 -0000

Author: cy
Date: Sat Sep 12 02:36:17 2015
New Revision: 287700
URL: https://svnweb.freebsd.org/changeset/base/287700

Log:
  MFC r287468, turn on RAWDCF by default.

Modified:
  stable/10/usr.sbin/ntp/config.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/ntp/config.h
==============================================================================
--- stable/10/usr.sbin/ntp/config.h	Fri Sep 11 23:49:41 2015	(r287699)
+++ stable/10/usr.sbin/ntp/config.h	Sat Sep 12 02:36:17 2015	(r287700)
@@ -120,7 +120,7 @@
 #define CLOCK_PST 1
 
 /* DCF77 raw time code */
-/* #undef CLOCK_RAWDCF */
+#define CLOCK_RAWDCF 1
 
 /* RCC 8000 clock */
 /* #undef CLOCK_RCC8000 */

From owner-svn-src-stable-10@freebsd.org  Sat Sep 12 20:36:41 2015
Return-Path: 
Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9E6ACA03C15;
 Sat, 12 Sep 2015 20:36:41 +0000 (UTC) (envelope-from hrs@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 8D3CA1B61;
 Sat, 12 Sep 2015 20:36:41 +0000 (UTC) (envelope-from hrs@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.70])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8CKafYb036064;
 Sat, 12 Sep 2015 20:36:41 GMT (envelope-from hrs@FreeBSD.org)
Received: (from hrs@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8CKae5m036054;
 Sat, 12 Sep 2015 20:36:40 GMT (envelope-from hrs@FreeBSD.org)
Message-Id: <201509122036.t8CKae5m036054@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org
 using -f
From: Hiroki Sato 
Date: Sat, 12 Sep 2015 20:36:40 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject: svn commit: r287723 - in stable/10: sbin/ifconfig share/man/man4
 sys/net
X-SVN-Group: stable-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-stable-10@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for only the 10-stable src tree
 
List-Unsubscribe: , 
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: , 
 
X-List-Received-Date: Sat, 12 Sep 2015 20:36:41 -0000

Author: hrs
Date: Sat Sep 12 20:36:39 2015
New Revision: 287723
URL: https://svnweb.freebsd.org/changeset/base/287723

Log:
  MFC 272159,272161,272386,272446,272547,272548,273210:
  
  - Make lagg protos a enum.
  
  - When reconfiguring protocol on a lagg, first set it to LAGG_PROTO_NONE,
    then drop lock, run the attach routines, and then set it to specific
    proto. This removes tons of WITNESS warnings.
  
  - Make lagg protocol attach handlers not failing and allocate memory
    with M_WAITOK.
  
  - Virtualize lagg(4) cloner.  This change fixes a panic when tearing down
    if_lagg(4) interfaces which were cloned in a vnet jail.
  
    Sysctl nodes which are dynamically generated for each cloned interface
    (net.link.lagg.N.*) have been removed, and use_flowid and flowid_shift
    ifconfig(8) parameters have been added instead.  Flags and per-interface
    statistics counters are displayed in "ifconfig -v".
  
  - Separate option handling from SIOC[SG]LAGG to SIOC[SG]LAGGOPTS for
    backward compatibility with old ifconfig(8).
  
  - Move L2 addr configuration for the primary port to a taskqueue.  This fixes
    LOR of softc rmlock in iflladdr_event handlers.
  
  - Call if_delmulti_ifma() after LACP_UNLOCK().  This fixes another LOR.
  
  - Fix a panic in lacp_transit_expire().
  
  - Fix a panic in lagg_input() upon shutting down a port.
  
  - Use printb() for boolean flags in ro_opts and actor_state for LACP.
  
  - Fix lladdr configuration which could prevent LACP mode from working.
  
  - Fix LORs when a laggport interface has an IPv6 LLA.

Modified:
  stable/10/sbin/ifconfig/ifconfig.8
  stable/10/sbin/ifconfig/iflagg.c
  stable/10/share/man/man4/lagg.4
  stable/10/sys/net/ieee8023ad_lacp.c
  stable/10/sys/net/ieee8023ad_lacp.h
  stable/10/sys/net/if_lagg.c
  stable/10/sys/net/if_lagg.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sbin/ifconfig/ifconfig.8
==============================================================================
--- stable/10/sbin/ifconfig/ifconfig.8	Sat Sep 12 20:14:54 2015	(r287722)
+++ stable/10/sbin/ifconfig/ifconfig.8	Sat Sep 12 20:36:39 2015	(r287723)
@@ -28,7 +28,7 @@
 .\"     From: @(#)ifconfig.8	8.3 (Berkeley) 1/5/94
 .\" $FreeBSD$
 .\"
-.Dd July 24, 2015
+.Dd September 12, 2015
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -2393,9 +2393,16 @@ Remove the interface named by
 from the aggregation interface.
 .It Cm laggproto Ar proto
 Set the aggregation protocol.
-The default is failover.
-The available options are failover, fec, lacp, loadbalance, roundrobin and
-none.
+The default is
+.Li failover .
+The available options are
+.Li failover ,
+.Li lacp ,
+.Li loadbalance ,
+.Li roundrobin ,
+.Li broadcast
+and
+.Li none .
 .It Cm lagghash Ar option Ns Oo , Ns Ar option Oc
 Set the packet layers to hash for aggregation protocols which load balance.
 The default is
@@ -2410,7 +2417,34 @@ src/dst address for IPv4 or IPv6.
 .It Cm l4
 src/dst port for TCP/UDP/SCTP.
 .El
-.Pp
+.It Cm use_flowid
+Enable local hash computation for RSS hash on the interface.
+The
+.Li loadbalance
+and
+.Li lacp
+modes will use the RSS hash from the network card if available
+to avoid computing one, this may give poor traffic distribution
+if the hash is invalid or uses less of the protocol header information.
+.Cm use_flowid
+disables use of RSS hash from the network card.
+The default value can be set via the
+.Va net.link.lagg.default_use_flowid
+.Xr sysctl 8
+variable.
+.Li 0
+means
+.Dq disabled
+and
+.Li 1
+means
+.Dq enabled .
+.It Cm -use_flowid
+Disable local hash computation for RSS hash on the interface.
+.It Cm flowid_shift Ar number
+Set a shift parameter for RSS local hash computation.
+Hash is calculated by using flowid bits in a packet header mbuf
+which are shifted by the number of this parameter.
 .El
 .Pp
 The following parameters are specific to IP tunnel interfaces,

Modified: stable/10/sbin/ifconfig/iflagg.c
==============================================================================
--- stable/10/sbin/ifconfig/iflagg.c	Sat Sep 12 20:14:54 2015	(r287722)
+++ stable/10/sbin/ifconfig/iflagg.c	Sat Sep 12 20:36:39 2015	(r287723)
@@ -17,6 +17,7 @@ static const char rcsid[] =
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -68,7 +69,7 @@ setlaggproto(const char *val, int d, int
 	bzero(&ra, sizeof(ra));
 	ra.ra_proto = LAGG_PROTO_MAX;
 
-	for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++) {
+	for (i = 0; i < nitems(lpr); i++) {
 		if (strcmp(val, lpr[i].lpr_name) == 0) {
 			ra.ra_proto = lpr[i].lpr_proto;
 			break;
@@ -83,6 +84,48 @@ setlaggproto(const char *val, int d, int
 }
 
 static void
+setlaggflowidshift(const char *val, int d, int s, const struct afswtch *afp)
+{
+	struct lagg_reqopts ro;
+
+	bzero(&ro, sizeof(ro));
+	ro.ro_opts = LAGG_OPT_FLOWIDSHIFT;
+	strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
+	ro.ro_flowid_shift = (int)strtol(val, NULL, 10);
+	if (ro.ro_flowid_shift & ~LAGG_OPT_FLOWIDSHIFT_MASK)
+		errx(1, "Invalid flowid_shift option: %s", val);
+	
+	if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
+		err(1, "SIOCSLAGGOPTS");
+}
+
+static void
+setlaggsetopt(const char *val, int d, int s, const struct afswtch *afp)
+{
+	struct lagg_reqopts ro;
+
+	bzero(&ro, sizeof(ro));
+	ro.ro_opts = d;
+	switch (ro.ro_opts) {
+	case LAGG_OPT_USE_FLOWID:
+	case -LAGG_OPT_USE_FLOWID:
+	case LAGG_OPT_LACP_STRICT:
+	case -LAGG_OPT_LACP_STRICT:
+	case LAGG_OPT_LACP_TXTEST:
+	case -LAGG_OPT_LACP_TXTEST:
+	case LAGG_OPT_LACP_RXTEST:
+	case -LAGG_OPT_LACP_RXTEST:
+		break;
+	default:
+		err(1, "Invalid lagg option");
+	}
+	strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
+	
+	if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
+		err(1, "SIOCSLAGGOPTS");
+}
+
+static void
 setlagghash(const char *val, int d, int s, const struct afswtch *afp)
 {
 	struct lagg_reqflags rf;
@@ -144,6 +187,7 @@ lagg_status(int s)
 	struct lagg_protos lpr[] = LAGG_PROTOS;
 	struct lagg_reqport rp, rpbuf[LAGG_MAX_PORTS];
 	struct lagg_reqall ra;
+	struct lagg_reqopts ro;
 	struct lagg_reqflags rf;
 	struct lacp_opreq *lp;
 	const char *proto = "";
@@ -151,6 +195,7 @@ lagg_status(int s)
 
 	bzero(&rp, sizeof(rp));
 	bzero(&ra, sizeof(ra));
+	bzero(&ro, sizeof(ro));
 
 	strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
 	strlcpy(rp.rp_portname, name, sizeof(rp.rp_portname));
@@ -162,6 +207,9 @@ lagg_status(int s)
 	ra.ra_size = sizeof(rpbuf);
 	ra.ra_port = rpbuf;
 
+	strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
+	ioctl(s, SIOCGLAGGOPTS, &ro);
+
 	strlcpy(rf.rf_ifname, name, sizeof(rf.rf_ifname));
 	if (ioctl(s, SIOCGLAGGFLAGS, &rf) != 0)
 		rf.rf_flags = 0;
@@ -169,7 +217,7 @@ lagg_status(int s)
 	if (ioctl(s, SIOCGLAGG, &ra) == 0) {
 		lp = (struct lacp_opreq *)&ra.ra_lacpreq;
 
-		for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++) {
+		for (i = 0; i < nitems(lpr); i++) {
 			if (ra.ra_proto == lpr[i].lpr_proto) {
 				proto = lpr[i].lpr_name;
 				break;
@@ -197,16 +245,27 @@ lagg_status(int s)
 		if (isport)
 			printf(" laggdev %s", rp.rp_ifname);
 		putchar('\n');
-		if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
-			printf("\tlag id: %s\n",
-			    lacp_format_peer(lp, "\n\t\t "));
+		if (verbose) {
+			printf("\tlagg options:\n");
+			printb("\t\tflags", ro.ro_opts, LAGG_OPT_BITS);
+			putchar('\n');
+			printf("\t\tflowid_shift: %d\n", ro.ro_flowid_shift);
+			printf("\tlagg statistics:\n");
+			printf("\t\tactive ports: %d\n", ro.ro_active);
+			printf("\t\tflapping: %u\n", ro.ro_flapping);
+			if (ra.ra_proto == LAGG_PROTO_LACP) {
+				printf("\tlag id: %s\n",
+				    lacp_format_peer(lp, "\n\t\t "));
+			}
+		}
 
 		for (i = 0; i < ra.ra_ports; i++) {
 			lp = (struct lacp_opreq *)&rpbuf[i].rp_lacpreq;
 			printf("\tlaggport: %s ", rpbuf[i].rp_portname);
 			printb("flags", rpbuf[i].rp_flags, LAGG_PORT_BITS);
 			if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
-				printf(" state=%X", lp->actor_state);
+				printb(" state", lp->actor_state,
+				    LACP_STATE_BITS);
 			putchar('\n');
 			if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
 				printf("\t\t%s\n",
@@ -226,6 +285,15 @@ static struct cmd lagg_cmds[] = {
 	DEF_CMD_ARG("-laggport",	unsetlaggport),
 	DEF_CMD_ARG("laggproto",	setlaggproto),
 	DEF_CMD_ARG("lagghash",		setlagghash),
+	DEF_CMD("use_flowid",	LAGG_OPT_USE_FLOWID,	setlaggsetopt),
+	DEF_CMD("-use_flowid",	-LAGG_OPT_USE_FLOWID,	setlaggsetopt),
+	DEF_CMD("lacp_strict",	LAGG_OPT_LACP_STRICT,	setlaggsetopt),
+	DEF_CMD("-lacp_strict",	-LAGG_OPT_LACP_STRICT,	setlaggsetopt),
+	DEF_CMD("lacp_txtest",	LAGG_OPT_LACP_TXTEST,	setlaggsetopt),
+	DEF_CMD("-lacp_txtest",	-LAGG_OPT_LACP_TXTEST,	setlaggsetopt),
+	DEF_CMD("lacp_rxtest",	LAGG_OPT_LACP_RXTEST,	setlaggsetopt),
+	DEF_CMD("-lacp_rxtest",	-LAGG_OPT_LACP_RXTEST,	setlaggsetopt),
+	DEF_CMD_ARG("flowid_shift",	setlaggflowidshift),
 };
 static struct afswtch af_lagg = {
 	.af_name	= "af_lagg",

Modified: stable/10/share/man/man4/lagg.4
==============================================================================
--- stable/10/share/man/man4/lagg.4	Sat Sep 12 20:14:54 2015	(r287722)
+++ stable/10/share/man/man4/lagg.4	Sat Sep 12 20:36:39 2015	(r287723)
@@ -16,7 +16,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 23, 2012
+.Dd October 1, 2014
 .Dt LAGG 4
 .Os
 .Sh NAME
@@ -143,9 +143,9 @@ modes will use the RSS hash from the net
 computing one, this may give poor traffic distribution if the hash is invalid
 or uses less of the protocol header information.
 Local hash computation can be forced per interface by setting the
-.Va net.link.lagg.X.use_flowid
-.Xr sysctl 8
-variable to zero where X is the interface number.
+.Cm use_flowid
+.Xr ifconfig 8
+flag.
 The default for new interfaces is set via the
 .Va net.link.lagg.default_use_flowid
 .Xr sysctl 8 .

Modified: stable/10/sys/net/ieee8023ad_lacp.c
==============================================================================
--- stable/10/sys/net/ieee8023ad_lacp.c	Sat Sep 12 20:14:54 2015	(r287722)
+++ stable/10/sys/net/ieee8023ad_lacp.c	Sat Sep 12 20:36:39 2015	(r287723)
@@ -187,15 +187,15 @@ static const char *lacp_format_portid(co
 static void	lacp_dprintf(const struct lacp_port *, const char *, ...)
 		    __attribute__((__format__(__printf__, 2, 3)));
 
-static int lacp_debug = 0;
+static VNET_DEFINE(int, lacp_debug);
+#define	V_lacp_debug	VNET(lacp_debug)
 SYSCTL_NODE(_net_link_lagg, OID_AUTO, lacp, CTLFLAG_RD, 0, "ieee802.3ad");
-SYSCTL_INT(_net_link_lagg_lacp, OID_AUTO, debug, CTLFLAG_RW | CTLFLAG_TUN,
-    &lacp_debug, 0, "Enable LACP debug logging (1=debug, 2=trace)");
-TUNABLE_INT("net.link.lagg.lacp.debug", &lacp_debug);
-
-#define LACP_DPRINTF(a) if (lacp_debug & 0x01) { lacp_dprintf a ; }
-#define LACP_TRACE(a) if (lacp_debug & 0x02) { lacp_dprintf(a,"%s\n",__func__); }
-#define LACP_TPRINTF(a) if (lacp_debug & 0x04) { lacp_dprintf a ; }
+SYSCTL_INT(_net_link_lagg_lacp, OID_AUTO, debug, CTLFLAG_RWTUN | CTLFLAG_VNET,
+    &VNET_NAME(lacp_debug), 0, "Enable LACP debug logging (1=debug, 2=trace)");
+
+#define LACP_DPRINTF(a) if (V_lacp_debug & 0x01) { lacp_dprintf a ; }
+#define LACP_TRACE(a) if (V_lacp_debug & 0x02) { lacp_dprintf(a,"%s\n",__func__); }
+#define LACP_TPRINTF(a) if (V_lacp_debug & 0x04) { lacp_dprintf a ; }
 
 /*
  * partner administration variables.
@@ -298,7 +298,7 @@ lacp_pdu_input(struct lacp_port *lp, str
 		goto bad;
 	}
 
-        if (lacp_debug > 0) {
+        if (V_lacp_debug > 0) {
 		lacp_dprintf(lp, "lacpdu receive\n");
 		lacp_dump_lacpdu(du);
 	}
@@ -383,7 +383,7 @@ lacp_xmit_lacpdu(struct lacp_port *lp)
 	    sizeof(du->ldu_collector));
 	du->ldu_collector.lci_maxdelay = 0;
 
-	if (lacp_debug > 0) {
+	if (V_lacp_debug > 0) {
 		lacp_dprintf(lp, "lacpdu transmit\n");
 		lacp_dump_lacpdu(du);
 	}
@@ -495,12 +495,14 @@ lacp_tick(void *arg)
 		if ((lp->lp_state & LACP_STATE_AGGREGATION) == 0)
 			continue;
 
+		CURVNET_SET(lp->lp_ifp->if_vnet);
 		lacp_run_timers(lp);
 
 		lacp_select(lp);
 		lacp_sm_mux(lp);
 		lacp_sm_tx(lp);
 		lacp_sm_ptx_tx_schedule(lp);
+		CURVNET_RESTORE();
 	}
 	callout_reset(&lsc->lsc_callout, hz, lacp_tick, lsc);
 }
@@ -577,12 +579,13 @@ lacp_port_destroy(struct lagg_port *lgp)
 	lacp_disable_distributing(lp);
 	lacp_unselect(lp);
 
+	LIST_REMOVE(lp, lp_next);
+	LACP_UNLOCK(lsc);
+
 	/* The address may have already been removed by if_purgemaddrs() */
 	if (!lgp->lp_detaching)
 		if_delmulti_ifma(lp->lp_ifma);
 
-	LIST_REMOVE(lp, lp_next);
-	LACP_UNLOCK(lsc);
 	free(lp, M_DEVBUF);
 }
 
@@ -743,58 +746,19 @@ lacp_transit_expire(void *vp)
 
 	LACP_LOCK_ASSERT(lsc);
 
+	CURVNET_SET(lsc->lsc_softc->sc_ifp->if_vnet);
 	LACP_TRACE(NULL);
+	CURVNET_RESTORE();
 
 	lsc->lsc_suppress_distributing = FALSE;
 }
 
-static void
-lacp_attach_sysctl(struct lacp_softc *lsc, struct sysctl_oid *p_oid)
-{
-	struct lagg_softc *sc = lsc->lsc_softc;
-
-	SYSCTL_ADD_UINT(&sc->ctx, SYSCTL_CHILDREN(p_oid), OID_AUTO,
-	    "lacp_strict_mode",
-	    CTLFLAG_RW,
-	    &lsc->lsc_strict_mode,
-	    lsc->lsc_strict_mode,
-	    "Enable LACP strict mode");
-}
-
-static void
-lacp_attach_sysctl_debug(struct lacp_softc *lsc, struct sysctl_oid *p_oid)
-{
-	struct lagg_softc *sc = lsc->lsc_softc;
-	struct sysctl_oid *oid;
-
-	/* Create a child of the parent lagg interface */
-	oid = SYSCTL_ADD_NODE(&sc->ctx, SYSCTL_CHILDREN(p_oid),
-	    OID_AUTO, "debug", CTLFLAG_RD, NULL, "DEBUG");
-
-	SYSCTL_ADD_UINT(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
-	    "rx_test",
-	    CTLFLAG_RW,
-	    &lsc->lsc_debug.lsc_rx_test,
-	    lsc->lsc_debug.lsc_rx_test,
-	    "Bitmap of if_dunit entries to drop RX frames for");
-	SYSCTL_ADD_UINT(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
-	    "tx_test",
-	    CTLFLAG_RW,
-	    &lsc->lsc_debug.lsc_tx_test,
-	    lsc->lsc_debug.lsc_tx_test,
-	    "Bitmap of if_dunit entries to drop TX frames for");
-}
-
-int
+void
 lacp_attach(struct lagg_softc *sc)
 {
 	struct lacp_softc *lsc;
-	struct sysctl_oid *oid;
 
-	lsc = malloc(sizeof(struct lacp_softc),
-	    M_DEVBUF, M_NOWAIT|M_ZERO);
-	if (lsc == NULL)
-		return (ENOMEM);
+	lsc = malloc(sizeof(struct lacp_softc), M_DEVBUF, M_WAITOK | M_ZERO);
 
 	sc->sc_psc = (caddr_t)lsc;
 	lsc->lsc_softc = sc;
@@ -806,35 +770,24 @@ lacp_attach(struct lagg_softc *sc)
 	TAILQ_INIT(&lsc->lsc_aggregators);
 	LIST_INIT(&lsc->lsc_ports);
 
-	/* Create a child of the parent lagg interface */
-	oid = SYSCTL_ADD_NODE(&sc->ctx, SYSCTL_CHILDREN(sc->sc_oid),
-	    OID_AUTO, "lacp", CTLFLAG_RD, NULL, "LACP");
-
-	/* Attach sysctl nodes */
-	lacp_attach_sysctl(lsc, oid);
-	lacp_attach_sysctl_debug(lsc, oid);
-
 	callout_init_mtx(&lsc->lsc_transit_callout, &lsc->lsc_mtx, 0);
 	callout_init_mtx(&lsc->lsc_callout, &lsc->lsc_mtx, 0);
 
 	/* if the lagg is already up then do the same */
 	if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
 		lacp_init(sc);
-
-	return (0);
 }
 
 int
-lacp_detach(struct lagg_softc *sc)
+lacp_detach(void *psc)
 {
-	struct lacp_softc *lsc = LACP_SOFTC(sc);
+	struct lacp_softc *lsc = (struct lacp_softc *)psc;
 
 	KASSERT(TAILQ_EMPTY(&lsc->lsc_aggregators),
 	    ("aggregators still active"));
 	KASSERT(lsc->lsc_active_aggregator == NULL,
 	    ("aggregator still attached"));
 
-	sc->sc_psc = NULL;
 	callout_drain(&lsc->lsc_transit_callout);
 	callout_drain(&lsc->lsc_callout);
 
@@ -883,7 +836,7 @@ lacp_select_tx_port(struct lagg_softc *s
 		return (NULL);
 	}
 
-	if (sc->use_flowid &&
+	if ((sc->sc_opts & LAGG_OPT_USE_FLOWID) &&
 	    M_HASHTYPE_GET(m) != M_HASHTYPE_NONE)
 		hash = m->m_pkthdr.flowid >> sc->flowid_shift;
 	else
@@ -1425,7 +1378,7 @@ lacp_sm_mux(struct lacp_port *lp)
 	enum lacp_selected selected = lp->lp_selected;
 	struct lacp_aggregator *la;
 
-	if (lacp_debug > 1)
+	if (V_lacp_debug > 1)
 		lacp_dprintf(lp, "%s: state= 0x%x, selected= 0x%x, "
 		    "p_sync= 0x%x, p_collecting= 0x%x\n", __func__,
 		    lp->lp_mux_state, selected, p_sync, p_collecting);

Modified: stable/10/sys/net/ieee8023ad_lacp.h
==============================================================================
--- stable/10/sys/net/ieee8023ad_lacp.h	Sat Sep 12 20:14:54 2015	(r287722)
+++ stable/10/sys/net/ieee8023ad_lacp.h	Sat Sep 12 20:36:39 2015	(r287723)
@@ -75,6 +75,7 @@
 	"\007DEFAULTED"		\
 	"\010EXPIRED"
 
+#ifdef _KERNEL
 /*
  * IEEE802.3 slow protocols
  *
@@ -282,8 +283,8 @@ struct lacp_softc {
 
 struct mbuf	*lacp_input(struct lagg_port *, struct mbuf *);
 struct lagg_port *lacp_select_tx_port(struct lagg_softc *, struct mbuf *);
-int		lacp_attach(struct lagg_softc *);
-int		lacp_detach(struct lagg_softc *);
+void		lacp_attach(struct lagg_softc *);
+int		lacp_detach(void *);
 void		lacp_init(struct lagg_softc *);
 void		lacp_stop(struct lagg_softc *);
 int		lacp_port_create(struct lagg_port *);
@@ -336,3 +337,4 @@ lacp_isdistributing(struct lagg_port *lg
 #define	LACP_LAGIDSTR_MAX	\
 	(1 + LACP_PARTNERSTR_MAX + 1 + LACP_PARTNERSTR_MAX + 1)
 #define	LACP_STATESTR_MAX	(255) /* XXX */
+#endif	/* _KERNEL */

Modified: stable/10/sys/net/if_lagg.c
==============================================================================
--- stable/10/sys/net/if_lagg.c	Sat Sep 12 20:14:54 2015	(r287722)
+++ stable/10/sys/net/if_lagg.c	Sat Sep 12 20:36:39 2015	(r287723)
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 
 #if defined(INET) || defined(INET6)
 #include 
@@ -81,13 +82,21 @@ static struct {
 	{0, NULL}
 };
 
-SLIST_HEAD(__trhead, lagg_softc) lagg_list;	/* list of laggs */
-static struct mtx	lagg_list_mtx;
+VNET_DEFINE(SLIST_HEAD(__trhead, lagg_softc), lagg_list); /* list of laggs */
+#define	V_lagg_list	VNET(lagg_list)
+static VNET_DEFINE(struct mtx, lagg_list_mtx);
+#define	V_lagg_list_mtx	VNET(lagg_list_mtx)
+#define	LAGG_LIST_LOCK_INIT(x)		mtx_init(&V_lagg_list_mtx, \
+					"if_lagg list", NULL, MTX_DEF)
+#define	LAGG_LIST_LOCK_DESTROY(x)	mtx_destroy(&V_lagg_list_mtx)
+#define	LAGG_LIST_LOCK(x)		mtx_lock(&V_lagg_list_mtx)
+#define	LAGG_LIST_UNLOCK(x)		mtx_unlock(&V_lagg_list_mtx)
 eventhandler_tag	lagg_detach_cookie = NULL;
 
 static int	lagg_clone_create(struct if_clone *, int, caddr_t);
 static void	lagg_clone_destroy(struct ifnet *);
-static struct if_clone *lagg_cloner;
+static VNET_DEFINE(struct if_clone *, lagg_cloner);
+#define	V_lagg_cloner	VNET(lagg_cloner)
 static const char laggname[] = "lagg";
 
 static void	lagg_lladdr(struct lagg_softc *, uint8_t *);
@@ -122,24 +131,23 @@ static void	lagg_media_status(struct ifn
 static struct lagg_port *lagg_link_active(struct lagg_softc *,
 	    struct lagg_port *);
 static const void *lagg_gethdr(struct mbuf *, u_int, u_int, void *);
-static int	lagg_sysctl_active(SYSCTL_HANDLER_ARGS);
 
 /* Simple round robin */
-static int	lagg_rr_attach(struct lagg_softc *);
+static void	lagg_rr_attach(struct lagg_softc *);
 static int	lagg_rr_detach(struct lagg_softc *);
 static int	lagg_rr_start(struct lagg_softc *, struct mbuf *);
 static struct mbuf *lagg_rr_input(struct lagg_softc *, struct lagg_port *,
 		    struct mbuf *);
 
 /* Active failover */
-static int	lagg_fail_attach(struct lagg_softc *);
+static void	lagg_fail_attach(struct lagg_softc *);
 static int	lagg_fail_detach(struct lagg_softc *);
 static int	lagg_fail_start(struct lagg_softc *, struct mbuf *);
 static struct mbuf *lagg_fail_input(struct lagg_softc *, struct lagg_port *,
 		    struct mbuf *);
 
 /* Loadbalancing */
-static int	lagg_lb_attach(struct lagg_softc *);
+static void	lagg_lb_attach(struct lagg_softc *);
 static int	lagg_lb_detach(struct lagg_softc *);
 static int	lagg_lb_port_create(struct lagg_port *);
 static void	lagg_lb_port_destroy(struct lagg_port *);
@@ -149,7 +157,7 @@ static struct mbuf *lagg_lb_input(struct
 static int	lagg_lb_porttable(struct lagg_softc *, struct lagg_port *);
 
 /* 802.3ad LACP */
-static int	lagg_lacp_attach(struct lagg_softc *);
+static void	lagg_lacp_attach(struct lagg_softc *);
 static int	lagg_lacp_detach(struct lagg_softc *);
 static int	lagg_lacp_start(struct lagg_softc *, struct mbuf *);
 static struct mbuf *lagg_lacp_input(struct lagg_softc *, struct lagg_port *,
@@ -159,9 +167,9 @@ static void	lagg_lacp_lladdr(struct lagg
 static void	lagg_callout(void *);
 
 /* lagg protocol table */
-static const struct {
-	int			ti_proto;
-	int			(*ti_attach)(struct lagg_softc *);
+static const struct lagg_proto {
+	lagg_proto	ti_proto;
+	void		(*ti_attach)(struct lagg_softc *);
 } lagg_protos[] = {
 	{ LAGG_PROTO_ROUNDROBIN,	lagg_rr_attach },
 	{ LAGG_PROTO_FAILOVER,		lagg_fail_attach },
@@ -175,31 +183,55 @@ SYSCTL_DECL(_net_link);
 SYSCTL_NODE(_net_link, OID_AUTO, lagg, CTLFLAG_RW, 0,
     "Link Aggregation");
 
-static int lagg_failover_rx_all = 0; /* Allow input on any failover links */
-SYSCTL_INT(_net_link_lagg, OID_AUTO, failover_rx_all, CTLFLAG_RW,
-    &lagg_failover_rx_all, 0,
+/* Allow input on any failover links */
+static VNET_DEFINE(int, lagg_failover_rx_all);
+#define	V_lagg_failover_rx_all	VNET(lagg_failover_rx_all)
+SYSCTL_INT(_net_link_lagg, OID_AUTO, failover_rx_all, CTLFLAG_RW | CTLFLAG_VNET,
+    &VNET_NAME(lagg_failover_rx_all), 0,
     "Accept input from any interface in a failover lagg");
-static int def_use_flowid = 1; /* Default value for using flowid */
-TUNABLE_INT("net.link.lagg.default_use_flowid", &def_use_flowid);
-SYSCTL_INT(_net_link_lagg, OID_AUTO, default_use_flowid, CTLFLAG_RW,
-    &def_use_flowid, 0,
+
+/* Default value for using M_FLOWID */
+static VNET_DEFINE(int, def_use_flowid) = 1;
+#define	V_def_use_flowid	VNET(def_use_flowid)
+SYSCTL_INT(_net_link_lagg, OID_AUTO, default_use_flowid, CTLFLAG_RWTUN,
+    &VNET_NAME(def_use_flowid), 0,
     "Default setting for using flow id for load sharing");
-static int def_flowid_shift = 16; /* Default value for using flow shift */
-TUNABLE_INT("net.link.lagg.default_flowid_shift", &def_flowid_shift);
-SYSCTL_INT(_net_link_lagg, OID_AUTO, default_flowid_shift, CTLFLAG_RW,
-    &def_flowid_shift, 0,
+
+/* Default value for using M_FLOWID */
+static VNET_DEFINE(int, def_flowid_shift) = 16;
+#define	V_def_flowid_shift	VNET(def_flowid_shift)
+SYSCTL_INT(_net_link_lagg, OID_AUTO, default_flowid_shift, CTLFLAG_RWTUN,
+    &VNET_NAME(def_flowid_shift), 0,
     "Default setting for flowid shift for load sharing");
 
+static void
+vnet_lagg_init(const void *unused __unused)
+{
+
+	LAGG_LIST_LOCK_INIT();
+	SLIST_INIT(&V_lagg_list);
+	V_lagg_cloner = if_clone_simple(laggname, lagg_clone_create,
+	    lagg_clone_destroy, 0);
+}
+VNET_SYSINIT(vnet_lagg_init, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY,
+    vnet_lagg_init, NULL);
+
+static void
+vnet_lagg_uninit(const void *unused __unused)
+{
+
+	if_clone_detach(V_lagg_cloner);
+	LAGG_LIST_LOCK_DESTROY();
+}
+VNET_SYSUNINIT(vnet_lagg_uninit, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY,
+    vnet_lagg_uninit, NULL);
+
 static int
 lagg_modevent(module_t mod, int type, void *data)
 {
 
 	switch (type) {
 	case MOD_LOAD:
-		mtx_init(&lagg_list_mtx, "if_lagg list", NULL, MTX_DEF);
-		SLIST_INIT(&lagg_list);
-		lagg_cloner = if_clone_simple(laggname, lagg_clone_create,
-		    lagg_clone_destroy, 0);
 		lagg_input_p = lagg_input;
 		lagg_linkstate_p = lagg_port_state;
 		lagg_detach_cookie = EVENTHANDLER_REGISTER(
@@ -209,10 +241,8 @@ lagg_modevent(module_t mod, int type, vo
 	case MOD_UNLOAD:
 		EVENTHANDLER_DEREGISTER(ifnet_departure_event,
 		    lagg_detach_cookie);
-		if_clone_detach(lagg_cloner);
 		lagg_input_p = NULL;
 		lagg_linkstate_p = NULL;
-		mtx_destroy(&lagg_list_mtx);
 		break;
 	default:
 		return (EOPNOTSUPP);
@@ -278,10 +308,8 @@ lagg_clone_create(struct if_clone *ifc, 
 {
 	struct lagg_softc *sc;
 	struct ifnet *ifp;
-	int i, error = 0;
 	static const u_char eaddr[6];	/* 00:00:00:00:00:00 */
-	struct sysctl_oid *oid;
-	char num[14];			/* sufficient for 32 bits */
+	int i;
 
 	sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
 	ifp = sc->sc_ifp = if_alloc(IFT_ETHER);
@@ -295,29 +323,10 @@ lagg_clone_create(struct if_clone *ifc, 
 	sc->sc_ibytes = counter_u64_alloc(M_WAITOK);
 	sc->sc_obytes = counter_u64_alloc(M_WAITOK);
 
-	sysctl_ctx_init(&sc->ctx);
-	snprintf(num, sizeof(num), "%u", unit);
-	sc->use_flowid = def_use_flowid;
-	sc->flowid_shift = def_flowid_shift;
-	sc->sc_oid = oid = SYSCTL_ADD_NODE(&sc->ctx,
-		&SYSCTL_NODE_CHILDREN(_net_link, lagg),
-		OID_AUTO, num, CTLFLAG_RD, NULL, "");
-	SYSCTL_ADD_INT(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
-		"use_flowid", CTLFLAG_RW, &sc->use_flowid,
-		sc->use_flowid, "Use flow id for load sharing");
-	SYSCTL_ADD_INT(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
-		"flowid_shift", CTLFLAG_RW, &sc->flowid_shift,
-		sc->flowid_shift,
-		"Shift flowid bits to prevent multiqueue collisions");
-	SYSCTL_ADD_INT(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
-		"count", CTLFLAG_RD, &sc->sc_count, sc->sc_count,
-		"Total number of ports");
-	SYSCTL_ADD_PROC(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
-		"active", CTLTYPE_INT|CTLFLAG_RD, sc, 0, lagg_sysctl_active,
-		"I", "Total number of active ports");
-	SYSCTL_ADD_INT(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
-		"flapping", CTLFLAG_RD, &sc->sc_flapping,
-		sc->sc_flapping, "Total number of port change events");
+	if (V_def_use_flowid)
+		sc->sc_opts |= LAGG_OPT_USE_FLOWID;
+	sc->flowid_shift = V_def_flowid_shift;
+
 	/* Hash all layers by default */
 	sc->sc_flags = LAGG_F_HASHL2|LAGG_F_HASHL3|LAGG_F_HASHL4;
 
@@ -325,11 +334,7 @@ lagg_clone_create(struct if_clone *ifc, 
 	for (i = 0; lagg_protos[i].ti_proto != LAGG_PROTO_NONE; i++) {
 		if (lagg_protos[i].ti_proto == LAGG_PROTO_DEFAULT) {
 			sc->sc_proto = lagg_protos[i].ti_proto;
-			if ((error = lagg_protos[i].ti_attach(sc)) != 0) {
-				if_free(ifp);
-				free(sc, M_DEVBUF);
-				return (error);
-			}
+			lagg_protos[i].ti_attach(sc);
 			break;
 		}
 	}
@@ -371,9 +376,9 @@ lagg_clone_create(struct if_clone *ifc, 
 		lagg_unregister_vlan, sc, EVENTHANDLER_PRI_FIRST);
 
 	/* Insert into the global list of laggs */
-	mtx_lock(&lagg_list_mtx);
-	SLIST_INSERT_HEAD(&lagg_list, sc, sc_entries);
-	mtx_unlock(&lagg_list_mtx);
+	LAGG_LIST_LOCK();
+	SLIST_INSERT_HEAD(&V_lagg_list, sc, sc_entries);
+	LAGG_LIST_UNLOCK();
 
 	callout_reset(&sc->sc_callout, hz, lagg_callout, sc);
 
@@ -400,10 +405,9 @@ lagg_clone_destroy(struct ifnet *ifp)
 	/* Unhook the aggregation protocol */
 	if (sc->sc_detach != NULL)
 		(*sc->sc_detach)(sc);
+	else
+		LAGG_WUNLOCK(sc);
 
-	LAGG_WUNLOCK(sc);
-
-	sysctl_ctx_free(&sc->ctx);
 	ifmedia_removeall(&sc->sc_media);
 	ether_ifdetach(ifp);
 	if_free(ifp);
@@ -417,9 +421,9 @@ lagg_clone_destroy(struct ifnet *ifp)
 	counter_u64_free(sc->sc_ibytes);
 	counter_u64_free(sc->sc_obytes);
 
-	mtx_lock(&lagg_list_mtx);
-	SLIST_REMOVE(&lagg_list, sc, lagg_softc, sc_entries);
-	mtx_unlock(&lagg_list_mtx);
+	LAGG_LIST_LOCK();
+	SLIST_REMOVE(&V_lagg_list, sc, lagg_softc, sc_entries);
+	LAGG_LIST_UNLOCK();
 
 	taskqueue_drain(taskqueue_swi, &sc->sc_lladdr_task);
 	LAGG_LOCK_DESTROY(sc);
@@ -431,15 +435,28 @@ static void
 lagg_lladdr(struct lagg_softc *sc, uint8_t *lladdr)
 {
 	struct ifnet *ifp = sc->sc_ifp;
+	struct lagg_port lp;
 
 	if (memcmp(lladdr, IF_LLADDR(ifp), ETHER_ADDR_LEN) == 0)
 		return;
 
+	LAGG_WLOCK_ASSERT(sc);
+	/*
+	 * Set the link layer address on the lagg interface.
+	 * sc_lladdr() notifies the MAC change to
+	 * the aggregation protocol.  iflladdr_event handler which
+	 * may trigger gratuitous ARPs for INET will be handled in
+	 * a taskqueue.
+	 */
 	bcopy(lladdr, IF_LLADDR(ifp), ETHER_ADDR_LEN);
-	/* Let the protocol know the MAC has changed */
 	if (sc->sc_lladdr != NULL)
 		(*sc->sc_lladdr)(sc);
-	EVENTHANDLER_INVOKE(iflladdr_event, ifp);
+
+	bzero(&lp, sizeof(lp));
+	lp.lp_ifp = sc->sc_ifp;
+	lp.lp_softc = sc;
+
+	lagg_port_lladdr(&lp, lladdr);
 }
 
 static void
@@ -487,11 +504,13 @@ lagg_port_lladdr(struct lagg_port *lp, u
 	struct ifnet *ifp = lp->lp_ifp;
 	struct lagg_llq *llq;
 	int pending = 0;
+	int primary;
 
 	LAGG_WLOCK_ASSERT(sc);
 
-	if (lp->lp_detaching ||
-	    memcmp(lladdr, IF_LLADDR(ifp), ETHER_ADDR_LEN) == 0)
+	primary = (sc->sc_primary->lp_ifp == ifp) ? 1 : 0;
+	if (primary == 0 && (lp->lp_detaching ||
+	    memcmp(lladdr, IF_LLADDR(ifp), ETHER_ADDR_LEN) == 0))
 		return;
 
 	/* Check to make sure its not already queued to be changed */
@@ -510,6 +529,7 @@ lagg_port_lladdr(struct lagg_port *lp, u
 
 	/* Update the lladdr even if pending, it may have changed */
 	llq->llq_ifp = ifp;
+	llq->llq_primary = primary;
 	bcopy(lladdr, llq->llq_lladdr, ETHER_ADDR_LEN);
 
 	if (!pending)
@@ -542,14 +562,20 @@ lagg_port_setlladdr(void *arg, int pendi
 	for (llq = head; llq != NULL; llq = head) {
 		ifp = llq->llq_ifp;
 
-		/* Set the link layer address */
 		CURVNET_SET(ifp->if_vnet);
-		error = if_setlladdr(ifp, llq->llq_lladdr, ETHER_ADDR_LEN);
+		if (llq->llq_primary == 0) {
+			/*
+			 * Set the link layer address on the laggport interface.
+			 * if_setlladdr() triggers gratuitous ARPs for INET.
+			 */
+			error = if_setlladdr(ifp, llq->llq_lladdr,
+			    ETHER_ADDR_LEN);
+			if (error)
+				printf("%s: setlladdr failed on %s\n", __func__,
+				    ifp->if_xname);
+		} else
+			EVENTHANDLER_INVOKE(iflladdr_event, ifp);
 		CURVNET_RESTORE();
-		if (error)
-			printf("%s: setlladdr failed on %s\n", __func__,
-			    ifp->if_xname);
-
 		head = SLIST_NEXT(llq, llq_entries);
 		free(llq, M_DEVBUF);
 	}
@@ -581,34 +607,6 @@ lagg_port_create(struct lagg_softc *sc, 
 	if (ifp->if_type != IFT_ETHER)
 		return (EPROTONOSUPPORT);
 
-#ifdef INET6
-	/*
-	 * The member interface should not have inet6 address because
-	 * two interfaces with a valid link-local scope zone must not be
-	 * merged in any form.  This restriction is needed to
-	 * prevent violation of link-local scope zone.  Attempts to
-	 * add a member interface which has inet6 addresses triggers
-	 * removal of all inet6 addresses on the member interface.
-	 */
-	SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
-		if (in6ifa_llaonifp(lp->lp_ifp)) {
-			in6_ifdetach(lp->lp_ifp);
-			if_printf(sc->sc_ifp,
-			    "IPv6 addresses on %s have been removed "
-			    "before adding it as a member to prevent "
-			    "IPv6 address scope violation.\n",
-			    lp->lp_ifp->if_xname);
-		}
-	}
-	if (in6ifa_llaonifp(ifp)) {
-		in6_ifdetach(ifp);
-		if_printf(sc->sc_ifp,
-		    "IPv6 addresses on %s have been removed "
-		    "before adding it as a member to prevent "
-		    "IPv6 address scope violation.\n",
-		    ifp->if_xname);
-	}
-#endif
 	/* Allow the first Ethernet member to define the MTU */
 	if (SLIST_EMPTY(&sc->sc_ports))
 		sc->sc_ifp->if_mtu = ifp->if_mtu;
@@ -623,10 +621,10 @@ lagg_port_create(struct lagg_softc *sc, 
 		return (ENOMEM);
 
 	/* Check if port is a stacked lagg */
-	mtx_lock(&lagg_list_mtx);
-	SLIST_FOREACH(sc_ptr, &lagg_list, sc_entries) {
+	LAGG_LIST_LOCK();
+	SLIST_FOREACH(sc_ptr, &V_lagg_list, sc_entries) {
 		if (ifp == sc_ptr->sc_ifp) {
-			mtx_unlock(&lagg_list_mtx);
+			LAGG_LIST_UNLOCK();
 			free(lp, M_DEVBUF);
 			return (EINVAL);
 			/* XXX disable stacking for the moment, its untested */
@@ -634,14 +632,14 @@ lagg_port_create(struct lagg_softc *sc, 
 			lp->lp_flags |= LAGG_PORT_STACK;
 			if (lagg_port_checkstacking(sc_ptr) >=
 			    LAGG_MAX_STACKING) {
-				mtx_unlock(&lagg_list_mtx);
+				LAGG_LIST_UNLOCK();
 				free(lp, M_DEVBUF);
 				return (E2BIG);
 			}
 #endif
 		}
 	}
-	mtx_unlock(&lagg_list_mtx);
+	LAGG_LIST_UNLOCK();
 
 	/* Change the interface type */
 	lp->lp_iftype = ifp->if_type;
@@ -991,10 +989,12 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 {
 	struct lagg_softc *sc = (struct lagg_softc *)ifp->if_softc;
 	struct lagg_reqall *ra = (struct lagg_reqall *)data;
+	struct lagg_reqopts *ro = (struct lagg_reqopts *)data;
 	struct lagg_reqport *rp = (struct lagg_reqport *)data, rpbuf;
 	struct lagg_reqflags *rf = (struct lagg_reqflags *)data;
 	struct ifreq *ifr = (struct ifreq *)data;
 	struct lagg_port *lp;
+	const struct lagg_proto *proto = NULL;
 	struct ifnet *tpif;
 	struct thread *td = curthread;
 	char *buf, *outbuf;
@@ -1042,50 +1042,136 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 		error = priv_check(td, PRIV_NET_LAGG);
 		if (error)
 			break;
-		if (ra->ra_proto >= LAGG_PROTO_MAX) {
+		for (proto = lagg_protos; proto->ti_proto != LAGG_PROTO_NONE;
+		    proto++) {
+			if (proto->ti_proto == ra->ra_proto) {
+				if (sc->sc_ifflags & IFF_DEBUG)
+					printf("%s: using proto %u\n",
+					    sc->sc_ifname, proto->ti_proto);
+				break;
+			}
+		}
+		if (proto->ti_proto == LAGG_PROTO_NONE) {
 			error = EPROTONOSUPPORT;
 			break;
 		}
+		/* Set to LAGG_PROTO_NONE during the attach. */
 		LAGG_WLOCK(sc);
 		if (sc->sc_proto != LAGG_PROTO_NONE) {
-			/* Reset protocol first in case detach unlocks */
 			sc->sc_proto = LAGG_PROTO_NONE;
-			error = sc->sc_detach(sc);
-			sc->sc_detach = NULL;
-			sc->sc_start = NULL;
-			sc->sc_input = NULL;
-			sc->sc_port_create = NULL;
-			sc->sc_port_destroy = NULL;
-			sc->sc_linkstate = NULL;
-			sc->sc_init = NULL;
-			sc->sc_stop = NULL;
-			sc->sc_lladdr = NULL;
-			sc->sc_req = NULL;
-			sc->sc_portreq = NULL;
-		} else if (sc->sc_input != NULL) {
-			/* Still detaching */
-			error = EBUSY;
+			if (sc->sc_detach != NULL)
+				sc->sc_detach(sc);
+			else
+				LAGG_WUNLOCK(sc);
 		}
-		if (error != 0) {
-			LAGG_WUNLOCK(sc);
+		proto->ti_attach(sc);
+		LAGG_WLOCK(sc);
+		sc->sc_proto = proto->ti_proto;
+		LAGG_WUNLOCK(sc);
+		break;
+	case SIOCGLAGGOPTS:
+		ro->ro_opts = sc->sc_opts;
+		if (sc->sc_proto == LAGG_PROTO_LACP) {
+			struct lacp_softc *lsc;
+
+			lsc = (struct lacp_softc *)sc->sc_psc;
+			if (lsc->lsc_debug.lsc_tx_test != 0)
+				ro->ro_opts |= LAGG_OPT_LACP_TXTEST;
+			if (lsc->lsc_debug.lsc_rx_test != 0)
+				ro->ro_opts |= LAGG_OPT_LACP_RXTEST;
+			if (lsc->lsc_strict_mode != 0)
+				ro->ro_opts |= LAGG_OPT_LACP_STRICT;
+
+			ro->ro_active = sc->sc_active;
+		} else {
+			ro->ro_active = 0;
+			SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
+				ro->ro_active += LAGG_PORTACTIVE(lp);
+		}
+		ro->ro_flapping = sc->sc_flapping;
+		ro->ro_flowid_shift = sc->flowid_shift;
+		break;
+	case SIOCSLAGGOPTS:
+		error = priv_check(td, PRIV_NET_LAGG);
+		if (error)
+			break;
+		if (ro->ro_opts == 0)
+			break;
+		/*
+		 * Set options.  LACP options are stored in sc->sc_psc,
+		 * not in sc_opts.
+		 */
+		int valid, lacp;
+
+		switch (ro->ro_opts) {
+		case LAGG_OPT_USE_FLOWID:
+		case -LAGG_OPT_USE_FLOWID:
+		case LAGG_OPT_FLOWIDSHIFT:
+			valid = 1;
+			lacp = 0;
+			break;
+		case LAGG_OPT_LACP_TXTEST:
+		case -LAGG_OPT_LACP_TXTEST:
+		case LAGG_OPT_LACP_RXTEST:
+		case -LAGG_OPT_LACP_RXTEST:
+		case LAGG_OPT_LACP_STRICT:
+		case -LAGG_OPT_LACP_STRICT:
+			valid = lacp = 1;
+			break;
+		default:
+			valid = lacp = 0;
 			break;
 		}
-		for (int i = 0; i < (sizeof(lagg_protos) /
-		    sizeof(lagg_protos[0])); i++) {
-			if (lagg_protos[i].ti_proto == ra->ra_proto) {
-				if (sc->sc_ifflags & IFF_DEBUG)
-					printf("%s: using proto %u\n",
-					    sc->sc_ifname,
-					    lagg_protos[i].ti_proto);
-				sc->sc_proto = lagg_protos[i].ti_proto;
-				if (sc->sc_proto != LAGG_PROTO_NONE)

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***