From nobody Sun Feb 8 18:09:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1644508479; cv=none; d=zohomail.com; s=zohoarc; b=Sin46MbxmHjwgP8lZxGI6QS/2984+9dkwYbR1gogVCH0ZdDtCOxgM4IOgu0jMjoVqqjCFpIJqGD8gk8ouNAY2AazKvQFHlFVgQKzhy3FND5/bbuH7qFdgUEuI5ki8IK4KZi0PjRvNXUowfBGWTWIJt/6iaM3J2/obLM8S5UtEX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644508479; 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=1GbBvbwOXxoOJZZHBEs9xY1JIqroCbrB9K8ZwddsSrc=; b=lG+OGI74AsCaYbl7XIPuohdRHNKbMUp1vmuwnHd3vM/bePywlA0GXY6kAHSsx8bjTxmTytb11dW+KrCQxwKMROtMzFDDNzzTRz7fJuMGfHoR04faTeI8zv+1OQSnaZgTe4U6qPGtNEyBnR2VBg2jdAVbpxYPEv9nJkvcIYHioIg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1644508479387768.0734266085955; Thu, 10 Feb 2022 07:54:39 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-173-QFgllSxDNv2zMH9kyDFblA-1; Thu, 10 Feb 2022 10:54:36 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C529107B279; Thu, 10 Feb 2022 15:54:31 +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 274DC1062220; Thu, 10 Feb 2022 15:54:31 +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 C961F4CA93; Thu, 10 Feb 2022 15:54:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21AFpegj011380 for ; Thu, 10 Feb 2022 10:51:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8812E75748; Thu, 10 Feb 2022 15:51:40 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12B8975133 for ; Thu, 10 Feb 2022 15:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644508478; 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=1GbBvbwOXxoOJZZHBEs9xY1JIqroCbrB9K8ZwddsSrc=; b=YJH7BHM8k32QdDqQsSC+ilYRRr3ci6D6YM+xYGGMQeN6fkhe7ghMGc4uoX134GdfxMBVgF 78MlrESDPfwPV0RuBSzU54e4oJkI1mYLRQNWle4vG5/f35omQwMYbJOL3pN7CQehF9Ft+m YGmwIHZiWIAdr1YmdT75xvOyazgwz4Y= X-MC-Unique: QFgllSxDNv2zMH9kyDFblA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/6] ch_driver: Introduce and use virCHDomainRemoveInactive() Date: Thu, 10 Feb 2022 16:51:33 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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: 1644508480086100001 Content-Type: text/plain; charset="utf-8" There are few places where a call to virDomainObjListRemove() is guarded with !vm->persistent check. And there are some places which are missing this check completely (leading us to losing a domain). To prevent such mistakes introduce virCHDomainRemoveInactive() which does the check for us. Also replace all occurrences of virDomainObjListRemove() with the call to the new function. Signed-off-by: Michal Privoznik --- src/ch/ch_domain.c | 9 +++++++++ src/ch/ch_domain.h | 4 ++++ src/ch/ch_driver.c | 17 +++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index 0b4dbbf142..25f581c1c3 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -136,6 +136,15 @@ virCHDomainObjEndJob(virDomainObj *obj) virCondSignal(&priv->job.cond); } =20 +void +virCHDomainRemoveInactive(virCHDriver *driver, + virDomainObj *vm) +{ + if (vm->persistent) { + virDomainObjListRemove(driver->domains, vm); + } +} + static void * virCHDomainObjPrivateAlloc(void *opaque) { diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index c1d3be212e..11a20a874a 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -88,6 +88,10 @@ virCHDomainObjBeginJob(virDomainObj *obj, enum virCHDoma= inJob job) void virCHDomainObjEndJob(virDomainObj *obj); =20 +void +virCHDomainRemoveInactive(virCHDriver *driver, + virDomainObj *vm); + int virCHDomainRefreshThreadInfo(virDomainObj *vm); =20 diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index cd156a222b..ef74a00bf7 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -237,7 +237,7 @@ chDomainCreateXML(virConnectPtr conn, =20 cleanup: if (vm && !dom) { - virDomainObjListRemove(driver->domains, vm); + virCHDomainRemoveInactive(driver, vm); } virDomainObjEndAPI(&vm); return dom; @@ -342,10 +342,9 @@ chDomainUndefineFlags(virDomainPtr dom, goto cleanup; } =20 - if (virDomainObjIsActive(vm)) { - vm->persistent =3D 0; - } else { - virDomainObjListRemove(driver->domains, vm); + vm->persistent =3D 0; + if (!virDomainObjIsActive(vm)) { + virCHDomainRemoveInactive(driver, vm); } =20 ret =3D 0; @@ -608,12 +607,14 @@ chDomainDestroyFlags(virDomainPtr dom, unsigned int f= lags) if (virDomainObjCheckActive(vm) < 0) goto endjob; =20 - ret =3D virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED); + if (virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED) < 0) + goto endjob; + + virCHDomainRemoveInactive(driver, vm); + ret =3D 0; =20 endjob: virCHDomainObjEndJob(vm); - if (!vm->persistent) - virDomainObjListRemove(driver->domains, vm); =20 cleanup: virDomainObjEndAPI(&vm); --=20 2.34.1