@@ -141,7 +141,7 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
141
141
* total_in = 0 ;
142
142
143
143
in_page = find_get_page (mapping , start >> PAGE_SHIFT );
144
- data_in = page_address (in_page );
144
+ data_in = kmap (in_page );
145
145
146
146
/*
147
147
* store the size of all chunks of compressed data in
@@ -152,7 +152,7 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
152
152
ret = - ENOMEM ;
153
153
goto out ;
154
154
}
155
- cpage_out = page_address (out_page );
155
+ cpage_out = kmap (out_page );
156
156
out_offset = LZO_LEN ;
157
157
tot_out = LZO_LEN ;
158
158
pages [0 ] = out_page ;
@@ -210,6 +210,7 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
210
210
if (out_len == 0 && tot_in >= len )
211
211
break ;
212
212
213
+ kunmap (out_page );
213
214
if (nr_pages == nr_dest_pages ) {
214
215
out_page = NULL ;
215
216
ret = - E2BIG ;
@@ -221,7 +222,7 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
221
222
ret = - ENOMEM ;
222
223
goto out ;
223
224
}
224
- cpage_out = page_address (out_page );
225
+ cpage_out = kmap (out_page );
225
226
pages [nr_pages ++ ] = out_page ;
226
227
227
228
pg_bytes_left = PAGE_SIZE ;
@@ -243,11 +244,12 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
243
244
break ;
244
245
245
246
bytes_left = len - tot_in ;
247
+ kunmap (in_page );
246
248
put_page (in_page );
247
249
248
250
start += PAGE_SIZE ;
249
251
in_page = find_get_page (mapping , start >> PAGE_SHIFT );
250
- data_in = page_address (in_page );
252
+ data_in = kmap (in_page );
251
253
in_len = min (bytes_left , PAGE_SIZE );
252
254
}
253
255
@@ -257,17 +259,22 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
257
259
}
258
260
259
261
/* store the size of all chunks of compressed data */
260
- sizes_ptr = page_address (pages [0 ]);
262
+ sizes_ptr = kmap_local_page (pages [0 ]);
261
263
write_compress_length (sizes_ptr , tot_out );
264
+ kunmap_local (sizes_ptr );
262
265
263
266
ret = 0 ;
264
267
* total_out = tot_out ;
265
268
* total_in = tot_in ;
266
269
out :
267
270
* out_pages = nr_pages ;
271
+ if (out_page )
272
+ kunmap (out_page );
268
273
269
- if (in_page )
274
+ if (in_page ) {
275
+ kunmap (in_page );
270
276
put_page (in_page );
277
+ }
271
278
272
279
return ret ;
273
280
}
@@ -283,16 +290,19 @@ static void copy_compressed_segment(struct compressed_bio *cb,
283
290
u32 orig_in = * cur_in ;
284
291
285
292
while (* cur_in < orig_in + len ) {
293
+ char * kaddr ;
286
294
struct page * cur_page ;
287
295
u32 copy_len = min_t (u32 , PAGE_SIZE - offset_in_page (* cur_in ),
288
296
orig_in + len - * cur_in );
289
297
290
298
ASSERT (copy_len );
291
299
cur_page = cb -> compressed_pages [* cur_in / PAGE_SIZE ];
292
300
301
+ kaddr = kmap (cur_page );
293
302
memcpy (dest + * cur_in - orig_in ,
294
- page_address ( cur_page ) + offset_in_page (* cur_in ),
303
+ kaddr + offset_in_page (* cur_in ),
295
304
copy_len );
305
+ kunmap (cur_page );
296
306
297
307
* cur_in += copy_len ;
298
308
}
@@ -303,6 +313,7 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
303
313
struct workspace * workspace = list_entry (ws , struct workspace , list );
304
314
const struct btrfs_fs_info * fs_info = btrfs_sb (cb -> inode -> i_sb );
305
315
const u32 sectorsize = fs_info -> sectorsize ;
316
+ char * kaddr ;
306
317
int ret ;
307
318
/* Compressed data length, can be unaligned */
308
319
u32 len_in ;
@@ -311,7 +322,9 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
311
322
/* Bytes decompressed so far */
312
323
u32 cur_out = 0 ;
313
324
314
- len_in = read_compress_length (page_address (cb -> compressed_pages [0 ]));
325
+ kaddr = kmap (cb -> compressed_pages [0 ]);
326
+ len_in = read_compress_length (kaddr );
327
+ kunmap (cb -> compressed_pages [0 ]);
315
328
cur_in += LZO_LEN ;
316
329
317
330
/*
@@ -344,9 +357,9 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
344
357
ASSERT (cur_in / sectorsize ==
345
358
(cur_in + LZO_LEN - 1 ) / sectorsize );
346
359
cur_page = cb -> compressed_pages [cur_in / PAGE_SIZE ];
360
+ kaddr = kmap (cur_page );
347
361
ASSERT (cur_page );
348
- seg_len = read_compress_length (page_address (cur_page ) +
349
- offset_in_page (cur_in ));
362
+ seg_len = read_compress_length (kaddr + offset_in_page (cur_in ));
350
363
cur_in += LZO_LEN ;
351
364
352
365
/* Copy the compressed segment payload into workspace */
@@ -431,7 +444,7 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,
431
444
destlen = min_t (unsigned long , destlen , PAGE_SIZE );
432
445
bytes = min_t (unsigned long , destlen , out_len - start_byte );
433
446
434
- kaddr = page_address (dest_page );
447
+ kaddr = kmap_local_page (dest_page );
435
448
memcpy (kaddr , workspace -> buf + start_byte , bytes );
436
449
437
450
/*
@@ -441,6 +454,7 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,
441
454
*/
442
455
if (bytes < destlen )
443
456
memset (kaddr + bytes , 0 , destlen - bytes );
457
+ kunmap_local (kaddr );
444
458
out :
445
459
return ret ;
446
460
}
0 commit comments