]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Support secure discard on zvols
authorRichard Yao <ryao@gentoo.org>
Fri, 10 Oct 2014 15:23:23 +0000 (11:23 -0400)
committerRichard Yao <ryao@gentoo.org>
Fri, 4 Sep 2015 19:37:24 +0000 (15:37 -0400)
Linux 2.6.36 introduced REQ_SECURE to indicate when discards *must* be
processed, such that we cannot do optimizations like block alignment.
Consequently, the discard semantics prior to 2.6.36 require us to always
process unaligned discards. Previously, we would do this optimization
regardless. This patch changes things to correctly restrict this
optimization to situations where REQ_SECURE exists, but is not included
in the flags.

Signed-off-by: Richard Yao <ryao@gentoo.org>
module/zfs/zvol.c

index 074ec51e6f9ec18b1572c2690ab44f67f976e9c0..492f8ff8793b05ad2aa6e67d48be6531a4bc8e10 100644 (file)
@@ -650,14 +650,19 @@ zvol_discard(struct bio *bio)
                return (SET_ERROR(EIO));
 
        /*
-        * Align the request to volume block boundaries. If we don't,
-        * then this will force dnode_free_range() to zero out the
-        * unaligned parts, which is slow (read-modify-write) and
-        * useless since we are not freeing any space by doing so.
-        * XXX: We should handle secure discard by zeroing out unaligned parts.
+        * Align the request to volume block boundaries when REQ_SECURE is
+        * available, but not requested. If we don't, then this will force
+        * dnode_free_range() to zero out the unaligned parts, which is slow
+        * (read-modify-write) and useless since we are not freeing any space
+        * by doing so. Kernels that do not support REQ_SECURE (2.6.32 through
+        * 2.6.35) will not receive this optimization.
         */
-       start = P2ROUNDUP(start, zv->zv_volblocksize);
-       end = P2ALIGN(end, zv->zv_volblocksize);
+#ifdef REQ_SECURE
+       if (!(bio->bi_rw & REQ_SECURE)) {
+               start = P2ROUNDUP(start, zv->zv_volblocksize);
+               end = P2ALIGN(end, zv->zv_volblocksize);
+       }
+#endif
 
        if (start >= end)
                return (0);