From patchwork Wed Apr 28 20:32:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 51251 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 1DD32B7D2E for ; Thu, 29 Apr 2010 07:26:42 +1000 (EST) Received: from localhost ([127.0.0.1]:60485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7EmF-0006yC-6z for incoming@patchwork.ozlabs.org; Wed, 28 Apr 2010 17:26:39 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O7Dvl-0004xC-RB for qemu-devel@nongnu.org; Wed, 28 Apr 2010 16:32:25 -0400 Received: from [140.186.70.92] (port=45135 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7Dvk-0004v8-Bg for qemu-devel@nongnu.org; Wed, 28 Apr 2010 16:32:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O7Dvi-0001z8-42 for qemu-devel@nongnu.org; Wed, 28 Apr 2010 16:32:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6359) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O7Dvh-0001z1-So for qemu-devel@nongnu.org; Wed, 28 Apr 2010 16:32:22 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3SKWLQ4025732 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 28 Apr 2010 16:32:21 -0400 Received: from localhost (vpn-8-180.rdu.redhat.com [10.11.8.180]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3SKWJXG027595; Wed, 28 Apr 2010 16:32:20 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 28 Apr 2010 17:32:08 -0300 Message-Id: <1272486729-14771-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1272486729-14771-1-git-send-email-lcapitulino@redhat.com> References: <1272486729-14771-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: armbru@redhat.com Subject: [Qemu-devel] [PATCH 1/2] qemu-error: Introduce get_errno_name() 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 We need to expose errno in QMP, for three reasons: 1. Some error handling functions print errno codes to the user, while it's debatable whether this is good or not from a user perspective, sometimes it's the best we can do because it's what system calls and libraries return 2. Some events (eg. BLOCK_IO_ERROR) will be made even more complete with errno information 3. It's very good for debugging So, we need a way to expose those codes in QMP. We can't just use the codes themselfs because they may vary between systems. The best solution I can think of is to return the string representation of the name. For example, EIO becomes "EIO". This is what get_errno_name() does. Signed-off-by: Luiz Capitulino --- qemu-error.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-error.h | 1 + 2 files changed, 86 insertions(+), 0 deletions(-) diff --git a/qemu-error.c b/qemu-error.c index 5a35e7c..7035417 100644 --- a/qemu-error.c +++ b/qemu-error.c @@ -207,3 +207,88 @@ void error_report(const char *fmt, ...) va_end(ap); error_printf("\n"); } + +/* + * Probably only useful for QMP + */ +const char *get_errno_name(int err) +{ + switch (abs(err)) { + case EPERM: + return "EPERM"; + case ENOENT: + return "ENOENT"; + case ESRCH: + return "ESRCH"; + case EINTR: + return "EINTR"; + case EIO: + return "EIO"; + case ENXIO: + return "ENXIO"; + case E2BIG: + return "E2BIG"; + case ENOEXEC: + return "ENOEXEC"; + case EBADF: + return "EBADF"; + case ECHILD: + return "ECHILD"; + case EAGAIN: + return "EAGAIN"; + case ENOMEM: + return "ENOMEM"; + case EACCES: + return "EACCES"; + case EFAULT: + return "EFAULT"; + case ENOTBLK: + return "ENOTBLK"; + case EBUSY: + return "EBUSY"; + case EEXIST: + return "EEXIST"; + case EXDEV: + return "EXDEV"; + case ENODEV: + return "ENODEV"; + case ENOTDIR: + return "ENOTDIR"; + case EISDIR: + return "EISDIR"; + case EINVAL: + return "EINVAL"; + case ENFILE: + return "ENFILE"; + case EMFILE: + return "EMFILE"; + case ENOTTY: + return "ENOTTY"; + case ETXTBSY: + return "ETXTBSY"; + case EFBIG: + return "EFBIG"; + case ENOSPC: + return "ENOSPC"; + case ESPIPE: + return "ESPIPE"; + case EROFS: + return "EROFS"; + case EMLINK: + return "EMLINK"; + case EPIPE: + return "EPIPE"; + case EDOM: + return "EDOM"; + case ERANGE: + return "ERANGE"; + case ENOMEDIUM: + return "ENOMEDIUM"; + case ENOTSUP: + return "ENOTSUP"; + default: + return "unknown"; + } + + abort(); +} diff --git a/qemu-error.h b/qemu-error.h index a45609f..c5e39b5 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_name(int err); #endif