From nobody Sat Nov 23 12:43:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 171629334759140.163964397362065; Tue, 21 May 2024 05:09:07 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 430561B85; Tue, 21 May 2024 08:09:06 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 87D621A18; Tue, 21 May 2024 08:07:00 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E682819C1; Tue, 21 May 2024 08:06:56 -0400 (EDT) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 3D67419A8 for ; Tue, 21 May 2024 08:06:55 -0400 (EDT) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1ee0132a6f3so631215ad.0 for ; Tue, 21 May 2024 05:06:55 -0700 (PDT) Received: from localhost.localdomain ([49.47.193.102]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f309415d97sm21637935ad.28.2024.05.21.05.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 05:06:53 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716293214; x=1716898014; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fQRmfIgDCM1euoP+jBzE3LfS1oxjJK+JGs0BJ0uiOAA=; b=a/o1QKnQ7OaHK/1SwWs7JANDv0RyIfMrQ6xGVdn55wrOcw0QlYNx3aah2tVcNB/xWF SL/ntFTVQksF89wGVLakV2uzwBmDjXNuBOweVbqLLUHeKkb05FxYuwMa/bujpAlL4ujm DPBnBntQDMUMNmAKsw7pn+KofZ5fm7noT76s0gnwxEK4x0A0rVc5hhweI4nDje0RGQ8+ Qil+i1SflWe0HyDHoJ9FgUUvIttsS1DpyfVstpirIuZuWBtPPUVdFvDEjzPW1AQFZolk 5W0fjlfDGwNo9s9K9icgC7z3YFNIfjZII10AOO0Oq2jvTUb1ClVck6qOLyfRJkd1Ndgf r8VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716293214; x=1716898014; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fQRmfIgDCM1euoP+jBzE3LfS1oxjJK+JGs0BJ0uiOAA=; b=MZLd9G19WDiqxCs/qRE3lwoZJXHiFuam4j4FbKvep0dQHoJQOhuW55iA/QcVMA2AeP V4K/zhEcL5r7SccLp9HDxHAOlWSs2AMELJmw4OQqRPOzPMfwzf6Wpp2ESigfrGWy/Dui x9dtNcDPkr+4XVhHyWiuhuCsJJK45fCytStC+VaJC/ctQXFD1R6MW0BuhmxbO/ZLUmrK px9D5yffZZRSJcQzCyQJpvsDemyiYVZZ67LmxBiMJRUGl5ANWwFX48ms2gMgFqhHjGqO goLwFg1dIzsNhbA/W2qsXSVqAwtwqMTj7xM4LgjrbQVLym2NO5nEn/nnae8NURZYpiG8 U3ZQ== X-Gm-Message-State: AOJu0YzKpnnGX8N0cdrUlUDeyh2vHOR7YKgnrgXf46MTC9w8CPJMhHgG JyK0SSjbs/48aIwdZeoUqK91hAy6rXNADkGq/SZBkHtn346gxiGOetyO9g== X-Google-Smtp-Source: AGHT+IGxRJD8rOJ7cIKq+gWakvbEn8DPQkwU48NwLJsD4bKPT5I1/ODw+dB0roQGhApsKPWtuUmKsg== X-Received: by 2002:a17:902:f68b:b0:1f3:33b:ff08 with SMTP id d9443c01a7336-1f3033c0483mr48160965ad.58.1716293213561; Tue, 21 May 2024 05:06:53 -0700 (PDT) From: Rayhan Faizel To: devel@lists.libvirt.org Subject: [PATCH] qemu: Optimize monitor event name lookup with hash tables Date: Tue, 21 May 2024 17:36:48 +0530 Message-Id: <20240521120648.610648-1-rayhan.faizel@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: PIPS5RVOYVYMOHEWQH6EHXITLCFPCKUK X-Message-ID-Hash: PIPS5RVOYVYMOHEWQH6EHXITLCFPCKUK X-MailFrom: rayhan.faizel@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Rayhan Faizel X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1716293349578100001 Content-Type: text/plain; charset="utf-8" Currently, monitor event names are looked up using binary search which has O(log(n)) time complexity. This can be optimized even further with a compile-time static hash table generated by the gperf tool. As gperf ensures perfect hashing, lookup times are guaranteed to be O(1). This patch also makes gperf a requirement for compiling libvirt if the QEMU driver is enabled. Signed-off-by: Rayhan Faizel --- docs/kbase/internals/qemu-event-handlers.rst | 13 +- meson.build | 2 + src/qemu/meson.build | 9 + src/qemu/qemu_monitor_event.gperf | 68 ++++++++ src/qemu/qemu_monitor_json.c | 171 +++++-------------- src/qemu/qemu_monitor_json.h | 45 +++++ 6 files changed, 170 insertions(+), 138 deletions(-) create mode 100644 src/qemu/qemu_monitor_event.gperf diff --git a/docs/kbase/internals/qemu-event-handlers.rst b/docs/kbase/inte= rnals/qemu-event-handlers.rst index 3589c4c48c..5ec11e28bd 100644 --- a/docs/kbase/internals/qemu-event-handlers.rst +++ b/docs/kbase/internals/qemu-event-handlers.rst @@ -23,16 +23,15 @@ QEMU monitor events =20 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 -should have an entry like this for each event that libvirt -understands:: +event by name from a hash-table, generated at compile-time by ``gperf`` +based on a list of entries defined in ``qemu_monitor_event.gperf``. +``qemu_monitor_event.gperf`` should should have an entry like this +for each event that libvirt understands:: =20 - { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, }, - -NB: This table is searched with bsearch, so it *must* be alphabetically so= rted. + "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged =20 ``qemuMonitorJSONIOProcessEvent`` calls the function listed in -``eventHandlers``, e.g.:: +``qemu_monitor_event.gperf``, e.g.:: =20 qemu_monitor_json.c:qemuMonitorJSONHandleNicRxFilterChanged() =20 diff --git a/meson.build b/meson.build index e8b0094b91..03f1f0d56d 100644 --- a/meson.build +++ b/meson.build @@ -1708,6 +1708,8 @@ if not get_option('driver_qemu').disabled() qemu_slirp_path =3D '/usr/bin/slirp-helper' endif conf.set_quoted('QEMU_SLIRP_HELPER', qemu_slirp_path) + + gperf_prog =3D find_program('gperf') endif endif =20 diff --git a/src/qemu/meson.build b/src/qemu/meson.build index 907893d431..2440476a7b 100644 --- a/src/qemu/meson.build +++ b/src/qemu/meson.build @@ -88,11 +88,20 @@ qemu_shim_sources =3D files( 'qemu_shim.c', ) =20 +qemu_driver_gperf_sources =3D [] + +qemu_driver_gperf_sources +=3D custom_target( + 'qemu_monitor_event.c', + input : 'qemu_monitor_event.gperf', + output : 'qemu_monitor_event.c', + command : [gperf_prog, '@INPUT@', '--output-file', '@OUTPUT@']) + if conf.has('WITH_QEMU') qemu_driver_impl =3D static_library( 'virt_driver_qemu_impl', [ qemu_driver_sources, + qemu_driver_gperf_sources, qemu_dtrace_gen_headers, ], dependencies: [ diff --git a/src/qemu/qemu_monitor_event.gperf b/src/qemu/qemu_monitor_even= t.gperf new file mode 100644 index 0000000000..de2f958b9e --- /dev/null +++ b/src/qemu/qemu_monitor_event.gperf @@ -0,0 +1,68 @@ +/* + * qemu_monitor_event.gperf: QEMU Monitor Event Lookup Table + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +%{ +#include "qemu_monitor_json.h" +%} +qemuEventHandler; +%null_strings +%define initializer-suffix ,NULL +%language=3DANSI-C +%define slot-name type +%define lookup-function-name qemu_monitor_event_lookup +%define hash-function-name qemu_monitor_event_hash +%readonly-tables +%omit-struct-type +%struct-type +%% +"ACPI_DEVICE_OST", qemuMonitorJSONHandleAcpiOstInfo +"BALLOON_CHANGE", qemuMonitorJSONHandleBalloonChange +"BLOCK_IO_ERROR", qemuMonitorJSONHandleIOError +"BLOCK_WRITE_THRESHOLD", qemuMonitorJSONHandleBlockThreshold +"DEVICE_DELETED", qemuMonitorJSONHandleDeviceDeleted +"DEVICE_TRAY_MOVED", qemuMonitorJSONHandleTrayChange +"DEVICE_UNPLUG_GUEST_ERROR", qemuMonitorJSONHandleDeviceUnplugErr +"DUMP_COMPLETED", qemuMonitorJSONHandleDumpCompleted +"GUEST_CRASHLOADED", qemuMonitorJSONHandleGuestCrashloaded +"GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic +"JOB_STATUS_CHANGE", qemuMonitorJSONHandleJobStatusChange +"MEMORY_DEVICE_SIZE_CHANGE", qemuMonitorJSONHandleMemoryDeviceSizeChange +"MEMORY_FAILURE", qemuMonitorJSONHandleMemoryFailure +"MIGRATION", qemuMonitorJSONHandleMigrationStatus +"MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass +"NETDEV_STREAM_DISCONNECTED", qemuMonitorJSONHandleNetdevStreamDisconnected +"NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged +"PR_MANAGER_STATUS_CHANGED", qemuMonitorJSONHandlePRManagerStatusChanged +"RDMA_GID_STATUS_CHANGED", qemuMonitorJSONHandleRdmaGidStatusChanged +"RESET", qemuMonitorJSONHandleReset +"RESUME", qemuMonitorJSONHandleResume +"RTC_CHANGE", qemuMonitorJSONHandleRTCChange +"SHUTDOWN", qemuMonitorJSONHandleShutdown +"SPICE_CONNECTED", qemuMonitorJSONHandleSPICEConnect +"SPICE_DISCONNECTED", qemuMonitorJSONHandleSPICEDisconnect +"SPICE_INITIALIZED", qemuMonitorJSONHandleSPICEInitialize +"SPICE_MIGRATE_COMPLETED", qemuMonitorJSONHandleSpiceMigrated +"STOP", qemuMonitorJSONHandleStop +"SUSPEND", qemuMonitorJSONHandlePMSuspend +"SUSPEND_DISK", qemuMonitorJSONHandlePMSuspendDisk +"VNC_CONNECTED", qemuMonitorJSONHandleVNCConnect +"VNC_DISCONNECTED", qemuMonitorJSONHandleVNCDisconnect +"VNC_INITIALIZED", qemuMonitorJSONHandleVNCInitialize +"VSERPORT_CHANGE", qemuMonitorJSONHandleSerialChange +"WAKEUP", qemuMonitorJSONHandlePMWakeup +"WATCHDOG", qemuMonitorJSONHandleWatchdog diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index eb84a3d938..93df4490ad 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -49,102 +49,12 @@ VIR_LOG_INIT("qemu.qemu_monitor_json"); =20 #define LINE_ENDING "\r\n" =20 -static void qemuMonitorJSONHandleShutdown(qemuMonitor *mon, virJSONValue *= data); -static void qemuMonitorJSONHandleReset(qemuMonitor *mon, virJSONValue *dat= a); -static void qemuMonitorJSONHandleStop(qemuMonitor *mon, virJSONValue *data= ); -static void qemuMonitorJSONHandleResume(qemuMonitor *mon, virJSONValue *da= ta); -static void qemuMonitorJSONHandleRTCChange(qemuMonitor *mon, virJSONValue = *data); -static void qemuMonitorJSONHandleWatchdog(qemuMonitor *mon, virJSONValue *= data); -static void qemuMonitorJSONHandleIOError(qemuMonitor *mon, virJSONValue *d= ata); -static void qemuMonitorJSONHandleVNCConnect(qemuMonitor *mon, virJSONValue= *data); -static void qemuMonitorJSONHandleVNCInitialize(qemuMonitor *mon, virJSONVa= lue *data); -static void qemuMonitorJSONHandleVNCDisconnect(qemuMonitor *mon, virJSONVa= lue *data); -static void qemuMonitorJSONHandleSPICEConnect(qemuMonitor *mon, virJSONVal= ue *data); -static void qemuMonitorJSONHandleSPICEInitialize(qemuMonitor *mon, virJSON= Value *data); -static void qemuMonitorJSONHandleSPICEDisconnect(qemuMonitor *mon, virJSON= Value *data); -static void qemuMonitorJSONHandleTrayChange(qemuMonitor *mon, virJSONValue= *data); -static void qemuMonitorJSONHandlePMWakeup(qemuMonitor *mon, virJSONValue *= data); -static void qemuMonitorJSONHandlePMSuspend(qemuMonitor *mon, virJSONValue = *data); -static void qemuMonitorJSONHandleJobStatusChange(qemuMonitor *mon, virJSON= Value *data); -static void qemuMonitorJSONHandleBalloonChange(qemuMonitor *mon, virJSONVa= lue *data); -static void qemuMonitorJSONHandlePMSuspendDisk(qemuMonitor *mon, virJSONVa= lue *data); -static void qemuMonitorJSONHandleGuestCrashloaded(qemuMonitor *mon, virJSO= NValue *data); -static void qemuMonitorJSONHandleGuestPanic(qemuMonitor *mon, virJSONValue= *data); -static void qemuMonitorJSONHandleDeviceDeleted(qemuMonitor *mon, virJSONVa= lue *data); -static void qemuMonitorJSONHandleNicRxFilterChanged(qemuMonitor *mon, virJ= SONValue *data); -static void qemuMonitorJSONHandleSerialChange(qemuMonitor *mon, virJSONVal= ue *data); -static void qemuMonitorJSONHandleSpiceMigrated(qemuMonitor *mon, virJSONVa= lue *data); -static void qemuMonitorJSONHandleMigrationStatus(qemuMonitor *mon, virJSON= Value *data); -static void qemuMonitorJSONHandleMigrationPass(qemuMonitor *mon, virJSONVa= lue *data); -static void qemuMonitorJSONHandleAcpiOstInfo(qemuMonitor *mon, virJSONValu= e *data); -static void qemuMonitorJSONHandleBlockThreshold(qemuMonitor *mon, virJSONV= alue *data); -static void qemuMonitorJSONHandleDumpCompleted(qemuMonitor *mon, virJSONVa= lue *data); -static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitor *mon, = virJSONValue *data); -static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitor *mon, vi= rJSONValue *data); -static void qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, virJSONVa= lue *data); -static void qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, = virJSONValue *data); -static void qemuMonitorJSONHandleDeviceUnplugErr(qemuMonitor *mon, virJSON= Value *data); -static void qemuMonitorJSONHandleNetdevStreamDisconnected(qemuMonitor *mon= , virJSONValue *data); - -typedef struct { - const char *type; - void (*handler)(qemuMonitor *mon, virJSONValue *data); -} qemuEventHandler; - -static qemuEventHandler eventHandlers[] =3D { - { "ACPI_DEVICE_OST", qemuMonitorJSONHandleAcpiOstInfo, }, - { "BALLOON_CHANGE", qemuMonitorJSONHandleBalloonChange, }, - { "BLOCK_IO_ERROR", qemuMonitorJSONHandleIOError, }, - { "BLOCK_WRITE_THRESHOLD", qemuMonitorJSONHandleBlockThreshold, }, - { "DEVICE_DELETED", qemuMonitorJSONHandleDeviceDeleted, }, - { "DEVICE_TRAY_MOVED", qemuMonitorJSONHandleTrayChange, }, - { "DEVICE_UNPLUG_GUEST_ERROR", qemuMonitorJSONHandleDeviceUnplugErr, }, - { "DUMP_COMPLETED", qemuMonitorJSONHandleDumpCompleted, }, - { "GUEST_CRASHLOADED", qemuMonitorJSONHandleGuestCrashloaded, }, - { "GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic, }, - { "JOB_STATUS_CHANGE", qemuMonitorJSONHandleJobStatusChange, }, - { "MEMORY_DEVICE_SIZE_CHANGE", qemuMonitorJSONHandleMemoryDeviceSizeCh= ange, }, - { "MEMORY_FAILURE", qemuMonitorJSONHandleMemoryFailure, }, - { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, }, - { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, }, - { "NETDEV_STREAM_DISCONNECTED", qemuMonitorJSONHandleNetdevStreamDisco= nnected, }, - { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, }, - { "PR_MANAGER_STATUS_CHANGED", qemuMonitorJSONHandlePRManagerStatusCha= nged, }, - { "RDMA_GID_STATUS_CHANGED", qemuMonitorJSONHandleRdmaGidStatusChanged= , }, - { "RESET", qemuMonitorJSONHandleReset, }, - { "RESUME", qemuMonitorJSONHandleResume, }, - { "RTC_CHANGE", qemuMonitorJSONHandleRTCChange, }, - { "SHUTDOWN", qemuMonitorJSONHandleShutdown, }, - { "SPICE_CONNECTED", qemuMonitorJSONHandleSPICEConnect, }, - { "SPICE_DISCONNECTED", qemuMonitorJSONHandleSPICEDisconnect, }, - { "SPICE_INITIALIZED", qemuMonitorJSONHandleSPICEInitialize, }, - { "SPICE_MIGRATE_COMPLETED", qemuMonitorJSONHandleSpiceMigrated, }, - { "STOP", qemuMonitorJSONHandleStop, }, - { "SUSPEND", qemuMonitorJSONHandlePMSuspend, }, - { "SUSPEND_DISK", qemuMonitorJSONHandlePMSuspendDisk, }, - { "VNC_CONNECTED", qemuMonitorJSONHandleVNCConnect, }, - { "VNC_DISCONNECTED", qemuMonitorJSONHandleVNCDisconnect, }, - { "VNC_INITIALIZED", qemuMonitorJSONHandleVNCInitialize, }, - { "VSERPORT_CHANGE", qemuMonitorJSONHandleSerialChange, }, - { "WAKEUP", qemuMonitorJSONHandlePMWakeup, }, - { "WATCHDOG", qemuMonitorJSONHandleWatchdog, }, - /* We use bsearch, so keep this list sorted. */ -}; - -static int -qemuMonitorEventCompare(const void *key, const void *elt) -{ - const char *type =3D key; - const qemuEventHandler *handler =3D elt; - return strcmp(type, handler->type); -} - static int qemuMonitorJSONIOProcessEvent(qemuMonitor *mon, virJSONValue *obj) { const char *type; - qemuEventHandler *handler; + const qemuEventHandler *handler; virJSONValue *data; g_autofree char *details =3D NULL; virJSONValue *timestamp; @@ -171,8 +81,7 @@ qemuMonitorJSONIOProcessEvent(qemuMonitor *mon, } qemuMonitorEmitEvent(mon, type, seconds, micros, details); =20 - handler =3D bsearch(type, eventHandlers, G_N_ELEMENTS(eventHandlers), - sizeof(eventHandlers[0]), qemuMonitorEventCompare); + handler =3D qemu_monitor_event_lookup(type, strlen(type)); if (handler) { VIR_DEBUG("handle %s handler=3D%p data=3D%p", type, handler->handler, data); @@ -543,7 +452,7 @@ qemuMonitorJSONMakeCommand(const char *cmdname, } =20 =20 -static void qemuMonitorJSONHandleShutdown(qemuMonitor *mon, virJSONValue *= data) +void qemuMonitorJSONHandleShutdown(qemuMonitor *mon, virJSONValue *data) { bool guest =3D false; virTristateBool guest_initiated =3D VIR_TRISTATE_BOOL_ABSENT; @@ -554,17 +463,17 @@ static void qemuMonitorJSONHandleShutdown(qemuMonitor= *mon, virJSONValue *data) qemuMonitorEmitShutdown(mon, guest_initiated); } =20 -static void qemuMonitorJSONHandleReset(qemuMonitor *mon, virJSONValue *dat= a G_GNUC_UNUSED) +void qemuMonitorJSONHandleReset(qemuMonitor *mon, virJSONValue *data G_GNU= C_UNUSED) { qemuMonitorEmitReset(mon); } =20 -static void qemuMonitorJSONHandleStop(qemuMonitor *mon, virJSONValue *data= G_GNUC_UNUSED) +void qemuMonitorJSONHandleStop(qemuMonitor *mon, virJSONValue *data G_GNUC= _UNUSED) { qemuMonitorEmitStop(mon); } =20 -static void qemuMonitorJSONHandleResume(qemuMonitor *mon, virJSONValue *da= ta G_GNUC_UNUSED) +void qemuMonitorJSONHandleResume(qemuMonitor *mon, virJSONValue *data G_GN= UC_UNUSED) { qemuMonitorEmitResume(mon); } @@ -635,7 +544,7 @@ qemuMonitorJSONGuestPanicExtractInfo(virJSONValue *data) } =20 =20 -static void +void qemuMonitorJSONHandleGuestPanic(qemuMonitor *mon, virJSONValue *data) { @@ -649,7 +558,7 @@ qemuMonitorJSONHandleGuestPanic(qemuMonitor *mon, } =20 =20 -static void qemuMonitorJSONHandleRTCChange(qemuMonitor *mon, virJSONValue = *data) +void qemuMonitorJSONHandleRTCChange(qemuMonitor *mon, virJSONValue *data) { long long offset =3D 0; if (virJSONValueObjectGetNumberLong(data, "offset", &offset) < 0) { @@ -665,7 +574,7 @@ VIR_ENUM_IMPL(qemuMonitorWatchdogAction, "none", "pause", "reset", "poweroff", "shutdown", "debug", "= inject-nmi", ); =20 -static void qemuMonitorJSONHandleWatchdog(qemuMonitor *mon, virJSONValue *= data) +void qemuMonitorJSONHandleWatchdog(qemuMonitor *mon, virJSONValue *data) { const char *action; int actionID; @@ -689,7 +598,7 @@ VIR_ENUM_IMPL(qemuMonitorIOErrorAction, ); =20 =20 -static void +void qemuMonitorJSONHandleIOError(qemuMonitor *mon, virJSONValue *data) { const char *device; @@ -802,19 +711,19 @@ qemuMonitorJSONHandleGraphicsVNC(qemuMonitor *mon, authScheme, x509dname, saslUsername); } =20 -static void qemuMonitorJSONHandleVNCConnect(qemuMonitor *mon, virJSONValue= *data) +void qemuMonitorJSONHandleVNCConnect(qemuMonitor *mon, virJSONValue *data) { qemuMonitorJSONHandleGraphicsVNC(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_= CONNECT); } =20 =20 -static void qemuMonitorJSONHandleVNCInitialize(qemuMonitor *mon, virJSONVa= lue *data) +void qemuMonitorJSONHandleVNCInitialize(qemuMonitor *mon, virJSONValue *da= ta) { qemuMonitorJSONHandleGraphicsVNC(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_= INITIALIZE); } =20 =20 -static void qemuMonitorJSONHandleVNCDisconnect(qemuMonitor *mon, virJSONVa= lue *data) +void qemuMonitorJSONHandleVNCDisconnect(qemuMonitor *mon, virJSONValue *da= ta) { qemuMonitorJSONHandleGraphicsVNC(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_= DISCONNECT); } @@ -884,24 +793,24 @@ qemuMonitorJSONHandleGraphicsSPICE(qemuMonitor *mon, } =20 =20 -static void qemuMonitorJSONHandleSPICEConnect(qemuMonitor *mon, virJSONVal= ue *data) +void qemuMonitorJSONHandleSPICEConnect(qemuMonitor *mon, virJSONValue *dat= a) { qemuMonitorJSONHandleGraphicsSPICE(mon, data, VIR_DOMAIN_EVENT_GRAPHIC= S_CONNECT); } =20 =20 -static void qemuMonitorJSONHandleSPICEInitialize(qemuMonitor *mon, virJSON= Value *data) +void qemuMonitorJSONHandleSPICEInitialize(qemuMonitor *mon, virJSONValue *= data) { qemuMonitorJSONHandleGraphicsSPICE(mon, data, VIR_DOMAIN_EVENT_GRAPHIC= S_INITIALIZE); } =20 =20 -static void qemuMonitorJSONHandleSPICEDisconnect(qemuMonitor *mon, virJSON= Value *data) +void qemuMonitorJSONHandleSPICEDisconnect(qemuMonitor *mon, virJSONValue *= data) { qemuMonitorJSONHandleGraphicsSPICE(mon, data, VIR_DOMAIN_EVENT_GRAPHIC= S_DISCONNECT); } =20 -static void +void qemuMonitorJSONHandleJobStatusChange(qemuMonitor *mon, virJSONValue *data) { @@ -924,7 +833,7 @@ qemuMonitorJSONHandleJobStatusChange(qemuMonitor *mon, } =20 =20 -static void +void qemuMonitorJSONHandleTrayChange(qemuMonitor *mon, virJSONValue *data) { @@ -955,14 +864,14 @@ qemuMonitorJSONHandleTrayChange(qemuMonitor *mon, qemuMonitorEmitTrayChange(mon, devAlias, devid, reason); } =20 -static void +void qemuMonitorJSONHandlePMWakeup(qemuMonitor *mon, virJSONValue *data G_GNUC_UNUSED) { qemuMonitorEmitPMWakeup(mon); } =20 -static void +void qemuMonitorJSONHandlePMSuspend(qemuMonitor *mon, virJSONValue *data G_GNUC_UNUSED) { @@ -970,7 +879,7 @@ qemuMonitorJSONHandlePMSuspend(qemuMonitor *mon, } =20 =20 -static void +void qemuMonitorJSONHandleBalloonChange(qemuMonitor *mon, virJSONValue *data) { @@ -983,14 +892,14 @@ qemuMonitorJSONHandleBalloonChange(qemuMonitor *mon, qemuMonitorEmitBalloonChange(mon, actual); } =20 -static void +void qemuMonitorJSONHandlePMSuspendDisk(qemuMonitor *mon, virJSONValue *data G_GNUC_UNUSED) { qemuMonitorEmitPMSuspendDisk(mon); } =20 -static void +void qemuMonitorJSONHandleDeviceDeleted(qemuMonitor *mon, virJSONValue *data) { const char *device; @@ -1004,7 +913,7 @@ qemuMonitorJSONHandleDeviceDeleted(qemuMonitor *mon, v= irJSONValue *data) } =20 =20 -static void +void qemuMonitorJSONHandleDeviceUnplugErr(qemuMonitor *mon, virJSONValue *data) { const char *device; @@ -1021,7 +930,7 @@ qemuMonitorJSONHandleDeviceUnplugErr(qemuMonitor *mon,= virJSONValue *data) } =20 =20 -static void +void qemuMonitorJSONHandleNetdevStreamDisconnected(qemuMonitor *mon, virJSONVal= ue *data) { const char *name; @@ -1035,7 +944,7 @@ qemuMonitorJSONHandleNetdevStreamDisconnected(qemuMoni= tor *mon, virJSONValue *da } =20 =20 -static void +void qemuMonitorJSONHandleNicRxFilterChanged(qemuMonitor *mon, virJSONValue *da= ta) { const char *name; @@ -1049,7 +958,7 @@ qemuMonitorJSONHandleNicRxFilterChanged(qemuMonitor *m= on, virJSONValue *data) } =20 =20 -static void +void qemuMonitorJSONHandleSerialChange(qemuMonitor *mon, virJSONValue *data) { @@ -1070,7 +979,7 @@ qemuMonitorJSONHandleSerialChange(qemuMonitor *mon, } =20 =20 -static void +void qemuMonitorJSONHandleSpiceMigrated(qemuMonitor *mon, virJSONValue *data G_GNUC_UNUSED) { @@ -1078,7 +987,7 @@ qemuMonitorJSONHandleSpiceMigrated(qemuMonitor *mon, } =20 =20 -static void +void qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, virJSONValue *data) { @@ -1100,7 +1009,7 @@ qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonit= or *mon, } =20 =20 -static void +void qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, virJSONValue *data) { @@ -1147,7 +1056,7 @@ qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, } =20 =20 -static void +void qemuMonitorJSONHandleMigrationStatus(qemuMonitor *mon, virJSONValue *data) { @@ -1168,7 +1077,7 @@ qemuMonitorJSONHandleMigrationStatus(qemuMonitor *mon, } =20 =20 -static void +void qemuMonitorJSONHandleMigrationPass(qemuMonitor *mon, virJSONValue *data) { @@ -1183,7 +1092,7 @@ qemuMonitorJSONHandleMigrationPass(qemuMonitor *mon, } =20 =20 -static void +void qemuMonitorJSONHandleAcpiOstInfo(qemuMonitor *mon, virJSONValue *data) { virJSONValue *info; @@ -1220,7 +1129,7 @@ qemuMonitorJSONHandleAcpiOstInfo(qemuMonitor *mon, vi= rJSONValue *data) } =20 =20 -static void +void qemuMonitorJSONHandleBlockThreshold(qemuMonitor *mon, virJSONValue *data) { const char *nodename; @@ -1280,7 +1189,7 @@ qemuMonitorJSONExtractDumpStats(virJSONValue *result, } =20 =20 -static void +void qemuMonitorJSONHandleDumpCompleted(qemuMonitor *mon, virJSONValue *data) { @@ -1302,8 +1211,8 @@ qemuMonitorJSONHandleDumpCompleted(qemuMonitor *mon, } =20 =20 -static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitor *mon, - virJSONValue *data) +void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitor *mon, + virJSONValue *data) { const char *name; bool connected; @@ -1323,8 +1232,8 @@ static void qemuMonitorJSONHandlePRManagerStatusChang= ed(qemuMonitor *mon, } =20 =20 -static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitor *mon, - virJSONValue *data) +void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitor *mon, + virJSONValue *data) { const char *netdev; bool gid_status; @@ -1357,7 +1266,7 @@ static void qemuMonitorJSONHandleRdmaGidStatusChanged= (qemuMonitor *mon, } =20 =20 -static void +void qemuMonitorJSONHandleGuestCrashloaded(qemuMonitor *mon, virJSONValue *data) { diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 9684660d86..5bd4b21b7d 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -27,6 +27,51 @@ #include "cpu/cpu.h" #include "util/virgic.h" =20 +typedef struct { + const char *type; + void (*handler)(qemuMonitor *mon, virJSONValue *data); +} qemuEventHandler; + +const qemuEventHandler * +qemu_monitor_event_lookup(const char *str, size_t len); + +void qemuMonitorJSONHandleShutdown(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleReset(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleStop(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleResume(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleRTCChange(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleWatchdog(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleIOError(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleVNCConnect(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleVNCInitialize(qemuMonitor *mon, virJSONValue *da= ta); +void qemuMonitorJSONHandleVNCDisconnect(qemuMonitor *mon, virJSONValue *da= ta); +void qemuMonitorJSONHandleSPICEConnect(qemuMonitor *mon, virJSONValue *dat= a); +void qemuMonitorJSONHandleSPICEInitialize(qemuMonitor *mon, virJSONValue *= data); +void qemuMonitorJSONHandleSPICEDisconnect(qemuMonitor *mon, virJSONValue *= data); +void qemuMonitorJSONHandleTrayChange(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandlePMWakeup(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandlePMSuspend(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleJobStatusChange(qemuMonitor *mon, virJSONValue *= data); +void qemuMonitorJSONHandleBalloonChange(qemuMonitor *mon, virJSONValue *da= ta); +void qemuMonitorJSONHandlePMSuspendDisk(qemuMonitor *mon, virJSONValue *da= ta); +void qemuMonitorJSONHandleGuestCrashloaded(qemuMonitor *mon, virJSONValue = *data); +void qemuMonitorJSONHandleGuestPanic(qemuMonitor *mon, virJSONValue *data); +void qemuMonitorJSONHandleDeviceDeleted(qemuMonitor *mon, virJSONValue *da= ta); +void qemuMonitorJSONHandleNicRxFilterChanged(qemuMonitor *mon, virJSONValu= e *data); +void qemuMonitorJSONHandleSerialChange(qemuMonitor *mon, virJSONValue *dat= a); +void qemuMonitorJSONHandleSpiceMigrated(qemuMonitor *mon, virJSONValue *da= ta); +void qemuMonitorJSONHandleMigrationStatus(qemuMonitor *mon, virJSONValue *= data); +void qemuMonitorJSONHandleMigrationPass(qemuMonitor *mon, virJSONValue *da= ta); +void qemuMonitorJSONHandleAcpiOstInfo(qemuMonitor *mon, virJSONValue *data= ); +void qemuMonitorJSONHandleBlockThreshold(qemuMonitor *mon, virJSONValue *d= ata); +void qemuMonitorJSONHandleDumpCompleted(qemuMonitor *mon, virJSONValue *da= ta); +void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitor *mon, virJSON= Value *data); +void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitor *mon, virJSONVa= lue *data); +void qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, virJSONValue *da= ta); +void qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, virJSON= Value *data); +void qemuMonitorJSONHandleDeviceUnplugErr(qemuMonitor *mon, virJSONValue *= data); +void qemuMonitorJSONHandleNetdevStreamDisconnected(qemuMonitor *mon, virJS= ONValue *data); + int qemuMonitorJSONIOProcessLine(qemuMonitor *mon, const char *line, --=20 2.34.1