From nobody Tue Feb 10 01:59:18 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=1677026228; cv=none; d=zohomail.com; s=zohoarc; b=R6z4D6O2cXV+IXc/SIOXHnBTjTd3/hkWuwqtRmPFpAxjCX4u4Z/k3YZ+L1EePcPisZtUxCudRJ6Q3TQUwmhYKignX2g5+RnfpOInT5qOY2TCnjmyJBFecYLtbLWAll24U7JWRk8die4hBaDW+4nTbHL9yMkrWVcvIMAF/5meDbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677026228; 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=FFNiyTDg087bGTNckD36d1HRf7ss1tn0oTUNEZSv3qc=; b=lomI1hzHczmDV2gM2WLRwtLwaeMwPRRp1+Kfwb6dPsKyCZp3sWu+ZHNFzNd+ZvNuZKzyf/qCnwJBx7ta0UZqWt3DGPRkKX42VBcm/mUUuQdgdS9qcCGl0GFLaWCh1L8i0Sgvav8wE4ofJKhqmCLVfnfHqREQ9LMTAObdM02MiNk= 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 1677026228506877.6870214642215; Tue, 21 Feb 2023 16:37:08 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-516-v6a_fsqyOTCF6F2E-j9qpw-1; Tue, 21 Feb 2023 19:36:05 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA0A11C02CB7; Wed, 22 Feb 2023 00:36:02 +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 C9E9E1121319; Wed, 22 Feb 2023 00:36:02 +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 A48DB1946A7A; Wed, 22 Feb 2023 00:36:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 362A51946587 for ; Wed, 22 Feb 2023 00:36:00 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 13F372026D3F; Wed, 22 Feb 2023 00:36:00 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.2.16.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id E90FA2026D4B; Wed, 22 Feb 2023 00:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677026227; 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=FFNiyTDg087bGTNckD36d1HRf7ss1tn0oTUNEZSv3qc=; b=hpKOwIbOjnRQseS2xvD8NwIeVPg7xS4M3hWw2Cr/1dFGj8opyv1yxxQgrv526Df2yx2A6P ZlFCdbI5hnlbCDUFiOdSdnJwhItB8r1cHZfac4gdfAk8r3gJ+IgWKFMSxgkrjQWAVgeTI8 MAApcoKMvEee5/ywRaPxZM9Q58rZUHc= X-MC-Unique: v6a_fsqyOTCF6F2E-j9qpw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 3/3] qemu: respond to NETDEV_STREAM_DISCONNECTED event Date: Tue, 21 Feb 2023 19:35:59 -0500 Message-Id: <20230222003559.62442-4-laine@redhat.com> In-Reply-To: <20230222003559.62442-1-laine@redhat.com> References: <20230222003559.62442-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: , Cc: passt-dev@passt.top Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: 1677026230262100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When a QEMU netdev is of type "stream", if the socket it uses for connectivity to the host network gets closed, then QEMU will send a NETDEV_STREAM_DISCONNECTED event. We know that any stream netdev we've created is backed by a passt process, and if the socket was closed, that means the passt process has disappeared. When we receive this event, we can respond by starting a new passt process with the same options (including socket path) we originally used. If we have previously created the stream netdev device with a "reconnect" option, then QEMU will automatically reconnect to this new passt process. (If we hadn't used "reconnect", then QEMU will never try to reconnect to the new passt process, so there's no point in starting it.) Note that NETDEV_STREAM_DISCONNECTED is an event sent for the netdev (ie "host side") of the network device, and so it sends the "netdev-id" to specify which device was disconnected. But libvirt's virDomainNetDef (the object used to keep track of network devices) is the internal representation of both the host-side "netdev", and the guest side device, and virDomainNetDef doesn't directly keep track of the netdev-id, only of the device's "alias" (which is the "id" parameter of the *guest* side of the device). Fortunately, by convention libvirt always names the host-side of devices as "host" + alias, so in order to search for the affected NetDef, all we need to do is trim the 1st 4 characters from the netdev-id and look for the NetDef having that resulting trimmed string as its alias. (Contrast this to NIC_RX_FILTER_CHANGED, which is an event received for the guest side of the device, and so directly contains the device alias.) Resolves: https://bugzilla.redhat.com/2172098 Signed-off-by: Laine Stump --- src/qemu/qemu_domain.c | 1 + src/qemu/qemu_domain.h | 1 + src/qemu/qemu_driver.c | 82 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor.c | 11 +++++ src/qemu/qemu_monitor.h | 6 +++ src/qemu/qemu_monitor_json.c | 16 +++++++ src/qemu/qemu_process.c | 18 ++++++++ 7 files changed, 135 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e9bc0f375d..4cf9a259ea 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11238,6 +11238,7 @@ qemuProcessEventFree(struct qemuProcessEvent *event) break; case QEMU_PROCESS_EVENT_WATCHDOG: case QEMU_PROCESS_EVENT_DEVICE_DELETED: + case QEMU_PROCESS_EVENT_NETDEV_STREAM_DISCONNECTED: case QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED: case QEMU_PROCESS_EVENT_SERIAL_CHANGED: case QEMU_PROCESS_EVENT_MONITOR_EOF: diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 1053d1d4cb..6adc067681 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -447,6 +447,7 @@ typedef enum { QEMU_PROCESS_EVENT_WATCHDOG =3D 0, QEMU_PROCESS_EVENT_GUESTPANIC, QEMU_PROCESS_EVENT_DEVICE_DELETED, + QEMU_PROCESS_EVENT_NETDEV_STREAM_DISCONNECTED, QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED, QEMU_PROCESS_EVENT_SERIAL_CHANGED, QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6154fe9bfe..47d6a0dd95 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -40,6 +40,7 @@ #include "qemu_hostdev.h" #include "qemu_hotplug.h" #include "qemu_monitor.h" +#include "qemu_passt.h" #include "qemu_process.h" #include "qemu_migration.h" #include "qemu_migration_params.h" @@ -3622,6 +3623,84 @@ processDeviceDeletedEvent(virQEMUDriver *driver, } =20 =20 +static void +processNetdevStreamDisconnectedEvent(virDomainObj *vm, + const char *netdevId) +{ + virDomainDeviceDef dev; + virDomainNetDef *def; + qemuDomainObjPrivate *priv; + virQEMUCaps *qemuCaps; + const char *devAlias =3D NULL; + + /* The event sends us the "netdev-id", but we don't store the + * netdev-id in the NetDef and thus can't use it to find the + * correct NetDef. We *do* keep the device alias in the NetDef. + * By definition, the netdev-id is "host" + devAlias, so we just + * need to remove "host" from the front of netdev-id to get + * something we can use to find the proper NetDef. + */ + if (STREQLEN(netdevId, "host", 4)) + devAlias =3D &netdevId[4]; + + if (!devAlias) { + VIR_WARN("Received NETDEV_STREAM_DISCONNECTED event for unrecogniz= ed netdev %s from domain %p %s", + netdevId, vm, vm->def->name); + return; + } + + VIR_DEBUG("Received NETDEV_STREAM_DISCONNECTED event for device %s fro= m domain %p %s", + devAlias, vm, vm->def->name); + + if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0) + return; + + if (!virDomainObjIsActive(vm)) { + VIR_DEBUG("Domain is not running"); + goto endjob; + } + + if (virDomainDefFindDevice(vm->def, devAlias, &dev, true) < 0) { + VIR_WARN("NETDEV_STREAM_DISCONNECTED event received for non-existe= nt device %s in domain %s", + devAlias, vm->def->name); + goto endjob; + } + if (dev.type !=3D VIR_DOMAIN_DEVICE_NET) { + VIR_WARN("NETDEV_STREAM_DISCONNECTED event received for non-networ= k device %s in domain %s", + devAlias, vm->def->name); + goto endjob; + } + def =3D dev.data.net; + + if (def->backend.type !=3D VIR_DOMAIN_NET_BACKEND_PASST) { + VIR_DEBUG("ignore NETDEV_STREAM_DISCONNECTED event for non-passt n= etwork device %s in domain %s", + def->info.alias, vm->def->name); + goto endjob; + } + + priv =3D vm->privateData; + qemuCaps =3D priv->qemuCaps; + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV_STREAM_RECONNECT)) { + VIR_WARN("ignore NETDEV_STREAM_DISCONNECTED event for passt networ= k device %s in domain %s - QEMU binary does not support reconnect", + def->info.alias, vm->def->name); + goto endjob; + } + + /* handle the event - restart the passt process with its original + * parameters + */ + VIR_DEBUG("process NETDEV_STREAM_DISCONNECTED event for network device= %s in domain %s", + def->info.alias, vm->def->name); + + if (qemuPasstStart(vm, def) < 0) + goto endjob; + + endjob: + virDomainObjEndJob(vm); +} + + static void processNicRxFilterChangedEvent(virDomainObj *vm, const char *devAlias) @@ -3971,6 +4050,9 @@ static void qemuProcessEventHandler(void *data, void = *opaque) case QEMU_PROCESS_EVENT_DEVICE_DELETED: processDeviceDeletedEvent(driver, vm, processEvent->data); break; + case QEMU_PROCESS_EVENT_NETDEV_STREAM_DISCONNECTED: + processNetdevStreamDisconnectedEvent(vm, processEvent->data); + break; case QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED: processNicRxFilterChangedEvent(vm, processEvent->data); break; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 38f89167e0..1fa35f03cc 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1265,6 +1265,17 @@ qemuMonitorEmitNicRxFilterChanged(qemuMonitor *mon, } =20 =20 +void +qemuMonitorEmitNetdevStreamDisconnected(qemuMonitor *mon, + const char *devAlias) +{ + VIR_DEBUG("mon=3D%p", mon); + + QEMU_MONITOR_CALLBACK(mon, domainNetdevStreamDisconnected, + mon->vm, devAlias); +} + + void qemuMonitorEmitSerialChange(qemuMonitor *mon, const char *devAlias, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 2d16214ba2..2fa06b99a3 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -250,6 +250,9 @@ typedef void (*qemuMonitorDomainDeviceUnplugErrCallback= )(qemuMonitor *mon, virDomainObj *vm, const char *devPa= th, const char *devAl= ias); +typedef void (*qemuMonitorDomainNetdevStreamDisconnectedCallback)(qemuMoni= tor *mon, + virDomai= nObj *vm, + const ch= ar *devAlias); typedef void (*qemuMonitorDomainNicRxFilterChangedCallback)(qemuMonitor *m= on, virDomainObj *= vm, const char *de= vAlias); @@ -397,6 +400,7 @@ struct _qemuMonitorCallbacks { qemuMonitorDomainMemoryFailureCallback domainMemoryFailure; qemuMonitorDomainMemoryDeviceSizeChange domainMemoryDeviceSizeChange; qemuMonitorDomainDeviceUnplugErrCallback domainDeviceUnplugError; + qemuMonitorDomainNetdevStreamDisconnectedCallback domainNetdevStreamDi= sconnected; }; =20 qemuMonitor *qemuMonitorOpen(virDomainObj *vm, @@ -480,6 +484,8 @@ void qemuMonitorEmitDeviceDeleted(qemuMonitor *mon, void qemuMonitorEmitDeviceUnplugErr(qemuMonitor *mon, const char *devPath, const char *devAlias); +void qemuMonitorEmitNetdevStreamDisconnected(qemuMonitor *mon, + const char *devAlias); void qemuMonitorEmitNicRxFilterChanged(qemuMonitor *mon, const char *devAlias); void qemuMonitorEmitSerialChange(qemuMonitor *mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index ba6276ec8e..e81b464eea 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -84,6 +84,7 @@ static void qemuMonitorJSONHandleRdmaGidStatusChanged(qem= uMonitor *mon, virJSONV 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); =20 typedef struct { const char *type; @@ -106,6 +107,7 @@ static qemuEventHandler eventHandlers[] =3D { { "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= , }, @@ -1021,6 +1023,20 @@ qemuMonitorJSONHandleDeviceUnplugErr(qemuMonitor *mo= n, virJSONValue *data) } =20 =20 +static void +qemuMonitorJSONHandleNetdevStreamDisconnected(qemuMonitor *mon, virJSONVal= ue *data) +{ + const char *name; + + if (!(name =3D virJSONValueObjectGetString(data, "netdev-id"))) { + VIR_WARN("missing device in NETDEV_STREAM_DISCONNECTED event"); + return; + } + + qemuMonitorEmitNetdevStreamDisconnected(mon, name); +} + + static void qemuMonitorJSONHandleNicRxFilterChanged(qemuMonitor *mon, virJSONValue *da= ta) { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d4499c6f84..63d7e1138d 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1361,6 +1361,23 @@ qemuProcessHandleBlockThreshold(qemuMonitor *mon G_G= NUC_UNUSED, } =20 =20 +static void +qemuProcessHandleNetdevStreamDisconnected(qemuMonitor *mon G_GNUC_UNUSED, + virDomainObj *vm, + const char *devAlias) +{ + virObjectLock(vm); + + VIR_DEBUG("Device %s Netdev Stream Disconnected in domain %p %s", + devAlias, vm, vm->def->name); + + qemuProcessEventSubmit(vm, QEMU_PROCESS_EVENT_NETDEV_STREAM_DISCONNECT= ED, + 0, 0, g_strdup(devAlias)); + + virObjectUnlock(vm); +} + + static void qemuProcessHandleNicRxFilterChanged(qemuMonitor *mon G_GNUC_UNUSED, virDomainObj *vm, @@ -1802,6 +1819,7 @@ static qemuMonitorCallbacks monitorCallbacks =3D { .domainMemoryFailure =3D qemuProcessHandleMemoryFailure, .domainMemoryDeviceSizeChange =3D qemuProcessHandleMemoryDeviceSizeCha= nge, .domainDeviceUnplugError =3D qemuProcessHandleDeviceUnplugErr, + .domainNetdevStreamDisconnected =3D qemuProcessHandleNetdevStreamDisco= nnected, }; =20 static void --=20 2.39.2