qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, tomoki.sekiyama.qu@hitachi.com,
	lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH 03/12] qemu-ga: qmp_guest_file_*: improve error reporting
Date: Tue,  8 Jan 2013 17:00:00 -0600	[thread overview]
Message-ID: <1357686009-13139-4-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1357686009-13139-1-git-send-email-mdroth@linux.vnet.ibm.com>

From: Luiz Capitulino <lcapitulino@redhat.com>

Use error_setg_errno() when possible with an improved error description.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/commands-posix.c |   22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index ebb58be..d5f2dcd 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -138,7 +138,8 @@ 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_setg_errno(err, errno, "failed to open file '%s' (mode: '%s')",
+                         path, mode);
         return -1;
     }
 
@@ -149,7 +150,8 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E
     ret = fcntl(fd, F_GETFL);
     ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK);
     if (ret == -1) {
-        error_set(err, QERR_QGA_COMMAND_FAILED, "fcntl() failed");
+        error_setg_errno(err, errno, "failed to make file '%s' non-blocking",
+                         path);
         fclose(fh);
         return -1;
     }
@@ -171,7 +173,7 @@ void qmp_guest_file_close(int64_t handle, Error **err)
 
     ret = fclose(gfh->fh);
     if (ret == EOF) {
-        error_set(err, QERR_QGA_COMMAND_FAILED, "fclose() failed");
+        error_setg_errno(err, errno, "failed to close handle");
         return;
     }
 
@@ -195,7 +197,8 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
     if (!has_count) {
         count = QGA_READ_COUNT_DEFAULT;
     } else if (count < 0) {
-        error_set(err, QERR_INVALID_PARAMETER, "count");
+        error_setg(err, "value '%" PRId64 "' is invalid for argument count",
+                   count);
         return NULL;
     }
 
@@ -203,8 +206,8 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
     buf = g_malloc0(count+1);
     read_count = fread(buf, 1, count, fh);
     if (ferror(fh)) {
+        error_setg_errno(err, errno, "failed to read file");
         slog("guest-file-read failed, handle: %ld", handle);
-        error_set(err, QERR_QGA_COMMAND_FAILED, "fread() failed");
     } else {
         buf[read_count] = 0;
         read_data = g_malloc0(sizeof(GuestFileRead));
@@ -240,15 +243,16 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
     if (!has_count) {
         count = buf_len;
     } else if (count < 0 || count > buf_len) {
+        error_setg(err, "value '%" PRId64 "' is invalid for argument count",
+                   count);
         g_free(buf);
-        error_set(err, QERR_INVALID_PARAMETER, "count");
         return NULL;
     }
 
     write_count = fwrite(buf, 1, count, fh);
     if (ferror(fh)) {
+        error_setg_errno(err, errno, "failed to write to file");
         slog("guest-file-write failed, handle: %ld", handle);
-        error_set(err, QERR_QGA_COMMAND_FAILED, "fwrite() error");
     } else {
         write_data = g_malloc0(sizeof(GuestFileWrite));
         write_data->count = write_count;
@@ -275,7 +279,7 @@ struct GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
     fh = gfh->fh;
     ret = fseek(fh, offset, whence);
     if (ret == -1) {
-        error_set(err, QERR_QGA_COMMAND_FAILED, strerror(errno));
+        error_setg_errno(err, errno, "failed to seek file");
     } else {
         seek_data = g_malloc0(sizeof(GuestFileRead));
         seek_data->position = ftell(fh);
@@ -299,7 +303,7 @@ void qmp_guest_file_flush(int64_t handle, Error **err)
     fh = gfh->fh;
     ret = fflush(fh);
     if (ret == EOF) {
-        error_set(err, QERR_QGA_COMMAND_FAILED, strerror(errno));
+        error_setg_errno(err, errno, "failed to flush file");
     }
 }
 
-- 
1.7.9.5

  parent reply	other threads:[~2013-01-08 23:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-08 22:59 [Qemu-devel] [PULL 0/12] qemu-ga: error handling improvements and fsfreeze hooks Michael Roth
2013-01-08 22:59 ` [Qemu-devel] [PATCH 01/12] qemu-ga: guest_file_handle_find(): take an Error argument Michael Roth
2013-01-08 22:59 ` [Qemu-devel] [PATCH 02/12] qemu-ga: qmp_guest_file_close(): fix fclose() error check Michael Roth
2013-01-08 23:00 ` Michael Roth [this message]
2013-01-08 23:00 ` [Qemu-devel] [PATCH 04/12] qemu-ga: qmp_guest_shutdown(): improve error reporting Michael Roth
2013-01-08 23:00 ` [Qemu-devel] [PATCH 05/12] qemu-ga: build_fs_mount_list(): take an Error argument Michael Roth
2013-01-08 23:00 ` [Qemu-devel] [PATCH 06/12] qemu-ga: qmp_guest_fsfreeze_*(): get rid of sprintf() + error_set() Michael Roth
2013-01-08 23:00 ` [Qemu-devel] [PATCH 07/12] qemu-ga: qmp_guest_fstrim(): " Michael Roth
2013-01-08 23:00 ` [Qemu-devel] [PATCH 08/12] qemu-ga: qmp_guest_network_get_interfaces(): get rid of snprintf() " Michael Roth
2013-01-08 23:00 ` [Qemu-devel] [PATCH 09/12] qemu-ga: bios_supports_mode(): improve error reporting Michael Roth
2013-01-08 23:00 ` [Qemu-devel] [PATCH 10/12] qemu-ga: guest_suspend(): " Michael Roth
2013-01-08 23:00 ` [Qemu-devel] [PATCH 11/12] qemu-ga: execute hook to quiesce the guest on fsfreeze-freeze/thaw Michael Roth
2013-01-09 21:02   ` Blue Swirl
2013-01-10 11:17     ` Luiz Capitulino
2013-01-08 23:00 ` [Qemu-devel] [PATCH 12/12] qemu-ga: sample fsfreeze hooks Michael Roth
2013-01-09 17:01 ` [Qemu-devel] [PULL 0/12] qemu-ga: error handling improvements and " Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1357686009-13139-4-git-send-email-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=tomoki.sekiyama.qu@hitachi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).