From: "Cédric Le Goater" <clg@kaod.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Alistair Francis" <alistair@alistair23.me>,
"Francisco Iglesias" <frasse.iglesias@gmail.com>,
"Kevin Wolf" <kwolf@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Peter Delevoryas" <peter@pjd.dev>,
qemu-block@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH] m25p80: Warn the user when the backend file is too small for the device
Date: Tue, 15 Nov 2022 15:51:35 +0100 [thread overview]
Message-ID: <566a0720-f732-cb27-a98f-367e1981a02f@kaod.org> (raw)
In-Reply-To: <CAFEAcA9OiNsX4-O60zKXL8WoEJbOH2TQr3LwDFJH4SOS8EPTMg@mail.gmail.com>
On 11/15/22 15:34, Peter Maydell wrote:
> On Tue, 15 Nov 2022 at 14:22, Cédric Le Goater <clg@kaod.org> wrote:
>>
>> Currently, when a block backend is attached to a m25p80 device and the
>> associated file size does not match the flash model, QEMU complains
>> with the error message "failed to read the initial flash content".
>> This is confusing for the user.
>
> The commit message says we get an unhelpful error if the
> file size "does not match"...
>
>> Improve the reported error with a new message regarding the file size.
>>
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> ---
>> hw/block/m25p80.c | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
>> index 02adc87527..e0515e2a1e 100644
>> --- a/hw/block/m25p80.c
>> +++ b/hw/block/m25p80.c
>> @@ -1606,6 +1606,14 @@ static void m25p80_realize(SSIPeripheral *ss, Error **errp)
>> if (s->blk) {
>> uint64_t perm = BLK_PERM_CONSISTENT_READ |
>> (blk_supports_write_perm(s->blk) ? BLK_PERM_WRITE : 0);
>> +
>> + if (blk_getlength(s->blk) < s->size) {
>
> ...but the code change is only checking for "too small".
>
> What happens if the user provides a backing file that is too large ?
That's ok because the blk_pread() call following, which loads in RAM
the initial data, won't fail.
It might be better to enforce a strict check on the size to avoid
further confusion ? and change the error message to be clear.
>
>> + error_setg(errp,
>> + "backend file is too small for flash device %s (%d MB)",
>> + object_class_get_name(OBJECT_CLASS(mc)), s->size >> 20);
>
> This potentially reports to the user a size which isn't the
> right one for them to use to set the size of the backing file,
> if that required size isn't an exact number of MB.
True. We have a few devices which size is below 1MB. Using a KB unit
should be fine.
Thanks,
C.
>
>> + return;
>> + }
>> +
>> ret = blk_set_perm(s->blk, perm, BLK_PERM_ALL, errp);
>> if (ret < 0) {
>> return;
>> --
>> 2.38.1
>
> thanks
> -- PMM
next prev parent reply other threads:[~2022-11-15 14:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 14:21 [PATCH] m25p80: Warn the user when the backend file is too small for the device Cédric Le Goater
2022-11-15 14:34 ` Peter Maydell
2022-11-15 14:51 ` Cédric Le Goater [this message]
2022-11-15 14:55 ` Peter Maydell
2022-11-15 14:56 ` Cédric Le Goater
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=566a0720-f732-cb27-a98f-367e1981a02f@kaod.org \
--to=clg@kaod.org \
--cc=alistair@alistair23.me \
--cc=frasse.iglesias@gmail.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peter@pjd.dev \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).