From nobody Wed May 15 17:11:20 2024 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=1644845601; cv=none; d=zohomail.com; s=zohoarc; b=Bvky3d/NbUIuld0eUVBOdfkxSUQQJr4TvsJc/JS/9muHtAY7ZhRdj1r8VGZ9HuruqjoG+O+JL3TQ5AU3IDbhDkeOn0qShdkv0FJEcwhO2XqYgl9Xi4MVfnoyMEFQK3h8GRADRwNoc4Vqnf2ZYiuUFzxUJWq0wfQNNSc1pCqdT/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644845601; 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=mUHjA8NbPJNdPiv0YHscj28d/leerLhQ+k1ogYYtZ2o=; b=CZsuuwG09QocCnknOhgdUeV59d0F3SUmuYYwNHV1lhZ3hdMhn2eXVFwj1iAGG/QbgPCKycloOcxBMp2Ulvo4kSk04EsmhTiXesxHewnEwSW38M6OnElpW2y+1+nx9FVP2Hqk9HuWGhYzMpUOJvdrRDAOIExnWiDidxFQi3ahlc0= 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 1644845601873260.80928047304474; Mon, 14 Feb 2022 05:33:21 -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-661-RxXWI97qPJqLeLjVqAG5pQ-1; Mon, 14 Feb 2022 08:33:19 -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 4B2091018F60; Mon, 14 Feb 2022 13:33:14 +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 0B2EE108F847; Mon, 14 Feb 2022 13:33: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 982464A7CA; Mon, 14 Feb 2022 13:33:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21EDXAR3009437 for ; Mon, 14 Feb 2022 08:33:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id E021D7C0FE; Mon, 14 Feb 2022 13:33:10 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A00418038 for ; Mon, 14 Feb 2022 13:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644845600; 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=mUHjA8NbPJNdPiv0YHscj28d/leerLhQ+k1ogYYtZ2o=; b=AZ5BKmJg5mrYCZV2kkdjlEe2hz//biNzHIwJOK3HuNeqqXfdBXqjv55CA4N0ClJjRNgf31 d5a4E/souwzey2n62du7Qsdy9vyk7hMygYo9HbOZ34j2m83HcKmO0uIQHw4D3rYCqBlDj7 XihfdfR0H/YtDraxGSAtlFWjECyzulo= X-MC-Unique: RxXWI97qPJqLeLjVqAG5pQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] tests: Track if @vm was created by qemuMonitorCommonTestNew() Date: Mon, 14 Feb 2022 14:32:56 +0100 Message-Id: <0b7dab9d72d6b429fc938d518803835f92678691.1644844874.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: 1644845603114100001 Content-Type: text/plain; charset="utf-8" There are two ways how a domain object can appear in _qemuMonitorTest structure. Either it was created by qemuMonitorCommonTestNew() or caller created the object and we are just leasing it. But this also means we have to release the domain object differently. If the domain object was created by us, then we must unlock and unref it (which is what virDomainObjEndAPI()) does, but if it just a leased object then we have to refrain from unlocking it because this would create lock/unlock imbalance. Moreover, caller might want to keep the object locked. Signed-off-by: Michal Privoznik --- tests/qemumonitortestutils.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 86300da68a..bb7a8e1191 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -84,6 +84,7 @@ struct _qemuMonitorTest { qemuMonitorTestItem **items; =20 virDomainObj *vm; + bool vm_created; GHashTable *qapischema; }; =20 @@ -406,7 +407,10 @@ qemuMonitorTestFree(qemuMonitorTest *test) =20 g_object_unref(test->eventThread); =20 - virObjectUnref(test->vm); + if (test->vm_created) + virDomainObjEndAPI(&test->vm); + else + virObjectUnref(test->vm); =20 if (test->started) virThreadJoin(&test->thread); @@ -1025,6 +1029,7 @@ qemuMonitorCommonTestNew(virDomainXMLOption *xmlopt, return NULL; if (!(test->vm->def =3D virDomainDefNew(xmlopt))) return NULL; + test->vm_created =3D true; } =20 if (virNetSocketNewListenUNIX(path, 0700, geteuid(), getegid(), --=20 2.34.1 From nobody Wed May 15 17:11:20 2024 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=1644845616; cv=none; d=zohomail.com; s=zohoarc; b=mG7QL2TxCFvbQypcB3Mq9zeKtWa5Z6Mv6dlhitX41OeBUri5ZMoAuvTpBmbdiubBJcZAu6+0ubeyQpRje5OYXt3sWf86lfGj7PuTCy8FyMfxK4QWrbLpPqM9aZ3OOhrsaP96deMhTLVi9YjsiO85IUAz08ZTpR+B4/NJBKkZsOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644845616; 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=PuEiJEjA+Qmt7GHcySGw0ZXLnhDuLggXvWkiNusGyaE=; b=atVEAjXS8d22WeOUcq4hUdob3xcXk5FVR1yyq2MYQNFlyi6lnghmG3MyoIcZpc7rnVlPth/+dMqD9UTNxzI2XirUvuM+heME6p5qHBQJsCcJjfcfLIWFAUwm7PU6zKswkrUiNFM1NmYeTakBNBTgOSnc+28LO43WoVyGc3C1ieg= 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 1644845616639511.78890448762286; Mon, 14 Feb 2022 05:33:36 -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-112-4J1yI_u6P1irZ01VKj4tMw-1; Mon, 14 Feb 2022 08:33:32 -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 1865581432F; Mon, 14 Feb 2022 13:33:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB1E6108F847; Mon, 14 Feb 2022 13:33:26 +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 29FD71809CBA; Mon, 14 Feb 2022 13:33:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21EDXB80009442 for ; Mon, 14 Feb 2022 08:33:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id ADD4C7C0FE; Mon, 14 Feb 2022 13:33:11 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37BA018038 for ; Mon, 14 Feb 2022 13:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644845615; 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=PuEiJEjA+Qmt7GHcySGw0ZXLnhDuLggXvWkiNusGyaE=; b=Z8c8Rj4iP8TP9XYPopoJ8gDwveqQNIMV0uOzRkCH8FippF6OM4HEsqXOOLsQvNj6KFtjXQ e2VwmeHNNAu0x8jJHYone/OrnyfwG/U4XC36vgh9FL+CY+FhrkTsL2CS0Xu3NFOsoyugbS /+UU7cn82VbnQbRplAM/fDi8i9gWlKw= X-MC-Unique: 4J1yI_u6P1irZ01VKj4tMw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] tests: Destroy domain object properly Date: Mon, 14 Feb 2022 14:32:57 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: 1644845617238100001 Content-Type: text/plain; charset="utf-8" In a lot of cases we do plain virObjectUnref() with the domain object lock held. While this looks okay, what really happens under the hood is that we destroy a locked mutex. But with a help from virDomainObjEndAPI() we can do the right thing and unlock the mutex before destroying it. Signed-off-by: Michal Privoznik --- tests/qemuhotplugtest.c | 13 +++++-------- tests/qemusecuritytest.c | 3 ++- tests/qemuxml2argvtest.c | 22 +++++++++++++--------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 263a92425c..de136f7987 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -278,7 +278,7 @@ testQemuHotplug(const void *data) goto cleanup; =20 if (test->vm) { - vm =3D test->vm; + vm =3D g_steal_pointer(&test->vm); if (!vm->def) { VIR_TEST_VERBOSE("test skipped due to failure of dependent tes= t"); goto cleanup; @@ -352,12 +352,9 @@ testQemuHotplug(const void *data) /* don't dispose test monitor with VM */ if (priv) priv->mon =3D NULL; - if (keep) { - test->vm =3D vm; - } else { - virObjectUnref(vm); - test->vm =3D NULL; - } + if (keep) + test->vm =3D g_steal_pointer(&vm); + virDomainObjEndAPI(&vm); virDomainDeviceDefFree(dev); return ((ret < 0 && fail) || (!ret && !fail)) ? 0 : -1; } @@ -397,7 +394,7 @@ testQemuHotplugCpuDataFree(struct testQemuHotplugCpuDat= a *data) priv =3D data->vm->privateData; priv->mon =3D NULL; =20 - virObjectUnref(data->vm); + virDomainObjEndAPI(&data->vm); } =20 if (data->mon) { diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c index 924c625a4c..2a7641dc83 100644 --- a/tests/qemusecuritytest.c +++ b/tests/qemusecuritytest.c @@ -86,7 +86,7 @@ static int testDomain(const void *opaque) { const struct testData *data =3D opaque; - g_autoptr(virDomainObj) vm =3D NULL; + virDomainObj *vm =3D NULL; g_autoptr(GHashTable) notRestored =3D virHashNew(NULL); size_t i; int ret =3D -1; @@ -126,6 +126,7 @@ testDomain(const void *opaque) =20 ret =3D 0; cleanup: + virDomainObjEndAPI(&vm); g_unsetenv(ENVVAR); freePaths(); return ret; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 6cf35a0ebf..794d76c776 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -642,11 +642,12 @@ testCompareXMLToArgvValidateSchema(virQEMUDriver *drv, unsigned int flags) { g_auto(GStrv) args =3D NULL; - g_autoptr(virDomainObj) vm =3D NULL; + virDomainObj *vm =3D NULL; qemuDomainObjPrivate *priv =3D NULL; GHashTable *schema =3D NULL; g_autoptr(virCommand) cmd =3D NULL; unsigned int parseFlags =3D info->parseFlags; + int ret =3D -1; =20 /* comment out with line comment to enable schema checking for non _CA= PS tests if (!info->schemafile) @@ -669,29 +670,32 @@ testCompareXMLToArgvValidateSchema(virQEMUDriver *drv, return 0; =20 if (!(vm =3D virDomainObjNew(driver.xmlopt))) - return -1; + goto cleanup; =20 parseFlags |=3D VIR_DOMAIN_DEF_PARSE_INACTIVE; if (!(vm->def =3D virDomainDefParseFile(info->infile, driver.xmlopt, NULL, parseFlags))) - return -1; + goto cleanup; =20 priv =3D vm->privateData; =20 if (virBitmapParse("0-3", &priv->autoNodeset, 4) < 0) - return -1; + goto cleanup; =20 if (!(cmd =3D testCompareXMLToArgvCreateArgs(drv, vm, migrateURI, info= , flags))) - return -1; + goto cleanup; =20 if (virCommandGetArgList(cmd, &args) < 0) - return -1; + goto cleanup; =20 if (testCompareXMLToArgvValidateSchemaCommand(args, schema) < 0) - return -1; + goto cleanup; =20 - return 0; + ret =3D 0; + cleanup: + virDomainObjEndAPI(&vm); + return ret; } =20 =20 @@ -885,7 +889,7 @@ testCompareXMLToArgv(const void *data) =20 cleanup: virDomainChrSourceDefClear(&monitor_chr); - virObjectUnref(vm); + virDomainObjEndAPI(&vm); virIdentitySetCurrent(NULL); virSetConnectSecret(NULL); virSetConnectStorage(NULL); --=20 2.34.1