From nobody Tue Nov 26 07:48:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1582353626; cv=none; d=zohomail.com; s=zohoarc; b=LmjXS4MdzhrCgduoxYjPoy54FjRafYgB8+pTsY7IY6fUKJK4pwFXTiMml5T/rfFD6kKTmRY+2oro5csKg6I1eEKWxJd7X6Y3Ry/W+IvIOi5ouPJlJJg+45B+ajb6hzRmc4Da394+EDSnKkutHdEGj15Dy57FtcdT5E1H3HOcI9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582353626; 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=KO0z3TtkI0TSoZ7kcI5Ldl96ZSdAXrlSMjWjVQ10CQo=; b=ZNCk0QR5BOTKYRGnWnhbBFhAxDICRR3Iswt96/Y31McgUFIdQoMyWanB4t+tjZWpujIryhL7G/GDTR1BldnjPiJn4yBDJCHvOoeuFbWCCfxBmCYfh3xgPjTP7KCr4o5jV+WE17i2oeWxiEwbeENo9Ntjj6XSuMHCVQwtGHINjRU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1582353626661251.67102515597207; Fri, 21 Feb 2020 22:40:26 -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-264-o-splqD7NBSG4LzsJNcb6g-1; Sat, 22 Feb 2020 01:40:22 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6632918A5500; Sat, 22 Feb 2020 06:40: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 3D1AE8B74C; Sat, 22 Feb 2020 06:40:17 +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 EC00818089CF; Sat, 22 Feb 2020 06:40:16 +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 01M6dcan021721 for ; Sat, 22 Feb 2020 01:39:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id C73401032530; Sat, 22 Feb 2020 06:39:38 +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 C239D1032523 for ; Sat, 22 Feb 2020 06:39:38 +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 A159785A30E for ; Sat, 22 Feb 2020 06:39:38 +0000 (UTC) Received: from mail-yw1-f65.google.com (mail-yw1-f65.google.com [209.85.161.65]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-LO1dicm4PiqmR3G-Rsh8ow-1; Sat, 22 Feb 2020 01:39:36 -0500 Received: by mail-yw1-f65.google.com with SMTP id i126so2628761ywe.7 for ; Fri, 21 Feb 2020 22:39:36 -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.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 22:39:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582353625; 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=KO0z3TtkI0TSoZ7kcI5Ldl96ZSdAXrlSMjWjVQ10CQo=; b=KT+9ShYwnhLHZ7UFh46LrHzEcdIdL2xeicklUfNX2UbfcQZhhlrONHmkW0vqHG/mCce4h2 ATaTVcHDZqPvwIbqYPgj98aYcWUpMsTXiZIY+RoEHSdwZt7WxzXWkajhU+iterlbA6Q5KP 92/z0btsJDH+cg75uEpzNnmqW7ZuF6I= X-MC-Unique: o-splqD7NBSG4LzsJNcb6g-1 X-MC-Unique: LO1dicm4PiqmR3G-Rsh8ow-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=OWtAEN/Drt65M1QWKqT1Lj2htdW4ejKwe3CzHohNCXA=; b=HxlJ/APVR4Gx4MB5ObTUVj8gy+2bspKHDVRwnRIDbHFawd+7HFaTTOKdvuvPjFUwVU aQ340IuzCa6ZGv0ghsgHlNuLslzlBSecXqst+Xt+H+2vIZ+gcrvEaZSRgLA0Ndn6szEC uhIsLPONkoDbXmf1xPwwLznKOepUpgpxFfMDTKCR5AX73PPvQO9BIjhFvXC3aKkIKI1U BU7g7mml6xcz/s6s2Cck7dfTMRsQYb7LhiUpqROTqOz0zLIli/41jnkEKzhrXdpJBdMk tuImMX4MNqdfZc1WRiapU1Hk91AoCDCh4UmJ7GKbjnANXkVw4SgNsB98NTWefd8onFTl cJwA== X-Gm-Message-State: APjAAAWl+D0tzDx+JoiqCOG+SypJ428EM072bPBbVeSlJ1o915tQl5le 8PDu/x1VI/7bsNQZKGaiSk0spbPA44q9nqG+YdzAhqrBTjt9O+i478AZvG39DfOrQcDW1yh6CZj a4/89y4u2/dyu496o3Pj05M2K9W0SnfFGrxWfTVSxjbgr6+G3vc9PVSvp6N64Yxmo/9E= X-Google-Smtp-Source: APXvYqy6DxpXWy1qK+Vd/tkBHJ6/L+wInh62hVS7agBG1mrop2/2lEY2075n8mbyAKta+gWxQtYLdA== X-Received: by 2002:a5b:9ca:: with SMTP id y10mr37471744ybq.195.1582353575561; Fri, 21 Feb 2020 22:39:35 -0800 (PST) From: Ryan Moeller X-Google-Original-From: Ryan Moeller To: libvir-list@redhat.com Subject: [PATCH 08/16] Make bhyveMonitor a virClass Date: Sat, 22 Feb 2020 01:38:47 -0500 Message-Id: <20200222063855.89637-9-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 01M6dcan021721 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.11 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_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