@@ -427,22 +427,25 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
427
427
struct gfs2_alloc_parms ap = { .aflags = 0 , };
428
428
u64 offset = page_offset (page );
429
429
unsigned int data_blocks , ind_blocks , rblocks ;
430
+ vm_fault_t ret = VM_FAULT_LOCKED ;
430
431
struct gfs2_holder gh ;
431
432
unsigned int length ;
432
433
loff_t size ;
433
- int ret ;
434
+ int err ;
434
435
435
436
sb_start_pagefault (inode -> i_sb );
436
437
437
438
gfs2_holder_init (ip -> i_gl , LM_ST_EXCLUSIVE , 0 , & gh );
438
- ret = gfs2_glock_nq (& gh );
439
- if (ret )
439
+ err = gfs2_glock_nq (& gh );
440
+ if (err ) {
441
+ ret = block_page_mkwrite_return (err );
440
442
goto out_uninit ;
443
+ }
441
444
442
445
/* Check page index against inode size */
443
446
size = i_size_read (inode );
444
447
if (offset >= size ) {
445
- ret = - EINVAL ;
448
+ ret = VM_FAULT_SIGBUS ;
446
449
goto out_unlock ;
447
450
}
448
451
@@ -469,24 +472,30 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
469
472
!gfs2_write_alloc_required (ip , offset , length )) {
470
473
lock_page (page );
471
474
if (!PageUptodate (page ) || page -> mapping != inode -> i_mapping ) {
472
- ret = - EAGAIN ;
475
+ ret = VM_FAULT_NOPAGE ;
473
476
unlock_page (page );
474
477
}
475
478
goto out_unlock ;
476
479
}
477
480
478
- ret = gfs2_rindex_update (sdp );
479
- if (ret )
481
+ err = gfs2_rindex_update (sdp );
482
+ if (err ) {
483
+ ret = block_page_mkwrite_return (err );
480
484
goto out_unlock ;
485
+ }
481
486
482
487
gfs2_write_calc_reserv (ip , length , & data_blocks , & ind_blocks );
483
488
ap .target = data_blocks + ind_blocks ;
484
- ret = gfs2_quota_lock_check (ip , & ap );
485
- if (ret )
489
+ err = gfs2_quota_lock_check (ip , & ap );
490
+ if (err ) {
491
+ ret = block_page_mkwrite_return (err );
486
492
goto out_unlock ;
487
- ret = gfs2_inplace_reserve (ip , & ap );
488
- if (ret )
493
+ }
494
+ err = gfs2_inplace_reserve (ip , & ap );
495
+ if (err ) {
496
+ ret = block_page_mkwrite_return (err );
489
497
goto out_quota_unlock ;
498
+ }
490
499
491
500
rblocks = RES_DINODE + ind_blocks ;
492
501
if (gfs2_is_jdata (ip ))
@@ -495,27 +504,35 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
495
504
rblocks += RES_STATFS + RES_QUOTA ;
496
505
rblocks += gfs2_rg_blocks (ip , data_blocks + ind_blocks );
497
506
}
498
- ret = gfs2_trans_begin (sdp , rblocks , 0 );
499
- if (ret )
507
+ err = gfs2_trans_begin (sdp , rblocks , 0 );
508
+ if (err ) {
509
+ ret = block_page_mkwrite_return (err );
500
510
goto out_trans_fail ;
511
+ }
501
512
502
513
lock_page (page );
503
- ret = - EAGAIN ;
504
514
/* If truncated, we must retry the operation, we may have raced
505
515
* with the glock demotion code.
506
516
*/
507
- if (!PageUptodate (page ) || page -> mapping != inode -> i_mapping )
517
+ if (!PageUptodate (page ) || page -> mapping != inode -> i_mapping ) {
518
+ ret = VM_FAULT_NOPAGE ;
508
519
goto out_trans_end ;
520
+ }
509
521
510
522
/* Unstuff, if required, and allocate backing blocks for page */
511
- ret = 0 ;
512
- if (gfs2_is_stuffed (ip ))
513
- ret = gfs2_unstuff_dinode (ip , page );
514
- if (ret == 0 )
515
- ret = gfs2_allocate_page_backing (page , length );
523
+ if (gfs2_is_stuffed (ip )) {
524
+ err = gfs2_unstuff_dinode (ip , page );
525
+ if (err ) {
526
+ ret = block_page_mkwrite_return (err );
527
+ goto out_trans_end ;
528
+ }
529
+ }
530
+ err = gfs2_allocate_page_backing (page , length );
531
+ if (err )
532
+ ret = block_page_mkwrite_return (err );
516
533
517
534
out_trans_end :
518
- if (ret )
535
+ if (ret != VM_FAULT_LOCKED )
519
536
unlock_page (page );
520
537
gfs2_trans_end (sdp );
521
538
out_trans_fail :
@@ -526,12 +543,12 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
526
543
gfs2_glock_dq (& gh );
527
544
out_uninit :
528
545
gfs2_holder_uninit (& gh );
529
- if (ret == 0 ) {
546
+ if (ret == VM_FAULT_LOCKED ) {
530
547
set_page_dirty (page );
531
548
wait_for_stable_page (page );
532
549
}
533
550
sb_end_pagefault (inode -> i_sb );
534
- return block_page_mkwrite_return ( ret ) ;
551
+ return ret ;
535
552
}
536
553
537
554
static vm_fault_t gfs2_fault (struct vm_fault * vmf )
0 commit comments