Add error reporting to libxc library
PATCH 1/1 Add error reporting to libxc library
Attached to this mail is an update of my previous patch to add an error reporting API to the libxc library. The patch is against xen-devel on changeset 12722.
Previous discussions were:
Original post:
http://lists.xensource.com/archives/html/xen-devel/2006-09/msg00702.html
2nd posting:
http://lists.xensource.com/archives/html/xen-devel/2006-10/msg01041.html
This 3rd version of the patch has the following characteristics:
- 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 problem.
- 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
This should address the recommendations / suggestions from the previous round of feedback on this patch.
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 mesages from these helpers.
Since I've not been keeping up with development on XenAPI I'm not clear on what (if any) extra code is needed to get errors integrated with this new control API. Hopefully it should be little-to-no work, but I could do with someone who knows XenAPI details validating this.
Regards,
Dan.
Signature · 4 lines
|=- 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 -=|
tools/libxc/xc_hvm_build.c +10 -6
@@ -285,7 +285,6 @@ static int xc_hvm_build_internal(int xc_if (setup_guest (xc_handle, domid, memsize, image, image_size, &ctxt) <0 ) { -ERROR ("Error constructing guest OS" ); goto error_out; }
@@ -329,26 +328,30 @@ static int parseelfimage(char *elfbase,if ( !IS_ELF (*ehdr) ) { -ERROR ("Kernel image does not have an ELF header." ); +xc_set_error (XC_INVALID_KERNEL , +"Kernel image does not have an ELF header." );return -EINVAL ; }if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize ) { -ERROR ("ELF program headers extend beyond end of image." ); +xc_set_error (XC_INVALID_KERNEL , +"ELF program headers extend beyond end of image." );return -EINVAL ; }if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize ) { -ERROR ("ELF section headers extend beyond end of image." ); +xc_set_error (XC_INVALID_KERNEL , +"ELF section headers extend beyond end of image." );return -EINVAL ; }/* Find the section-header strings table. */ if ( ehdr->e_shstrndx ==SHN_UNDEF ) { -ERROR ("ELF image has no section-header strings table (shstrtab)." ); +xc_set_error (XC_INVALID_KERNEL , +"ELF image has no section-header strings table (shstrtab)." );return -EINVAL ; } shdr = (Elf32_Shdr *)(elfbase + ehdr->e_shoff +
@@ -370,7 +373,8 @@ static int parseelfimage(char *elfbase, (ehdr->e_entry < kernstart) || (ehdr->e_entry > kernend) ) { -ERROR ("Malformed ELF image." ); +xc_set_error (XC_INVALID_KERNEL , +"Malformed ELF image." );return -EINVAL ; }
tools/libxc/xc_linux_build.c +7 -5
@@ -120,7 +120,7 @@ static int probeimageformat(const char *if (probe_elf (image, image_size, load_funcs) &&probe_bin (image, image_size, load_funcs) ) { -ERROR ("Unrecognized image format" ); +xc_set_error (XC_INVALID_KERNEL ,"Not a valid ELF or raw kernel image" );return -EINVAL ; }
@@ -618,17 +618,20 @@ static int compat_check(int xc_handle, sxen_capabilities_info_t xen_caps ="" ;if (xc_version (xc_handle, XENVER_capabilities, &xen_caps) !=0 ) { -ERROR ("Cannot determine host capabilities." ); +xc_set_error (XC_INVALID_KERNEL , +"Cannot determine host capabilities." );return 0 ; }if (strstr (xen_caps,"xen-3.0-x86_32p" )) {if (dsi->pae_kernel == PAEKERN_no) { -ERROR ("Non PAE-kernel on PAE host." ); +xc_set_error (XC_INVALID_KERNEL , +"Non PAE-kernel on PAE host." );return 0 ; } }else if (dsi->pae_kernel != PAEKERN_no) { -ERROR ("PAE-kernel on non-PAE host." ); +xc_set_error (XC_INVALID_KERNEL , +"PAE-kernel on non-PAE host." );return 0 ; }
@@ -1141,7 +1144,6 @@ static int xc_linux_build_internal(int x console_evtchn, console_mfn, features_bitmap) < 0 ) { -ERROR ("Error constructing guest OS" ); goto error_out; }
tools/libxc/xc_load_elf.c +80 -23
186 lines not on this page · raw message
tools/libxc/xc_private.c +65 -0
71 lines not on this page · raw message
tools/libxc/xc_private.h +5 -14
@@ -59,23 +59,14 @@ #define PPRINTF(_f, _a...)#endif -#define ERROR(_m, _a...) \ -do { \ - int __saved_errno = errno; \ - DPRINTF("ERROR: " _m "\n" , ## _a ); \ - errno = __saved_errno; \ -} while (0) +void xc_set_error (int code,const char *fmt, ...); + +#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))int lock_pages (void *addr,size_t len);void unlock_pages (void *addr,size_t len); - -#define PERROR(_m, _a...) \ -do { \ - int __saved_errno = errno; \ - DPRINTF("ERROR: " _m " (%d = %s)\n" , ## _a , \ - __saved_errno, strerror(__saved_errno)); \ - errno = __saved_errno; \ -} while (0)static inline void safe_munlock (const void *addr,size_t len) {
tools/libxc/xenctrl.h +42 -0
46 lines not on this page · raw message
tools/python/xen/lowlevel/xc/xc.c +59 -45
333 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel