diff --git a/include/sys/ddt.h b/include/sys/ddt.h index 6378c042c7..2f9ff84b28 100644 --- a/include/sys/ddt.h +++ b/include/sys/ddt.h @@ -58,9 +58,6 @@ enum ddt_class { #define DDT_TYPE_CURRENT 0 -#define DDT_COMPRESS_BYTEORDER_MASK 0x80 -#define DDT_COMPRESS_FUNCTION_MASK 0x7f - /* * On-disk ddt entry: key (name) and physical storage (value). */ @@ -92,8 +89,6 @@ typedef struct ddt_key { #define DDK_GET_CRYPT(ddk) BF64_GET((ddk)->ddk_prop, 39, 1) #define DDK_SET_CRYPT(ddk, x) BF64_SET((ddk)->ddk_prop, 39, 1, x) -#define DDT_KEY_WORDS (sizeof (ddt_key_t) / sizeof (uint64_t)) - #define DDE_GET_NDVAS(dde) (DDK_GET_CRYPT(&dde->dde_key) \ ? SPA_DVAS_PER_BP - 1 : SPA_DVAS_PER_BP) @@ -220,9 +215,6 @@ extern void ddt_get_dedup_stats(spa_t *spa, ddt_stat_t *dds_total); extern uint64_t ddt_get_dedup_dspace(spa_t *spa); extern uint64_t ddt_get_pool_dedup_ratio(spa_t *spa); -extern size_t ddt_compress(void *src, uchar_t *dst, size_t s_len, size_t d_len); -extern void ddt_decompress(uchar_t *src, void *dst, size_t s_len, size_t d_len); - extern ddt_t *ddt_select(spa_t *spa, const blkptr_t *bp); extern void ddt_enter(ddt_t *ddt); extern void ddt_exit(ddt_t *ddt); diff --git a/module/zfs/ddt.c b/module/zfs/ddt.c index 05b28acbcd..221e964138 100644 --- a/module/zfs/ddt.c +++ b/module/zfs/ddt.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -554,47 +553,6 @@ ddt_get_pool_dedup_ratio(spa_t *spa) return (dds_total.dds_ref_dsize * 100 / dds_total.dds_dsize); } -size_t -ddt_compress(void *src, uchar_t *dst, size_t s_len, size_t d_len) -{ - uchar_t *version = dst++; - int cpfunc = ZIO_COMPRESS_ZLE; - zio_compress_info_t *ci = &zio_compress_table[cpfunc]; - size_t c_len; - - ASSERT3U(d_len, >=, s_len + 1); /* no compression plus version byte */ - - c_len = ci->ci_compress(src, dst, s_len, d_len - 1, ci->ci_level); - - if (c_len == s_len) { - cpfunc = ZIO_COMPRESS_OFF; - memcpy(dst, src, s_len); - } - - *version = cpfunc; - if (ZFS_HOST_BYTEORDER) - *version |= DDT_COMPRESS_BYTEORDER_MASK; - - return (c_len + 1); -} - -void -ddt_decompress(uchar_t *src, void *dst, size_t s_len, size_t d_len) -{ - uchar_t version = *src++; - int cpfunc = version & DDT_COMPRESS_FUNCTION_MASK; - zio_compress_info_t *ci = &zio_compress_table[cpfunc]; - - if (ci->ci_decompress != NULL) - (void) ci->ci_decompress(src, dst, s_len, d_len, ci->ci_level); - else - memcpy(dst, src, d_len); - - if (((version & DDT_COMPRESS_BYTEORDER_MASK) != 0) != - (ZFS_HOST_BYTEORDER != 0)) - byteswap_uint64_array(dst, d_len); -} - ddt_t * ddt_select(spa_t *spa, const blkptr_t *bp) { diff --git a/module/zfs/ddt_zap.c b/module/zfs/ddt_zap.c index a1d296407a..6b9d60c560 100644 --- a/module/zfs/ddt_zap.c +++ b/module/zfs/ddt_zap.c @@ -30,10 +30,57 @@ #include #include #include +#include static unsigned int ddt_zap_default_bs = 15; static unsigned int ddt_zap_default_ibs = 15; +#define DDT_ZAP_COMPRESS_BYTEORDER_MASK 0x80 +#define DDT_ZAP_COMPRESS_FUNCTION_MASK 0x7f + +#define DDT_KEY_WORDS (sizeof (ddt_key_t) / sizeof (uint64_t)) + +static size_t +ddt_zap_compress(void *src, uchar_t *dst, size_t s_len, size_t d_len) +{ + uchar_t *version = dst++; + int cpfunc = ZIO_COMPRESS_ZLE; + zio_compress_info_t *ci = &zio_compress_table[cpfunc]; + size_t c_len; + + ASSERT3U(d_len, >=, s_len + 1); /* no compression plus version byte */ + + c_len = ci->ci_compress(src, dst, s_len, d_len - 1, ci->ci_level); + + if (c_len == s_len) { + cpfunc = ZIO_COMPRESS_OFF; + memcpy(dst, src, s_len); + } + + *version = cpfunc; + if (ZFS_HOST_BYTEORDER) + *version |= DDT_ZAP_COMPRESS_BYTEORDER_MASK; + + return (c_len + 1); +} + +static void +ddt_zap_decompress(uchar_t *src, void *dst, size_t s_len, size_t d_len) +{ + uchar_t version = *src++; + int cpfunc = version & DDT_ZAP_COMPRESS_FUNCTION_MASK; + zio_compress_info_t *ci = &zio_compress_table[cpfunc]; + + if (ci->ci_decompress != NULL) + (void) ci->ci_decompress(src, dst, s_len, d_len, ci->ci_level); + else + memcpy(dst, src, d_len); + + if (((version & DDT_ZAP_COMPRESS_BYTEORDER_MASK) != 0) != + (ZFS_HOST_BYTEORDER != 0)) + byteswap_uint64_array(dst, d_len); +} + static int ddt_zap_create(objset_t *os, uint64_t *objectp, dmu_tx_t *tx, boolean_t prehash) { @@ -77,7 +124,7 @@ ddt_zap_lookup(objset_t *os, uint64_t object, ddt_entry_t *dde) if (error) goto out; - ddt_decompress(cbuf, dde->dde_phys, csize, sizeof (dde->dde_phys)); + ddt_zap_decompress(cbuf, dde->dde_phys, csize, sizeof (dde->dde_phys)); out: kmem_free(cbuf, sizeof (dde->dde_phys) + 1); @@ -97,7 +144,7 @@ ddt_zap_update(objset_t *os, uint64_t object, ddt_entry_t *dde, dmu_tx_t *tx) uchar_t cbuf[sizeof (dde->dde_phys) + 1]; uint64_t csize; - csize = ddt_compress(dde->dde_phys, cbuf, + csize = ddt_zap_compress(dde->dde_phys, cbuf, sizeof (dde->dde_phys), sizeof (cbuf)); return (zap_update_uint64(os, object, (uint64_t *)&dde->dde_key, @@ -138,7 +185,7 @@ ddt_zap_walk(objset_t *os, uint64_t object, ddt_entry_t *dde, uint64_t *walk) DDT_KEY_WORDS, 1, csize, cbuf); ASSERT0(error); if (error == 0) { - ddt_decompress(cbuf, dde->dde_phys, csize, + ddt_zap_decompress(cbuf, dde->dde_phys, csize, sizeof (dde->dde_phys)); dde->dde_key = *(ddt_key_t *)za.za_name; }