From nobody Mon Feb 9 16:16:51 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AAB7280309; Tue, 3 Feb 2026 06:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770100220; cv=none; b=N2MJ1UjmiuJVWN3doM7zT3uxF+hnXNKOsdxusr4/XM2Rr6y8hHz2gu8k+1CHDK+n7VbX0KUccwHQNCU5scKPUYTRiUA+G95bLPMm96jCokdHYaIn6cVmDCw8zPIVAH0oEnHp5FvlcoexuRs94QSznhpCew/WTfO6hL/xYMiIoLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770100220; c=relaxed/simple; bh=0H3W+6a71flSLzpqq6UEC3TaLlEPPuhZoaLQAw8asCU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hZtPGrmHxpGGRV68+kBiEEjxDBzPG5UuBXsZZhUTWQkx5jibj9w6WS9JI0h9+3UixhQJvgqg5R8CqUTirco4NfU6Xl6RefpVBQXMLzvHikmvbETP0RmWX1R+iOC+poYcqJhZsFkV1LDmrTzKl8gCSFEV4Wjn7NKT6QEhvAEr12M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.198]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4f4tqq14jkzYQtxx; Tue, 3 Feb 2026 14:29:27 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 18EA440577; Tue, 3 Feb 2026 14:30:14 +0800 (CST) Received: from huaweicloud.com (unknown [10.50.85.155]) by APP4 (Coremail) with SMTP id gCh0CgAHaPjnlYFpiadbGA--.27803S9; Tue, 03 Feb 2026 14:30:13 +0800 (CST) From: Zhang Yi 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, ojaswin@linux.ibm.com, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, yizhang089@gmail.com, libaokun1@huawei.com, yangerkun@huawei.com, yukuai@fnnas.com Subject: [PATCH -next v2 05/22] ext4: stop passing handle to ext4_journalled_block_zero_range() Date: Tue, 3 Feb 2026 14:25:05 +0800 Message-ID: <20260203062523.3869120-6-yi.zhang@huawei.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260203062523.3869120-1-yi.zhang@huawei.com> References: <20260203062523.3869120-1-yi.zhang@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgAHaPjnlYFpiadbGA--.27803S9 X-Coremail-Antispam: 1UD129KBjvJXoW3GF15WFW7tw48WFW3WryxGrg_yoWfXr1Dpr yUAw1rCr43uryq9F4xKFsFvr4a93Z7GFW8Gry7Gr9YvasrXw1xKF1DK3WrtFWjqrW7Wa10 vF4Yy34jg3WUJ3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHab4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7Iv64x0x7Aq67IIx4CEVc8vx2IErcIFxwACI4 02YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCF 04k20xvEw4C26cxK6c8Ij28IcwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8 JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUFPETDU UUU Sender: yi.zhang@huaweicloud.com X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ Content-Type: text/plain; charset="utf-8" When zeroing partial blocks, only the journal data mode requires an active journal handle. Therefore, stop passing the handle to ext4_zero_partial_blocks() and related functions, and make ext4_journalled_block_zero_range() start a handle independently. Currently, this change has no practical impact because all calls occur within the context of an active handle. This change prepares for moving ext4_block_truncate_page() out of an active handle, which is a prerequisite for converting block zero range operations to the iomap infrastructure because it requires active writeback after truncate down. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 4 ++-- fs/ext4/extents.c | 6 +++--- fs/ext4/inode.c | 54 +++++++++++++++++++++++++---------------------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index e0ed273e2e8a..19d0b4917aea 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3103,8 +3103,8 @@ extern int ext4_chunk_trans_blocks(struct inode *, in= t nrblocks); extern int ext4_chunk_trans_extent(struct inode *inode, int nrblocks); extern int ext4_meta_trans_blocks(struct inode *inode, int lblocks, int pextents); -extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, - loff_t lstart, loff_t lend); +extern int ext4_zero_partial_blocks(struct inode *inode, + loff_t lstart, loff_t lend); extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf); extern qsize_t *ext4_get_reserved_space(struct inode *inode); extern int ext4_get_projid(struct inode *inode, kprojid_t *projid); diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 3630b27e4fd7..953bf8945bda 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4627,8 +4627,8 @@ static int ext4_alloc_file_blocks(struct file *file, = ext4_lblk_t offset, inode_get_ctime(inode)); if (epos > old_size) { pagecache_isize_extended(inode, old_size, epos); - ext4_zero_partial_blocks(handle, inode, - old_size, epos - old_size); + ext4_zero_partial_blocks(inode, old_size, + epos - old_size); } } ret2 =3D ext4_mark_inode_dirty(handle, inode); @@ -4746,7 +4746,7 @@ static long ext4_zero_range(struct file *file, loff_t= offset, } =20 /* Zero out partial block at the edges of the range */ - ret =3D ext4_zero_partial_blocks(handle, inode, offset, len); + ret =3D ext4_zero_partial_blocks(inode, offset, len); if (ret) goto out_handle; =20 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 7990ad566e10..c05b1c0a1b45 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1458,7 +1458,7 @@ static int ext4_write_end(const struct kiocb *iocb, =20 if (old_size < pos && !verity) { pagecache_isize_extended(inode, old_size, pos); - ext4_zero_partial_blocks(handle, inode, old_size, pos - old_size); + ext4_zero_partial_blocks(inode, old_size, pos - old_size); } /* * Don't mark the inode dirty under folio lock. First, it unnecessarily @@ -1576,7 +1576,7 @@ static int ext4_journalled_write_end(const struct kio= cb *iocb, =20 if (old_size < pos && !verity) { pagecache_isize_extended(inode, old_size, pos); - ext4_zero_partial_blocks(handle, inode, old_size, pos - old_size); + ext4_zero_partial_blocks(inode, old_size, pos - old_size); } =20 if (size_changed) { @@ -3252,7 +3252,7 @@ static int ext4_da_do_write_end(struct address_space = *mapping, if (IS_ERR(handle)) return PTR_ERR(handle); if (zero_len) - ext4_zero_partial_blocks(handle, inode, old_size, zero_len); + ext4_zero_partial_blocks(inode, old_size, zero_len); ext4_mark_inode_dirty(handle, inode); ext4_journal_stop(handle); =20 @@ -4126,16 +4126,23 @@ static int ext4_block_zero_range(struct inode *inod= e, loff_t from, return 0; } =20 -static int ext4_journalled_block_zero_range(handle_t *handle, - struct inode *inode, loff_t from, loff_t length, bool *did_zero) +static int ext4_journalled_block_zero_range(struct inode *inode, loff_t fr= om, + loff_t length, bool *did_zero) { struct buffer_head *bh; struct folio *folio; + handle_t *handle; int err; =20 + handle =3D ext4_journal_start(inode, EXT4_HT_MISC, 1); + if (IS_ERR(handle)) + return PTR_ERR(handle); + bh =3D ext4_block_get_zero_range(inode, from, length); - if (IS_ERR_OR_NULL(bh)) - return PTR_ERR_OR_ZERO(bh); + if (IS_ERR_OR_NULL(bh)) { + err =3D PTR_ERR_OR_ZERO(bh); + goto out_handle; + } folio =3D bh->b_folio; =20 BUFFER_TRACE(bh, "get write access"); @@ -4156,6 +4163,8 @@ static int ext4_journalled_block_zero_range(handle_t = *handle, out: folio_unlock(folio); folio_put(folio); +out_handle: + ext4_journal_stop(handle); return err; } =20 @@ -4166,9 +4175,9 @@ static int ext4_journalled_block_zero_range(handle_t = *handle, * the end of the block it will be shortened to end of the block * that corresponds to 'from' */ -static int ext4_block_zero_page_range(handle_t *handle, - struct address_space *mapping, loff_t from, loff_t length, - bool *did_zero) +static int ext4_block_zero_page_range(struct address_space *mapping, + loff_t from, loff_t length, + bool *did_zero) { struct inode *inode =3D mapping->host; unsigned blocksize =3D inode->i_sb->s_blocksize; @@ -4185,7 +4194,7 @@ static int ext4_block_zero_page_range(handle_t *handl= e, return dax_zero_range(inode, from, length, did_zero, &ext4_iomap_ops); } else if (ext4_should_journal_data(inode)) { - return ext4_journalled_block_zero_range(handle, inode, from, + return ext4_journalled_block_zero_range(inode, from, length, did_zero); } return ext4_block_zero_range(inode, from, length, did_zero); @@ -4198,8 +4207,7 @@ static int ext4_block_zero_page_range(handle_t *handl= e, * of that block so it doesn't yield old data if the file is later grown. * Return the zeroed length on success. */ -static int ext4_block_truncate_page(handle_t *handle, - struct address_space *mapping, loff_t from) +static int ext4_block_truncate_page(struct address_space *mapping, loff_t = from) { unsigned length; unsigned blocksize; @@ -4214,16 +4222,14 @@ static int ext4_block_truncate_page(handle_t *handl= e, blocksize =3D i_blocksize(inode); length =3D blocksize - (from & (blocksize - 1)); =20 - err =3D ext4_block_zero_page_range(handle, mapping, from, length, - &did_zero); + err =3D ext4_block_zero_page_range(mapping, from, length, &did_zero); if (err) return err; =20 return did_zero ? length : 0; } =20 -int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, - loff_t lstart, loff_t length) +int ext4_zero_partial_blocks(struct inode *inode, loff_t lstart, loff_t le= ngth) { struct super_block *sb =3D inode->i_sb; struct address_space *mapping =3D inode->i_mapping; @@ -4241,20 +4247,19 @@ int ext4_zero_partial_blocks(handle_t *handle, stru= ct inode *inode, /* Handle partial zero within the single block */ if (start =3D=3D end && (partial_start || (partial_end !=3D sb->s_blocksize - 1))) { - err =3D ext4_block_zero_page_range(handle, mapping, - lstart, length, NULL); + err =3D ext4_block_zero_page_range(mapping, lstart, length, NULL); return err; } /* Handle partial zero out on the start of the range */ if (partial_start) { - err =3D ext4_block_zero_page_range(handle, mapping, lstart, + err =3D ext4_block_zero_page_range(mapping, lstart, sb->s_blocksize, NULL); if (err) return err; } /* Handle partial zero out on the end of the range */ if (partial_end !=3D sb->s_blocksize - 1) - err =3D ext4_block_zero_page_range(handle, mapping, + err =3D ext4_block_zero_page_range(mapping, byte_end - partial_end, partial_end + 1, NULL); return err; @@ -4462,7 +4467,7 @@ int ext4_punch_hole(struct file *file, loff_t offset,= loff_t length) return ret; } =20 - ret =3D ext4_zero_partial_blocks(handle, inode, offset, length); + ret =3D ext4_zero_partial_blocks(inode, offset, length); if (ret) goto out_handle; =20 @@ -4614,8 +4619,7 @@ int ext4_truncate(struct inode *inode) if (inode->i_size & (inode->i_sb->s_blocksize - 1)) { unsigned int zero_len; =20 - zero_len =3D ext4_block_truncate_page(handle, mapping, - inode->i_size); + zero_len =3D ext4_block_truncate_page(mapping, inode->i_size); if (zero_len < 0) { err =3D zero_len; goto out_stop; @@ -5990,7 +5994,7 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dent= ry *dentry, inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); if (oldsize & (inode->i_sb->s_blocksize - 1)) - ext4_block_truncate_page(handle, + ext4_block_truncate_page( inode->i_mapping, oldsize); } =20 --=20 2.52.0