diff mbox series

[3/4] ubifs: Use a folio in do_truncation()

Message ID 20230605165029.2908304-4-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series ubifs: Convert writeback to use folios | expand

Commit Message

Matthew Wilcox June 5, 2023, 4:50 p.m. UTC
Convert from the old page APIs to the new folio APIs which saves
a few hidden calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/ubifs/file.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Comments

Matthew Wilcox June 5, 2023, 5:05 p.m. UTC | #1
On Mon, Jun 05, 2023 at 05:50:28PM +0100, Matthew Wilcox (Oracle) wrote:
> Convert from the old page APIs to the new folio APIs which saves
> a few hidden calls to compound_head().

Argh.  This fix was supposed to be folded in.


diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index 1b2055d5ec5f..67cf5138ccc4 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -1161,7 +1161,7 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
 		struct folio *folio;
 
 		folio = filemap_lock_folio(inode->i_mapping, index);
-		if (folio) {
+		if (!IS_ERR(folio)) {
 			if (folio_test_dirty(folio)) {
 				/*
 				 * 'ubifs_jnl_truncate()' will try to truncate
Zhihao Cheng June 8, 2023, 2:31 p.m. UTC | #2
在 2023/6/6 1:05, Matthew Wilcox 写道:
> On Mon, Jun 05, 2023 at 05:50:28PM +0100, Matthew Wilcox (Oracle) wrote:
>> Convert from the old page APIs to the new folio APIs which saves
>> a few hidden calls to compound_head().
> 
> Argh.  This fix was supposed to be folded in.
> 
> 
> diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
> index 1b2055d5ec5f..67cf5138ccc4 100644
> --- a/fs/ubifs/file.c
> +++ b/fs/ubifs/file.c
> @@ -1161,7 +1161,7 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
>   		struct folio *folio;
>   
>   		folio = filemap_lock_folio(inode->i_mapping, index);
> -		if (folio) {
> +		if (!IS_ERR(folio)) {
>   			if (folio_test_dirty(folio)) {
>   				/*
>   				 * 'ubifs_jnl_truncate()' will try to truncate
> .
> 


Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
diff mbox series

Patch

diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index 1c7a99c36906..c0e68b3d7582 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -1153,11 +1153,11 @@  static int do_truncation(struct ubifs_info *c, struct inode *inode,
 
 	if (offset) {
 		pgoff_t index = new_size >> PAGE_SHIFT;
-		struct page *page;
+		struct folio *folio;
 
-		page = find_lock_page(inode->i_mapping, index);
-		if (page) {
-			if (PageDirty(page)) {
+		folio = filemap_lock_folio(inode->i_mapping, index);
+		if (folio) {
+			if (folio_test_dirty(folio)) {
 				/*
 				 * 'ubifs_jnl_truncate()' will try to truncate
 				 * the last data node, but it contains
@@ -1166,14 +1166,14 @@  static int do_truncation(struct ubifs_info *c, struct inode *inode,
 				 * 'ubifs_jnl_truncate()' will see an already
 				 * truncated (and up to date) data node.
 				 */
-				ubifs_assert(c, PagePrivate(page));
+				ubifs_assert(c, folio->private != NULL);
 
-				clear_page_dirty_for_io(page);
+				folio_clear_dirty_for_io(folio);
 				if (UBIFS_BLOCKS_PER_PAGE_SHIFT)
-					offset = new_size &
-						 (PAGE_SIZE - 1);
-				err = do_writepage(page, offset);
-				put_page(page);
+					offset = offset_in_folio(folio,
+							new_size);
+				err = do_writepage(&folio->page, offset);
+				folio_put(folio);
 				if (err)
 					goto out_budg;
 				/*
@@ -1186,8 +1186,8 @@  static int do_truncation(struct ubifs_info *c, struct inode *inode,
 				 * to 'ubifs_jnl_truncate()' to save it from
 				 * having to read it.
 				 */
-				unlock_page(page);
-				put_page(page);
+				folio_unlock(folio);
+				folio_put(folio);
 			}
 		}
 	}