From patchwork Tue Apr 20 21:09:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 50580 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B3428B7D0B for ; Wed, 21 Apr 2010 07:28:04 +1000 (EST) Received: from localhost ([127.0.0.1]:49449 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4KzA-0004ZQ-T1 for incoming@patchwork.ozlabs.org; Tue, 20 Apr 2010 17:28:00 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4Ki7-0007An-34 for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:23 -0400 Received: from [140.186.70.92] (port=37320 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4Ki2-00079E-KV for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4Khz-0003wj-8p for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26534) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4Khy-0003wX-KB for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:15 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3KLADtf027830 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 20 Apr 2010 17:10:13 -0400 Received: from localhost (vpn-9-57.rdu.redhat.com [10.11.9.57]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3KLABKH031280; Tue, 20 Apr 2010 17:10:12 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org, armbru@redhat.com, quintela@redhat.com, kwolf@redhat.com Date: Tue, 20 Apr 2010 18:09:37 -0300 Message-Id: <1271797792-24571-8-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1271797792-24571-1-git-send-email-lcapitulino@redhat.com> References: <1271797792-24571-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH 07/22] qemu-error: Introduce get_errno_string() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org There are error handling functions in QEMU which print errno codes to the user. While it's debatable if this is good from a user perspective, sometimes it's the best you can do because it's what system calls return and this is also useful for debugging. So, we need a way to expose those codes in QMP. We can't use the codes themselfs because they may vary between systems. The best solution I can think of is returning the string representation of the name. For example, EIO becomes "EIO". This is what get_errno_string() does. Signed-off-by: Luiz Capitulino --- qemu-error.c | 25 +++++++++++++++++++++++++ qemu-error.h | 1 + 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/qemu-error.c b/qemu-error.c index 5a35e7c..55ce133 100644 --- a/qemu-error.c +++ b/qemu-error.c @@ -207,3 +207,28 @@ void error_report(const char *fmt, ...) va_end(ap); error_printf("\n"); } + +/* + * This is probably only useful for QMP + */ +const char *get_errno_string(int err) +{ + assert(err < 0); + + switch (err) { + case -EINVAL: + return "EINVAL"; + case -EIO: + return "EIO"; + case -ENOENT: + return "ENOENT"; + case -ENOMEDIUM: + return "ENOMEDIUM"; + case -ENOTSUP: + return "ENOTSUP"; + default: + return "unknown"; + } + + abort(); +} diff --git a/qemu-error.h b/qemu-error.h index a45609f..bf2b890 100644 --- a/qemu-error.h +++ b/qemu-error.h @@ -38,4 +38,5 @@ void error_print_loc(void); void error_set_progname(const char *argv0); void error_report(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); +const char *get_errno_string(int err); #endif