tools/libxc: various errno changes
cover tools/libxc: various errno changes
Some changes related to pass errno to callers of xc_domain_save. Compile and runtime tested with my migration constraint changes.
Olaf Hering (4):
tools/libxc: remove double inclusion of errno.h tools/libxc: assign positive values to errno tools/xc: preserve errno in ERROR and DRINTF macros tools/xc: pass errno to callers of xc_domain_save
tools/libxc/xc_compression.c | 1 - tools/libxc/xc_domain_save.c | 33 ++++++++++++++++++++++----------- tools/libxc/xc_flask.c | 1 - tools/libxc/xc_foreign_memory.c | 2 +- tools/libxc/xc_gnttab.c | 1 - tools/libxc/xc_mem_paging.c | 2 +- tools/libxc/xc_minios.c | 3 +-- tools/libxc/xc_pm.c | 1 - tools/libxc/xc_private.h | 29 ++++++++++++++++++++++------- tools/misc/xen-hptool.c | 1 - tools/misc/xen-mfndump.c | 1 - 11 files changed, 47 insertions(+), 28 deletions(-)
PATCH 1/4 tools/libxc: remove double inclusion of errno.h
xc_private.h includes errno.h already
--- tools/libxc/xc_compression.c | 1 - tools/libxc/xc_flask.c | 1 - tools/libxc/xc_gnttab.c | 1 - tools/libxc/xc_minios.c | 1 - tools/libxc/xc_pm.c | 1 - tools/misc/xen-hptool.c | 1 - tools/misc/xen-mfndump.c | 1 - 7 files changed, 7 deletions(-)
tools/libxc/xc_compression.c +0 -1
@@ -32,7 +32,6 @@#include <unistd.h> #include <sys/types.h> #include <inttypes.h> -#include <errno.h> #include "xc_private.h" #include "xenctrl.h" #include "xg_save_restore.h"
tools/libxc/xc_flask.c +0 -1
@@ -19,7 +19,6 @@#include "xc_private.h" #include <unistd.h> #include <stdio.h> -#include <errno.h> #include <fcntl.h> #include <string.h> #include <sys/mman.h>
tools/libxc/xc_gnttab.c +0 -1
@@ -18,7 +18,6 @@*/ #include "xc_private.h" -#include <errno.h> int xc_gnttab_op (xc_interface *xch,int cmd,void * op,int op_size,int count) {
tools/libxc/xc_minios.c +0 -1
@@ -29,7 +29,6 @@#include <mini-os/events.h> #include <mini-os/wait.h> #include <sys/mman.h> -#include <errno.h> #include <xen/memory.h> #include <unistd.h>
tools/libxc/xc_pm.c +0 -1
@@ -19,7 +19,6 @@* */ -#include <errno.h> #include <stdbool.h> #include "xc_private.h"
tools/misc/xen-hptool.c +0 -1
@@ -1,7 +1,6 @@#include <xenctrl.h> #include <xc_private.h> #include <xc_core.h> -#include <errno.h> #include <unistd.h> #define ARRAY_SIZE (a) (sizeof (a) / sizeof ((a)[0]))
tools/misc/xen-mfndump.c +0 -1
@@ -1,7 +1,6 @@#include <xenctrl.h> #include <xc_private.h> #include <xc_core.h> -#include <errno.h> #include <unistd.h> #include <inttypes.h>
Re: [PATCH 1/4] tools/libxc: remove double inclusion of errno.h
Olaf Hering writes ("[PATCH 1/4] tools/libxc: remove double inclusion of errno.h"):
Quoted 1 line
xc_private.hincludeserrno.halready
PATCH 2/4 tools/libxc: assign positive values to errno
In reply to Olaf Hering--- tools/libxc/xc_foreign_memory.c | 2 +- tools/libxc/xc_mem_paging.c | 2 +- tools/libxc/xc_minios.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
tools/libxc/xc_foreign_memory.c +1 -1
@@ -27,7 +27,7 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,int i, *err;if (num <0 ) { - errno = -EINVAL ; + errno =EINVAL ;return NULL ; }
tools/libxc/xc_mem_paging.c +1 -1
@@ -76,7 +76,7 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id, {int rc, old_errno; - errno = -EINVAL ; + errno =EINVAL ;if ( !buffer )return -1 ;
tools/libxc/xc_minios.c +1 -1
@@ -349,7 +349,7 @@ static int minios_evtchn_unbind(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t } }printf ("Warning: couldn't find port %" PRId32" for xc handle %x\n" , port, fd); - errno = -EINVAL ; + errno =EINVAL ;return -1 ; }
Re: [PATCH 2/4] tools/libxc: assign positive values to errno
Olaf Hering writes ("[PATCH 2/4] tools/libxc: assign positive values to errno"):
Quoted 1 line
Signed-off-by Olaf Hering <[email protected]>
Re: [PATCH 2/4] tools/libxc: assign positive values to errno
Quoted 5 lines · Ian Jackson
Olaf Hering writes ("[PATCH 2/4]
tools/libxc: assign positive values to errno"):Quoted 1 line
Signed-off-by Olaf Hering <[email protected]>Acked-by Ian Jackson <[email protected]>Committed-by Ian Jackson <[email protected]>
Are you still planning to do a more comprehensive sweep of libxc's error reporting for 4.5?
Ian.
Re: [PATCH 2/4] tools/libxc: assign positive values to errno
Quoted 9 lines · Ian Campbell
Quoted 5 lines · Ian Jackson
Olaf Hering writes ("[PATCH 2/4]
tools/libxc: assign positive values to errno"):Quoted 1 line
Signed-off-by Olaf Hering <[email protected]>Acked-by Ian Jackson <[email protected]>Committed-by Ian Jackson <[email protected]>Are you still planning to do a more comprehensive sweep of libxc's error reporting for 4.5?
I will at least update suspend/resume code paths while working on the migration constrains patch. While doing that I could also poke around in other areas.
Olaf
Re: [PATCH 2/4] tools/libxc: assign positive values to errno
Quoted 9 lines · Olaf Hering
Quoted 7 lines · Ian Campbell
Quoted 5 lines · Ian Jackson
Olaf Hering writes ("[PATCH 2/4]
tools/libxc: assign positive values to errno"):Quoted 1 line
Signed-off-by Olaf Hering <[email protected]>Acked-by Ian Jackson <[email protected]>Committed-by Ian Jackson <[email protected]>
Quoted 6 lines
Quoted 2 lines
Are you still planning to do a more comprehensive sweep of libxc's error reporting for 4.5?
I will at least update suspend/resume code paths while working on the migration constrains patch. While doing that I could also poke around in other areas.
I was actually talking to Ian J, but if you are doing some then tHat's great too!
Thanks,
Ian.
Re: [PATCH 2/4] tools/libxc: assign positive values to errno
In reply to Ian CampbellIan Campbell writes ("Re: [PATCH 2/4] tools/libxc: assign positive values to errno"):
Quoted 2 lines
Are you still planning to do a more comprehensive sweep of libxc's error reporting for 4.5?
Ideally, yes.
Ian.
PATCH 3/4 tools/xc: preserve errno in ERROR and DRINTF macros
In reply to Olaf HeringThis simplifies a changes made in a follow-up patch.
--- tools/libxc/xc_private.h | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
tools/libxc/xc_private.h +22 -7
@@ -119,13 +119,28 @@ void xc_report_progress_step(xc_interface *xch,/* anamorphic macros: struct xc_interface *xch must be in scope */ -#define IPRINTF(_f, _a...) xc_report(xch, xch->error_handler, XTL_INFO,0, _f , ## _a) -#define DPRINTF(_f, _a...) xc_report(xch, xch->error_handler, XTL_DETAIL,0, _f , ## _a) -#define DBGPRINTF(_f, _a...) xc_report(xch, xch->error_handler, XTL_DEBUG,0, _f , ## _a) - -#define ERROR(_m, _a...) xc_report_error(xch,XC_INTERNAL_ERROR,_m , ## _a ) -#define PERROR(_m, _a...) xc_report_error(xch,XC_INTERNAL_ERROR,_m \ - " (%d = %s)", ## _a , errno, xc_strerror(xch, errno)) +#define IPRINTF(_f, _a...) do { int __errno = errno; \ + xc_report(xch, xch->error_handler, XTL_INFO,0, _f , ## _a); \ + errno = __errno; \ + } while (0) +#define DPRINTF(_f, _a...) do { int __errno = errno; \ + xc_report(xch, xch->error_handler, XTL_DETAIL,0, _f , ## _a); \ + errno = __errno; \ + } while (0) +#define DBGPRINTF(_f, _a...) do { int __errno = errno; \ + xc_report(xch, xch->error_handler, XTL_DEBUG,0, _f , ## _a); \ + errno = __errno; \ + } while (0) + +#define ERROR(_m, _a...) do { int __errno = errno; \ + xc_report_error(xch,XC_INTERNAL_ERROR,_m , ## _a ); \ + errno = __errno; \ + } while (0) +#define PERROR(_m, _a...) do { int __errno = errno; \ + xc_report_error(xch,XC_INTERNAL_ERROR,_m " (%d = %s)", \ + ## _a , errno, xc_strerror(xch, errno)); \ + errno = __errno; \ + } while (0)/* * HYPERCALL ARGUMENT BUFFERS
Re: [PATCH 3/4] tools/xc: preserve errno in ERROR and DRINTF macros
Olaf Hering writes ("[PATCH 3/4] tools/xc: preserve errno in ERROR and DRINTF macros"):
Quoted 1 line
This simplifies a changes made in a follow-up patch.
Thanks. See my comments in my other email...
Ian.
PATCH v2 4/4 tools/xc: pass errno to callers of xc_domain_save
In reply to Olaf HeringCallers of xc_domain_save use errno to print diagnostics if the call fails. But xc_domain_save does not preserve the actual errno in case of a failure.
This change preserves errno in all cases where code jumps to the label "out". In addition a new label "exit" is added to catch also code which used to do just "return 1".
Now libxl_save_helper:complete can print the actual error string.
v2:
- preserve errno during inital jump to label "out"
- use errno as success indicator
--- tools/libxc/xc_domain_save.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
tools/libxc/xc_domain_save.c +22 -11
@@ -150,6 +150,7 @@ static inline int outbuf_write(xc_interface *xch, struct outbuf* ob, void* buf, size_t len) { if ( len > ob->size - ob->pos ) { + errno = ERANGE;DBGPRINTF ("outbuf_write: %zu > %zu@%zu\n" , len, ob->size - ob->pos, ob->pos);return -1 ; }
@@ -806,7 +807,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterxc_dominfo_t info;DECLARE_DOMCTL ; -int rc =1 , frc, i, j, last_iter =0 , iter =0 ; +int rc, frc, i, j, last_iter =0 , iter =0 ;int live = (flags &XCFLAGS_LIVE );int debug = (flags &XCFLAGS_DEBUG );int superpages = !!hvm;
@@ -899,7 +900,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter {ERROR ("No switch_qemu_logdirty callback provided." ); errno =EINVAL ; -return 1 ; + goto exit; }outbuf_init (xch, &ob_pagebuf,OUTBUF_SIZE );
@@ -914,13 +915,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter &ctx->max_mfn, &ctx->hvirt_start, &ctx->pt_levels, &dinfo->guest_width) ) {ERROR ("Unable to get platform info." ); -return 1 ; + goto exit; }if (xc_domain_getinfo (xch, dom,1 , &info) !=1 ) {PERROR ("Could not get domain info" ); -return 1 ; + goto exit; } shared_info_frame = info.shared_info_frame;
@@ -942,6 +943,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterif ( dinfo->p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK ) { + errno =E2BIG ;ERROR ("Cannot save this big a guest" ); goto out; }
@@ -1012,6 +1014,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterif ( !to_send || !to_fix || !to_skip ) { + errno =ENOMEM ;ERROR ("Couldn't allocate to_send array" ); goto out; }
@@ -1030,6 +1033,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter hvm_buf =malloc (hvm_buf_size);if ( !hvm_buf ) { + errno =ENOMEM ;ERROR ("Couldn't allocate memory" ); goto out; }
@@ -1598,6 +1602,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterif ( info.max_vcpu_id >=XC_SR_MAX_VCPUS ) { + errno =E2BIG ;ERROR ("Too many VCPUS in guest!" ); goto out; }
@@ -1830,7 +1835,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter }/* HVM guests are done now */ - rc =0 ; + errno =0 ; goto out; }
@@ -1888,6 +1893,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter mfn =GET_FIELD (&ctxt, user_regs.edx);if ( !MFN_IS_IN_PSEUDOPHYS_MAP (mfn) ) { + errno =ERANGE ;ERROR ("Suspend record is not in range of pseudophys map" ); goto out; }
@@ -1910,6 +1916,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter mfn =GET_FIELD (&ctxt, gdt_frames[j]);if ( !MFN_IS_IN_PSEUDOPHYS_MAP (mfn) ) { + errno =ERANGE ;ERROR ("GDT frame is not in range of pseudophys map" ); goto out; }
@@ -1920,6 +1927,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterif ( !MFN_IS_IN_PSEUDOPHYS_MAP (UNFOLD_CR3 (GET_FIELD (&ctxt, ctrlreg[3 ]))) ) { + errno =ERANGE ;ERROR ("PT base is not in range of pseudophys map" ); goto out; }
@@ -1931,6 +1939,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter {if ( !MFN_IS_IN_PSEUDOPHYS_MAP (UNFOLD_CR3 (ctxt.x64.ctrlreg[1 ])) ) { + errno =ERANGE ;ERROR ("PT base is not in range of pseudophys map" ); goto out; }
@@ -2027,9 +2036,10 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter }/* Success! */ - rc =0 ; + errno =0 ; out: + rc = errno; completed =1 ;if ( !rc && callbacks->postcopy )
@@ -2044,13 +2054,11 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterif (wrcompressed (io_fd) <0 ) {ERROR ("Error when writing compressed data, after postcopy\n" ); - rc =1 ; goto out; }/* Append the tailbuf data to the main outbuf */ if (wrexact (io_fd, ob_tailbuf.buf, ob_tailbuf.pos) ) { - rc =1 ;PERROR ("Error when copying tailbuf into outbuf" ); goto out; }
@@ -2059,7 +2067,8 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter/* Flush last write and discard cache for file. */ if ( ob &&outbuf_flush (xch, ob, io_fd) <0 ) {PERROR ("Error when flushing output buffer" ); - rc =1 ; +if (!rc) + rc = errno; }discard_file_cache (xch, io_fd,1 /* flush */ );
@@ -2130,9 +2139,11 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterfree (hvm_buf);outbuf_free (&ob_pagebuf); -DPRINTF ("Save exit of domid %u with rc=%d\n" , dom, rc); + errno = rc; +exit: +DPRINTF ("Save exit of domid %u with errno=%d\n" , dom, errno); -return !!rc; +return !!errno; }/*
Re: [PATCH 4/4 v2] tools/xc: pass errno to callers of xc_domain_save
Olaf Hering writes ("[PATCH 4/4 v2] tools/xc: pass errno to callers of xc_domain_save"):
tools/libxc/xc_domain_save.c int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter · line 918
Quoted 6 lines
tools/libxc/xc_domain_save.c +1
-1@@ -914,13 +915,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter &ctx->max_mfn, &ctx->hvirt_start, &ctx->pt_levels, &dinfo->guest_width) ) {ERROR ("Unable to get platform info." ); -return 1 ; + goto exit;
This all looks pretty good, thanks.
Can I suggest that these cases could probably benefit from
assert(errno)
?
That way there is no risk of thinking we have succeeded because some subfunction with poor error handling has failed but not set errno.
One option for doing centrally would be:
tools/libxc/xc_domain_save.c int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter · line 2038
Quoted 1 line
tools/libxc/xc_domain_save.c +0
-0/* Success! */
- - rc = 0; - + errno = 0; + goto out_rc;
tools/libxc/xc_domain_save.c int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter · line 2042
Quoted 2 lines
tools/libxc/xc_domain_save.c +1
-0out: + rc = errno;
+ assert(rc);
+ out_rc:
tools/libxc/xc_domain_save.c int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter · line 2043
Quoted 1 line
tools/libxc/xc_domain_save.c +0
-0completed =1 ;
Thanks,
Ian.
Re: [PATCH 4/4 v2] tools/xc: pass errno to callers of xc_domain_save
Quoted 2 lines · Ian Jackson
Can I suggest that these cases could probably benefit from
assert(errno)
I think that verifying errno in that case is a good thing. But:
Wouldnt that abort() applications using libxc, including libvirtd?
Olaf
Re: [PATCH 4/4 v2] tools/xc: pass errno to callers of xc_domain_save
Quoted 7 lines · Olaf Hering
Quoted 2 lines · Ian Jackson
Can I suggest that these cases could probably benefit from
assert(errno)I think that verifying errno in that case is a good thing. But:
Wouldnt thatabort()applications using libxc, including libvirtd?
I see that libxl contains many assert(), so one more would probably not hurt.
Olaf