From nobody Tue May 14 02:57:44 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=1647439738; cv=none; d=zohomail.com; s=zohoarc; b=EJgP2pQ/+RN1Fah92x6iWjYginSFGBRfqbGwrhS7/dkayhpnXRm07CIw1N3DFl8Qtr6BiR2Od3v6TEUtvM+xLppRHYx1hLwdXxiR7w2gLu5NuZaSS5D/nSEvd5IIqPYMxQzg+GLNKzkTTYhUYdtXY/S5+1tEyf4IzLTCPAGSmPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647439738; 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=YgJUYwOAPDF4PMo7g0k22/tjJ8ofeUvc9hZJMP61Ii0=; b=gVd/J/sJ9KuQlq2LhvEhKi28JgYL5Lg4ZusOWL+3hnhmbkpngHbHTXKjQz5XI2Y4uu7VndWbFkTLbirH9vnrmdRQlwyeOLnP8azb6VX/iWnQAtFCQNy2KcjX4whqM6gKqmYY0qGGOJqaM4mPbVYZ577fNi+bHFI1Vx71/cVK4o4= 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 1647439738720599.5177477399835; Wed, 16 Mar 2022 07:08:58 -0700 (PDT) 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-622-M-9IQMWFMvCjp5pXqq78ng-1; Wed, 16 Mar 2022 10:08:54 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B357A185A7B2; Wed, 16 Mar 2022 14:08:51 +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 9A1EE401E78; Wed, 16 Mar 2022 14:08:51 +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 18A361949762; Wed, 16 Mar 2022 14:08:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D7D331940356 for ; Wed, 16 Mar 2022 14:08:49 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B44AD400F746; Wed, 16 Mar 2022 14:08:49 +0000 (UTC) Received: from fedora.brq.redhat.com (unknown [10.34.247.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 336BD400F73E for ; Wed, 16 Mar 2022 14:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647439737; 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=YgJUYwOAPDF4PMo7g0k22/tjJ8ofeUvc9hZJMP61Ii0=; b=Q9SVNmtMR7DC+/BFvOhy1RrHAo8N0MTuMu49iVChjlAYCTdrgmsvQnDb+Ej4F5pQ/022kk 6j2AeuKoq0hGvhUQEwgKdBoHBz/WJUNmFiHfRqkFySQte8cyFZxvSc5VlUhTZrXyVCNTbH tEeOLRxXQ42ACgNVkx6h98+dVcL8Nb0= X-MC-Unique: M-9IQMWFMvCjp5pXqq78ng-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 1/2] qemu: domainjob: Allow operations if cb is not set in job structure Date: Wed, 16 Mar 2022 15:08:38 +0100 Message-Id: <783efa09f7ad910832ebd2a3e18cb62037887b7b.1647438542.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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 2.85 on 10.11.54.10 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: 1647439740879100001 Content-Type: text/plain; charset="utf-8" We should allow resetting / freeing / restoring / parsing / formatting qemuDomainJobObj even if 'cb' attribute is not set. This is theoretical for now, but the attribute must not be always set in the future. It is sufficient to check if 'cb' exists before dereferencing it. This commit partially reverts af16e754cd4efc3ca1. Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/qemu/qemu_domainjob.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c index 3e73eba4ed..7b81cd8a2b 100644 --- a/src/qemu/qemu_domainjob.c +++ b/src/qemu/qemu_domainjob.c @@ -239,8 +239,10 @@ qemuDomainObjResetAsyncJob(qemuDomainJobObj *job) job->abortJob =3D false; VIR_FREE(job->error); g_clear_pointer(&job->current, virDomainJobDataFree); - job->cb->resetJobPrivate(job->privateData); job->apiFlags =3D 0; + + if (job->cb) + job->cb->resetJobPrivate(job->privateData); } =20 int @@ -258,7 +260,8 @@ qemuDomainObjRestoreJob(virDomainObj *obj, job->privateData =3D g_steal_pointer(&priv->job.privateData); job->apiFlags =3D priv->job.apiFlags; =20 - if (!(priv->job.privateData =3D priv->job.cb->allocJobPrivate())) + if (priv->job.cb && + !(priv->job.privateData =3D priv->job.cb->allocJobPrivate())) return -1; job->cb =3D priv->job.cb; =20 @@ -270,16 +273,15 @@ qemuDomainObjRestoreJob(virDomainObj *obj, void qemuDomainObjClearJob(qemuDomainJobObj *job) { - if (!job->cb) - return; - qemuDomainObjResetJob(job); qemuDomainObjResetAsyncJob(job); - g_clear_pointer(&job->privateData, job->cb->freeJobPrivate); g_clear_pointer(&job->current, virDomainJobDataFree); g_clear_pointer(&job->completed, virDomainJobDataFree); virCondDestroy(&job->cond); virCondDestroy(&job->asyncCond); + + if (job->cb) + g_clear_pointer(&job->privateData, job->cb->freeJobPrivate); } =20 bool @@ -1228,7 +1230,8 @@ qemuDomainObjPrivateXMLFormatJob(virBuffer *buf, if (priv->job.asyncJob !=3D QEMU_ASYNC_JOB_NONE) virBufferAsprintf(&attrBuf, " flags=3D'0x%lx'", priv->job.apiFlags= ); =20 - if (priv->job.cb->formatJob(&childBuf, &priv->job, vm) < 0) + if (priv->job.cb && + priv->job.cb->formatJob(&childBuf, &priv->job, vm) < 0) return -1; =20 virXMLFormatElement(buf, "job", &attrBuf, &childBuf); @@ -1288,7 +1291,8 @@ qemuDomainObjPrivateXMLParseJob(virDomainObj *vm, return -1; } =20 - if (priv->job.cb->parseJob(ctxt, job, vm) < 0) + if (priv->job.cb && + priv->job.cb->parseJob(ctxt, job, vm) < 0) return -1; =20 return 0; --=20 2.35.1 From nobody Tue May 14 02:57:44 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=fail; 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=1647439741; cv=none; d=zohomail.com; s=zohoarc; b=KTFQcmpHt/VidBL511jmipIXOL+7zCJAf21OFuEzxfvuN/VJUSVkK2WZrmieqapy94HUfhpoGuy8j+X3vE46AWv0K3QV0VinopENPoYJRT7YSIzqaBflOuA9H/phz16pMsrCeMm83c2jvXJDAA+s0LUCgcXLkpK3oI/AzvVSrWA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647439741; 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=/E0jQSNkIEeB/yW+tqCgU6n5YNAZGGhWc5lCkuZoiAs=; b=Gb7ENFYlkAAcGHBE+hYQo00oHR3aptHoJWcGC+4ZzgWIcx774C9IkECKI3/tXb4RzCov2SAGtLpeMEoqC+gXzBegtGrM4CgO08B/ZCb8on/CGD0BQVfmnX12KkFpx2eD4xvzZTRqStT39OjVbqbOfRYlb1rRFyC4w0PXD0LjXTs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1647439741632434.172832370347; Wed, 16 Mar 2022 07:09:01 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-363-d-_7sNFaNtuVPmk8SkYvVw-1; Wed, 16 Mar 2022 10:08:54 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6972D3C1986E; Wed, 16 Mar 2022 14:08:52 +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 4F012401E80; Wed, 16 Mar 2022 14:08:52 +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 75FE0193F50C; Wed, 16 Mar 2022 14:08:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A35FD1949761 for ; Wed, 16 Mar 2022 14:08:50 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 94397404D8FB; Wed, 16 Mar 2022 14:08:50 +0000 (UTC) Received: from fedora.brq.redhat.com (unknown [10.34.247.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AE8A400F746 for ; Wed, 16 Mar 2022 14:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647439742; 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=/E0jQSNkIEeB/yW+tqCgU6n5YNAZGGhWc5lCkuZoiAs=; b=X1sjHudBxUPZVGbKP4FW2vAyGyEaKquSc9onk+rRRyAd5wrZ+AmvDghBpBDbitZtCh8gay jykyWNPvzudkbE0ItsPSAJk+md8lcBsdvmd6cmqD0JipK7RwzEdFDShykPd+XxKC+Ssugc SVrpyjQZKMWSEPt6wEYJNfk/WzBjYWg= X-MC-Unique: d-_7sNFaNtuVPmk8SkYvVw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 2/2] qemu: domainjob: Allow InitJob if cb is not set in qemuDomainObjInitJob() Date: Wed, 16 Mar 2022 15:08:39 +0100 Message-Id: <4f375805347e9891e00850dd1027b9dc59957530.1647438542.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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 2.85 on 10.11.54.10 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: fail (Signature date is -1 seconds in the future.) X-ZM-MESSAGEID: 1647439760442100001 Content-Type: text/plain; charset="utf-8" This allows init job even if cb structure is not set. This patch also includes slight rewriting of the function to make it look cleaner when freeing resources, by allocating privateData at the end. Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/qemu/qemu_domainjob.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c index 7b81cd8a2b..28c09ae179 100644 --- a/src/qemu/qemu_domainjob.c +++ b/src/qemu/qemu_domainjob.c @@ -189,17 +189,18 @@ qemuDomainObjInitJob(qemuDomainJobObj *job, memset(job, 0, sizeof(*job)); job->cb =3D cb; =20 - if (!(job->privateData =3D job->cb->allocJobPrivate())) + if (virCondInit(&job->cond) < 0) return -1; =20 - if (virCondInit(&job->cond) < 0) { - job->cb->freeJobPrivate(job->privateData); + if (virCondInit(&job->asyncCond) < 0) { + virCondDestroy(&job->cond); return -1; } =20 - if (virCondInit(&job->asyncCond) < 0) { - job->cb->freeJobPrivate(job->privateData); + if (job->cb && + !(job->privateData =3D job->cb->allocJobPrivate())) { virCondDestroy(&job->cond); + virCondDestroy(&job->asyncCond); return -1; } =20 --=20 2.35.1