From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id AE9A65A0082 for ; Wed, 22 Feb 2023 11:21:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677061274; h=from:from: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; bh=nmSxJ/834zcy9jO1Xya6JE0bXMcWcy8c2H7RRYmUy24=; b=iVquQ23a84+/vr2wADj1SaGrGyV6Fcytb662jHiZC46dShBIuXZtbvs9FK2AmxPnQcZkhA tFFJI07BaCUIIwWZJoBoLdMFdq4QTnsUpaDzlDwmtTD70y4z+SYoFG5Xc0OADhRtwmHMfB heMrLv/rL+zsR6+fstkd2vv5LxPB2xQ= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-311-5IxrXfsXPySiJEO9q1KwbA-1; Wed, 22 Feb 2023 05:21:13 -0500 X-MC-Unique: 5IxrXfsXPySiJEO9q1KwbA-1 Received: by mail-ed1-f71.google.com with SMTP id cf11-20020a0564020b8b00b0049ec3a108beso9878514edb.7 for ; Wed, 22 Feb 2023 02:21:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nmSxJ/834zcy9jO1Xya6JE0bXMcWcy8c2H7RRYmUy24=; b=kbXhms7G0/gPLcoXfYLae8+IPDxw/sTt72lVwUYfF3HqycR/BTYgHu+r4yR7OObxtg 7sYY5nU/Pj6o+2Y+u1NdhNHYc2Y/dSy3abg27HaRpUBVoIxJfnQ/Jlh1Yf+QO23PluYQ dTwOY7+En4vUhJ7nYcOTnDzZ8N2N9tUmxUTrrtgXCp63gj8658SPKxF95jThBuiOTXjM lvSlnoSOgviEAB34oGoI3dSUkTujUy21O5PI25+jW0bxIf+toNYtwzI/zvrQLhxWTPKA k91qWPPswiQvze/CNjc2f5blt0+f9pfbxVjoNrjYT95UShb3TA/HOD+7OUV14sdytPdi YsLA== X-Gm-Message-State: AO0yUKXDUNy1pYtaJ/ap48nf+wcMM+MCznu/4NaEhpPlRVd90fe/ReIy czQewdkP7Ob6KHgbbPHX/Y4jHHYV/Wq0VY39pFMi8UXsE/APhEY2Y7uDzCpU94DYkr9aym5MA7/ maEdIdXDzmktS X-Received: by 2002:a17:906:264d:b0:8a9:e330:3a23 with SMTP id i13-20020a170906264d00b008a9e3303a23mr15382963ejc.26.1677061272241; Wed, 22 Feb 2023 02:21:12 -0800 (PST) X-Google-Smtp-Source: AK7set9jsiQIaMBUzfkh/etClAMBKplW8h8GeBu4k2T1mGv6ZWhVctBQmVbuXo99C4mCCgoAAFtEAA== X-Received: by 2002:a17:906:264d:b0:8a9:e330:3a23 with SMTP id i13-20020a170906264d00b008a9e3303a23mr15382946ejc.26.1677061271954; Wed, 22 Feb 2023 02:21:11 -0800 (PST) Received: from [10.43.2.39] (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id fp16-20020a1709069e1000b008e22978b98bsm1512402ejc.61.2023.02.22.02.21.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Feb 2023 02:21:11 -0800 (PST) Message-ID: <8f40512a-5d39-e7e7-4e7b-b880e6660347@redhat.com> Date: Wed, 22 Feb 2023 11:21:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [libvirt PATCH 3/3] qemu: respond to NETDEV_STREAM_DISCONNECTED event To: Laine Stump , libvir-list@redhat.com References: <20230222003559.62442-1-laine@redhat.com> <20230222003559.62442-4-laine@redhat.com> From: =?UTF-8?B?TWljaGFsIFByw612b3puw61r?= In-Reply-To: <20230222003559.62442-4-laine@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: J7IDLSDD42CGTXNWZ2LGGUCSMTXD2QVA X-Message-ID-Hash: J7IDLSDD42CGTXNWZ2LGGUCSMTXD2QVA X-Mailman-Approved-At: Thu, 23 Feb 2023 09:26:34 +0100 CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 2/22/23 01:35, Laine Stump wrote: > 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 = 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, > } > > > +static void > +processNetdevStreamDisconnectedEvent(virDomainObj *vm, > + const char *netdevId) > +{ > + virDomainDeviceDef dev; > + virDomainNetDef *def; > + qemuDomainObjPrivate *priv; > + virQEMUCaps *qemuCaps; > + const char *devAlias = 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 = &netdevId[4]; This is open coding STRSKIP(): devAlias = STRSKIP(netdevId, "host"); > + > + if (!devAlias) { > + VIR_WARN("Received NETDEV_STREAM_DISCONNECTED event for unrecognized netdev %s from domain %p %s", > + netdevId, vm, vm->def->name); > + return; > + } > + > + VIR_DEBUG("Received NETDEV_STREAM_DISCONNECTED event for device %s from 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-existent device %s in domain %s", > + devAlias, vm->def->name); > + goto endjob; > + } > + if (dev.type != VIR_DOMAIN_DEVICE_NET) { > + VIR_WARN("NETDEV_STREAM_DISCONNECTED event received for non-network device %s in domain %s", > + devAlias, vm->def->name); > + goto endjob; > + } > + def = dev.data.net; > + > + if (def->backend.type != VIR_DOMAIN_NET_BACKEND_PASST) { > + VIR_DEBUG("ignore NETDEV_STREAM_DISCONNECTED event for non-passt network device %s in domain %s", > + def->info.alias, vm->def->name); > + goto endjob; > + } > + > + priv = vm->privateData; > + qemuCaps = priv->qemuCaps; > + These two can be done in variable declaration. Alternatively, if you want to lose @priv variable completely you can go with: virQEMUCaps *caps = QEMU_DOMAIN_PRIVATE(vm)->qemuCaps; > + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV_STREAM_RECONNECT)) { > + VIR_WARN("ignore NETDEV_STREAM_DISCONNECTED event for passt network 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); > +} > + Michal