From nobody Tue Nov 26 07:40:33 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=1582353723; cv=none; d=zohomail.com; s=zohoarc; b=aGQ32wZj8IEy2ZUPnpL1OuQS2fo9A8/JT9kT28MTTvXQWV4ExaJBvI9uUtkWkOoeB9T69Ms3Hc++vwXhUZGKV7nz+OGydsm0zTfMZvazA+5bmNQHkJ+BetKK/SuBr6MxThACHzSymgOWtlBQ8XoYyKmJZBZm90RSkY/accPgZbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582353723; 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=+KEnc/M2u1vtOq7byLY/tjxqteMUZASB3RpwswtsBa4=; b=XuD2Xf55sEv3t4Qdr5LvKV2kZt6xCPW9ZVl2d6Y7PSMi+/hqD+gAOIvxNXjf2Do7ekXhMJ5vyu5IczzBoTKKJDK9QZeUPP5klOuestk5yBDBI8NMsx8+5kDZoFWJICcj3AGDkePqAHwxP9uSIowu6zaqlihp8R2VE8BmCI9/Dh4= 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-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1582353723339302.5027120753874; Fri, 21 Feb 2020 22:42:03 -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-18-IeCrsdyPPESFqF6J3g0rpQ-1; Sat, 22 Feb 2020 01:41:09 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 534D118A5505; Sat, 22 Feb 2020 06:41:01 +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 2754890788; Sat, 22 Feb 2020 06:41:01 +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 CAD9D860D4; Sat, 22 Feb 2020 06:41:00 +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 01M6diZU021752 for ; Sat, 22 Feb 2020 01:39:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id C13DD1032530; Sat, 22 Feb 2020 06:39:44 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC5351032523 for ; Sat, 22 Feb 2020 06:39:44 +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 A1E4185A30E for ; Sat, 22 Feb 2020 06:39:44 +0000 (UTC) Received: from mail-yw1-f66.google.com (mail-yw1-f66.google.com [209.85.161.66]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-377-VPK9zgZVNYC56E_t-ZMucw-1; Sat, 22 Feb 2020 01:39:42 -0500 Received: by mail-yw1-f66.google.com with SMTP id h126so2638225ywc.6 for ; Fri, 21 Feb 2020 22:39:42 -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.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 22:39:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582353722; 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=+KEnc/M2u1vtOq7byLY/tjxqteMUZASB3RpwswtsBa4=; b=Y6EqZJcwHGSqjKs85CycDSmBzwmd8mI6i/Sh76gD6S6PCDjhLkLS+aK0o9O3yBcfRM9Jz3 JVJObKWOgOnM4hHLSZSE+8GxDfYcuidwlC+IbjtdKwRMIqLTOIi8t5IReba+hFpfhfHYBL wCWHIPs1R61WQ5q8zUM81+ne+pjv/Ro= X-MC-Unique: IeCrsdyPPESFqF6J3g0rpQ-1 X-MC-Unique: VPK9zgZVNYC56E_t-ZMucw-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=XGvJLsTREio1QIpp5c7NrMw6Sg6CQdK0mb5OfvwWbqM=; b=lger+NVj9WhWQZsY++yK9eChx6W5uGdUa1jJmS22u4c+sGJSjIxU5afLRbg72Xf3cK YlxlPBFyCqAAgqCHWxSvTix2+x+cn+pAWvP6QBwm17N9pUjnWOfU4YQRGE5T8IsPO0yn f3ERNN0rnTuWhGRoTdaKuDmYGORmbg3tvLfhdddxXclm480BgREZ87hHV2YU5TGAUowm 4n4nMqbAWvoC69IIS/5KN/Zu/74m+1CaYzoo+ytx5jqDt4IgNonbTYaapa1iNi2bqdEt Y80CFlQh0/viSNZqNuAuKM5lk8emqCYxgiYbwXGWIq2wPvOyieSK074ryFek7ws4a6/y 6LgA== X-Gm-Message-State: APjAAAUspV1z1vcxe25cmrSCDUta+oc++VhqOme32jQToOJhoDntF4rO WcBZN4XqdaZm8m8d8ot1AVh27mM/tFujto3GWROAdjMqbaDw+DxU6V2bGZ03KLwX450W3rT5Xrk AqOD9ZByWu/isrYKVbI8eMeelvij5DTW/gpfISvQOVFKhWUUoabYUqusXMXH+ASU+9Cw= X-Google-Smtp-Source: APXvYqwwinwk5454XHP5Ip5ipdpqmJNHmzA0zQKVkiM7u6HKVpQT1sPnFMVNDy1vPwk6eZtvnwyKLw== X-Received: by 2002:a25:b947:: with SMTP id s7mr35573565ybm.50.1582353581462; Fri, 21 Feb 2020 22:39:41 -0800 (PST) From: Ryan Moeller X-Google-Original-From: Ryan Moeller To: libvir-list@redhat.com Subject: [PATCH 10/16] Add hooks for bhyve backend Date: Sat, 22 Feb 2020 01:38:49 -0500 Message-Id: <20200222063855.89637-11-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 01M6diZU021752 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.79 on 10.5.11.13 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_process.c | 33 +++++++++++++++++++++++++++++++++ src/util/virhook.c | 15 +++++++++++++++ src/util/virhook.h | 11 +++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index a11f75a894..45162503d4 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -37,6 +37,7 @@ #include "bhyve_process.h" #include "datatypes.h" #include "virerror.h" +#include "virhook.h" #include "virlog.h" #include "virfile.h" #include "viralloc.h" @@ -91,6 +92,24 @@ virBhyveFormatDevMapFile(const char *vm_name, char **fn_= out) *fn_out =3D g_strdup_printf("%s/grub_bhyve-%s-device.map", BHYVE_STATE= _DIR, vm_name); } =20 +static int +bhyveProcessStartHook(virDomainObjPtr vm, virHookBhyveOpType op) +{ + if (!virHookPresent(VIR_HOOK_DRIVER_BHYVE)) + return 0; + + return virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op, + VIR_HOOK_SUBOP_BEGIN, NULL, NULL, NULL); +} + +static void +bhyveProcessStopHook(virDomainObjPtr vm, virHookBhyveOpType op) +{ + if (virHookPresent(VIR_HOOK_DRIVER_BHYVE)) + virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op, + VIR_HOOK_SUBOP_END, NULL, NULL, NULL); +} + int virBhyveProcessStart(virConnectPtr conn, virDomainObjPtr vm, @@ -135,6 +154,10 @@ 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; @@ -176,6 +199,9 @@ virBhyveProcessStart(virConnectPtr conn, goto cleanup; } =20 + if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_START) < 0) + goto cleanup; + /* Now we can start the domain */ VIR_DEBUG("Starting domain '%s'", vm->def->name); if (virCommandRun(cmd, NULL) < 0) @@ -200,6 +226,9 @@ virBhyveProcessStart(virConnectPtr conn, BHYVE_STATE_DIR) < 0) goto cleanup; =20 + if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_STARTED) < 0) + goto cleanup; + ret =3D 0; =20 cleanup: @@ -263,6 +292,8 @@ virBhyveProcessStop(bhyveConnPtr driver, if ((priv !=3D NULL) && (priv->mon !=3D NULL)) bhyveMonitorClose(priv->mon); =20 + bhyveProcessStopHook(vm, VIR_HOOK_BHYVE_OP_STOPPED); + /* Cleanup network interfaces */ bhyveNetCleanup(vm); =20 @@ -284,6 +315,8 @@ virBhyveProcessStop(bhyveConnPtr driver, vm->pid =3D -1; vm->def->id =3D -1; =20 + bhyveProcessStopHook(vm, VIR_HOOK_BHYVE_OP_RELEASE); + cleanup: virCommandFree(cmd); =20 diff --git a/src/util/virhook.c b/src/util/virhook.c index 5bdacdd79f..e499841f66 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -47,6 +47,7 @@ VIR_ENUM_DECL(virHookQemuOp); VIR_ENUM_DECL(virHookLxcOp); VIR_ENUM_DECL(virHookNetworkOp); VIR_ENUM_DECL(virHookLibxlOp); +VIR_ENUM_DECL(virHookBhyveOp); =20 VIR_ENUM_IMPL(virHookDriver, VIR_HOOK_DRIVER_LAST, @@ -55,6 +56,7 @@ VIR_ENUM_IMPL(virHookDriver, "lxc", "network", "libxl", + "bhyve", ); =20 VIR_ENUM_IMPL(virHookDaemonOp, @@ -115,6 +117,15 @@ VIR_ENUM_IMPL(virHookLibxlOp, "reconnect", ); =20 +VIR_ENUM_IMPL(virHookBhyveOp, + VIR_HOOK_BHYVE_OP_LAST, + "start", + "stopped", + "prepare", + "release", + "started", +); + static int virHooksFound =3D -1; =20 /** @@ -283,6 +294,10 @@ virHookCall(int driver, break; case VIR_HOOK_DRIVER_NETWORK: opstr =3D virHookNetworkOpTypeToString(op); + break; + case VIR_HOOK_DRIVER_BHYVE: + opstr =3D virHookBhyveOpTypeToString(op); + break; } if (opstr =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/util/virhook.h b/src/util/virhook.h index f91cb87b10..d8237c837e 100644 --- a/src/util/virhook.h +++ b/src/util/virhook.h @@ -29,6 +29,7 @@ typedef enum { VIR_HOOK_DRIVER_LXC, /* LXC domains related events */ VIR_HOOK_DRIVER_NETWORK, /* network related events */ VIR_HOOK_DRIVER_LIBXL, /* Xen libxl domains related events= */ + VIR_HOOK_DRIVER_BHYVE, /* Bhyve domains related events */ =20 VIR_HOOK_DRIVER_LAST, } virHookDriverType; @@ -97,6 +98,16 @@ typedef enum { VIR_HOOK_LIBXL_OP_LAST, } virHookLibxlOpType; =20 +typedef enum { + VIR_HOOK_BHYVE_OP_START, /* domain is about to start */ + VIR_HOOK_BHYVE_OP_STOPPED, /* domain has stopped */ + VIR_HOOK_BHYVE_OP_PREPARE, /* domain startup initiated */ + VIR_HOOK_BHYVE_OP_RELEASE, /* domain destruction is over */ + VIR_HOOK_BHYVE_OP_STARTED, /* domain has started */ + + VIR_HOOK_BHYVE_OP_LAST, +} virHookBhyveOpType; + int virHookInitialize(void); =20 int virHookPresent(int driver); --=20 2.24.1