Use GFP_ATOMIC for allocations that are required for swap on zvols

dmu_bio_clone(), __vdev_disk_physio() and vdev_disk_io_flush() are used
when doing swap to a zvol. Failing to use GFP_ATOMIC permits them to
block under memory pressure, which can prevent swap operations and cause
deadlocks. We use GFP_ATOMIC | __GFP_HIGH for these allocations because
they are required for swap operations on zvols.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
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>
Linux 3.10 compat: bops->release() now returns void.

torvalds/linux@db2a144b

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
Illumos #2882, #2883, #2900

2882 implement libzfs_core
2883 changing "canmount" property to "on" should not always remount dataset
2900 "zfs snapshot" should be able to create multiple, arbitrary snapshots at once

Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Chris Siden <christopher.siden@delphix.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Bill Pijewski <wdp@joyent.com>
Reviewed by: Dan Kruchinin <dan.kruchinin@gmail.com>
Approved by: Eric Schrock <Eric.Schrock@delphix.com>

References:
  illumos/illumos-gate@4445fffbbb1ea25fd0e9ea68b9380dd7a6709025

Ported-by: Tim Chase <tim@chase2k.com>
Closes #1293

Porting notes:

Add "nosleep" versions of the fnvlist_dup, fnvlist_merge, fnvlist_alloc
and fnvlist_pack functions with a suffix of "_nosleep".  They simply
perform their allocations with the KM_NOSLEEP flag.

Add zvol minor device creation to the new zfs_snapshot_nvl function.

Remove the logging of the "release" operation in
dsl_dataset_user_release_sync().  The logging caused a null dereference
because ds->ds_dir is zeroed in dsl_dataset_destroy_sync() and the
logging functions try to get the ds name via the dsl_dataset_name()
function. I've got no idea why this particular code would have worked
in Illumos.  This code has subsequently been completely reworked in
Illumos commit 3b2aab1 (3464 zfs synctask code needs restructuring).

Squash some "may be used uninitialized" warning/erorrs.

Fix some printf format warnings for %lld and %llu.
Illumos #3098 zfs userspace/groupspace fail without saying why when run as non-root

ZFSOnLinux currently We do not actually need this change because we lack
delegation support and therefore only permit root commands to be run as
root, but Illumos #3464 depends on this change and it would not hurt to
have it in the code for when delegation support is implemented.

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

Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
Ported-by: Richard Yao <ryao@gentoo.org>
Illumos #3557, #3558, #3559, #3560 import

This was a single commit in upstream Illumos:

3557 dumpvp_size is not updated correctly when a dump zvol's size is changed
3558 setting the volsize on a dump device does not return back ENOSPC
3559 setting a volsize larger than the space available sometimes succeeds
3560 dumpadm should be able to remove a dump device

Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Approved by: Albert Lee <trisk@nexenta.com>

Many of the changes made in this upstream Illumos commit was not
relevant to use because ZFSOnLinux has an almost completely rewritten
zvol.c and Linux lacks dump devices.  However, a few changes do apply
and they areare relevant in that they should make future code imports
easier to do, so we import them.

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>
Illumos #3603, #3604: bobj improvements

3603 panic from bpobj_enqueue_subobj()
3604 zdb should print bpobjs more verbosely

https://www.illumos.org/issues/3603
https://www.illumos.org/issues/3604

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>
Illumos #3588 provide zfs properties for logical (uncompressed) space used and referenced

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

Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Reviewed by: Richard Elling <richard.elling@dey-sys.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
Ported-by: Richard Yao <ryao@gentoo.org>