Skip to content

Commit 0fc3bcd

Browse files
author
Andreas Gruenbacher
committed
gfs2: Clean up the error handling in gfs2_page_mkwrite
We're setting an error number so that block_page_mkwrite_return translates it into the corresponding VM_FAULT_* code in several places, but this is getting confusing, so set the VM_FAULT_* codes directly instead. (No change in functionality.) Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 5d49d35 commit 0fc3bcd

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

fs/gfs2/file.c

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -427,22 +427,25 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
427427
struct gfs2_alloc_parms ap = { .aflags = 0, };
428428
u64 offset = page_offset(page);
429429
unsigned int data_blocks, ind_blocks, rblocks;
430+
vm_fault_t ret = VM_FAULT_LOCKED;
430431
struct gfs2_holder gh;
431432
unsigned int length;
432433
loff_t size;
433-
int ret;
434+
int err;
434435

435436
sb_start_pagefault(inode->i_sb);
436437

437438
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);
440442
goto out_uninit;
443+
}
441444

442445
/* Check page index against inode size */
443446
size = i_size_read(inode);
444447
if (offset >= size) {
445-
ret = -EINVAL;
448+
ret = VM_FAULT_SIGBUS;
446449
goto out_unlock;
447450
}
448451

@@ -469,24 +472,30 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
469472
!gfs2_write_alloc_required(ip, offset, length)) {
470473
lock_page(page);
471474
if (!PageUptodate(page) || page->mapping != inode->i_mapping) {
472-
ret = -EAGAIN;
475+
ret = VM_FAULT_NOPAGE;
473476
unlock_page(page);
474477
}
475478
goto out_unlock;
476479
}
477480

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);
480484
goto out_unlock;
485+
}
481486

482487
gfs2_write_calc_reserv(ip, length, &data_blocks, &ind_blocks);
483488
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);
486492
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);
489497
goto out_quota_unlock;
498+
}
490499

491500
rblocks = RES_DINODE + ind_blocks;
492501
if (gfs2_is_jdata(ip))
@@ -495,27 +504,35 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
495504
rblocks += RES_STATFS + RES_QUOTA;
496505
rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks);
497506
}
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);
500510
goto out_trans_fail;
511+
}
501512

502513
lock_page(page);
503-
ret = -EAGAIN;
504514
/* If truncated, we must retry the operation, we may have raced
505515
* with the glock demotion code.
506516
*/
507-
if (!PageUptodate(page) || page->mapping != inode->i_mapping)
517+
if (!PageUptodate(page) || page->mapping != inode->i_mapping) {
518+
ret = VM_FAULT_NOPAGE;
508519
goto out_trans_end;
520+
}
509521

510522
/* 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);
516533

517534
out_trans_end:
518-
if (ret)
535+
if (ret != VM_FAULT_LOCKED)
519536
unlock_page(page);
520537
gfs2_trans_end(sdp);
521538
out_trans_fail:
@@ -526,12 +543,12 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
526543
gfs2_glock_dq(&gh);
527544
out_uninit:
528545
gfs2_holder_uninit(&gh);
529-
if (ret == 0) {
546+
if (ret == VM_FAULT_LOCKED) {
530547
set_page_dirty(page);
531548
wait_for_stable_page(page);
532549
}
533550
sb_end_pagefault(inode->i_sb);
534-
return block_page_mkwrite_return(ret);
551+
return ret;
535552
}
536553

537554
static vm_fault_t gfs2_fault(struct vm_fault *vmf)

0 commit comments

Comments
 (0)