Revert Fix ASSERTION(!dsl_pool_sync_context(tx->tx_pool))

Commit eec8164771bee067c3cd55ed0a16dadeeba276de worked around an issue
involving direct reclaim through the use of PF_MEMALLOC.   Since we
are reworking thing to use KM_PUSHPAGE so that swap works, we revert
this patch in favor of the use of KM_PUSHPAGE in the affected areas.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #726
Revert Fix zpl_writepage() deadlock

The commit, cfc9a5c88f91f7b4d606fce89505e1f404691ea5, to fix deadlocks
in zpl_writepage() relied on PF_MEMALLOC.   That had the effect of
disabling the direct reclaim path on all allocations originating from
calls to this function, but it failed to address the actual cause of
those deadlocks.  This led to the same deadlocks being observed with
swap on zvols, but not with swap on the loop device, which exercises
this code.

The use of PF_MEMALLOC also had the side effect of permitting
allocations to be made from ZONE_DMA in instances that did not require
it.  This contributes to the possibility of panics caused by depletion
of pages from ZONE_DMA.

As such, we revert this patch in favor of a proper fix for both issues.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #726
Revert Disable direct reclaim for z_wr_* threads

This commit used PF_MEMALLOC to prevent a memory reclaim deadlock.
However, commit 49be0ccf1fdc2ce852271d4d2f8b7a9c2c4be6db eliminated
the invocation of __cv_init(), which was the cause of the deadlock.
PF_MEMALLOC has the side effect of permitting pages from ZONE_DMA
to be allocated.  The use of PF_MEMALLOC was found to cause stability
problems when doing swap on zvols. Since this technique is known to
cause problems and no longer fixes anything, we revert it.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #726
Import Illumos #701: UNMAP support for COMSTAR

Reviewed by: Garrett D'Amore <garrett@nexenta.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Reviewed by: George Wilson <gwilson@zfsmail.com>
Approved by: Garrett D'Amore <garrett@nexenta.com>

Refererce to Illumos issue:
  https://www.illumos.org/issues/701

This enables logging of discard operations to the ZIL by merging
illumos/illumos-gate@b77b9231da168bb31490f65bf2697f6031b7f601.  There is
one key difference between the Illumos code and our import of it. The
illumos code will treat discard requests as synchronous operations when
the write-cache is disabled by checking ZVOL_WCE in zv->zv_flags.  That
is set by the DKIOCSETWCE ioctl on Solaris. This does not appear to
have an analog on Linux, so the Ilumos behavior is not implemented in
our code.

Ported-by: Richard Yao <ryao@cs.stonybrook.edu>
Modify txg_hold_open to support preemptable kernels
Modify fm_ena_generate to support preemptable kernels
Set discard_zeroes_data on zvols

This implements a suggestion by Richard Laager. It ensures that the
kernel will know that discard operations are guarenteed to zero blocks.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Fix build failures on PaX/GRSecurity patched kernels

Gentoo Hardened kernels include the PaX/GRSecurity patches. They use a
dialect of C that relies on a GCC plugin. In particular, struct
file_operations has been marked do_const in the PaX/GRSecurity dialect,
which causes GCC to consider all instances of it as const. This caused
failures in the autotools checks and the ZFS source code.

To address this, we modify the autotools checks to take into account
differences between the PaX C dialect and the regular C dialect. We also
modify struct zfs_acl's z_ops member to be a pointer to a function
pointer table and make a char * pointer const. This avoids issues in the
PaX/GRSecurity dialect.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Fix znode corruption when using xattr=sa.

Using a separate SA handle (rather than zp->z_sa_hdl) to update
attributes corrupts the znode's mode flags (and possibly other
attributes as well).

This patch changes the zfs_sa_get_xattr/zfs_sa_set_xattr functions
so that they use zp->z_sa_hdl.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Revert CONFIG_PREEMPT checks
Make callers responsible for memory allocation in zfs_range_lock()

zfs_range_lock() is used in zvols, and previously, it could deadlock due
to an allocation using KM_SLEEP. We avoid this by moving responsibility
the memory allocation from zfs_range_lock() to the caller. This enables
us to avoid such deadlocks and use stack allocations, which are more
efficient and prevents deadlocks. The contexts in which stack
allocations are done do not appear to be stack heavy, so we do not risk
overflowing the stack from doing this.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>