[PATCH -next] hostfs: Convert hostfs_writepage to use folio

Li Zetao posted 1 patch 1 year, 4 months ago
fs/hostfs/hostfs_kern.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
[PATCH -next] hostfs: Convert hostfs_writepage to use folio
Posted by Li Zetao 1 year, 4 months ago
convert to use folio, so that we can get rid of 'page->index' to
prepare for removal of 'index' field in structure page [1].

[1]: https://lore.kernel.org/all/Zp8fgUSIBGQ1TN0D@casper.infradead.org/

Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 fs/hostfs/hostfs_kern.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 6d1cf2436ead..e17e70f20fa1 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -411,18 +411,19 @@ static const struct file_operations hostfs_dir_fops = {
 
 static int hostfs_writepage(struct page *page, struct writeback_control *wbc)
 {
-	struct address_space *mapping = page->mapping;
-	struct inode *inode = mapping->host;
+	struct folio *folio = page_folio(page);
+	struct address_space *mapping = folio->mapping;
+	struct inode *inode = folio_inode(folio);
 	char *buffer;
-	loff_t base = page_offset(page);
+	loff_t base = folio_pos(folio);
 	int count = PAGE_SIZE;
 	int end_index = inode->i_size >> PAGE_SHIFT;
 	int err;
 
-	if (page->index >= end_index)
+	if (folio->index >= end_index)
 		count = inode->i_size & (PAGE_SIZE-1);
 
-	buffer = kmap_local_page(page);
+	buffer = kmap_local_folio(folio, 0);
 
 	err = write_file(HOSTFS_I(inode)->fd, &base, buffer, count);
 	if (err != count) {
@@ -439,7 +440,7 @@ static int hostfs_writepage(struct page *page, struct writeback_control *wbc)
 
  out:
 	kunmap_local(buffer);
-	unlock_page(page);
+	folio_unlock(folio);
 
 	return err;
 }
-- 
2.34.1
Re: [PATCH -next] hostfs: Convert hostfs_writepage to use folio
Posted by Richard Weinberger 1 year, 3 months ago
----- Ursprüngliche Mail -----
> Von: "Li Zetao" <lizetao1@huawei.com>
> An: "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>, "Johannes Berg"
> <johannes@sipsolutions.net>
> CC: lizetao1@huawei.com, "linux-um" <linux-um@lists.infradead.org>, "linux-kernel" <linux-kernel@vger.kernel.org>
> Gesendet: Dienstag, 20. August 2024 04:50:45
> Betreff: [PATCH -next] hostfs: Convert hostfs_writepage to use folio

> convert to use folio, so that we can get rid of 'page->index' to
> prepare for removal of 'index' field in structure page [1].
> 
> [1]: https://lore.kernel.org/all/Zp8fgUSIBGQ1TN0D@casper.infradead.org/
> 
> Cc: Matthew Wilcox <willy@infradead.org>

You patch submission didn't CC Matthew. Adding him now.

> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
> fs/hostfs/hostfs_kern.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
> index 6d1cf2436ead..e17e70f20fa1 100644
> --- a/fs/hostfs/hostfs_kern.c
> +++ b/fs/hostfs/hostfs_kern.c
> @@ -411,18 +411,19 @@ static const struct file_operations hostfs_dir_fops = {
> 
> static int hostfs_writepage(struct page *page, struct writeback_control *wbc)
> {
> -	struct address_space *mapping = page->mapping;
> -	struct inode *inode = mapping->host;
> +	struct folio *folio = page_folio(page);
> +	struct address_space *mapping = folio->mapping;
> +	struct inode *inode = folio_inode(folio);
> 	char *buffer;
> -	loff_t base = page_offset(page);
> +	loff_t base = folio_pos(folio);
> 	int count = PAGE_SIZE;
> 	int end_index = inode->i_size >> PAGE_SHIFT;
> 	int err;
> 
> -	if (page->index >= end_index)
> +	if (folio->index >= end_index)
> 		count = inode->i_size & (PAGE_SIZE-1);
> 
> -	buffer = kmap_local_page(page);
> +	buffer = kmap_local_folio(folio, 0);
> 
> 	err = write_file(HOSTFS_I(inode)->fd, &base, buffer, count);
> 	if (err != count) {
> @@ -439,7 +440,7 @@ static int hostfs_writepage(struct page *page, struct
> writeback_control *wbc)
> 
>  out:
> 	kunmap_local(buffer);
> -	unlock_page(page);
> +	folio_unlock(folio);
> 
> 	return err;
> }
> --
> 2.34.1
Re: [PATCH -next] hostfs: Convert hostfs_writepage to use folio
Posted by Matthew Wilcox 1 year, 3 months ago
On Thu, Sep 12, 2024 at 08:22:48PM +0200, Richard Weinberger wrote:
> ----- Ursprüngliche Mail -----
> > Von: "Li Zetao" <lizetao1@huawei.com>
> > An: "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>, "Johannes Berg"
> > <johannes@sipsolutions.net>
> > CC: lizetao1@huawei.com, "linux-um" <linux-um@lists.infradead.org>, "linux-kernel" <linux-kernel@vger.kernel.org>
> > Gesendet: Dienstag, 20. August 2024 04:50:45
> > Betreff: [PATCH -next] hostfs: Convert hostfs_writepage to use folio
> 
> > convert to use folio, so that we can get rid of 'page->index' to
> > prepare for removal of 'index' field in structure page [1].

Ideally, we would not do this, instead converting hostfs to use
writepages instead of writepage.  I haven't done this work; would
someone like to do it?

> > static int hostfs_writepage(struct page *page, struct writeback_control *wbc)
> > {
> > -	struct address_space *mapping = page->mapping;
> > -	struct inode *inode = mapping->host;
> > +	struct folio *folio = page_folio(page);
> > +	struct address_space *mapping = folio->mapping;
> > +	struct inode *inode = folio_inode(folio);

Don't use folio_inode() here, leave it as it was.

> > -	if (page->index >= end_index)
> > +	if (folio->index >= end_index)
> > 		count = inode->i_size & (PAGE_SIZE-1);
> > 
> > -	buffer = kmap_local_page(page);
> > +	buffer = kmap_local_folio(folio, 0);

These two lines assume that hostfs remains a non-large-folio filesystem.
I'm not sure what the plans are for hostfs.
Re: [PATCH -next] hostfs: Convert hostfs_writepage to use folio
Posted by Richard Weinberger 1 year, 3 months ago
----- Ursprüngliche Mail -----
> Von: "Matthew Wilcox" <willy@infradead.org>
>> > -	buffer = kmap_local_page(page);
>> > +	buffer = kmap_local_folio(folio, 0);
> 
> These two lines assume that hostfs remains a non-large-folio filesystem.
> I'm not sure what the plans are for hostfs.

Somewhere deep on my TODO are plans to remove hostfs and replace it
with something such as 9p or virtiofs.
Any volunteers? :-)

Thanks,
//richard