From nobody Tue May 7 06:04:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1590686442; cv=none; d=zohomail.com; s=zohoarc; b=j21Y5CSFqQzgeSKe6mC7onl3AXmG5qzE16IyuiS55IX61pGc/9eHKXpQGCq1ptSlCVMc/FFw8Tt0IU/Aax9ucxWC8qaNMemSxBfXJCiqULHT+8Y68mdHvIdzn/I+K7aQaSnodijp1Qm9Pf8HlF8aExHQ3+MGmELFOLVUObfooX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590686442; 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=ZbctiKEHxCiHC5XEmdtePOe7nEJBd9qk4K8Cz9G+ChI=; b=mLhi524s31d/Lp4LPV0hMohcoBfGDm4TgMmdef+DaOQR/MexN+k+mpI6v1KpNp5lW0woYiOEnEoDJzIiaD2dB62aSQu6hkK9H7JyHyCu7m71sf++4IFZ4yNEFSlnv/Eq8dxzK3693UZYO7GDfrkOQ82fkYfmRbQrm8Ngfv02k3Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1590686442979208.3564695066242; Thu, 28 May 2020 10:20:42 -0700 (PDT) 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-435-fT437UNENCqOvI30qnmCRw-1; Thu, 28 May 2020 13:20:39 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ED4CE1009619; Thu, 28 May 2020 17:20:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9AF70768C7; Thu, 28 May 2020 17:20: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 3D53F6B558; Thu, 28 May 2020 17:20:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04SHKFrR026032 for ; Thu, 28 May 2020 13:20:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2CBBD2156A3B; Thu, 28 May 2020 17:20:15 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DDE642156880 for ; Thu, 28 May 2020 17:20:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3EF8180CDBA for ; Thu, 28 May 2020 17:20:12 +0000 (UTC) Received: from m4a0072g.houston.softwaregrp.com (m4a0072g.houston.softwaregrp.com [15.124.2.130]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-A3GyefAZOnSwZpwGBg11UQ-1; Thu, 28 May 2020 13:20:10 -0400 Received: FROM m4a0072g.houston.softwaregrp.com (15.120.17.147) BY m4a0072g.houston.softwaregrp.com WITH ESMTP FOR libvir-list@redhat.com; Thu, 28 May 2020 17:18:59 +0000 Received: from M4W0334.microfocus.com (2002:f78:1192::f78:1192) by M4W0335.microfocus.com (2002:f78:1193::f78:1193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Thu, 28 May 2020 17:10:22 +0000 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (15.124.8.12) by M4W0334.microfocus.com (15.120.17.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10 via Frontend Transport; Thu, 28 May 2020 17:10:22 +0000 Received: from CY4PR1801MB2071.namprd18.prod.outlook.com (2603:10b6:910:79::35) by CY4PR1801MB1893.namprd18.prod.outlook.com (2603:10b6:910:75::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.19; Thu, 28 May 2020 17:10:19 +0000 Received: from CY4PR1801MB2071.namprd18.prod.outlook.com ([fe80::412:7771:b22b:7f67]) by CY4PR1801MB2071.namprd18.prod.outlook.com ([fe80::412:7771:b22b:7f67%6]) with mapi id 15.20.3021.030; Thu, 28 May 2020 17:10:19 +0000 Received: from linux-tbji.provo.novell.com (192.150.157.105) by SN4PR0501CA0035.namprd05.prod.outlook.com (2603:10b6:803:40::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.8 via Frontend Transport; Thu, 28 May 2020 17:10:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590686441; 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=ZbctiKEHxCiHC5XEmdtePOe7nEJBd9qk4K8Cz9G+ChI=; b=LVgvlCGt+yg43RD2FaI5IID1vP8R4V6FQ3ngsqWnuWxL8GpIJiUOeS8TzzXn97qyVpkzG7 sD3Tee7zQmvjiZ/dWg+dYIFpcO06Zn/yQmK3WsCauHzUIoVubmLguwWdhv7KkJJJR7uYV1 p1TKlto502lvHkH4N2ZTwbdH7Me8E7s= X-MC-Unique: fT437UNENCqOvI30qnmCRw-1 X-MC-Unique: A3GyefAZOnSwZpwGBg11UQ-1 From: Jim Fehlig To: Subject: [PATCH] libxl: Normalize MAC address in device conf when hotplugging a netdev Date: Thu, 28 May 2020 11:09:57 -0600 Message-ID: <20200528170957.5104-1-jfehlig@suse.com> X-ClientProxiedBy: SN4PR0501CA0035.namprd05.prod.outlook.com (2603:10b6:803:40::48) To CY4PR1801MB2071.namprd18.prod.outlook.com (2603:10b6:910:79::35) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Originating-IP: [192.150.157.105] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 90924d59-b60a-4c21-b1d6-08d80329ff84 X-MS-TrafficTypeDiagnostic: CY4PR1801MB1893: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-Forefront-PRVS: 0417A3FFD2 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8bo0ftvVWMDzzDrH5AbevWigwOBH36sIqTDBCbtsLY1OP+g7yPHVI5ZaEeP3LCdf10+1U+SnB0bmkdQyhWjuX9eZbln27YRnUG9tzSs9xnI8ihzCKD3w0Iti1IleM1dyku/Ooezk/NRN88tqPihAQrozP44eq2AOfHz0VrxXR5jZZ5y6cCenJ6wisvYnAYS1ZVVjCZcaV05EOHpXHAN8VNB6EsRaMAS/eVfHOwSGh2nnsgK84iRgKRkHuS2aKpN7ra5sUXU5IaLFIGsm400kDxLaRK2NBbyh+32yF3YeiNIkanCk0SnPvGnSSvm4NLBT X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY4PR1801MB2071.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(396003)(39860400002)(366004)(346002)(136003)(376002)(26005)(52116002)(316002)(6506007)(5660300002)(6666004)(1076003)(36756003)(86362001)(2906002)(6512007)(66946007)(8676002)(66476007)(66556008)(107886003)(2616005)(6916009)(956004)(16526019)(186003)(83380400001)(6486002)(478600001)(4326008)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: VfI7v0zWW/OrLbVU/f+V0i5HiPEiCx9pqt6EZvgwXwPzbO6lf8k/L2mR0qssNqoFLkROfFgOUlLso31bctZZ4FbDKCdbtKqPkaB0XOmlxYZbN0tdeQD+OU2iTceg6+2+vOuVEDZucwQpZ+tKSbHZjvysl3YbmTquomjoHjylfh8i4L/ieESQjv2mVDPjycxGP/j+CA9CYE/rraaRK81KssIRCMthJ5iWr5Oic2vnzjK5nWK6sS9t+wQtjUX2z4ZcV9mu2AbRjbIzMdv18KgoQe25TRmNdPddpKh1kUf0ZUBG6LICi5DzlN3xI6PYkkhxPtZpLSzgDaHpkryPSaYB90wCtyyMNLYNg/xDY9Q8QoEaFX32S510qCb/Z/cnG6Cof7iK8mXIN4PRrymlef9Yo6j5R+JkdqTuZR7UqoaEfFy+vZd8oPSf3J9Lm530/htWeyGEAB9WU5m5F2+k74cE3ID0onLgKLPpJ5Ejh3eZcIU6iDBd0Qw275DyPL86xiDe X-MS-Exchange-CrossTenant-Network-Message-Id: 90924d59-b60a-4c21-b1d6-08d80329ff84 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2020 17:10:19.3610 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZPE6bDgnJCy5HEvAwZryIJAKWypx5bhK0Ydexy0Qmbo3mE5mcM+kHS/hstsV3NHhYA3JntRXAaFdlfSgk9pycQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1801MB1893 X-OriginatorOrg: suse.com X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 04SHKFrR026032 X-loop: libvir-list@redhat.com 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.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Similar to commit 6c17606b7cc, normalize the MAC addresses in persistent and live device config to avoid a different MAC address for the device once the VM is rebooted and persistent config takes affect. Signed-off-by: Jim Fehlig Reviewed-by: Laine Stump --- src/libxl/libxl_driver.c | 56 +++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 63ec0a2188..a80bc3fe3a 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -4096,6 +4096,31 @@ libxlDomainUpdateDeviceConfig(virDomainDefPtr vmdef,= virDomainDeviceDefPtr dev) } =20 =20 +static void +libxlDomainAttachDeviceNormalize(const virDomainDeviceDef *devConf, + virDomainDeviceDefPtr devLive) +{ + /* + * 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. This is done after all + * post-parse tweaks and validation, so be very careful about what + * changes are made. + */ + + /* 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 libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, unsigned int flags) @@ -4104,7 +4129,9 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const = char *xml, libxlDriverConfigPtr cfg =3D libxlDriverConfigGet(driver); virDomainObjPtr vm =3D NULL; virDomainDefPtr vmdef =3D NULL; - virDomainDeviceDefPtr dev =3D NULL; + virDomainDeviceDefPtr devConf =3D NULL; + virDomainDeviceDef devConfSave =3D { 0 }; + virDomainDeviceDefPtr devLive =3D NULL; int ret =3D -1; =20 virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE | @@ -4123,28 +4150,36 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, cons= t char *xml, goto endjob; =20 if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { - if (!(dev =3D virDomainDeviceDefParse(xml, vm->def, - driver->xmlopt, NULL, - VIR_DOMAIN_DEF_PARSE_INACTIVE)= )) + if (!(devConf =3D virDomainDeviceDefParse(xml, vm->def, + driver->xmlopt, NULL, + VIR_DOMAIN_DEF_PARSE_INACT= IVE))) goto endjob; =20 /* Make a copy for updated domain. */ if (!(vmdef =3D virDomainObjCopyPersistentDef(vm, driver->xmlopt, = NULL))) goto endjob; =20 - if (libxlDomainAttachDeviceConfig(vmdef, dev) < 0) + /* + * devConf will be NULLed out by + * libxlDomainAttachDeviceConfig(), so save it for later use by + * libxlDomainAttachDeviceNormalize() + */ + devConfSave =3D *devConf; + + if (libxlDomainAttachDeviceConfig(vmdef, devConf) < 0) goto endjob; } =20 if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) { - /* If dev exists it was created to modify the domain config. Free = it. */ - virDomainDeviceDefFree(dev); - if (!(dev =3D virDomainDeviceDefParse(xml, vm->def, + if (!(devLive =3D virDomainDeviceDefParse(xml, vm->def, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE)= )) goto endjob; =20 - if (libxlDomainAttachDeviceLive(driver, vm, dev) < 0) + if (flags & VIR_DOMAIN_AFFECT_CONFIG) + libxlDomainAttachDeviceNormalize(&devConfSave, devLive); + + if (libxlDomainAttachDeviceLive(driver, vm, devLive) < 0) goto endjob; =20 /* @@ -4171,7 +4206,8 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const = char *xml, =20 cleanup: virDomainDefFree(vmdef); - virDomainDeviceDefFree(dev); + virDomainDeviceDefFree(devConf); + virDomainDeviceDefFree(devLive); virDomainObjEndAPI(&vm); virObjectUnref(cfg); return ret; --=20 2.26.0