From nobody Tue Nov 26 07:34:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=ixsystems.com ARC-Seal: i=1; a=rsa-sha256; t=1582353648; cv=none; d=zohomail.com; s=zohoarc; b=chxtWFYrMOuo30MBAY61W/Xr0wvVw6pfuPzHRLbTxd3rA1OhPkRboSdmFoMHcREan8fndr5QIc7bjyRhoVNShrwPY7Z2Ug9lzFqNkPRckzGRUp4Im8eCi28iSL/L+KC02zK7yIK+Ie+yebQsfc3tc9ibPJ+z2DJLj4jJsetP4yg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582353648; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ITlRbxUaLtP6HeziRCZZEZKL8ecpRPv07lIYBDd51g8=; b=KetSvl4FXGxkbK9RBfMDt9WwXmvwdZUhW+mAS1nERjoEHmb8ypfxhQnI8p6jTQmt7wA1jj2c82wFhDW4aJamjjVezhuXiN7tDcyPFWVLoKtSfoNdh1FLVzZyS/+4FuAjxlF956RjVtWpoQ8D0PdSgScy029HEo3jzy2Km4VKeKk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1582353648126715.3901479435158; Fri, 21 Feb 2020 22:40:48 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-53-Xf7l82fKMm6DpyZlBulUUA-1; Sat, 22 Feb 2020 01:40:44 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1BB6A800EB4; Sat, 22 Feb 2020 06:40:39 +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 E63E810027BF; Sat, 22 Feb 2020 06:40:38 +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 96939860D3; Sat, 22 Feb 2020 06:40:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01M6dpD6021784 for ; Sat, 22 Feb 2020 01:39:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id CA3FC1032547; Sat, 22 Feb 2020 06:39:51 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C49C71032531 for ; Sat, 22 Feb 2020 06:39:47 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7A1D4800313 for ; Sat, 22 Feb 2020 06:39:47 +0000 (UTC) Received: from mail-yw1-f67.google.com (mail-yw1-f67.google.com [209.85.161.67]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-269-6nLbKp31MYWMguhtRVYUPQ-1; Sat, 22 Feb 2020 01:39:45 -0500 Received: by mail-yw1-f67.google.com with SMTP id t141so2614269ywc.11 for ; Fri, 21 Feb 2020 22:39:45 -0800 (PST) Received: from xeon-freebsd.freqlabs.com. (69-228-200-148.lightspeed.knvltn.sbcglobal.net. [69.228.200.148]) by smtp.gmail.com with ESMTPSA id c84sm2482131ywa.1.2020.02.21.22.39.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 22:39:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582353647; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ITlRbxUaLtP6HeziRCZZEZKL8ecpRPv07lIYBDd51g8=; b=JEcb0ek+1ITmILDkRmFCad+J+u7KsZy7QH4sIFJBwm559bm93cJVO8/JM5Rk9GpR/3XNCX rIg5kU6Wq+tT8QDHYH+iDY/0lsBVweTvr6TSZLgbCojD4vo/AseFtvjG8AnEqdDRlGOQPh m26CNF94gFfWWi6zGE8wFvB5pVA+Hrw= X-MC-Unique: Xf7l82fKMm6DpyZlBulUUA-1 X-MC-Unique: 6nLbKp31MYWMguhtRVYUPQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5wVTud9ilV8De9l3NZaP/kXUQVtho4TEL2gccD9UyTA=; b=Uko2KlBVueBrqmFlMP8Ne4MDFSwZXtGRgTCnFkhjthBT++fLZpX6aVEKF7ShfiKstI +vMwgri1AYsgAdGaZ/dN+ZuNSmKzmSvusWYziSJqdklwo2opO1LfeAh88DKGqQN+kfNf kItfxIDcZGHS/QiIJYFGJggPwvS/hibIuOC7W5Oj+pnBXQWJJSjIyJKn7ZPeglXQyyj8 VYWcDHYucJLDAj5oLGsVUiVaV58QUhg3bt3Y+9fDfePiusQPlqqb0/D0BjGW1dK0uKed rMy7BJP+eBVg8rriyHK9RdywJI2ApjIFdIkc7xWkjPoqfKhR1z4ERoPLzBWNUW4LwEhb OxSw== X-Gm-Message-State: APjAAAUjty9eH/vTUSygsd2tox2bhbjCrWj75aEtDDTDRyUVKskKzpFH hQJcW2LpeDmk8SKWwQRWVBIMURAnOvCp9klk2hhOhMGbdKWM75HlRgvYu35qZDE7uQus2ea+JV2 JbdMQqoo2Bip1rl/2hsp8/g3VFn7gP7hYgrrDeb6Uxu3Cs8DuTmiSWS5RqYx4l6l6ZX8= X-Google-Smtp-Source: APXvYqzi0zvSRJm3NS2JWEa0si0QkRussuizPfo91TX6fFo40vvVHpuTxieXg4QL9NXWYyQLFUoXEg== X-Received: by 2002:a0d:d7c3:: with SMTP id z186mr33394178ywd.454.1582353584437; Fri, 21 Feb 2020 22:39:44 -0800 (PST) From: Ryan Moeller X-Google-Original-From: Ryan Moeller To: libvir-list@redhat.com Subject: [PATCH 11/16] Add reboot support for bhyve backend Date: Sat, 22 Feb 2020 01:38:50 -0500 Message-Id: <20200222063855.89637-12-ryan@iXsystems.com> In-Reply-To: <20200222063855.89637-1-ryan@iXsystems.com> References: <20200222063855.89637-1-ryan@iXsystems.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01M6dpD6021784 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Ryan Moeller --- src/bhyve/bhyve_driver.c | 30 ++++++++++++++++++++++ src/bhyve/bhyve_monitor.c | 19 +++++++++----- src/bhyve/bhyve_monitor.h | 2 ++ src/bhyve/bhyve_process.c | 52 ++++++++++++++++++++++++++++----------- src/bhyve/bhyve_process.h | 3 +++ 5 files changed, 85 insertions(+), 21 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 625dc0ec22..05ffc2f050 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1013,6 +1013,35 @@ bhyveDomainShutdown(virDomainPtr dom) return bhyveDomainShutdownFlags(dom, 0); } =20 +static int +bhyveDomainReboot(virDomainPtr dom, unsigned int flags) +{ + virConnectPtr conn =3D dom->conn; + virDomainObjPtr vm; + bhyveDomainObjPrivatePtr priv; + int ret =3D -1; + + virCheckFlags(VIR_DOMAIN_REBOOT_ACPI_POWER_BTN, -1); + + if (!(vm =3D bhyveDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainRebootEnsureACL(conn, vm->def, flags) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + priv =3D vm->privateData; + bhyveMonitorSetReboot(priv->mon); + + ret =3D virBhyveProcessShutdown(vm); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static int bhyveDomainOpenConsole(virDomainPtr dom, const char *dev_name G_GNUC_UNUSED, @@ -1657,6 +1686,7 @@ static virHypervisorDriver bhyveHypervisorDriver =3D { .domainDestroyFlags =3D bhyveDomainDestroyFlags, /* 5.6.0 */ .domainShutdown =3D bhyveDomainShutdown, /* 1.3.3 */ .domainShutdownFlags =3D bhyveDomainShutdownFlags, /* 5.6.0 */ + .domainReboot =3D bhyveDomainReboot, /* TBD */ .domainLookupByUUID =3D bhyveDomainLookupByUUID, /* 1.2.2 */ .domainLookupByName =3D bhyveDomainLookupByName, /* 1.2.2 */ .domainLookupByID =3D bhyveDomainLookupByID, /* 1.2.3 */ diff --git a/src/bhyve/bhyve_monitor.c b/src/bhyve/bhyve_monitor.c index a1b1a21a6f..e5cd39a086 100644 --- a/src/bhyve/bhyve_monitor.c +++ b/src/bhyve/bhyve_monitor.c @@ -41,10 +41,11 @@ VIR_LOG_INIT("bhyve.bhyve_monitor"); struct _bhyveMonitor { virObject parent; =20 - int kq; - int watch; bhyveConnPtr driver; virDomainObjPtr vm; + int kq; + int watch; + bool reboot; }; =20 static virClassPtr bhyveMonitorClass; @@ -100,6 +101,12 @@ bhyveMonitorUnregister(bhyveMonitorPtr mon) mon->watch =3D -1; } =20 +void +bhyveMonitorSetReboot(bhyveMonitorPtr mon) +{ + mon->reboot =3D true; +} + static void bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque) { @@ -148,11 +155,10 @@ bhyveMonitorIO(int watch, int kq, int events G_GNUC_U= NUSED, void *opaque) name, WTERMSIG(status)); virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_CRASHED); } else if (WIFEXITED(status)) { - if (WEXITSTATUS(status) =3D=3D 0) { + if (WEXITSTATUS(status) =3D=3D 0 || mon->reboot) { /* 0 - reboot */ - /* TODO: Implementing reboot is a little more complicated.= */ - VIR_INFO("Guest %s rebooted; destroying domain.", name); - virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOW= N); + VIR_INFO("Guest %s rebooted; restarting domain.", name); + virBhyveProcessRestart(driver, vm); } else if (WEXITSTATUS(status) < 3) { /* 1 - shutdown, 2 - halt, 3 - triple fault. others - erro= r */ VIR_INFO("Guest %s shut itself down; destroying domain.", = name); @@ -179,6 +185,7 @@ bhyveMonitorOpenImpl(virDomainObjPtr vm, bhyveConnPtr d= river) return NULL; =20 mon->driver =3D driver; + mon->reboot =3D false; =20 virObjectRef(vm); mon->vm =3D vm; diff --git a/src/bhyve/bhyve_monitor.h b/src/bhyve/bhyve_monitor.h index 226866e6d9..175cc87192 100644 --- a/src/bhyve/bhyve_monitor.h +++ b/src/bhyve/bhyve_monitor.h @@ -29,3 +29,5 @@ typedef bhyveMonitor *bhyveMonitorPtr; =20 bhyveMonitorPtr bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver); void bhyveMonitorClose(bhyveMonitorPtr mon); + +void bhyveMonitorSetReboot(bhyveMonitorPtr mon); diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 45162503d4..060018bc70 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -110,11 +110,10 @@ bhyveProcessStopHook(virDomainObjPtr vm, virHookBhyve= OpType op) VIR_HOOK_SUBOP_END, NULL, NULL, NULL); } =20 -int -virBhyveProcessStart(virConnectPtr conn, - virDomainObjPtr vm, - virDomainRunningReason reason, - unsigned int flags) +static int +virBhyveProcessStartImpl(bhyveConnPtr driver, + virDomainObjPtr vm, + virDomainRunningReason reason) { char *devmap_file =3D NULL; char *devicemap =3D NULL; @@ -122,7 +121,6 @@ virBhyveProcessStart(virConnectPtr conn, int logfd =3D -1; virCommandPtr cmd =3D NULL; virCommandPtr load_cmd =3D NULL; - bhyveConnPtr driver =3D conn->privateData; bhyveDomainObjPrivatePtr priv =3D vm->privateData; int ret =3D -1, rc; =20 @@ -154,10 +152,6 @@ virBhyveProcessStart(virConnectPtr conn, if (bhyveDomainAssignAddresses(vm->def, NULL) < 0) goto cleanup; =20 - /* Run an early hook to setup missing devices. */ - if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0) - goto cleanup; - /* Call bhyve to start the VM */ if (!(cmd =3D virBhyveProcessBuildBhyveCmd(driver, vm->def, false))) goto cleanup; @@ -213,11 +207,6 @@ virBhyveProcessStart(virConnectPtr conn, goto cleanup; } =20 - if (flags & VIR_BHYVE_PROCESS_START_AUTODESTROY && - virCloseCallbacksSet(driver->closeCallbacks, vm, - conn, bhyveProcessAutoDestroy) < 0) - goto cleanup; - vm->def->id =3D vm->pid; virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason); priv->mon =3D bhyveMonitorOpen(vm, driver); @@ -262,6 +251,26 @@ virBhyveProcessStart(virConnectPtr conn, return ret; } =20 +int +virBhyveProcessStart(virConnectPtr conn, + virDomainObjPtr vm, + virDomainRunningReason reason, + unsigned int flags) +{ + bhyveConnPtr driver =3D conn->privateData; + + /* Run an early hook to setup missing devices. */ + if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0) + return -1; + + if (flags & VIR_BHYVE_PROCESS_START_AUTODESTROY && + virCloseCallbacksSet(driver->closeCallbacks, vm, + conn, bhyveProcessAutoDestroy) < 0) + return -1; + + return virBhyveProcessStartImpl(driver, vm, reason); +} + int virBhyveProcessStop(bhyveConnPtr driver, virDomainObjPtr vm, @@ -349,6 +358,19 @@ virBhyveProcessShutdown(virDomainObjPtr vm) return 0; } =20 +int +virBhyveProcessRestart(bhyveConnPtr driver, + virDomainObjPtr vm) +{ + if (virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN) < 0) + return -1; + + if (virBhyveProcessStartImpl(driver, vm, VIR_DOMAIN_RUNNING_BOOTED) < = 0) + return -1; + + return 0; +} + int virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm, unsigned long long *cpustats) diff --git a/src/bhyve/bhyve_process.h b/src/bhyve/bhyve_process.h index 8419e44faa..d7b4e0bd4e 100644 --- a/src/bhyve/bhyve_process.h +++ b/src/bhyve/bhyve_process.h @@ -32,6 +32,9 @@ int virBhyveProcessStop(bhyveConnPtr driver, virDomainObjPtr vm, virDomainShutoffReason reason); =20 +int virBhyveProcessRestart(bhyveConnPtr driver, + virDomainObjPtr vm); + int virBhyveProcessShutdown(virDomainObjPtr vm); =20 int virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm, --=20 2.24.1