From nobody Wed May 8 14:58:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1576602274; cv=none; d=zohomail.com; s=zohoarc; b=YBQyYWjJ6mX7bnh74rf9fFC/v0W1vd4BH4qJ59j+4Y/jjEz7xzcHZISD+UsjFWjEWYDVV/UhmV0KYlU8LcJ47H3mz97If5jlP2Wc3eDoQMhZ/1kwgwsf8MBio/ga0swdceJOXtxs3FdTT2k+P1VT3YI6ue71r348TInEoFjP/+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576602274; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=xwQLcjkwWMwXyV5siScs8qRZRNkxl0PFQ1rrDODD4DQ=; b=IzxkrMuE8ge0yJWQHXtvb7qZ/yQo3uCLz/mJorGlmXd9QotQFW51wao+n2cpe/D+9weoXe254zXyFWmL3EGuaOiEx3QJ3RaiLh64O1RrmkO9AbzghYf7zIhXI9Kxm858R0NibJCU+TZVAaFOzTq62oqMxPU1zXfwTqoUJ/ZFbKk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1576602274258820.6319178914108; Tue, 17 Dec 2019 09:04:34 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-7LMjFDjGMyqsmnSmKoyOyA-1; Tue, 17 Dec 2019 12:04:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50B54106BCB9; Tue, 17 Dec 2019 17:04:25 +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 9D9CA7C823; Tue, 17 Dec 2019 17:04:24 +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 5FF3A18089CD; Tue, 17 Dec 2019 17:04:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBHH4LOK030983 for ; Tue, 17 Dec 2019 12:04:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8D7F561355; Tue, 17 Dec 2019 17:04:21 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-175.phx2.redhat.com [10.3.116.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47AF76137F for ; Tue, 17 Dec 2019 17:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576602272; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xwQLcjkwWMwXyV5siScs8qRZRNkxl0PFQ1rrDODD4DQ=; b=bLkP5GRUNtCbDpLuSUGsBzBg13S/2q+TlG1lzkB/WGTK/AqfrjBwLlL5C15/MulOfeFbAB waD4zM7eiPk+ITd4rqs07Vfh4VMR70G05Inz+DMArIHPnFkvjxzIpDRzURaTLlG4yX26W+ 29Km8nl/I/mFJDHpM/xUgAnvDJ2eABs= From: Laine Stump To: libvir-list@redhat.com Date: Tue, 17 Dec 2019 12:04:14 -0500 Message-Id: <20191217170414.694855-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: homogenize MAC address in live & config when hotplugging a netdev 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 7LMjFDjGMyqsmnSmKoyOyA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Prior to commit 55ce6564634 (first in libvirt 4.6.0), the XML sent to virDomainAttachDeviceFlags() was parsed only once, and the results of that parse were inserted into both the live object of the running domain and into the persistent config. Thus, if MAC address was omitted from in XML for a network device (), both the live and config object would have the same MAC address. Commit 55ce6564634 changed the code to parse the incoming XML twice - once for live and once for config. This does eliminate the problem of PCI (/scsi/sata) address conflicts caused by allocating an address based on existing devices in live object, but then inserting the result into the config (which may already have a device using that address), BUT it also means that when the MAC address of a network device hasn't been specified in the XML, each copy will get a different auto-generated MAC address. This results in the MAC address of the device changing the next time the domain is shutdown and restarted, which creates havoc with the guest OS's network config. There have been several discussions about this in the last > 1 year, attempting to find the ideal solution to this problem that makes MAC addresses consistent and accounts for all sorts of corner cases with PCI/scsi/sata addresses. All of these discussions fizzled out because every proposal was either too difficult to implement or failed to fix some esoteric case someone thought up. So, in the interest of solving the MAC address problem while not making the "other address" situation any worse than before, this patch simply adds a qemuDomainAttachDeviceLiveAndConfigHomogenize() function that (for now) copies the MAC address from the config object to the live object (if the original xml had then this will be an effective NOP (as the macs already match)). Any downstream libvirt containing upstream commit 55ce6564634 should have this patch as well. https://bugzilla.redhat.com/1783411 Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/qemu/qemu_driver.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 924f01d3eb..19ddff80b5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8623,6 +8623,30 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, return 0; } =20 + +static void +qemuDomainAttachDeviceLiveAndConfigHomogenize(const virDomainDeviceDef *de= vConf, + virDomainDeviceDefPtr devLiv= e) +{ + /* + * fixup anything that needs to be identical in the live and + * config versions of DeviceDef, but might not be. Do this by + * changing the contents of devLive. + */ + + /* MAC address should be identical in both DeviceDefs, but if it + * wasn't specified in the XML, and was instead autogenerated, it + * will be different for the two since they are each the result of + * a separate parser call. If it *was* specified, it will already + * be the same, so copying does no harm. + */ + + if (devConf->type =3D=3D VIR_DOMAIN_DEVICE_NET) + virMacAddrSet(&devLive->data.net->mac, &devConf->data.net->mac); + +} + + static int qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, virQEMUDriverPtr driver, @@ -8633,6 +8657,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr v= m, virDomainDefPtr vmdef =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; virDomainDeviceDefPtr devConf =3D NULL; + virDomainDeviceDef devConfSave =3D { 0 }; virDomainDeviceDefPtr devLive =3D NULL; int ret =3D -1; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | @@ -8657,6 +8682,13 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr = vm, parse_flags))) goto cleanup; =20 + /* + * devConf will be NULLed out by + * qemuDomainAttachDeviceConfig(), so save it for later use by + * qemuDomainDeviceLiveAndConfigHomogenize() + */ + devConfSave =3D *devConf; + if (virDomainDeviceValidateAliasForHotplug(vm, devConf, VIR_DOMAIN_AFFECT_CONFI= G) < 0) goto cleanup; @@ -8678,6 +8710,9 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr v= m, parse_flags))) goto cleanup; =20 + if (flags & VIR_DOMAIN_AFFECT_CONFIG) + qemuDomainAttachDeviceLiveAndConfigHomogenize(&devConfSave, de= vLive); + if (virDomainDeviceValidateAliasForHotplug(vm, devLive, VIR_DOMAIN_AFFECT_LIVE)= < 0) goto cleanup; --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list