From nobody Sun Feb 8 03:33:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1582526845; cv=none; d=zohomail.com; s=zohoarc; b=TXNC8F63sZmkF3rel3BxAYawYvUc8XLGJMpbOfzHeF9zkE8f2g/WQpqzsoXlkd6HedN0T/ZPNpmxOn3vmJHQPsyy+9rlTD8NkIvMYmiIPBx9ffBV8S01VTmz+2VKh019OD3sN7iu0OorGOVKj7bNQO9XdnoYK5AU/OtlNOkw9Z4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582526845; h=Content-Type:Content-Transfer-Encoding:Cc: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=qp8iQSB64ivSp2BjDdC5rZYApRZUcWbkUjB+gJShWmM=; b=c2aumJK8woeFlp/o+p2HhaZiZWCovJBZOHAYXLRvhTCW+YPnD8aKklWX9Ik7qeNfxCRuGz7X7+nwZryuyXjTTCChm7ozoklKdaDEEK07IZhwV3/9AYDY0kG7ySCXiCb8SnDcuisJ3diHp6P5lmrtKH/ZkbaSaLi1BFh5FRNBiVY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1582526845488209.20863840403285; Sun, 23 Feb 2020 22:47:25 -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-418-fAOUk2L7M9muO5hIpAWPJA-1; Mon, 24 Feb 2020 01:47:22 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B575185735D; Mon, 24 Feb 2020 06:47:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E55085C578; Mon, 24 Feb 2020 06:47:16 +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 9DD7418089C8; Mon, 24 Feb 2020 06:47:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01O6kdrI025553 for ; Mon, 24 Feb 2020 01:46:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id BB7132028CD5; Mon, 24 Feb 2020 06:46:39 +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 B5B5E2026D68 for ; Mon, 24 Feb 2020 06:46:37 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 A5123800646 for ; Mon, 24 Feb 2020 06:46:37 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-75-8ubzdL1pO9Clu0Mh6qEhDQ-1; Mon, 24 Feb 2020 01:46:35 -0500 Received: by mail-yb1-f195.google.com with SMTP id y18so1426650ybj.8 for ; Sun, 23 Feb 2020 22:46:35 -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 j184sm4821447ywa.39.2020.02.23.22.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2020 22:46:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582526844; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=qp8iQSB64ivSp2BjDdC5rZYApRZUcWbkUjB+gJShWmM=; b=Ej89kz7ABLY5HTlELqsLJrirW1vpy/sMIPTLXWbguOEfa5o1tD+tVayZ2Gj/d36TnA6IP+ qqKCHnof3RrOUEf8RUvTIYhYZLbnlmKV4LlNqDcs0NFfDJ3f32AZSwxe8NoadesZ8/XN89 vdbGqGn4tBWpvKvkdR2WR4VrXKaj30w= X-MC-Unique: fAOUk2L7M9muO5hIpAWPJA-1 X-MC-Unique: 8ubzdL1pO9Clu0Mh6qEhDQ-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:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wcEwGHBENlNMP4PN7jYz10y2K+9YPaac/bbYf2GDphQ=; b=CGjjmoTQmzEkwVNs7SIcXD+JwaPMTgrAWoD09lkRWhTIjyEQpOXFWH3Mb3bSzFW1iY couuU9aAJ6xCO37NowxDIm3D8sC734G5Y3dY+yW7HOE5ZlH/348vi2+o0xA8LX8quymS DzRf6zQ0Qkk1YArAB/SYoywORkb+YG6OiShWGYiYJCBxXj6BgExLPrPTVJjI9YakRMNn v5BYCMdGvrLz7SLIJPP1AyLCWU0+JNLqs9W1AeNAVFGhG6fUolQ6C7S3KMuEB7zmA74y ikM65kjIi8cLklk94uSw6PUjkgRkYsdwzsKP7CSv8xUofuGH9sqT6LSarVGMQIZlP+v5 zHSA== X-Gm-Message-State: APjAAAX2YFl+vCGQzXGKee5qj7uyg7csQlZ09q9cpoVaW57To0l+B5lj j7Sq+NNrrTbXC2aRIiVqy+osfZVzCr+miSGSMILwcsXEVaL0X9aw3vG/ofTHQ0YId44o8W7PbQM bEDllKDZGFoKyshovsMxzGufVlFeTBwvbcBLaIlFaYhpG1xdFIJyONu9QZGXM4enRcaY= X-Google-Smtp-Source: APXvYqzkrwsHMEz3RLxhwhjSBqDqi+DW9dmBt7a8qtTV4HoqpZ9X5fUaurAWx+vQV2AZYmQnfEfzxA== X-Received: by 2002:a25:3203:: with SMTP id y3mr41504698yby.424.1582526794469; Sun, 23 Feb 2020 22:46:34 -0800 (PST) From: Ryan Moeller X-Google-Original-From: Ryan Moeller To: libvir-list@redhat.com Subject: [PATCH v1 04/12] bhyve: monitor: Make bhyveMonitor a virClass Date: Mon, 24 Feb 2020 01:46:16 -0500 Message-Id: <20200224064624.66649-5-ryan@iXsystems.com> In-Reply-To: <20200224064624.66649-1-ryan@iXsystems.com> References: <20200224064624.66649-1-ryan@iXsystems.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01O6kdrI025553 X-loop: libvir-list@redhat.com Cc: Ryan Moeller 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.16 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" This makes lifecycle management a bit easier thanks to ref counting, and it is closer to what the qemu driver does. Signed-off-by: Ryan Moeller Reviewed-by: Daniel P. Berrang=C3=A9 --- src/bhyve/bhyve_monitor.c | 116 +++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 40 deletions(-) diff --git a/src/bhyve/bhyve_monitor.c b/src/bhyve/bhyve_monitor.c index 0e55e19772..58d40e1f70 100644 --- a/src/bhyve/bhyve_monitor.c +++ b/src/bhyve/bhyve_monitor.c @@ -32,24 +32,51 @@ #include "virerror.h" #include "virfile.h" #include "virlog.h" +#include "virobject.h" =20 #define VIR_FROM_THIS VIR_FROM_BHYVE =20 VIR_LOG_INIT("bhyve.bhyve_monitor"); =20 struct _bhyveMonitor { + virObject parent; + int kq; int watch; bhyveConnPtr driver; + virDomainObjPtr vm; }; =20 +static virClassPtr bhyveMonitorClass; + +static void +bhyveMonitorDispose(void *obj) +{ + bhyveMonitorPtr mon =3D obj; + + VIR_FORCE_CLOSE(mon->kq); + virObjectUnref(mon->vm); +} + +static int +bhyveMonitorOnceInit(void) +{ + if (!VIR_CLASS_NEW(bhyveMonitor, virClassForObject())) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(bhyveMonitor); + static void bhyveMonitorIO(int watch, int kq, int events G_GNUC_UNUSED, void *opaque) { const struct timespec zerowait =3D { 0, 0 }; - virDomainObjPtr vm =3D opaque; - bhyveDomainObjPrivatePtr priv =3D vm->privateData; - bhyveMonitorPtr mon =3D priv->mon; + bhyveMonitorPtr mon =3D opaque; + virDomainObjPtr vm =3D mon->vm; + bhyveConnPtr driver =3D mon->driver; + const char *name; struct kevent kev; int rc, status; =20 @@ -82,60 +109,49 @@ bhyveMonitorIO(int watch, int kq, int events G_GNUC_UN= USED, void *opaque) return; } =20 + name =3D vm->def->name; status =3D kev.data; if (WIFSIGNALED(status) && WCOREDUMP(status)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Guest %s got signal %d and crashed"), - vm->def->name, - WTERMSIG(status)); - virBhyveProcessStop(mon->driver, vm, - VIR_DOMAIN_SHUTOFF_CRASHED); + name, WTERMSIG(status)); + virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_CRASHED); } else if (WIFEXITED(status)) { if (WEXITSTATUS(status) =3D=3D 0) { /* 0 - reboot */ /* TODO: Implementing reboot is a little more complicated.= */ - VIR_INFO("Guest %s rebooted; destroying domain.", - vm->def->name); - virBhyveProcessStop(mon->driver, vm, - VIR_DOMAIN_SHUTOFF_SHUTDOWN); + VIR_INFO("Guest %s rebooted; destroying domain.", name); + virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOW= N); } else if (WEXITSTATUS(status) < 3) { /* 1 - shutdown, 2 - halt, 3 - triple fault. others - erro= r */ - VIR_INFO("Guest %s shut itself down; destroying domain.", - vm->def->name); - virBhyveProcessStop(mon->driver, vm, - VIR_DOMAIN_SHUTOFF_SHUTDOWN); + VIR_INFO("Guest %s shut itself down; destroying domain.", = name); + virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOW= N); } else { VIR_INFO("Guest %s had an error and exited with status %d;= destroying domain.", - vm->def->name, WEXITSTATUS(status)); - virBhyveProcessStop(mon->driver, vm, - VIR_DOMAIN_SHUTOFF_UNKNOWN); + name, WEXITSTATUS(status)); + virBhyveProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_UNKNOWN= ); } } } } =20 -static void -bhyveMonitorRelease(void *opaque) -{ - virDomainObjPtr vm =3D opaque; - bhyveDomainObjPrivatePtr priv =3D vm->privateData; - bhyveMonitorPtr mon =3D priv->mon; - - VIR_FORCE_CLOSE(mon->kq); - VIR_FREE(mon); -} - -bhyveMonitorPtr -bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver) +static bhyveMonitorPtr +bhyveMonitorOpenImpl(virDomainObjPtr vm, bhyveConnPtr driver) { - bhyveMonitorPtr mon =3D NULL; + bhyveMonitorPtr mon; struct kevent kev; =20 - if (VIR_ALLOC(mon) < 0) + if (bhyveMonitorInitialize() < 0) + return NULL; + + if (!(mon =3D virObjectNew(bhyveMonitorClass))) return NULL; =20 mon->driver =3D driver; =20 + virObjectRef(vm); + mon->vm =3D vm; + mon->kq =3D kqueue(); if (mon->kq < 0) { virReportError(VIR_ERR_SYSTEM_ERROR, "%s", @@ -150,14 +166,17 @@ bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr dri= ver) goto cleanup; } =20 + virObjectRef(mon); mon->watch =3D virEventAddHandle(mon->kq, VIR_EVENT_HANDLE_READABLE | VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP, bhyveMonitorIO, - vm, - bhyveMonitorRelease); + mon, + virObjectFreeCallback); if (mon->watch < 0) { + VIR_DEBUG("failed to add event handle for mon %p", mon); + virObjectUnref(mon); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to register monitor events")); goto cleanup; @@ -166,18 +185,35 @@ bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr dri= ver) return mon; =20 cleanup: - bhyveMonitorRelease(mon); + bhyveMonitorClose(mon); return NULL; } =20 +bhyveMonitorPtr +bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driver) +{ + bhyveMonitorPtr mon; + + virObjectRef(vm); + mon =3D bhyveMonitorOpenImpl(vm, driver); + virObjectUnref(vm); + + return mon; +} + void bhyveMonitorClose(bhyveMonitorPtr mon) { if (mon =3D=3D NULL) return; =20 - if (mon->watch > 0) - virEventRemoveHandle(mon->watch); - else - bhyveMonitorRelease(mon); + VIR_DEBUG("cleaning up bhyveMonitor %p", mon); + + if (mon->watch < 0) + return; + + virEventRemoveHandle(mon->watch); + mon->watch =3D -1; + + virObjectUnref(mon); } --=20 2.24.1