From patchwork Tue Sep 2 16:22:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 385220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1D235140086 for ; Wed, 3 Sep 2014 02:23:34 +1000 (EST) Received: from localhost ([::1]:39234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOqrk-0001qf-6s for incoming@patchwork.ozlabs.org; Tue, 02 Sep 2014 12:23:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOqrL-0001ZC-LE for qemu-devel@nongnu.org; Tue, 02 Sep 2014 12:23:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOqrC-0007ZD-KX for qemu-devel@nongnu.org; Tue, 02 Sep 2014 12:23:07 -0400 Received: from mail-pd0-x233.google.com ([2607:f8b0:400e:c02::233]:51450) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOqrC-0007Y9-DH for qemu-devel@nongnu.org; Tue, 02 Sep 2014 12:22:58 -0400 Received: by mail-pd0-f179.google.com with SMTP id z10so8995105pdj.10 for ; Tue, 02 Sep 2014 09:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=jPSJ5EpfsUSYKv7IYs9P5vGFE/mgNbQ/aNwAQoXzKqA=; b=Ucp1suEf6s7avO47szx85wKsTir0SrJFVFXq1/VXTsQH9szhhfy1RHxcrw4EjXtIi0 ktGoeRiBWcVk0k0kG+UYuDlaU1twuqRLDC1qOLtCYCDc/M536HmkS4au9jQ0kPN1CCpH 5isW/QBNJv3SGbjpAMev9imR/dBAnPN1itRgUblGyEKK5r6WRIGATc91otyHR4CrKa9h XCwTlVStslrfH8jIRdgKFcBUsOsuFIo6xhXkGzwMpbjqXTp7vUbyFkN8hfobf7ltmtiq CqVzPLEk5zV/OF6vrnWFWT2kVPn6iBKiAI5bPHVoZJnOKSt/jQbjiPrQEcIvxjIdwSB5 +gxg== X-Received: by 10.66.159.8 with SMTP id wy8mr48748479pab.17.1409674976482; Tue, 02 Sep 2014 09:22:56 -0700 (PDT) Received: from [192.168.1.103] ([223.72.65.70]) by mx.google.com with ESMTPSA id fk10sm12668283pab.29.2014.09.02.09.22.53 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 02 Sep 2014 09:22:55 -0700 (PDT) Message-ID: <5405EED9.2090701@gmail.com> Date: Wed, 03 Sep 2014 00:22:49 +0800 From: Chen Gang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: stefano.stabellini@eu.citrix.com X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::233 Cc: xen-devel@lists.xensource.com, qemu-devel Subject: [Qemu-devel] [PATCH] xen-hvm.c: Improve the return method for xen_hvm_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When failure occurs, it need use "return -1" instead of exit(1), so can let upper caller has chance to print failure information, too, then user can know the failure result more clearly. xen_hvm_init() may also return -errno, which may let upper caller think more (e.g. free some other related resources and try again), although at present, all related upper callers still exit(1). It is not a normal function which does not release related resources, if return -1. So need give the related comments for it. It passes common test under fedora 20 x86_64: "./configure --enable-xen && make -j4 && make check" execute result: "echo $? == 0". Signed-off-by: Chen Gang --- xen-hvm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xen-hvm.c b/xen-hvm.c index 0d09940..35efec0 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -978,6 +978,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data) xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); } +/* return value: 0 is OK, -errno is failure, -1 is critical issue -- exit(1) */ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, MemoryRegion **ram_memory) { @@ -998,6 +999,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, state->xenstore = xs_daemon_open(); if (state->xenstore == NULL) { perror("xen: xenstore open"); + xc_evtchn_close(state->xce_handle); g_free(state); return -errno; } @@ -1069,7 +1071,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, /* Initialize backend core & drivers */ if (xen_be_init() != 0) { fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__); - exit(1); + return -1; } xen_be_register("console", &xen_console_ops); xen_be_register("vkbd", &xen_kbdmouse_ops);