15
15
* decompression.
16
16
*/
17
17
18
- #include <linux/ crypto.h>
18
+ #include <crypto/acompress .h>
19
19
#include "ubifs.h"
20
20
21
21
/* Fake description object for the "none" compressor */
@@ -26,11 +26,8 @@ static struct ubifs_compressor none_compr = {
26
26
};
27
27
28
28
#ifdef CONFIG_UBIFS_FS_LZO
29
- static DEFINE_MUTEX (lzo_mutex );
30
-
31
29
static struct ubifs_compressor lzo_compr = {
32
30
.compr_type = UBIFS_COMPR_LZO ,
33
- .comp_mutex = & lzo_mutex ,
34
31
.name = "lzo" ,
35
32
.capi_name = "lzo" ,
36
33
};
@@ -42,13 +39,8 @@ static struct ubifs_compressor lzo_compr = {
42
39
#endif
43
40
44
41
#ifdef CONFIG_UBIFS_FS_ZLIB
45
- static DEFINE_MUTEX (deflate_mutex );
46
- static DEFINE_MUTEX (inflate_mutex );
47
-
48
42
static struct ubifs_compressor zlib_compr = {
49
43
.compr_type = UBIFS_COMPR_ZLIB ,
50
- .comp_mutex = & deflate_mutex ,
51
- .decomp_mutex = & inflate_mutex ,
52
44
.name = "zlib" ,
53
45
.capi_name = "deflate" ,
54
46
};
@@ -60,13 +52,8 @@ static struct ubifs_compressor zlib_compr = {
60
52
#endif
61
53
62
54
#ifdef CONFIG_UBIFS_FS_ZSTD
63
- static DEFINE_MUTEX (zstd_enc_mutex );
64
- static DEFINE_MUTEX (zstd_dec_mutex );
65
-
66
55
static struct ubifs_compressor zstd_compr = {
67
56
.compr_type = UBIFS_COMPR_ZSTD ,
68
- .comp_mutex = & zstd_enc_mutex ,
69
- .decomp_mutex = & zstd_dec_mutex ,
70
57
.name = "zstd" ,
71
58
.capi_name = "zstd" ,
72
59
};
@@ -80,6 +67,30 @@ static struct ubifs_compressor zstd_compr = {
80
67
/* All UBIFS compressors */
81
68
struct ubifs_compressor * ubifs_compressors [UBIFS_COMPR_TYPES_CNT ];
82
69
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
+
83
94
/**
84
95
* ubifs_compress - compress data.
85
96
* @c: UBIFS file-system description object
@@ -112,23 +123,14 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,
112
123
if (in_len < UBIFS_MIN_COMPR_LEN )
113
124
goto no_compr ;
114
125
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 );
125
131
}
126
132
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 )
132
134
goto no_compr ;
133
135
134
136
return ;
@@ -139,6 +141,31 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,
139
141
* compr_type = UBIFS_COMPR_NONE ;
140
142
}
141
143
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
+
142
169
/**
143
170
* ubifs_decompress - decompress data.
144
171
* @c: UBIFS file-system description object
@@ -155,7 +182,6 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,
155
182
int ubifs_decompress (const struct ubifs_info * c , const void * in_buf ,
156
183
int in_len , void * out_buf , int * out_len , int compr_type )
157
184
{
158
- int err ;
159
185
struct ubifs_compressor * compr ;
160
186
161
187
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,
176
202
return 0 ;
177
203
}
178
204
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 );
188
207
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
+ }
190
212
}
191
213
192
214
/**
@@ -199,7 +221,7 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
199
221
static int __init compr_init (struct ubifs_compressor * compr )
200
222
{
201
223
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 );
203
225
if (IS_ERR (compr -> cc )) {
204
226
pr_err ("UBIFS error (pid %d): cannot initialize compressor %s, error %ld" ,
205
227
current -> pid , compr -> name , PTR_ERR (compr -> cc ));
@@ -218,7 +240,7 @@ static int __init compr_init(struct ubifs_compressor *compr)
218
240
static void compr_exit (struct ubifs_compressor * compr )
219
241
{
220
242
if (compr -> capi_name )
221
- crypto_free_comp (compr -> cc );
243
+ crypto_free_acomp (compr -> cc );
222
244
}
223
245
224
246
/**
0 commit comments