From: Jan Kara <jack@suse.cz>
To: Zhang Yi <yi.zhang@huaweicloud.com>
Cc: linux-ext4@vger.kernel.org, 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, chengzhihao1@huawei.com, yukuai3@huawei.com
Subject: Re: [PATCH v2 09/10] ext4: factor out the common checking part of all fallocate operations
Date: Mon, 23 Sep 2024 10:31:22 +0200 [thread overview]
Message-ID: <20240923083122.amqnlzxj53beqtwj@quack3> (raw)
In-Reply-To: <20240904062925.716856-10-yi.zhang@huaweicloud.com>
On Wed 04-09-24 14:29:24, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
>
> Now the beginning of all the five functions in ext4_fallocate() (punch
> hole, zero range, insert range, collapse range and normal fallocate) are
> almost the same, they need to hold i_rwsem and check the validity of
> input parameters, so move the holding of i_rwsem to ext4_fallocate()
> and factor out a common helper to check the input parameters can make
> the code more clear.
>
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
...
> +static int ext4_fallocate_check(struct inode *inode, int mode,
> + loff_t offset, loff_t len)
> +{
> + /* Currently except punch_hole, just for extent based files. */
> + if (!(mode & FALLOC_FL_PUNCH_HOLE) &&
> + !ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
> + return -EOPNOTSUPP;
> +
> + /*
> + * Insert range and collapse range works only on fs cluster size
> + * aligned regions.
> + */
> + if (mode & (FALLOC_FL_INSERT_RANGE | FALLOC_FL_COLLAPSE_RANGE) &&
> + !IS_ALIGNED(offset | len, EXT4_CLUSTER_SIZE(inode->i_sb)))
> + return -EINVAL;
> +
> + if (mode & FALLOC_FL_INSERT_RANGE) {
> + /* Collapse range, offset must be less than i_size */
> + if (offset >= inode->i_size)
> + return -EINVAL;
> + /* Check whether the maximum file size would be exceeded */
> + if (len > inode->i_sb->s_maxbytes - inode->i_size)
> + return -EFBIG;
> + } else if (mode & FALLOC_FL_COLLAPSE_RANGE) {
> + /*
> + * Insert range, there is no need to overlap collapse
> + * range with EOF, in which case it is effectively a
> + * truncate operation.
> + */
> + if (offset + len >= inode->i_size)
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
I don't think this helps. If the code is really shared, then the
factorization is good but here you have to do various checks what operation
we perform and in that case I don't think it really helps readability to
factor out checks into a common function.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-09-23 8:31 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-04 6:29 [PATCH v2 00/10] ext4: clean up and refactor fallocate Zhang Yi
2024-09-04 6:29 ` [PATCH v2 01/10] ext4: write out dirty data before dropping pages Zhang Yi
2024-09-17 16:50 ` Jan Kara
2024-09-18 12:27 ` Zhang Yi
2024-09-04 6:29 ` [PATCH v2 02/10] ext4: don't explicit update times in ext4_fallocate() Zhang Yi
2024-09-20 16:04 ` Jan Kara
2024-09-04 6:29 ` [PATCH v2 03/10] ext4: drop ext4_update_disksize_before_punch() Zhang Yi
2024-09-20 16:13 ` Jan Kara
2024-09-24 7:43 ` Zhang Yi
2024-09-24 10:11 ` Jan Kara
2024-09-24 11:09 ` Zhang Yi
2024-09-04 6:29 ` [PATCH v2 04/10] ext4: refactor ext4_zero_range() Zhang Yi
2024-09-20 16:24 ` Jan Kara
2024-09-04 6:29 ` [PATCH v2 05/10] ext4: refactor ext4_punch_hole() Zhang Yi
2024-09-20 16:31 ` Jan Kara
2024-09-04 6:29 ` [PATCH v2 06/10] ext4: refactor ext4_collapse_range() Zhang Yi
2024-09-20 16:35 ` Jan Kara
2024-09-04 6:29 ` [PATCH v2 07/10] ext4: refactor ext4_insert_range() Zhang Yi
2024-09-23 8:17 ` Jan Kara
2024-09-04 6:29 ` [PATCH v2 08/10] ext4: factor out ext4_do_fallocate() Zhang Yi
2024-09-23 8:20 ` Jan Kara
2024-09-04 6:29 ` [PATCH v2 09/10] ext4: factor out the common checking part of all fallocate operations Zhang Yi
2024-09-23 8:31 ` Jan Kara [this message]
2024-09-24 7:52 ` Zhang Yi
2024-09-04 6:29 ` [PATCH v2 10/10] ext4: factor out a common helper to lock and flush data before fallocate Zhang Yi
2024-09-23 8:54 ` Jan Kara
2024-09-24 8:11 ` Zhang Yi
2024-09-24 10:05 ` Jan Kara
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=20240923083122.amqnlzxj53beqtwj@quack3 \
--to=jack@suse.cz \
--cc=adilger.kernel@dilger.ca \
--cc=chengzhihao1@huawei.com \
--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=yi.zhang@huaweicloud.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