Skip to content

Commit

Permalink
btrfs: add comments for btrfs_check_can_nocow() and can_nocow_extent()
Browse files Browse the repository at this point in the history
These two functions have extra conditions that their callers need to
meet, and some not-that-common parameters used for return value.

So adding some comments may save reviewers some time.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Qu Wenruo authored and David Sterba committed Jul 27, 2020
1 parent 6d4572a commit e4ecaf9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 21 additions & 0 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,27 @@ lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages,
return ret;
}

/*
* Check if we can do nocow write into the range [@pos, @pos + @write_bytes)
*
* @pos: File offset
* @write_bytes: The length to write, will be updated to the nocow writeable
* range
* @nowait: Whether this function could sleep
*
* This function will flush ordered extents in the range to ensure proper
* nocow checks for (nowait == false) case.
*
* Return:
* >0 and update @write_bytes if we can do nocow write
* 0 if we can't do nocow write
* -EAGAIN if we can't get the needed lock or there are ordered extents
* for * (nowait == true) case
* <0 if other error happened
*
* NOTE: For wait (nowait == false) calls, callers need to release the drew
* write lock of inode->root->snapshot_lock when return value > 0.
*/
int btrfs_check_can_nocow(struct btrfs_inode *inode, loff_t pos,
size_t *write_bytes, bool nowait)
{
Expand Down
21 changes: 19 additions & 2 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -6945,8 +6945,25 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode,
}

/*
* returns 1 when the nocow is safe, < 1 on error, 0 if the
* block must be cow'd
* Check if we can do nocow write into the range [@offset, @offset + @len)
*
* @offset: File offset
* @len: The length to write, will be updated to the nocow writeable
* range
* @orig_start: (optional) Return the original file offset of the file extent
* @orig_len: (optional) Return the original on-disk length of the file extent
* @ram_bytes: (optional) Return the ram_bytes of the file extent
*
* This function will flush ordered extents in the range to ensure proper
* nocow checks for (nowait == false) case.
*
* Return:
* >0 and update @len if we can do nocow write
* 0 if we can't do nocow write
* <0 if error happened
*
* NOTE: This only checks the file extents, caller is responsible to wait for
* any ordered extents.
*/
noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
u64 *orig_start, u64 *orig_block_len,
Expand Down

0 comments on commit e4ecaf9

Please sign in to comment.