From nobody Sun Apr 28 11:09:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1508866537118272.3391077793261; Tue, 24 Oct 2017 10:35:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3BFF272B6; Tue, 24 Oct 2017 17:35:34 +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 BFA505C8A1; Tue, 24 Oct 2017 17:35:34 +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 8AAF21804485; Tue, 24 Oct 2017 17:35:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9OHZFif024617 for ; Tue, 24 Oct 2017 13:35:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id E6E057DF63; Tue, 24 Oct 2017 17:35:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 177E518B9E; Tue, 24 Oct 2017 17:35:11 +0000 (UTC) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CD78601F; Tue, 24 Oct 2017 17:35:10 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id a8so20182045pfc.0; Tue, 24 Oct 2017 10:35:10 -0700 (PDT) Received: from ps-f25-dev.eng.nutanix.com ([205.209.132.2]) by smtp.gmail.com with ESMTPSA id k2sm1333236pff.126.2017.10.24.10.35.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Oct 2017 10:35:08 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E3BFF272B6 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E3BFF272B6 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E1peYVoL" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4CD78601F Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=saxenap.ltc@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4CD78601F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tOBriN2I4dUcFW5JhAGXqtbLKyYoXUZEni05FHc4MXQ=; b=E1peYVoLCx4mk8F/f8BpR8ZahJOnjfud1f1N27TT6890TY3h5hDWHPHhx3B/prL4+b Ygi1EsE4XHeKjZiCJCmzs7T+gkHHwivK4usK3zGcI25spgkA8iOxgrcILAUzrcA7rzXM q+GNHMmba3u4v/LaTYmDVKaxUGjNUcAmGETX1PDpHAPKBVP+8CQmrYZGWC+Aa2O/ED3h b5LPF6IPQDN4tlpfzwwQJXZGpS6kDltB2QIt90K+7+ibfnYpRMlVm5TIsoKLz0Tjrcyu Xre8xR3OIQRNlsnoLpqqyqqusKI0rMJi/Zp+QRSo7Ai0LFKE0LK8j6HPEnmC/0m3tINi yrog== 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; bh=tOBriN2I4dUcFW5JhAGXqtbLKyYoXUZEni05FHc4MXQ=; b=nJ50sauiWu0NSZP0roWiN8Cvk1y4M3g6oBAUfhjcA3f3eySyIKQkkztVkIB7w3/TBu FAbnZ1Zqn/Qcrq9WwbBohIWmhVgSqQLK11TdvNO7xzPSomn4Ae8M6crnK3WvTMVM76bn t7H2P5VBdDSzUKlxjzs4klauwp670fnsjejx3K00NuKs9LXU2Evy+yg9mxKtPuzIoKCd ZkPcyp+90VBdxyBEZE/bSfE2J2hXDuL25LMRUaaJVE+zegDOucLXne8j24tQxMvRwuu/ KaQqU/athJ5J4JYloPcuAAJG7ed9t2WM7yZDCK1ushRjySqvCzF4PskRMQqzjjG0niHW fVZg== X-Gm-Message-State: AMCzsaW51rc5bg1b80yEb/ntmLQNw3DGVmmNCh+eb3ZIskbZ2skR9xa9 dRIY5/kLIk43oa363TD5jbzvlw== X-Google-Smtp-Source: ABhQp+Sn3SSHmHuv09FEcNy4ipVVxdKJ34tNfcei0WBiQ9ZRC08FBQsI5GkASok1ex6Oic1+rsSw/g== X-Received: by 10.101.69.74 with SMTP id x10mr15389560pgr.294.1508866509406; Tue, 24 Oct 2017 10:35:09 -0700 (PDT) From: Prerna Saxena To: libvir-list@redhat.com Date: Tue, 24 Oct 2017 10:34:55 -0700 Message-Id: <20171024173501.18105-3-saxenap.ltc@gmail.com> In-Reply-To: <20171024173501.18105-1-saxenap.ltc@gmail.com> References: <20171024173501.18105-1-saxenap.ltc@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 24 Oct 2017 17:35:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 24 Oct 2017 17:35:10 +0000 (UTC) for IP:'209.85.192.193' DOMAIN:'mail-pf0-f193.google.com' HELO:'mail-pf0-f193.google.com' FROM:'saxenap.ltc@gmail.com' RCPT:'' X-RedHat-Spam-Score: -2.41 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.192.193 mail-pf0-f193.google.com 209.85.192.193 mail-pf0-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: --jdenemar@redhat.com, --pkrempa@redhat.com Subject: [libvirt] [[RFC] 2/8] QEMU Event handling: Introduce async event helpers in qemu_event.[ch] 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 24 Oct 2017 17:35:35 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" These contain basic functions for setting up event lists (global as well as per-VM). Also include methods for enqueuing and dequeuing events. Per-event metadata is also encoded herewith. Signed-off-by: Prerna Saxena --- src/Makefile.am | 1 + src/qemu/qemu_event.c | 75 +++++++++++++++++ src/qemu/qemu_event.h | 224 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 300 insertions(+) create mode 100644 src/qemu/qemu_event.c create mode 100644 src/qemu/qemu_event.h diff --git a/src/Makefile.am b/src/Makefile.am index b74856b..73a98ca 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -903,6 +903,7 @@ QEMU_DRIVER_SOURCES =3D \ qemu/qemu_domain.c qemu/qemu_domain.h \ qemu/qemu_domain_address.c qemu/qemu_domain_address.h \ qemu/qemu_cgroup.c qemu/qemu_cgroup.h \ + qemu/qemu_event.c qemu/qemu_event.h \ qemu/qemu_hostdev.c qemu/qemu_hostdev.h \ qemu/qemu_hotplug.c qemu/qemu_hotplug.h \ qemu/qemu_hotplugpriv.h \ diff --git a/src/qemu/qemu_event.c b/src/qemu/qemu_event.c new file mode 100644 index 0000000..e27ea0d --- /dev/null +++ b/src/qemu/qemu_event.c @@ -0,0 +1,75 @@ +/* + * qemu_event.c: + * optimize qemu async event handling. + * + * Copyright (C) 2017-2026 Nutanix, Inc. + * Copyright (C) 2017 Prerna Saxena + * + * 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 + * . + * + * Author: Prerna Saxena + */ + +#include "config.h" +#include "internal.h" +# include "qemu_monitor.h" +# include "qemu_conf.h" +# include "qemu_event.h" +#include "qemu_process.h" + +#include "virerror.h" +#include "viralloc.h" +#include "virlog.h" +#include "virobject.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_QEMU + +VIR_LOG_INIT("qemu.qemu_event"); + +VIR_ENUM_IMPL(qemuMonitorEvent, + QEMU_EVENT_LAST, + "ACPI Event", "Balloon Change", "Block IO Error", + "Block Job Event", + "Block Write Threshold", "Device Deleted", + "Device Tray Moved", "Graphics", "Guest Panicked", + "Migration", "Migration pass", + "Nic RX Filter Changed", "Powerdown", "Reset", "Resume", + "RTC Change", "Shutdown", "Stop", + "Suspend", "Suspend To Disk", + "Virtual Serial Port Change", + "Wakeup", "Watchdog"); + +virQemuEventList* virQemuEventListInit(void) +{ + virQemuEventList *ev_list; + if (VIR_ALLOC(ev_list) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Unable to allocate virQemuEventList"); + return NULL; + } + + if (virMutexInit(&ev_list->lock) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot initialize mutex")); + VIR_FREE(ev_list); + return NULL; + } + + ev_list->head =3D NULL; + ev_list->last =3D NULL; + + return ev_list; +} diff --git a/src/qemu/qemu_event.h b/src/qemu/qemu_event.h new file mode 100644 index 0000000..9781795 --- /dev/null +++ b/src/qemu/qemu_event.h @@ -0,0 +1,224 @@ +/* + * qemu_event.h: interaction with QEMU JSON monitor event layer + * Carve out improved interactions with qemu. + * + * Copyright (C) 2017-2026 Nutanix, Inc. + * Copyright (C) 2017 Prerna Saxena + * + * 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 + * . + * + * Author: Prerna Saxena + */ + + +#ifndef QEMU_EVENT_H +# define QEMU_EVENT_H + +# include "internal.h" +# include "virobject.h" + +typedef enum { + QEMU_EVENT_ACPI_OST, + QEMU_EVENT_BALLOON_CHANGE, + QEMU_EVENT_BLOCK_IO_ERROR, + QEMU_EVENT_BLOCK_JOB, + QEMU_EVENT_BLOCK_WRITE_THRESHOLD, + QEMU_EVENT_DEVICE_DELETED, + QEMU_EVENT_DEVICE_TRAY_MOVED, + QEMU_EVENT_GRAPHICS, + QEMU_EVENT_GUEST_PANICKED, + QEMU_EVENT_MIGRATION, + QEMU_EVENT_MIGRATION_PASS, + QEMU_EVENT_NIC_RX_FILTER_CHANGED, + QEMU_EVENT_POWERDOWN, + QEMU_EVENT_RESET, + QEMU_EVENT_RESUME, + QEMU_EVENT_RTC_CHANGE, + QEMU_EVENT_SHUTDOWN, + QEMU_EVENT_STOP, + QEMU_EVENT_SUSPEND, + QEMU_EVENT_SUSPEND_DISK, + QEMU_EVENT_SERIAL_CHANGE, + QEMU_EVENT_WAKEUP, + QEMU_EVENT_WATCHDOG, + + QEMU_EVENT_LAST, + +} qemuMonitorEventType; + +VIR_ENUM_DECL(qemuMonitorEvent); + +struct _qemuEvent; +typedef struct _qemuEvent * qemuEventPtr; + +struct qemuEventAcpiOstInfoData { + char *alias; + char *slotType; + char *slot; + unsigned int source; + unsigned int status; +}; + +struct qemuEventBalloonChangeData { + unsigned long long actual; +}; + +struct qemuEventIOErrorData { + char *device; + int action; + char *reason; +}; + +struct qemuEventBlockJobData { + int status; + char *device; + int type; +}; + +struct qemuEventBlockThresholdData { + char *nodename; + unsigned long long threshold; + unsigned long long excess; +}; + +struct qemuEventDeviceDeletedData { + char *device; +}; + +struct qemuEventTrayChangeData { + char *devAlias; + int reason; +}; + +struct qemuEventGuestPanicData { +}; + +struct qemuEventMigrationStatusData { + int status; +}; + +struct qemuEventMigrationPassData { + int pass; +}; + +struct qemuEventNicRxFilterChangeData { + char *devAlias; +}; + +struct qemuEventRTCChangeData { + long long offset; +}; + +struct qemuEventGraphicsData { + int phase; + int localFamilyID; + int remoteFamilyID; + + char *localNode; + char *localService; + char *remoteNode; + char *remoteService; + char *authScheme; + char *x509dname; + char *saslUsername; +}; + +struct qemuEventSerialChangeData { + char *devAlias; + bool connected; +}; + +struct qemuEventWatchdogData { + int action; +}; + +struct _qemuEvent { + qemuMonitorEventType ev_type; + unsigned long ev_id; + long long seconds; + unsigned int micros; + virDomainObjPtr vm; + void (*handler)(qemuEventPtr ev, void *opaque); + union qemuEventData { + struct qemuEventAcpiOstInfoData ev_acpi; + struct qemuEventBalloonChangeData ev_balloon; + struct qemuEventIOErrorData ev_IOErr; + struct qemuEventBlockJobData ev_blockJob; + struct qemuEventBlockThresholdData ev_threshold; + struct qemuEventDeviceDeletedData ev_deviceDel; + struct qemuEventTrayChangeData ev_tray; + struct qemuEventGuestPanicData ev_panic; + struct qemuEventMigrationStatusData ev_migStatus; + struct qemuEventMigrationPassData ev_migPass; + struct qemuEventNicRxFilterChangeData ev_nic; + struct qemuEventRTCChangeData ev_rtc; + struct qemuEventGraphicsData ev_graphics; + struct qemuEventSerialChangeData ev_serial; + struct qemuEventWatchdogData ev_watchdog; + } evData; +}; + + + +// Define a Global event queue. +// This is a double LL with qemuEventPtr embedded. + +struct _qemuGlobalEventListElement { + unsigned long ev_id; + virDomainObjPtr vm; + struct _qemuGlobalEventListElement *prev; + struct _qemuGlobalEventListElement *next; +}; + +struct _qemuGlobalEventList { + virMutex lock; + struct _qemuGlobalEventListElement *head; + struct _qemuGlobalEventListElement *last; +}; + +/* Global list of event entries of all VM */ +typedef struct _qemuGlobalEventList virQemuEventList; + +struct _qemuVmEventQueueElement { + qemuEventPtr ev; + struct _qemuVmEventQueueElement *next; +}; + +// Define a Per-VM event queue.=20 +struct _qemuVmEventQueue { + struct _qemuVmEventQueueElement *head; + struct _qemuVmEventQueueElement *last; + virMutex lock; + }; + +typedef struct _qemuVmEventQueue virQemuVmEventQueue; + + + +virQemuEventList* virQemuEventListInit(void); +int virQemuVmEventListInit(virDomainObjPtr vm); +/** + * viEnqueueVMEvent() + * Adds a new event to : + * - the global event queue. + * - the event queue for this VM + * + */ +int virEnqueueVMEvent(virQemuEventList *qlist, qemuEventPtr ev); +qemuEventPtr virDequeueVMEvent(virQemuEventList *qlist, virDomainObjPtr vm= ); +void virEventWorkerScanQueue(void *dummy, void *opaque); +void virEventRunHandler(qemuEventPtr ev, void *opaque); +void virDomainConsumeVMEvents(virDomainObjPtr vm, void *opaque); +#endif --=20 2.9.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list