From 6da69ebc61688058b39062241e53881c7228186d Mon Sep 17 00:00:00 2001 Message-Id: <6da69ebc61688058b39062241e53881c7228186d.1367947969.git.minovotn@redhat.com> In-Reply-To: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com> References: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com> From: Michal Novotny Date: Tue, 7 May 2013 18:36:15 +0200 Subject: [PATCH 008/114] Revert "qemu-ga: qmp_guest_file_*: improve error reporting" This reverts commit 6dd175e6cffba5437e265d239898cc46deecf8c2. Reverting as asked by Laszlo in message <51892739.2030807@redhat.com> because of the ordering issue (most likely) related to supersed testing. Signed-off-by: Michal Novotny --- qga/commands-posix.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 6463a9a..a009321 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -242,8 +242,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_setg_errno(err, errno, "failed to open file '%s' (mode: '%s')", - path, mode); + error_set(err, QERR_OPEN_FILE_FAILED, path, strerror(errno)); return -1; } @@ -254,8 +253,7 @@ 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_setg_errno(err, errno, "failed to make file '%s' non-blocking", - path); + error_set(err, QERR_QGA_COMMAND_FAILED, "fcntl() failed"); fclose(fh); return -1; } @@ -277,7 +275,7 @@ void qmp_guest_file_close(int64_t handle, Error **err) ret = fclose(gfh->fh); if (ret == EOF) { - error_setg_errno(err, errno, "failed to close handle"); + error_set(err, QERR_QGA_COMMAND_FAILED, "fclose() failed"); return; } @@ -301,8 +299,7 @@ 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_setg(err, "value '%" PRId64 "' is invalid for argument count", - count); + error_set(err, QERR_INVALID_PARAMETER, "count"); return NULL; } @@ -310,8 +307,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)); @@ -347,16 +344,15 @@ 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; @@ -383,7 +379,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_setg_errno(err, errno, "failed to seek file"); + error_set(err, QERR_QGA_COMMAND_FAILED, strerror(errno)); } else { seek_data = g_malloc0(sizeof(GuestFileRead)); seek_data->position = ftell(fh); @@ -407,7 +403,7 @@ void qmp_guest_file_flush(int64_t handle, Error **err) fh = gfh->fh; ret = fflush(fh); if (ret == EOF) { - error_setg_errno(err, errno, "failed to flush file"); + error_set(err, QERR_QGA_COMMAND_FAILED, strerror(errno)); } } -- 1.7.11.7