diff mbox series

[v3,10/10] fuse: convert fuse_notify_store to use folios

Message ID 877bb686a99010b19778570591de923296626896.1727469663.git.josef@toxicpanda.com (mailing list archive)
State New
Headers show
Series fuse: folio conversions | expand

Commit Message

Josef Bacik Sept. 27, 2024, 8:45 p.m. UTC
This function creates pages in an inode and copies data into them,
update the function to use a folio instead of a page, and use the
appropriate folio helpers.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/fuse/dev.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

Comments

Joanne Koong Sept. 27, 2024, 11:08 p.m. UTC | #1
On Fri, Sep 27, 2024 at 1:46 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> This function creates pages in an inode and copies data into them,
> update the function to use a folio instead of a page, and use the
> appropriate folio helpers.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Joanne Koong <joannelkoong@gmail.com>

> ---
>  fs/fuse/dev.c | 30 +++++++++++++++++-------------
>  1 file changed, 17 insertions(+), 13 deletions(-)
>
> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> index 4c58113eb6a1..5b011c8fa9d6 100644
> --- a/fs/fuse/dev.c
> +++ b/fs/fuse/dev.c
> @@ -1654,24 +1654,28 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
>
>         num = outarg.size;
>         while (num) {
> +               struct folio *folio;
>                 struct page *page;
>                 unsigned int this_num;
>
> -               err = -ENOMEM;
> -               page = find_or_create_page(mapping, index,
> -                                          mapping_gfp_mask(mapping));
> -               if (!page)
> +               folio = __filemap_get_folio(mapping, index,
> +                                           FGP_LOCK|FGP_ACCESSED|FGP_CREAT,
> +                                           mapping_gfp_mask(mapping));
> +               if (IS_ERR(folio)) {
> +                       err = PTR_ERR(folio);
>                         goto out_iput;
> -
> -               this_num = min_t(unsigned, num, PAGE_SIZE - offset);
> -               err = fuse_copy_page(cs, &page, offset, this_num, 0);
> -               if (!PageUptodate(page) && !err && offset == 0 &&
> -                   (this_num == PAGE_SIZE || file_size == end)) {
> -                       zero_user_segment(page, this_num, PAGE_SIZE);
> -                       SetPageUptodate(page);
>                 }
> -               unlock_page(page);
> -               put_page(page);
> +
> +               page = &folio->page;
> +               this_num = min_t(unsigned, num, folio_size(folio) - offset);
> +               err = fuse_copy_page(cs, &page, offset, this_num, 0);
> +               if (!folio_test_uptodate(folio) && !err && offset == 0 &&
> +                   (this_num == folio_size(folio) || file_size == end)) {
> +                       folio_zero_range(folio, this_num, folio_size(folio));
> +                       folio_mark_uptodate(folio);
> +               }
> +               folio_unlock(folio);
> +               folio_put(folio);
>
>                 if (err)
>                         goto out_iput;
> --
> 2.43.0
>
>
diff mbox series

Patch

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 4c58113eb6a1..5b011c8fa9d6 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1654,24 +1654,28 @@  static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 
 	num = outarg.size;
 	while (num) {
+		struct folio *folio;
 		struct page *page;
 		unsigned int this_num;
 
-		err = -ENOMEM;
-		page = find_or_create_page(mapping, index,
-					   mapping_gfp_mask(mapping));
-		if (!page)
+		folio = __filemap_get_folio(mapping, index,
+					    FGP_LOCK|FGP_ACCESSED|FGP_CREAT,
+					    mapping_gfp_mask(mapping));
+		if (IS_ERR(folio)) {
+			err = PTR_ERR(folio);
 			goto out_iput;
-
-		this_num = min_t(unsigned, num, PAGE_SIZE - offset);
-		err = fuse_copy_page(cs, &page, offset, this_num, 0);
-		if (!PageUptodate(page) && !err && offset == 0 &&
-		    (this_num == PAGE_SIZE || file_size == end)) {
-			zero_user_segment(page, this_num, PAGE_SIZE);
-			SetPageUptodate(page);
 		}
-		unlock_page(page);
-		put_page(page);
+
+		page = &folio->page;
+		this_num = min_t(unsigned, num, folio_size(folio) - offset);
+		err = fuse_copy_page(cs, &page, offset, this_num, 0);
+		if (!folio_test_uptodate(folio) && !err && offset == 0 &&
+		    (this_num == folio_size(folio) || file_size == end)) {
+			folio_zero_range(folio, this_num, folio_size(folio));
+			folio_mark_uptodate(folio);
+		}
+		folio_unlock(folio);
+		folio_put(folio);
 
 		if (err)
 			goto out_iput;