MFC r252026:
  Use IPSECSTAT_INC() and IPSEC6STAT_INC() macros for ipsec statistics
  accounting.


git-svn-id: svn://svn.freebsd.org/base/stable/9@252692 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r252028:
  Use corresponding macros to update statistics for AH, ESP, IPIP, IPCOMP,
  PFKEY.


git-svn-id: svn://svn.freebsd.org/base/stable/9@252693 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Protect the #define MALLOC_PRODUCTION directive in case it was also
defined on the command line (due to MALLOC_PRODUCTION=yes in src.conf).


git-svn-id: svn://svn.freebsd.org/base/stable/9@252699 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r240774:
Don't use global nfs_root_node variable as per-file storage. There are
fields that should be file-specific.


git-svn-id: svn://svn.freebsd.org/base/stable/9@252700 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC  r240780, r252468:
Make nfs_readdir() more careful about using response data, cached in global
buffer. For now it fixes bug when following `ls` command will return data
from previous one aborted by pager. Also it should allow to read several
directories same time, for example, for recursive tracerse.


git-svn-id: svn://svn.freebsd.org/base/stable/9@252701 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Merge clang 3.3 release and various fixes: r241214, r246705, r248548,
r249423, r249817, r250217, r250593, r250616, r250997, r251216, r251662,
r251761, r251785, r251790, r252039.

MFC r241214 (by jkim):
  Do not install incomplete unwind.h from clang.  This header file was meant
  to be a wrapper for the canonical system header file.  Unfortunately, we do
  not have one (yet) and some times it is causing weird failures when clang
  is used for building ports.  More complete and correct file will come from
  libcxxrt in the future.

  Discussed with:	dim, kib, theraven

MFC r246705 (by andrew):
  Allow us to build clang for ARM EABI. Clang and llvm use the
  arm-gnueabi-freebsd10.0 triple for EABI. Use this when we are on arm or
  armv6 and are building for EABI.

  Reviewed by:	dim

MFC r248548 (by andrew):
  Pull in r177252 from upstream clang trunk:

   Make sure to use same EABI version for external assembler as for
   integrated as.

  This allows us to use gcc on a world built with clang on ARM.

MFC r249423:
  Upgrade our copy of llvm/clang to trunk r178860, in preparation of the
  upcoming 3.3 release (branching and freezing expected in a few weeks).

  Preliminary release notes can be found at the usual location:
  <http://llvm.org/docs/ReleaseNotes.html>

  An MFC is planned once the actual 3.3 release is finished.

MFC r249817:
  Pull in r180121 from upstream llvm trunk:

    LoopVectorizer: Fix 15830. When scalarizing and unrolling stores make
    sure that the order in which the elements are scalarized is the same
    as the original order.
    This fixes a miscompilation in FreeBSD's regex library.

  This should fix lib/libc/regex/regcomp.c at -O3 with clang 3.3 r178860
  on CPUs with SSE.  Before this change, the vectorizer could incorrectly
  rearrange the second loop in computejumps(), leading to possibly invalid
  entries in the re_gets::charjump table.

  The net result was that for example "sed s/@CC@/foo/" failed to work
  correctly, leading to trouble with many configure scripts.

MFC r250217:
  Allow building clang on older FreeBSD releases, where log2() does not
  exist yet.  With this change, I have verified that building head on
  8.1-RELEASE works.

  Noticed by:	Ryan Stone <rysto32@gmail.com>

MFC r250593:
  Pull in r181286 from upstream llvm trunk:

    LoopVectorize: getConsecutiveVector must respect signed arithmetic

    We were passing an i32 to ConstantInt::get where an i64 was needed and we must
    also pass the sign if we pass negatives numbers. The start index passed to
    getConsecutiveVector must also be signed.

    Should fix PR15882.

  This should fix Firefox crashes some people have been reporting, when it
  is compiled with -O3.

MFC r250616:
  Use an ugly hack to get around bootstrapping problems when building
  clang on head between r239347 and r245428.

  The former revision introduced CLOCK_PROCESS_CPUTIME_ID as a clock id
  for the clock_gettime() function and friends, but it was only added in
  <sys/time.h>, not in <time.h>.  Any program including <time.h> would
  therefore not be able to use CLOCK_PROCESS_CPUTIME_ID, even though the
  value of _POSIX_CPUTIME indicates its existence.  The latter revision
  synchronized the defines again.

  Work around this problem by defining the id on the command line for the
  particular .cpp file that needs it.  If the id ever changes value, this
  hack will need to be updated.

MFC r250997:
  Pull in r182656 from upstream llvm trunk:

    LoopVectorize: LoopSimplify can't canonicalize loops with an
    indirectbr in it, don't assert on those cases.

    Fixes PR16139.

  This should fix clang assertion failures when optimizing at -O3, similar
  to:

    Assertion failed: (TheLoop->getLoopPreheader() && "No preheader!!"),
    function canVectorize, file
    contrib/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp, line 2171.

  Reported by:	O. Hartmann <ohartman@zedat.fu-berlin.de>
  PR:		ports/178332, ports/178977

MFC r251216 (by ed):
  Pull in r183033 and r183036 from LLVM trunk:

    Add support for optimized (non-generic) atomic libcalls.

    For integer types of sizes 1, 2, 4 and 8, libcompiler-rt (and libgcc)
    provide atomic functions that pass parameters by value and return
    results directly.

    libgcc and libcompiler-rt only provide optimized libcalls for
    __atomic_fetch_*, as generic libcalls on non-integer types would make
    little sense. This means that we can finally make __atomic_fetch_*
    work
    on architectures for which we don't provide these operations as
    builtins
    (e.g. ARM).

    This should fix the dreaded "cannot compile this atomic library call
    yet" error that would pop up once every while.

  This should make it possible for me to get C11 atomics working on all of
  our platforms.

MFC r251662:
  Upgrade our copy of llvm/clang to 3.3 release.

  Release notes are still in the works, these will follow soon.

MFC r251761:
  Pull in r181620 from llvm trunk:

    [ms-inline asm] Fix a crasher when we fail on a direct match.

    The issue was that the MatchingInlineAsm and VariantID args to the
    MatchInstructionImpl function weren't being set properly.  Specifically, when
    parsing intel syntax, the parser thought it was parsing inline assembly in the
    at&t dialect; that will never be the case.

    The crash was caused when the emitter tried to emit the instruction, but the
    operands weren't set.  When parsing inline assembly we only set the opcode, not
    the operands, which is used to lookup the instruction descriptor.
    rdar://13854391 and PR15945

    Also, this commit reverts r176036.  Now that we're correctly parsing the intel
    syntax the pushad/popad don't match properly.  I've reimplemented that fix using
    a MnemonicAlias.

  Pull in r183907 from llvm trunk:

    X86: Make the cmov aliases work with intel syntax too.

  These commits make a number of Intel-style inline assembly mnemonics
  aliases (occurring in several ports) work properly, which could cause
  assertions otherwise.

  Reported by:	kwm, bapt

MFC r251785 (by ed)
  Pull in r184040 from upstream clang trunk:

    Emit native implementations of atomic operations on FreeBSD/armv6.

    Just like on Linux, FreeBSD/armv6 assumes the system supports
    ldrex/strex unconditionally. It is also used by the kernel. We can
    therefore enable support for it, like we do on Linux.

    While there, change one of the unit tests to explicitly test against
    armv5 instead of armv7, as it actually tests whether libcalls are
    emitted.

MFC r251790 (by andrew):
  Pull in r183926 from LLVM trunk:

    Allow clang to build __clear_cache on ARM.

    __clear_cache is special. It needs no signature, but is a real function in
    compiler_rt or libgcc.

    Patch by Andrew Turner.

  This allows us to build the __clear_cache function in compiler-rt.

MFC r252039:
  Pull in r183984 from llvm trunk:

    Make PrologEpilogInserter save/restore all callee saved registers in
    functions which call __builtin_unwind_init()

    __builtin_unwind_init() is an undocumented gcc intrinsic which has
    this effect, and is used in libgcc_eh.

    Goes part of the way toward fixing PR8541.

  This obsoletes the ugly hack to libgcc's unwind code from r245272, and
  should also work for other arches, so revert the hack too.


git-svn-id: svn://svn.freebsd.org/base/stable/9@252723 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r249940:
Teach GEOM and CAM about the difference between the max "size" of r/w and delete
requests.

MFC r252657:
Bump disk(9) ABI version to signify the addition of d_delmaxsize.

Make the addition of the d_delmaxsize binary compatible.  This allows storage
drivers compiled for 9.0 and 9.1 to work by preserving the ABI for disks.

Reviewed by:	mav


git-svn-id: svn://svn.freebsd.org/base/stable/9@252730 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r252387:

Make libsupc++'s __cxa_call_terminate() prototype consistent with the
definition.

Submitted by:	dt71@gmx.com


git-svn-id: svn://svn.freebsd.org/base/stable/9@252731 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC: r252067
Since some NFSv4 servers enforce the requirement for a reserved port#,
enable use of the (no)resvport mount option for NFSv4. I had thought
that the RFC required that non-reserved port #s be allowed, but I couldn't
find it in the RFC.


git-svn-id: svn://svn.freebsd.org/base/stable/9@252739 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Merge r252230:

  Implement ifconfig_wlanX="HOSTAP".

  Not only this is a bit cleaner, it allows multiple instances of hostapd to be
  running on the system host, useful for simultaneous dual-band WiFi.
  This is similar to ifconfig_wlanX="WPA" but it uses /etc/hostapd-wlanX.conf.
  Compatibility with hostapd_enable=YES/NO was kept.


git-svn-id: svn://svn.freebsd.org/base/stable/9@252748 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r251629: 3741 zfs needs better comments

Embellish the comments in various components of ZFS.  Move some comments
around closer to what they describe.  Specifically, answer the questions:

- What are some of the edge cases of the dbuf state machine?
- What does a txg quiesce do?
- When does the DMU notify threads waiting on txg's that they may
  proceed?
- How do the calculations for RAIDZ map allocations work?
- What process do the RAIDZ I/O start and done callbacks follow?

While here, adjust the function prototype of dmu_zfetch.c:dmu_zfetch_colinear()
to match its comment which describes its return as a boolean.

Submitted by:	asomers, gibbs, will
Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Eric Schrock <eric.schrock@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic


git-svn-id: svn://svn.freebsd.org/base/stable/9@252749 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r251631: illumos #3742 zfs comments need cleaner, more consistent style

- Make more of ZFS's comments use a natural English writing flow.
- Break up long paragraphs, fix various typos and spelling errors.
- Don't prefix a function description with its name when the function
  definition immediately follows.
- Remove useless comments.
- Add extra whitespace where it makes the comments more readable.

New comments were separated from this change and added in r251629.

Submitted by:	asomers, gibbs, will
Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		George Wilson <george.wilson@delphix.com>,
		Eric Schrock <eric.schrock@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic


git-svn-id: svn://svn.freebsd.org/base/stable/9@252751 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r251632: illumos #3743 zfs needs a refcount audit

Audit zap cursor usage and correct missing calls to zap_cursor_fini().

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_errlog.c:
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zap.c:
	Correct early exit handling of several functions that
	previously failed to close a cursor prior to returning.

Submitted by:	gibbs

Audit holders of dmu_bufs and correct missing calls to dmu_buf_rele().

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_dataset.c:
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zap.c:
	Correct early exit handling of several functions that
	previously failed to release a dmu_buf prior to returning.

Submitted by:	will

Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Eric Schrock <eric.schrock@delphix.com>,
		George Wilson <george.wilson@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic


git-svn-id: svn://svn.freebsd.org/base/stable/9@252754 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r251633: illumos #3744 zfs shouldn't ignore errors unmounting
snapshots

Propagate errors from zfs_unmount_snap() up to its callers wherever
feasible.

Submitted by:	will
Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic


git-svn-id: svn://svn.freebsd.org/base/stable/9@252756 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r251634: illumos #3745 zpool create should treat -O mountpoint and -m the same

cddl/contrib/opensolaris/cmd/zpool/zpool_main.c:  (change 644608)
	This allows specifying a mountpoint using the latter form and having
	its value checked and used as it would be using the former form.

	As a consequence of this change:

	1. The mountpoint property is set in the fsprops nvlist prior
	   to creating the pool, rather than being set after creating
	   the pool.  To me, this is the proper approach, since it
	   avoids creating the pool if the mountpoint setting would
	   cause the command to fail.
	2. The mountpoint property, unlike all others, can be specified
	   more than once.  Only the last setting takes effect.  This
	   is to avoid breaking potential existing users that specify
	   -m more than once.

Submitted by:	will

cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c
	Fix "zpool create -R <whatever> -m <whatever>".  Ever since
	change 644608, this has been broken.  The problem is that some
	old code in libzfs_pool.c would force a pool's mountpoint to
	"/" when creating a pool with an altroot.  That probably
	implemented some old policy decision regarding altroots, but it
	conflicts with the current manpage.  It also had no effect
	until 644608, because the zpool command would _always_ change
	the pool's mountpoint after creating it.  The solution is to
	delete the old code from libzfs_pool.c.

Submitted by:	asomers

Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic


git-svn-id: svn://svn.freebsd.org/base/stable/9@252758 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r251635: illumos #3747 txg commit callbacks don't work

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/txg.c:
	Fix commit callbacks by moving them to the task's list.
	Previously, list_move_tail() returned without doing anything because
	the task list was passed as the source rather than destination.

cddl/contrib/opensolaris/cmd/ztest/ztest.c:
	Check the commit callback threshold correctly.

Submitted by:	will
Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic


git-svn-id: svn://svn.freebsd.org/base/stable/9@252760 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r251636: illumos #3749 zfs event processing should work on R/O root
filesystems

This log is a modified version of the original one written by gibbs@,
to account for changes made during the illumos RTI process.

Allow ZFS asynchronous event handling to proceed even if the root file
system is mounted read-only.  This restriction appears to have been put
in place to avoid errors with updating the configuration cache file.
However:

 o The majority of asynchronous event handling does not involve
   configuration cache file updates.
 o The configuration cache file need not be on the root file system,
   so the check was not complete.
 o Other classes of errors (e.g. file system full) can also prevent
   a successful update yet do not prevent asynchronous event processing.
 o Configurations such as NanoBSD never have a read-write root,
   so ZFS event processing is permanently disabled in these systems.
 o Failure to handle asynchronous events promptly can extend the
   window of time that a pool is in a critical state.

At worst, a missed configuration cache update will force the operator to
perform a manual "zfs import" (note -f is not required) to inform the
system about a newly created pool.  To minimize the likelihood of this
rare occurrence, configuration cache write failures now emit FMA events
(via devctl) so the operator can take corrective action, and the write
is retried every 5 minutes.  The retry interval, in seconds, is tunable
via the sysctl "vfs.zfs.ccw_retry_interval".

As a side effect of reporting configuration cache events, other sysevents,
such as re-silver start/stop, are now also reported via devctl.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c:
	o As is done in zfs_fm.c, provide a manual declaration for
	  devctl_notify().  Both declarations could be combined
	  into spa_impl.h, but the declaration is fault management
	  related, not spa specific.  sys/fm/fs/zfs.h would be ideal
	  if it weren't so public and reserved for FMA string
	  definitions.  I'm open to suggestions on how to improve
	  this nit while minimizing our divergence from Solaris.
	o Use devctl_notify() to implement sysevent support in
	  spa_event_notify().  The subsystem is EC_ZFS so that
	  these events can never collide with those emitted in
	  zfs_fm.c.
	o Add the sysctl "vfs.zfs.ccw_retry_interval".  The value
	  defaults to 5 minutes and is used to rate limit, on a
	  per-pool basis, configuration cache file write attempts.
	o Modify spa_async_dispatch to honor configuration cache
	  write limiting.  If other events are pending, a configuration
	  cache write will be attempted at the same time, so the
	  rate limiting only applies when the asynchronous dispatch
	  system is otherwise idle.  Async events should be rare
	  (e.g. device arrival/departure) and configuration cache
	  writes rarer, so a more complicated system to strictly
	  honor the retry limit seems unwarranted.
	o Remove check in spa_async_dispatch() for the root file
	  system being read-write.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c:
	Instead of silently ignoring configuration cache write
	failures, report them via a new FMA event as well as
	to the console.  The current zfs_ereport_post() doesn't
	allow arbitrary name=value pairs to be appended to the
	report, so the configuration cache file name is only
	available on the console output.  This limitation should
	be addressed in a future update.

	Note: This error report is only posted once per incident,
	to avoid spamming.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_impl.h:
	Add a hrtime_t to the spa data structure to track the
	time (via gethrtime()) of the last configuration cache file
	write failure.  This is referenced in spa_async_dispatch()
	to effect the rate limiting.

sys/cddl/contrib/opensolaris/uts/common/sys/fm/fs/zfs.h:
	  Add FM_EREPORT_ZFS_CONFIG_CACHE_WRITE as an ereport class.

Submitted by:	gibbs
Reviewed by:	Matthew Ahrens <mahrens@delphix.com>,
		Eric Schrock <eric.schrock@delphix.com>,
		Christopher Siden <christopher.siden@delphix.com>
Sponsored by:	Spectra Logic


git-svn-id: svn://svn.freebsd.org/base/stable/9@252762 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r251646 + r252219:

MFV r251644:

Poor ZFS send / receive performance due to snapshot
hold / release processing (by smh@)

Illumos ZFS issues:
3740 Poor ZFS send / receive performance due to snapshot
     hold / release processing

MFV r252215:

Restore a previous behavior before r251646, where when destructing
ZFS snapshot, the ioctl would return ENOENT when it hit any of
them in the errlist (the new behavior was only return ENOENT when
all returns error).

Illumos ZFS issues:
  3829 fix for 3740 changed behavior of zfs destroy/hold/release ioctl


git-svn-id: svn://svn.freebsd.org/base/stable/9@252764 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r252218:

Diff reduction against Illumos, no real change to code itself.

This marks vendor branch revision 252213 as merged, the actual code was
committed in r245479.


git-svn-id: svn://svn.freebsd.org/base/stable/9@252766 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
MFC r252360:

Don't attempt to do DHCP on certain interfaces, similar to what's done for
ipv6_autoconfif() in r212577.


git-svn-id: svn://svn.freebsd.org/base/stable/9@252768 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f