From nobody Mon Feb 9 09:28:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652716301; cv=none; d=zohomail.com; s=zohoarc; b=GMR9Yc2z1+dnDq9Le4tIPxMtl4I+0rZ18ZMjBhxTa0fT6U3NB0gdNs66WBZeKM9P0P5vnxVQX0jA4eKMhCU+gxOQKJLbxJ+OpmyZqukqTefHSMlk71l486oF6sHg7HtpfqWXkk6u7XUtU41oVPyJp1qK7zVDZCr6xLVWkKPS+RY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652716301; 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=nulmPiJJ4wS2cAb95cLBylaVTvWdupYqg0C6gunjL44=; b=SJQNpnVoHfpXr6nlIMHhHjIgWwY9MwnYbL2l18ER1Psy6i+AiZ6VW8HtLvIJ7hRklyeY+nnsPPMrPj86YOIXEUCXsVaiQpjH8Kgeg4UD5Jy/29uK1gtnwFsjIt07lgE0aH95SE8lqe0fIs0f3OQ5FaECkPwQmtQtJnCr2oKyt0E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1652716301001534.6627248064821; Mon, 16 May 2022 08:51:41 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-497-1KOHeVtHNO-rKxFflfsJpw-1; Mon, 16 May 2022 11:51:37 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 606FF811E78; Mon, 16 May 2022 15:51:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D92F492C14; Mon, 16 May 2022 15:51:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2B3C11947054; Mon, 16 May 2022 15:51:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 613191947072 for ; Mon, 16 May 2022 15:51:32 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3EC161541C42; Mon, 16 May 2022 15:51:32 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B8801541C40 for ; Mon, 16 May 2022 15:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652716300; 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=nulmPiJJ4wS2cAb95cLBylaVTvWdupYqg0C6gunjL44=; b=AEp9UFeLsRx/Vy+udYvPugmgVo2xZiDz89zwWWqKwkPpOVWi1UyFDLhotz2KEy+KQwXQ8q RfIlDInub+YhHUBn4HSCtabr9Y8ynWwXnm2cP/+NfN+39Rih0LwKs/MaHxV3MnLHSBPMDR aJeAUKuGb77Liu73MnU4IJW/ctJBh18= X-MC-Unique: 1KOHeVtHNO-rKxFflfsJpw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/3] qemu: EVENTHANDLERS.txt: Move to kbase and rSTisze Date: Mon, 16 May 2022 17:51:26 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652716301538100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- docs/kbase/index.rst | 3 ++ docs/kbase/internals/meson.build | 1 + .../kbase/internals/qemu-event-handlers.rst | 44 ++++++++++--------- 3 files changed, 28 insertions(+), 20 deletions(-) rename src/qemu/EVENTHANDLERS.txt =3D> docs/kbase/internals/qemu-event-han= dlers.rst (64%) diff --git a/docs/kbase/index.rst b/docs/kbase/index.rst index d0f2167be8..8b710db85a 100644 --- a/docs/kbase/index.rst +++ b/docs/kbase/index.rst @@ -107,3 +107,6 @@ Internals `QEMU migration internals `__ Description of migration phases in the ``v2`` and ``v3`` migration prot= ocol. + +`QEMU monitor event handling `__ + Brief outline how events emitted by qemu on the monitor are handlded. diff --git a/docs/kbase/internals/meson.build b/docs/kbase/internals/meson.= build index 4f7b223786..a16d5a290b 100644 --- a/docs/kbase/internals/meson.build +++ b/docs/kbase/internals/meson.build @@ -5,6 +5,7 @@ docs_kbase_internals_files =3D [ 'locking', 'migration', 'overview', + 'qemu-event-handlers', 'qemu-migration', 'qemu-threads', 'rpc', diff --git a/src/qemu/EVENTHANDLERS.txt b/docs/kbase/internals/qemu-event-h= andlers.rst similarity index 64% rename from src/qemu/EVENTHANDLERS.txt rename to docs/kbase/internals/qemu-event-handlers.rst index 39094d793e..3589c4c48c 100644 --- a/src/qemu/EVENTHANDLERS.txt +++ b/docs/kbase/internals/qemu-event-handlers.rst @@ -1,10 +1,14 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +QEMU event handlers +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + This is a short description of how an example qemu event can be used to trigger handler code that is called from the context of a worker thread, rather than directly from the event thread (which should itself never block, and can't do things like send qemu monitor commands, etc). -In this case (the NIC_RX_FILTER_CHANGED event) the event is handled by +In this case (the ``NIC_RX_FILTER_CHANGED`` event) the event is handled by calling a qemu monitor command to get the current RX filter state, then executing ioctls/sending netlink messages on the host in response to changes in that filter state. This event is *not* propagated to the @@ -14,39 +18,39 @@ to the end of this document, please do!). Hopefully this narration will be helpful when adding handlers for other qemu events in the future. ----------------------------------------------------- +QEMU monitor events +------------------- Any event emitted by qemu is received by -qemu_monitor_json.c:qemuMonitorJSONIOProcessEvent(). It looks up the -event by name in the table eventHandlers (in the same file), which +``qemu_monitor_json.c:qemuMonitorJSONIOProcessEvent()``. It looks up the +event by name in the table ``eventHandlers`` (in the same file), which should have an entry like this for each event that libvirt -understands: +understands:: { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, }, - NB: This table is searched with bsearch, so it *must* be - alphabetically sorted. +NB: This table is searched with bsearch, so it *must* be alphabetically so= rted. -qemuMonitorJSONIOProcessEvent calls the function listed in -eventHandlers, e.g.: +``qemuMonitorJSONIOProcessEvent`` calls the function listed in +``eventHandlers``, e.g.:: qemu_monitor_json.c:qemuMonitorJSONHandleNicRxFilterChanged() which extracts any required data from the JSON ("name" in this case), -and calls: +and calls:: qemu_monitor.c:qemuMonitorEmitNicRxFilterChanged() -which uses QEMU_MONITOR_CALLBACK() to call -mon->cb->domainNicRxFilterChanged(). domainNicRxFilterChanged is one -in a list of function pointers in qemu_process.c:monitorCallbacks. For -our example, it has been set to: +which uses ``QEMU_MONITOR_CALLBACK()`` to call +``mon->cb->domainNicRxFilterChanged()``. ``domainNicRxFilterChanged`` is o= ne +in a list of function pointers in ``qemu_process.c:monitorCallbacks``. For +our example, it has been set to:: qemuProcessHandleNicRxFilterChanged() -This function allocates a qemuProcessEvent object, and queues an event -named QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED (you'll want to add an -enum to qemu_domain.h:qemuProcessEventType for your event) for a +This function allocates a ``qemuProcessEvent`` object, and queues an event +named ``QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED`` (you'll want to add an +enum to ``qemu_domain.h:qemuProcessEventType`` for your event) for a worker thread to handle. (Everything up to this point has happened in the context of the thread @@ -56,17 +60,17 @@ monitor. Everything after this is handled in the contex= t of a worker thread, so it has more freedom to make qemu monitor calls and blocking system calls on the host.) -When the worker thread gets the event, it calls +When the worker thread gets the event, it calls:: qemuProcessEventHandler() which switches on the eventType (in our example, -QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED) and decides to call: +``QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED``) and decides to call:: processNicRxFilterChangedEvent() and *that* is where the actual work will be done (and any -event-specific memory allocated during qemuProcessHandleXXX() will be +event-specific memory allocated during ``qemuProcessHandleXXX()`` will be freed). Note that this function must do proper refcounting of the domain object, and assure that the domain is still active prior to performing any operations - it is possible that the domain could have --=20 2.35.3