Allow fetching the pool from the device at mount

To simplify integration with the xfstests test suite the
mount.zfs helper has been extended.  When passed a block
device (/dev/sdX) to mount, instead of a pool/dataset,
the pool name will be read from any existing zfs label
and used.  This allows you to mount the root dataset of
a zfs filesystem by specifing any of the member vdevs.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Return -EOPNOTSUPP for ZFS_IOC_{GET|SET}FLAGS

Until these hooks are fully implemented return the expected
-EOPNOTSUPP error to indicate they are not functional.  This
allows test suites such as xfstests to cleanly skip testing
this functionality until it's implemented.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #229
Fix module probe failure on 32-bit systems

Previous commit 7ef5e54e2e28884a04dc800657967b891239e933 caused
module probe failure on 32-bit systems, dmesg showed

  Unknown symbol __moddi3

This was caused by the modulo operation 'gethrtime() % tqs->stqs_count'
in the committed code.  Instead of implementing __moddi3 for all 32-bit
systems, Behlendorf advised we can just cast the return value of
gethrtime() into a uint64_t, since gethrtime does not return negative
value on all circumstances we need not care about the potential overflow.

Signed-off-by: Ying Zhu <casualfisher@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1551
Add error message for missing /etc/mtab

The zpool command should not silently fail when the /etc/mtab
file does not exist.  This can occur in an initramfs environment
when the /etc/mtab file hasn't yet been generated.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1541
Formating changes for zpool manpage

Some of these entries were hidden before.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1553
Add absent \n at the end of the help text line

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #1545
Override default SPA config location via environment

When using zdb with non-default SPA config file it is not convenient
to add -U <non-default-config-file-path> all the time. This commit
introduces support for setting/overriding SPA config location via
environment variable 'SPA_CONFIG_PATH'.

If -U flag is specified in the command line it will override any other
value as usual.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1545
Fix zfs_sb_teardown/zfs_resume_fs NULL dereference

Fix a pair of conditions in which a concurrent umount can cause
NULL pointer dereferences:

* zfs_sb_teardown - prevent a NULL dereference by not calling
                    dmu_objset_pool with a null z_os.

* zfs_resume_fs - don't try to unmount with a null z_os.  This
                  change makes the ZoL code more consistent
                  with both Illumos and FreeBSD.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1543
kmem_zalloc(..., KM_SLEEP) will never fail

By definitition these allocations will never fail.  For
consistency with the rest of the code remove this dead error
handling code.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1558
Readd zfs_holey() from OpenSolaris

This patch restores the zfs_holey() function from OpenSolaris.
This was removed by commit 3558fd7 because it wasn't clear we
had a use for it in ZoL.  However, this functionality is a
prerequisite for adding SEEK_DATA/SEEK_HOLE support to the ZPL.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <ryao@gentoo.org>
Issue #1384
Add SEEK_DATA/SEEK_HOLE to lseek()/llseek()

The approach taken was the rework zfs_holey() as little as
possible and then just wrap the code as needed to ensure
correct locking and error handling.

Tested with xfstests 285 and 286.  All tests pass except for
7-9 of 285 which try to reserve blocks first via fallocate(2)
and fail because fallocate(2) is not yet supported.

Note that the filp->f_lock spinlock did not exist prior to
Linux 2.6.30, but we avoid the need for autotools check by
virtue of the fact that SEEK_DATA/SEEK_HOLE support was not
added until Linux 3.1.

An autoconf check was added for lseek_execute() which is
currently a private function but the expectation is that it
will be exported perhaps as early as Linux 3.11.

Reviewed-by: Richard Laager <rlaager@wiktel.com>
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1384
Add zfs_sync_pass_* tunable parameters

Commit 55d85d5a8c45c4559a4a0e675c37b0c3afb19c2f (backport of
the upstream changes) replaced three hardcoded constants:

    #define SYNC_PASS_DEFERRED_FREE 2 /* defer frees after this pass */
    #define SYNC_PASS_DONT_COMPRESS 4 /* don't compress after this pass */
    #define SYNC_PASS_REWRITE       1 /* rewrite new bps after this pass */

with a tunable parameters:

    int zfs_sync_pass_deferred_free = 2; /* defer frees starting in this pass */
    int zfs_sync_pass_dont_compress = 5; /* don't compress starting in this pass */
    int zfs_sync_pass_rewrite = 2;       /* rewrite new bps starting in this pass */

This commit makes these tunables available as module parameters
in Linux.  They should only be used for performance analysis
because changing them can result in subtle and pathological
performance problems.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1562
Use MAXPATHLEN instead of sizeof in snprintf

This silences a GCC 4.8.0 warning by fixing a programming error
caught by static analysis:

../../cmd/ztest/ztest.c: In function ‘ztest_vdev_aux_add_remove’:
../../cmd/ztest/ztest.c:2584:33: error: argument to ‘sizeof’
  in ‘snprintf’ call is the same expression as the destination;
  did you mean to provide an explicit length?
  [-Werror=sizeof-pointer-memaccess]
  (void) snprintf(path, sizeof (path), ztest_aux_template,
                                 ^

Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1480
Illumos #3122 zfs destroy filesystem should prefetch blocks

3122 zfs destroy filesystem should prefetch blocks
Reviewed by: Christopher Siden <chris.siden@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Approved by: Garrett D'Amore <garrett@damore.org>

References:
  illumos/illumos-gate@b4709335aa83dcbfd0dba33c9be21fcabebd28e4
  https://www.illumos.org/issues/3122

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1565
Illumos #3498 panic in arc_read()

3498 panic in arc_read(): !refcount_is_zero(&pbuf->b_hdr->b_refcnt)
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Richard Lowe <richlowe@richlowe.net>

References:
  illumos/illumos-gate@1b912ec7100c10e7243bf0879af0fe580e08c73d
  https://www.illumos.org/issues/3498

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1249