1515 * decompression.
1616 */
1717
18- #include <linux/ crypto.h>
18+ #include <crypto/acompress .h>
1919#include "ubifs.h"
2020
2121/* Fake description object for the "none" compressor */
@@ -26,11 +26,8 @@ static struct ubifs_compressor none_compr = {
2626};
2727
2828#ifdef CONFIG_UBIFS_FS_LZO
29- static DEFINE_MUTEX (lzo_mutex );
30-
3129static struct ubifs_compressor lzo_compr = {
3230 .compr_type = UBIFS_COMPR_LZO ,
33- .comp_mutex = & lzo_mutex ,
3431 .name = "lzo" ,
3532 .capi_name = "lzo" ,
3633};
@@ -42,13 +39,8 @@ static struct ubifs_compressor lzo_compr = {
4239#endif
4340
4441#ifdef CONFIG_UBIFS_FS_ZLIB
45- static DEFINE_MUTEX (deflate_mutex );
46- static DEFINE_MUTEX (inflate_mutex );
47-
4842static struct ubifs_compressor zlib_compr = {
4943 .compr_type = UBIFS_COMPR_ZLIB ,
50- .comp_mutex = & deflate_mutex ,
51- .decomp_mutex = & inflate_mutex ,
5244 .name = "zlib" ,
5345 .capi_name = "deflate" ,
5446};
@@ -60,13 +52,8 @@ static struct ubifs_compressor zlib_compr = {
6052#endif
6153
6254#ifdef CONFIG_UBIFS_FS_ZSTD
63- static DEFINE_MUTEX (zstd_enc_mutex );
64- static DEFINE_MUTEX (zstd_dec_mutex );
65-
6655static struct ubifs_compressor zstd_compr = {
6756 .compr_type = UBIFS_COMPR_ZSTD ,
68- .comp_mutex = & zstd_enc_mutex ,
69- .decomp_mutex = & zstd_dec_mutex ,
7057 .name = "zstd" ,
7158 .capi_name = "zstd" ,
7259};
@@ -80,6 +67,30 @@ static struct ubifs_compressor zstd_compr = {
8067/* All UBIFS compressors */
8168struct ubifs_compressor * ubifs_compressors [UBIFS_COMPR_TYPES_CNT ];
8269
70+ static int ubifs_compress_req (const struct ubifs_info * c ,
71+ struct acomp_req * req ,
72+ void * out_buf , int * out_len ,
73+ const char * compr_name )
74+ {
75+ struct crypto_wait wait ;
76+ int in_len = req -> slen ;
77+ int dlen = * out_len ;
78+ int err ;
79+
80+ dlen = min (dlen , in_len - UBIFS_MIN_COMPRESS_DIFF );
81+
82+ crypto_init_wait (& wait );
83+ acomp_request_set_callback (req , CRYPTO_TFM_REQ_MAY_BACKLOG ,
84+ crypto_req_done , & wait );
85+ acomp_request_set_dst_dma (req , out_buf , dlen );
86+ err = crypto_acomp_compress (req );
87+ err = crypto_wait_req (err , & wait );
88+ * out_len = req -> dlen ;
89+ acomp_request_free (req );
90+
91+ return err ;
92+ }
93+
8394/**
8495 * ubifs_compress - compress data.
8596 * @c: UBIFS file-system description object
@@ -112,23 +123,14 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,
112123 if (in_len < UBIFS_MIN_COMPR_LEN )
113124 goto no_compr ;
114125
115- if (compr -> comp_mutex )
116- mutex_lock (compr -> comp_mutex );
117- err = crypto_comp_compress (compr -> cc , in_buf , in_len , out_buf ,
118- (unsigned int * )out_len );
119- if (compr -> comp_mutex )
120- mutex_unlock (compr -> comp_mutex );
121- if (unlikely (err )) {
122- ubifs_warn (c , "cannot compress %d bytes, compressor %s, error %d, leave data uncompressed" ,
123- in_len , compr -> name , err );
124- goto no_compr ;
126+ {
127+ ACOMP_REQUEST_ALLOC (req , compr -> cc , GFP_NOFS | __GFP_NOWARN );
128+
129+ acomp_request_set_src_nondma (req , in_buf , in_len );
130+ err = ubifs_compress_req (c , req , out_buf , out_len , compr -> name );
125131 }
126132
127- /*
128- * If the data compressed only slightly, it is better to leave it
129- * uncompressed to improve read speed.
130- */
131- if (in_len - * out_len < UBIFS_MIN_COMPRESS_DIFF )
133+ if (err )
132134 goto no_compr ;
133135
134136 return ;
@@ -139,6 +141,31 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,
139141 * compr_type = UBIFS_COMPR_NONE ;
140142}
141143
144+ static int ubifs_decompress_req (const struct ubifs_info * c ,
145+ struct acomp_req * req ,
146+ const void * in_buf , int in_len , int * out_len ,
147+ const char * compr_name )
148+ {
149+ struct crypto_wait wait ;
150+ int err ;
151+
152+ crypto_init_wait (& wait );
153+ acomp_request_set_callback (req , CRYPTO_TFM_REQ_MAY_BACKLOG ,
154+ crypto_req_done , & wait );
155+ acomp_request_set_src_dma (req , in_buf , in_len );
156+ err = crypto_acomp_decompress (req );
157+ err = crypto_wait_req (err , & wait );
158+ * out_len = req -> dlen ;
159+
160+ if (err )
161+ ubifs_err (c , "cannot decompress %d bytes, compressor %s, error %d" ,
162+ in_len , compr_name , err );
163+
164+ acomp_request_free (req );
165+
166+ return err ;
167+ }
168+
142169/**
143170 * ubifs_decompress - decompress data.
144171 * @c: UBIFS file-system description object
@@ -155,7 +182,6 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,
155182int ubifs_decompress (const struct ubifs_info * c , const void * in_buf ,
156183 int in_len , void * out_buf , int * out_len , int compr_type )
157184{
158- int err ;
159185 struct ubifs_compressor * compr ;
160186
161187 if (unlikely (compr_type < 0 || compr_type >= UBIFS_COMPR_TYPES_CNT )) {
@@ -176,17 +202,13 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
176202 return 0 ;
177203 }
178204
179- if (compr -> decomp_mutex )
180- mutex_lock (compr -> decomp_mutex );
181- err = crypto_comp_decompress (compr -> cc , in_buf , in_len , out_buf ,
182- (unsigned int * )out_len );
183- if (compr -> decomp_mutex )
184- mutex_unlock (compr -> decomp_mutex );
185- if (err )
186- ubifs_err (c , "cannot decompress %d bytes, compressor %s, error %d" ,
187- in_len , compr -> name , err );
205+ {
206+ ACOMP_REQUEST_ALLOC (req , compr -> cc , GFP_NOFS | __GFP_NOWARN );
188207
189- return err ;
208+ acomp_request_set_dst_nondma (req , out_buf , * out_len );
209+ return ubifs_decompress_req (c , req , in_buf , in_len , out_len ,
210+ compr -> name );
211+ }
190212}
191213
192214/**
@@ -199,7 +221,7 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
199221static int __init compr_init (struct ubifs_compressor * compr )
200222{
201223 if (compr -> capi_name ) {
202- compr -> cc = crypto_alloc_comp (compr -> capi_name , 0 , 0 );
224+ compr -> cc = crypto_alloc_acomp (compr -> capi_name , 0 , 0 );
203225 if (IS_ERR (compr -> cc )) {
204226 pr_err ("UBIFS error (pid %d): cannot initialize compressor %s, error %ld" ,
205227 current -> pid , compr -> name , PTR_ERR (compr -> cc ));
@@ -218,7 +240,7 @@ static int __init compr_init(struct ubifs_compressor *compr)
218240static void compr_exit (struct ubifs_compressor * compr )
219241{
220242 if (compr -> capi_name )
221- crypto_free_comp (compr -> cc );
243+ crypto_free_acomp (compr -> cc );
222244}
223245
224246/**
0 commit comments