linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Yi <yi.zhang@huaweicloud.com>
To: linux-ext4@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz,
	ritesh.list@gmail.com, yi.zhang@huawei.com,
	yi.zhang@huaweicloud.com, chengzhihao1@huawei.com,
	yukuai3@huawei.com
Subject: [PATCH 03/10] ext4: drop ext4_update_disksize_before_punch()
Date: Fri, 30 Aug 2024 15:37:53 +0800	[thread overview]
Message-ID: <20240830073800.2131781-4-yi.zhang@huaweicloud.com> (raw)
In-Reply-To: <20240830073800.2131781-1-yi.zhang@huaweicloud.com>

From: Zhang Yi <yi.zhang@huawei.com>

Since we always write back dirty data before zeroing range and punching
hole, the delalloc extended file's disksize of should be updated
properly when writing back pages, hence we don't need to update file's
disksize before discarding page cache in ext4_zero_range() and
ext4_punch_hole(), just drop ext4_update_disksize_before_punch().

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
 fs/ext4/ext4.h    |  3 ---
 fs/ext4/extents.c |  4 ----
 fs/ext4/inode.c   | 37 +------------------------------------
 3 files changed, 1 insertion(+), 43 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 08acd152261e..e8d7965f62c4 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3414,9 +3414,6 @@ static inline int ext4_update_inode_size(struct inode *inode, loff_t newsize)
 	return changed;
 }
 
-int ext4_update_disksize_before_punch(struct inode *inode, loff_t offset,
-				      loff_t len);
-
 struct ext4_group_info {
 	unsigned long   bb_state;
 #ifdef AGGRESSIVE_CHECK
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 19a9b14935b7..d9fccf2970e9 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4637,10 +4637,6 @@ static long ext4_zero_range(struct file *file, loff_t offset,
 		flags |= (EXT4_GET_BLOCKS_CONVERT_UNWRITTEN |
 			  EXT4_EX_NOCACHE);
 
-		ret = ext4_update_disksize_before_punch(inode, offset, len);
-		if (ret)
-			goto out_invalidate_lock;
-
 		/* Now release the pages and zero block aligned part of pages */
 		truncate_pagecache_range(inode, start, end - 1);
 
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 8af25442d44d..9343ce9f2b01 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3872,37 +3872,6 @@ int ext4_can_truncate(struct inode *inode)
 	return 0;
 }
 
-/*
- * We have to make sure i_disksize gets properly updated before we truncate
- * page cache due to hole punching or zero range. Otherwise i_disksize update
- * can get lost as it may have been postponed to submission of writeback but
- * that will never happen after we truncate page cache.
- */
-int ext4_update_disksize_before_punch(struct inode *inode, loff_t offset,
-				      loff_t len)
-{
-	handle_t *handle;
-	int ret;
-
-	loff_t size = i_size_read(inode);
-
-	WARN_ON(!inode_is_locked(inode));
-	if (offset > size || offset + len < size)
-		return 0;
-
-	if (EXT4_I(inode)->i_disksize >= size)
-		return 0;
-
-	handle = ext4_journal_start(inode, EXT4_HT_MISC, 1);
-	if (IS_ERR(handle))
-		return PTR_ERR(handle);
-	ext4_update_i_disksize(inode, size);
-	ret = ext4_mark_inode_dirty(handle, inode);
-	ext4_journal_stop(handle);
-
-	return ret;
-}
-
 static void ext4_wait_dax_page(struct inode *inode)
 {
 	filemap_invalidate_unlock(inode->i_mapping);
@@ -4022,13 +3991,9 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
 	last_block_offset = round_down((offset + length), sb->s_blocksize) - 1;
 
 	/* Now release the pages and zero block aligned part of pages*/
-	if (last_block_offset > first_block_offset) {
-		ret = ext4_update_disksize_before_punch(inode, offset, length);
-		if (ret)
-			goto out_dio;
+	if (last_block_offset > first_block_offset)
 		truncate_pagecache_range(inode, first_block_offset,
 					 last_block_offset);
-	}
 
 	if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
 		credits = ext4_writepage_trans_blocks(inode);
-- 
2.39.2


  parent reply	other threads:[~2024-08-30  7:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-30  7:37 [PATCH 00/10] ext4: clean up and refactor fallocate Zhang Yi
2024-08-30  7:37 ` [PATCH 01/10] ext4: write out dirty data before dropping pages Zhang Yi
2024-08-30  7:37 ` [PATCH 02/10] ext4: don't explicit update times in ext4_fallocate() Zhang Yi
2024-08-30  7:37 ` Zhang Yi [this message]
2024-08-30  7:37 ` [PATCH 04/10] ext4: refactor ext4_zero_range() Zhang Yi
2024-08-30  7:37 ` [PATCH 05/10] ext4: refactor ext4_punch_hole() Zhang Yi
2024-08-30  7:37 ` [PATCH 06/10] ext4: refactor ext4_collapse_range() Zhang Yi
2024-08-30  7:37 ` [PATCH 07/10] ext4: refactor ext4_insert_range() Zhang Yi
2024-08-30  7:37 ` [PATCH 08/10] ext4: factor out ext4_do_fallocate() Zhang Yi
2024-08-30  7:37 ` [PATCH 09/10] ext4: factor out the common checking part of all fallocate operations Zhang Yi
2024-08-30  7:38 ` [PATCH 10/10] ext4: factor out a common helper to lock and flush data before fallocate Zhang Yi

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=20240830073800.2131781-4-yi.zhang@huaweicloud.com \
    --to=yi.zhang@huaweicloud.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=chengzhihao1@huawei.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).