Don't test for gang blocks when populating the trim map.

Since 2fd4ce81a6748b46728127212a1ba384c008696f, gang block free zios
have correct size, so there's no need to skip them. Besides, the test
fails with a NULL dereference bug on RAID-Z because io_bp is NULL in
this case.
Don't TRIM after the SPA has been frozen.

Currently, the TRIM module doesn't check for spa_freeze_txg when
issuing TRIM requests. In a normal run this isn't an issue since
vdev_config_sync() doesn't wake the TRIM thread if the SPA is frozen.

However, when closing a frozen pool, trim_thread_destroy() gets called,
which wakes the TRIM thread, which results in a TRIM commit. As a
result, all TXGs until spa_syncing_txg - txg_limit get TRIMmed, which
includes spa_freeze_txg.

As a result, when reopening, ZFS tries to read data from the frozen
TXG, and fails.

This patch fixes the issue by taking spa_freeze_txg into account when
commiting TRIMs.
Add TRIM support for disk vdevs using Linux DISCARD interface.

We introduce a new vdev_disk_io_trim() function inspired from the Linux
blkdev_issue_discard() function and the pre-existing vdev_disk_physio()
function. The new function takes care of splitting discard requests
into smaller ones if necessary according to maximum discard limits.
Add TRIM support for file vdevs.

This adds TRIM support for file vdevs, using the newly-added VOP_SPACE
compatibility interface which translates to Linux
fallocate(FALLOC_FL_PUNCH_HOLE). When a TRIM request is issued to a
file vdev, ZFS will "punch a hole" (deallocate space) inside the
underlying file. Note that few Linux filesystems support hole punching
(currently OCFS2, XFS, and ext4).

Note that for this to work, you need to build against a kernel that
supports file hole punching (i.e. Linux >= 2.6.38). In addition, for
this to work in userspace (e.g. ztest), the installed userspace
kernel headers (i.e. /usr/include/linux) must be up-to-date.

NOTE: you need VOP_SPACE() support in SPL for this patch to build.
Fix assertion failure due to stale inflight writes.

ztest runs with TRIM enabled on a backing filesystem that doesn't
support hole punching revealed the following race condition:

 1. A write is issued to a vdev and added to the TRIM map inflight
    writes tree.
 2. The very first TRIM request for this vdev is issued.
 3. The TRIM request fails with EOPNOTSUPP, as expected. vdev_notrim
    is set.
 4. The write completes. trim_map_write_done() is called.
 5. trim_map_write_done() sees that vdev_notrim is set, and returns
    immediately.
 6. As a result, the write stays in the TRIM map inflight writes tree
    forever.
 7. When the vdev is closed, trim_map_destroy() tries to destroy the
    inflight writes tree, which triggers an assertion failure because
    it isn't empty.

This patch fixes the issue by removing the check on vdev_notrim in
trim_map_write_done().
Fix assertion failure due to inflight frees.

ztest runs with TRIM enabled revealed a race condition which occurs when
a vdev close is pending while there are TRIM requests in flight. When
the TRIM ZIOs complete, the SPA lock is released. The SPA lock is then
immediately taken by the vdev close path, which calls trim_map_destroy()
before trim_map_vdev_commit_done() has a chance to run.
trim_map_destroy() then tries to destroy the inflight free tree, which
fails with an assertion failure because it is non-empty.

This patch fixes the issue by making trim_map_destroy() call
trim_map_vdev_commit_done() before destroying the TRIM map.