Add PowerPC to supported VTOCs

This code was was inherited from Solaris which was careful to define
the expected VTOC for various supported architectures.  While this
check may have made sense there it's something we should be able to
safely drop under Linux.

However, I'm not quite ready to do that yet.  So for the moment I'm
just doing the very safe thing of adding PowerPC as a supported type.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Move zfs.release generation to configure step

Previously, the zfs.release file was created at 'make install' time.
This is slightly problematic when the file is needed without running
'make install'. Because of this, the step creating the file was removed
from 'make install' and replaced with a more appropriate zfs.release.in
file.

As a result, the zfs.release file will now be created earlier as part
of the 'configure' step as opposed to the 'make install' step.

Signed-off-by: Prakash Surya <surya1@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Move partition scanning from userspace to module.

Currently, zpool online -e (dynamic vdev expansion) doesn't work on
whole disks because we're invoking ioctl(BLKRRPART) from userspace
while ZFS still has a partition open on the disk, which results in
EBUSY.

This patch moves the BLKRRPART invocation from the zpool utility to the
module. Specifically, this is done just before opening the device in
vdev_disk_open() which is called inside vdev_reopen(). This requires
jumping through some hoops to get to the disk device from the partition
device, and to make sure we can still open the partition after the
BLKRRPART call.

Note that this new code path is triggered on dynamic vdev expansion
only; other actions, like creating a new pool, are unchanged and still
call BLKRRPART from userspace.

This change also depends on API changes which are available in 2.6.37
and latter kernels.  The build system has been updated to detect this,
but there is no compatibility mode for older kernels.  This means that
online expansion will NOT be available in older kernels.  However, it
will still be possible to expand the vdev offline.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #808
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. Lastly, we modify zpl_put_link() to address a PaX change
to the function prototype of nd_get_link().  This avoids compiler errors
in the PaX/GRSecurity dialect.

Note that the change in zpl_put_link() causes a warning that becomes a
build failure when debugging is enabled. Fixing that warning requires
ryao/spl@5ca50ef459c59bc74b7a7cd3af7311da2b1cd2c3.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #484
Add 'inline' keyword

The '__attribute__((always_inline))' does not strictly imply
'inline'.  Newer versions of gcc detect this misuse and issue
the following warning.  Including the missing 'inline' resolves
the build warning.

    ./module/zfs/dsl_scan.c:758:1:error: always_inline function
    might not be inlinable [-Werror=attributes]

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
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 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
Linux 3.5 compatibility: miscellaneous changes

torvalds/linux@b0b0382bb4904965a9e9fca77ad87514dfda0d1c changed
export_operations->encode_fn() to use struct inode * instead of struct
dentry *

torvalds/linux@dbd5768f87ff6fb0a4fe09c4d7b6c4a24de99430 renamed
end_writeback() to clear_inode()

torvalds/linux@17cf28afea2a1112f240a3a2da8af883be024811 removed
inode_operations->truncate_range(). The file hole punching functionality
is provided by inode_operations->fallocate()

Closes zfsonlinux/zfs#784

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

I made the following observations when examining arc_status from a
i386 system suffering from low performance and heavy idle load:

	- memory_throttle_count was extremely high
	- mru_evict_metadata and mru_ghost_evict_metadata were high
	- mfu_evict_data == 0
	- mfu_ghost_size == 0
	- mfu_ghost_evict_data == 0
	- mfu_ghost_evict_metadata == 0
	- arc_meta_used == arc_meta_max, but much less than arc_meta_limit
	- c_max == c
	- c_max >> arc_p_min_shift == c_min

Upon comparsion with an amd64 system, I noticed the following:

	- memory_throttle_count was low
	- mfu_evict_data, mfu_ghost_size, mfu_ghost_evict_data and
		  mfu_ghost_evict_metadata were all greater than zero
	- arc_meta_used < arc_meta_max < arc_meta_limit
	- c_max >> arc_p_min_shift > c_min
	- c_max > c

After looking at the code, I decided to make a few changes. First, I am
changing the minimum value of c_min to 16MB to mimic the change made in
freebsd/freebsd-head@8a78bd4cc19835b58ed1a8fbb45635a274dab8e9. Second, I
am changing the code to consider the minimum of both virtual memory and
physical memory when accepting changes to zfs_arc_max.

My hope is that changing the minimum value of c_min will correct some of
the inconsistencies between amd64 and i386 systems.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Fix show_options() detection on Hardened Linux 3.3 and later

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