From: Qu Wenruo <wqu@suse.com>
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 5/5] btrfs: use a single variable to track return value at btrfs_page_mkwrite()
Date: Thu, 15 May 2025 06:32:17 +0930 [thread overview]
Message-ID: <2d54e2cc-b874-4aea-b848-be92ed5a968d@suse.com> (raw)
In-Reply-To: <b3a84d4894aebd5d3e7097fb7f07892fcf1b2316.1747222631.git.fdmanana@suse.com>
在 2025/5/14 21:08, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> We have two variables to track return values, ret and ret2, with types
> vm_fault_t (an unsigned int type) and int, which makes it a bit confusing
> and harder to keep track. So use a single variable, of type int, and under
> the 'out' label return vmf_error(ret) in case ret contains an error,
> otherwise return VM_FAULT_NOPAGE. This is equivalent to what we had before
> and it's simpler.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/file.c | 37 ++++++++++++++++---------------------
> 1 file changed, 16 insertions(+), 21 deletions(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index f6b32f24185c..8ce6f45f45e0 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -1841,8 +1841,7 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
> unsigned long zero_start;
> loff_t size;
> size_t fsize = folio_size(folio);
> - vm_fault_t ret;
> - int ret2;
> + int ret;
> u64 reserved_space;
> u64 page_start;
> u64 page_end;
> @@ -1863,21 +1862,14 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
> * end up waiting indefinitely to get a lock on the page currently
> * being processed by btrfs_page_mkwrite() function.
> */
> - ret2 = btrfs_delalloc_reserve_space(BTRFS_I(inode), &data_reserved,
> - page_start, reserved_space);
> - if (ret2) {
> - ret = vmf_error(ret2);
> + ret = btrfs_delalloc_reserve_space(BTRFS_I(inode), &data_reserved,
> + page_start, reserved_space);
> + if (ret < 0)
> goto out_noreserve;
> - }
>
> - ret2 = file_update_time(vmf->vma->vm_file);
> - if (ret2) {
> - ret = vmf_error(ret2);
> + ret = file_update_time(vmf->vma->vm_file);
> + if (ret < 0)
> goto out;
> - }
> -
> - /* Make the VM retry the fault. */
> - ret = VM_FAULT_NOPAGE;
> again:
> down_read(&BTRFS_I(inode)->i_mmap_lock);
> folio_lock(folio);
> @@ -1891,9 +1883,8 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
> folio_wait_writeback(folio);
>
> btrfs_lock_extent(io_tree, page_start, page_end, &cached_state);
> - ret2 = set_folio_extent_mapped(folio);
> - if (ret2 < 0) {
> - ret = vmf_error(ret2);
> + ret = set_folio_extent_mapped(folio);
> + if (ret < 0) {
> btrfs_unlock_extent(io_tree, page_start, page_end, &cached_state);
> goto out_unlock;
> }
> @@ -1933,11 +1924,10 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
> EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING |
> EXTENT_DEFRAG, &cached_state);
>
> - ret2 = btrfs_set_extent_delalloc(BTRFS_I(inode), page_start, end, 0,
> + ret = btrfs_set_extent_delalloc(BTRFS_I(inode), page_start, end, 0,
> &cached_state);
> - if (ret2) {
> + if (ret < 0) {
> btrfs_unlock_extent(io_tree, page_start, page_end, &cached_state);
> - ret = vmf_error(ret2);
> goto out_unlock;
> }
>
> @@ -1974,7 +1964,12 @@ static vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
> extent_changeset_free(data_reserved);
> out_noreserve:
> sb_end_pagefault(inode->i_sb);
> - return ret;
> +
> + if (ret < 0)
> + return vmf_error(ret);
> +
> + /* Make the VM retry the fault. */
> + return VM_FAULT_NOPAGE;
> }
>
> static const struct vm_operations_struct btrfs_file_vm_ops = {
next prev parent reply other threads:[~2025-05-14 21:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-14 10:29 [PATCH 0/3] btrfs: fix a bug and cleanups in btrfs_page_mkwrite() fdmanana
2025-05-14 10:29 ` [PATCH 1/3] btrfs: fix wrong start offset for delalloc space release during mmap write fdmanana
2025-05-14 10:38 ` Qu Wenruo
2025-05-14 10:41 ` Filipe Manana
2025-05-14 10:29 ` [PATCH 2/3] btrfs: pass true to btrfs_delalloc_release_space() at btrfs_page_mkwrite() fdmanana
2025-05-14 10:40 ` Qu Wenruo
2025-05-14 10:29 ` [PATCH 3/3] btrfs: simplify early error checking in btrfs_page_mkwrite() fdmanana
2025-05-14 10:50 ` Qu Wenruo
2025-05-14 10:57 ` Filipe Manana
2025-05-14 11:35 ` Filipe Manana
2025-05-14 11:38 ` [PATCH v2 0/5] btrfs: fix a bug and cleanups " fdmanana
2025-05-14 11:38 ` [PATCH v2 1/5] btrfs: fix wrong start offset for delalloc space release during mmap write fdmanana
2025-05-14 11:38 ` [PATCH v2 2/5] btrfs: pass true to btrfs_delalloc_release_space() at btrfs_page_mkwrite() fdmanana
2025-05-14 11:38 ` [PATCH v2 3/5] btrfs: simplify early error checking in btrfs_page_mkwrite() fdmanana
2025-05-14 21:01 ` Qu Wenruo
2025-05-14 11:38 ` [PATCH v2 4/5] btrfs: don't return VM_FAULT_SIGBUS on failure to set delalloc for mmap write fdmanana
2025-05-14 21:01 ` Qu Wenruo
2025-05-14 11:38 ` [PATCH v2 5/5] btrfs: use a single variable to track return value at btrfs_page_mkwrite() fdmanana
2025-05-14 21:02 ` Qu Wenruo [this message]
2025-05-15 13:19 ` [PATCH v2 0/5] btrfs: fix a bug and cleanups in btrfs_page_mkwrite() David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d54e2cc-b874-4aea-b848-be92ed5a968d@suse.com \
--to=wqu@suse.com \
--cc=fdmanana@kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox