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>
Call zvol_create_minors() in spa_open_common() when initializing pool

There is an extremely odd bug that causes zvols to fail to appear on
some systems, but not others. Recently, I was able to consistently
reproduce this issue over a period of 1 month. The issue disappeared
after I applied this change from FreeBSD.

This is from FreeBSD's pool version 28 import, which occurred in
revision 219089.

Ported-by: Richard Yao <ryao@cs.stonybrook.edu>
Improve zvol initialization code

In addition, the following error will occur on some (possibly all)
kernels because blk_init_queue() will try to take the spinlock before we
initialize it.

[    5.538871] BUG: spinlock bad magic on CPU#0, zpool/4054
[    5.538885]  lock: 0xffff88021a73de60, .magic: 00000000, .owner:
<none>/-1, .owner_cpu: 0
[    5.538888] Pid: 4054, comm: zpool Not tainted 3.9.3 #11
[    5.538890] Call Trace:
[    5.538898]  [<ffffffff81478ef8>] spin_dump+0x8c/0x91
[    5.538902]  [<ffffffff81478f1e>] spin_bug+0x21/0x26
[    5.538906]  [<ffffffff812da097>] do_raw_spin_lock+0x127/0x130
[    5.538911]  [<ffffffff81253301>] ? zvol_probe+0x91/0xf0
[    5.538914]  [<ffffffff8147d851>] _raw_spin_lock_irq+0x21/0x30
[    5.538919]  [<ffffffff812c2c1e>] cfq_init_queue+0x1fe/0x350
[    5.538922]  [<ffffffff81253360>] ? zvol_probe+0xf0/0xf0
[    5.538926]  [<ffffffff812aacb8>] elevator_init+0x78/0x140
[    5.538930]  [<ffffffff812b2677>] blk_init_allocated_queue+0x87/0xb0
[    5.538933]  [<ffffffff81253360>] ? zvol_probe+0xf0/0xf0
[    5.538937]  [<ffffffff812b26d5>] blk_init_queue_node+0x35/0x70
[    5.538941]  [<ffffffff812b271e>] blk_init_queue+0xe/0x10
[    5.538944]  [<ffffffff8125211b>] __zvol_create_minor+0x24b/0x620
[    5.538947]  [<ffffffff81253264>] zvol_create_minors_cb+0x24/0x30
[    5.538952]  [<ffffffff811bd9ca>] dmu_objset_find_spa+0xea/0x510
[    5.538955]  [<ffffffff81253240>] ? zvol_free+0x60/0x60
[    5.538958]  [<ffffffff811bda71>] dmu_objset_find_spa+0x191/0x510
[    5.538962]  [<ffffffff81253240>] ? zvol_free+0x60/0x60
[    5.538965]  [<ffffffff81253ea2>] zvol_create_minors+0x92/0x180
[    5.538969]  [<ffffffff811f8d80>] spa_open_common+0x250/0x380
[    5.538973]  [<ffffffff811f8ece>] spa_open+0xe/0x10
[    5.538977]  [<ffffffff8122817e>] pool_status_check.part.22+0x1e/0x80
[    5.538980]  [<ffffffff81228a55>] zfsdev_ioctl+0x155/0x190
[    5.538984]  [<ffffffff8116a695>] do_vfs_ioctl+0x325/0x5a0
[    5.538989]  [<ffffffff81163f1d>] ? final_putname+0x1d/0x40
[    5.538992]  [<ffffffff8116a950>] sys_ioctl+0x40/0x80
[    5.538996]  [<ffffffff814812c9>] ? do_page_fault+0x9/0x10
[    5.539000]  [<ffffffff81483929>] system_call_fastpath+0x16/0x1b
[    5.541118]  zd0: unknown partition table

We fix this by calling spin_lock_init before blk_init_queue.

Also, we do not cleanup from failures in zvol_init particularly
well. We resolve this with changes to zvol_init() and zvol_fini().

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>
Import zfs_holey() from Open Solaris

This is prerequisite to adding support for SEEK_DATA/SEEK_HOLE to the
ZPL. It is split into its own commit for proper attribution.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Richard Laager <rlaager@wiktel.com>
SEEK_DATA/SEEK_HOLE support

This adds SEEK_DATA/SEEK_HOLE to lseek()/llseek().

This is a heavily revised version of the patch proposed in
zfsonlinux/zfs#1516. The original message by Li Dongyang was:

```
Add SEEK_DATA/SEEK_HOLE by creating our own zpl_file_llseek().
Tested with xfstests 285 and 286. test0[7-9] of 285 will try to reserve
the blocks first via fallocate(2), we will fail there as currently we
don't support that.
```

My revisions address some issues that I spotted and also some things
that were spotted upon review by Richard Laager. The behavior on errors
has been altered to match the Solaris version, which is where this
extension was invented. It should still pass the XFS tests, but I am not
setup to verify that. The zfs_holey() function from Open Solaris was
moved to its own commit for attribution purposes.

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.

Closes zfsonlinux/zfs#1384

Original-patch-by: Li Dongyang <dongyang.li@anu.edu.au>
Signed-off-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Richard Laager <rlaager@wiktel.com>
Use kmem_cache for zil_vdev_node_t objects

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