From 8ac22c61bfa23e82f6c8c15d817ebc057f4d57a8 Mon Sep 17 00:00:00 2001 From: Vitaut Bajaryn Date: Sun, 1 May 2016 15:38:10 +0200 Subject: [PATCH] Store required feature flags in zio_compress_table Add zio_compress_info_t.ci_feature --- include/sys/zio.h | 2 +- include/sys/zio_compress.h | 2 + module/zfs/dmu_objset.c | 1 - module/zfs/zfs_ioctl.c | 21 +++------ module/zfs/zio_compress.c | 96 +++++++++++++++++++++++++------------- 5 files changed, 73 insertions(+), 49 deletions(-) diff --git a/include/sys/zio.h b/include/sys/zio.h index 83f6d9237fc9..099bafa952e0 100644 --- a/include/sys/zio.h +++ b/include/sys/zio.h @@ -158,7 +158,7 @@ enum bp_compress { /* * The number of "legacy" compression functions which can be set on individual - * objects. + * objects and don't require feature flags. */ #define ZIO_COMPRESS_LEGACY_FUNCTIONS ZIO_COMPRESS_LZ4 diff --git a/include/sys/zio_compress.h b/include/sys/zio_compress.h index adc34a9fea3f..a9b15057fdf1 100644 --- a/include/sys/zio_compress.h +++ b/include/sys/zio_compress.h @@ -32,6 +32,7 @@ #define _SYS_ZIO_COMPRESS_H #include +#include #ifdef __cplusplus extern "C" { @@ -51,6 +52,7 @@ typedef const struct zio_compress_info { zio_compress_func_t *ci_compress; /* compression function */ enum bp_compress ci_bp_compress_value; /* value stored in BP */ + spa_feature_t ci_feature; /* required feature flag */ int ci_level; /* level parameter */ char *ci_name; /* algorithm name */ } zio_compress_info_t; diff --git a/module/zfs/dmu_objset.c b/module/zfs/dmu_objset.c index ef6adf2c9fc1..af0d841e8c4d 100644 --- a/module/zfs/dmu_objset.c +++ b/module/zfs/dmu_objset.c @@ -1068,7 +1068,6 @@ dmu_objset_write_done(zio_t *zio, arc_buf_t *abuf, void *arg) (void) dsl_dataset_block_kill(ds, bp_orig, tx, B_TRUE); dsl_dataset_block_born(ds, bp, tx); - /* TODO create zio_compress_to_feature */ if (os->os_compress >= ZIO_COMPRESS_LZ4HC_1 && os->os_compress <= ZIO_COMPRESS_LZ4HC_16) ds->ds_feature_activation_needed[ diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c index 05eff163ffec..22f5ae34d33f 100644 --- a/module/zfs/zfs_ioctl.c +++ b/module/zfs/zfs_ioctl.c @@ -155,6 +155,7 @@ #include #include #include +#include #include #include #include @@ -3715,26 +3716,16 @@ zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr) SPA_VERSION_ZLE_COMPRESSION)) return (SET_ERROR(ENOTSUP)); - if (intval == ZIO_COMPRESS_LZ4 || - (intval >= ZIO_COMPRESS_LZ4HC_1 && - intval <= ZIO_COMPRESS_LZ4HC_16)) { + if (intval >= ZIO_COMPRESS_LEGACY_FUNCTIONS) { + spa_feature_t feature = + zio_compress_table[intval].ci_feature; spa_t *spa; if ((err = spa_open(dsname, &spa, FTAG)) != 0) return (err); - /* TODO create zio_compress_to_feature */ - if (intval == ZIO_COMPRESS_LZ4 && - !spa_feature_is_enabled(spa, - SPA_FEATURE_LZ4_COMPRESS)) { - spa_close(spa, FTAG); - return (SET_ERROR(ENOTSUP)); - } - - if (intval >= ZIO_COMPRESS_LZ4HC_1 && - intval <= ZIO_COMPRESS_LZ4HC_16 && - !spa_feature_is_enabled(spa, - SPA_FEATURE_LZ4HC_COMPRESS)) { + if (feature != SPA_FEATURE_NONE && + !spa_feature_is_enabled(spa, feature)) { spa_close(spa, FTAG); return (SET_ERROR(ENOTSUP)); } diff --git a/module/zfs/zio_compress.c b/module/zfs/zio_compress.c index 9f62ea6f2aa7..57502b764728 100644 --- a/module/zfs/zio_compress.c +++ b/module/zfs/zio_compress.c @@ -47,38 +47,70 @@ */ zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS] = { - {NULL, BP_COMPRESS_INHERIT, 0, "inherit"}, - {NULL, BP_COMPRESS_ON, 0, "on"}, - {NULL, BP_COMPRESS_OFF, 0, "uncompressed"}, - {lzjb_compress, BP_COMPRESS_LZJB, 0, "lzjb"}, - {NULL, BP_COMPRESS_EMPTY, 0, "empty"}, - {gzip_compress, BP_COMPRESS_GZIP_1, 1, "gzip-1"}, - {gzip_compress, BP_COMPRESS_GZIP_2, 2, "gzip-2"}, - {gzip_compress, BP_COMPRESS_GZIP_3, 3, "gzip-3"}, - {gzip_compress, BP_COMPRESS_GZIP_4, 4, "gzip-4"}, - {gzip_compress, BP_COMPRESS_GZIP_5, 5, "gzip-5"}, - {gzip_compress, BP_COMPRESS_GZIP_6, 6, "gzip-6"}, - {gzip_compress, BP_COMPRESS_GZIP_7, 7, "gzip-7"}, - {gzip_compress, BP_COMPRESS_GZIP_8, 8, "gzip-8"}, - {gzip_compress, BP_COMPRESS_GZIP_9, 9, "gzip-9"}, - {zle_compress, BP_COMPRESS_ZLE, 64, "zle"}, - {lz4_compress_zfs, BP_COMPRESS_LZ4, 0, "lz4"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 1, "lz4hc-1"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 2, "lz4hc-2"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 3, "lz4hc-3"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 4, "lz4hc-4"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 5, "lz4hc-5"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 6, "lz4hc-6"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 7, "lz4hc-7"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 8, "lz4hc-8"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 9, "lz4hc-9"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 10, "lz4hc-10"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 11, "lz4hc-11"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 12, "lz4hc-12"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 13, "lz4hc-13"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 14, "lz4hc-14"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 15, "lz4hc-15"}, - {lz4hc_compress_zfs, BP_COMPRESS_LZ4, 16, "lz4hc-16"}, + {NULL, BP_COMPRESS_INHERIT, SPA_FEATURE_NONE, + 0, "inherit"}, + {NULL, BP_COMPRESS_ON, SPA_FEATURE_NONE, + 0, "on"}, + {NULL, BP_COMPRESS_OFF, SPA_FEATURE_NONE, + 0, "uncompressed"}, + {lzjb_compress, BP_COMPRESS_LZJB, SPA_FEATURE_NONE, + 0, "lzjb"}, + {NULL, BP_COMPRESS_EMPTY, SPA_FEATURE_NONE, + 0, "empty"}, + {gzip_compress, BP_COMPRESS_GZIP_1, SPA_FEATURE_NONE, + 1, "gzip-1"}, + {gzip_compress, BP_COMPRESS_GZIP_2, SPA_FEATURE_NONE, + 2, "gzip-2"}, + {gzip_compress, BP_COMPRESS_GZIP_3, SPA_FEATURE_NONE, + 3, "gzip-3"}, + {gzip_compress, BP_COMPRESS_GZIP_4, SPA_FEATURE_NONE, + 4, "gzip-4"}, + {gzip_compress, BP_COMPRESS_GZIP_5, SPA_FEATURE_NONE, + 5, "gzip-5"}, + {gzip_compress, BP_COMPRESS_GZIP_6, SPA_FEATURE_NONE, + 6, "gzip-6"}, + {gzip_compress, BP_COMPRESS_GZIP_7, SPA_FEATURE_NONE, + 7, "gzip-7"}, + {gzip_compress, BP_COMPRESS_GZIP_8, SPA_FEATURE_NONE, + 8, "gzip-8"}, + {gzip_compress, BP_COMPRESS_GZIP_9, SPA_FEATURE_NONE, + 9, "gzip-9"}, + {zle_compress, BP_COMPRESS_ZLE, SPA_FEATURE_NONE, + 64, "zle"}, + {lz4_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4_COMPRESS, 0, "lz4"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 1, "lz4hc-1"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 2, "lz4hc-2"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 3, "lz4hc-3"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 4, "lz4hc-4"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 5, "lz4hc-5"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 6, "lz4hc-6"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 7, "lz4hc-7"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 8, "lz4hc-8"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 9, "lz4hc-9"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 10, "lz4hc-10"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 11, "lz4hc-11"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 12, "lz4hc-12"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 13, "lz4hc-13"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 14, "lz4hc-14"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 15, "lz4hc-15"}, + {lz4hc_compress_zfs, BP_COMPRESS_LZ4, + SPA_FEATURE_LZ4HC_COMPRESS, 16, "lz4hc-16"}, }; zio_decompress_info_t zio_decompress_table[BP_COMPRESS_VALUES] = {