--- old/usr/src/uts/common/fs/zfs/sys/zio.h	Mon Aug  5 17:27:05 2019
+++ new/usr/src/uts/common/fs/zfs/sys/zio.h	Mon Aug  5 17:27:05 2019
@@ -21,7 +21,7 @@
 
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
@@ -44,6 +44,16 @@
 #endif
 
 /*
+ * Checksum state w.r.t. SHA256 acceleration.
+ */
+typedef enum {
+	CKSTATE_NONE = 0,
+	CKSTATE_WAITING,
+	CKSTATE_CHECKSUMMING,
+	CKSTATE_CHECKSUM_DONE
+} zio_checksum_state_t;
+
+/*
  * Embedded checksum
  */
 #define	ZEC_MAGIC	0x210da7ab10c7a11ULL
@@ -138,6 +148,18 @@
 #define	ZIO_FAILURE_MODE_CONTINUE	1
 #define	ZIO_FAILURE_MODE_PANIC		2
 
+/*
+ * Macro for asserting validity of the priorities obtained by conversion
+ * from CoS/vdev properties
+ */
+#define	ZIO_PRIORITY_QUEUEABLE_VALID(prio)	\
+	(((prio) >= ZIO_PRIORITY_SYNC_READ) &&	\
+	((prio) < ZIO_PRIORITY_NUM_QUEUEABLE))
+
+#define	ZIO_PIPELINE_CONTINUE		0x100
+#define	ZIO_PIPELINE_STOP		0x101
+#define	ZIO_PIPELINE_RESTART_STAGE	0x102
+
 enum zio_flag {
 	/*
 	 * Flags inherited by gang, ddt, and vdev children,
@@ -206,11 +228,8 @@
 
 #define	ZIO_VDEV_CHILD_FLAGS(zio)				\
 	(((zio)->io_flags & ZIO_FLAG_VDEV_INHERIT) |		\
-	ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_CANFAIL)
+	ZIO_FLAG_CANFAIL)
 
-#define	ZIO_CHILD_BIT(x)		(1 << (x))
-#define	ZIO_CHILD_BIT_IS_SET(val, x)	((val) & (1 << (x)))
-
 enum zio_child {
 	ZIO_CHILD_VDEV = 0,
 	ZIO_CHILD_GANG,
@@ -219,14 +238,6 @@
 	ZIO_CHILD_TYPES
 };
 
-#define	ZIO_CHILD_VDEV_BIT		ZIO_CHILD_BIT(ZIO_CHILD_VDEV)
-#define	ZIO_CHILD_GANG_BIT		ZIO_CHILD_BIT(ZIO_CHILD_GANG)
-#define	ZIO_CHILD_DDT_BIT		ZIO_CHILD_BIT(ZIO_CHILD_DDT)
-#define	ZIO_CHILD_LOGICAL_BIT		ZIO_CHILD_BIT(ZIO_CHILD_LOGICAL)
-#define	ZIO_CHILD_ALL_BITS					\
-	(ZIO_CHILD_VDEV_BIT | ZIO_CHILD_GANG_BIT | 		\
-	ZIO_CHILD_DDT_BIT | ZIO_CHILD_LOGICAL_BIT)
-
 enum zio_wait_type {
 	ZIO_WAIT_READY = 0,
 	ZIO_WAIT_DONE,
@@ -245,6 +256,8 @@
 extern boolean_t zio_dva_throttle_enabled;
 extern const char *zio_type_name[ZIO_TYPES];
 
+struct range_tree;
+
 /*
  * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
  * identifies any block in the pool.  By convention, the meta-objset (MOS)
@@ -304,9 +317,13 @@
 	dmu_object_type_t	zp_type;
 	uint8_t			zp_level;
 	uint8_t			zp_copies;
-	boolean_t		zp_dedup;
-	boolean_t		zp_dedup_verify;
+	uint8_t			zp_dedup;
+	uint8_t			zp_dedup_verify;
 	boolean_t		zp_nopwrite;
+	boolean_t		zp_metadata;
+	boolean_t		zp_usesc;
+	boolean_t		zp_usewbc;
+	uint64_t		zp_zpl_meta_to_special;
 } zio_prop_t;
 
 typedef struct zio_cksum_report zio_cksum_report_t;
@@ -386,6 +403,30 @@
 	list_node_t	zl_child_node;
 } zio_link_t;
 
+/*
+ * When smart compression is enabled, this callback info structure is
+ * passed to write zio's to monitor per-object compression performance.
+ *
+ * When zio_write determines that the `compression' setting for the dataset
+ * is not `off', if `sc_ask' is not NULL, it will call the `sc_ask' callback
+ * function, asking the upper layers whether it should really try to compress
+ * the object in question. If the function returns B_TRUE, compression is
+ * attempted. Once compression is done, sc_result is called to inform the
+ * upper layers of the compression result. By comparing the zio's io_size to
+ * io_orig_size it can monitor compression performance on the particular
+ * object in question (if io_size == io_orig_size, then compression failed).
+ * It is not legal to pass a NULL sc_ask but non-NULL sc_result to zio_write.
+ */
+typedef struct zio_smartcomp_info {
+	boolean_t (*sc_ask)(void *userinfo, const zio_t *);
+	void (*sc_result)(void *userinfo, const zio_t *);
+	void *sc_userinfo;
+} zio_smartcomp_info_t;
+
+#define	ZIO_SHOULD_COMPRESS(zio) \
+	((zio)->io_smartcomp.sc_ask == NULL || \
+	(zio)->io_smartcomp.sc_ask((zio)->io_smartcomp.sc_userinfo, (zio)))
+
 struct zio {
 	/* Core information about this I/O */
 	zbookmark_phys_t	io_bookmark;
@@ -405,6 +446,7 @@
 	list_t		io_child_list;
 	zio_t		*io_logical;
 	zio_transform_t *io_transform_stack;
+	zio_smartcomp_info_t	io_smartcomp;
 
 	/* Callback info */
 	zio_done_func_t	*io_ready;
@@ -465,6 +507,20 @@
 
 	/* Taskq dispatching state */
 	taskq_ent_t	io_tqent;
+
+	/* Timestamp for tracking vdev I/O latency */
+	hrtime_t io_vd_timestamp;
+
+	/* Checksum acceleration */
+	zio_checksum_state_t	zio_checksum_state;
+	zio_cksum_t		*zio_checksump;
+	void			*zio_checksum_datap;
+	uint64_t		zio_checksum_data_size;
+	struct zio		*zio_checksum_next;
+	zio_cksum_t		actual_cksum;
+
+	/* Metaslab class that will be used */
+	metaslab_class_t *io_mc;
 };
 
 extern int zio_bookmark_compare(const void *, const void *);
@@ -484,7 +540,8 @@
     zio_done_func_t *ready, zio_done_func_t *children_ready,
     zio_done_func_t *physdone, zio_done_func_t *done,
     void *private, zio_priority_t priority, enum zio_flag flags,
-    const zbookmark_phys_t *zb);
+    const zbookmark_phys_t *zb,
+    const zio_smartcomp_info_t *smartcomp);
 
 extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
     struct abd *data, uint64_t size, zio_done_func_t *done, void *private,
@@ -502,6 +559,10 @@
 extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
     zio_done_func_t *done, void *private, enum zio_flag flags);
 
+extern zio_t *zio_trim(spa_t *spa, vdev_t *vd, struct range_tree *tree,
+    zio_done_func_t *done, void *private, enum zio_flag flags,
+    int dkiocfree_flags, metaslab_t *msp);
+
 extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
     uint64_t size, struct abd *data, int checksum,
     zio_done_func_t *done, void *private, zio_priority_t priority,
@@ -512,6 +573,9 @@
     zio_done_func_t *done, void *private, zio_priority_t priority,
     enum zio_flag flags, boolean_t labels);
 
+extern zio_t *zio_wbc(zio_type_t type, vdev_t *vd, abd_t *data,
+    uint64_t size, uint64_t offset);
+
 extern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg,
     const blkptr_t *bp, enum zio_flag flags);
 
@@ -604,7 +668,6 @@
 
 extern void zfs_ereport_send_interim_checksum(zio_cksum_report_t *report);
 extern void zfs_ereport_free_checksum(zio_cksum_report_t *report);
-
 /* If we have the good data in hand, this function can be used */
 extern void zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd,
     struct zio *zio, uint64_t offset, uint64_t length,
@@ -619,6 +682,9 @@
 int zbookmark_compare(uint16_t dbss1, uint8_t ibs1, uint16_t dbss2,
     uint8_t ibs2, const zbookmark_phys_t *zb1, const zbookmark_phys_t *zb2);
 
+/* best effort dedup */
+void zio_best_effort_dedup(zio_t *zio);
+
 #ifdef	__cplusplus
 }
 #endif
