* [PATCH v5] fixed the blok file statx issue
@ 2025-08-25 22:17 Cloud User
2025-08-25 22:17 ` [PATCH 1/2] loop: Rename and merge get_size/get_loop_size to lo_calculate_size Cloud User
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Cloud User @ 2025-08-25 22:17 UTC (permalink / raw)
To: Yu Kuai, ming.lei, hch, yukuai3, rajeevm
Cc: linux-block, linux-kernel, yi.zhang, yangerkun, johnny.chenyi
This fixes the statx issue which caused multiple test issue
Rajeev Mishra (2):
loop: Rename and merge get_size/get_loop_size to lo_calculate_size
loop: use vfs_getattr_nosec for accurate file size
drivers/block/loop.c | 43 +++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] loop: Rename and merge get_size/get_loop_size to lo_calculate_size
2025-08-25 22:17 [PATCH v5] fixed the blok file statx issue Cloud User
@ 2025-08-25 22:17 ` Cloud User
2025-08-25 22:17 ` [PATCH 2/2] loop: use vfs_getattr_nosec for accurate file size Cloud User
2025-08-26 0:49 ` [PATCH v5] fixed the blok file statx issue Yu Kuai
2 siblings, 0 replies; 5+ messages in thread
From: Cloud User @ 2025-08-25 22:17 UTC (permalink / raw)
To: Yu Kuai, ming.lei, hch, yukuai3, rajeevm
Cc: linux-block, linux-kernel, yi.zhang, yangerkun, johnny.chenyi
From: Rajeev Mishra <rajeevm@hpe.com>
Renamed get_size to lo_calculate_size and merged the logic from
get_size and get_loop_size into a single function.
Updated all callers to use lo_calculate_size
Signed-off-by: Rajeev Mishra <rajeevm@hpe.com>
---
drivers/block/loop.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 1b6ee91f8eb9..0e1b9eb9db10 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -137,20 +137,18 @@ 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)
+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 (offset > 0)
- loopsize -= offset;
+ if (lo->lo_offset > 0)
+ loopsize -= lo->lo_offset;
/* offset is beyond i_size, weird but possible */
if (loopsize < 0)
return 0;
-
- if (sizelimit > 0 && sizelimit < loopsize)
- loopsize = sizelimit;
+ 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.
@@ -158,11 +156,6 @@ static loff_t get_size(loff_t offset, loff_t sizelimit, struct file *file)
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);
-}
-
/*
* We support direct I/O only if lo_offset is aligned with the logical I/O size
* of backing device, and the logical block size of loop is bigger than that of
@@ -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;
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] loop: use vfs_getattr_nosec for accurate file size
2025-08-25 22:17 [PATCH v5] fixed the blok file statx issue Cloud User
2025-08-25 22:17 ` [PATCH 1/2] loop: Rename and merge get_size/get_loop_size to lo_calculate_size Cloud User
@ 2025-08-25 22:17 ` Cloud User
2025-08-26 0:49 ` [PATCH v5] fixed the blok file statx issue Yu Kuai
2 siblings, 0 replies; 5+ messages in thread
From: Cloud User @ 2025-08-25 22:17 UTC (permalink / raw)
To: Yu Kuai, ming.lei, hch, yukuai3, rajeevm
Cc: linux-block, linux-kernel, yi.zhang, yangerkun, johnny.chenyi
From: Rajeev Mishra <rajeevm@hpe.com>
In lo_calculate_size(), use vfs_getattr_nosec() for non-block files.
For block files, continue using i_size_read(). This improves size
accuracy on network and distributed filesystems.
Signed-off-by: Rajeev Mishra <rajeevm@hpe.com>
---
drivers/block/loop.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 0e1b9eb9db10..a6214ae40ef0 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -139,9 +139,24 @@ static int part_shift;
static loff_t lo_calculate_size(struct loop_device *lo, struct file *file)
{
+ struct kstat stat;
loff_t loopsize;
- /* Compute loopsize in bytes */
- loopsize = i_size_read(file->f_mapping->host);
+ int ret;
+
+ /*
+ * Get the accurate file size. This provides better results than
+ * cached inode data, particularly for network filesystems where
+ * metadata may be stale.
+ */
+ if (S_ISBLK(file->f_inode->i_mode)) {
+ loopsize = i_size_read(file->f_mapping->host);
+ } else {
+ ret = vfs_getattr_nosec(&file->f_path, &stat, STATX_SIZE, 0);
+ if (ret)
+ return 0;
+ loopsize = stat.size;
+ }
+
if (lo->lo_offset > 0)
loopsize -= lo->lo_offset;
/* offset is beyond i_size, weird but possible */
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v5] fixed the blok file statx issue
2025-08-25 22:17 [PATCH v5] fixed the blok file statx issue Cloud User
2025-08-25 22:17 ` [PATCH 1/2] loop: Rename and merge get_size/get_loop_size to lo_calculate_size Cloud User
2025-08-25 22:17 ` [PATCH 2/2] loop: use vfs_getattr_nosec for accurate file size Cloud User
@ 2025-08-26 0:49 ` Yu Kuai
2025-08-26 2:58 ` Cloud User
2 siblings, 1 reply; 5+ messages in thread
From: Yu Kuai @ 2025-08-26 0:49 UTC (permalink / raw)
To: Cloud User, Yu Kuai, ming.lei, hch
Cc: linux-block, linux-kernel, yi.zhang, yangerkun, johnny.chenyi,
yukuai (C)
Hi,
在 2025/08/26 6:17, Cloud User 写道:
> This fixes the statx issue which caused multiple test issue
>
> Rajeev Mishra (2):
> loop: Rename and merge get_size/get_loop_size to lo_calculate_size
> loop: use vfs_getattr_nosec for accurate file size
>
> drivers/block/loop.c | 43 +++++++++++++++++++++++++------------------
> 1 file changed, 25 insertions(+), 18 deletions(-)
>
There is no need, to late for this now. :(
Thanks,
Kuai
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5] fixed the blok file statx issue
2025-08-26 0:49 ` [PATCH v5] fixed the blok file statx issue Yu Kuai
@ 2025-08-26 2:58 ` Cloud User
0 siblings, 0 replies; 5+ messages in thread
From: Cloud User @ 2025-08-26 2:58 UTC (permalink / raw)
To: Cloud User, Yu Kuai, ming.lei, hch
Cc: linux-block, linux-kernel, yi.zhang, yangerkun, johnny.chenyi,
yukuai
Hi,
在 2025/08/26 6:17, Cloud User 写道:
> This fixes the statx issue which caused multiple test issue
>
> Rajeev Mishra (2):
> loop: Rename and merge get_size/get_loop_size to lo_calculate_size
> loop: use vfs_getattr_nosec for accurate file size
>
> drivers/block/loop.c | 43 +++++++++++++++++++++++++------------------
> 1 file changed, 25 insertions(+), 18 deletions(-)
>
There is no need, to late for this now. :(
>>> Thanks Kuai for your continued support. I just want to make sure the original
>>>> fix which calls vfs_getattr_nosec in lo_calculate_size is not getting
>>> discarded. Again thanks for your quick response
Thanks,
Kuai
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-26 2:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-25 22:17 [PATCH v5] fixed the blok file statx issue Cloud User
2025-08-25 22:17 ` [PATCH 1/2] loop: Rename and merge get_size/get_loop_size to lo_calculate_size Cloud User
2025-08-25 22:17 ` [PATCH 2/2] loop: use vfs_getattr_nosec for accurate file size Cloud User
2025-08-26 0:49 ` [PATCH v5] fixed the blok file statx issue Yu Kuai
2025-08-26 2:58 ` Cloud User
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).