Fixing a bug related to set_capacity() before add_disk().

See these references:
  http://osdir.com/ml/linux.enbd.general/2002-10/msg00176.html
  http://osdir.com/ml/linux.enbd.general/2002-10/msg00177.html
  http://stackoverflow.com/questions/13518404/add-disk-hangs-on-insmod
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>
Use kmem_cache for zil_vdev_node_t objects

Signed-off-by: Richard Yao <ryao@gentoo.org>
Use bitfields for boolean values in znode_t

znode_t uses 1312 bytes in length on Linux 3.9.6 amd64. Switching to
bitfields for boolean values reduces the size to 1296 bytes. Further
reductions should be possible if padding were removed, but saving 16
bytes per struct can translate into megabytes of savings when hundreds
of thousands of znodes are cached. While the savings is relatively
small in comparison to memory used, the small efficiency gain is
practically free.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Remove unused option -r from zpool

Signed-off-by: Richard Yao <ryao@gentoo.org>
Implement -t option to zpool import for temporary pool names

Specifying newname to a pool import currently changes the pool name. We
implement option -t. Specifying option -t in conjuction with newpool to
zpool import will make the name change temporary. In specific, the
original pool name will be used in all label updates and therefore is
retained upon export.

This is useful in any situation where maintenance on a system's root
pool is done from another system. A good example is environments using
virtualization, where it is more desireable to do rollback of the root
dataset of a guest's root pool than it is to rollback of the zvol
hosting the guest's root pool when an issue prevents the guest from
booting properly. Other examples include maintenance on root pools
hosted on iSCSI and operating system installations on USB keys that are
used to rescue non-bootable sytems.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Illumos #3639 zpool.cache should skip over readonly pools

Normally we don't list pools that are imported read-only in the cache
file, however you can accidentally get one into the cache file by
importing and exporting a read-write pool while a read-only pool is
imported:

$ zpool import -o readonly test1
$ zpool import test2
$ zpool export test2
$ zdb -C

This is a problem because if the machine reboots we import all pools in
the cache file as read-write.

https://www.illumos.org/issues/3639

Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Basil Crow <basil.crow@delphix.com>
Approved by: Gordon Ross <gwr@nexenta.com>
Ported-by: Richard Yao <ryao@gentoo.org>
Remove zio_alloc_arena

We declare zio_alloc_arena using extern, but it does not appear to exist
anywhere in the code. This permits undefined behavior, so lets remove
it.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Remove arc_data_buf_alloc()/arc_data_buf_free()

These functions are used in neither Illumos nor ZFSOnLinux. They appear
to have been replaced by arc_buf_alloc()/arc_buf_free(), so lets remove
them.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Revert Integrate ARC more tightly with Linux

The reverts nearly all of the changes, with some adjustments to
arc_memory_throttle() because some of the original code did not make
sense and changes had been made to it since this patch was written.

Signed-off-by: Richard Yao <ryao@gentoo.org>

Conflicts:
	module/zfs/arc.c
Simplify reclaim

On Illumos, kswapd and arc_reclaim_thread share responsibility for
memory reclaimation. arc_reclaim_thread will attempt to keep ahead of
system memory needs and kswapd will signal it as needed. On Linux, a
thread that needs memory when there is none available will immediately
begin "direct reclaim", which means that it will try freeing memory
itself.

This poses a few problems. First, it is possible for hundreds of threads
to enter direct reclaim. Unfortunately, only one can reclaim from ARC at
a time. This means that one will reap while the others will be told to
do other things. If we enter a state where ARC is the only source of
memory available on the system, then we effectively have a fork bomb
where all of the other reclaim threads will starve reclaimation from ARC
of CPU time.

Additionally, it is possible for ARC and Linux to have different ideas
of when a system is low on memory. If Linux thinks it is out of memory
and ARC disagrees, we will have a situation where arc_reclaim_thread
spins.

This patch attempts to address the first issue by signalling
arc_reclaim_thread to enter reclaim and blocking until
eitheri signalled by arc_reclaim_thread 1 second passes. Resuming after
1 second is necessary to resolve a race between arc_reclaim_thread doing
its broadcast and sleeping. A previous patch had empirical success in
resolving the second by moving primary responsibility for ARC memory
reclaimation to the ARC shrinker callback. This patch moves all ARC
memory reclaimation duties to arc_reclaim_thread, which should have a
similar effect.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Remove b_thawed from arc_buf_hdr_t

The code involving b_thawed appears to be dead, so lets discard it.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Make dmu_sync_arg_cache

Signed-off-by: Richard Yao <ryao@gentoo.org>
Make zio_gang_node_t cache

Signed-off-by: Richard Yao <ryao@gentoo.org>
User namespace compatibility

Signed-off-by: Richard Yao <ryao@gentoo.org>
Move ARC allocations to slab caches

Signed-off-by: Richard Yao <ryao@gentoo.org>
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.
Make SLAB caches for dmu_tx_* operations

Signed-off-by: Richard Yao <ryao@gentoo.org>
Make slab cache for rl_t

Signed-off-by: Richard Yao <ryao@gentoo.org>