From nobody Sun Apr 28 08:16:45 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 1506421456732373.18788832526093; Tue, 26 Sep 2017 03:24:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6938181DF7; Tue, 26 Sep 2017 10:24:15 +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 9A52A77D42; Tue, 26 Sep 2017 10:24:14 +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 E0B6C4EE50; Tue, 26 Sep 2017 10:24:13 +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 v8QA5XjE014646 for ; Tue, 26 Sep 2017 06:05:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id B7EAE757BC; Tue, 26 Sep 2017 10:05:33 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE48B757C5; Tue, 26 Sep 2017 10:05:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6938181DF7 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 26 Sep 2017 12:05:02 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH] qemu: domain: Extract common clearing of VM private data 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 26 Sep 2017 10:24:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" VM private data is cleared when the VM is turned off and also when the VM object is being freed. Some of the clearing code was duplicated. Extract it to a separate function. This also removes the now unnecessary function qemuDomainClearPrivatePaths. --- src/qemu/qemu_domain.c | 76 +++++++++++++++++++++++++++++++++------------= ---- src/qemu/qemu_domain.h | 4 +-- src/qemu/qemu_process.c | 36 ++--------------------- 3 files changed, 55 insertions(+), 61 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index cb371f1e8..7cb2bfce1 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1684,16 +1684,6 @@ qemuDomainSetPrivatePaths(virQEMUDriverPtr driver, } -void -qemuDomainClearPrivatePaths(virDomainObjPtr vm) -{ - qemuDomainObjPrivatePtr priv =3D vm->privateData; - - VIR_FREE(priv->libDir); - VIR_FREE(priv->channelTargetDir); -} - - static void * qemuDomainObjPrivateAlloc(void *opaque) { @@ -1721,24 +1711,69 @@ qemuDomainObjPrivateAlloc(void *opaque) return NULL; } -static void -qemuDomainObjPrivateFree(void *data) +/** + * qemuDomainObjPrivateDataClear: + * @priv: domain private data + * + * Clears private data entries, which are not necessary or stale if the VM= is + * not running. + */ +void +qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv) { - qemuDomainObjPrivatePtr priv =3D data; + virStringListFree(priv->qemuDevices); + priv->qemuDevices =3D NULL; + + virCgroupFree(&priv->cgroup); + + virPerfFree(priv->perf); + priv->perf =3D NULL; + + VIR_FREE(priv->machineName); virObjectUnref(priv->qemuCaps); + priv->qemuCaps =3D NULL; - virBitmapFree(priv->namespaces); + VIR_FREE(priv->pidfile); - virCgroupFree(&priv->cgroup); + VIR_FREE(priv->libDir); + VIR_FREE(priv->channelTargetDir); + + /* remove automatic pinning data */ + virBitmapFree(priv->autoNodeset); + priv->autoNodeset =3D NULL; + virBitmapFree(priv->autoCpuset); + priv->autoCpuset =3D NULL; + + /* remove address data */ virDomainPCIAddressSetFree(priv->pciaddrs); + priv->pciaddrs =3D NULL; virDomainUSBAddressSetFree(priv->usbaddrs); + priv->usbaddrs =3D NULL; + + /* clean up migration data */ + VIR_FREE(priv->migTLSAlias); + virCPUDefFree(priv->origCPU); + priv->origCPU =3D NULL; + + /* clear previously used namespaces */ + virBitmapFree(priv->namespaces); + priv->namespaces =3D NULL; +} + + +static void +qemuDomainObjPrivateFree(void *data) +{ + qemuDomainObjPrivatePtr priv =3D data; + + qemuDomainObjPrivateDataClear(priv); + virDomainChrSourceDefFree(priv->monConfig); qemuDomainObjFreeJob(priv); VIR_FREE(priv->lockState); VIR_FREE(priv->origname); - virStringListFree(priv->qemuDevices); virChrdevFree(priv->devs); /* This should never be non-NULL if we get here, but just in case... */ @@ -1751,19 +1786,10 @@ qemuDomainObjPrivateFree(void *data) qemuAgentClose(priv->agent); } VIR_FREE(priv->cleanupCallbacks); - virBitmapFree(priv->autoNodeset); - virBitmapFree(priv->autoCpuset); - - VIR_FREE(priv->machineName); - VIR_FREE(priv->libDir); - VIR_FREE(priv->channelTargetDir); qemuDomainSecretInfoFree(&priv->migSecinfo); - VIR_FREE(priv->migTLSAlias); qemuDomainMasterKeyFree(priv); - virCPUDefFree(priv->origCPU); - VIR_FREE(priv); } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 09201b1a4..cdf94b2f6 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -676,6 +676,8 @@ void qemuDomainCleanupRemove(virDomainObjPtr vm, void qemuDomainCleanupRun(virQEMUDriverPtr driver, virDomainObjPtr vm); +void qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv); + extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks; extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace; extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig; @@ -783,8 +785,6 @@ int qemuDomainNetVLAN(virDomainNetDefPtr def); int qemuDomainSetPrivatePaths(virQEMUDriverPtr driver, virDomainObjPtr vm); -void qemuDomainClearPrivatePaths(virDomainObjPtr vm); - virDomainDiskDefPtr qemuDomainDiskByName(virDomainDefPtr def, const char *= name); char *qemuDomainGetMasterKeyFilePath(const char *libDir); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c104985aa..0a2493770 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6196,8 +6196,6 @@ void qemuProcessStop(virQEMUDriverPtr driver, virFileDeleteTree(priv->libDir); virFileDeleteTree(priv->channelTargetDir); - qemuDomainClearPrivatePaths(vm); - ignore_value(virDomainChrDefForeach(vm->def, false, qemuProcessCleanupChardevDevice, @@ -6248,9 +6246,6 @@ void qemuProcessStop(virQEMUDriverPtr driver, VIR_FREE(vm->def->seclabels[i]->imagelabel); } - virStringListFree(priv->qemuDevices); - priv->qemuDevices =3D NULL; - qemuHostdevReAttachDomainDevices(driver, vm->def); def =3D vm->def; @@ -6319,10 +6314,6 @@ void qemuProcessStop(virQEMUDriverPtr driver, VIR_WARN("Failed to remove cgroup for %s", vm->def->name); } - virCgroupFree(&priv->cgroup); - - virPerfFree(priv->perf); - priv->perf =3D NULL; qemuProcessRemoveDomainStatus(driver, vm); @@ -6376,37 +6367,14 @@ void qemuProcessStop(virQEMUDriverPtr driver, } } - VIR_FREE(priv->machineName); - vm->taint =3D 0; vm->pid =3D -1; virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason); for (i =3D 0; i < vm->def->niothreadids; i++) vm->def->iothreadids[i]->thread_id =3D 0; - virObjectUnref(priv->qemuCaps); - priv->qemuCaps =3D NULL; - VIR_FREE(priv->pidfile); - /* remove automatic pinning data */ - virBitmapFree(priv->autoNodeset); - priv->autoNodeset =3D NULL; - virBitmapFree(priv->autoCpuset); - priv->autoCpuset =3D NULL; - - /* remove address data */ - virDomainPCIAddressSetFree(priv->pciaddrs); - priv->pciaddrs =3D NULL; - virDomainUSBAddressSetFree(priv->usbaddrs); - priv->usbaddrs =3D NULL; - - /* clean up migration data */ - VIR_FREE(priv->migTLSAlias); - virCPUDefFree(priv->origCPU); - priv->origCPU =3D NULL; - - /* clear previously used namespaces */ - virBitmapFree(priv->namespaces); - priv->namespaces =3D NULL; + /* clear all private data entries which are no longer needed */ + qemuDomainObjPrivateDataClear(priv); /* The "release" hook cleans up additional resources */ if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list