From nobody Sun Feb 8 10:16:56 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=1582526816; cv=none; d=zohomail.com; s=zohoarc; b=SLyNH6Q580iHyP2rsXxchGIK+i31QgIn9ee3L3CY512LAZN+qBUH4jFPnAcbdNivTe7zKq1qadQ60JdDHvWsmK6dyxM13XA9il7uecVXBrnFB8TgsUe/A2T79TRtA6oNDx3zhn8u4l5egPIKwV3GfXJ8Hji+7psT0CVuIVl/Aqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582526816; 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=F73Rh1mKbzBa3EAjcp3zxFccRZBC31e0WP+dVw+SVxE=; b=BdzMg6byf/EcGggnxUSo90oGRHZYfPIoE7qlH2vIpryM5SnscL63LS3IxwN9FVSzMVJZTt78sy27x8V1cGNAWx6oBRL2ctT970cDG9qsD0uTIYyVPdWIGmMb4eOkKwKIrAfK4+IIFi8IYCqN3Oq5NhUUZEtL01kD6uOlypKMCRQ= 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 15825268165301011.8433092361939; Sun, 23 Feb 2020 22:46:56 -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-438-8nvDjnVJOTa4L011oaXpWQ-1; Mon, 24 Feb 2020 01:46:53 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A5DA800D50; Mon, 24 Feb 2020 06:46:47 +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 D02685C10D; Mon, 24 Feb 2020 06:46:46 +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 7D318860D9; Mon, 24 Feb 2020 06:46:41 +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 01O6kdLE025554 for ; Mon, 24 Feb 2020 01:46:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id BDC192026D68; Mon, 24 Feb 2020 06:46:39 +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 B645D2028CD4 for ; Mon, 24 Feb 2020 06:46:38 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.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 3245085A30F for ; Mon, 24 Feb 2020 06:46:38 +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-172-4L18YX8fMVqGnSpMCxQcCw-1; Mon, 24 Feb 2020 01:46:36 -0500 Received: by mail-yb1-f195.google.com with SMTP id b141so4170396ybg.10 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=1582526815; 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=F73Rh1mKbzBa3EAjcp3zxFccRZBC31e0WP+dVw+SVxE=; b=R+Sq+DOHYJaAuuYL5qCvdUGLvDyr6E4a1OfeLXgrXY1x1l7w4m1EVwr4it4NFQcfqs4u9x hmLlSGNk9HBDJoc3RLAzn0xr1uBPs5gqNn1QNbvKfjmz3Wml9t1Btlfp8ZhzwfkOSzEcB8 pFGvXvvju2Q3Otcys7wy3H994nVunn8= X-MC-Unique: 8nvDjnVJOTa4L011oaXpWQ-1 X-MC-Unique: 4L18YX8fMVqGnSpMCxQcCw-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=EaSKwksq/N+6pynW94MO1B2aEF7cl/RR9XrUnxQ9Jrw=; b=ffCcxFgaAVVgIuhQ0uLaHVfEJgBteOQ8ZhU4tBAsMALXmk/sI39VLDcsobiJcAsteV lUKD7Q0Mt24tCYxw6Ezrr0vJYgqryx7KCmXLvywfjpJXlFkvRPfhxqT8OZ3IhY/NjiIk 2rfSwvYmBI9e1Iu5AI9bbyBEQsA/FSpNEPx7mn82QHARDWd2oMmB3ec3eG3e4l5OWWGY iyrhVcMWjc6PbCWmuB88VX+KNamAGBlZyOH7EmbkIyfA8jwpM2wQbDJkBNzDlxKtaIV4 XD1cucqsmXEivlg0ESmiyNwhsgl34dqs7nut/Etzb4c0y57MBIyzN+Pw3rG8E0YXG0HI XOVw== X-Gm-Message-State: APjAAAVQ+ra5RSjMZQSb+3CovBuFchVQ7NzCxIqQRNNYH+tcRHQMOhIU AUvS6xaV9DVGgOEeHE4tOKb5mPKLsZiFu74VmN5ozavAh/CDCadEa+B3xytQMXEK2nIwR/ZTB00 SdRPRwJlfZDMx3RMIWASXFyVUmAPuK77xxHc6qrIS4DMW/oYqFOki45XXE32MvPBtW6s= X-Google-Smtp-Source: APXvYqwpMAQNdXoWdJKBaJWqW3ir3j5dhImE/FpmjqCgOXwzi2N08pcO76TZ7ct0hr2hvBodqHQG+A== X-Received: by 2002:a25:bb81:: with SMTP id y1mr7122280ybg.139.1582526795153; Sun, 23 Feb 2020 22:46:35 -0800 (PST) From: Ryan Moeller X-Google-Original-From: Ryan Moeller To: libvir-list@redhat.com Subject: [PATCH v1 05/12] bhyve: monitor: refactor register/unregister Date: Mon, 24 Feb 2020 01:46:17 -0500 Message-Id: <20200224064624.66649-6-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 01O6kdLE025554 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.15 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" Pull the code for registering and unregistering a bhyve monitor object into separate functions to improve code clarity. Signed-off-by: Ryan Moeller Reviewed-by: Daniel P. Berrang=C3=A9 --- src/bhyve/bhyve_monitor.c | 50 ++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/bhyve/bhyve_monitor.c b/src/bhyve/bhyve_monitor.c index 58d40e1f70..a1b1a21a6f 100644 --- a/src/bhyve/bhyve_monitor.c +++ b/src/bhyve/bhyve_monitor.c @@ -69,6 +69,37 @@ bhyveMonitorOnceInit(void) =20 VIR_ONCE_GLOBAL_INIT(bhyveMonitor); =20 +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) { @@ -166,17 +197,7 @@ bhyveMonitorOpenImpl(virDomainObjPtr vm, bhyveConnPtr = driver) goto cleanup; } =20 - 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); + if (!bhyveMonitorRegister(mon)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to register monitor events")); goto cleanup; @@ -209,11 +230,6 @@ bhyveMonitorClose(bhyveMonitorPtr mon) =20 VIR_DEBUG("cleaning up bhyveMonitor %p", mon); =20 - if (mon->watch < 0) - return; - - virEventRemoveHandle(mon->watch); - mon->watch =3D -1; - + bhyveMonitorUnregister(mon); virObjectUnref(mon); } --=20 2.24.1