Patchwork Improve error reporting on file access

login
register
mail settings
Submitter Markus Armbruster
Date Oct. 27, 2009, 4:51 p.m.
Message ID <m3k4ygg4ps.fsf@crossbow.pond.sub.org>
Download mbox | patch
Permalink /patch/37005/
State New
Headers show

Comments

Markus Armbruster - Oct. 27, 2009, 4:51 p.m.
Mark McLoughlin <markmc@redhat.com> writes:

> On Thu, 2009-10-01 at 09:42 -0500, Justin M. Forbes wrote:
>> Author: Justin M. Forbes <jforbes@redhat.com>
>> Date:   Thu Oct 1 09:34:56 2009 -0500
>> 
>>     Improve error reporting on file access
>>     
>>     By making the error reporting include strerror(errno), it gives the user
>>     a bit more indication as to why qemu failed.  This is particularly
>>     important for people running qemu as a non root user.
>>     
>>     Signed-off-by: Justin M. Forbes <jforbes@redhat.com>
>
> Certainly looks sensible to me
>
> Not having this is hurting us in Fedora 12 because we've started running
> qemu as an unprivileged user and people are having a hard time figuring
> out the various errors they're seeing caused by the change. This should
> help them.
>
> Only concern is that errno might not be getting propagated correctly by
> some of these functions, but we can fix that later if so.

Here's one:

bdrv_open2() returns the error code.  Usually, it also leaves it in
errno, but not always.  Try:

    $ >mt.img
    $ ~/work/qemu/bld/qemu-img create -f qcow2 -b mt.img mt.qcow2
    Formatting 'mt.qcow2', fmt=qcow2 size=0 backing_file='mt.img' encryption=off cluster_size=0 
    $ qemu [...] -drive file=mt.qcow2
    qemu: could not open disk image mt.qcow2: Success
malc - Oct. 27, 2009, 5:38 p.m.
On Tue, 27 Oct 2009, Markus Armbruster wrote:

> Mark McLoughlin <markmc@redhat.com> writes:
> 
> > On Thu, 2009-10-01 at 09:42 -0500, Justin M. Forbes wrote:
> >> Author: Justin M. Forbes <jforbes@redhat.com>
> >> Date:   Thu Oct 1 09:34:56 2009 -0500
> >> 
> >>     Improve error reporting on file access
> >>     
> >>     By making the error reporting include strerror(errno), it gives the user
> >>     a bit more indication as to why qemu failed.  This is particularly
> >>     important for people running qemu as a non root user.
> >>     
> >>     Signed-off-by: Justin M. Forbes <jforbes@redhat.com>
> >
> > Certainly looks sensible to me
> >
> > Not having this is hurting us in Fedora 12 because we've started running
> > qemu as an unprivileged user and people are having a hard time figuring
> > out the various errors they're seeing caused by the change. This should
> > help them.
> >
> > Only concern is that errno might not be getting propagated correctly by
> > some of these functions, but we can fix that later if so.
> 
> Here's one:
> 
> diff --git a/vl.c b/vl.c
> index 7bfd415..70fd2ca 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2232,8 +2232,8 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
>      }
> 
>      if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
> -        fprintf(stderr, "qemu: could not open disk image %s\n",
> -                        file);
> +        fprintf(stderr, "qemu: could not open disk image %s: %s\n",
> +                        file, strerror(errno));
>          return NULL;
>      }
> 

bdrv_open2 is not guaranteed to use POSIX functions for it's file
manipulation, hence the patch is wrong.
Andreas Färber - Nov. 29, 2009, 12:20 p.m.
Hello,

Am 27.10.2009 um 18:38 schrieb malc:

> On Tue, 27 Oct 2009, Markus Armbruster wrote:
>
>> Mark McLoughlin <markmc@redhat.com> writes:
>>
>>> On Thu, 2009-10-01 at 09:42 -0500, Justin M. Forbes wrote:
>>>> Author: Justin M. Forbes <jforbes@redhat.com>
>>>> Date:   Thu Oct 1 09:34:56 2009 -0500
>>>>
>>>>    Improve error reporting on file access
>>>>
>>>>    By making the error reporting include strerror(errno), it  
>>>> gives the user
>>>>    a bit more indication as to why qemu failed.  This is  
>>>> particularly
>>>>    important for people running qemu as a non root user.
>>>>
>>>>    Signed-off-by: Justin M. Forbes <jforbes@redhat.com>

>>> Only concern is that errno might not be getting propagated  
>>> correctly by
>>> some of these functions, but we can fix that later if so.
>>
>> Here's one:
>>
>> diff --git a/vl.c b/vl.c
>> index 7bfd415..70fd2ca 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -2232,8 +2232,8 @@ DriveInfo *drive_init(QemuOpts *opts, void  
>> *opaque,
>>     }
>>
>>     if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
>> -        fprintf(stderr, "qemu: could not open disk image %s\n",
>> -                        file);
>> +        fprintf(stderr, "qemu: could not open disk image %s: %s\n",
>> +                        file, strerror(errno));
>>         return NULL;
>>     }
>>
>
> bdrv_open2 is not guaranteed to use POSIX functions for it's file
> manipulation, hence the patch is wrong.

It appears, the patch was applied in  
850810d01b45e6ce99ac6696773e967890db2937 (Oct 5).

On OpenSolaris 2009.06 amd64 I now get:

qemu: could not open disk image /[...].iso: Not owner

I am owner though. If I run it with pfexec (priviledged), I get:

qemu: could not open disk image /[...].iso: No such file or directory

The file is there and my script used to work before Juan's Makefile  
reorganization with the --whole-archive workaround I posted.

So my guess is, we do see a stray errno here?

Andreas
Markus Armbruster - Jan. 18, 2010, 5:43 p.m.
Andreas Färber <andreas.faerber@web.de> writes:

> Hello,
>
> Am 27.10.2009 um 18:38 schrieb malc:
>
>> On Tue, 27 Oct 2009, Markus Armbruster wrote:
>>
>>> Mark McLoughlin <markmc@redhat.com> writes:
>>>
>>>> On Thu, 2009-10-01 at 09:42 -0500, Justin M. Forbes wrote:
>>>>> Author: Justin M. Forbes <jforbes@redhat.com>
>>>>> Date:   Thu Oct 1 09:34:56 2009 -0500
>>>>>
>>>>>    Improve error reporting on file access
>>>>>
>>>>>    By making the error reporting include strerror(errno), it
>>>>> gives the user
>>>>>    a bit more indication as to why qemu failed.  This is
>>>>> particularly
>>>>>    important for people running qemu as a non root user.
>>>>>
>>>>>    Signed-off-by: Justin M. Forbes <jforbes@redhat.com>
>
>>>> Only concern is that errno might not be getting propagated
>>>> correctly by
>>>> some of these functions, but we can fix that later if so.
>>>
>>> Here's one:
>>>
>>> diff --git a/vl.c b/vl.c
>>> index 7bfd415..70fd2ca 100644
>>> --- a/vl.c
>>> +++ b/vl.c
>>> @@ -2232,8 +2232,8 @@ DriveInfo *drive_init(QemuOpts *opts, void
>>> *opaque,
>>>     }
>>>
>>>     if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
>>> -        fprintf(stderr, "qemu: could not open disk image %s\n",
>>> -                        file);
>>> +        fprintf(stderr, "qemu: could not open disk image %s: %s\n",
>>> +                        file, strerror(errno));
>>>         return NULL;
>>>     }
>>>
>>
>> bdrv_open2 is not guaranteed to use POSIX functions for it's file
>> manipulation, hence the patch is wrong.
>
> It appears, the patch was applied in
> 850810d01b45e6ce99ac6696773e967890db2937 (Oct 5).
>
> On OpenSolaris 2009.06 amd64 I now get:
>
> qemu: could not open disk image /[...].iso: Not owner
>
> I am owner though. If I run it with pfexec (priviledged), I get:
>
> qemu: could not open disk image /[...].iso: No such file or directory
>
> The file is there and my script used to work before Juan's Makefile
> reorganization with the --whole-archive workaround I posted.
>
> So my guess is, we do see a stray errno here?
>
> Andreas

As malc said, the patch is wrong.  It should be reverted until somebody
comes up with a fix.

Patch

diff --git a/vl.c b/vl.c
index 7bfd415..70fd2ca 100644
--- a/vl.c
+++ b/vl.c
@@ -2232,8 +2232,8 @@  DriveInfo *drive_init(QemuOpts *opts, void *opaque,
     }

     if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
-        fprintf(stderr, "qemu: could not open disk image %s\n",
-                        file);
+        fprintf(stderr, "qemu: could not open disk image %s: %s\n",
+                        file, strerror(errno));
         return NULL;
     }