All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Hollis Blanchard <hollisb@us.ibm.com>
Cc: xen-devel@lists.xensource.com
Subject: Re: Error reporting capabilities for libxc
Date: Tue, 26 Sep 2006 19:49:24 +0100	[thread overview]
Message-ID: <20060926184924.GK8885@redhat.com> (raw)
In-Reply-To: <1159296001.8847.16.camel@basalt.austin.ibm.com>

On Tue, Sep 26, 2006 at 01:40:01PM -0500, Hollis Blanchard wrote:
> On Fri, 2006-09-22 at 21:31 +0100, Daniel P. Berrange wrote:
> > So, I've prototyped a simple error reporting mechanism for libxc. The idea
> > is we first define an enum for the broad classes of errors which can occur.
> > As proof of concept I've defined one generic error code, and a special one
> > for invalid kernels
> > 
> >  typedef enum {
> >     XC_ERROR_NONE = 0,
> >     XC_INTERNAL_ERROR = 1,
> >     XC_INVALID_KERNEL = 2,
> >  } xc_error_code;
> > 
> > Next, I created an internal function  for setting the error code, and
> > providing an associated descritive message
> > 
> >   void xc_set_error(int code, const char *fmt, ...);
> > 
> > And simply re-defined the existing ERROR & PERROR macros to use this 
> > function passing the generic XC_INTERNAL_ERROR
> > 
> >  #define ERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m, ## _a)
> > 
> >  #define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, "%s (%d = %s)", _m, errno, strerror(errno))
> > 
> > In the various places which deal with validating the guest kernel I
> > changed calls to ERROR to call xc_set_error(XC_INVALID_KERNEL,...)
> > instead. We can define further error codes over time to reduce use
> > fo the genreic XC_INTERNAL_ERROR as desired.
> > 
> > In the public API defined a way to either fetch the last error, or
> > register a callback for receving errors:
> > 
> >   int xc_get_last_error_code(void);
> >   const char *xc_get_last_error_message(void);
> >   void xc_clear_last_error(void);
> >   const char *xc_error_code_to_desc(int code);
> > 
> >   typedef void (*xc_error_handler)(int code, const char *msg);
> >   void xc_default_error_handler(int code, const char *msg);
> >   xc_error_handler xc_set_error_handler(xc_error_handler handler);
> 
> Isn't the whole idea of "get_last_error" racy by design? I guess errno
> has the same problem, but I'm not quite clear how it's solved there (a
> magic array of errnos that is somehow sized to include all threads?)

Yeah, the libc errno  is kept in thread local storage, so we'll have to
do the same thing here to be thread-safe. The async callback function is of
course always thread safe, but a little more inconvient for the caller to
use so I wanted to allow the direct access too. 

Regards,
Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 

  reply	other threads:[~2006-09-26 18:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-22 20:31 Error reporting capabilities for libxc Daniel P. Berrange
2006-09-26 11:45 ` Stephen C. Tweedie
2006-09-26 12:28   ` Keir Fraser
2006-09-26 13:18     ` Daniel P. Berrange
2006-09-26 18:40 ` Hollis Blanchard
2006-09-26 18:49   ` Daniel P. Berrange [this message]
2006-09-26 21:37   ` Muli Ben-Yehuda
  -- strict thread matches above, loose matches on Subject: below --
2006-09-26 12:58 Ian Pratt
2006-09-26 13:20 ` Daniel P. Berrange
2006-10-23 18:00 ` Daniel P. Berrange
2006-10-23 19:17   ` Anthony Liguori
2006-10-23 19:27     ` Daniel P. Berrange
2006-10-23 20:04       ` Anthony Liguori
2006-10-23 20:08         ` Daniel P. Berrange
2006-10-23 20:40   ` John Levon
2006-10-23 21:04   ` John Levon
2006-10-23 21:09     ` Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060926184924.GK8885@redhat.com \
    --to=berrange@redhat.com \
    --cc=hollisb@us.ibm.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.