Skip to contentSkip to conversation

Improve error reporting on file access

PATCH In review Justin M. Forbes 5 participants 6 messages Oct 1, 2009 – Jan 18, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Improve error reporting on file access

commit 1755cdcf9c6328bdcc8558a38af774e31421a145

Author: Justin M. Forbes <[email protected]>
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.

hw/pc.c +6 -6
index bc2875e..8e54fa4 100644
@@ -844,8 +844,8 @@ static void load_linux(void *fw_cfg,
     if (!f || !(kernel_size = get_file_size(f)) ||
 	fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) !=
 	MIN(ARRAY_SIZE(header), kernel_size)) {
-	fprintf(stderr, "qemu: could not load kernel '%s'\n",
-		kernel_filename);
+	fprintf(stderr, "qemu: could not load kernel '%s': %s\n",
+		kernel_filename, strerror(errno));
 	exit(1);
     }
 
@@ -950,8 +950,8 @@ static void load_linux(void *fw_cfg,
 
 	fi = fopen(initrd_filename, "rb");
 	if (!fi) {
-	    fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
-		    initrd_filename);
+	    fprintf(stderr, "qemu: could not load initial ram disk '%s': %s\n",
+		    initrd_filename, strerror(errno));
 	    exit(1);
 	}
 
@@ -959,8 +959,8 @@ static void load_linux(void *fw_cfg,
 	initrd_addr = (initrd_max-initrd_size) & ~4095;
 
 	if (!fread_targphys_ok(initrd_addr, initrd_size, fi)) {
-	    fprintf(stderr, "qemu: read error on initial ram disk '%s'\n",
-		    initrd_filename);
+	    fprintf(stderr, "qemu: read error on initial ram disk '%s': %s\n",
+		    initrd_filename, strerror(errno));
 	    exit(1);
 	}
 	fclose(fi);
vl.c +10 -10
index 7bfd415..70fd2ca 100644
@@ -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;
     }
 
@@ -5487,7 +5487,7 @@ int main(int argc, char **argv, char **envp)
             if (len != 1)
                 exit(1);
             else if (status == 1) {
-                fprintf(stderr, "Could not acquire pidfile\n");
+                fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno));
                 exit(1);
             } else
                 exit(0);
@@ -5514,7 +5514,7 @@ int main(int argc, char **argv, char **envp)
             uint8_t status = 1;
             write(fds[1], &status, 1);
         } else
-            fprintf(stderr, "Could not acquire pid file\n");
+            fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
         exit(1);
     }
 #endif
@@ -5699,8 +5699,8 @@ int main(int argc, char **argv, char **envp)
             snprintf(label, sizeof(label), "serial%d", i);
             serial_hds[i] = qemu_chr_open(label, devname, NULL);
             if (!serial_hds[i]) {
-                fprintf(stderr, "qemu: could not open serial device '%s'\n",
-                        devname);
+                fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
+                        devname, strerror(errno));
                 exit(1);
             }
         }
@@ -5713,8 +5713,8 @@ int main(int argc, char **argv, char **envp)
             snprintf(label, sizeof(label), "parallel%d", i);
             parallel_hds[i] = qemu_chr_open(label, devname, NULL);
             if (!parallel_hds[i]) {
-                fprintf(stderr, "qemu: could not open parallel device '%s'\n",
-                        devname);
+                fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
+                        devname, strerror(errno));
                 exit(1);
             }
         }
@@ -5727,8 +5727,8 @@ int main(int argc, char **argv, char **envp)
             snprintf(label, sizeof(label), "virtcon%d", i);
             virtcon_hds[i] = qemu_chr_open(label, devname, NULL);
             if (!virtcon_hds[i]) {
-                fprintf(stderr, "qemu: could not open virtio console '%s'\n",
-                        devname);
+                fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
+                        devname, strerror(errno));
                 exit(1);
             }
         }
#1 lore raw
Quoted 10 lines · Justin M. Forbes
Author: Justin M. Forbes <[email protected]>
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.

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.

Cheers,
Mark.

#2 lore raw
Quoted 14 lines · Mark McLoughlin
Quoted 10 lines · Justin M. Forbes
Author: Justin M. Forbes <[email protected]>
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.

Certainly looks sensible to me

Quoted 7 lines

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:

vl.c +2 -2
index 7bfd415..70fd2ca 100644
@@ -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() 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
#3 lore raw
Quoted 31 lines · Markus Armbruster
Quoted 14 lines · Mark McLoughlin
Quoted 10 lines · Justin M. Forbes
Author: Justin M. Forbes <[email protected]>
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.

Certainly looks sensible to me

Quoted 7 lines

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:

vl.c +0 -0
index 7bfd415..70fd2ca 100644

vl.c DriveInfo *drive_init(QemuOpts *opts, void *opaque, · line 2239

Quoted 10 lines
vl.c +2 -2
@@ -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.

Signature · 1 line
mailto:[email protected]
#4 lore raw

Hello,

Am 27.10.2009 um 18:38 schrieb malc:

Quoted 31 lines · Markus Armbruster
Quoted 30 lines
Quoted 12 lines · Mark McLoughlin
Quoted 11 lines · Justin M. Forbes
Author: Justin M. Forbes <[email protected]>
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.

Quoted 4 lines
Quoted 1 line

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:

vl.c +0 -0
index 7bfd415..70fd2ca 100644
@@ -2232,8 +2232,8 @@ DriveInfo *drive_init(QemuOpts *opts, void  
 *opaque,
    }
 
Quoted 11 lines

vl.c DriveInfo *drive_init(QemuOpts *opts, void *opaque, · line 2238

Quoted 8 lines
vl.c +2 -2
    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

#5 lore raw
Quoted 57 lines · Andreas Färber

Hello,

Am 27.10.2009 um 18:38 schrieb malc:

Quoted 32 lines · Markus Armbruster
Quoted 31 lines
Quoted 12 lines · Mark McLoughlin
Quoted 11 lines · Justin M. Forbes
Author: Justin M. Forbes <[email protected]>
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.

Quoted 5 lines
Quoted 1 line

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:

vl.c +0 -0
index 7bfd415..70fd2ca 100644
@@ -2232,8 +2232,8 @@ DriveInfo *drive_init(QemuOpts *opts, void
 *opaque,
    }
 
Quoted 11 lines

vl.c DriveInfo *drive_init(QemuOpts *opts, void *opaque, · line 2238

Quoted 8 lines
vl.c +2 -2
    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:

Quoted 8 lines

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.