From nobody Thu May 2 23:39:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1513728109810831.7527868344176; Tue, 19 Dec 2017 16:01:49 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 417CE8765D; Wed, 20 Dec 2017 00:01:47 +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 6596262660; Wed, 20 Dec 2017 00:01:45 +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 B8AE54BB79; Wed, 20 Dec 2017 00:01:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vBK01fZ7007222 for ; Tue, 19 Dec 2017 19:01:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4968F53; Wed, 20 Dec 2017 00:01:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-111.phx2.redhat.com [10.3.117.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 100DA5D969 for ; Wed, 20 Dec 2017 00:01:38 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 19 Dec 2017 19:01:37 -0500 Message-Id: <20171220000137.22529-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: Introduce qemuDomainDelChardevTLSObjects 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Dec 2017 00:01:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Let's make a comment deletion helper similar to the Add helper that can be called after the ExitMonitor. The modify qemuDomainRemoveChrDevice and qemuDomainRemoveRNGDevice to call the helper instead of inlining the copy and pasted code. Signed-off-by: John Ferlan Reviewed-by: Chen Hanxiao --- An offshoot of the redirdev hot unplug patches from Chen Hanxiao. Let's create a helper that can remove the TLS chardev objects for the specific devices that may have used them.=20 src/qemu/qemu_hotplug.c | 107 +++++++++++++++++++++++---------------------= ---- 1 file changed, 52 insertions(+), 55 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 7de04c85a..85f47bee2 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1562,6 +1562,47 @@ qemuDomainAddChardevTLSObjects(virConnectPtr conn, } =20 =20 +static int +qemuDomainDelChardevTLSObjects(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *inAlias) +{ + int ret =3D -1; + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + qemuDomainObjPrivatePtr priv =3D vm->privateData; + char *tlsAlias =3D NULL; + char *secAlias =3D NULL; + + if (!(tlsAlias =3D qemuAliasTLSObjFromSrcAlias(inAlias))) + goto cleanup; + + /* Best shot at this as the secinfo is destroyed after process launch + * and this path does not recreate it. Thus, if the config has the + * secret UUID and we have a serial TCP chardev, then formulate a + * secAlias which we'll attempt to destroy. */ + if (cfg->chardevTLSx509secretUUID && + !(secAlias =3D qemuDomainGetSecretAESAlias(inAlias, false))) + goto cleanup; + + qemuDomainObjEnterMonitor(driver, vm); + + ignore_value(qemuMonitorDelObject(priv->mon, tlsAlias)); + if (secAlias) + ignore_value(qemuMonitorDelObject(priv->mon, secAlias)); + + if (qemuDomainObjExitMonitor(driver, vm) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(tlsAlias); + VIR_FREE(secAlias); + virObjectUnref(cfg); + return ret; +} + + int qemuDomainAttachRedirdevDevice(virConnectPtr conn, virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -4120,10 +4161,7 @@ qemuDomainRemoveChrDevice(virQEMUDriverPtr driver, virDomainChrDefPtr chr) { virObjectEventPtr event; - virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); char *charAlias =3D NULL; - char *tlsAlias =3D NULL; - char *secAlias =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; int ret =3D -1; int rc; @@ -4134,34 +4172,18 @@ qemuDomainRemoveChrDevice(virQEMUDriverPtr driver, if (!(charAlias =3D qemuAliasChardevFromDevAlias(chr->info.alias))) goto cleanup; =20 - if (chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_TCP && - chr->source->data.tcp.haveTLS =3D=3D VIR_TRISTATE_BOOL_YES) { - - if (!(tlsAlias =3D qemuAliasTLSObjFromSrcAlias(charAlias))) - goto cleanup; - - /* Best shot at this as the secinfo is destroyed after process lau= nch - * and this path does not recreate it. Thus, if the config has the - * secret UUID and we have a serial TCP chardev, then formulate a - * secAlias which we'll attempt to destroy. */ - if (cfg->chardevTLSx509secretUUID && - !(secAlias =3D qemuDomainGetSecretAESAlias(charAlias, false))) - goto cleanup; - } - qemuDomainObjEnterMonitor(driver, vm); rc =3D qemuMonitorDetachCharDev(priv->mon, charAlias); =20 - if (rc =3D=3D 0) { - if (tlsAlias) - ignore_value(qemuMonitorDelObject(priv->mon, tlsAlias)); - if (secAlias) - ignore_value(qemuMonitorDelObject(priv->mon, secAlias)); - } - if (qemuDomainObjExitMonitor(driver, vm) < 0) goto cleanup; =20 + if (chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_TCP && + chr->source->data.tcp.haveTLS =3D=3D VIR_TRISTATE_BOOL_YES && + rc =3D=3D 0 && + qemuDomainDelChardevTLSObjects(driver, vm, charAlias) < 0) + goto cleanup; + virDomainAuditChardev(vm, chr, NULL, "detach", rc =3D=3D 0); =20 if (rc < 0) @@ -4185,9 +4207,6 @@ qemuDomainRemoveChrDevice(virQEMUDriverPtr driver, =20 cleanup: VIR_FREE(charAlias); - VIR_FREE(tlsAlias); - VIR_FREE(secAlias); - virObjectUnref(cfg); return ret; } =20 @@ -4198,11 +4217,8 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver, virDomainRNGDefPtr rng) { virObjectEventPtr event; - virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); char *charAlias =3D NULL; char *objAlias =3D NULL; - char *tlsAlias =3D NULL; - char *secAlias =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; ssize_t idx; int ret =3D -1; @@ -4218,34 +4234,18 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver, if (!(charAlias =3D qemuAliasChardevFromDevAlias(rng->info.alias))) goto cleanup; =20 - if (rng->backend =3D=3D VIR_DOMAIN_RNG_BACKEND_EGD) { - if (!(tlsAlias =3D qemuAliasTLSObjFromSrcAlias(charAlias))) - goto cleanup; - - /* Best shot at this as the secinfo is destroyed after process lau= nch - * and this path does not recreate it. Thus, if the config has the - * secret UUID and we have a serial TCP chardev, then formulate a - * secAlias which we'll attempt to destroy. */ - if (cfg->chardevTLSx509secretUUID && - !(secAlias =3D qemuDomainGetSecretAESAlias(charAlias, false))) - goto cleanup; - } - qemuDomainObjEnterMonitor(driver, vm); =20 rc =3D qemuMonitorDelObject(priv->mon, objAlias); =20 - if (rc =3D=3D 0 && rng->backend =3D=3D VIR_DOMAIN_RNG_BACKEND_EGD) { - ignore_value(qemuMonitorDetachCharDev(priv->mon, charAlias)); - if (tlsAlias) - ignore_value(qemuMonitorDelObject(priv->mon, tlsAlias)); - if (secAlias) - ignore_value(qemuMonitorDelObject(priv->mon, secAlias)); - } - if (qemuDomainObjExitMonitor(driver, vm) < 0) goto cleanup; =20 + if (rng->backend =3D=3D VIR_DOMAIN_RNG_BACKEND_EGD && + rc =3D=3D 0 && + qemuDomainDelChardevTLSObjects(driver, vm, charAlias) < 0) + goto cleanup; + virDomainAuditRNG(vm, rng, NULL, "detach", rc =3D=3D 0); =20 if (rc < 0) @@ -4269,9 +4269,6 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver, cleanup: VIR_FREE(charAlias); VIR_FREE(objAlias); - VIR_FREE(tlsAlias); - VIR_FREE(secAlias); - virObjectUnref(cfg); return ret; } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list