From patchwork Tue Jan 8 23:00:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 210560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0C04E2C00AE for ; Wed, 9 Jan 2013 10:05:39 +1100 (EST) Received: from localhost ([::1]:51847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsiEi-0006YE-T7 for incoming@patchwork.ozlabs.org; Tue, 08 Jan 2013 18:05:36 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsiEL-0006N0-Bv for qemu-devel@nongnu.org; Tue, 08 Jan 2013 18:05:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsiEK-0006fW-3u for qemu-devel@nongnu.org; Tue, 08 Jan 2013 18:05:13 -0500 Received: from mail-ia0-f180.google.com ([209.85.210.180]:49313) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsiEJ-0006fO-V6 for qemu-devel@nongnu.org; Tue, 08 Jan 2013 18:05:12 -0500 Received: by mail-ia0-f180.google.com with SMTP id t4so878881iag.39 for ; Tue, 08 Jan 2013 15:05:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=7pdXCBeXp7wJ0bE0f1UZUy3lrYJpOVIXwuOg2w1tm7Y=; b=eisEjHcatYr58qaFqiADHRrvnt3W81jbrvdYNNi++8cyA3HC12teTrzXmugk0IwBF5 eCJxsHRr0nY8x4Vg4E1QDJybQ7O94LdIpZs+CThTVoQoWwjt2SKauf5iA7PB6240QH7i kyLtpnQ2WUsRd15Ull56nviz40zhlQaakzP90gVQAnSHiF786vjC2cgOiLSRVwGcEBjG Op4nUW5KQaL03G4ujCPZCnMTQhgp3/Q6sFDQoPGvGycHBJytOTPRfkBORDGv2+KB4FDc S1UcpAorxDIeq02l/4jvZBbnKpdulwldSu75cynVj8H1itGZhCTJgKElkGC94rIssQp7 20LA== X-Received: by 10.50.189.193 with SMTP id gk1mr10760619igc.87.1357686311440; Tue, 08 Jan 2013 15:05:11 -0800 (PST) Received: from localhost ([32.97.110.59]) by mx.google.com with ESMTPS id yf6sm784045igb.0.2013.01.08.15.05.10 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Jan 2013 15:05:10 -0800 (PST) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 8 Jan 2013 17:00:00 -0600 Message-Id: <1357686009-13139-4-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1357686009-13139-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1357686009-13139-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.180 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 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Luiz Capitulino Use error_setg_errno() when possible with an improved error description. Signed-off-by: Luiz Capitulino Signed-off-by: Michael Roth --- 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"); } }