Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O8vLd-000489-JT for qemu-devel@nongnu.org; Mon, 03 May 2010 09:06:09 -0400 Received: from [140.186.70.92] (port=38500 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O8vLb-00046p-WC for qemu-devel@nongnu.org; Mon, 03 May 2010 09:06:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O8vLZ-0000uO-Dq for qemu-devel@nongnu.org; Mon, 03 May 2010 09:06:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16022) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O8vLZ-0000uD-5R for qemu-devel@nongnu.org; Mon, 03 May 2010 09:06:05 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o43D64Zq027690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 3 May 2010 09:06:04 -0400 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH 1/2] qemu-error: Introduce get_errno_name() References: <1272486729-14771-1-git-send-email-lcapitulino@redhat.com> <1272486729-14771-2-git-send-email-lcapitulino@redhat.com> Date: Mon, 03 May 2010 15:06:01 +0200 In-Reply-To: <1272486729-14771-2-git-send-email-lcapitulino@redhat.com> (Luiz Capitulino's message of "Wed, 28 Apr 2010 17:32:08 -0300") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: qemu-devel@nongnu.org Luiz Capitulino writes: > 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 EDOM: > + return "EDOM"; > + case ERANGE: > + return "ERANGE"; > + case ENOMEDIUM: > + return "ENOMEDIUM"; > + case ENOTSUP: > + return "ENOTSUP"; > + default: > + return "unknown"; How did you choose the codes to implement? POSIX has many more... > + } > + > + 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