@@ -190,13 +190,20 @@ static bool ext2_check_page(struct page *page, int quiet)
190
190
return false;
191
191
}
192
192
193
+ /*
194
+ * Calls to ext2_get_page()/ext2_put_page() must be nested according to the
195
+ * rules documented in kmap_local_page()/kunmap_local().
196
+ *
197
+ * NOTE: ext2_find_entry() and ext2_dotdot() act as a call to ext2_get_page()
198
+ * and should be treated as a call to ext2_get_page() for nesting purposes.
199
+ */
193
200
static struct page * ext2_get_page (struct inode * dir , unsigned long n ,
194
- int quiet )
201
+ int quiet , void * * page_addr )
195
202
{
196
203
struct address_space * mapping = dir -> i_mapping ;
197
204
struct page * page = read_mapping_page (mapping , n , NULL );
198
205
if (!IS_ERR (page )) {
199
- kmap (page );
206
+ * page_addr = kmap_local_page (page );
200
207
if (unlikely (!PageChecked (page ))) {
201
208
if (PageError (page ) || !ext2_check_page (page , quiet ))
202
209
goto fail ;
@@ -205,7 +212,7 @@ static struct page * ext2_get_page(struct inode *dir, unsigned long n,
205
212
return page ;
206
213
207
214
fail :
208
- ext2_put_page (page );
215
+ ext2_put_page (page , * page_addr );
209
216
return ERR_PTR (- EIO );
210
217
}
211
218
@@ -276,7 +283,7 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
276
283
for ( ; n < npages ; n ++ , offset = 0 ) {
277
284
char * kaddr , * limit ;
278
285
ext2_dirent * de ;
279
- struct page * page = ext2_get_page (inode , n , 0 );
286
+ struct page * page = ext2_get_page (inode , n , 0 , ( void * * ) & kaddr );
280
287
281
288
if (IS_ERR (page )) {
282
289
ext2_error (sb , __func__ ,
@@ -285,7 +292,6 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
285
292
ctx -> pos += PAGE_SIZE - offset ;
286
293
return PTR_ERR (page );
287
294
}
288
- kaddr = page_address (page );
289
295
if (unlikely (need_revalidate )) {
290
296
if (offset ) {
291
297
offset = ext2_validate_entry (kaddr , offset , chunk_mask );
@@ -300,7 +306,7 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
300
306
if (de -> rec_len == 0 ) {
301
307
ext2_error (sb , __func__ ,
302
308
"zero-length directory entry" );
303
- ext2_put_page (page );
309
+ ext2_put_page (page , kaddr );
304
310
return - EIO ;
305
311
}
306
312
if (de -> inode ) {
@@ -312,13 +318,13 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
312
318
if (!dir_emit (ctx , de -> name , de -> name_len ,
313
319
le32_to_cpu (de -> inode ),
314
320
d_type )) {
315
- ext2_put_page (page );
321
+ ext2_put_page (page , kaddr );
316
322
return 0 ;
317
323
}
318
324
}
319
325
ctx -> pos += ext2_rec_len_from_disk (de -> rec_len );
320
326
}
321
- ext2_put_page (page );
327
+ ext2_put_page (page , kaddr );
322
328
}
323
329
return 0 ;
324
330
}
@@ -332,9 +338,16 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
332
338
* Entry is guaranteed to be valid.
333
339
*
334
340
* On Success ext2_put_page() should be called on *res_page.
341
+ *
342
+ * NOTE: Calls to ext2_get_page()/ext2_put_page() must be nested according to
343
+ * the rules documented in kmap_local_page()/kunmap_local().
344
+ *
345
+ * ext2_find_entry() and ext2_dotdot() act as a call to ext2_get_page() and
346
+ * should be treated as a call to ext2_get_page() for nesting purposes.
335
347
*/
336
348
struct ext2_dir_entry_2 * ext2_find_entry (struct inode * dir ,
337
- const struct qstr * child , struct page * * res_page )
349
+ const struct qstr * child , struct page * * res_page ,
350
+ void * * res_page_addr )
338
351
{
339
352
const char * name = child -> name ;
340
353
int namelen = child -> len ;
@@ -344,38 +357,40 @@ struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
344
357
struct page * page = NULL ;
345
358
struct ext2_inode_info * ei = EXT2_I (dir );
346
359
ext2_dirent * de ;
360
+ void * page_addr ;
347
361
348
362
if (npages == 0 )
349
363
goto out ;
350
364
351
365
/* OFFSET_CACHE */
352
366
* res_page = NULL ;
367
+ * res_page_addr = NULL ;
353
368
354
369
start = ei -> i_dir_start_lookup ;
355
370
if (start >= npages )
356
371
start = 0 ;
357
372
n = start ;
358
373
do {
359
374
char * kaddr ;
360
- page = ext2_get_page (dir , n , 0 );
375
+ page = ext2_get_page (dir , n , 0 , & page_addr );
361
376
if (IS_ERR (page ))
362
377
return ERR_CAST (page );
363
378
364
- kaddr = page_address ( page ) ;
379
+ kaddr = page_addr ;
365
380
de = (ext2_dirent * ) kaddr ;
366
381
kaddr += ext2_last_byte (dir , n ) - reclen ;
367
382
while ((char * ) de <= kaddr ) {
368
383
if (de -> rec_len == 0 ) {
369
384
ext2_error (dir -> i_sb , __func__ ,
370
385
"zero-length directory entry" );
371
- ext2_put_page (page );
386
+ ext2_put_page (page , page_addr );
372
387
goto out ;
373
388
}
374
389
if (ext2_match (namelen , name , de ))
375
390
goto found ;
376
391
de = ext2_next_entry (de );
377
392
}
378
- ext2_put_page (page );
393
+ ext2_put_page (page , page_addr );
379
394
380
395
if (++ n >= npages )
381
396
n = 0 ;
@@ -393,6 +408,7 @@ struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
393
408
394
409
found :
395
410
* res_page = page ;
411
+ * res_page_addr = page_addr ;
396
412
ei -> i_dir_start_lookup = n ;
397
413
return de ;
398
414
}
@@ -402,15 +418,24 @@ struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
402
418
* (as a parameter - p).
403
419
*
404
420
* On Success ext2_put_page() should be called on *p.
421
+ *
422
+ * NOTE: Calls to ext2_get_page()/ext2_put_page() must be nested according to
423
+ * the rules documented in kmap_local_page()/kunmap_local().
424
+ *
425
+ * ext2_find_entry() and ext2_dotdot() act as a call to ext2_get_page() and
426
+ * should be treated as a call to ext2_get_page() for nesting purposes.
405
427
*/
406
- struct ext2_dir_entry_2 * ext2_dotdot (struct inode * dir , struct page * * p )
428
+ struct ext2_dir_entry_2 * ext2_dotdot (struct inode * dir , struct page * * p ,
429
+ void * * pa )
407
430
{
408
- struct page * page = ext2_get_page (dir , 0 , 0 );
431
+ void * page_addr ;
432
+ struct page * page = ext2_get_page (dir , 0 , 0 , & page_addr );
409
433
ext2_dirent * de = NULL ;
410
434
411
435
if (!IS_ERR (page )) {
412
- de = ext2_next_entry ((ext2_dirent * ) page_address ( page ) );
436
+ de = ext2_next_entry ((ext2_dirent * ) page_addr );
413
437
* p = page ;
438
+ * pa = page_addr ;
414
439
}
415
440
return de ;
416
441
}
@@ -419,13 +444,14 @@ int ext2_inode_by_name(struct inode *dir, const struct qstr *child, ino_t *ino)
419
444
{
420
445
struct ext2_dir_entry_2 * de ;
421
446
struct page * page ;
447
+ void * page_addr ;
422
448
423
- de = ext2_find_entry (dir , child , & page );
449
+ de = ext2_find_entry (dir , child , & page , & page_addr );
424
450
if (IS_ERR (de ))
425
451
return PTR_ERR (de );
426
452
427
453
* ino = le32_to_cpu (de -> inode );
428
- ext2_put_page (page );
454
+ ext2_put_page (page , page_addr );
429
455
return 0 ;
430
456
}
431
457
@@ -435,10 +461,11 @@ static int ext2_prepare_chunk(struct page *page, loff_t pos, unsigned len)
435
461
}
436
462
437
463
void ext2_set_link (struct inode * dir , struct ext2_dir_entry_2 * de ,
438
- struct page * page , struct inode * inode , int update_times )
464
+ struct page * page , void * page_addr , struct inode * inode ,
465
+ int update_times )
439
466
{
440
467
loff_t pos = page_offset (page ) +
441
- (char * ) de - (char * ) page_address ( page ) ;
468
+ (char * ) de - (char * ) page_addr ;
442
469
unsigned len = ext2_rec_len_from_disk (de -> rec_len );
443
470
int err ;
444
471
@@ -466,10 +493,10 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
466
493
unsigned reclen = EXT2_DIR_REC_LEN (namelen );
467
494
unsigned short rec_len , name_len ;
468
495
struct page * page = NULL ;
496
+ void * page_addr = NULL ;
469
497
ext2_dirent * de ;
470
498
unsigned long npages = dir_pages (dir );
471
499
unsigned long n ;
472
- char * kaddr ;
473
500
loff_t pos ;
474
501
int err ;
475
502
@@ -479,14 +506,15 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
479
506
* to protect that region.
480
507
*/
481
508
for (n = 0 ; n <= npages ; n ++ ) {
509
+ char * kaddr ;
482
510
char * dir_end ;
483
511
484
- page = ext2_get_page (dir , n , 0 );
512
+ page = ext2_get_page (dir , n , 0 , & page_addr );
485
513
err = PTR_ERR (page );
486
514
if (IS_ERR (page ))
487
515
goto out ;
488
516
lock_page (page );
489
- kaddr = page_address ( page ) ;
517
+ kaddr = page_addr ;
490
518
dir_end = kaddr + ext2_last_byte (dir , n );
491
519
de = (ext2_dirent * )kaddr ;
492
520
kaddr += PAGE_SIZE - reclen ;
@@ -517,14 +545,14 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
517
545
de = (ext2_dirent * ) ((char * ) de + rec_len );
518
546
}
519
547
unlock_page (page );
520
- ext2_put_page (page );
548
+ ext2_put_page (page , page_addr );
521
549
}
522
550
BUG ();
523
551
return - EINVAL ;
524
552
525
553
got_it :
526
554
pos = page_offset (page ) +
527
- (char * )de - (char * ) page_address ( page ) ;
555
+ (char * )de - (char * ) page_addr ;
528
556
err = ext2_prepare_chunk (page , pos , rec_len );
529
557
if (err )
530
558
goto out_unlock ;
@@ -544,7 +572,7 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
544
572
mark_inode_dirty (dir );
545
573
/* OFFSET_CACHE */
546
574
out_put :
547
- ext2_put_page (page );
575
+ ext2_put_page (page , page_addr );
548
576
out :
549
577
return err ;
550
578
out_unlock :
@@ -641,21 +669,22 @@ int ext2_make_empty(struct inode *inode, struct inode *parent)
641
669
*/
642
670
int ext2_empty_dir (struct inode * inode )
643
671
{
672
+ void * page_addr = NULL ;
644
673
struct page * page = NULL ;
645
674
unsigned long i , npages = dir_pages (inode );
646
675
int dir_has_error = 0 ;
647
676
648
677
for (i = 0 ; i < npages ; i ++ ) {
649
678
char * kaddr ;
650
679
ext2_dirent * de ;
651
- page = ext2_get_page (inode , i , dir_has_error );
680
+ page = ext2_get_page (inode , i , dir_has_error , & page_addr );
652
681
653
682
if (IS_ERR (page )) {
654
683
dir_has_error = 1 ;
655
684
continue ;
656
685
}
657
686
658
- kaddr = page_address ( page ) ;
687
+ kaddr = page_addr ;
659
688
de = (ext2_dirent * )kaddr ;
660
689
kaddr += ext2_last_byte (inode , i ) - EXT2_DIR_REC_LEN (1 );
661
690
@@ -681,12 +710,12 @@ int ext2_empty_dir (struct inode * inode)
681
710
}
682
711
de = ext2_next_entry (de );
683
712
}
684
- ext2_put_page (page );
713
+ ext2_put_page (page , page_addr );
685
714
}
686
715
return 1 ;
687
716
688
717
not_empty :
689
- ext2_put_page (page );
718
+ ext2_put_page (page , page_addr );
690
719
return 0 ;
691
720
}
692
721
0 commit comments