From nobody Sat May 4 15:05:36 2024 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=1666083490; cv=none; d=zohomail.com; s=zohoarc; b=V6N5tGA1E49d1ibUToP75bUg3lhbpQAJoKrVPS2bTsrCWIGMFQYCP/cHnr9S6AdF9FFruDYdFdMGV2U0/CYazHrazbzvdbnJGF3GAEp5uuYhyLwtgGO3tXvxTQhmPanGYkWuwuRILPVwGcmHaHEv06O9K8NyIQHbx3XgMi4hXkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666083490; 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=OSAmQaBDtpQszg80WybrnLQl074hOuGTllR5AkTeLCI=; b=PXbdbT4xS2jXSjUb2mwwFK07VEAgp+yGQIaH/kQqplCNHFnglumc1TbRICDfhrgnZYbKJ95bPDyRYipTN5YH7WRIELfj98kyGYoweJpN/iegRSIuPOBEB6fZts0YO30g5QOpk9a5ofQMZ0xaH4pUIj0/ehU8SD9wD0uZIta7uXA= 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 1666083490313361.30748242185837; Tue, 18 Oct 2022 01:58:10 -0700 (PDT) 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-661-rIVxuTqEOOmwLJIrnaRg3w-1; Tue, 18 Oct 2022 04:58:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4881F38041CB; Tue, 18 Oct 2022 08:57:57 +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 2DCED2022E01; Tue, 18 Oct 2022 08:57:57 +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 4C7B91946A41; Tue, 18 Oct 2022 08:57:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 22B0D1946595 for ; Tue, 18 Oct 2022 08:57:51 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9AD49403032B; Tue, 18 Oct 2022 08:57:51 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40C98403032A for ; Tue, 18 Oct 2022 08:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666083489; 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=OSAmQaBDtpQszg80WybrnLQl074hOuGTllR5AkTeLCI=; b=hkXEmBSeEekGYoeV4QxeX5A5Q1070mGJXeZ8WzkpH3FBMpX+8GBX34Kk8EdmH2ljk7RXOy OeX4rXdxy9eFefYpbc1NJR/6eyr0aM4cuTLvSkGZSNjxSzoFvagydoi1xvBrow1mrQr/AV xB7hCyFqQD74sJTXi0lrpWt5hYv3VAg= X-MC-Unique: rIVxuTqEOOmwLJIrnaRg3w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/5] processNicRxFilterChangedEvent: Free @guestFilter and @hostFilter automatically Date: Tue, 18 Oct 2022 10:57:45 +0200 Message-Id: <5f26eba2e3b5236aefa283c10c415b6a70f44293.1666083387.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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 3.1 on 10.11.54.4 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: 1666083490792100007 Content-Type: text/plain; charset="utf-8"; x-default="true" There's no need to call virNetDevRxFilterFree() explicitly, when corresponding variables can be declared as g_autoptr(virNetDevRxFilter). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5c75000742..afebae3b93 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3817,8 +3817,8 @@ processNicRxFilterChangedEvent(virDomainObj *vm, qemuDomainObjPrivate *priv =3D vm->privateData; virDomainDeviceDef dev; virDomainNetDef *def; - virNetDevRxFilter *guestFilter =3D NULL; - virNetDevRxFilter *hostFilter =3D NULL; + g_autoptr(virNetDevRxFilter) guestFilter =3D NULL; + g_autoptr(virNetDevRxFilter) hostFilter =3D NULL; int ret; =20 VIR_DEBUG("Received NIC_RX_FILTER_CHANGED event for device %s " @@ -3826,7 +3826,7 @@ processNicRxFilterChangedEvent(virDomainObj *vm, devAlias, vm, vm->def->name); =20 if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) - goto cleanup; + return; =20 if (!virDomainObjIsActive(vm)) { VIR_DEBUG("Domain is not running"); @@ -3907,10 +3907,6 @@ processNicRxFilterChangedEvent(virDomainObj *vm, =20 endjob: virDomainObjEndJob(vm); - - cleanup: - virNetDevRxFilterFree(hostFilter); - virNetDevRxFilterFree(guestFilter); } =20 =20 --=20 2.37.3 From nobody Sat May 4 15:05:36 2024 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=1666083485; cv=none; d=zohomail.com; s=zohoarc; b=ito63B8yeVXDxQq1h59rZ1vznJrAKXW7QnibFuDT/kIEe8Ab4YMZMmsfbaDlFx+dscOhP7UQzxzbOAXaimYyb0dqhFAyYG2RZdnz+KVWV0k5N2sL8YXiIZLFujehYLeUKuwoFmS0lKXmkll2wS683NsaLoUlv0ePNJ0aRnnmZIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666083485; 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=pkoauflg6LiZwZXKTQ6drBzH6OqGE7BniNOEjYVZPPk=; b=GVKYOvEdN7wqLjxsRDOLi+/PYFadbT1D61PD2cs3AJWndTTBshmFXGqIBijL/eX9QQHHzWoumeXpjFx7PZmIGei+90RP/KO6YykHN17ajQLSvZoTixsbMK5xxeQ4ZZ/6af+BRViNomhfP2Ksc+9Nb612zzPN2askngie+DFQJVQ= 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 1666083485601411.6344193721418; Tue, 18 Oct 2022 01:58:05 -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-627-VnZcR7UBMgOjz97j0VKUFw-1; Tue, 18 Oct 2022 04:58:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DEA34833AFA; Tue, 18 Oct 2022 08:57:57 +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 C72CB2157F21; Tue, 18 Oct 2022 08:57:57 +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 98C031946A52; Tue, 18 Oct 2022 08:57:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 227E1194658F for ; Tue, 18 Oct 2022 08:57:52 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3958B414A819; Tue, 18 Oct 2022 08:57:52 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id D26FD403032A for ; Tue, 18 Oct 2022 08:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666083484; 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=pkoauflg6LiZwZXKTQ6drBzH6OqGE7BniNOEjYVZPPk=; b=XIsGEs0jTLlhM0gUJovm/2Dp6d6HCGU1AjmXsUTaIZpWpSDY/WRKay8UaZ284ENriNn4MY 6QMcrxgRDKBNJVD04enxCFeocd0mutGD+J7W1wnTJFvOj3ksafXydvMuOxCTY5CgVnZaLo 3cpJ94Uy9meIVRCtxcJsXvs6wN2mtTk= X-MC-Unique: VnZcR7UBMgOjz97j0VKUFw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/5] qemu: Move parts of NIC_RX_FILTER_CHANGED even handling into a function Date: Tue, 18 Oct 2022 10:57:46 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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 3.1 on 10.11.54.6 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: 1666083487003100002 Content-Type: text/plain; charset="utf-8"; x-default="true" Parts of the code that responds to the NIC_RX_FILTER_CHANGED event are going to be re-used. Separate them into a function (qemuDomainSyncRxFilter()) and move the code into qemu_domain.c so that it can be re-used from other places of the driver. There's one slight change though: instead of passing device alias from the just received event to qemuMonitorQueryRxFilter(), I've switched to using the alias stored in our domain definition. But these two are guaranteed to be equal. virDomainDefFindDevice() made sure about that, if nothing else. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_domain.c | 251 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 4 + src/qemu/qemu_driver.c | 242 +-------------------------------------- 3 files changed, 256 insertions(+), 241 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 4c14fc2aef..1b93ebe579 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11774,3 +11774,254 @@ qemuDomainObjWait(virDomainObj *vm) =20 return 0; } + + +static void +syncNicRxFilterMacAddr(char *ifname, virNetDevRxFilter *guestFilter, + virNetDevRxFilter *hostFilter) +{ + char newMacStr[VIR_MAC_STRING_BUFLEN]; + + if (virMacAddrCmp(&hostFilter->mac, &guestFilter->mac)) { + virMacAddrFormat(&guestFilter->mac, newMacStr); + + /* set new MAC address from guest to associated macvtap device */ + if (virNetDevSetMAC(ifname, &guestFilter->mac) < 0) { + VIR_WARN("Couldn't set new MAC address %s to device %s " + "while responding to NIC_RX_FILTER_CHANGED", + newMacStr, ifname); + } else { + VIR_DEBUG("device %s MAC address set to %s", ifname, newMacStr= ); + } + } +} + + +static void +syncNicRxFilterGuestMulticast(char *ifname, virNetDevRxFilter *guestFilter, + virNetDevRxFilter *hostFilter) +{ + size_t i, j; + bool found; + char macstr[VIR_MAC_STRING_BUFLEN]; + + for (i =3D 0; i < guestFilter->multicast.nTable; i++) { + found =3D false; + + for (j =3D 0; j < hostFilter->multicast.nTable; j++) { + if (virMacAddrCmp(&guestFilter->multicast.table[i], + &hostFilter->multicast.table[j]) =3D=3D 0) { + found =3D true; + break; + } + } + + if (!found) { + virMacAddrFormat(&guestFilter->multicast.table[i], macstr); + + if (virNetDevAddMulti(ifname, &guestFilter->multicast.table[i]= ) < 0) { + VIR_WARN("Couldn't add new multicast MAC address %s to " + "device %s while responding to NIC_RX_FILTER_CHAN= GED", + macstr, ifname); + } else { + VIR_DEBUG("Added multicast MAC %s to %s interface", + macstr, ifname); + } + } + } +} + + +static void +syncNicRxFilterHostMulticast(char *ifname, virNetDevRxFilter *guestFilter, + virNetDevRxFilter *hostFilter) +{ + size_t i, j; + bool found; + char macstr[VIR_MAC_STRING_BUFLEN]; + + for (i =3D 0; i < hostFilter->multicast.nTable; i++) { + found =3D false; + + for (j =3D 0; j < guestFilter->multicast.nTable; j++) { + if (virMacAddrCmp(&hostFilter->multicast.table[i], + &guestFilter->multicast.table[j]) =3D=3D 0) { + found =3D true; + break; + } + } + + if (!found) { + virMacAddrFormat(&hostFilter->multicast.table[i], macstr); + + if (virNetDevDelMulti(ifname, &hostFilter->multicast.table[i])= < 0) { + VIR_WARN("Couldn't delete multicast MAC address %s from " + "device %s while responding to NIC_RX_FILTER_CHAN= GED", + macstr, ifname); + } else { + VIR_DEBUG("Deleted multicast MAC %s from %s interface", + macstr, ifname); + } + } + } +} + + +static void +syncNicRxFilterPromiscMode(char *ifname, + virNetDevRxFilter *guestFilter, + virNetDevRxFilter *hostFilter) +{ + bool promisc; + bool setpromisc =3D false; + + /* Set macvtap promisc mode to true if the guest has vlans defined */ + /* or synchronize the macvtap promisc mode if different from guest */ + if (guestFilter->vlan.nTable > 0) { + if (!hostFilter->promiscuous) { + setpromisc =3D true; + promisc =3D true; + } + } else if (hostFilter->promiscuous !=3D guestFilter->promiscuous) { + setpromisc =3D true; + promisc =3D guestFilter->promiscuous; + } + + if (setpromisc) { + if (virNetDevSetPromiscuous(ifname, promisc) < 0) { + VIR_WARN("Couldn't set PROMISC flag to %s for device %s " + "while responding to NIC_RX_FILTER_CHANGED", + promisc ? "true" : "false", ifname); + } + } +} + + +static void +syncNicRxFilterMultiMode(char *ifname, virNetDevRxFilter *guestFilter, + virNetDevRxFilter *hostFilter) +{ + if (hostFilter->multicast.mode !=3D guestFilter->multicast.mode || + (guestFilter->multicast.overflow && + guestFilter->multicast.mode =3D=3D VIR_NETDEV_RX_FILTER_MODE_NORM= AL)) { + switch (guestFilter->multicast.mode) { + case VIR_NETDEV_RX_FILTER_MODE_ALL: + if (virNetDevSetRcvAllMulti(ifname, true) < 0) { + VIR_WARN("Couldn't set allmulticast flag to 'on' for " + "device %s while responding to " + "NIC_RX_FILTER_CHANGED", ifname); + } + break; + + case VIR_NETDEV_RX_FILTER_MODE_NORMAL: + if (guestFilter->multicast.overflow && + (hostFilter->multicast.mode =3D=3D VIR_NETDEV_RX_FILTER_MO= DE_ALL)) { + break; + } + + if (virNetDevSetRcvMulti(ifname, true) < 0) { + VIR_WARN("Couldn't set multicast flag to 'on' for " + "device %s while responding to " + "NIC_RX_FILTER_CHANGED", ifname); + } + + if (virNetDevSetRcvAllMulti(ifname, + guestFilter->multicast.overflow) <= 0) { + VIR_WARN("Couldn't set allmulticast flag to '%s' for " + "device %s while responding to " + "NIC_RX_FILTER_CHANGED", + virTristateSwitchTypeToString(virTristateSwitchFr= omBool(guestFilter->multicast.overflow)), + ifname); + } + break; + + case VIR_NETDEV_RX_FILTER_MODE_NONE: + if (virNetDevSetRcvAllMulti(ifname, false) < 0) { + VIR_WARN("Couldn't set allmulticast flag to 'off' for " + "device %s while responding to " + "NIC_RX_FILTER_CHANGED", ifname); + } + + if (virNetDevSetRcvMulti(ifname, false) < 0) { + VIR_WARN("Couldn't set multicast flag to 'off' for " + "device %s while responding to " + "NIC_RX_FILTER_CHANGED", + ifname); + } + break; + } + } +} + + +static void +syncNicRxFilterDeviceOptions(char *ifname, virNetDevRxFilter *guestFilter, + virNetDevRxFilter *hostFilter) +{ + syncNicRxFilterPromiscMode(ifname, guestFilter, hostFilter); + syncNicRxFilterMultiMode(ifname, guestFilter, hostFilter); +} + + +static void +syncNicRxFilterMulticast(char *ifname, + virNetDevRxFilter *guestFilter, + virNetDevRxFilter *hostFilter) +{ + syncNicRxFilterGuestMulticast(ifname, guestFilter, hostFilter); + syncNicRxFilterHostMulticast(ifname, guestFilter, hostFilter); +} + + +int +qemuDomainSyncRxFilter(virDomainObj *vm, + virDomainNetDef *def) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virNetDevRxFilter) guestFilter =3D NULL; + g_autoptr(virNetDevRxFilter) hostFilter =3D NULL; + int rc; + + qemuDomainObjEnterMonitor(vm); + rc =3D qemuMonitorQueryRxFilter(priv->mon, def->info.alias, &guestFilt= er); + qemuDomainObjExitMonitor(vm); + if (rc < 0) + return -1; + + if (virDomainNetGetActualType(def) =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { + if (virNetDevGetRxFilter(def->ifname, &hostFilter)) { + VIR_WARN("Couldn't get current RX filter for device %s while r= esponding to NIC_RX_FILTER_CHANGED", + def->ifname); + return -1; + } + + /* For macvtap connections, set the following macvtap network devi= ce + * attributes to match those of the guest network device: + * - MAC address + * - Multicast MAC address table + * - Device options: + * - PROMISC + * - MULTICAST + * - ALLMULTI + */ + syncNicRxFilterMacAddr(def->ifname, guestFilter, hostFilter); + syncNicRxFilterMulticast(def->ifname, guestFilter, hostFilter); + syncNicRxFilterDeviceOptions(def->ifname, guestFilter, hostFilter); + } + + if (virDomainNetGetActualType(def) =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK)= { + const char *brname =3D virDomainNetGetActualBridgeName(def); + + /* For libivrt network connections, set the following TUN/TAP netw= ork + * device attributes to match those of the guest network device: + * - QoS filters (which are based on MAC address) + */ + if (virDomainNetGetActualBandwidth(def) && + def->data.network.actual && + virNetDevBandwidthUpdateFilter(brname, &guestFilter->mac, + def->data.network.actual->class= _id) < 0) + return -1; + } + + return 0; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index a22deaf113..f436861efc 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1098,3 +1098,7 @@ qemuDomainRemoveLogs(virQEMUDriver *driver, =20 int qemuDomainObjWait(virDomainObj *vm); + +int +qemuDomainSyncRxFilter(virDomainObj *vm, + virDomainNetDef *def); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index afebae3b93..86bc35ca92 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3614,212 +3614,12 @@ processDeviceDeletedEvent(virQEMUDriver *driver, } =20 =20 -static void -syncNicRxFilterMacAddr(char *ifname, virNetDevRxFilter *guestFilter, - virNetDevRxFilter *hostFilter) -{ - char newMacStr[VIR_MAC_STRING_BUFLEN]; - - if (virMacAddrCmp(&hostFilter->mac, &guestFilter->mac)) { - virMacAddrFormat(&guestFilter->mac, newMacStr); - - /* set new MAC address from guest to associated macvtap device */ - if (virNetDevSetMAC(ifname, &guestFilter->mac) < 0) { - VIR_WARN("Couldn't set new MAC address %s to device %s " - "while responding to NIC_RX_FILTER_CHANGED", - newMacStr, ifname); - } else { - VIR_DEBUG("device %s MAC address set to %s", ifname, newMacStr= ); - } - } -} - - -static void -syncNicRxFilterGuestMulticast(char *ifname, virNetDevRxFilter *guestFilter, - virNetDevRxFilter *hostFilter) -{ - size_t i, j; - bool found; - char macstr[VIR_MAC_STRING_BUFLEN]; - - for (i =3D 0; i < guestFilter->multicast.nTable; i++) { - found =3D false; - - for (j =3D 0; j < hostFilter->multicast.nTable; j++) { - if (virMacAddrCmp(&guestFilter->multicast.table[i], - &hostFilter->multicast.table[j]) =3D=3D 0) { - found =3D true; - break; - } - } - - if (!found) { - virMacAddrFormat(&guestFilter->multicast.table[i], macstr); - - if (virNetDevAddMulti(ifname, &guestFilter->multicast.table[i]= ) < 0) { - VIR_WARN("Couldn't add new multicast MAC address %s to " - "device %s while responding to NIC_RX_FILTER_CHAN= GED", - macstr, ifname); - } else { - VIR_DEBUG("Added multicast MAC %s to %s interface", - macstr, ifname); - } - } - } -} - - -static void -syncNicRxFilterHostMulticast(char *ifname, virNetDevRxFilter *guestFilter, - virNetDevRxFilter *hostFilter) -{ - size_t i, j; - bool found; - char macstr[VIR_MAC_STRING_BUFLEN]; - - for (i =3D 0; i < hostFilter->multicast.nTable; i++) { - found =3D false; - - for (j =3D 0; j < guestFilter->multicast.nTable; j++) { - if (virMacAddrCmp(&hostFilter->multicast.table[i], - &guestFilter->multicast.table[j]) =3D=3D 0) { - found =3D true; - break; - } - } - - if (!found) { - virMacAddrFormat(&hostFilter->multicast.table[i], macstr); - - if (virNetDevDelMulti(ifname, &hostFilter->multicast.table[i])= < 0) { - VIR_WARN("Couldn't delete multicast MAC address %s from " - "device %s while responding to NIC_RX_FILTER_CHAN= GED", - macstr, ifname); - } else { - VIR_DEBUG("Deleted multicast MAC %s from %s interface", - macstr, ifname); - } - } - } -} - - -static void -syncNicRxFilterPromiscMode(char *ifname, - virNetDevRxFilter *guestFilter, - virNetDevRxFilter *hostFilter) -{ - bool promisc; - bool setpromisc =3D false; - - /* Set macvtap promisc mode to true if the guest has vlans defined */ - /* or synchronize the macvtap promisc mode if different from guest */ - if (guestFilter->vlan.nTable > 0) { - if (!hostFilter->promiscuous) { - setpromisc =3D true; - promisc =3D true; - } - } else if (hostFilter->promiscuous !=3D guestFilter->promiscuous) { - setpromisc =3D true; - promisc =3D guestFilter->promiscuous; - } - - if (setpromisc) { - if (virNetDevSetPromiscuous(ifname, promisc) < 0) { - VIR_WARN("Couldn't set PROMISC flag to %s for device %s " - "while responding to NIC_RX_FILTER_CHANGED", - promisc ? "true" : "false", ifname); - } - } -} - - -static void -syncNicRxFilterMultiMode(char *ifname, virNetDevRxFilter *guestFilter, - virNetDevRxFilter *hostFilter) -{ - if (hostFilter->multicast.mode !=3D guestFilter->multicast.mode || - (guestFilter->multicast.overflow && - guestFilter->multicast.mode =3D=3D VIR_NETDEV_RX_FILTER_MODE_NORM= AL)) { - switch (guestFilter->multicast.mode) { - case VIR_NETDEV_RX_FILTER_MODE_ALL: - if (virNetDevSetRcvAllMulti(ifname, true) < 0) { - VIR_WARN("Couldn't set allmulticast flag to 'on' for " - "device %s while responding to " - "NIC_RX_FILTER_CHANGED", ifname); - } - break; - - case VIR_NETDEV_RX_FILTER_MODE_NORMAL: - if (guestFilter->multicast.overflow && - (hostFilter->multicast.mode =3D=3D VIR_NETDEV_RX_FILTER_MO= DE_ALL)) { - break; - } - - if (virNetDevSetRcvMulti(ifname, true) < 0) { - VIR_WARN("Couldn't set multicast flag to 'on' for " - "device %s while responding to " - "NIC_RX_FILTER_CHANGED", ifname); - } - - if (virNetDevSetRcvAllMulti(ifname, - guestFilter->multicast.overflow) <= 0) { - VIR_WARN("Couldn't set allmulticast flag to '%s' for " - "device %s while responding to " - "NIC_RX_FILTER_CHANGED", - virTristateSwitchTypeToString(virTristateSwitchFr= omBool(guestFilter->multicast.overflow)), - ifname); - } - break; - - case VIR_NETDEV_RX_FILTER_MODE_NONE: - if (virNetDevSetRcvAllMulti(ifname, false) < 0) { - VIR_WARN("Couldn't set allmulticast flag to 'off' for " - "device %s while responding to " - "NIC_RX_FILTER_CHANGED", ifname); - } - - if (virNetDevSetRcvMulti(ifname, false) < 0) { - VIR_WARN("Couldn't set multicast flag to 'off' for " - "device %s while responding to " - "NIC_RX_FILTER_CHANGED", - ifname); - } - break; - } - } -} - - -static void -syncNicRxFilterDeviceOptions(char *ifname, virNetDevRxFilter *guestFilter, - virNetDevRxFilter *hostFilter) -{ - syncNicRxFilterPromiscMode(ifname, guestFilter, hostFilter); - syncNicRxFilterMultiMode(ifname, guestFilter, hostFilter); -} - - -static void -syncNicRxFilterMulticast(char *ifname, - virNetDevRxFilter *guestFilter, - virNetDevRxFilter *hostFilter) -{ - syncNicRxFilterGuestMulticast(ifname, guestFilter, hostFilter); - syncNicRxFilterHostMulticast(ifname, guestFilter, hostFilter); -} - static void processNicRxFilterChangedEvent(virDomainObj *vm, const char *devAlias) { - qemuDomainObjPrivate *priv =3D vm->privateData; virDomainDeviceDef dev; virDomainNetDef *def; - g_autoptr(virNetDevRxFilter) guestFilter =3D NULL; - g_autoptr(virNetDevRxFilter) hostFilter =3D NULL; - int ret; =20 VIR_DEBUG("Received NIC_RX_FILTER_CHANGED event for device %s " "from domain %p %s", @@ -3862,49 +3662,9 @@ processNicRxFilterChangedEvent(virDomainObj *vm, VIR_DEBUG("process NIC_RX_FILTER_CHANGED event for network " "device %s in domain %s", def->info.alias, vm->def->name); =20 - qemuDomainObjEnterMonitor(vm); - ret =3D qemuMonitorQueryRxFilter(priv->mon, devAlias, &guestFilter); - qemuDomainObjExitMonitor(vm); - if (ret < 0) + if (qemuDomainSyncRxFilter(vm, def) < 0) goto endjob; =20 - if (virDomainNetGetActualType(def) =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { - - if (virNetDevGetRxFilter(def->ifname, &hostFilter)) { - VIR_WARN("Couldn't get current RX filter for device %s " - "while responding to NIC_RX_FILTER_CHANGED", - def->ifname); - goto endjob; - } - - /* For macvtap connections, set the following macvtap network devi= ce - * attributes to match those of the guest network device: - * - MAC address - * - Multicast MAC address table - * - Device options: - * - PROMISC - * - MULTICAST - * - ALLMULTI - */ - syncNicRxFilterMacAddr(def->ifname, guestFilter, hostFilter); - syncNicRxFilterMulticast(def->ifname, guestFilter, hostFilter); - syncNicRxFilterDeviceOptions(def->ifname, guestFilter, hostFilter); - } - - if (virDomainNetGetActualType(def) =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK)= { - const char *brname =3D virDomainNetGetActualBridgeName(def); - - /* For libivrt network connections, set the following TUN/TAP netw= ork - * device attributes to match those of the guest network device: - * - QoS filters (which are based on MAC address) - */ - if (virDomainNetGetActualBandwidth(def) && - def->data.network.actual && - virNetDevBandwidthUpdateFilter(brname, &guestFilter->mac, - def->data.network.actual->class= _id) < 0) - goto endjob; - } - endjob: virDomainObjEndJob(vm); } --=20 2.37.3 From nobody Sat May 4 15:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1666083483; cv=none; d=zohomail.com; s=zohoarc; b=V4v6MTvzSModT2EY6LlNb+DWRNx7N+t/pz5ceKqdFUol0TzpUzbbZEM7XsAUDFGySiwH8JUFnA4yafbvrA7iOSnyGwweKQWIA+6A3XC6KQEGod6n+DzjexzxM+UZ2N10WERvp3NoMiwad6Vt4Y3yrCp97K20FjCmACIe+BBDitk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666083483; 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=3hUvTwFbVuNJNL74zfJsGtM4r0BSernUgcxXOQ4QkLA=; b=CwlVWT6HmJF1IvZGOfw8h/x9gyLtpyIuuhsF0Lcd7zeUJ18kXUnmTR3xwhJKpNy2ps46+p2tN8wt0WZaA4k8qkf5pKCmAnsgYSfAwMOiWy1hkB4YFAn5Fec/sKz3M+4PcZ9AeZPPmGLHs0Ny+vom18BEUPYFG6XP3NUDa6tFP8s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1666083483908515.6035408990106; Tue, 18 Oct 2022 01:58:03 -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-42-IvtKLs-7Nj6biOL1NL4zTw-1; Tue, 18 Oct 2022 04:57:59 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D0086833AED; Tue, 18 Oct 2022 08:57:56 +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 2843B401D29; Tue, 18 Oct 2022 08:57:56 +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 ED6571946594; Tue, 18 Oct 2022 08:57:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 22F871946597 for ; Tue, 18 Oct 2022 08:57:52 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CFC854081B9B; Tue, 18 Oct 2022 08:57:52 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71676414A818 for ; Tue, 18 Oct 2022 08:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666083482; 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=3hUvTwFbVuNJNL74zfJsGtM4r0BSernUgcxXOQ4QkLA=; b=ObaUP/Xsg///+m685ALieJW+OMEJpzKVYGkOPrbIvnAK8d5RI06WAWKyi9N/5Y6CgxNm2k wHu0cVeLATN563JcD5Qcwo/CLEj4OHK09eSDNKzOyWH5/YLpnajPGVJyjooBywpDEnkV+7 zcRf5QaWdaInfBa5NYKCxpmdVWW0STA= X-MC-Unique: IvtKLs-7Nj6biOL1NL4zTw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/5] qemu: Acquire QUERY job instead of MODIFY when handling NIC_RX_FILTER_CHANGED event Date: Tue, 18 Oct 2022 10:57:47 +0200 Message-Id: <7b9f87eb773e592cfc014c9f82e9990eb85d8eae.1666083387.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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 3.1 on 10.11.54.9 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: 1666083484760100001 Content-Type: text/plain; charset="utf-8"; x-default="true" We are not updating domain XML to new MAC address, just merely setting host side of macvtap. But we don't need a MODIFY job for that, QUERY is just fine. This allows us to process the event should it occur during migration. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 86bc35ca92..d5fb2913be 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3625,7 +3625,7 @@ processNicRxFilterChangedEvent(virDomainObj *vm, "from domain %p %s", devAlias, vm, vm->def->name); =20 - if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) + if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0) return; =20 if (!virDomainObjIsActive(vm)) { --=20 2.37.3 From nobody Sat May 4 15:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1666083487; cv=none; d=zohomail.com; s=zohoarc; b=j5WDFxcNFPOQwyudLcl+6Bxx5LaXSD1dmJpkaNDGzPusUSTz25tckdjCQxUxfS3hN/YnbSGwZi0Vs2xfMGk5EAaJ4hbcEmBca/J9bPwu3KFclR58/xi7Us4yZnX00sU2KvJirBUfLaGEB9wCAxfYGldweiCbdtcm+bxXRT+x/vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666083487; 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=LsCm9iTF1wTWHMcKxig/ohwQB4//UquyXUvRkz/w7pA=; b=EapDRYwmGXumpZ3iG1aOjvK9wcT++IZPekmO6ordpJA0IrmSq0JkwDAWYPYk6LqO+HHq2kWIvV9yHJ5i/IkxWnmqHR9E1JhLWzt5OAqDn9AHVWZ8pRySgTlBT2vNtJL2/BwYc1ZQSuzl24dd8awApIWJ6QZZDWCnMkWrOvpf2Jo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1666083487117982.738165859603; Tue, 18 Oct 2022 01:58:07 -0700 (PDT) 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-248-8FyOamt3PUGDGAHOCW5ACA-1; Tue, 18 Oct 2022 04:58:01 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F2C13C1392B; Tue, 18 Oct 2022 08:57:58 +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 10E67C15BA4; Tue, 18 Oct 2022 08:57:58 +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 B225F1946A66; Tue, 18 Oct 2022 08:57:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2325319465A0 for ; Tue, 18 Oct 2022 08:57:53 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6976A40E8108; Tue, 18 Oct 2022 08:57:53 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 100DC4081B9C for ; Tue, 18 Oct 2022 08:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666083486; 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=LsCm9iTF1wTWHMcKxig/ohwQB4//UquyXUvRkz/w7pA=; b=gOVJvFVgJX41GAoJEEYnXLAoD6K5k8nN4m2EMktiUFTGK9WTxihQljxhdvSKcd9nyVTeCf 0DcX+mHoRMRGcr5RSCIbCRdtFLQ0VfQtNSKK6t4qdwPrV6fNDLk2b6LaMtIY8tl4s5V48I 7daxkarfpL59tt31JMp15okX8cTs3vI= X-MC-Unique: 8FyOamt3PUGDGAHOCW5ACA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/5] qemu: Refresh state after restore from a save image Date: Tue, 18 Oct 2022 10:57:48 +0200 Message-Id: <815063f27b32ab15ddf483ead0951da28c449c5e.1666083387.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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 3.1 on 10.11.54.8 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: 1666083488778100005 Content-Type: text/plain; charset="utf-8"; x-default="true" When restoring a domain from a save image, we need to query QEMU for some runtime information that is not stored in status XML, or even if it is, it's not parsed (e.g. virtio-mem actual size, or soon rx-filters for macvtaps). During migration, this is done in qemuMigrationDstFinishFresh(), or in case of newly started domain in qemuProcessStart(). Except, the way that the code is written, when restoring from a save image (which is effectively a migration), the state is never refreshed, because qemuProcessStart() sees incoming migration so it does not refresh the state thinking it'll be done in the finish phase. But restoring from a save image has no finish phase. Therefore, refresh the state explicitly after the domain was restored but before vCPUs are resumed. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_saveimage.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c index 79567bf17d..ef62303728 100644 --- a/src/qemu/qemu_saveimage.c +++ b/src/qemu/qemu_saveimage.c @@ -672,6 +672,8 @@ qemuSaveImageStartVM(virConnectPtr conn, VIR_DOMAIN_EVENT_STARTED_RESTORED); virObjectEventStateQueue(driver->domainEventState, event); =20 + if (qemuProcessRefreshState(driver, vm, asyncJob) < 0) + goto cleanup; =20 /* If it was running before, resume it now unless caller requested pau= se. */ if (header->was_running && !start_paused) { --=20 2.37.3 From nobody Sat May 4 15:05:36 2024 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=1666083491; cv=none; d=zohomail.com; s=zohoarc; b=LXRfLrDhoEZq5Kon9teV4eS08LYx7holQxjBdfnFjDjEIWUvhanKOkW8UaMxgCdqcil1GSzgiHG7Nrl0JmPpLPKjkH+dSMBCbU23ESU1W5ufI2zRI0HjtUrO7AQz8iPH+qGJtAH3TXniHkCPUEFysJS67vHumIaCqAc8gH6JZl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666083491; 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=FqNkREYYYpRSbgkbV7oS1Mzou4Vm9oMiahyF78r+trE=; b=kHo5v0xoB2n8IMDlSgg2ysTFWoswMVLouR4vPl1OkTx1/uEfn7NmXiZmdPrZ2EHV3lSC9rkA2zNNXjtKjWrbN5bVz+XfAYx8r+ADTSr2u0tEFhX6I6vJEwf8ksUxS37KaRLTzT3Nygh2HtOtmdbqtFJpThA8H99xdbAQVi0rI8A= 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 1666083491279881.4456435681064; Tue, 18 Oct 2022 01:58:11 -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-517-W9MCTzpYP5KbDJcKTInbkg-1; Tue, 18 Oct 2022 04:58:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5FDE018E5355; Tue, 18 Oct 2022 08:57:57 +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 130A4146820E; Tue, 18 Oct 2022 08:57:57 +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 3405F19465B7; Tue, 18 Oct 2022 08:57:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 318B919465A3 for ; Tue, 18 Oct 2022 08:57:55 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0720F4081B9E; Tue, 18 Oct 2022 08:57:54 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id A123E40EC001 for ; Tue, 18 Oct 2022 08:57:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666083490; 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=FqNkREYYYpRSbgkbV7oS1Mzou4Vm9oMiahyF78r+trE=; b=MBXV8xUeDzIxIJwoN6acYHsw2h8UdLnKTnb9unK4kjwRCQ2JQk1R+/PIIBY6w24YZ6kZ2q 2iUvtHQ/kosdfPEBZU2lSylk6KZQHDMnT9KmNUx988zkgSnZdl1lQNN4j7nIkJSsslxHGU 8IJ9LOiNYFNyGZr00KtP+lB4mcViIOg= X-MC-Unique: W9MCTzpYP5KbDJcKTInbkg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/5] qemu: Refresh rx-filters more often Date: Tue, 18 Oct 2022 10:57:49 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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 3.1 on 10.11.54.7 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: 1666083492764100009 Content-Type: text/plain; charset="utf-8"; x-default="true" There are couple of scenarios where we need to reflect MAC change done in the guest: 1) domain restore from a file (here, we don't store updated MAC in the save file and thus on restore create the macvtap with the original MAC), 2) reconnecting to a running domain (here, the guest might have changed the MAC while we were not running), 3) migration (here, guest might change the MAC address but we fail to respond to it, Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_domain.c | 9 ++++++--- src/qemu/qemu_domain.h | 3 ++- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_process.c | 27 +++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1b93ebe579..b408ec0607 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11975,14 +11975,17 @@ syncNicRxFilterMulticast(char *ifname, =20 int qemuDomainSyncRxFilter(virDomainObj *vm, - virDomainNetDef *def) + virDomainNetDef *def, + virDomainAsyncJob asyncJob) { qemuDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virNetDevRxFilter) guestFilter =3D NULL; g_autoptr(virNetDevRxFilter) hostFilter =3D NULL; int rc; =20 - qemuDomainObjEnterMonitor(vm); + if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) + return -1; + rc =3D qemuMonitorQueryRxFilter(priv->mon, def->info.alias, &guestFilt= er); qemuDomainObjExitMonitor(vm); if (rc < 0) @@ -11990,7 +11993,7 @@ qemuDomainSyncRxFilter(virDomainObj *vm, =20 if (virDomainNetGetActualType(def) =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { if (virNetDevGetRxFilter(def->ifname, &hostFilter)) { - VIR_WARN("Couldn't get current RX filter for device %s while r= esponding to NIC_RX_FILTER_CHANGED", + VIR_WARN("Couldn't get current RX filter for device %s", def->ifname); return -1; } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f436861efc..37e0a90452 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1101,4 +1101,5 @@ qemuDomainObjWait(virDomainObj *vm); =20 int qemuDomainSyncRxFilter(virDomainObj *vm, - virDomainNetDef *def); + virDomainNetDef *def, + virDomainAsyncJob asyncJob); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d5fb2913be..803d2c1771 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3662,7 +3662,7 @@ processNicRxFilterChangedEvent(virDomainObj *vm, VIR_DEBUG("process NIC_RX_FILTER_CHANGED event for network " "device %s in domain %s", def->info.alias, vm->def->name); =20 - if (qemuDomainSyncRxFilter(vm, def) < 0) + if (qemuDomainSyncRxFilter(vm, def, VIR_ASYNC_JOB_NONE) < 0) goto endjob; =20 endjob: diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 1a9175f40f..fe98601fce 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7756,6 +7756,26 @@ qemuProcessLaunch(virConnectPtr conn, } =20 =20 +static int +qemuProcessRefreshRxFilters(virDomainObj *vm, + virDomainAsyncJob asyncJob) +{ + size_t i; + + for (i =3D 0; i < vm->def->nnets; i++) { + virDomainNetDef *def =3D vm->def->nets[i]; + + if (!virDomainNetGetActualTrustGuestRxFilters(def)) + continue; + + if (qemuDomainSyncRxFilter(vm, def, asyncJob) < 0) + return -1; + } + + return 0; +} + + /** * qemuProcessRefreshState: * @driver: qemu driver data @@ -7787,6 +7807,10 @@ qemuProcessRefreshState(virQEMUDriver *driver, if (qemuProcessRefreshDisks(vm, asyncJob) < 0) return -1; =20 + VIR_DEBUG("Updating rx-filter data"); + if (qemuProcessRefreshRxFilters(vm, asyncJob) < 0) + return -1; + return 0; } =20 @@ -8807,6 +8831,9 @@ qemuProcessReconnect(void *opaque) if (qemuSecurityReserveLabel(driver->securityManager, obj->def, obj->p= id) < 0) goto error; =20 + if (qemuProcessRefreshRxFilters(obj, VIR_ASYNC_JOB_NONE) < 0) + goto error; + qemuProcessNotifyNets(obj->def); =20 qemuProcessFiltersInstantiate(obj->def); --=20 2.37.3