Skip to contentSkip to conversation

screendump qapi convertion

PATCH Superseded Alon Levy 2 participants 31 messages Mar 14, 2012 – Mar 26, 2012 Kbuild

lore
Share & tools
lore

Alon Levy

author
#0 lore raw

v2 cover screendump qapi convertion

The blockdev patch is more RFC'ish, and not actually related. It is just a natural candidate to reuse the error_set_file_open_failed introduced by the first patch for usage in ppm_save but also useful for other places that all call fopen.

v2 changes:
split screendump convertion to an addition "add Error** param" handle various errors of fopen with new qerror codes

Alon Levy (4):
error: add error_set_file_open_failed
vga_hw_screen_dump: add Error** param
qapi: convert screendump
blockdev: use error_set_file_open_failed

Luiz Capitulino (1):
vga: ppm_save(): Return error on failure

 blockdev.c           |   11 +++++++----
 console.c            |    5 +++--
 console.h            |    6 ++++--
 cpus.c               |    4 ++--
 error.c              |   44 ++++++++++++++++++++++++++++++++++++++++++++
 error.h              |    4 ++++
 hmp-commands.hx      |    3 +--
 hmp.c                |    8 ++++++++
 hmp.h                |    1 +
 hw/blizzard.c        |    5 +++--
 hw/g364fb.c          |    4 +++-
 hw/omap_lcdc.c       |    4 +++-
 hw/qxl.c             |    8 +++++---
 hw/tcx.c             |   13 +++++++++----
 hw/vga.c             |   15 ++++++++++-----
 hw/vga_int.h         |    3 ++-
 hw/vmware_vga.c      |    8 +++++---
 monitor.c            |    6 ------
 qapi-schema.json     |   13 +++++++++++++
 qerror.c             |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h             |   27 +++++++++++++++++++++++++++
 qga/commands-posix.c |    2 +-
 qmp-commands.hx      |    5 +----
 qmp.c                |    5 +++++
 24 files changed, 197 insertions(+), 43 deletions(-)
Signature · 1 line
1.7.9.3
author
#1 lore raw

PATCH v2 1/5 error: add error_set_file_open_failed

---
 cpus.c               |    4 ++--
 error.c              |   44 ++++++++++++++++++++++++++++++++++++++++++++
 error.h              |    4 ++++
 qerror.c             |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h             |   27 +++++++++++++++++++++++++++
 qga/commands-posix.c |    2 +-
 6 files changed, 114 insertions(+), 3 deletions(-)
cpus.c +2 -2
index 17b055f..c87035f 100644
@@ -1178,7 +1178,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set_file_open_failed(errp, filename, errno);
         return;
     }
 
@@ -1208,7 +1208,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set_file_open_failed(errp, filename, errno);
         return;
     }
 
error.c +44 -0

47 lines not on this page · raw message

error.h +4 -0
index 6361f40..f3a80f3 100644
@@ -67,4 +67,8 @@ void error_free(Error *err);
  */
 bool error_is_type(Error *err, const char *fmt);
 
+/**
+ * Helper to set error for a open (2) style return code.
+ */
+void error_set_file_open_failed(Error **errp, const char *file_name, int ret);
 #endif
qerror.c +36 -0
index f55d435..23c260b 100644
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_OPEN_FILE_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EACCES,
+        .desc      = "Cannot access '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EEXIST,
+        .desc      = "File already exists '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_ENOSPC,
+        .desc      = "No space left opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EPERM,
+        .desc      = "Permission denied (EPERM) for '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EROFS,
+        .desc      = "Read only filesystem opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_ENOTDIR,
+        .desc      = "Directory related error opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EFBIG,
+        .desc      = "File too big opening '%(filename)'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +27 -0
index e26c635..6ab9b8d 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_OPEN_FILE_EINTR \
+    "{ 'class': 'OpenFileEINTR', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EACCES \
+    "{ 'class': 'OpenFileEACCES', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EEXIST \
+    "{ 'class': 'OpenFileEEXIST', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EMFILE \
+    "{ 'class': 'OpenFileEMFILE', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_ENOSPC \
+    "{ 'class': 'OpenFileENOSPC', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EPERM \
+    "{ 'class': 'OpenFileEPERM', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EROFS \
+    "{ 'class': 'OpenFileEROFS', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_ENOTDIR \
+    "{ 'class': 'OpenFileENOTDIR', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EFBIG \
+    "{ 'class': 'OpenFileEFBIG', 'data': { 'filename': %s } }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
qga/commands-posix.c +1 -1
index 7b2be2f..4e5ef7f 100644
@@ -134,7 +134,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E
     slog("guest-file-open called, filepath: %s, mode: %s", path, mode);
     fh = fopen(path, mode);
     if (!fh) {
-        error_set(err, QERR_OPEN_FILE_FAILED, path);
+        error_set_file_open_failed(err, path, errno);
         return -1;
     }
 
Signature · 1 line
1.7.9.3
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/5] error: add error_set_file_open_failed

Quoted 37 lines · On Thu, 15 Mar 2012 00:55:10 +0200 Alon Levy <[email protected]> wrote:
---
 cpus.c               |    4 ++--
 error.c              |   44 ++++++++++++++++++++++++++++++++++++++++++++
 error.h              |    4 ++++
 qerror.c             |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h             |   27 +++++++++++++++++++++++++++
 qga/commands-posix.c |    2 +-
 6 files changed, 114 insertions(+), 3 deletions(-)
cpus.c +2 -2
index 17b055f..c87035f 100644
@@ -1178,7 +1178,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set_file_open_failed(errp, filename, errno);
         return;
     }
 
@@ -1208,7 +1208,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set_file_open_failed(errp, filename, errno);
         return;
     }
 
error.c +0 -0
index 990050f..b32d7f5 100644

error.c void error_set_qobject(Error **errp, QObject *obj) · line 149

Quoted 6 lines
error.c +3 -0
@@ -144,3 +144,47 @@ void error_set_qobject(Error **errp, QObject *obj)
 
     *errp = err;
 }
+
+void error_set_file_open_failed(Error **errp, const char *file_name, int ret)
+{

I prefer having:

void qemu_fopen_err(const char *filename, const char *mode, Error **errp);

It could live in osdep.c I think.

Also, please split this into two patches:

1. Add all the errors
2. Add qemu_fopen_err()

And don't change unrelated code. Other commands that will benefit from the new function should be converted in a different series.

CC'ing Anthony in case he has a different suggestion for the fopen() wrapper (of course we can an open() version too).

Quoted 59 lines
error.c +41 -0
+    const char *fmt = NULL;
+
+    switch (ret) {
+    case EACCES:
+        fmt = QERR_OPEN_FILE_EACCES;
+        break;
+    case EINTR:
+        fmt = QERR_OPEN_FILE_EINTR;
+        break;
+    case EEXIST:
+        fmt = QERR_OPEN_FILE_EEXIST;
+        break;
+    case EMFILE:
+        fmt = QERR_OPEN_FILE_EMFILE;
+        break;
+    case ENOSPC:
+        fmt = QERR_OPEN_FILE_ENOSPC;
+        break;
+    case EPERM:
+        fmt = QERR_OPEN_FILE_EPERM;
+        break;
+    case EROFS:
+        fmt = QERR_OPEN_FILE_EROFS;
+        break;
+    case ENOTDIR:
+        fmt = QERR_OPEN_FILE_ENOTDIR;
+        break;
+    case EFBIG:
+        fmt = QERR_OPEN_FILE_EFBIG;
+        break;
+    default:
+        /*
+         * EINVAL and ENOTSUP will result in the default
+         *
+         * ENOENT too, it's used by (for instance) bdrv_create_file for
+         * a different purpose then open (2) so just give a generic error.
+         */
+        fmt = QERR_OPEN_FILE_FAILED;
+    }
+    error_set(errp, fmt, file_name);
+}
error.h +4 -0
index 6361f40..f3a80f3 100644
@@ -67,4 +67,8 @@ void error_free(Error *err);
  */
 bool error_is_type(Error *err, const char *fmt);
 
+/**
+ * Helper to set error for a open (2) style return code.
+ */
+void error_set_file_open_failed(Error **errp, const char *file_name, int ret);
 #endif
qerror.c +0 -0
index f55d435..23c260b 100644

qerror.c static const QErrorStringTable qerror_table[] = { · line 218

Quoted 6 lines
qerror.c +3 -0
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_OPEN_FILE_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },

I see that you're adding _OPEN_FILE_ flavors to be able to pass the filename in the error. But this just workarounds a limitation of qerror: we should be able to set the error message at run-time.

I think the best thing to do is to have QERR_EINTR instead, with a generic message like "Operation has been interrupted" and we can improve QError to extend it to contain the file name.

This is valid for all errors below.

qerror.c static const QErrorStringTable qerror_table[] = { · line 222

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EACCES,
+        .desc      = "Cannot access '%(filename)'",
+    },

We already have PermissionDenied.

qerror.c static const QErrorStringTable qerror_table[] = { · line 226

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EEXIST,
+        .desc      = "File already exists '%(filename)'",
+    },

I wouldn't mind not having this one because most of the time qemu doesn't care if the file already exists.

qerror.c static const QErrorStringTable qerror_table[] = { · line 230

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening '%(filename)'",
+    },

This is an exception for what I said about _OPEN_FILE_ flavors above, this is fine because it's really a file error.

qerror.c static const QErrorStringTable qerror_table[] = { · line 238

Quoted 8 lines
qerror.c +8 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_ENOSPC,
+        .desc      = "No space left opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EPERM,
+        .desc      = "Permission denied (EPERM) for '%(filename)'",
+    },

I wouldn't mind reporting EACCESS and EPERM the same.

qerror.c static const QErrorStringTable qerror_table[] = { · line 242

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EROFS,
+        .desc      = "Read only filesystem opening '%(filename)'",
+    },

Let's have a QERR_READ_ONLY.

Quoted 63 lines
qerror.c +9 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_ENOTDIR,
+        .desc      = "Directory related error opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EFBIG,
+        .desc      = "File too big opening '%(filename)'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +27 -0
index e26c635..6ab9b8d 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_OPEN_FILE_EINTR \
+    "{ 'class': 'OpenFileEINTR', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EACCES \
+    "{ 'class': 'OpenFileEACCES', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EEXIST \
+    "{ 'class': 'OpenFileEEXIST', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EMFILE \
+    "{ 'class': 'OpenFileEMFILE', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_ENOSPC \
+    "{ 'class': 'OpenFileENOSPC', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EPERM \
+    "{ 'class': 'OpenFileEPERM', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EROFS \
+    "{ 'class': 'OpenFileEROFS', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_ENOTDIR \
+    "{ 'class': 'OpenFileENOTDIR', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EFBIG \
+    "{ 'class': 'OpenFileEFBIG', 'data': { 'filename': %s } }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
qga/commands-posix.c +1 -1
index 7b2be2f..4e5ef7f 100644
@@ -134,7 +134,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E
     slog("guest-file-open called, filepath: %s, mode: %s", path, mode);
     fh = fopen(path, mode);
     if (!fh) {
-        error_set(err, QERR_OPEN_FILE_FAILED, path);
+        error_set_file_open_failed(err, path, errno);
         return -1;
     }
 
author
#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/5] error: add error_set_file_open_failed

Quoted 49 lines · Luiz Capitulino
Quoted 37 lines · On Thu, 15 Mar 2012 00:55:10 +0200 Alon Levy <[email protected]> wrote:
---
 cpus.c               |    4 ++--
 error.c              |   44 ++++++++++++++++++++++++++++++++++++++++++++
 error.h              |    4 ++++
 qerror.c             |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h             |   27 +++++++++++++++++++++++++++
 qga/commands-posix.c |    2 +-
 6 files changed, 114 insertions(+), 3 deletions(-)
cpus.c +2 -2
index 17b055f..c87035f 100644
@@ -1178,7 +1178,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set_file_open_failed(errp, filename, errno);
         return;
     }
 
@@ -1208,7 +1208,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set_file_open_failed(errp, filename, errno);
         return;
     }
 
error.c +0 -0
index 990050f..b32d7f5 100644

error.c void error_set_qobject(Error **errp, QObject *obj) · line 149

Quoted 6 lines
error.c +3 -0
@@ -144,3 +144,47 @@ void error_set_qobject(Error **errp, QObject *obj)
 
     *errp = err;
 }
+
+void error_set_file_open_failed(Error **errp, const char *file_name, int ret)
+{

I prefer having:

Quoted 1 line

void qemu_fopen_err(const char *filename, const char *mode, Error **errp);

OK.

Quoted 2 lines

It could live in osdep.c I think.

OK.

Quoted 5 lines

Also, please split this into two patches:

1. Add all the errors
2. Add qemu_fopen_err()

OK.

Quoted 4 lines

And don't change unrelated code. Other commands that will benefit from the new function should be converted in a different series.

OK.

Quoted 73 lines

CC'ing Anthony in case he has a different suggestion for the fopen() wrapper (of course we can an open() version too).

Quoted 59 lines
error.c +41 -0
+    const char *fmt = NULL;
+
+    switch (ret) {
+    case EACCES:
+        fmt = QERR_OPEN_FILE_EACCES;
+        break;
+    case EINTR:
+        fmt = QERR_OPEN_FILE_EINTR;
+        break;
+    case EEXIST:
+        fmt = QERR_OPEN_FILE_EEXIST;
+        break;
+    case EMFILE:
+        fmt = QERR_OPEN_FILE_EMFILE;
+        break;
+    case ENOSPC:
+        fmt = QERR_OPEN_FILE_ENOSPC;
+        break;
+    case EPERM:
+        fmt = QERR_OPEN_FILE_EPERM;
+        break;
+    case EROFS:
+        fmt = QERR_OPEN_FILE_EROFS;
+        break;
+    case ENOTDIR:
+        fmt = QERR_OPEN_FILE_ENOTDIR;
+        break;
+    case EFBIG:
+        fmt = QERR_OPEN_FILE_EFBIG;
+        break;
+    default:
+        /*
+         * EINVAL and ENOTSUP will result in the default
+         *
+         * ENOENT too, it's used by (for instance) bdrv_create_file for
+         * a different purpose then open (2) so just give a generic error.
+         */
+        fmt = QERR_OPEN_FILE_FAILED;
+    }
+    error_set(errp, fmt, file_name);
+}
error.h +4 -0
index 6361f40..f3a80f3 100644
@@ -67,4 +67,8 @@ void error_free(Error *err);
  */
 bool error_is_type(Error *err, const char *fmt);
 
+/**
+ * Helper to set error for a open (2) style return code.
+ */
+void error_set_file_open_failed(Error **errp, const char *file_name, int ret);
 #endif
qerror.c +0 -0
index f55d435..23c260b 100644

qerror.c static const QErrorStringTable qerror_table[] = { · line 218

Quoted 6 lines
qerror.c +3 -0
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_OPEN_FILE_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },

I see that you're adding _OPEN_FILE_ flavors to be able to pass the filename in the error. But this just workarounds a limitation of qerror: we should be able to set the error message at run-time.

Quoted 4 lines

I think the best thing to do is to have QERR_EINTR instead, with a generic message like "Operation has been interrupted" and we can improve QError to extend it to contain the file name.

Sounds like we would not have the filename then, which would be a shame. But I don't mind doing that.

Quoted 9 lines

This is valid for all errors below.

qerror.c static const QErrorStringTable qerror_table[] = { · line 222

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EACCES,
+        .desc      = "Cannot access '%(filename)'",
+    },

We already have PermissionDenied.

Not the same use case - QERR_PERMISSION_DENIED is used for internal errors, not for an open / file related system permission error.

Quoted 7 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 226

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EEXIST,
+        .desc      = "File already exists '%(filename)'",
+    },

I wouldn't mind not having this one because most of the time qemu doesn't care if the file already exists.

I was really just going over everything open (2) manpage and copying what looked like it made sense. I can drop it.

Quoted 8 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 230

Quoted 5 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening '%(filename)'",
+    },

This is an exception for what I said about _OPEN_FILE_ flavors above, this is fine because it's really a file error.

They are all open (2) errors, see previous comment :)

Quoted 11 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 238

Quoted 9 lines
qerror.c +8 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_ENOSPC,
+        .desc      = "No space left opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EPERM,
+        .desc      = "Permission denied (EPERM) for '%(filename)'",
+    },

I wouldn't mind reporting EACCESS and EPERM the same.

But why do that? they are different at the system level, no reason to merge them. Except for EPERM being a bit cryptic (to me) it doesn't seem to be the same as EACCESS.

Quoted 7 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 242

Quoted 5 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EROFS,
+        .desc      = "Read only filesystem opening '%(filename)'",
+    },

Let's have a QERR_READ_ONLY.

OK.

Quoted 65 lines
Quoted 64 lines
qerror.c +9 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_ENOTDIR,
+        .desc      = "Directory related error opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EFBIG,
+        .desc      = "File too big opening '%(filename)'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +27 -0
index e26c635..6ab9b8d 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_OPEN_FILE_EINTR \
+    "{ 'class': 'OpenFileEINTR', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EACCES \
+    "{ 'class': 'OpenFileEACCES', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EEXIST \
+    "{ 'class': 'OpenFileEEXIST', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EMFILE \
+    "{ 'class': 'OpenFileEMFILE', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_ENOSPC \
+    "{ 'class': 'OpenFileENOSPC', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EPERM \
+    "{ 'class': 'OpenFileEPERM', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EROFS \
+    "{ 'class': 'OpenFileEROFS', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_ENOTDIR \
+    "{ 'class': 'OpenFileENOTDIR', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EFBIG \
+    "{ 'class': 'OpenFileEFBIG', 'data': { 'filename': %s } }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
qga/commands-posix.c +1 -1
index 7b2be2f..4e5ef7f 100644
@@ -134,7 +134,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E
     slog("guest-file-open called, filepath: %s, mode: %s", path, mode);
     fh = fopen(path, mode);
     if (!fh) {
-        error_set(err, QERR_OPEN_FILE_FAILED, path);
+        error_set_file_open_failed(err, path, errno);
         return -1;
     }
 
#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/5] error: add error_set_file_open_failed

Quoted 147 lines · On Thu, 15 Mar 2012 17:21:01 +0200 Alon Levy <[email protected]> wrote:
Quoted 49 lines · Luiz Capitulino
Quoted 37 lines · On Thu, 15 Mar 2012 00:55:10 +0200 Alon Levy <[email protected]> wrote:
---
 cpus.c               |    4 ++--
 error.c              |   44 ++++++++++++++++++++++++++++++++++++++++++++
 error.h              |    4 ++++
 qerror.c             |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h             |   27 +++++++++++++++++++++++++++
 qga/commands-posix.c |    2 +-
 6 files changed, 114 insertions(+), 3 deletions(-)
cpus.c +2 -2
index 17b055f..c87035f 100644
@@ -1178,7 +1178,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set_file_open_failed(errp, filename, errno);
         return;
     }
 
@@ -1208,7 +1208,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set_file_open_failed(errp, filename, errno);
         return;
     }
 
error.c +0 -0
index 990050f..b32d7f5 100644

error.c void error_set_qobject(Error **errp, QObject *obj) · line 149

Quoted 6 lines
error.c +3 -0
@@ -144,3 +144,47 @@ void error_set_qobject(Error **errp, QObject *obj)
 
     *errp = err;
 }
+
+void error_set_file_open_failed(Error **errp, const char *file_name, int ret)
+{

I prefer having:

Quoted 1 line

void qemu_fopen_err(const char *filename, const char *mode, Error **errp);

OK.

Quoted 2 lines

It could live in osdep.c I think.

OK.

Quoted 5 lines

Also, please split this into two patches:

1. Add all the errors
2. Add qemu_fopen_err()

OK.

Quoted 4 lines

And don't change unrelated code. Other commands that will benefit from the new function should be converted in a different series.

OK.

Quoted 73 lines

CC'ing Anthony in case he has a different suggestion for the fopen() wrapper (of course we can an open() version too).

Quoted 59 lines
error.c +41 -0
+    const char *fmt = NULL;
+
+    switch (ret) {
+    case EACCES:
+        fmt = QERR_OPEN_FILE_EACCES;
+        break;
+    case EINTR:
+        fmt = QERR_OPEN_FILE_EINTR;
+        break;
+    case EEXIST:
+        fmt = QERR_OPEN_FILE_EEXIST;
+        break;
+    case EMFILE:
+        fmt = QERR_OPEN_FILE_EMFILE;
+        break;
+    case ENOSPC:
+        fmt = QERR_OPEN_FILE_ENOSPC;
+        break;
+    case EPERM:
+        fmt = QERR_OPEN_FILE_EPERM;
+        break;
+    case EROFS:
+        fmt = QERR_OPEN_FILE_EROFS;
+        break;
+    case ENOTDIR:
+        fmt = QERR_OPEN_FILE_ENOTDIR;
+        break;
+    case EFBIG:
+        fmt = QERR_OPEN_FILE_EFBIG;
+        break;
+    default:
+        /*
+         * EINVAL and ENOTSUP will result in the default
+         *
+         * ENOENT too, it's used by (for instance) bdrv_create_file for
+         * a different purpose then open (2) so just give a generic error.
+         */
+        fmt = QERR_OPEN_FILE_FAILED;
+    }
+    error_set(errp, fmt, file_name);
+}
error.h +4 -0
index 6361f40..f3a80f3 100644
@@ -67,4 +67,8 @@ void error_free(Error *err);
  */
 bool error_is_type(Error *err, const char *fmt);
 
+/**
+ * Helper to set error for a open (2) style return code.
+ */
+void error_set_file_open_failed(Error **errp, const char *file_name, int ret);
 #endif
qerror.c +0 -0
index f55d435..23c260b 100644

qerror.c static const QErrorStringTable qerror_table[] = { · line 218

Quoted 6 lines
qerror.c +3 -0
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_OPEN_FILE_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },

I see that you're adding _OPEN_FILE_ flavors to be able to pass the filename in the error. But this just workarounds a limitation of qerror: we should be able to set the error message at run-time.

Quoted 6 lines
Quoted 4 lines

I think the best thing to do is to have QERR_EINTR instead, with a generic message like "Operation has been interrupted" and we can improve QError to extend it to contain the file name.

Sounds like we would not have the filename then, which would be a shame.

We can have it in the future.

Quoted 9 lines

But I don't mind doing that.

Quoted 7 lines

This is valid for all errors below.

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EACCES,
+        .desc      = "Cannot access '%(filename)'",
+    },
Quoted 5 lines
Quoted 2 lines

We already have PermissionDenied.

Not the same use case - QERR_PERMISSION_DENIED is used for internal errors, not for an open / file related system permission error.

No problem.

Quoted 11 lines
Quoted 8 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 226

Quoted 5 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EEXIST,
+        .desc      = "File already exists '%(filename)'",
+    },

I wouldn't mind not having this one because most of the time qemu doesn't care if the file already exists.

I was really just going over everything open (2) manpage and copying what looked like it made sense. I can drop it.

We should only report possible errors, something like ENXIO is not possible in this case.

Quoted 22 lines
Quoted 9 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 230

Quoted 6 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening '%(filename)'",
+    },

This is an exception for what I said about _OPEN_FILE_ flavors above, this is fine because it's really a file error.

They are all open (2) errors, see previous comment :)

Quoted 10 lines
Quoted 9 lines
qerror.c +8 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_ENOSPC,
+        .desc      = "No space left opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EPERM,
+        .desc      = "Permission denied (EPERM) for '%(filename)'",
+    },
Quoted 5 lines
Quoted 1 line

I wouldn't mind reporting EACCESS and EPERM the same.

But why do that? they are different at the system level, no reason to merge them. Except for EPERM being a bit cryptic (to me) it doesn't seem to be the same as EACCESS.

I'm avoiding having a huge amount of errors w/o strong justification, but this is minor to me, do what you think is best.

Quoted 77 lines
Quoted 8 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 242

Quoted 6 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EROFS,
+        .desc      = "Read only filesystem opening '%(filename)'",
+    },

Let's have a QERR_READ_ONLY.

OK.

Quoted 65 lines
Quoted 64 lines
qerror.c +9 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_ENOTDIR,
+        .desc      = "Directory related error opening '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EFBIG,
+        .desc      = "File too big opening '%(filename)'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +27 -0
index e26c635..6ab9b8d 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_OPEN_FILE_EINTR \
+    "{ 'class': 'OpenFileEINTR', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EACCES \
+    "{ 'class': 'OpenFileEACCES', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EEXIST \
+    "{ 'class': 'OpenFileEEXIST', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EMFILE \
+    "{ 'class': 'OpenFileEMFILE', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_ENOSPC \
+    "{ 'class': 'OpenFileENOSPC', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EPERM \
+    "{ 'class': 'OpenFileEPERM', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EROFS \
+    "{ 'class': 'OpenFileEROFS', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_ENOTDIR \
+    "{ 'class': 'OpenFileENOTDIR', 'data': { 'filename': %s } }"
+
+#define QERR_OPEN_FILE_EFBIG \
+    "{ 'class': 'OpenFileEFBIG', 'data': { 'filename': %s } }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
qga/commands-posix.c +1 -1
index 7b2be2f..4e5ef7f 100644
@@ -134,7 +134,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E
     slog("guest-file-open called, filepath: %s, mode: %s", path, mode);
     fh = fopen(path, mode);
     if (!fh) {
-        error_set(err, QERR_OPEN_FILE_FAILED, path);
+        error_set_file_open_failed(err, path, errno);
         return -1;
     }
 
author
#5 lore raw

PATCH v2 2/5 vga_hw_screen_dump: add Error** param

In reply to Alon Levy
---
 console.c       |    5 +++--
 console.h       |    6 ++++--
 hw/blizzard.c   |    3 ++-
 hw/g364fb.c     |    4 +++-
 hw/omap_lcdc.c  |    4 +++-
 hw/qxl.c        |    6 ++++--
 hw/tcx.c        |   13 +++++++++----
 hw/vga.c        |    7 +++++--
 hw/vmware_vga.c |    6 ++++--
 monitor.c       |    4 +++-
 10 files changed, 40 insertions(+), 18 deletions(-)
console.c +3 -2
index 6a463f5..d3fccf3 100644
@@ -24,6 +24,7 @@
 #include "qemu-common.h"
 #include "console.h"
 #include "qemu-timer.h"
+#include "error.h"
 
 //#define DEBUG_CONSOLE
 #define DEFAULT_BACKSCROLL 512
@@ -173,7 +174,7 @@ void vga_hw_invalidate(void)
         active_console->hw_invalidate(active_console->hw);
 }
 
-void vga_hw_screen_dump(const char *filename)
+void vga_hw_screen_dump(const char *filename, Error **errp)
 {
     TextConsole *previous_active_console;
     bool cswitch;
@@ -187,7 +188,7 @@ void vga_hw_screen_dump(const char *filename)
         console_select(0);
     }
     if (consoles[0] && consoles[0]->hw_screen_dump) {
-        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch);
+        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch, errp);
     } else {
         error_report("screen dump not implemented");
     }
console.h +4 -2
index 4334db5..caf13f5 100644
@@ -6,6 +6,7 @@
 #include "notify.h"
 #include "monitor.h"
 #include "trace.h"
+#include "error.h"
 
 /* keyboard/mouse support */
 
@@ -343,7 +344,8 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
 
 typedef void (*vga_hw_update_ptr)(void *);
 typedef void (*vga_hw_invalidate_ptr)(void *);
-typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
+typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
+                                       Error **errp);
 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
 
 DisplayState *graphic_console_init(vga_hw_update_ptr update,
@@ -354,7 +356,7 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,
 
 void vga_hw_update(void);
 void vga_hw_invalidate(void);
-void vga_hw_screen_dump(const char *filename);
+void vga_hw_screen_dump(const char *filename, Error **errp);
 void vga_hw_text_update(console_ch_t *chardata);
 
 int is_graphic_console(void);
hw/blizzard.c +2 -1
index c7d844d..76df78c 100644
@@ -23,6 +23,7 @@
 #include "devices.h"
 #include "vga_int.h"
 #include "pixel_ops.h"
+#include "error.h"
 
 typedef void (*blizzard_fn_t)(uint8_t *, const uint8_t *, unsigned int);
 
@@ -933,7 +934,7 @@ static void blizzard_update_display(void *opaque)
 }
 
 static void blizzard_screen_dump(void *opaque, const char *filename,
-                                 bool cswitch)
+                                 bool cswitch, Error **errp)
 {
     BlizzardState *s = (BlizzardState *) opaque;
 
hw/g364fb.c +3 -1
index 3a0b68f..7774d05 100644
@@ -22,6 +22,7 @@
 #include "pixel_ops.h"
 #include "trace.h"
 #include "sysbus.h"
+#include "error.h"
 
 typedef struct G364State {
     /* hardware */
@@ -289,7 +290,8 @@ static void g364fb_reset(G364State *s)
     g364fb_invalidate_display(s);
 }
 
-static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     G364State *s = opaque;
     int y, x;
hw/omap_lcdc.c +3 -1
index f172093..aec7210 100644
@@ -20,6 +20,7 @@
 #include "console.h"
 #include "omap.h"
 #include "framebuffer.h"
+#include "error.h"
 
 struct omap_lcd_panel_s {
     MemoryRegion *sysmem;
@@ -264,7 +265,8 @@ static int ppm_save(const char *filename, uint8_t *data,
     return 0;
 }
 
-static void omap_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void omap_screen_dump(void *opaque, const char *filename, bool cswitch,
+                             Error **errp)
 {
     struct omap_lcd_panel_s *omap_lcd = opaque;
     if (cswitch) {
hw/qxl.c +4 -2
index e17b0e3..27f27f5 100644
@@ -23,6 +23,7 @@
 #include "qemu-queue.h"
 #include "monitor.h"
 #include "sysemu.h"
+#include "error.h"
 
 #include "qxl.h"
 
@@ -1492,7 +1493,8 @@ static void qxl_hw_invalidate(void *opaque)
     vga->invalidate(vga);
 }
 
-static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     PCIQXLDevice *qxl = opaque;
     VGACommonState *vga = &qxl->vga;
@@ -1504,7 +1506,7 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch)
         ppm_save(filename, qxl->ssd.ds->surface);
         break;
     case QXL_MODE_VGA:
-        vga->screen_dump(vga, filename, cswitch);
+        vga->screen_dump(vga, filename, cswitch, errp);
         break;
     default:
         break;
hw/tcx.c +9 -4
index ac7dcb4..f342a5d 100644
@@ -26,6 +26,7 @@
 #include "pixel_ops.h"
 #include "sysbus.h"
 #include "qdev-addr.h"
+#include "error.h"
 
 #define MAXX 1024
 #define MAXY 768
@@ -56,8 +57,10 @@ typedef struct TCXState {
     uint8_t dac_index, dac_state;
 } TCXState;
 
-static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch);
-static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch);
+static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error *errp);
+static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch,
+                              Error *errp);
 
 static void tcx_set_dirty(TCXState *s)
 {
@@ -574,7 +577,8 @@ static int tcx_init1(SysBusDevice *dev)
     return 0;
 }
 
-static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error *errp)
 {
     TCXState *s = opaque;
     FILE *f;
@@ -601,7 +605,8 @@ static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch)
     return;
 }
 
-static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch,
+                              Error *errp)
 {
     TCXState *s = opaque;
     FILE *f;
hw/vga.c +5 -2
index 6dc98f6..79c5c38 100644
@@ -31,6 +31,7 @@
 #include "qemu-timer.h"
 #include "xen.h"
 #include "trace.h"
+#include "error.h"
 
 //#define DEBUG_VGA
 //#define DEBUG_VGA_MEM
@@ -163,7 +164,8 @@ static uint32_t expand4[256];
 static uint16_t expand2[256];
 static uint8_t expand4to8[16];
 
-static void vga_screen_dump(void *opaque, const char *filename, bool cswitch);
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error **errp);
 
 static void vga_update_memory_access(VGACommonState *s)
 {
@@ -2409,7 +2411,8 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
 
 /* save the vga display in a PPM image even if no display is
    available */
-static void vga_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error **errp)
 {
     VGACommonState *s = opaque;
 
hw/vmware_vga.c +4 -2
index 142d9f4..6868778 100644
@@ -26,6 +26,7 @@
 #include "console.h"
 #include "pci.h"
 #include "vmware_vga.h"
+#include "error.h"
 
 #undef VERBOSE
 #define HW_RECT_ACCEL
@@ -1003,11 +1004,12 @@ static void vmsvga_invalidate_display(void *opaque)
 
 /* save the vga display in a PPM image even if no display is
    available */
-static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     struct vmsvga_state_s *s = opaque;
     if (!s->enable) {
-        s->vga.screen_dump(&s->vga, filename, cswitch);
+        s->vga.screen_dump(&s->vga, filename, cswitch, errp);
         return;
     }
 
monitor.c +3 -1
index cbdfbad..79399ab 100644
@@ -895,7 +895,9 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
 
 static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
-    vga_hw_screen_dump(qdict_get_str(qdict, "filename"));
+    Error *errp = NULL;
+
+    vga_hw_screen_dump(qdict_get_str(qdict, "filename"), &errp);
     return 0;
 }
 
Signature · 1 line
1.7.9.3
#6 lore raw

Re: [Qemu-devel] [PATCH v2 2/5] vga_hw_screen_dump: add Error** param

Quoted 1 line · On Thu, 15 Mar 2012 00:55:11 +0200 Alon Levy <[email protected]> wrote:

Please, explain why. More comments at the bottom.

Quoted 279 lines
---
 console.c       |    5 +++--
 console.h       |    6 ++++--
 hw/blizzard.c   |    3 ++-
 hw/g364fb.c     |    4 +++-
 hw/omap_lcdc.c  |    4 +++-
 hw/qxl.c        |    6 ++++--
 hw/tcx.c        |   13 +++++++++----
 hw/vga.c        |    7 +++++--
 hw/vmware_vga.c |    6 ++++--
 monitor.c       |    4 +++-
 10 files changed, 40 insertions(+), 18 deletions(-)
console.c +3 -2
index 6a463f5..d3fccf3 100644
@@ -24,6 +24,7 @@
 #include "qemu-common.h"
 #include "console.h"
 #include "qemu-timer.h"
+#include "error.h"
 
 //#define DEBUG_CONSOLE
 #define DEFAULT_BACKSCROLL 512
@@ -173,7 +174,7 @@ void vga_hw_invalidate(void)
         active_console->hw_invalidate(active_console->hw);
 }
 
-void vga_hw_screen_dump(const char *filename)
+void vga_hw_screen_dump(const char *filename, Error **errp)
 {
     TextConsole *previous_active_console;
     bool cswitch;
@@ -187,7 +188,7 @@ void vga_hw_screen_dump(const char *filename)
         console_select(0);
     }
     if (consoles[0] && consoles[0]->hw_screen_dump) {
-        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch);
+        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch, errp);
     } else {
         error_report("screen dump not implemented");
     }
console.h +4 -2
index 4334db5..caf13f5 100644
@@ -6,6 +6,7 @@
 #include "notify.h"
 #include "monitor.h"
 #include "trace.h"
+#include "error.h"
 
 /* keyboard/mouse support */
 
@@ -343,7 +344,8 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
 
 typedef void (*vga_hw_update_ptr)(void *);
 typedef void (*vga_hw_invalidate_ptr)(void *);
-typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
+typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
+                                       Error **errp);
 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
 
 DisplayState *graphic_console_init(vga_hw_update_ptr update,
@@ -354,7 +356,7 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,
 
 void vga_hw_update(void);
 void vga_hw_invalidate(void);
-void vga_hw_screen_dump(const char *filename);
+void vga_hw_screen_dump(const char *filename, Error **errp);
 void vga_hw_text_update(console_ch_t *chardata);
 
 int is_graphic_console(void);
hw/blizzard.c +2 -1
index c7d844d..76df78c 100644
@@ -23,6 +23,7 @@
 #include "devices.h"
 #include "vga_int.h"
 #include "pixel_ops.h"
+#include "error.h"
 
 typedef void (*blizzard_fn_t)(uint8_t *, const uint8_t *, unsigned int);
 
@@ -933,7 +934,7 @@ static void blizzard_update_display(void *opaque)
 }
 
 static void blizzard_screen_dump(void *opaque, const char *filename,
-                                 bool cswitch)
+                                 bool cswitch, Error **errp)
 {
     BlizzardState *s = (BlizzardState *) opaque;
 
hw/g364fb.c +3 -1
index 3a0b68f..7774d05 100644
@@ -22,6 +22,7 @@
 #include "pixel_ops.h"
 #include "trace.h"
 #include "sysbus.h"
+#include "error.h"
 
 typedef struct G364State {
     /* hardware */
@@ -289,7 +290,8 @@ static void g364fb_reset(G364State *s)
     g364fb_invalidate_display(s);
 }
 
-static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     G364State *s = opaque;
     int y, x;
hw/omap_lcdc.c +3 -1
index f172093..aec7210 100644
@@ -20,6 +20,7 @@
 #include "console.h"
 #include "omap.h"
 #include "framebuffer.h"
+#include "error.h"
 
 struct omap_lcd_panel_s {
     MemoryRegion *sysmem;
@@ -264,7 +265,8 @@ static int ppm_save(const char *filename, uint8_t *data,
     return 0;
 }
 
-static void omap_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void omap_screen_dump(void *opaque, const char *filename, bool cswitch,
+                             Error **errp)
 {
     struct omap_lcd_panel_s *omap_lcd = opaque;
     if (cswitch) {
hw/qxl.c +4 -2
index e17b0e3..27f27f5 100644
@@ -23,6 +23,7 @@
 #include "qemu-queue.h"
 #include "monitor.h"
 #include "sysemu.h"
+#include "error.h"
 
 #include "qxl.h"
 
@@ -1492,7 +1493,8 @@ static void qxl_hw_invalidate(void *opaque)
     vga->invalidate(vga);
 }
 
-static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     PCIQXLDevice *qxl = opaque;
     VGACommonState *vga = &qxl->vga;
@@ -1504,7 +1506,7 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch)
         ppm_save(filename, qxl->ssd.ds->surface);
         break;
     case QXL_MODE_VGA:
-        vga->screen_dump(vga, filename, cswitch);
+        vga->screen_dump(vga, filename, cswitch, errp);
         break;
     default:
         break;
hw/tcx.c +9 -4
index ac7dcb4..f342a5d 100644
@@ -26,6 +26,7 @@
 #include "pixel_ops.h"
 #include "sysbus.h"
 #include "qdev-addr.h"
+#include "error.h"
 
 #define MAXX 1024
 #define MAXY 768
@@ -56,8 +57,10 @@ typedef struct TCXState {
     uint8_t dac_index, dac_state;
 } TCXState;
 
-static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch);
-static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch);
+static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error *errp);
+static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch,
+                              Error *errp);
 
 static void tcx_set_dirty(TCXState *s)
 {
@@ -574,7 +577,8 @@ static int tcx_init1(SysBusDevice *dev)
     return 0;
 }
 
-static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error *errp)
 {
     TCXState *s = opaque;
     FILE *f;
@@ -601,7 +605,8 @@ static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch)
     return;
 }
 
-static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch,
+                              Error *errp)
 {
     TCXState *s = opaque;
     FILE *f;
hw/vga.c +5 -2
index 6dc98f6..79c5c38 100644
@@ -31,6 +31,7 @@
 #include "qemu-timer.h"
 #include "xen.h"
 #include "trace.h"
+#include "error.h"
 
 //#define DEBUG_VGA
 //#define DEBUG_VGA_MEM
@@ -163,7 +164,8 @@ static uint32_t expand4[256];
 static uint16_t expand2[256];
 static uint8_t expand4to8[16];
 
-static void vga_screen_dump(void *opaque, const char *filename, bool cswitch);
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error **errp);
 
 static void vga_update_memory_access(VGACommonState *s)
 {
@@ -2409,7 +2411,8 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
 
 /* save the vga display in a PPM image even if no display is
    available */
-static void vga_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error **errp)
 {
     VGACommonState *s = opaque;
 
hw/vmware_vga.c +4 -2
index 142d9f4..6868778 100644
@@ -26,6 +26,7 @@
 #include "console.h"
 #include "pci.h"
 #include "vmware_vga.h"
+#include "error.h"
 
 #undef VERBOSE
 #define HW_RECT_ACCEL
@@ -1003,11 +1004,12 @@ static void vmsvga_invalidate_display(void *opaque)
 
 /* save the vga display in a PPM image even if no display is
    available */
-static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     struct vmsvga_state_s *s = opaque;
     if (!s->enable) {
-        s->vga.screen_dump(&s->vga, filename, cswitch);
+        s->vga.screen_dump(&s->vga, filename, cswitch, errp);
         return;
     }
 
monitor.c +0 -0
index cbdfbad..79399ab 100644

monitor.c static int client_migrate_info(Monitor *mon, const QDict *qdict, · line 900

Quoted 7 lines
monitor.c +3 -1
@@ -895,7 +895,9 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
 
 static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
-    vga_hw_screen_dump(qdict_get_str(qdict, "filename"));
+    Error *errp = NULL;
+
+    vga_hw_screen_dump(qdict_get_str(qdict, "filename"), &errp);

Better to pass NULL, as it communicates this is not used (yet).

Quoted 3 lines
monitor.c +0 -0
     return 0;
 }
 
author
#7 lore raw

Re: [Qemu-devel] [PATCH v2 2/5] vga_hw_screen_dump: add Error** param

Quoted 6 lines · Luiz Capitulino
Quoted 1 line · On Thu, 15 Mar 2012 00:55:11 +0200 Alon Levy <[email protected]> wrote:

Please, explain why. More comments at the bottom.

Sure.

Quoted 281 lines
Quoted 281 lines
---
 console.c       |    5 +++--
 console.h       |    6 ++++--
 hw/blizzard.c   |    3 ++-
 hw/g364fb.c     |    4 +++-
 hw/omap_lcdc.c  |    4 +++-
 hw/qxl.c        |    6 ++++--
 hw/tcx.c        |   13 +++++++++----
 hw/vga.c        |    7 +++++--
 hw/vmware_vga.c |    6 ++++--
 monitor.c       |    4 +++-
 10 files changed, 40 insertions(+), 18 deletions(-)
console.c +3 -2
index 6a463f5..d3fccf3 100644
@@ -24,6 +24,7 @@
 #include "qemu-common.h"
 #include "console.h"
 #include "qemu-timer.h"
+#include "error.h"
 
 //#define DEBUG_CONSOLE
 #define DEFAULT_BACKSCROLL 512
@@ -173,7 +174,7 @@ void vga_hw_invalidate(void)
         active_console->hw_invalidate(active_console->hw);
 }
 
-void vga_hw_screen_dump(const char *filename)
+void vga_hw_screen_dump(const char *filename, Error **errp)
 {
     TextConsole *previous_active_console;
     bool cswitch;
@@ -187,7 +188,7 @@ void vga_hw_screen_dump(const char *filename)
         console_select(0);
     }
     if (consoles[0] && consoles[0]->hw_screen_dump) {
-        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch);
+        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch, errp);
     } else {
         error_report("screen dump not implemented");
     }
console.h +4 -2
index 4334db5..caf13f5 100644
@@ -6,6 +6,7 @@
 #include "notify.h"
 #include "monitor.h"
 #include "trace.h"
+#include "error.h"
 
 /* keyboard/mouse support */
 
@@ -343,7 +344,8 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
 
 typedef void (*vga_hw_update_ptr)(void *);
 typedef void (*vga_hw_invalidate_ptr)(void *);
-typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
+typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
+                                       Error **errp);
 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
 
 DisplayState *graphic_console_init(vga_hw_update_ptr update,
@@ -354,7 +356,7 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,
 
 void vga_hw_update(void);
 void vga_hw_invalidate(void);
-void vga_hw_screen_dump(const char *filename);
+void vga_hw_screen_dump(const char *filename, Error **errp);
 void vga_hw_text_update(console_ch_t *chardata);
 
 int is_graphic_console(void);
hw/blizzard.c +2 -1
index c7d844d..76df78c 100644
@@ -23,6 +23,7 @@
 #include "devices.h"
 #include "vga_int.h"
 #include "pixel_ops.h"
+#include "error.h"
 
 typedef void (*blizzard_fn_t)(uint8_t *, const uint8_t *, unsigned int);
 
@@ -933,7 +934,7 @@ static void blizzard_update_display(void *opaque)
 }
 
 static void blizzard_screen_dump(void *opaque, const char *filename,
-                                 bool cswitch)
+                                 bool cswitch, Error **errp)
 {
     BlizzardState *s = (BlizzardState *) opaque;
 
hw/g364fb.c +3 -1
index 3a0b68f..7774d05 100644
@@ -22,6 +22,7 @@
 #include "pixel_ops.h"
 #include "trace.h"
 #include "sysbus.h"
+#include "error.h"
 
 typedef struct G364State {
     /* hardware */
@@ -289,7 +290,8 @@ static void g364fb_reset(G364State *s)
     g364fb_invalidate_display(s);
 }
 
-static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     G364State *s = opaque;
     int y, x;
hw/omap_lcdc.c +3 -1
index f172093..aec7210 100644
@@ -20,6 +20,7 @@
 #include "console.h"
 #include "omap.h"
 #include "framebuffer.h"
+#include "error.h"
 
 struct omap_lcd_panel_s {
     MemoryRegion *sysmem;
@@ -264,7 +265,8 @@ static int ppm_save(const char *filename, uint8_t *data,
     return 0;
 }
 
-static void omap_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void omap_screen_dump(void *opaque, const char *filename, bool cswitch,
+                             Error **errp)
 {
     struct omap_lcd_panel_s *omap_lcd = opaque;
     if (cswitch) {
hw/qxl.c +4 -2
index e17b0e3..27f27f5 100644
@@ -23,6 +23,7 @@
 #include "qemu-queue.h"
 #include "monitor.h"
 #include "sysemu.h"
+#include "error.h"
 
 #include "qxl.h"
 
@@ -1492,7 +1493,8 @@ static void qxl_hw_invalidate(void *opaque)
     vga->invalidate(vga);
 }
 
-static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     PCIQXLDevice *qxl = opaque;
     VGACommonState *vga = &qxl->vga;
@@ -1504,7 +1506,7 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch)
         ppm_save(filename, qxl->ssd.ds->surface);
         break;
     case QXL_MODE_VGA:
-        vga->screen_dump(vga, filename, cswitch);
+        vga->screen_dump(vga, filename, cswitch, errp);
         break;
     default:
         break;
hw/tcx.c +9 -4
index ac7dcb4..f342a5d 100644
@@ -26,6 +26,7 @@
 #include "pixel_ops.h"
 #include "sysbus.h"
 #include "qdev-addr.h"
+#include "error.h"
 
 #define MAXX 1024
 #define MAXY 768
@@ -56,8 +57,10 @@ typedef struct TCXState {
     uint8_t dac_index, dac_state;
 } TCXState;
 
-static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch);
-static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch);
+static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error *errp);
+static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch,
+                              Error *errp);
 
 static void tcx_set_dirty(TCXState *s)
 {
@@ -574,7 +577,8 @@ static int tcx_init1(SysBusDevice *dev)
     return 0;
 }
 
-static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error *errp)
 {
     TCXState *s = opaque;
     FILE *f;
@@ -601,7 +605,8 @@ static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch)
     return;
 }
 
-static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch,
+                              Error *errp)
 {
     TCXState *s = opaque;
     FILE *f;
hw/vga.c +5 -2
index 6dc98f6..79c5c38 100644
@@ -31,6 +31,7 @@
 #include "qemu-timer.h"
 #include "xen.h"
 #include "trace.h"
+#include "error.h"
 
 //#define DEBUG_VGA
 //#define DEBUG_VGA_MEM
@@ -163,7 +164,8 @@ static uint32_t expand4[256];
 static uint16_t expand2[256];
 static uint8_t expand4to8[16];
 
-static void vga_screen_dump(void *opaque, const char *filename, bool cswitch);
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error **errp);
 
 static void vga_update_memory_access(VGACommonState *s)
 {
@@ -2409,7 +2411,8 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
 
 /* save the vga display in a PPM image even if no display is
    available */
-static void vga_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error **errp)
 {
     VGACommonState *s = opaque;
 
hw/vmware_vga.c +4 -2
index 142d9f4..6868778 100644
@@ -26,6 +26,7 @@
 #include "console.h"
 #include "pci.h"
 #include "vmware_vga.h"
+#include "error.h"
 
 #undef VERBOSE
 #define HW_RECT_ACCEL
@@ -1003,11 +1004,12 @@ static void vmsvga_invalidate_display(void *opaque)
 
 /* save the vga display in a PPM image even if no display is
    available */
-static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     struct vmsvga_state_s *s = opaque;
     if (!s->enable) {
-        s->vga.screen_dump(&s->vga, filename, cswitch);
+        s->vga.screen_dump(&s->vga, filename, cswitch, errp);
         return;
     }
 
monitor.c +0 -0
index cbdfbad..79399ab 100644
@@ -895,7 +895,9 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
 
Quoted 8 lines

monitor.c static int client_migrate_info(Monitor *mon, const QDict *qdict, · line 900

Quoted 6 lines
monitor.c +3 -1
 static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
-    vga_hw_screen_dump(qdict_get_str(qdict, "filename"));
+    Error *errp = NULL;
+
+    vga_hw_screen_dump(qdict_get_str(qdict, "filename"), &errp);

Better to pass NULL, as it communicates this is not used (yet).

OK, in that case I'll check that it actually handles that case correctly (the point of passing a valid pointer was to not worry about that right now).

Quoted 5 lines
Quoted 4 lines
monitor.c +0 -0
     return 0;
 }
 
author
#8 lore raw

PATCH v2 3/5 qapi: convert screendump

In reply to Alon Levy
---
 hmp-commands.hx  |    3 +--
 hmp.c            |    8 ++++++++
 hmp.h            |    1 +
 monitor.c        |    8 --------
 qapi-schema.json |   13 +++++++++++++
 qmp-commands.hx  |    5 +----
 qmp.c            |    5 +++++
 7 files changed, 29 insertions(+), 14 deletions(-)
hmp-commands.hx +1 -2
index 6980214..d26421a 100644
@@ -194,8 +194,7 @@ ETEXI
         .args_type  = "filename:F",
         .params     = "filename",
         .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd = hmp_screendump,
     },
 
 STEXI
hmp.c +8 -0
index 290c43d..42dc79a 100644
@@ -860,3 +860,11 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
 
     hmp_handle_error(mon, &error);
 }
+
+void hmp_screendump(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+
+    qmp_screendump(qdict_get_str(qdict, "filename"), &err);
+    hmp_handle_error(mon, &err);
+}
hmp.h +1 -0
index 5409464..25d123f 100644
@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);
 void hmp_block_stream(Monitor *mon, const QDict *qdict);
 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
+void hmp_screendump(Monitor *mon, const QDict *qdict);
 
 #endif
monitor.c +0 -8
index 79399ab..f79ce9a 100644
@@ -893,14 +893,6 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
     return -1;
 }
 
-static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-    Error *errp = NULL;
-
-    vga_hw_screen_dump(qdict_get_str(qdict, "filename"), &errp);
-    return 0;
-}
-
 static void do_logfile(Monitor *mon, const QDict *qdict)
 {
     cpu_set_log_filename(qdict_get_str(qdict, "filename"));
qapi-schema.json +13 -0
index 04fa84f..4f251ca 100644
@@ -1663,3 +1663,16 @@
 { 'command': 'qom-list-types',
   'data': { '*implements': 'str', '*abstract': 'bool' },
   'returns': [ 'ObjectTypeInfo' ] }
+
+##
+# @screendump:
+#
+# Write a PPM of the VGA screen to a file.
+#
+# @filename: the name of a new PPM file to create to store the image
+#
+# Returns: Nothing on success
+#
+# Since: 1.1
+##
+{ 'command': 'screendump', 'data': {'filename': 'str'} }
qmp-commands.hx +1 -4
index dfe8a5b..5fe57fd 100644
@@ -146,10 +146,7 @@ EQMP
     {
         .name       = "screendump",
         .args_type  = "filename:F",
-        .params     = "filename",
-        .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd_new = qmp_marshal_input_screendump,
     },
 
 SQMP
qmp.c +5 -0
index a182b51..086cec8 100644
@@ -415,3 +415,8 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
 
     return ret;
 }
+
+void qmp_screendump(const char *filename, Error **errp)
+{
+    vga_hw_screen_dump(filename, errp);
+}
Signature · 1 line
1.7.9.3
#9 lore raw

Re: [Qemu-devel] [PATCH v2 3/5] qapi: convert screendump

Quoted 78 lines · On Thu, 15 Mar 2012 00:55:12 +0200 Alon Levy <[email protected]> wrote:
---
 hmp-commands.hx  |    3 +--
 hmp.c            |    8 ++++++++
 hmp.h            |    1 +
 monitor.c        |    8 --------
 qapi-schema.json |   13 +++++++++++++
 qmp-commands.hx  |    5 +----
 qmp.c            |    5 +++++
 7 files changed, 29 insertions(+), 14 deletions(-)
hmp-commands.hx +1 -2
index 6980214..d26421a 100644
@@ -194,8 +194,7 @@ ETEXI
         .args_type  = "filename:F",
         .params     = "filename",
         .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd = hmp_screendump,
     },
 
 STEXI
hmp.c +8 -0
index 290c43d..42dc79a 100644
@@ -860,3 +860,11 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
 
     hmp_handle_error(mon, &error);
 }
+
+void hmp_screendump(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+
+    qmp_screendump(qdict_get_str(qdict, "filename"), &err);
+    hmp_handle_error(mon, &err);
+}
hmp.h +1 -0
index 5409464..25d123f 100644
@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);
 void hmp_block_stream(Monitor *mon, const QDict *qdict);
 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
+void hmp_screendump(Monitor *mon, const QDict *qdict);
 
 #endif
monitor.c +0 -8
index 79399ab..f79ce9a 100644
@@ -893,14 +893,6 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
     return -1;
 }
 
-static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-    Error *errp = NULL;
-
-    vga_hw_screen_dump(qdict_get_str(qdict, "filename"), &errp);
-    return 0;
-}
-
 static void do_logfile(Monitor *mon, const QDict *qdict)
 {
     cpu_set_log_filename(qdict_get_str(qdict, "filename"));
qapi-schema.json +0 -0
index 04fa84f..4f251ca 100644
@@ -1663,3 +1663,16 @@
 { 'command': 'qom-list-types',
   'data': { '*implements': 'str', '*abstract': 'bool' },

qapi-schema.json line 1674

Quoted 10 lines
qapi-schema.json +9 -0
   'returns': [ 'ObjectTypeInfo' ] }
+
+##
+# @screendump:
+#
+# Write a PPM of the VGA screen to a file.
+#
+# @filename: the name of a new PPM file to create to store the image
+#
+# Returns: Nothing on success

Note that you have to document all the _possible_ errors. Look for other examples in this file.

Quoted 33 lines
qapi-schema.json +4 -0
+#
+# Since: 1.1
+##
+{ 'command': 'screendump', 'data': {'filename': 'str'} }
qmp-commands.hx +1 -4
index dfe8a5b..5fe57fd 100644
@@ -146,10 +146,7 @@ EQMP
     {
         .name       = "screendump",
         .args_type  = "filename:F",
-        .params     = "filename",
-        .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd_new = qmp_marshal_input_screendump,
     },
 
 SQMP
qmp.c +5 -0
index a182b51..086cec8 100644
@@ -415,3 +415,8 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
 
     return ret;
 }
+
+void qmp_screendump(const char *filename, Error **errp)
+{
+    vga_hw_screen_dump(filename, errp);
+}
author
#10 lore raw

Re: [Qemu-devel] [PATCH v2 3/5] qapi: convert screendump

Quoted 86 lines · Luiz Capitulino
Quoted 83 lines · On Thu, 15 Mar 2012 00:55:12 +0200 Alon Levy <[email protected]> wrote:
---
 hmp-commands.hx  |    3 +--
 hmp.c            |    8 ++++++++
 hmp.h            |    1 +
 monitor.c        |    8 --------
 qapi-schema.json |   13 +++++++++++++
 qmp-commands.hx  |    5 +----
 qmp.c            |    5 +++++
 7 files changed, 29 insertions(+), 14 deletions(-)
hmp-commands.hx +1 -2
index 6980214..d26421a 100644
@@ -194,8 +194,7 @@ ETEXI
         .args_type  = "filename:F",
         .params     = "filename",
         .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd = hmp_screendump,
     },
 
 STEXI
hmp.c +8 -0
index 290c43d..42dc79a 100644
@@ -860,3 +860,11 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
 
     hmp_handle_error(mon, &error);
 }
+
+void hmp_screendump(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+
+    qmp_screendump(qdict_get_str(qdict, "filename"), &err);
+    hmp_handle_error(mon, &err);
+}
hmp.h +1 -0
index 5409464..25d123f 100644
@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);
 void hmp_block_stream(Monitor *mon, const QDict *qdict);
 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
+void hmp_screendump(Monitor *mon, const QDict *qdict);
 
 #endif
monitor.c +0 -8
index 79399ab..f79ce9a 100644
@@ -893,14 +893,6 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
     return -1;
 }
 
-static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-    Error *errp = NULL;
-
-    vga_hw_screen_dump(qdict_get_str(qdict, "filename"), &errp);
-    return 0;
-}
-
 static void do_logfile(Monitor *mon, const QDict *qdict)
 {
     cpu_set_log_filename(qdict_get_str(qdict, "filename"));
qapi-schema.json +4 -0
index 04fa84f..4f251ca 100644
@@ -1663,3 +1663,16 @@
 { 'command': 'qom-list-types',
   'data': { '*implements': 'str', '*abstract': 'bool' },
   'returns': [ 'ObjectTypeInfo' ] }
+
+##
+# @screendump:
+#
Quoted 8 lines

qapi-schema.json line 1674

Quoted 5 lines
qapi-schema.json +5 -0
+# Write a PPM of the VGA screen to a file.
+#
+# @filename: the name of a new PPM file to create to store the image
+#
+# Returns: Nothing on success

Note that you have to document all the _possible_ errors. Look for other examples in this file.

Yes, forgot about that. Another reason to split the other users of qerr_fopen_err then :)

Quoted 36 lines
Quoted 34 lines
qapi-schema.json +4 -0
+#
+# Since: 1.1
+##
+{ 'command': 'screendump', 'data': {'filename': 'str'} }
qmp-commands.hx +1 -4
index dfe8a5b..5fe57fd 100644
@@ -146,10 +146,7 @@ EQMP
     {
         .name       = "screendump",
         .args_type  = "filename:F",
-        .params     = "filename",
-        .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd_new = qmp_marshal_input_screendump,
     },
 
 SQMP
qmp.c +5 -0
index a182b51..086cec8 100644
@@ -415,3 +415,8 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
 
     return ret;
 }
+
+void qmp_screendump(const char *filename, Error **errp)
+{
+    vga_hw_screen_dump(filename, errp);
+}
author
#11 lore raw

PATCH v2 4/5 vga: ppm_save(): Return error on failure

In reply to Alon Levy

From: Luiz Capitulino <[email protected]>

This makes all devices using ppm_save() return an error appropriately when the screendump command fails.

Based on a code by Anthony Liguori.

---
 hw/blizzard.c   |    2 +-
 hw/qxl.c        |    2 +-
 hw/vga.c        |    8 +++++---
 hw/vga_int.h    |    3 ++-
 hw/vmware_vga.c |    2 +-
 5 files changed, 10 insertions(+), 7 deletions(-)
hw/blizzard.c +1 -1
index 76df78c..29e5ae6 100644
@@ -942,7 +942,7 @@ static void blizzard_screen_dump(void *opaque, const char *filename,
         blizzard_update_display(opaque);
     }
     if (s && ds_get_data(s->state))
-        ppm_save(filename, s->state->surface);
+        ppm_save(filename, s->state->surface, errp);
 }
 
 #define DEPTH 8
hw/qxl.c +1 -1
index 27f27f5..aa68612 100644
@@ -1503,7 +1503,7 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch,
     case QXL_MODE_COMPAT:
     case QXL_MODE_NATIVE:
         qxl_render_update(qxl);
-        ppm_save(filename, qxl->ssd.ds->surface);
+        ppm_save(filename, qxl->ssd.ds->surface, errp);
         break;
     case QXL_MODE_VGA:
         vga->screen_dump(vga, filename, cswitch, errp);
hw/vga.c +5 -3
index 79c5c38..80e6dca 100644
@@ -2365,7 +2365,7 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion *system_memory)
 /********************************************************/
 /* vga screen dump */
 
-int ppm_save(const char *filename, struct DisplaySurface *ds)
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp)
 {
     FILE *f;
     uint8_t *d, *d1;
@@ -2377,8 +2377,10 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
 
     trace_ppm_save(filename, ds);
     f = fopen(filename, "wb");
-    if (!f)
+    if (!f) {
+        error_set_file_open_failed(errp, filename, errno);
         return -1;
+    }
     fprintf(f, "P6\n%d %d\n%d\n",
             ds->width, ds->height, 255);
     linebuf = g_malloc(ds->width * 3);
@@ -2420,5 +2422,5 @@ static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
         vga_invalidate_display(s);
         vga_hw_update();
     }
-    ppm_save(filename, s->ds->surface);
+    ppm_save(filename, s->ds->surface, errp);
 }
hw/vga_int.h +2 -1
index 7685b2b..63078ba 100644
@@ -24,6 +24,7 @@
 
 #include <hw/hw.h>
 #include "memory.h"
+#include "error.h"
 
 #define ST01_V_RETRACE      0x08
 #define ST01_DISP_ENABLE    0x01
@@ -200,7 +201,7 @@ void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val);
 uint32_t vga_mem_readb(VGACommonState *s, target_phys_addr_t addr);
 void vga_mem_writeb(VGACommonState *s, target_phys_addr_t addr, uint32_t val);
 void vga_invalidate_scanlines(VGACommonState *s, int y1, int y2);
-int ppm_save(const char *filename, struct DisplaySurface *ds);
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp);
 
 int vga_ioport_invalid(VGACommonState *s, uint32_t addr);
 void vga_init_vbe(VGACommonState *s, MemoryRegion *address_space);
hw/vmware_vga.c +1 -1
index 6868778..0769652 100644
@@ -1016,7 +1016,7 @@ static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch,
     if (s->depth == 32) {
         DisplaySurface *ds = qemu_create_displaysurface_from(s->width,
                 s->height, 32, ds_get_linesize(s->vga.ds), s->vga.vram_ptr);
-        ppm_save(filename, ds);
+        ppm_save(filename, ds, errp);
         g_free(ds);
     }
 }
Signature · 1 line
1.7.9.3
author
#12 lore raw

PATCH v2 5/5 blockdev: use error_set_file_open_failed

In reply to Alon Levy

This is a little trickier, since those calls chain in many fun ways and produce sometimes their own return values reusing existing errno values for similar meanings. In that respect error_set_file_open_failed specifically ignores EINVAL, ENOTSUP and ENOENT. The first two simply are not returned by open (2), but the last is but I chose to ignore it to allow easy reuse in blockdev to avoid confusion when it is used internally by the create functions.

---
 blockdev.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
blockdev.c +7 -4
index 1a500b8..544d067 100644
@@ -777,7 +777,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
                                   states->old_bs->drv->format_name,
                                   NULL, -1, flags);
             if (ret) {
-                error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+                error_set_file_open_failed(errp, new_image_file, -ret);
                 goto delete_and_fail;
             }
         }
@@ -787,7 +787,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
         ret = bdrv_open(states->new_bs, new_image_file,
                         flags | BDRV_O_NO_BACKING, drv);
         if (ret != 0) {
-            error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+            error_set_file_open_failed(errp, new_image_file, -ret);
             goto delete_and_fail;
         }
     }
@@ -881,8 +881,11 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
                                     int bdrv_flags, BlockDriver *drv,
                                     const char *password, Error **errp)
 {
-    if (bdrv_open(bs, filename, bdrv_flags, drv) < 0) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+    int ret;
+
+    ret = bdrv_open(bs, filename, bdrv_flags, drv);
+    if (ret < 0) {
+        error_set_file_open_failed(errp, filename, ret);
         return;
     }
 
Signature · 1 line
1.7.9.3
#13 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] blockdev: use error_set_file_open_failed

Quoted 7 lines · On Thu, 15 Mar 2012 00:55:14 +0200 Alon Levy <[email protected]> wrote:

This is a little trickier, since those calls chain in many fun ways and produce sometimes their own return values reusing existing errno values for similar meanings. In that respect error_set_file_open_failed specifically ignores EINVAL, ENOTSUP and ENOENT. The first two simply are not returned by open (2), but the last is but I chose to ignore it to allow easy reuse in blockdev to avoid confusion when it is used internally by the create functions.

Please, just drop this from this series as it's completely unrelated to the screendump command.

Quoted 42 lines
---
 blockdev.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
blockdev.c +7 -4
index 1a500b8..544d067 100644
@@ -777,7 +777,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
                                   states->old_bs->drv->format_name,
                                   NULL, -1, flags);
             if (ret) {
-                error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+                error_set_file_open_failed(errp, new_image_file, -ret);
                 goto delete_and_fail;
             }
         }
@@ -787,7 +787,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
         ret = bdrv_open(states->new_bs, new_image_file,
                         flags | BDRV_O_NO_BACKING, drv);
         if (ret != 0) {
-            error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+            error_set_file_open_failed(errp, new_image_file, -ret);
             goto delete_and_fail;
         }
     }
@@ -881,8 +881,11 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
                                     int bdrv_flags, BlockDriver *drv,
                                     const char *password, Error **errp)
 {
-    if (bdrv_open(bs, filename, bdrv_flags, drv) < 0) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+    int ret;
+
+    ret = bdrv_open(bs, filename, bdrv_flags, drv);
+    if (ret < 0) {
+        error_set_file_open_failed(errp, filename, ret);
         return;
     }
 
author
#14 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] blockdev: use error_set_file_open_failed

Quoted 11 lines · Luiz Capitulino
Quoted 7 lines · On Thu, 15 Mar 2012 00:55:14 +0200 Alon Levy <[email protected]> wrote:

This is a little trickier, since those calls chain in many fun ways and produce sometimes their own return values reusing existing errno values for similar meanings. In that respect error_set_file_open_failed specifically ignores EINVAL, ENOTSUP and ENOENT. The first two simply are not returned by open (2), but the last is but I chose to ignore it to allow easy reuse in blockdev to avoid confusion when it is used internally by the create functions.

Quoted 2 lines

Please, just drop this from this series as it's completely unrelated to the screendump command.

After I went to all the trouble jumping through blockdev.c ? OK :)

Quoted 44 lines
Quoted 43 lines
---
 blockdev.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
blockdev.c +7 -4
index 1a500b8..544d067 100644
@@ -777,7 +777,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
                                   states->old_bs->drv->format_name,
                                   NULL, -1, flags);
             if (ret) {
-                error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+                error_set_file_open_failed(errp, new_image_file, -ret);
                 goto delete_and_fail;
             }
         }
@@ -787,7 +787,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
         ret = bdrv_open(states->new_bs, new_image_file,
                         flags | BDRV_O_NO_BACKING, drv);
         if (ret != 0) {
-            error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+            error_set_file_open_failed(errp, new_image_file, -ret);
             goto delete_and_fail;
         }
     }
@@ -881,8 +881,11 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
                                     int bdrv_flags, BlockDriver *drv,
                                     const char *password, Error **errp)
 {
-    if (bdrv_open(bs, filename, bdrv_flags, drv) < 0) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+    int ret;
+
+    ret = bdrv_open(bs, filename, bdrv_flags, drv);
+    if (ret < 0) {
+        error_set_file_open_failed(errp, filename, ret);
         return;
     }
 
author
#15 lore raw

v3 cover screendump qapi convertion

In reply to Alon Levy

v3 changes: (Requested by Luiz Capitulino)

 rename helper to qemu_fopen_err
 don't touch unrelated subsystems
 move helper to osdep - I couldn't do it that way without dragging a lot of dependencies into libcacard which uses osdep-obj-y, so I split it so that there is now a osdep-no-qerror-obj-y that is solemnly used by libcacard and is contained in osdep-obj-y.
 rename some of the QERR codes, specifically most of them lost the OPEN_FILE substring.

split the first patch in two, adding error codes and adding qemu_fopen_err

v2 changes:
split screendump convertion to an addition "add Error** param" handle various errors of fopen with new qerror codes

Alon Levy (4):
qerror: add error codes for fopen failure
add qemu_fopen_err
vga_hw_screen_dump: add Error** param
qapi: convert screendump

Luiz Capitulino (1):
vga: ppm_save(): Return error on failure

 Makefile.objs      |    8 +++++---
 console.c          |    5 +++--
 console.h          |    6 ++++--
 hmp-commands.hx    |    3 +--
 hmp.c              |    8 ++++++++
 hmp.h              |    1 +
 hw/blizzard.c      |    5 +++--
 hw/g364fb.c        |    4 +++-
 hw/omap_lcdc.c     |    4 +++-
 hw/qxl.c           |    8 +++++---
 hw/tcx.c           |   13 +++++++++----
 hw/vga.c           |   15 ++++++++++-----
 hw/vga_int.h       |    3 ++-
 hw/vmware_vga.c    |    8 +++++---
 libcacard/Makefile |    2 +-
 monitor.c          |    6 ------
 osdep-qerror.c     |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 osdep-qerror.h     |    8 ++++++++
 osdep.c            |    1 -
 qapi-schema.json   |   24 ++++++++++++++++++++++++
 qerror.c           |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h           |   27 +++++++++++++++++++++++++++
 qmp-commands.hx    |    5 +----
 qmp.c              |    5 +++++
 24 files changed, 216 insertions(+), 41 deletions(-)
 create mode 100644 osdep-qerror.c
 create mode 100644 osdep-qerror.h
Signature · 1 line
1.7.9.3
author
#16 lore raw

PATCH v3 1/5 qerror: add error codes for fopen failure

Added:

QERR_EINTR
QERR_EACCES
QERR_EEXIST
QERR_OPEN_FILE_EMFILE
QERR_ENOSPC
QERR_EPERM
QERR_READ_ONLY
QERR_ENOTDIR
QERR_EFBIG

---
 qerror.c |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h |   27 +++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
qerror.c +36 -0
index f55d435..4915939 100644
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },
+    {
+        .error_fmt = QERR_EACCES,
+        .desc      = "Cannot access file'",
+    },
+    {
+        .error_fmt = QERR_EEXIST,
+        .desc      = "File already exists'",
+    },
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOSPC,
+        .desc      = "No space left opening file'",
+    },
+    {
+        .error_fmt = QERR_EPERM,
+        .desc      = "Permission denied (EPERM) opening file'",
+    },
+    {
+        .error_fmt = QERR_READ_ONLY,
+        .desc      = "Read only filesystem opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOTDIR,
+        .desc      = "Directory related error opening file'",
+    },
+    {
+        .error_fmt = QERR_EFBIG,
+        .desc      = "File too big opening'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +27 -0
index e26c635..ddc04e8 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_OPEN_FILE_EMFILE \
+    "{ 'class': 'OpenFileEMFILE', 'data': {} }"
+
+#define QERR_EINTR \
+    "{ 'class': 'EINTR', 'data': {} }"
+
+#define QERR_EACCES \
+    "{ 'class': 'EACCES', 'data': {} }"
+
+#define QERR_EEXIST \
+    "{ 'class': 'EEXIST', 'data': {} }"
+
+#define QERR_ENOSPC \
+    "{ 'class': 'ENOSPC', 'data': {} }"
+
+#define QERR_EPERM \
+    "{ 'class': 'EPERM', 'data': {} }"
+
+#define QERR_READ_ONLY \
+    "{ 'class': 'ReadOnly', 'data': {} }"
+
+#define QERR_ENOTDIR \
+    "{ 'class': 'ENOTDIR', 'data': {} }"
+
+#define QERR_EFBIG \
+    "{ 'class': 'EFBIG', 'data': {} }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
Signature · 1 line
1.7.9.3
#17 lore raw

Re: [Qemu-devel] [PATCH v3 1/5] qerror: add error codes for fopen failure

Quoted 23 lines · On Sun, 18 Mar 2012 19:29:09 +0100 Alon Levy <[email protected]> wrote:

Added:

QERR_EINTR
QERR_EACCES
QERR_EEXIST
QERR_OPEN_FILE_EMFILE
QERR_ENOSPC
QERR_EPERM
QERR_READ_ONLY
QERR_ENOTDIR
QERR_EFBIG

---
 qerror.c |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h |   27 +++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
qerror.c +0 -0
index f55d435..4915939 100644

qerror.c static const QErrorStringTable qerror_table[] = { · line 218

Quoted 6 lines
qerror.c +3 -0
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },

There are two problems here. First, the QERR_INTR macro doesn't have the filename argument, so this will crash.

The second problem is that, I've talked to Anthony and EINTR should not be returned to clients, it should be handled intead. So, please handle it during write().

qerror.c static const QErrorStringTable qerror_table[] = { · line 222

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EACCES,
+        .desc      = "Cannot access file'",
+    },

We already have QERR_PERMISSION_DENIED.

qerror.c static const QErrorStringTable qerror_table[] = { · line 226

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EEXIST,
+        .desc      = "File already exists'",
+    },

Can you use the description provided by man 3 errno? This is valid for all errors you're adding.

Quoted 37 lines
qerror.c +25 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOSPC,
+        .desc      = "No space left opening file'",
+    },
+    {
+        .error_fmt = QERR_EPERM,
+        .desc      = "Permission denied (EPERM) opening file'",
+    },
+    {
+        .error_fmt = QERR_READ_ONLY,
+        .desc      = "Read only filesystem opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOTDIR,
+        .desc      = "Directory related error opening file'",
+    },
+    {
+        .error_fmt = QERR_EFBIG,
+        .desc      = "File too big opening'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +1 -0
index e26c635..ddc04e8 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_OPEN_FILE_EMFILE \

qerror.h QError *qobject_to_qerror(const QObject *obj); · line 194

Quoted 10 lines
qerror.h +10 -0
+    "{ 'class': 'OpenFileEMFILE', 'data': {} }"
+
+#define QERR_EINTR \
+    "{ 'class': 'EINTR', 'data': {} }"
+
+#define QERR_EACCES \
+    "{ 'class': 'EACCES', 'data': {} }"
+
+#define QERR_EEXIST \
+    "{ 'class': 'EEXIST', 'data': {} }"

We use more descriptive names instead of using the errno name. Like AlreadyExists. Please fix it for errors you adding.

Quoted 19 lines
qerror.h +16 -0
+
+#define QERR_ENOSPC \
+    "{ 'class': 'ENOSPC', 'data': {} }"
+
+#define QERR_EPERM \
+    "{ 'class': 'EPERM', 'data': {} }"
+
+#define QERR_READ_ONLY \
+    "{ 'class': 'ReadOnly', 'data': {} }"
+
+#define QERR_ENOTDIR \
+    "{ 'class': 'ENOTDIR', 'data': {} }"
+
+#define QERR_EFBIG \
+    "{ 'class': 'EFBIG', 'data': {} }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
author
#18 lore raw

Re: [Qemu-devel] [PATCH v3 1/5] qerror: add error codes for fopen failure

Quoted 21 lines · Luiz Capitulino
Quoted 18 lines · On Sun, 18 Mar 2012 19:29:09 +0100 Alon Levy <[email protected]> wrote:

Added:

QERR_EINTR
QERR_EACCES
QERR_EEXIST
QERR_OPEN_FILE_EMFILE
QERR_ENOSPC
QERR_EPERM
QERR_READ_ONLY
QERR_ENOTDIR
QERR_EFBIG

---
 qerror.c |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h |   27 +++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
Quoted 14 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 218

Quoted 11 lines
qerror.c +3 -0
index f55d435..4915939 100644
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },

There are two problems here. First, the QERR_INTR macro doesn't have the filename argument, so this will crash.

Ugh, missed that.

Quoted 5 lines

The second problem is that, I've talked to Anthony and EINTR should not be returned to clients, it should be handled intead. So, please handle it during write().

Quoted 7 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 222

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EACCES,
+        .desc      = "Cannot access file'",
+    },

We already have QERR_PERMISSION_DENIED.

So you want to have both error conditions (EACCESS and EPERM) translated to the more generic PERMISSION_DENIED? This means that information is lost when looking at the error value. The main thing would be to show the filename, which we will do later as you said, so fine I guess.

Quoted 7 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 226

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EEXIST,
+        .desc      = "File already exists'",
+    },

Can you use the description provided by man 3 errno? This is valid for all errors you're adding.

It's a bit lengthy. But sure.

Quoted 37 lines
Quoted 37 lines
qerror.c +25 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOSPC,
+        .desc      = "No space left opening file'",
+    },
+    {
+        .error_fmt = QERR_EPERM,
+        .desc      = "Permission denied (EPERM) opening file'",
+    },
+    {
+        .error_fmt = QERR_READ_ONLY,
+        .desc      = "Read only filesystem opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOTDIR,
+        .desc      = "Directory related error opening file'",
+    },
+    {
+        .error_fmt = QERR_EFBIG,
+        .desc      = "File too big opening'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +0 -0
index e26c635..ddc04e8 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
Quoted 14 lines

qerror.h QError *qobject_to_qerror(const QObject *obj); · line 194

Quoted 11 lines
qerror.h +11 -0
+#define QERR_OPEN_FILE_EMFILE \
+    "{ 'class': 'OpenFileEMFILE', 'data': {} }"
+
+#define QERR_EINTR \
+    "{ 'class': 'EINTR', 'data': {} }"
+
+#define QERR_EACCES \
+    "{ 'class': 'EACCES', 'data': {} }"
+
+#define QERR_EEXIST \
+    "{ 'class': 'EEXIST', 'data': {} }"

We use more descriptive names instead of using the errno name. Like AlreadyExists. Please fix it for errors you adding.

Actually this was on purpose, to allow someone catching it to know it originated in a failed systemcall. So your way the catcher would have to go read the source (or hopefully I'll choose similar names).

Quoted 22 lines
Quoted 20 lines
qerror.h +16 -0
+
+#define QERR_ENOSPC \
+    "{ 'class': 'ENOSPC', 'data': {} }"
+
+#define QERR_EPERM \
+    "{ 'class': 'EPERM', 'data': {} }"
+
+#define QERR_READ_ONLY \
+    "{ 'class': 'ReadOnly', 'data': {} }"
+
+#define QERR_ENOTDIR \
+    "{ 'class': 'ENOTDIR', 'data': {} }"
+
+#define QERR_EFBIG \
+    "{ 'class': 'EFBIG', 'data': {} }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
#19 lore raw

Re: [Qemu-devel] [PATCH v3 1/5] qerror: add error codes for fopen failure

Quoted 49 lines · On Fri, 23 Mar 2012 21:53:03 +0200 Alon Levy <[email protected]> wrote:
Quoted 21 lines · Luiz Capitulino
Quoted 18 lines · On Sun, 18 Mar 2012 19:29:09 +0100 Alon Levy <[email protected]> wrote:

Added:

QERR_EINTR
QERR_EACCES
QERR_EEXIST
QERR_OPEN_FILE_EMFILE
QERR_ENOSPC
QERR_EPERM
QERR_READ_ONLY
QERR_ENOTDIR
QERR_EFBIG

---
 qerror.c |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h |   27 +++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
Quoted 14 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 218

Quoted 11 lines
qerror.c +3 -0
index f55d435..4915939 100644
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },

There are two problems here. First, the QERR_INTR macro doesn't have the filename argument, so this will crash.

Ugh, missed that.

Quoted 10 lines

The second problem is that, I've talked to Anthony and EINTR should not be returned to clients, it should be handled intead. So, please handle it during write().

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EACCES,
+        .desc      = "Cannot access file'",
+    },
Quoted 5 lines
Quoted 2 lines

We already have QERR_PERMISSION_DENIED.

So you want to have both error conditions (EACCESS and EPERM) translated to the more generic PERMISSION_DENIED?

I had forgotten about our discussion about this. You could add InvalidAccess, although I think we already use QERR_PERMISSION_DENIED as EACCESS...

Quoted 9 lines

This means that information is
lost when looking at the error value. The main thing would be to show the filename, which we will do later as you said, so fine I guess.

Quoted 5 lines
Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EEXIST,
+        .desc      = "File already exists'",
+    },
Quoted 4 lines
Quoted 2 lines

Can you use the description provided by man 3 errno? This is valid for all errors you're adding.

It's a bit lengthy. But sure.

You can trim it. The important point is to avoid creating new descriptions.

Quoted 53 lines
Quoted 38 lines
Quoted 38 lines
qerror.c +25 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOSPC,
+        .desc      = "No space left opening file'",
+    },
+    {
+        .error_fmt = QERR_EPERM,
+        .desc      = "Permission denied (EPERM) opening file'",
+    },
+    {
+        .error_fmt = QERR_READ_ONLY,
+        .desc      = "Read only filesystem opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOTDIR,
+        .desc      = "Directory related error opening file'",
+    },
+    {
+        .error_fmt = QERR_EFBIG,
+        .desc      = "File too big opening'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +0 -0
index e26c635..ddc04e8 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
Quoted 14 lines

qerror.h QError *qobject_to_qerror(const QObject *obj); · line 194

Quoted 11 lines
qerror.h +11 -0
+#define QERR_OPEN_FILE_EMFILE \
+    "{ 'class': 'OpenFileEMFILE', 'data': {} }"
+
+#define QERR_EINTR \
+    "{ 'class': 'EINTR', 'data': {} }"
+
+#define QERR_EACCES \
+    "{ 'class': 'EACCES', 'data': {} }"
+
+#define QERR_EEXIST \
+    "{ 'class': 'EEXIST', 'data': {} }"

We use more descriptive names instead of using the errno name. Like AlreadyExists. Please fix it for errors you adding.

Quoted 3 lines

Actually this was on purpose, to allow someone catching it to know it originated in a failed systemcall. So your way the catcher would have to go read the source (or hopefully I'll choose similar names).

No, if the command has a good description, like:

@AlreadyExists, if the file already exists

Then it's possible to know what happened and what the client should do.

Quoted 24 lines
Quoted 23 lines
Quoted 21 lines
qerror.h +16 -0
+
+#define QERR_ENOSPC \
+    "{ 'class': 'ENOSPC', 'data': {} }"
+
+#define QERR_EPERM \
+    "{ 'class': 'EPERM', 'data': {} }"
+
+#define QERR_READ_ONLY \
+    "{ 'class': 'ReadOnly', 'data': {} }"
+
+#define QERR_ENOTDIR \
+    "{ 'class': 'ENOTDIR', 'data': {} }"
+
+#define QERR_EFBIG \
+    "{ 'class': 'EFBIG', 'data': {} }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
author
#20 lore raw

Re: [Qemu-devel] [PATCH v3 1/5] qerror: add error codes for fopen failure

In reply to Luiz Capitulino
Quoted 36 lines · Luiz Capitulino
Quoted 23 lines · On Sun, 18 Mar 2012 19:29:09 +0100 Alon Levy <[email protected]> wrote:

Added:

QERR_EINTR
QERR_EACCES
QERR_EEXIST
QERR_OPEN_FILE_EMFILE
QERR_ENOSPC
QERR_EPERM
QERR_READ_ONLY
QERR_ENOTDIR
QERR_EFBIG

---
 qerror.c |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h |   27 +++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
qerror.c +0 -0
index f55d435..4915939 100644

qerror.c static const QErrorStringTable qerror_table[] = { · line 218

Quoted 6 lines
qerror.c +3 -0
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },

There are two problems here. First, the QERR_INTR macro doesn't have the filename argument, so this will crash.

Quoted 5 lines

The second problem is that, I've talked to Anthony and EINTR should not be returned to clients, it should be handled intead. So, please handle it during write().

From a brief due dilligence (git grep -A10 fopen | grep EINTR | wc -l ==

0) I gather that no one ever checks EINTR after fopen, so I'm going to avoid the complexity of possibly blocking in qemu_fopen_err and just note in the qapi-schema wherever an qemu_fopen_err derived error might be returned that the generic OpenFileFailed could indicate an EINTR.

I think it will at least be easier to fix it later in a single location, that is at qemu_fopen_err, in a later patch.

Quoted 88 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 222

Quoted 5 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EACCES,
+        .desc      = "Cannot access file'",
+    },

We already have QERR_PERMISSION_DENIED.

qerror.c static const QErrorStringTable qerror_table[] = { · line 226

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EEXIST,
+        .desc      = "File already exists'",
+    },

Can you use the description provided by man 3 errno? This is valid for all errors you're adding.

Quoted 37 lines
qerror.c +25 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOSPC,
+        .desc      = "No space left opening file'",
+    },
+    {
+        .error_fmt = QERR_EPERM,
+        .desc      = "Permission denied (EPERM) opening file'",
+    },
+    {
+        .error_fmt = QERR_READ_ONLY,
+        .desc      = "Read only filesystem opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOTDIR,
+        .desc      = "Directory related error opening file'",
+    },
+    {
+        .error_fmt = QERR_EFBIG,
+        .desc      = "File too big opening'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +1 -0
index e26c635..ddc04e8 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_OPEN_FILE_EMFILE \

qerror.h QError *qobject_to_qerror(const QObject *obj); · line 194

Quoted 10 lines
qerror.h +10 -0
+    "{ 'class': 'OpenFileEMFILE', 'data': {} }"
+
+#define QERR_EINTR \
+    "{ 'class': 'EINTR', 'data': {} }"
+
+#define QERR_EACCES \
+    "{ 'class': 'EACCES', 'data': {} }"
+
+#define QERR_EEXIST \
+    "{ 'class': 'EEXIST', 'data': {} }"

We use more descriptive names instead of using the errno name. Like AlreadyExists. Please fix it for errors you adding.

Quoted 19 lines
qerror.h +16 -0
+
+#define QERR_ENOSPC \
+    "{ 'class': 'ENOSPC', 'data': {} }"
+
+#define QERR_EPERM \
+    "{ 'class': 'EPERM', 'data': {} }"
+
+#define QERR_READ_ONLY \
+    "{ 'class': 'ReadOnly', 'data': {} }"
+
+#define QERR_ENOTDIR \
+    "{ 'class': 'ENOTDIR', 'data': {} }"
+
+#define QERR_EFBIG \
+    "{ 'class': 'EFBIG', 'data': {} }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
author
#21 lore raw

Re: [Qemu-devel] [PATCH v3 1/5] qerror: add error codes for fopen failure

In reply to Luiz Capitulino
Quoted 36 lines · Luiz Capitulino
Quoted 23 lines · On Sun, 18 Mar 2012 19:29:09 +0100 Alon Levy <[email protected]> wrote:

Added:

QERR_EINTR
QERR_EACCES
QERR_EEXIST
QERR_OPEN_FILE_EMFILE
QERR_ENOSPC
QERR_EPERM
QERR_READ_ONLY
QERR_ENOTDIR
QERR_EFBIG

---
 qerror.c |   36 ++++++++++++++++++++++++++++++++++++
 qerror.h |   27 +++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
qerror.c +0 -0
index f55d435..4915939 100644

qerror.c static const QErrorStringTable qerror_table[] = { · line 218

Quoted 6 lines
qerror.c +3 -0
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
         .desc      = "Could not open '%(filename)'",
     },
     {
+        .error_fmt = QERR_EINTR,
+        .desc      = "Interrupted open of '%(filename)'",
+    },

There are two problems here. First, the QERR_INTR macro doesn't have the filename argument, so this will crash.

Quoted 3 lines

The second problem is that, I've talked to Anthony and EINTR should not be returned to clients, it should be handled intead. So, please handle it during write().

That would require either blocking or using async monitor... and in general I guess it makes the signature of qemu_fopen_err be:

void qemu_fopen_err(const char *path, const char *mode, int block,
Error **errp)

Sounds ok?

Quoted 88 lines

qerror.c static const QErrorStringTable qerror_table[] = { · line 222

Quoted 5 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EACCES,
+        .desc      = "Cannot access file'",
+    },

We already have QERR_PERMISSION_DENIED.

qerror.c static const QErrorStringTable qerror_table[] = { · line 226

Quoted 4 lines
qerror.c +4 -0
+    {
+        .error_fmt = QERR_EEXIST,
+        .desc      = "File already exists'",
+    },

Can you use the description provided by man 3 errno? This is valid for all errors you're adding.

Quoted 37 lines
qerror.c +25 -0
+    {
+        .error_fmt = QERR_OPEN_FILE_EMFILE,
+        .desc      = "Max open files when opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOSPC,
+        .desc      = "No space left opening file'",
+    },
+    {
+        .error_fmt = QERR_EPERM,
+        .desc      = "Permission denied (EPERM) opening file'",
+    },
+    {
+        .error_fmt = QERR_READ_ONLY,
+        .desc      = "Read only filesystem opening file'",
+    },
+    {
+        .error_fmt = QERR_ENOTDIR,
+        .desc      = "Directory related error opening file'",
+    },
+    {
+        .error_fmt = QERR_EFBIG,
+        .desc      = "File too big opening'",
+    },
+    {
         .error_fmt = QERR_PERMISSION_DENIED,
         .desc      = "Insufficient permission to perform this operation",
     },
qerror.h +1 -0
index e26c635..ddc04e8 100644
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_OPEN_FILE_EMFILE \

qerror.h QError *qobject_to_qerror(const QObject *obj); · line 194

Quoted 10 lines
qerror.h +10 -0
+    "{ 'class': 'OpenFileEMFILE', 'data': {} }"
+
+#define QERR_EINTR \
+    "{ 'class': 'EINTR', 'data': {} }"
+
+#define QERR_EACCES \
+    "{ 'class': 'EACCES', 'data': {} }"
+
+#define QERR_EEXIST \
+    "{ 'class': 'EEXIST', 'data': {} }"

We use more descriptive names instead of using the errno name. Like AlreadyExists. Please fix it for errors you adding.

Quoted 19 lines
qerror.h +16 -0
+
+#define QERR_ENOSPC \
+    "{ 'class': 'ENOSPC', 'data': {} }"
+
+#define QERR_EPERM \
+    "{ 'class': 'EPERM', 'data': {} }"
+
+#define QERR_READ_ONLY \
+    "{ 'class': 'ReadOnly', 'data': {} }"
+
+#define QERR_ENOTDIR \
+    "{ 'class': 'ENOTDIR', 'data': {} }"
+
+#define QERR_EFBIG \
+    "{ 'class': 'EFBIG', 'data': {} }"
+
 #define QERR_PERMISSION_DENIED \
     "{ 'class': 'PermissionDenied', 'data': {} }"
 
author
#22 lore raw

PATCH v3 2/5 add qemu_fopen_err

In reply to Alon Levy

This adds a helper to conveniently set the correct error based on the errno after a failed fopen.

The added function is placed in it's own c file to allow libcacard to not develop dependencies on everything that qerror will bring in, which includes monitor and half of qemu. I tried to make it as less ugly as I could, by naming an osdep-no-qerror-obj-y and having that included in osdep-obj-y, and using only the former for libcacard.

---
 Makefile.objs      |    8 +++++---
 libcacard/Makefile |    2 +-
 osdep-qerror.c     |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 osdep-qerror.h     |    8 ++++++++
 osdep.c            |    1 -
 5 files changed, 66 insertions(+), 5 deletions(-)
 create mode 100644 osdep-qerror.c
 create mode 100644 osdep-qerror.h
Makefile.objs +5 -3
index 226b01d..fb5a73a 100644
@@ -20,9 +20,11 @@ universal-obj-y += $(qom-obj-y)
 
 #######################################################################
 # oslib-obj-y is code depending on the OS (win32 vs posix)
-oslib-obj-y = osdep.o
-oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
-oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
+oslib-no-qerror-obj-y = osdep.o
+oslib-no-qerror-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
+oslib-no-qerror-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
+oslib-obj-y = $(oslib-no-qerror-obj-y)
+oslib-obj-y += osdep-qerror.o
 
 #######################################################################
 # coroutines
libcacard/Makefile +1 -1
index c6a896a..83f483f 100644
@@ -8,7 +8,7 @@ libcacard_includedir=$(includedir)/cacard
 $(call set-vpath, $(SRC_PATH):$(libcacard_srcpath))
 
 # objects linked against normal qemu binaries, not compiled with libtool
-QEMU_OBJS=$(addprefix ../,$(oslib-obj-y) qemu-timer-common.o $(trace-obj-y))
+QEMU_OBJS=$(addprefix ../,$(oslib-no-qerror-obj-y) qemu-timer-common.o $(trace-obj-y))
 
 # objects linked into a shared library, built with libtool with -fPIC if required
 QEMU_OBJS_LIB=$(addsuffix .lo,$(basename $(QEMU_OBJS)))
osdep-qerror.c new file +52 -0

52 lines not on this page · raw message

osdep-qerror.h new file +8 -0
new file mode 100644
index 0000000..7320f4a
@@ -0,0 +1,8 @@
+#ifndef OSDEP_QERROR_H
+#define OSDEP_QERROR_H
+
+#include "error.h"
+
+void qemu_fopen_err(Error **errp, const char *file_name);
+
+#endif
osdep.c +0 -1
index 3e6bada..efdd21c 100644
@@ -241,4 +241,3 @@ ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags)
 
     return total;
 }
-
Signature · 1 line
1.7.9.3
#23 lore raw

Re: [Qemu-devel] [PATCH v3 2/5] add qemu_fopen_err

Quoted 8 lines · On Sun, 18 Mar 2012 19:29:10 +0100 Alon Levy <[email protected]> wrote:

This adds a helper to conveniently set the correct error based on the errno after a failed fopen.

The added function is placed in it's own c file to allow libcacard to not develop dependencies on everything that qerror will bring in, which includes monitor and half of qemu. I tried to make it as less ugly as I could, by naming an osdep-no-qerror-obj-y and having that included in osdep-obj-y, and using only the former for libcacard.

I'm not sure I like this, how will libcacard report errors then?

Quoted 52 lines
---
 Makefile.objs      |    8 +++++---
 libcacard/Makefile |    2 +-
 osdep-qerror.c     |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 osdep-qerror.h     |    8 ++++++++
 osdep.c            |    1 -
 5 files changed, 66 insertions(+), 5 deletions(-)
 create mode 100644 osdep-qerror.c
 create mode 100644 osdep-qerror.h
Makefile.objs +5 -3
index 226b01d..fb5a73a 100644
@@ -20,9 +20,11 @@ universal-obj-y += $(qom-obj-y)
 
 #######################################################################
 # oslib-obj-y is code depending on the OS (win32 vs posix)
-oslib-obj-y = osdep.o
-oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
-oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
+oslib-no-qerror-obj-y = osdep.o
+oslib-no-qerror-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
+oslib-no-qerror-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
+oslib-obj-y = $(oslib-no-qerror-obj-y)
+oslib-obj-y += osdep-qerror.o
 
 #######################################################################
 # coroutines
libcacard/Makefile +1 -1
index c6a896a..83f483f 100644
@@ -8,7 +8,7 @@ libcacard_includedir=$(includedir)/cacard
 $(call set-vpath, $(SRC_PATH):$(libcacard_srcpath))
 
 # objects linked against normal qemu binaries, not compiled with libtool
-QEMU_OBJS=$(addprefix ../,$(oslib-obj-y) qemu-timer-common.o $(trace-obj-y))
+QEMU_OBJS=$(addprefix ../,$(oslib-no-qerror-obj-y) qemu-timer-common.o $(trace-obj-y))
 
 # objects linked into a shared library, built with libtool with -fPIC if required
 QEMU_OBJS_LIB=$(addsuffix .lo,$(basename $(QEMU_OBJS)))
osdep-qerror.c new file +2 -0
new file mode 100644
index 0000000..6dac984
@@ -0,0 +1,52 @@
+#include "qerror.h"
+

osdep-qerror.c line 12

Quoted 10 lines
osdep-qerror.c new file +10 -0
+#include "osdep-qerror.h"
+
+/*
+ * Helper to set an Error after a failed fopen.
+ *
+ * Uses errno so it must not be changed by another intermediate call.
+ */
+void qemu_fopen_err(Error **errp, const char *file_name)
+{
+    const char *fmt = NULL;

Where's the fopen() call and the mode argument?

Quoted 63 lines
osdep-qerror.c new file +40 -0
+
+    switch (errno) {
+    case EACCES:
+        fmt = QERR_EACCES;
+        break;
+    case EINTR:
+        fmt = QERR_EINTR;
+        break;
+    case EEXIST:
+        fmt = QERR_EEXIST;
+        break;
+    case EMFILE:
+        fmt = QERR_OPEN_FILE_EMFILE;
+        break;
+    case ENOSPC:
+        fmt = QERR_ENOSPC;
+        break;
+    case EPERM:
+        fmt = QERR_EPERM;
+        break;
+    case EROFS:
+        fmt = QERR_READ_ONLY;
+        break;
+    case ENOTDIR:
+        fmt = QERR_ENOTDIR;
+        break;
+    case EFBIG:
+        fmt = QERR_EFBIG;
+        break;
+    default:
+        /*
+         * EINVAL and ENOTSUP will result in the default
+         *
+         * ENOENT too, it's used by (for instance) bdrv_create_file for
+         * a different purpose then open (2) so just give a generic error.
+         */
+        fmt = QERR_OPEN_FILE_FAILED;
+    }
+    error_set(errp, fmt, file_name);
+}
osdep-qerror.h new file +8 -0
new file mode 100644
index 0000000..7320f4a
@@ -0,0 +1,8 @@
+#ifndef OSDEP_QERROR_H
+#define OSDEP_QERROR_H
+
+#include "error.h"
+
+void qemu_fopen_err(Error **errp, const char *file_name);
+
+#endif
osdep.c +0 -1
index 3e6bada..efdd21c 100644
@@ -241,4 +241,3 @@ ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags)
 
     return total;
 }
-
author
#24 lore raw

Re: [Qemu-devel] [PATCH v3 2/5] add qemu_fopen_err

Quoted 6 lines · Luiz Capitulino
Quoted 3 lines · On Sun, 18 Mar 2012 19:29:10 +0100 Alon Levy <[email protected]> wrote:

This adds a helper to conveniently set the correct error based on the errno after a failed fopen.

Quoted 7 lines
Quoted 5 lines

The added function is placed in it's own c file to allow libcacard to not develop dependencies on everything that qerror will bring in, which includes monitor and half of qemu. I tried to make it as less ugly as I could, by naming an osdep-no-qerror-obj-y and having that included in osdep-obj-y, and using only the former for libcacard.

I'm not sure I like this, how will libcacard report errors then?

libcacard is a standalone library, it reports errors via it's existing interfaces. Changing it to use qerror is possibly a good idea but not part of this patchset.

Quoted 131 lines
Quoted 53 lines
---
 Makefile.objs      |    8 +++++---
 libcacard/Makefile |    2 +-
 osdep-qerror.c     |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 osdep-qerror.h     |    8 ++++++++
 osdep.c            |    1 -
 5 files changed, 66 insertions(+), 5 deletions(-)
 create mode 100644 osdep-qerror.c
 create mode 100644 osdep-qerror.h
Makefile.objs +5 -3
index 226b01d..fb5a73a 100644
@@ -20,9 +20,11 @@ universal-obj-y += $(qom-obj-y)
 
 #######################################################################
 # oslib-obj-y is code depending on the OS (win32 vs posix)
-oslib-obj-y = osdep.o
-oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
-oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
+oslib-no-qerror-obj-y = osdep.o
+oslib-no-qerror-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
+oslib-no-qerror-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
+oslib-obj-y = $(oslib-no-qerror-obj-y)
+oslib-obj-y += osdep-qerror.o
 
 #######################################################################
 # coroutines
libcacard/Makefile +1 -1
index c6a896a..83f483f 100644
@@ -8,7 +8,7 @@ libcacard_includedir=$(includedir)/cacard
 $(call set-vpath, $(SRC_PATH):$(libcacard_srcpath))
 
 # objects linked against normal qemu binaries, not compiled with libtool
-QEMU_OBJS=$(addprefix ../,$(oslib-obj-y) qemu-timer-common.o $(trace-obj-y))
+QEMU_OBJS=$(addprefix ../,$(oslib-no-qerror-obj-y) qemu-timer-common.o $(trace-obj-y))
 
 # objects linked into a shared library, built with libtool with -fPIC if required
 QEMU_OBJS_LIB=$(addsuffix .lo,$(basename $(QEMU_OBJS)))
osdep-qerror.c new file +2 -0
new file mode 100644
index 0000000..6dac984
@@ -0,0 +1,52 @@
+#include "qerror.h"
+

osdep-qerror.c line 12

Quoted 10 lines
osdep-qerror.c new file +10 -0
+#include "osdep-qerror.h"
+
+/*
+ * Helper to set an Error after a failed fopen.
+ *
+ * Uses errno so it must not be changed by another intermediate call.
+ */
+void qemu_fopen_err(Error **errp, const char *file_name)
+{
+    const char *fmt = NULL;

Where's the fopen() call and the mode argument?

Quoted 63 lines
osdep-qerror.c new file +40 -0
+
+    switch (errno) {
+    case EACCES:
+        fmt = QERR_EACCES;
+        break;
+    case EINTR:
+        fmt = QERR_EINTR;
+        break;
+    case EEXIST:
+        fmt = QERR_EEXIST;
+        break;
+    case EMFILE:
+        fmt = QERR_OPEN_FILE_EMFILE;
+        break;
+    case ENOSPC:
+        fmt = QERR_ENOSPC;
+        break;
+    case EPERM:
+        fmt = QERR_EPERM;
+        break;
+    case EROFS:
+        fmt = QERR_READ_ONLY;
+        break;
+    case ENOTDIR:
+        fmt = QERR_ENOTDIR;
+        break;
+    case EFBIG:
+        fmt = QERR_EFBIG;
+        break;
+    default:
+        /*
+         * EINVAL and ENOTSUP will result in the default
+         *
+         * ENOENT too, it's used by (for instance) bdrv_create_file for
+         * a different purpose then open (2) so just give a generic error.
+         */
+        fmt = QERR_OPEN_FILE_FAILED;
+    }
+    error_set(errp, fmt, file_name);
+}
osdep-qerror.h new file +8 -0
new file mode 100644
index 0000000..7320f4a
@@ -0,0 +1,8 @@
+#ifndef OSDEP_QERROR_H
+#define OSDEP_QERROR_H
+
+#include "error.h"
+
+void qemu_fopen_err(Error **errp, const char *file_name);
+
+#endif
osdep.c +0 -1
index 3e6bada..efdd21c 100644
@@ -241,4 +241,3 @@ ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags)
 
     return total;
 }
-
author
#25 lore raw

PATCH v3 3/5 vga_hw_screen_dump: add Error** param

In reply to Alon Levy

To later use for qapi implementation of screendump.

---
 console.c       |    5 +++--
 console.h       |    6 ++++--
 hw/blizzard.c   |    3 ++-
 hw/g364fb.c     |    4 +++-
 hw/omap_lcdc.c  |    4 +++-
 hw/qxl.c        |    6 ++++--
 hw/tcx.c        |   13 +++++++++----
 hw/vga.c        |    7 +++++--
 hw/vmware_vga.c |    6 ++++--
 monitor.c       |    2 +-
 10 files changed, 38 insertions(+), 18 deletions(-)
console.c +3 -2
index 6a463f5..d3fccf3 100644
@@ -24,6 +24,7 @@
 #include "qemu-common.h"
 #include "console.h"
 #include "qemu-timer.h"
+#include "error.h"
 
 //#define DEBUG_CONSOLE
 #define DEFAULT_BACKSCROLL 512
@@ -173,7 +174,7 @@ void vga_hw_invalidate(void)
         active_console->hw_invalidate(active_console->hw);
 }
 
-void vga_hw_screen_dump(const char *filename)
+void vga_hw_screen_dump(const char *filename, Error **errp)
 {
     TextConsole *previous_active_console;
     bool cswitch;
@@ -187,7 +188,7 @@ void vga_hw_screen_dump(const char *filename)
         console_select(0);
     }
     if (consoles[0] && consoles[0]->hw_screen_dump) {
-        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch);
+        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch, errp);
     } else {
         error_report("screen dump not implemented");
     }
console.h +4 -2
index 4334db5..caf13f5 100644
@@ -6,6 +6,7 @@
 #include "notify.h"
 #include "monitor.h"
 #include "trace.h"
+#include "error.h"
 
 /* keyboard/mouse support */
 
@@ -343,7 +344,8 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
 
 typedef void (*vga_hw_update_ptr)(void *);
 typedef void (*vga_hw_invalidate_ptr)(void *);
-typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
+typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
+                                       Error **errp);
 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
 
 DisplayState *graphic_console_init(vga_hw_update_ptr update,
@@ -354,7 +356,7 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,
 
 void vga_hw_update(void);
 void vga_hw_invalidate(void);
-void vga_hw_screen_dump(const char *filename);
+void vga_hw_screen_dump(const char *filename, Error **errp);
 void vga_hw_text_update(console_ch_t *chardata);
 
 int is_graphic_console(void);
hw/blizzard.c +2 -1
index c7d844d..76df78c 100644
@@ -23,6 +23,7 @@
 #include "devices.h"
 #include "vga_int.h"
 #include "pixel_ops.h"
+#include "error.h"
 
 typedef void (*blizzard_fn_t)(uint8_t *, const uint8_t *, unsigned int);
 
@@ -933,7 +934,7 @@ static void blizzard_update_display(void *opaque)
 }
 
 static void blizzard_screen_dump(void *opaque, const char *filename,
-                                 bool cswitch)
+                                 bool cswitch, Error **errp)
 {
     BlizzardState *s = (BlizzardState *) opaque;
 
hw/g364fb.c +3 -1
index 3a0b68f..7774d05 100644
@@ -22,6 +22,7 @@
 #include "pixel_ops.h"
 #include "trace.h"
 #include "sysbus.h"
+#include "error.h"
 
 typedef struct G364State {
     /* hardware */
@@ -289,7 +290,8 @@ static void g364fb_reset(G364State *s)
     g364fb_invalidate_display(s);
 }
 
-static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void g364fb_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     G364State *s = opaque;
     int y, x;
hw/omap_lcdc.c +3 -1
index f172093..aec7210 100644
@@ -20,6 +20,7 @@
 #include "console.h"
 #include "omap.h"
 #include "framebuffer.h"
+#include "error.h"
 
 struct omap_lcd_panel_s {
     MemoryRegion *sysmem;
@@ -264,7 +265,8 @@ static int ppm_save(const char *filename, uint8_t *data,
     return 0;
 }
 
-static void omap_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void omap_screen_dump(void *opaque, const char *filename, bool cswitch,
+                             Error **errp)
 {
     struct omap_lcd_panel_s *omap_lcd = opaque;
     if (cswitch) {
hw/qxl.c +4 -2
index e17b0e3..27f27f5 100644
@@ -23,6 +23,7 @@
 #include "qemu-queue.h"
 #include "monitor.h"
 #include "sysemu.h"
+#include "error.h"
 
 #include "qxl.h"
 
@@ -1492,7 +1493,8 @@ static void qxl_hw_invalidate(void *opaque)
     vga->invalidate(vga);
 }
 
-static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     PCIQXLDevice *qxl = opaque;
     VGACommonState *vga = &qxl->vga;
@@ -1504,7 +1506,7 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch)
         ppm_save(filename, qxl->ssd.ds->surface);
         break;
     case QXL_MODE_VGA:
-        vga->screen_dump(vga, filename, cswitch);
+        vga->screen_dump(vga, filename, cswitch, errp);
         break;
     default:
         break;
hw/tcx.c +9 -4
index ac7dcb4..f342a5d 100644
@@ -26,6 +26,7 @@
 #include "pixel_ops.h"
 #include "sysbus.h"
 #include "qdev-addr.h"
+#include "error.h"
 
 #define MAXX 1024
 #define MAXY 768
@@ -56,8 +57,10 @@ typedef struct TCXState {
     uint8_t dac_index, dac_state;
 } TCXState;
 
-static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch);
-static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch);
+static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error *errp);
+static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch,
+                              Error *errp);
 
 static void tcx_set_dirty(TCXState *s)
 {
@@ -574,7 +577,8 @@ static int tcx_init1(SysBusDevice *dev)
     return 0;
 }
 
-static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error *errp)
 {
     TCXState *s = opaque;
     FILE *f;
@@ -601,7 +605,8 @@ static void tcx_screen_dump(void *opaque, const char *filename, bool cswitch)
     return;
 }
 
-static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch,
+                              Error *errp)
 {
     TCXState *s = opaque;
     FILE *f;
hw/vga.c +5 -2
index 6dc98f6..79c5c38 100644
@@ -31,6 +31,7 @@
 #include "qemu-timer.h"
 #include "xen.h"
 #include "trace.h"
+#include "error.h"
 
 //#define DEBUG_VGA
 //#define DEBUG_VGA_MEM
@@ -163,7 +164,8 @@ static uint32_t expand4[256];
 static uint16_t expand2[256];
 static uint8_t expand4to8[16];
 
-static void vga_screen_dump(void *opaque, const char *filename, bool cswitch);
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error **errp);
 
 static void vga_update_memory_access(VGACommonState *s)
 {
@@ -2409,7 +2411,8 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
 
 /* save the vga display in a PPM image even if no display is
    available */
-static void vga_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                            Error **errp)
 {
     VGACommonState *s = opaque;
 
hw/vmware_vga.c +4 -2
index 142d9f4..6868778 100644
@@ -26,6 +26,7 @@
 #include "console.h"
 #include "pci.h"
 #include "vmware_vga.h"
+#include "error.h"
 
 #undef VERBOSE
 #define HW_RECT_ACCEL
@@ -1003,11 +1004,12 @@ static void vmsvga_invalidate_display(void *opaque)
 
 /* save the vga display in a PPM image even if no display is
    available */
-static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch,
+                               Error **errp)
 {
     struct vmsvga_state_s *s = opaque;
     if (!s->enable) {
-        s->vga.screen_dump(&s->vga, filename, cswitch);
+        s->vga.screen_dump(&s->vga, filename, cswitch, errp);
         return;
     }
 
monitor.c +1 -1
index d57e7bf..2156fcf 100644
@@ -895,7 +895,7 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
 
 static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
-    vga_hw_screen_dump(qdict_get_str(qdict, "filename"));
+    vga_hw_screen_dump(qdict_get_str(qdict, "filename"), NULL);
     return 0;
 }
 
Signature · 1 line
1.7.9.3
author
#26 lore raw

PATCH v3 4/5 qapi: convert screendump

In reply to Alon Levy

The documenting comment contains the long list of possible errors from qemu_fopen_err, this could probably be put somewhere else in the file once more of the api uses those common error classes.

---
 hmp-commands.hx  |    3 +--
 hmp.c            |    8 ++++++++
 hmp.h            |    1 +
 monitor.c        |    6 ------
 qapi-schema.json |   24 ++++++++++++++++++++++++
 qmp-commands.hx  |    5 +----
 qmp.c            |    5 +++++
 7 files changed, 40 insertions(+), 12 deletions(-)
hmp-commands.hx +1 -2
index 6980214..d26421a 100644
@@ -194,8 +194,7 @@ ETEXI
         .args_type  = "filename:F",
         .params     = "filename",
         .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd = hmp_screendump,
     },
 
 STEXI
hmp.c +8 -0
index 290c43d..42dc79a 100644
@@ -860,3 +860,11 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
 
     hmp_handle_error(mon, &error);
 }
+
+void hmp_screendump(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+
+    qmp_screendump(qdict_get_str(qdict, "filename"), &err);
+    hmp_handle_error(mon, &err);
+}
hmp.h +1 -0
index 5409464..25d123f 100644
@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);
 void hmp_block_stream(Monitor *mon, const QDict *qdict);
 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
+void hmp_screendump(Monitor *mon, const QDict *qdict);
 
 #endif
monitor.c +0 -6
index 2156fcf..34d7617 100644
@@ -893,12 +893,6 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
     return -1;
 }
 
-static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-    vga_hw_screen_dump(qdict_get_str(qdict, "filename"), NULL);
-    return 0;
-}
-
 static void do_logfile(Monitor *mon, const QDict *qdict)
 {
     cpu_set_log_filename(qdict_get_str(qdict, "filename"));
qapi-schema.json +24 -0
index 04fa84f..b9baba9 100644
@@ -1663,3 +1663,27 @@
 { 'command': 'qom-list-types',
   'data': { '*implements': 'str', '*abstract': 'bool' },
   'returns': [ 'ObjectTypeInfo' ] }
+
+##
+# @screendump:
+#
+# Write a PPM of the VGA screen to a file.
+#
+# @filename: the name of a new PPM file to create to store the image
+#
+# Returns: Nothing on success
+#          If @cpu is not a valid VCPU, InvalidParameterValue
+#          If @filename cannot be opened, OpenFileFailed or one of the more
+#          specific errors:
+#            EINTR - Interruped during operation
+#            EACCES - Cannot access file
+#            OpenFileEMFILE - Maximum open file descriptors reached
+#            ENOSPC - No space on device
+#            EPERM - No permission
+#            READ_ONLY - File system is read only
+#            ENOTDIR - Path to file contains a non directory element
+#
+##
+# Since: 1.1
+##
+{ 'command': 'screendump', 'data': {'filename': 'str'} }
qmp-commands.hx +1 -4
index dfe8a5b..5fe57fd 100644
@@ -146,10 +146,7 @@ EQMP
     {
         .name       = "screendump",
         .args_type  = "filename:F",
-        .params     = "filename",
-        .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd_new = qmp_marshal_input_screendump,
     },
 
 SQMP
qmp.c +5 -0
index a182b51..086cec8 100644
@@ -415,3 +415,8 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
 
     return ret;
 }
+
+void qmp_screendump(const char *filename, Error **errp)
+{
+    vga_hw_screen_dump(filename, errp);
+}
Signature · 1 line
1.7.9.3
#27 lore raw

Re: [Qemu-devel] [PATCH v3 4/5] qapi: convert screendump

Quoted 90 lines · On Sun, 18 Mar 2012 19:29:12 +0100 Alon Levy <[email protected]> wrote:

The documenting comment contains the long list of possible errors from qemu_fopen_err, this could probably be put somewhere else in the file once more of the api uses those common error classes.

---
 hmp-commands.hx  |    3 +--
 hmp.c            |    8 ++++++++
 hmp.h            |    1 +
 monitor.c        |    6 ------
 qapi-schema.json |   24 ++++++++++++++++++++++++
 qmp-commands.hx  |    5 +----
 qmp.c            |    5 +++++
 7 files changed, 40 insertions(+), 12 deletions(-)
hmp-commands.hx +1 -2
index 6980214..d26421a 100644
@@ -194,8 +194,7 @@ ETEXI
         .args_type  = "filename:F",
         .params     = "filename",
         .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd = hmp_screendump,
     },
 
 STEXI
hmp.c +8 -0
index 290c43d..42dc79a 100644
@@ -860,3 +860,11 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
 
     hmp_handle_error(mon, &error);
 }
+
+void hmp_screendump(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+
+    qmp_screendump(qdict_get_str(qdict, "filename"), &err);
+    hmp_handle_error(mon, &err);
+}
hmp.h +1 -0
index 5409464..25d123f 100644
@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);
 void hmp_block_stream(Monitor *mon, const QDict *qdict);
 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
+void hmp_screendump(Monitor *mon, const QDict *qdict);
 
 #endif
monitor.c +0 -6
index 2156fcf..34d7617 100644
@@ -893,12 +893,6 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
     return -1;
 }
 
-static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-    vga_hw_screen_dump(qdict_get_str(qdict, "filename"), NULL);
-    return 0;
-}
-
 static void do_logfile(Monitor *mon, const QDict *qdict)
 {
     cpu_set_log_filename(qdict_get_str(qdict, "filename"));
qapi-schema.json +9 -0
index 04fa84f..b9baba9 100644
@@ -1663,3 +1663,27 @@
 { 'command': 'qom-list-types',
   'data': { '*implements': 'str', '*abstract': 'bool' },
   'returns': [ 'ObjectTypeInfo' ] }
+
+##
+# @screendump:
+#
+# Write a PPM of the VGA screen to a file.
+#
+# @filename: the name of a new PPM file to create to store the image
+#
+# Returns: Nothing on success

qapi-schema.json line 1684

Quoted 10 lines
qapi-schema.json +10 -0
+#          If @cpu is not a valid VCPU, InvalidParameterValue
+#          If @filename cannot be opened, OpenFileFailed or one of the more
+#          specific errors:
+#            EINTR - Interruped during operation
+#            EACCES - Cannot access file
+#            OpenFileEMFILE - Maximum open file descriptors reached
+#            ENOSPC - No space on device
+#            EPERM - No permission
+#            READ_ONLY - File system is read only
+#            ENOTDIR - Path to file contains a non directory element

We write the errors a bit different, please take a look at other commands.

Quoted 34 lines
qapi-schema.json +5 -0
+#
+##
+# Since: 1.1
+##
+{ 'command': 'screendump', 'data': {'filename': 'str'} }
qmp-commands.hx +1 -4
index dfe8a5b..5fe57fd 100644
@@ -146,10 +146,7 @@ EQMP
     {
         .name       = "screendump",
         .args_type  = "filename:F",
-        .params     = "filename",
-        .help       = "save screen into PPM image 'filename'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_screen_dump,
+        .mhandler.cmd_new = qmp_marshal_input_screendump,
     },
 
 SQMP
qmp.c +5 -0
index a182b51..086cec8 100644
@@ -415,3 +415,8 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
 
     return ret;
 }
+
+void qmp_screendump(const char *filename, Error **errp)
+{
+    vga_hw_screen_dump(filename, errp);
+}
author
#28 lore raw

PATCH v3 5/5 vga: ppm_save(): Return error on failure

In reply to Alon Levy

From: Luiz Capitulino <[email protected]>

This makes all devices using ppm_save() return an error appropriately when the screendump command fails.

Based on a code by Anthony Liguori.

---
 hw/blizzard.c   |    2 +-
 hw/qxl.c        |    2 +-
 hw/vga.c        |    8 +++++---
 hw/vga_int.h    |    3 ++-
 hw/vmware_vga.c |    2 +-
 5 files changed, 10 insertions(+), 7 deletions(-)
hw/blizzard.c +1 -1
index 76df78c..29e5ae6 100644
@@ -942,7 +942,7 @@ static void blizzard_screen_dump(void *opaque, const char *filename,
         blizzard_update_display(opaque);
     }
     if (s && ds_get_data(s->state))
-        ppm_save(filename, s->state->surface);
+        ppm_save(filename, s->state->surface, errp);
 }
 
 #define DEPTH 8
hw/qxl.c +1 -1
index 27f27f5..aa68612 100644
@@ -1503,7 +1503,7 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch,
     case QXL_MODE_COMPAT:
     case QXL_MODE_NATIVE:
         qxl_render_update(qxl);
-        ppm_save(filename, qxl->ssd.ds->surface);
+        ppm_save(filename, qxl->ssd.ds->surface, errp);
         break;
     case QXL_MODE_VGA:
         vga->screen_dump(vga, filename, cswitch, errp);
hw/vga.c +5 -3
index 79c5c38..80e6dca 100644
@@ -2365,7 +2365,7 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion *system_memory)
 /********************************************************/
 /* vga screen dump */
 
-int ppm_save(const char *filename, struct DisplaySurface *ds)
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp)
 {
     FILE *f;
     uint8_t *d, *d1;
@@ -2377,8 +2377,10 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
 
     trace_ppm_save(filename, ds);
     f = fopen(filename, "wb");
-    if (!f)
+    if (!f) {
+        error_set_file_open_failed(errp, filename, errno);
         return -1;
+    }
     fprintf(f, "P6\n%d %d\n%d\n",
             ds->width, ds->height, 255);
     linebuf = g_malloc(ds->width * 3);
@@ -2420,5 +2422,5 @@ static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
         vga_invalidate_display(s);
         vga_hw_update();
     }
-    ppm_save(filename, s->ds->surface);
+    ppm_save(filename, s->ds->surface, errp);
 }
hw/vga_int.h +2 -1
index 7685b2b..63078ba 100644
@@ -24,6 +24,7 @@
 
 #include <hw/hw.h>
 #include "memory.h"
+#include "error.h"
 
 #define ST01_V_RETRACE      0x08
 #define ST01_DISP_ENABLE    0x01
@@ -200,7 +201,7 @@ void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val);
 uint32_t vga_mem_readb(VGACommonState *s, target_phys_addr_t addr);
 void vga_mem_writeb(VGACommonState *s, target_phys_addr_t addr, uint32_t val);
 void vga_invalidate_scanlines(VGACommonState *s, int y1, int y2);
-int ppm_save(const char *filename, struct DisplaySurface *ds);
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp);
 
 int vga_ioport_invalid(VGACommonState *s, uint32_t addr);
 void vga_init_vbe(VGACommonState *s, MemoryRegion *address_space);
hw/vmware_vga.c +1 -1
index 6868778..0769652 100644
@@ -1016,7 +1016,7 @@ static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch,
     if (s->depth == 32) {
         DisplaySurface *ds = qemu_create_displaysurface_from(s->width,
                 s->height, 32, ds_get_linesize(s->vga.ds), s->vga.vram_ptr);
-        ppm_save(filename, ds);
+        ppm_save(filename, ds, errp);
         g_free(ds);
     }
 }
Signature · 1 line
1.7.9.3
#29 lore raw

Re: [Qemu-devel] [PATCH v3 5/5] vga: ppm_save(): Return error on failure

Quoted 57 lines · On Sun, 18 Mar 2012 19:29:13 +0100 Alon Levy <[email protected]> wrote:

From: Luiz Capitulino <[email protected]>

This makes all devices using ppm_save() return an error appropriately when the screendump command fails.

Based on a code by Anthony Liguori.

---
 hw/blizzard.c   |    2 +-
 hw/qxl.c        |    2 +-
 hw/vga.c        |    8 +++++---
 hw/vga_int.h    |    3 ++-
 hw/vmware_vga.c |    2 +-
 5 files changed, 10 insertions(+), 7 deletions(-)
hw/blizzard.c +1 -1
index 76df78c..29e5ae6 100644
@@ -942,7 +942,7 @@ static void blizzard_screen_dump(void *opaque, const char *filename,
         blizzard_update_display(opaque);
     }
     if (s && ds_get_data(s->state))
-        ppm_save(filename, s->state->surface);
+        ppm_save(filename, s->state->surface, errp);
 }
 
 #define DEPTH 8
hw/qxl.c +1 -1
index 27f27f5..aa68612 100644
@@ -1503,7 +1503,7 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch,
     case QXL_MODE_COMPAT:
     case QXL_MODE_NATIVE:
         qxl_render_update(qxl);
-        ppm_save(filename, qxl->ssd.ds->surface);
+        ppm_save(filename, qxl->ssd.ds->surface, errp);
         break;
     case QXL_MODE_VGA:
         vga->screen_dump(vga, filename, cswitch, errp);
hw/vga.c +1 -1
index 79c5c38..80e6dca 100644
@@ -2365,7 +2365,7 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion *system_memory)
 /********************************************************/
 /* vga screen dump */
 
-int ppm_save(const char *filename, struct DisplaySurface *ds)
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp)
 {
     FILE *f;
     uint8_t *d, *d1;

hw/vga.c int ppm_save(const char *filename, struct DisplaySurface *ds) · line 2379

Quoted 3 lines
hw/vga.c +0 -0
@@ -2377,8 +2377,10 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
 
     trace_ppm_save(filename, ds);
     f = fopen(filename, "wb");

What I suggested to you was calling qemu_fopen_err() instead of fopen().

hw/vga.c int ppm_save(const char *filename, struct DisplaySurface *ds) · line 2381

Quoted 3 lines
hw/vga.c +2 -1
-    if (!f)
+    if (!f) {
+        error_set_file_open_failed(errp, filename, errno);

Does this even compile?

Also note that there are device models that don't use ppm_save(), they have to be converted too.

Quoted 46 lines
hw/vga.c +2 -1
         return -1;
+    }
     fprintf(f, "P6\n%d %d\n%d\n",
             ds->width, ds->height, 255);
     linebuf = g_malloc(ds->width * 3);
@@ -2420,5 +2422,5 @@ static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
         vga_invalidate_display(s);
         vga_hw_update();
     }
-    ppm_save(filename, s->ds->surface);
+    ppm_save(filename, s->ds->surface, errp);
 }
hw/vga_int.h +2 -1
index 7685b2b..63078ba 100644
@@ -24,6 +24,7 @@
 
 #include <hw/hw.h>
 #include "memory.h"
+#include "error.h"
 
 #define ST01_V_RETRACE      0x08
 #define ST01_DISP_ENABLE    0x01
@@ -200,7 +201,7 @@ void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val);
 uint32_t vga_mem_readb(VGACommonState *s, target_phys_addr_t addr);
 void vga_mem_writeb(VGACommonState *s, target_phys_addr_t addr, uint32_t val);
 void vga_invalidate_scanlines(VGACommonState *s, int y1, int y2);
-int ppm_save(const char *filename, struct DisplaySurface *ds);
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp);
 
 int vga_ioport_invalid(VGACommonState *s, uint32_t addr);
 void vga_init_vbe(VGACommonState *s, MemoryRegion *address_space);
hw/vmware_vga.c +1 -1
index 6868778..0769652 100644
@@ -1016,7 +1016,7 @@ static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch,
     if (s->depth == 32) {
         DisplaySurface *ds = qemu_create_displaysurface_from(s->width,
                 s->height, 32, ds_get_linesize(s->vga.ds), s->vga.vram_ptr);
-        ppm_save(filename, ds);
+        ppm_save(filename, ds, errp);
         g_free(ds);
     }
 }
author
#30 lore raw

Re: [Qemu-devel] [PATCH v3 5/5] vga: ppm_save(): Return error on failure

Quoted 61 lines · Luiz Capitulino
Quoted 58 lines · On Sun, 18 Mar 2012 19:29:13 +0100 Alon Levy <[email protected]> wrote:

From: Luiz Capitulino <[email protected]>

This makes all devices using ppm_save() return an error appropriately when the screendump command fails.

Based on a code by Anthony Liguori.

---
 hw/blizzard.c   |    2 +-
 hw/qxl.c        |    2 +-
 hw/vga.c        |    8 +++++---
 hw/vga_int.h    |    3 ++-
 hw/vmware_vga.c |    2 +-
 5 files changed, 10 insertions(+), 7 deletions(-)
hw/blizzard.c +1 -1
index 76df78c..29e5ae6 100644
@@ -942,7 +942,7 @@ static void blizzard_screen_dump(void *opaque, const char *filename,
         blizzard_update_display(opaque);
     }
     if (s && ds_get_data(s->state))
-        ppm_save(filename, s->state->surface);
+        ppm_save(filename, s->state->surface, errp);
 }
 
 #define DEPTH 8
hw/qxl.c +1 -1
index 27f27f5..aa68612 100644
@@ -1503,7 +1503,7 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch,
     case QXL_MODE_COMPAT:
     case QXL_MODE_NATIVE:
         qxl_render_update(qxl);
-        ppm_save(filename, qxl->ssd.ds->surface);
+        ppm_save(filename, qxl->ssd.ds->surface, errp);
         break;
     case QXL_MODE_VGA:
         vga->screen_dump(vga, filename, cswitch, errp);
hw/vga.c +1 -1
index 79c5c38..80e6dca 100644
@@ -2365,7 +2365,7 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion *system_memory)
 /********************************************************/
 /* vga screen dump */
 
-int ppm_save(const char *filename, struct DisplaySurface *ds)
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp)
 {
     FILE *f;
     uint8_t *d, *d1;
@@ -2377,8 +2377,10 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
 
Quoted 4 lines

hw/vga.c int ppm_save(const char *filename, struct DisplaySurface *ds) · line 2379

Quoted 2 lines
hw/vga.c +0 -0
     trace_ppm_save(filename, ds);
     f = fopen(filename, "wb");

What I suggested to you was calling qemu_fopen_err() instead of fopen().

Oh, I didn't understand it that way. Makes more sense, will do.

Quoted 6 lines

hw/vga.c int ppm_save(const char *filename, struct DisplaySurface *ds) · line 2381

Quoted 4 lines
hw/vga.c +2 -1
-    if (!f)
+    if (!f) {
+        error_set_file_open_failed(errp, filename, errno);

Does this even compile?

I don't recall. Moot now.

Quoted 4 lines

Also note that there are device models that don't use ppm_save(), they have to be converted too.

Will look at them.

Quoted 48 lines
Quoted 46 lines
hw/vga.c +2 -1
         return -1;
+    }
     fprintf(f, "P6\n%d %d\n%d\n",
             ds->width, ds->height, 255);
     linebuf = g_malloc(ds->width * 3);
@@ -2420,5 +2422,5 @@ static void vga_screen_dump(void *opaque, const char *filename, bool cswitch,
         vga_invalidate_display(s);
         vga_hw_update();
     }
-    ppm_save(filename, s->ds->surface);
+    ppm_save(filename, s->ds->surface, errp);
 }
hw/vga_int.h +2 -1
index 7685b2b..63078ba 100644
@@ -24,6 +24,7 @@
 
 #include <hw/hw.h>
 #include "memory.h"
+#include "error.h"
 
 #define ST01_V_RETRACE      0x08
 #define ST01_DISP_ENABLE    0x01
@@ -200,7 +201,7 @@ void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val);
 uint32_t vga_mem_readb(VGACommonState *s, target_phys_addr_t addr);
 void vga_mem_writeb(VGACommonState *s, target_phys_addr_t addr, uint32_t val);
 void vga_invalidate_scanlines(VGACommonState *s, int y1, int y2);
-int ppm_save(const char *filename, struct DisplaySurface *ds);
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp);
 
 int vga_ioport_invalid(VGACommonState *s, uint32_t addr);
 void vga_init_vbe(VGACommonState *s, MemoryRegion *address_space);
hw/vmware_vga.c +1 -1
index 6868778..0769652 100644
@@ -1016,7 +1016,7 @@ static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch,
     if (s->depth == 32) {
         DisplaySurface *ds = qemu_create_displaysurface_from(s->width,
                 s->height, 32, ds_get_linesize(s->vga.ds), s->vga.vram_ptr);
-        ppm_save(filename, ds);
+        ppm_save(filename, ds, errp);
         g_free(ds);
     }
 }