Message ID | 20201118085319.56668-2-wqu@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: add read-only support for subpage sector size | expand |
On 18/11/2020 09:55, Qu Wenruo wrote: > In alloc_extent_buffer(), after we got a page from btree inode, we check > if that page has private pointer attached. > > If attached, we check if the existing extent buffer has a proper refs. > If not (the eb is being freed), we will detach that private eb pointer. > > The point here is, we are detaching that eb pointer by calling: > - ClearPagePrivate() > - put_page() > > The put_page() here is especially confusing, as it's decreaing the ref > caused by attach_page_private(). > Without knowing that, it looks like the put_page() is for the > find_or_create_page() call, confusing the read. > > Since we're always modifing page private with attach_page_private() and > detach_page_private(), the only open-coded detach_page_private() here is > really confusing. > > Fix it by calling detach_page_private(). > > Signed-off-by: Qu Wenruo <wqu@suse.com> > --- > fs/btrfs/extent_io.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c > index f305777ee1a3..55115f485d09 100644 > --- a/fs/btrfs/extent_io.c > +++ b/fs/btrfs/extent_io.c > @@ -5310,14 +5310,13 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, > goto free_eb; > } > exists = NULL; > + WARN_ON(PageDirty(p)); > > /* > * Do this so attach doesn't complain and we need to > * drop the ref the old guy had. > */ > - ClearPagePrivate(p); > - WARN_ON(PageDirty(p)); > - put_page(p); > + detach_page_private(page); > } > attach_extent_buffer_page(eb, p); > spin_unlock(&mapping->private_lock); > There's one difference though, detach_page_private() does set a page's ->private to 0, whereas in alloc_extent_buffer() we didn't do it. I think setting it to 0 is more correct though, so Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
On Wed, Nov 18, 2020 at 04:53:06PM +0800, Qu Wenruo wrote: > index f305777ee1a3..55115f485d09 100644 > --- a/fs/btrfs/extent_io.c > +++ b/fs/btrfs/extent_io.c > @@ -5310,14 +5310,13 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, > goto free_eb; > } > exists = NULL; > + WARN_ON(PageDirty(p)); > > /* > * Do this so attach doesn't complain and we need to > * drop the ref the old guy had. > */ > - ClearPagePrivate(p); > - WARN_ON(PageDirty(p)); > - put_page(p); > + detach_page_private(page); Does this compile? The page is in 'p', not in 'page'. The code is moved in the next patch but each patch needs to compile.
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index f305777ee1a3..55115f485d09 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -5310,14 +5310,13 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, goto free_eb; } exists = NULL; + WARN_ON(PageDirty(p)); /* * Do this so attach doesn't complain and we need to * drop the ref the old guy had. */ - ClearPagePrivate(p); - WARN_ON(PageDirty(p)); - put_page(p); + detach_page_private(page); } attach_extent_buffer_page(eb, p); spin_unlock(&mapping->private_lock);
In alloc_extent_buffer(), after we got a page from btree inode, we check if that page has private pointer attached. If attached, we check if the existing extent buffer has a proper refs. If not (the eb is being freed), we will detach that private eb pointer. The point here is, we are detaching that eb pointer by calling: - ClearPagePrivate() - put_page() The put_page() here is especially confusing, as it's decreaing the ref caused by attach_page_private(). Without knowing that, it looks like the put_page() is for the find_or_create_page() call, confusing the read. Since we're always modifing page private with attach_page_private() and detach_page_private(), the only open-coded detach_page_private() here is really confusing. Fix it by calling detach_page_private(). Signed-off-by: Qu Wenruo <wqu@suse.com> --- fs/btrfs/extent_io.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)