From: Jens Axboe <axboe@kernel.dk>
To: Yu Kuai <yukuai1@huaweicloud.com>,
ming.lei@redhat.com, hch@infradead.org, yukuai3@huawei.com,
rajeevm@hpe.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
yi.zhang@huawei.com, yangerkun@huawei.com,
johnny.chenyi@huawei.com
Subject: Re: [PATCH v2] loop: fix zero sized loop for block special file
Date: Mon, 25 Aug 2025 07:56:02 -0600 [thread overview]
Message-ID: <36f30d8d-02fb-4579-b527-16da24cdc856@kernel.dk> (raw)
In-Reply-To: <20250825093205.3684121-1-yukuai1@huaweicloud.com>
On 8/25/25 3:32 AM, Yu Kuai wrote:
> static loff_t lo_calculate_size(struct loop_device *lo, struct file *file)
> {
> - struct kstat stat;
> loff_t loopsize;
> int ret;
>
> - /*
> - * Get the accurate file size. This provides better results than
> - * cached inode data, particularly for network filesystems where
> - * metadata may be stale.
> - */
> - ret = vfs_getattr_nosec(&file->f_path, &stat, STATX_SIZE, 0);
> - if (ret)
> - return 0;
> + if (S_ISBLK(file_inode(file)->i_mode)) {
> + loopsize = i_size_read(file->f_mapping->host);
> + } else {
> + struct kstat stat;
> +
> + /*
> + * Get the accurate file size. This provides better results than
> + * cached inode data, particularly for network filesystems where
> + * metadata may be stale.
> + */
> + ret = vfs_getattr_nosec(&file->f_path, &stat, STATX_SIZE, 0);
> + if (ret)
> + return 0;
> +
> + loopsize = stat.size;
> + }
Gah, that was pretty silly...
--
Jens Axboe
next prev parent reply other threads:[~2025-08-25 13:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-25 9:32 Yu Kuai
2025-08-25 10:48 ` Christoph Hellwig
2025-08-25 11:26 ` Ming Lei
2025-08-25 13:47 ` Jens Axboe
2025-08-25 13:56 ` Jens Axboe [this message]
2025-08-25 18:17 ` Cloud User
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=36f30d8d-02fb-4579-b527-16da24cdc856@kernel.dk \
--to=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=johnny.chenyi@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=rajeevm@hpe.com \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai1@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
all inboxes | Powered by JetHome®