Only reduce __zio_execute() stack usage in kernel space

Related to 91579709fccd3e55a21970742b66c388fb1403db we need to
be very careful about not overrunning the stack in kernel space.
However, in user space we're already allowing slightly larger
stacks so this stack usage optimization is not required there.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Revert "Avoid ELOOP on auto-mounted snapshots"

This reverts commit 7afcf5b1da83549bfba70a61fae7a00eaa63c2b0 which
accidentally introduced a regression with the .zfs snapshot directory.
While the updated code still does correctly mount the requested
snapshot.  It updates the vfsmount such that it references the
original dataset vfsmount.  The result is that the snapshot itself
isn't visible.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #816
call_usermodehelper() should wait for process

As of Linux 3.4 the UMH_WAIT_* constants were renumbered.  In
particular, the meaning of "1" changed from UMH_WAIT_PROC (wait for
process to complete), to UMH_WAIT_EXEC (wait for the exec, but not the
process).  A number of call sites used the number 1 instead of the
constant name, so the behavior was not as expected on kernels with this
change.

One visible consequence of this change was that processes accessing
automounted snapshots received an ELOOP error because they failed to
wait for zfs.mount to complete.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #816
Report realpath() canonicalization error

Rather than just reporting the failure include the passed
mount point and error number.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1153
Add /sbin/fsck.zfs helper

A fsck helper to accomidate distributions that expect to be able
to execute a fsck on all filesystem types.  Currently this script
does nothing but it could be extended to act as a compatibility
wrapper for 'zpool scrub'.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #964
'zfs receive' man page sync'ed with Illumos

The only valid options are -vnFu, these other ones seem to be
misplaced zfs send options.

Remove: -D -r -p -n -P

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1186
'zfs send' man page sync'ed with Illumos

* Move -R option up one position in the list to match
  the Illumos documentation.

* Move -D option up one position and refreshed it to
  match the Illumos documentation.

* Move -p option up one position and refreshed it to
  match the Illumos documentation.

* Add the -n, -P  documentation found in zfs receive
  in to zfs send where to belongs.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1187
Only use gcc -Wunused-but-set-variable when available

Certain versions of gcc generate an 'unrecognized command
line option' error message when -Wunused-but-set-variable
is used unconditionally.  This in turn can cause several
of the autoconf tests to misdetect an interface.

Now, the use of -Wunused-but-set-variable in the autoconf
tests was introduced by commit b9c59ec8 to address a gcc
4.6 compatibility problem.  So we really only need to pass
this option for version of gcc which are known to support it.

Therefore, the tests have been updated to use the result of
the existing ZFS_AC_CONFIG_ALWAYS_NO_UNUSED_BUT_SET_VARIABLE
which determines if gcc supports this option.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1004
Illumos #2618 arc.c mistypes in the comments

2618 arc.c mistypes in the comments

Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Josef Sipek <jeffpc@josefsipek.net>
Approved by: Richard Lowe <richlowe@richlowe.net>

References:
  illumos/illumos-gate@fc98fea58e89224f6f13d7fae246d6cb5dfa35ea
  illumos changeset: 13721:5b51a16a186f
  https://www.illumos.org/issues/2618

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Illumos #1557 assertion failed in userland taskq_destroy()

1557 assertion failed in userland taskq_destroy()

Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: George Wilson <gwilson@zfsmail.com>
Approved by: Eric Schrock <eric.schrock@delphix.com>

References:
  illumos/illumos-gate@aa846ad9bc4785806bb6263657698d5890afbc08
  illumos changeset: 13597:3eac1e8e0f4c
  https://www.illumos.org/issues/1557

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Illumos #1377 `zpool status -D' should tell if there are no DDT entries

1337 `zpool status -D' should tell if there are no DDT entries

Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Reviewed by: George Wilson <gwilson@zfsmail.com>
Approved by: Albert Lee <trisk@nexenta.com>

References:
  illumos/illumos-gate@ce72e614c133351311e87bbbe4eba8fea9e77768
  illumos changeset: 13432:d1ad8d106d64
  https://www.illumos.org/issues/1337

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Illumos #1884, #3028, #3048, #3049, #3060, #3061, #3093

1884 Empty "used" field for zfs *space commands
3028 zfs {group,user}space -n prints (null) instead of numeric GID/UID
3048 zfs {user,group}space [-s|-S] is broken
3049 zfs {user,group}space -t doesn't really filter the results
3060 zfs {user,group}space -H output isn't tab-delimited
3061 zfs {user,group}space -o doesn't use specified fields order
3093 zfs {user,group}space's -i is noop

Reviewed by: Garry Mills <gary_mills@fastmail.fm>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Approved by: Richard Lowe <richlowe@richlowe.net>

References:
  illumos/illumos-gate@89f5d17b06fc4132c983112b24836a779a0ed736
  illumos changeset: 13803:b5e49d71ff0e
  https://www.illumos.org/issues/1884
  https://www.illumos.org/issues/3028
  https://www.illumos.org/issues/3048
  https://www.illumos.org/issues/3049
  https://www.illumos.org/issues/3060
  https://www.illumos.org/issues/3061
  https://www.illumos.org/issues/3093

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1194
Illumos #3397, #3398

3397 zdb <pool> <objnum> output is too verbose
3398 zdb can't dump feature flags zap objects

Reviewed by: Matt Ahrens <matthew.ahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Approved by: Dan McDonald <danmcd@nexenta.com>

References:
  illumos/illumos-gate@e690fb27a7d1483f052505e1ff373d205f9dee99
  https://www.illumos.org/issues/3397
  https://www.illumos.org/issues/3398

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Illumos #3208 cross-endian incorrect user/group accounting

3208 moving zpool cross-endian results in incorrect user/group
accounting

Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <chris.siden@delphix.com>
Approved by: Richard Lowe <richlowe@richlowe.net>

References:
  illumos/illumos-gate@e828a46d29ad418487f50d56b5c19e2a1f9033a7
  illumos changeset: 13835:eea81edc4f14
  https://www.illumos.org/issues/3208

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #627
Closes #1136
Illumos #1862 incremental zfs receive fails for sparse file > 8PB

1862 incremental zfs receive fails for sparse file > 8PB

Reviewed by: Matt Ahrens <matthew.ahrens@delphix.com>
Reviewed by: Simon Klinkert <klinkert@webgods.de>
Approved by: Eric Schrock <eric.schrock@delphix.com>

References:
  illumos/illumos-gate@31495a1e56860f4575614774a592fe33fc9c71f2
  illumos changeset: 13789:f0c17d471b7a
  https://www.illumos.org/issues/1862

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Illumos #3189 kernel panic in test hotspare_onoffline_004_neg

3189 kernel panic in ZFS test suite during hotspare_onoffline_004_neg

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Arne Jansen <sensille@gmx.net>
Approved by: Dan McDonald <danmcd@nexenta.com>

References:
  illumos/illumos-gate@8f0b538d1dc99df23a6a89cfd9ffddc1b9804a00
  changeset: 13818:e9ad0a945d45
  https://www.illumos.org/issues/3189

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Ensure that zfs diff prints unicode safely.

In the stream_bytes() library function used by `zfs diff`, explicitly
cast each byte in the input string to an unsigned character so that the
Linux fprintf() correctly escapes to octal and does not mangle the output.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1172
Fix quoting error in unmount command

A misplaced single quote caused the umount command to fail with a
syntax error when unmounting snapshots under the .zfs/snapshot
control directory.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1210
Fix false ENOENT on snapshot control dentries

Lookups in the snapshot control directory for an existing snapshot
fail with ENOENT if an earlier lookup failed before the snapshot was
created.  This is because the earlier lookup causes a negative dentry
to be cached which is never invalidated.

The bug can be reproduced as follows (the second ls should succeed):

 $ ls /tank/.zfs/snapshot/s
 ls: cannot access /tank/.zfs/snapshot/s: No such file or directory
 $ zfs snap tank@s
 $ ls /tank/.zfs/snapshot/s
 ls: cannot access /tank/.zfs/snapshot/s: No such file or directory

To remedy this, always invalidate cached dentries in the snapshot
control directory.  Since these entries never exist on disk there is
no significant performance penalty for the extra lookups.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1192
Fix 'zfs rollback' on mounted file systems

Rolling back a mounted filesystem with open file handles and
cached dentries+inodes never worked properly in ZoL.  The
major issue was that Linux provides no easy mechanism for
modules to invalidate the inode cache for a file system.

Because of this it was possible that an inode from the previous
filesystem would not get properly dropped from the cache during
rolling back.  Then a new inode with the same inode number would
be create and collide with the existing cached inode.  Ideally
this would trigger an VERIFY() but in practice the error wasn't
handled and it would just NULL reference.

Luckily, this issue can be resolved by sprucing up the existing
Solaris zfs_rezget() functionality for the Linux VFS.

The way it works now is that when a file system is rolled back
all the cached inodes will be traversed and refetched from disk.
If a version of the cached inode exists on disk the in-core
copy will be updated accordingly.  If there is no match for that
object on disk it will be unhashed from the inode cache and
marked as stale.

This will effectively make the inode unfindable for lookups
allowing the inode number to be immediately recycled.  The inode
will then only be accessible from the cached dentries.  Subsequent
dentry lookups which reference a stale inode will result in the
dentry being invalidated.  Once invalidated the dentry will drop
its reference on the inode allowing it to be safely pruned from
the cache.

Special care is taken for negative dentries since they do not
reference any inode.  These dentires will be invalidate based
on when they were added to the dentry cache.  Entries added
before the last rollback will be invalidate to prevent them
from masking real files in the dataset.

Two nice side effects of this fix are:

* Removes the dependency on spl_invalidate_inodes(), it can now
  be safely removed from the SPL when we choose to do so.

* zfs_znode_alloc() no longer requires a dentry to be passed.
  This effectively reverts this portition of the code to its
  upstream counterpart.  The dentry is not instantiated more
  correctly in the Linux ZPL layer.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Closes #795