annotate tools/libxc/xc_csched.c @ 12765:2dd4569e0640

[LIBXC] Add an error reporting API to the libxc library.

- An 'xc_error' struct is used to pass around error
details. Currently contains two members 'code' an enumeration of
error types, and 'message' a free text description of the specific

- The xc_get_last_error() method returns a const pointer to the
internal instance of this struct manged by libxc. By returning a
const pointer we can add extra members to the end of the struct at
any time without worrying about ABI of callers. This will let us
provide more fine-grained info if needed in the future.

- The xc_error instance is statically defined inside libxc and marked
__thread. This ensures that errors are recorded per-thread, and
that when dealing with errors we never need to call malloc - all
storage needed is statically allocated.

- The xc_clear_last_error() method resets any currently recorded
error details

- The xc_error_code_to_desc() method converts the integer error code
into a generic user facing messsage. eg "Invalid kernel". Together
with the 'message' field from xc_error, this provides the user
visible feedback. eg "Invalid kernel: Non PAE-kernel on PAE host."

- A callback can be registered with xc_set_error_handler to receive
notification whenever an error is recorded, rather than querying
for error details after the fact with xc_get_last_error

- If built with -DDEBUG set, a default error handler will be
registered which calls fprintf(stderr), thus maintaining current
behaviour of logging errors to stderr during developer builds.

- The python binding for libxc is updated to use xc_get_last_error
to pull out error details whenever appropriate, instead of
returning info based on 'errno'

- The xc_set_error method is private to libxc internals, and is used
for setting error details

- The ERROR and PERROR macros have been updated to call xc_set_error
automatically specifying XC_INTERNAL_ERROR as the error code. This
gives a generic error report for all current failure points

- Some uses of the ERROR macro have been replaced with explicit
calls to xc_set_error to enable finer grained error reporting. In
particular the code dealing with invalid kernel types uses this
to report about PAE/architecture/wordsize mismatches

The patch has been tested by calling xm create against a varietry of
config files defining invalid kernels of various kinds. It has also
been tested with libvirt talking to xend. In both cases the error
messages were propagated all the way back up the stack.

There is only one place where I need to do further work. The suspend
& restore APIs in Xend invoke external helper programs rather than
calling libxc directly. This means that error details are essentially
lost. Since there is already code in XenD which scans STDERR from
these programs I will investigate adapting this to extract actual
error messages from these helpers.

Signed-off-by: Daniel P. Berrange <>
author kfraser@localhost.localdomain
date Thu Dec 07 11:36:26 2006 +0000 (2006-12-07)
parents 86d26e6ec89b
rev   line source
ack@10168 1 /****************************************************************************
ack@10168 2 * (C) 2006 - Emmanuel Ackaouy - XenSource Inc.
ack@10168 3 ****************************************************************************
ack@10168 4 *
ack@10168 5 * File: xc_csched.c
ack@10168 6 * Author: Emmanuel Ackaouy
ack@10168 7 *
ack@10168 8 * Description: XC Interface to the credit scheduler
ack@10168 9 *
ack@10168 10 */
ack@10168 11 #include "xc_private.h"
ack@10168 12
ack@10168 13
ack@10168 14 int
kaf24@10174 15 xc_sched_credit_domain_set(
ack@10168 16 int xc_handle,
ack@10168 17 uint32_t domid,
kfraser@11257 18 struct xen_domctl_sched_credit *sdom)
ack@10168 19 {
kfraser@11257 20 DECLARE_DOMCTL;
ack@10168 21
kfraser@11257 22 domctl.cmd = XEN_DOMCTL_scheduler_op;
kfraser@11257 23 domctl.domain = (domid_t) domid;
kfraser@11257 24 domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT;
kfraser@11257 25 domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
kfraser@11257 26 = *sdom;
ack@10168 27
kfraser@11257 28 return do_domctl(xc_handle, &domctl);
ack@10168 29 }
ack@10168 30
ack@10168 31 int
kaf24@10174 32 xc_sched_credit_domain_get(
ack@10168 33 int xc_handle,
ack@10168 34 uint32_t domid,
kfraser@11257 35 struct xen_domctl_sched_credit *sdom)
ack@10168 36 {
kfraser@11257 37 DECLARE_DOMCTL;
ack@10168 38 int err;
ack@10168 39
kfraser@11257 40 domctl.cmd = XEN_DOMCTL_scheduler_op;
kfraser@11257 41 domctl.domain = (domid_t) domid;
kfraser@11257 42 domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT;
kfraser@11257 43 domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo;
ack@10168 44
kfraser@11257 45 err = do_domctl(xc_handle, &domctl);
ack@10168 46 if ( err == 0 )
kfraser@11257 47 *sdom =;
ack@10168 48
ack@10168 49 return err;
ack@10168 50 }