annotate tools/libxc/xc_acm.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 58f28e00001e
children 96915ca8d5f2
rev   line source
kaf24@9907 1 /******************************************************************************
kaf24@10057 2 * xc_acm.c
kaf24@9907 3 *
kaf24@10057 4 * Copyright (C) 2005, 2006 IBM Corporation, R Sailer
kaf24@9907 5 *
kaf24@9907 6 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
kaf24@9907 7 * Use is subject to license terms.
kaf24@9907 8 *
kaf24@9907 9 * This program is free software; you can redistribute it and/or
kaf24@9907 10 * modify it under the terms of the GNU General Public License as
kaf24@9907 11 * published by the Free Software Foundation, version 2 of the
kaf24@9907 12 * License.
kaf24@9907 13 */
kaf24@9907 14
kaf24@9907 15 #include "xc_private.h"
kaf24@9907 16
kfraser@12485 17 int xc_acm_op(int xc_handle, int cmd, void *arg, unsigned long arg_size)
kaf24@9907 18 {
kaf24@9907 19 int ret = -1;
kaf24@9907 20 DECLARE_HYPERCALL;
kaf24@9907 21
kaf24@10057 22 hypercall.op = __HYPERVISOR_acm_op;
kaf24@10057 23 hypercall.arg[0] = cmd;
kaf24@10057 24 hypercall.arg[1] = (unsigned long) arg;
kaf24@9907 25
kfraser@11857 26 if (lock_pages(arg, arg_size) != 0) {
kfraser@11857 27 PERROR("xc_acm_op: arg lock failed");
kaf24@10057 28 goto out;
kaf24@9907 29 }
kaf24@9907 30 ret = do_xen_hypercall(xc_handle, &hypercall);
kfraser@11857 31 unlock_pages(arg, arg_size);
kaf24@10057 32 out:
kaf24@9907 33 return ret;
kaf24@9907 34 }
kaf24@9907 35
kaf24@9907 36 /*
kaf24@9907 37 * Local variables:
kaf24@9907 38 * mode: C
kaf24@9907 39 * c-set-style: "BSD"
kaf24@9907 40 * c-basic-offset: 4
kaf24@9907 41 * tab-width: 4
kaf24@9907 42 * indent-tabs-mode: nil
kaf24@9907 43 * End:
kaf24@9907 44 */