#include <linux/crypto.h>
int alloc_compr(const char *obd_name, enum ll_compr_type *type,
- unsigned int lvl, struct crypto_comp **cc, bool decompress);
+ unsigned int *lvl, struct crypto_comp **cc, bool decompress);
int compress_chunk(const char *obd_name, struct crypto_comp *cc,
const unsigned char *in, unsigned int in_len,
LL_COMPR_TYPE_MAX,
LL_COMPR_TYPE_UNCHANGED = 255
};
+/* lz4 levels go up to 27, but level is a 4 bit field, so we have a mapping */
+#define LL_LZ4FAST_MAX_LEVEL 15
#define COMPR_CHUNK_MIN_BITS 16
#define COMPR_GET_CHUNK_SIZE(log_bits) (1 << (log_bits + COMPR_CHUNK_MIN_BITS))
#define compr_type_best LL_COMPR_TYPE_GZIP
int alloc_compr(const char *obd_name, enum ll_compr_type *type,
- unsigned int lvl, struct crypto_comp **cc, bool decompress)
+ unsigned int *lvl, struct crypto_comp **cc, bool decompress)
{
int ret = 0;
LASSERT(ergo(decompress, *type != LL_COMPR_TYPE_BEST &&
*type != LL_COMPR_TYPE_FAST));
- if (*type == LL_COMPR_TYPE_BEST)
+ if (*type == LL_COMPR_TYPE_BEST) {
*type = compr_type_best;
- else if (*type == LL_COMPR_TYPE_FAST)
+ /* all compression types support a level 9 */
+ *lvl = 9;
+ } else if (*type == LL_COMPR_TYPE_FAST) {
*type = compr_type_fast;
+ /* lz4fast - our usual 'fast' interprets level as an
+ * acceleration factor, so special case that
+ */
+ if (*type == LL_COMPR_TYPE_LZ4FAST)
+ *lvl = LL_LZ4FAST_MAX_LEVEL;
+ else
+ /* all compression types support a level 0 */
+ *lvl = 0;
+ }
load_crypto_module(*type);
again:
- *cc = crypto_alloc_comp(crypto_name_from_type(*type, lvl), 0, 0);
+ *cc = crypto_alloc_comp(crypto_name_from_type(*type, *lvl), 0, 0);
if (IS_ERR(*cc)) {
ret = PTR_ERR(*cc);
CERROR("Cannot initialize compressor %i, error %i.\n", *type,
if (ret) {
*cc = NULL;
} else /* success */ {
- if (lvl != -1)
- ll_crypto_comp_set_level(*cc, lvl);
+ if (*lvl != -1)
+ ll_crypto_comp_set_level(*cc, *lvl);
CDEBUG(D_SEC, "%s: crypto_comp allocated, type %i, level %i\n",
- obd_name, *type, lvl);
+ obd_name, *type, *lvl);
}
RETURN(ret);
type = llch->llch_compr_type;
lvl = llch->llch_compr_level;
hdr_size = llch->llch_header_size;
- rc = alloc_compr(obd_name, &type, lvl, &cc, true);
+ rc = alloc_compr(obd_name, &type, &lvl, &cc, true);
if (rc) {
CERROR("%s: Setup for decompression failed, type %i, lvl %d, rc = %d\n",
obd_name, type, lvl, rc);
src_buf_bits = chunk_bits + 1;
dest_buf_bits = chunk_bits + 1;
- rc = alloc_compr(obd_name, &type, lvl, &cc, false);
+ rc = alloc_compr(obd_name, &type, &lvl, &cc, false);
/* if we're unable to setup compression, alloc_compr prints a warning
* but we do not fail the IO - just write data uncompressed
*/
buf_bits = chunk_bits + 1;
pages_per_chunk = chunk_size / PAGE_SIZE;
- rc = alloc_compr(obd_name, &type, lvl, &cc, true);
+ rc = alloc_compr(obd_name, &type, &lvl, &cc, true);
if (rc)
GOTO(out, rc);