From nobody Tue Feb 10 17:15:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1541015634918723.9834175798904; Wed, 31 Oct 2018 12:53:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7407886641; Wed, 31 Oct 2018 19:53:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F543610F8; Wed, 31 Oct 2018 19:53:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BC58A4BB74; Wed, 31 Oct 2018 19:53:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9VJpe0t014786 for ; Wed, 31 Oct 2018 15:51:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21D001001925; Wed, 31 Oct 2018 19:51:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 19C79100190E for ; Wed, 31 Oct 2018 19:51:40 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9B1789AC0 for ; Wed, 31 Oct 2018 19:51:38 +0000 (UTC) Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Wed, 31 Oct 2018 13:51:37 -0600 From: Jim Fehlig To: libvir-list@redhat.com Date: Wed, 31 Oct 2018 13:51:26 -0600 Message-Id: <20181031195127.4880-3-jfehlig@suse.com> In-Reply-To: <20181031195127.4880-1-jfehlig@suse.com> References: <20181031195127.4880-1-jfehlig@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 31 Oct 2018 19:51:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 31 Oct 2018 19:51:39 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH V2 2/3] libxl: Remove some goto labels in libxlDomainShutdownThread X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 31 Oct 2018 19:53:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are too many goto labels in libxlDomainShutdownThread. Convert the 'destroy' and 'restart' labels to helper functions, leaving only the commonly used pattern of 'endjob' and 'cleanup' labels. Signed-off-by: Jim Fehlig --- src/libxl/libxl_domain.c | 66 ++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 9ed6ee8fb3..4cdaee0e51 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -430,6 +430,30 @@ virDomainDefParserConfig libxlDomainDefParserConfig = =3D { }; =20 =20 +static void +libxlDomainShutdownHandleDestroy(libxlDriverPrivatePtr driver, + virDomainObjPtr vm) +{ + libxlDomainDestroyInternal(driver, vm); + libxlDomainCleanup(driver, vm); + if (!vm->persistent) + virDomainObjListRemove(driver->domains, vm); +} + + +static void +libxlDomainShutdownHandleRestart(libxlDriverPrivatePtr driver, + virDomainObjPtr vm) +{ + libxlDomainDestroyInternal(driver, vm); + libxlDomainCleanup(driver, vm); + if (libxlDomainStartNew(driver, vm, false) < 0) { + VIR_ERROR(_("Failed to restart VM '%s': %s"), + vm->def->name, virGetLastErrorMessage()); + } +} + + struct libxlShutdownThreadInfo { libxlDriverPrivatePtr driver; @@ -468,10 +492,12 @@ libxlDomainShutdownThread(void *opaque) VIR_DOMAIN_EVENT_STOPPED_SHUTDO= WN); switch ((virDomainLifecycleAction) vm->def->onPoweroff) { case VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY: - goto destroy; + libxlDomainShutdownHandleDestroy(driver, vm); + goto endjob; case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART: case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME: - goto restart; + libxlDomainShutdownHandleRestart(driver, vm); + goto endjob; case VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE: case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY: case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART: @@ -487,19 +513,23 @@ libxlDomainShutdownThread(void *opaque) VIR_DOMAIN_EVENT_STOPPED_CRASHE= D); switch ((virDomainLifecycleAction) vm->def->onCrash) { case VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY: - goto destroy; + libxlDomainShutdownHandleDestroy(driver, vm); + goto endjob; case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART: case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME: - goto restart; + libxlDomainShutdownHandleRestart(driver, vm); + goto endjob; case VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE: case VIR_DOMAIN_LIFECYCLE_ACTION_LAST: goto endjob; case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY: libxlDomainAutoCoreDump(driver, vm); - goto destroy; + libxlDomainShutdownHandleDestroy(driver, vm); + goto endjob; case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART: libxlDomainAutoCoreDump(driver, vm); - goto restart; + libxlDomainShutdownHandleRestart(driver, vm); + goto endjob; } } else if (xl_reason =3D=3D LIBXL_SHUTDOWN_REASON_REBOOT) { virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, @@ -510,10 +540,12 @@ libxlDomainShutdownThread(void *opaque) VIR_DOMAIN_EVENT_STOPPED_SHUTDO= WN); switch ((virDomainLifecycleAction) vm->def->onReboot) { case VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY: - goto destroy; + libxlDomainShutdownHandleDestroy(driver, vm); + goto endjob; case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART: case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME: - goto restart; + libxlDomainShutdownHandleRestart(driver, vm); + goto endjob; case VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE: case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY: case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART: @@ -531,26 +563,8 @@ libxlDomainShutdownThread(void *opaque) * Similar to the xl implementation, ignore SUSPEND. Any actions = needed * after calling libxl_domain_suspend() are handled by it's caller= s. */ - goto endjob; } else { VIR_INFO("Unhandled shutdown_reason %d", xl_reason); - goto endjob; - } - - destroy: - libxlDomainDestroyInternal(driver, vm); - libxlDomainCleanup(driver, vm); - if (!vm->persistent) - virDomainObjListRemove(driver->domains, vm); - - goto endjob; - - restart: - libxlDomainDestroyInternal(driver, vm); - libxlDomainCleanup(driver, vm); - if (libxlDomainStartNew(driver, vm, false) < 0) { - VIR_ERROR(_("Failed to restart VM '%s': %s"), - vm->def->name, virGetLastErrorMessage()); } =20 endjob: --=20 2.18.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list