From: Yu Kuai <yukuai1@huaweicloud.com>
To: Rajeev Mishra <rajeevm@hpe.com>,
axboe@kernel.dk, yukuai1@huaweicloud.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH v4 1/2] loop: Rename and merge get_size/get_loop_size to lo_calculate_size
Date: Thu, 14 Aug 2025 14:38:31 +0800 [thread overview]
Message-ID: <43c58aed-3fff-564b-e658-ebe3f7735fb9@huaweicloud.com> (raw)
In-Reply-To: <20250813195228.12021-2-rajeevm@hpe.com>
Hi,
在 2025/08/14 3:52, Rajeev Mishra 写道:
> - Renamed get_size to lo_calculate_size.
> - Merged get_size and get_loop_size logic into lo_calculate_size.
> - Updated all callers to use lo_calculate_size.
> - Added header to lo_calculate_size.
>
> Signed-off-by: Rajeev Mishra <rajeevm@hpe.com>
> ---
> drivers/block/loop.c | 50 +++++++++++++++++++-------------------------
> 1 file changed, 21 insertions(+), 29 deletions(-)
>
This patch has lots of style issues, please run checkpatch and fix
the warnings first.
Thanks,
Kuai
./scripts/checkpatch.pl
0001-loop-Rename-and-merge-get_size-get_loop_size-to-lo_c.patch
WARNING: please, no spaces at the start of a line
#52: FILE: drivers/block/loop.c:142:
+ loff_t loopsize;$
WARNING: please, no spaces at the start of a line
#54: FILE: drivers/block/loop.c:144:
+ loopsize = i_size_read(file->f_mapping->host);$
WARNING: please, no spaces at the start of a line
#55: FILE: drivers/block/loop.c:145:
+ if (lo->lo_offset > 0)$
WARNING: suspect code indent for conditional statements (7, 15)
#55: FILE: drivers/block/loop.c:145:
+ if (lo->lo_offset > 0)
+ loopsize -= lo->lo_offset;
WARNING: please, no spaces at the start of a line
#58: FILE: drivers/block/loop.c:148:
+ if (loopsize < 0)$
WARNING: suspect code indent for conditional statements (7, 15)
#58: FILE: drivers/block/loop.c:148:
+ if (loopsize < 0)
+ return 0;
WARNING: Statements should start on a tabstop
#59: FILE: drivers/block/loop.c:149:
+ return 0;
WARNING: please, no spaces at the start of a line
#60: FILE: drivers/block/loop.c:150:
+ if (lo->lo_sizelimit > 0 && lo->lo_sizelimit < loopsize)$
WARNING: suspect code indent for conditional statements (7, 15)
#60: FILE: drivers/block/loop.c:150:
+ if (lo->lo_sizelimit > 0 && lo->lo_sizelimit < loopsize)
+ loopsize = lo->lo_sizelimit;
WARNING: please, no spaces at the start of a line
#66: FILE: drivers/block/loop.c:156:
+ return loopsize >> 9;$
total: 0 errors, 10 warnings, 80 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or
--fix-inplace.
0001-loop-Rename-and-merge-get_size-get_loop_size-to-lo_c.patch has
style problems, please review.
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 1b6ee91f8eb9..5faf8607dfb2 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -137,30 +137,23 @@ static void loop_global_unlock(struct loop_device *lo, bool global)
> static int max_part;
> static int part_shift;
>
> -static loff_t get_size(loff_t offset, loff_t sizelimit, struct file *file)
> -{
> - loff_t loopsize;
> -
> - /* Compute loopsize in bytes */
> - loopsize = i_size_read(file->f_mapping->host);
> - if (offset > 0)
> - loopsize -= offset;
> - /* offset is beyond i_size, weird but possible */
> - if (loopsize < 0)
> - return 0;
> -
> - if (sizelimit > 0 && sizelimit < loopsize)
> - loopsize = sizelimit;
> - /*
> - * Unfortunately, if we want to do I/O on the device,
> - * the number of 512-byte sectors has to fit into a sector_t.
> - */
> - return loopsize >> 9;
> -}
> -
> -static loff_t get_loop_size(struct loop_device *lo, struct file *file)
> -{
> - return get_size(lo->lo_offset, lo->lo_sizelimit, file);
> +static loff_t lo_calculate_size(struct loop_device *lo, struct file *file)
> +{
> + loff_t loopsize;
> + /* Compute loopsize in bytes */
> + loopsize = i_size_read(file->f_mapping->host);
> + if (lo->lo_offset > 0)
> + loopsize -= lo->lo_offset;
> + /* offset is beyond i_size, weird but possible */
> + if (loopsize < 0)
> + return 0;
> + if (lo->lo_sizelimit > 0 && lo->lo_sizelimit < loopsize)
> + loopsize = lo->lo_sizelimit;
> + /*
> + * Unfortunately, if we want to do I/O on the device,
> + * the number of 512-byte sectors has to fit into a sector_t.
> + */
> + return loopsize >> 9;
> }
>
> /*
> @@ -569,7 +562,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
> error = -EINVAL;
>
> /* size of the new backing store needs to be the same */
> - if (get_loop_size(lo, file) != get_loop_size(lo, old_file))
> + if (lo_calculate_size(lo, file) != lo_calculate_size(lo, old_file))
> goto out_err;
>
> /*
> @@ -1063,7 +1056,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
> loop_update_dio(lo);
> loop_sysfs_init(lo);
>
> - size = get_loop_size(lo, file);
> + size = lo_calculate_size(lo, file);
> loop_set_size(lo, size);
>
> /* Order wrt reading lo_state in loop_validate_file(). */
> @@ -1255,8 +1248,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
> if (partscan)
> clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state);
> if (!err && size_changed) {
> - loff_t new_size = get_size(lo->lo_offset, lo->lo_sizelimit,
> - lo->lo_backing_file);
> + loff_t new_size = lo_calculate_size(lo, lo->lo_backing_file);
> loop_set_size(lo, new_size);
> }
> out_unlock:
> @@ -1399,7 +1391,7 @@ static int loop_set_capacity(struct loop_device *lo)
> if (unlikely(lo->lo_state != Lo_bound))
> return -ENXIO;
>
> - size = get_loop_size(lo, lo->lo_backing_file);
> + size = lo_calculate_size(lo, lo->lo_backing_file);
> loop_set_size(lo, size);
>
> return 0;
>
next prev parent reply other threads:[~2025-08-14 6:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 19:52 [PATCH v4 0/2] review of v3 loop: use vfs_getattr_nosec() Rajeev Mishra
2025-08-13 19:52 ` [PATCH v4 1/2] loop: Rename and merge get_size/get_loop_size to lo_calculate_size Rajeev Mishra
2025-08-14 6:38 ` Yu Kuai [this message]
2025-08-13 19:52 ` [PATCH v4 2/2] loop: use vfs_getattr_nosec for accurate file size Rajeev Mishra
2025-08-14 19:10 [PATCH v4 1/2] loop: Rename and merge get_size/get_loop_size to lo_calculate_size Rajeev Mishra
2025-08-18 2:29 ` Yu Kuai
2025-08-18 16:18 ` Jens Axboe
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=43c58aed-3fff-564b-e658-ebe3f7735fb9@huaweicloud.com \
--to=yukuai1@huaweicloud.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rajeevm@hpe.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
all inboxes | Powered by JetHome®