From: Ian Jackson Subject: Re: [Patch v2 2/3] correct xc_domain_save()'s return value Date: Fri, 14 Nov 2014 14:57:08 +0000 Message-ID: <21606.6212.353346.560825@mariner.uk.xensource.com> References: <1412820314-323-1-git-send-email-wency@cn.fujitsu.com> <1412820314-323-3-git-send-email-wency@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1412820314-323-3-git-send-email-wency@cn.fujitsu.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wen Congyang Cc: Lai Jiangshan , Andrew Cooper , Jiang Yunhong , Dong Eddie , xen devel , Yang Hongyang , Ian Campbell List-Id: xen-devel@lists.xenproject.org Wen Congyang writes ("[Patch v2 2/3] correct xc_domain_save()'s return value"): > If suspend_and_state() fails, the errno may be 0. But we assume > that the errno is not 0. So remove assert(). Thanks for spotting this. I think this is going in the wrong direction. Perhaps we could instead do something like the patch below ? Please let me know what you think. If you think this is a better idea, please submit it as a proper patch with a proper commit message. (Ideally we would fix the actual suspend hook in libxl, to always set errno, but that's too invasive a set of changes to do now, I think.) Thanks, Ian. Signed-off-by: Ian Jackson diff --git a/tools/libxc/include/xenguest.h b/tools/libxc/include/xenguest.h index 40bbac8..3ab9dd8 100644 --- a/tools/libxc/include/xenguest.h +++ b/tools/libxc/include/xenguest.h @@ -35,7 +35,9 @@ /* callbacks provided by xc_domain_save */ struct save_callbacks { /* Called after expiration of checkpoint interval, - * to suspend the guest. + * to suspend the guest. Returns 1 for success, or 0 for failure. + * On failure it should ideally set errno. (If it leaves errno + * as 0, EIO will be used instead.) */ int (*suspend)(void* data); diff --git a/tools/libxc/xc_domain_save.c b/tools/libxc/xc_domain_save.c index 254fdb3..444aac6 100644 --- a/tools/libxc/xc_domain_save.c +++ b/tools/libxc/xc_domain_save.c @@ -361,9 +361,15 @@ static int suspend_and_state(int (*suspend)(void*), void* data, xc_interface *xch, int io_fd, int dom, xc_dominfo_t *info) { + errno = 0; if ( !(*suspend)(data) ) { - ERROR("Suspend request failed"); + if (!errno) { + errno = EIO; + ERROR("Suspend request failed (without errno, using EINVAL)"); + } else { + ERROR("Suspend request failed"); + } return -1; }