qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: jordan.l.justen@intel.com, qemu-devel@nongnu.org, anthony@codemonkey.ws
Subject: Re: [Qemu-devel] [PATCH 1/2] pc_sysfw: Check for qemu_find_file() failure
Date: Thu, 16 Aug 2012 11:03:59 -0300	[thread overview]
Message-ID: <20120816110359.7a88e552@doriath.home> (raw)
In-Reply-To: <87txw3djyc.fsf@blackfin.pond.sub.org>

On Thu, 16 Aug 2012 15:50:51 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
> > On Thu, 16 Aug 2012 13:41:12 +0200
> > Markus Armbruster <armbru@redhat.com> wrote:
> >
> >> pc_fw_add_pflash_drv() ignores qemu_find_file() failure, and happily
> >> creates a drive without a medium.
> >> 
> >> When pc_system_flash_init() asks for its size, bdrv_getlength() fails
> >> with -ENOMEDIUM, which isn't checked either.  It fails relatively
> >> cleanly only because -ENOMEDIUM isn't a multiple of 4096:
> >> 
> >>     $ qemu-system-x86_64 -S -vnc :0 -bios nonexistant
> >>     qemu: PC system firmware (pflash) must be a multiple of 0x1000
> >>     [Exit 1 ]
> >> 
> >> Fix by handling the qemu_find_file() failure.
> >> 
> >> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> >> ---
> >>  hw/pc_sysfw.c | 5 +++++
> >>  1 file changed, 5 insertions(+)
> >> 
> >> diff --git a/hw/pc_sysfw.c b/hw/pc_sysfw.c
> >> index b45f0ac..fd22154 100644
> >> --- a/hw/pc_sysfw.c
> >> +++ b/hw/pc_sysfw.c
> >> @@ -84,6 +84,11 @@ static void pc_fw_add_pflash_drv(void)
> >>          bios_name = BIOS_FILENAME;
> >>      }
> >>      filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
> >> +    if (!filename) {
> >> +        error_report("Can't open BIOS image %s: %s",
> >> +                     bios_name, strerror(errno));
> >
> > Why not use plain fprintf()? This is called from machine init time, I
> > don't think this is ever called in monitor context.
> 
> error_report() makes the fact that's an error message obvious and
> greppable. 

fprintf(stderr, ...) too.

> It also prepends the message with PROGNAME:, which is better
> than literal "qemu:" when the executable isn't called qemu.

We can't spread error_report() usage just because of that. I mean, we're not
going to replace every usage of fprintf(stderr, ...) with error_report() just
because of that, right?

For this fix, I suggest calling fprintf() plus abort(), which is what is
done by the caller and several functions in the call chain.

For the long term, I suggest adding:

 o error_printf() prepend PROGNAME and calls fprintf()
 o die(): calls error_printf() and exit(1)

>  It would
> even point to -bios nicely if we bothered to preserve that information
> (we lose it by storing the option argument as naked char * without the
> location).
> 
> > Also, maybe you could add the following patch to this series?
> >
> >  http://lists.gnu.org/archive/html/qemu-devel/2012-06/msg04686.html
> 
> Can do in case I need to respin anyway.
> 
> > Although I'm not sure it qualifies for hard-freeze...
> 
> I didn't tag my series "for-1.2".  I understand that fixes to
> not-so-important stuff aren't welcome at this time even when they're
> really simple.
> 
> >> +        exit(1);
> >> +    }
> >>  
> >>      opts = drive_add(IF_PFLASH, -1, filename, "readonly=on");
> >>  
> 

  parent reply	other threads:[~2012-08-16 14:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-16 11:41 [Qemu-devel] [PATCH 0/2] Fix two buggy pc_sysfw error paths Markus Armbruster
2012-08-16 11:41 ` [Qemu-devel] [PATCH 1/2] pc_sysfw: Check for qemu_find_file() failure Markus Armbruster
2012-08-16 13:30   ` Luiz Capitulino
2012-08-16 13:50     ` Markus Armbruster
2012-08-16 13:58       ` Kevin Wolf
2012-08-16 14:03       ` Luiz Capitulino [this message]
2012-08-16 14:32         ` Markus Armbruster
2012-08-16 14:49           ` Luiz Capitulino
2012-08-16 15:12             ` Markus Armbruster
2012-08-16 16:49               ` Luiz Capitulino
2012-08-16 17:58                 ` Luiz Capitulino
2012-08-16 17:10   ` Jordan Justen
2012-08-16 11:41 ` [Qemu-devel] [PATCH 2/2] pc_sysfw: Plug memory leak on pc_fw_add_pflash_drv() error path Markus Armbruster
  -- strict thread matches above, loose matches on Subject: below --
2012-11-23 18:12 [Qemu-devel] [PATCH 0/2] pc_fw_add_pflash_drv() fixes Markus Armbruster
2012-11-23 18:12 ` [Qemu-devel] [PATCH 1/2] pc_sysfw: Check for qemu_find_file() failure Markus Armbruster

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=20120816110359.7a88e552@doriath.home \
    --to=lcapitulino@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=armbru@redhat.com \
    --cc=jordan.l.justen@intel.com \
    --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).