From nobody Sat Feb 7 15:30:15 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=1578045490; cv=none; d=zohomail.com; s=zohoarc; b=Sinp14+DRjNRhPcik0ixdh9vGJNY/tDNZ32YTIdQB36ZR2oct2bPgTJFapMWFGo/umnNkabOrDBDM1s8Jl+W2aEJrZ48pS/0pmRWorHkmJ3jIaWqTd+00f+nbendWGIcHxt0MyE4lt9vYQ0oi4kOsD3tKjdZlgz3K7sciHxcP9g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578045490; 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=R4Bs5U1l9o00yW1wdZlbJTrKiupOgTt2vc4SPGDGe+4=; b=Chjt70f8o86cBXdDS7/JCBdFtVX6gzDqMgWraFXZyAaSaBrRESJsF30v2vNPrJc7tqatntNPTiqpHeMLJoN8a3XcfOIS1oh7u4x4CFymnSi0zO++x5nvxi8DR89Zli+XROVMWH3a2/Voz9sDg5ic9sd5bjKP4ddyXqE6u9LkkWE= 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 1578045490177270.4489779754132; Fri, 3 Jan 2020 01:58:10 -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-370-ZkQ1NPxdOte7HeSmZ1Sh_Q-1; Fri, 03 Jan 2020 04:58:07 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57241800D48; Fri, 3 Jan 2020 09:58:02 +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 C1CF060BF7; Fri, 3 Jan 2020 09:58: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 70F9D18089C8; Fri, 3 Jan 2020 09:57:58 +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 002HkpI6017523 for ; Thu, 2 Jan 2020 12:46:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id C967010CB289; Thu, 2 Jan 2020 17:46:51 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C379810CD619 for ; Thu, 2 Jan 2020 17:46:51 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 A3AF2185B0C8 for ; Thu, 2 Jan 2020 17:46:51 +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-8-cegaS9ioMMaACZ1GwgT5UQ-1; Thu, 02 Jan 2020 12:46:50 -0500 Received: by mail-yw1-f67.google.com with SMTP id x138so17498045ywd.9 for ; Thu, 02 Jan 2020 09:46:49 -0800 (PST) Received: from mp03.tn.ixsystems.com ([12.189.233.131]) by smtp.gmail.com with ESMTPSA id a202sm21904073ywe.8.2020.01.02.09.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2020 09:46:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578045488; 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=R4Bs5U1l9o00yW1wdZlbJTrKiupOgTt2vc4SPGDGe+4=; b=YegZRaX1VJjUZ5B6iNeB6D9FPSCuOclzI7+j3/sWzkM7d7YW62vLbcdmkZGIEIvQgGD0xg WGFrS3OwPC3BMqwHnbe178pj+puT/UYteL9aceZ+UkhFF/woIlWI9CMzu9zQ+cbxnZtHAX dlfxkWejnHU6HeAjOi/L3t1zSIO5Sps= 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=nGzwj3DwZNzqecu4KqY5suojqL/bl7MNNxgzUe7eMuQ=; b=co7KT2OSS0t/viVhLoH8a9GbUX/+M0kPdEZ8ihrhUW1wAnbDPd4JdLDpsUx8pVWyIh gD0qvWfUyKyPMKJktGT6O/LIG3fOBQ9ZXgIYqgB6mYKbsbcdN4V3qD5eR9W1U6vCd23w XXoqtze4L7b2uAREWUtk9SOy01Xx/FUlz9vZ8mV+f/BaMUxDk9U28VHrl7/361ttxHkg /PO8imickyOSCG0OMiKy2EGK5LFT7J52TUb7hdVsty4KXVFZmsVkVDJyotyGW3Xu2jiV 3OdjIoYHZplIK/41D1vunvcLNjSfNDacTJbsJmqRt7gEsnJq9AzTDKQx3l1+jGBqy66f n40Q== X-Gm-Message-State: APjAAAWuj9ldBcZ8mRi+pJGU7jotkWi2XLjAysY836PPx4lGV2Bou63I TZdp1zms8ysyhsG4ggX9c9EdalvwW6HwD+h3Cetgaq4kOD41ajKVqMrR5Z8VX8uRfO7ApljuKz8 1TWsM78y2jyuv3Wx3JMhYce+IUF1qkYl1NywMX1Y65Pt7fLQpof/AMYKrRSr0cFZ/q9g= X-Google-Smtp-Source: APXvYqzjuqtxdfidDCezTgkXbuFZccFGVnkMfQHJsWkeUcd4Gj/nqGci57S8COfA0Ug0yMOCl3vdxQ== X-Received: by 2002:a0d:f5c3:: with SMTP id e186mr52792981ywf.102.1577987209182; Thu, 02 Jan 2020 09:46:49 -0800 (PST) From: Ryan Moeller X-Google-Original-From: Ryan Moeller To: libvir-list@redhat.com Date: Thu, 2 Jan 2020 17:46:31 +0000 Message-Id: <20200102174635.7231-9-ryan@iXsystems.com> In-Reply-To: <20200102174635.7231-1-ryan@iXsystems.com> References: <20200102174635.7231-1-ryan@iXsystems.com> MIME-Version: 1.0 X-MC-Unique: cegaS9ioMMaACZ1GwgT5UQ-1 X-MC-Unique: ZkQ1NPxdOte7HeSmZ1Sh_Q-1 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 002HkpI6017523 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Fri, 03 Jan 2020 04:57:56 -0500 Cc: Ryan Moeller Subject: [libvirt] [PATCH v2 08/12] Make bhyveMonitor a virClass 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.12 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Ryan Moeller Reviewed-by: Daniel P. Berrang=C3=A9 --- src/bhyve/bhyve_monitor.c | 144 ++++++++++++++++++++++++++------------ 1 file changed, 98 insertions(+), 46 deletions(-) diff --git a/src/bhyve/bhyve_monitor.c b/src/bhyve/bhyve_monitor.c index 0e55e19772..566c672ba0 100644 --- a/src/bhyve/bhyve_monitor.c +++ b/src/bhyve/bhyve_monitor.c @@ -32,24 +32,82 @@ #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, int, int, void *); + +static bool +bhyveMonitorRegister(bhyveMonitorPtr mon) +{ + virObjectRef(mon); + mon->watch =3D virEventAddHandle(mon->kq, + VIR_EVENT_HANDLE_READABLE | + VIR_EVENT_HANDLE_ERROR | + VIR_EVENT_HANDLE_HANGUP, + bhyveMonitorIO, + mon, + virObjectFreeCallback); + if (mon->watch < 0) { + VIR_DEBUG("failed to add event handle for mon %p", mon); + virObjectUnref(mon); + return false; + } + return true; +} + +static void +bhyveMonitorUnregister(bhyveMonitorPtr mon) +{ + if (mon->watch < 0) + return; + + virEventRemoveHandle(mon->watch); + mon->watch =3D -1; +} + 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 +140,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; restarting 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 +197,7 @@ bhyveMonitorOpen(virDomainObjPtr vm, bhyveConnPtr driv= er) goto cleanup; } =20 - mon->watch =3D virEventAddHandle(mon->kq, - VIR_EVENT_HANDLE_READABLE | - VIR_EVENT_HANDLE_ERROR | - VIR_EVENT_HANDLE_HANGUP, - bhyveMonitorIO, - vm, - bhyveMonitorRelease); - if (mon->watch < 0) { + if (!bhyveMonitorRegister(mon)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to register monitor events")); goto cleanup; @@ -166,18 +206,30 @@ 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); + + bhyveMonitorUnregister(mon); + virObjectUnref(mon); } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list