From nobody Mon Feb 9 10:32:34 2026 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=1669210483; cv=none; d=zohomail.com; s=zohoarc; b=nZqeZ9Qpn7yTt5Dmn+/NO3KvYpm65xMEZJZgq0QMPG4IdwOHoN+6ALYnNpzho8FbZswQjx9jK9PBtbwGnKTXLPAdM29IyInZEr44JlRFFHWC348KfeQD3KHBZmx5GAeEGnnlhpqahXUAKkhjMkCiONqhSKG0fK/DCiaNijbu/dg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669210483; 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=Z2ikUt0s4ssZz/cauo5hsKQVqNtIjo108qxGZe2f7LY=; b=DaSrVoanf7jLlYtSkAUIWFa3xaH4NTLwgQopKmy5U717E5+0VksVflzOKOOXJ0lkyAo7SxrQoGCeKK7Y6DxbAlbq4KF0Oyk3VfHynfXetvu5KtnU/gxbfkKVDutobZd4WPOf/PbMt8ZzcNyspNvwNjM7BBu+/Xa/EDV9vTpmb7c= 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 1669210483156648.3773927159099; Wed, 23 Nov 2022 05:34:43 -0800 (PST) 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-532-ncvWbccOPNag3x4waoHKVw-1; Wed, 23 Nov 2022 08:34:33 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E721787A9E3; Wed, 23 Nov 2022 13:34:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE44540C2086; Wed, 23 Nov 2022 13:34:30 +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 8534E1946A40; Wed, 23 Nov 2022 13:34:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A0BDC1946587 for ; Wed, 23 Nov 2022 12:36:46 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 92A712166B31; Wed, 23 Nov 2022 12:36:46 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03ECA2166B26 for ; Wed, 23 Nov 2022 12:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669210482; 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=Z2ikUt0s4ssZz/cauo5hsKQVqNtIjo108qxGZe2f7LY=; b=eN+nSJARpDqVP2nknDJ7W3wEEQ3xHkDl3IHpEoYM4M1VWX8qXDGEsM6GUXSwUX9iY75+G7 RjJtsr4kUP0xiXnxBUAWUGGFmJ3uGM/9TDZ2SjP9N7w45pcLeemtSszUAXbktX/Vs1xezr s4CyW7JkRPkFDoexYNBSzocBvsyA6ZE= X-MC-Unique: ncvWbccOPNag3x4waoHKVw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/7] qemuDomainDetachDeviceLiveAndConfig: Parse XML twice rather than use virDomainDeviceDefCopy Date: Wed, 23 Nov 2022 13:36:37 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.1 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: 1669210484850100001 Content-Type: text/plain; charset="utf-8" 'virDomainDeviceDefCopy' formats the definition and parses it back. Since we already are parsing the XML here, we're better off parsing it twice and save the formatting step. Signed-off-by: Peter Krempa --- src/qemu/qemu_driver.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ef0a2e06fd..bb345ef017 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7865,8 +7865,8 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *dr= iver, { qemuDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; - g_autoptr(virDomainDeviceDef) dev =3D NULL; - virDomainDeviceDef *dev_copy =3D NULL; + g_autoptr(virDomainDeviceDef) dev_config =3D NULL; + g_autoptr(virDomainDeviceDef) dev_live =3D NULL; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; g_autoptr(virDomainDef) vmdef =3D NULL; int ret =3D -1; @@ -7880,21 +7880,15 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *= driver, !(flags & VIR_DOMAIN_AFFECT_LIVE)) parse_flags |=3D VIR_DOMAIN_DEF_PARSE_INACTIVE; - dev =3D dev_copy =3D virDomainDeviceDefParse(xml, vm->def, - driver->xmlopt, priv->qemuCap= s, - parse_flags); - if (dev =3D=3D NULL) - goto cleanup; + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + if (!(dev_config =3D virDomainDeviceDefParse(xml, vm->def, driver-= >xmlopt, + priv->qemuCaps, parse_f= lags))) + goto cleanup; + } - if (flags & VIR_DOMAIN_AFFECT_CONFIG && - flags & VIR_DOMAIN_AFFECT_LIVE) { - /* If we are affecting both CONFIG and LIVE - * create a deep copy of device as adding - * to CONFIG takes one instance. - */ - dev_copy =3D virDomainDeviceDefCopy(dev, vm->def, - driver->xmlopt, priv->qemuCaps); - if (!dev_copy) + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (!(dev_live =3D virDomainDeviceDefParse(xml, vm->def, driver->x= mlopt, + priv->qemuCaps, parse_fla= gs))) goto cleanup; } @@ -7904,7 +7898,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *dr= iver, if (!vmdef) goto cleanup; - if (qemuDomainDetachDeviceConfig(vmdef, dev_copy, priv->qemuCaps, + if (qemuDomainDetachDeviceConfig(vmdef, dev_config, priv->qemuCaps, parse_flags, driver->xmlopt) < 0) goto cleanup; @@ -7913,7 +7907,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *dr= iver, if (flags & VIR_DOMAIN_AFFECT_LIVE) { int rc; - if ((rc =3D qemuDomainDetachDeviceLive(vm, dev, driver, false)) < = 0) + if ((rc =3D qemuDomainDetachDeviceLive(vm, dev_live, driver, false= )) < 0) goto cleanup; if (rc =3D=3D 0 && qemuDomainUpdateDeviceList(vm, VIR_ASYNC_JOB_NO= NE) < 0) @@ -7933,8 +7927,6 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *dr= iver, ret =3D 0; cleanup: - if (dev !=3D dev_copy) - virDomainDeviceDefFree(dev_copy); return ret; } --=20 2.37.3