]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/zio_compress.c
Fix typo/etc in module/zfs/zfs_ctldir.c
[mirror_zfs.git] / module / zfs / zio_compress.c
index 974af03d12c669cb77d614ce00e7b2af2f0ffdb4..f5cbc3e8218a93a5ff77b01c4f962c6c418492c0 100644 (file)
  */
 
 /*
- * Copyright (c) 2013, 2016 by Delphix. All rights reserved.
+ * Copyright (c) 2013, 2018 by Delphix. All rights reserved.
  */
 
 #include <sys/zfs_context.h>
-#include <sys/compress.h>
 #include <sys/spa.h>
 #include <sys/zfeature.h>
 #include <sys/zio.h>
 #include <sys/zio_compress.h>
 
+/*
+ * If nonzero, every 1/X decompression attempts will fail, simulating
+ * an undetected memory error.
+ */
+unsigned long zio_decompress_fail_fraction = 0;
+
 /*
  * Compression vectors.
  */
@@ -149,5 +154,15 @@ zio_decompress_data(enum zio_compress c, abd_t *src, void *dst,
        int ret = zio_decompress_data_buf(c, tmp, dst, s_len, d_len);
        abd_return_buf(src, tmp, s_len);
 
+       /*
+        * Decompression shouldn't fail, because we've already verifyied
+        * the checksum.  However, for extra protection (e.g. against bitflips
+        * in non-ECC RAM), we handle this error (and test it).
+        */
+       ASSERT0(ret);
+       if (zio_decompress_fail_fraction != 0 &&
+           spa_get_random(zio_decompress_fail_fraction) == 0)
+               ret = SET_ERROR(EINVAL);
+
        return (ret);
 }