Skip to content

Commit a08625f

Browse files
fdmananakdave
authored andcommitted
btrfs: simplify early error checking in btrfs_page_mkwrite()
We have this entangled error checks early at btrfs_page_mkwrite(): 1) Try to reserve delalloc space by calling btrfs_delalloc_reserve_space() and storing the return value in the ret2 variable; 2) If the reservation succeed, call file_update_time() and store the return value in ret2 and also set the local variable 'reserved' to true (1); 3) Then do an error check on ret2 to see if any of the previous calls failed and if so, jump either to the 'out' label or to the 'out_noreserve' label, depending on whether 'reserved' is true or not. This is unnecessarily complex. Instead change this to a simpler and more straightforward approach: 1) Call btrfs_delalloc_reserve_space(), if that returns an error jump to the 'out_noreserve' label; 2) The call file_update_time() and if that returns an error jump to the 'out' label. Like this there's less nested if statements, no need to use a local variable to track if space was reserved and if statements are used only to check errors. Also move the call to extent_changeset_free() out of the 'out_noreserve' label and under the 'out' label since the changeset is allocated only if the call to reserve delalloc space succeeded. Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent bf1c74c commit a08625f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

fs/btrfs/file.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,6 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
18431843
size_t fsize = folio_size(folio);
18441844
vm_fault_t ret;
18451845
int ret2;
1846-
int reserved = 0;
18471846
u64 reserved_space;
18481847
u64 page_start;
18491848
u64 page_end;
@@ -1866,17 +1865,17 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
18661865
*/
18671866
ret2 = btrfs_delalloc_reserve_space(BTRFS_I(inode), &data_reserved,
18681867
page_start, reserved_space);
1869-
if (!ret2) {
1870-
ret2 = file_update_time(vmf->vma->vm_file);
1871-
reserved = 1;
1872-
}
18731868
if (ret2) {
18741869
ret = vmf_error(ret2);
1875-
if (reserved)
1876-
goto out;
18771870
goto out_noreserve;
18781871
}
18791872

1873+
ret2 = file_update_time(vmf->vma->vm_file);
1874+
if (ret2) {
1875+
ret = vmf_error(ret2);
1876+
goto out;
1877+
}
1878+
18801879
/* Make the VM retry the fault. */
18811880
ret = VM_FAULT_NOPAGE;
18821881
again:
@@ -1972,9 +1971,9 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
19721971
btrfs_delalloc_release_extents(BTRFS_I(inode), fsize);
19731972
btrfs_delalloc_release_space(BTRFS_I(inode), data_reserved, page_start,
19741973
reserved_space, true);
1974+
extent_changeset_free(data_reserved);
19751975
out_noreserve:
19761976
sb_end_pagefault(inode->i_sb);
1977-
extent_changeset_free(data_reserved);
19781977
return ret;
19791978
}
19801979

0 commit comments

Comments
 (0)