Switch to C99

Upstream Illumos uses C99, but we have been building as C89. This
required backporting patches from Illumos from C99 to C89. There are no
known ABI compatibility issues when mixing C89 and C99 code. so lets
just build as C99 and save ourselves some trouble. This patch modifies
the autotools checks, userland code and kernel code to use C89.

Note that the Linux kernel passes -Wdeclaration-after-statement, so we
must pass -Wno-declaration-after-statement to counteract that. We also
do a little cleanup to simplify the makefiles.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Add missing code to zfs_debug.{c,h}

This is required to make Illumos 3962 merge.

Signed-off-by: Richard Yao <ryao@gentoo.org>
6939941 problem with moving files in zfs

Porting notes:

This commit was so old that only two lines applied to the modern
codebase.

Signed-off-by: Richard Yao <ryao@gentoo.org>
6977619 NULL pointer deference in sa_handle_get_from_db()

Ported-by: Richard Yao <ryao@gentoo.org>
Illumos #3006

3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument
     is zero

Reviewed by Matt Ahrens <matthew.ahrens@delphix.com>
Reviewed by George Wilson <george.wilson@delphix.com>
Approved by Eric Schrock <eric.schrock@delphix.com>

References:
  illumos/illumos-gate@fb09f5aad449c97fe309678f3f604982b563a96f
  https://illumos.org/issues/3006

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Illumos #3522

3522 zfs module should not allow uninitialized variables
Reviewed by: Sebastien Roy <seb@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Garrett D'Amore <garrett@damore.org>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3522
illumos/illumos-gate@d5285cae913f4e01ffa0e6693a6d8ef1fbea30ba

Porting notes:

1. ZFSOnLinux had already addressed many of these issues because of its use of
-Wall. However, the manner in which they were addressed differed. The illumos
fixes replace the ones previously made in ZFSOnLinux to reduce code
differences.

2. Part of the upstream patch made a small change to arc.c that might address
zfsonlinux/zfs#1334.

3. The initialization of aclsize in zfs_log_create() differs because vsecp is a
NULL pointer on ZFSOnLinux.

4. The changes to zfs_register_callbacks() were dropped because it has diverged
and needs to be resynced.
Illumos #3537

3537 want pool io kstats

Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Reviewed by: Sa?o Kiselkov <skiselkov.ml@gmail.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Gordon Ross <gwr@nexenta.com>

References:
	http://www.illumos.org/issues/3537
	illumos/illumos-gate@c3a6601

Ported by: Cyril Plisko <cyril.plisko@mountall.com>
Illumos #3561, #3116

3561 arc_meta_limit should be exposed via kstats
3116 zpool reguid may log negative guids to internal SPA history
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Approved by: Garrett D'Amore <garrett@damore.org>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3561
https://www.illumos.org/issues/3116
illumos/illumos-gate@20128a0826f9c53167caa9215c12f08beee48e30

Porting Notes:

1. The spa change was accidentally included in the libzfs_core merge.

2. "Add missing arcstats" (1834f2d8b715d25bafbb0e4a099994f45c3211ae) already
implemented these kstats a few years ago.
Illumos #3578, #3579

3578 transferring the freed map to the defer map should be constant time
3579 ztest trips assertion in metaslab_weight()
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Richard Elling <richard.elling@dey-sys.com>
Approved by: Dan McDonald <danmcd@nexenta.com>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3578
https://www.illumos.org/issues/3579
illumos/illumos-gate@9eb57f7f3fbb970d4b9b89dcd5ecf543fe2414d5
Illumos #3588

3588 provide zfs properties for logical (uncompressed) space used and referenced
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Reviewed by: Richard Elling <richard.elling@dey-sys.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3588
illumos/illumos-gate@77372cb0f35e8d3615ca2e16044f033397e88e21
Illumos #3582, #3584

3582 zfs_delay() should support a variable resolution
3584 DTrace sdt probes for ZFS txg states

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Reviewed by: Richard Elling <richard.elling@dey-sys.com>
Approved by: Garrett D'Amore <garrett@damore.org>

References:
    https://www.illumos.org/issues/3582
    illumos/illumos-gate@0689f76

Ported by: Ned Bass <bass6@llnl.gov>
Illumos #3603, #3604: bobj improvements

3603 panic from bpobj_enqueue_subobj()
3604 zdb should print bpobjs more verbosely
3871 GCC 4.5.3 does not like issue 3604 patch

https://www.illumos.org/issues/3603
https://www.illumos.org/issues/3604
https://www.illumos.org/issues/3871

Reviewed by: Henrik Mattson <henrik.mattson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Approved by: Dan McDonald <danmcd@nexenta.com>
Ported-by: Richard Yao <ryao@gentoo.org>

Note that the patch from Illumos issue 3871 is not accepted into Illumos
at the time of this writing. It is something that I wrote when porting
this. Documentation is in the Illumos issue.
Illumos #3517

3517 importing pool with autoreplace=on and "hole" vdevs crashes syseventd
Reviewed by: Albert Lee <trisk@nexenta.com>
Reviewed by: Jeffry Molanus <jeffry.molanus@nexenta.com>
Reviewed by: George Wilson <gwilson@zfsmail.com>
Approved by: Christopher Siden <christopher.siden@delphix.com>
Ported-by: Richard Yao <ryao@gentoo.org>

https://www.illumos.org/issues/3517
illumos/illumos-gate@efb4a871d8fd510a833bdca610528dde5ed69e42
Illumos #3598

3598 want to dtrace when errors are generated in zfs
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Approved by: Garrett D'Amore <garrett@damore.org>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3598
illumos/illumos-gate@be6fd75a69ae679453d9cda5bff3326111e6d1ca

Porting notes:

1. include/sys/zfs_context.h has been modified to render some new macros
inert until dtrace is available on Linux.

2. Linux-specific changes have been adapted to use SET_ERROR().
Illumos #3645, #3692

3645 dmu_send_impl: possibilty of pool hold leak
3692 Panic on zfs receive of a recursive deduplicated stream
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3645
https://www.illumos.org/issues/3692
illumos/illumos-gate@de8d9cff565e928d0ace86f3ea0e2b15094d61df
Illumos #3642, #3643

3642 dsl_scan_active() should not issue I/O to determine if async destroying is active
3643 txg_delay should not hold the tc_lock
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Approved by: Gordon Ross <gwr@nexenta.com>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3642
https://www.illumos.org/issues/3643
illumos/illumos-gate@4a92375985c37d61406d66cd2b10ee642eb1f5e7
Illumos #3699, #3739

3699 zfs hold or release of a non-existent snapshot does not output error
3739 cannot set zfs quota or reservation on pool version < 22
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Eric Shrock <eric.schrock@delphix.com>
Approved by: Dan McDonald <danmcd@nexenta.com>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3699
https://www.illumos.org/issues/3739
illumos/illumos-gate@013023d4ed2f6d0cf75380ec686a4aac392b4e43
Illumos #3741

3741 zfs needs better comments
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Approved by: Christopher Siden <christopher.siden@delphix.com>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3741
illumos/illumos-gate@3e30c24aeefdee1631958ecf17f18da671781956
Illumos #3742

3742 zfs comments need cleaner, more consistent style
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Approved by: Christopher Siden <christopher.siden@delphix.com>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3742
illumos/illumos-gate@f7170741490edba9d1d9c697c177c887172bc741

Porting notes:

The change to zfs_vfsops.c was dropped because it involves
zfs_mount_label_policy, which does not exist in the Linux port.
Illumos #3743

3743 zfs needs a refcount audit
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Christopher Siden <christopher.siden@delphix.com>
Ported-by: Richard Yao <ryao@gentoo.org>

References:

https://www.illumos.org/issues/3743
illumos/illumos-gate@b287be1ba86043996f49b1cc34c80cc620f9b841