From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1602167242; cv=none; d=zohomail.com; s=zohoarc; b=gYxVVmdOe+QtGoem8tquzSlmsJ8w+26hWujIC9WzUftu0dz8jX02GG8rlos7ZHjhUvRClqEkUFqF2nvcBgXyo5U2tSnwLyhl6hMQjPn6Zb7LJh2GN+W5oq4TzPsJ3Kxv7BgpfKI9ncft9O3aex/E/e0EKBpUFPm7NNve7lshq4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167242; 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=TAw5EQooBn6UImsdl/+VlYDOwdejBL7ynJkXMFH57cM=; b=dkxgeGDA3DWr6HYw1Vbu6DD92yiaq2jVXzusFfE6Fp19uEB3EGrPxWSnTsBrK1BrXkjNmMXYeXGtqmtuIDo8hGd0qgGaPgeObjRk0tLUrqcyS68RZ4dacC+vDyf9YamgZmgHl6kYp8MZPzcL3mzQDpFZl8bMhlEuxcpcJu4/wUM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1602167242849116.7413818221454; Thu, 8 Oct 2020 07:27:22 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-17--hCqOhWhN-yhRk5LGBuJqQ-1; Thu, 08 Oct 2020 10:27:19 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73DA510BBEC2; Thu, 8 Oct 2020 14:27:13 +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 15A945576B; Thu, 8 Oct 2020 14:27:13 +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 AA7951832FC3; Thu, 8 Oct 2020 14:27:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098ER88f017166 for ; Thu, 8 Oct 2020 10:27:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4951D9F58; Thu, 8 Oct 2020 14:27:08 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAF8D6715F for ; Thu, 8 Oct 2020 14:27:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167241; 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=TAw5EQooBn6UImsdl/+VlYDOwdejBL7ynJkXMFH57cM=; b=XS++RD2AnlUs8tnwqiQh3QY0AJjz+fOTbA9xGqpKv4vUHBbE/48bTvoxGw7z/cPY+pbSJZ bQQrFhN9X6cviG4JxxHRSJCwXt0WcaWkhalgoB+ha9dLUCc4C169XHXVZw7GLuBHwaaBo6 MM8FBSX7kDJy1vpxIEWuMQJo0YJFvLo= X-MC-Unique: -hCqOhWhN-yhRk5LGBuJqQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 01/10] qemu_cgroup: introduce qemuRestoreCgroupThread helper Date: Thu, 8 Oct 2020 16:26:54 +0200 Message-Id: <3fda17cb20857fa64d67390fa5deeef0ea5f392c.1602167149.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.79 on 10.5.11.15 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- src/qemu/qemu_cgroup.c | 71 +++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index b671991ad6..9017753053 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -960,16 +960,41 @@ qemuInitCgroup(virDomainObjPtr vm, return 0; } =20 -static void -qemuRestoreCgroupState(virDomainObjPtr vm) +static int +qemuRestoreCgroupThread(virCgroupPtr cgroup, + virCgroupThreadName thread, + int id) { - g_autofree char *mem_mask =3D NULL; + virCgroupPtr cgroup_temp =3D NULL; g_autofree char *nodeset =3D NULL; + int ret =3D -1; + + if (virCgroupNewThread(cgroup, thread, id, false, &cgroup_temp) < 0) + goto cleanup; + + if (virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0) + goto cleanup; + + if (virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0) + goto cleanup; + + if (virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virCgroupFree(&cgroup_temp); + return ret; +} + +static void +qemuRestoreCgroupState(virDomainObjPtr vm) +{ + g_autofree char *mem_mask =3D NULL; int empty =3D -1; qemuDomainObjPrivatePtr priv =3D vm->privateData; size_t i =3D 0; g_autoptr(virBitmap) all_nodes =3D NULL; - virCgroupPtr cgroup_temp =3D NULL; =20 if (!virNumaIsAvailable() || !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET= )) @@ -994,45 +1019,27 @@ qemuRestoreCgroupState(virDomainObjPtr vm) if (!vcpu->online) continue; =20 - if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, i, - false, &cgroup_temp) < 0 || - virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0 || - virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0 || - virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0) - goto cleanup; - - VIR_FREE(nodeset); - virCgroupFree(&cgroup_temp); + if (qemuRestoreCgroupThread(priv->cgroup, + VIR_CGROUP_THREAD_VCPU, i) < 0) + return; } =20 for (i =3D 0; i < vm->def->niothreadids; i++) { - if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_IOTHREAD, - vm->def->iothreadids[i]->iothread_id, - false, &cgroup_temp) < 0 || - virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0 || - virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0 || - virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0) - goto cleanup; - - VIR_FREE(nodeset); - virCgroupFree(&cgroup_temp); + if (qemuRestoreCgroupThread(priv->cgroup, VIR_CGROUP_THREAD_IOTHRE= AD, + vm->def->iothreadids[i]->iothread_id) = < 0) + return; } =20 - if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, - false, &cgroup_temp) < 0 || - virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0 || - virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0 || - virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0) - goto cleanup; + if (qemuRestoreCgroupThread(priv->cgroup, + VIR_CGROUP_THREAD_EMULATOR, 0) < 0) + return; =20 - cleanup: - virCgroupFree(&cgroup_temp); return; =20 error: virResetLastError(); VIR_DEBUG("Couldn't restore cgroups to meaningful state"); - goto cleanup; + return; } =20 int --=20 2.26.2 From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1602167291; cv=none; d=zohomail.com; s=zohoarc; b=NoRF/1y37x80LV7mOB/+us2cUW/XhZInqm1BWUdB44OAvuPj7RUtRWcOH5tRSk0s6ZHFyHDb28/Ea5u0VKUv06REmIIANaiODl2VjuLXXKibLJDTCBE0ufh7iCbKBFkH85XFOB11yqoY020QQ8sk9C5DnvtJOpkihlcycfpSgD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167291; 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=t2NenzeXC2j/QD5KnUlMPjOPjzKZ/wB61Q2S5lfJPII=; b=FF7Zh5Mu7Yse1+5VlFpYWGMdXIhs50xDn0c61uPapLNu2MOGfThEP7KDn4URBwJjAKDQSZ4ugmKCAF1kkKgyTS0/Uv8aQsMVrOGNdWWjqynWxtO+OTo2bj3WcANoELRc3IDI4ctgljrrTkSyzKLMizpemJR6ASOf/bTA9UKZ9M4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1602167291033292.35672503745855; Thu, 8 Oct 2020 07:28:11 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-oqGe6mXYMjm7Y2P7pvb0sg-1; Thu, 08 Oct 2020 10:27:33 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 595AB1007464; Thu, 8 Oct 2020 14:27:27 +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 34E4619C4F; Thu, 8 Oct 2020 14:27:27 +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 EE6E08C7C4; Thu, 8 Oct 2020 14:27:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098ER9DG017176 for ; Thu, 8 Oct 2020 10:27:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A7059F58; Thu, 8 Oct 2020 14:27:09 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D2BF61176 for ; Thu, 8 Oct 2020 14:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167289; 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=t2NenzeXC2j/QD5KnUlMPjOPjzKZ/wB61Q2S5lfJPII=; b=e3CzRhEkKtsClm0XxseZIDWYe+fYCSU325ykJKqG8f/f53kgd4GQWKT54GquTYTGTPKImh 2WmdU12Yb4JCPTghYtgo+8GKrpBoPR7vP3RK5Ryiotzsf6K3LbKHFnqLiQ/4svTOQ2SBDF a5mbv/JIIUkoSHQw7eOenKzMz/NWRvs= X-MC-Unique: oqGe6mXYMjm7Y2P7pvb0sg-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 02/10] util: vircgroup: use GLib alloc functions Date: Thu, 8 Oct 2020 16:26:55 +0200 Message-Id: <888fd2a992af28923964ca0c59d0b4d6d878629e.1602167149.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.23 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- src/util/vircgroup.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 5c0543c66a..d52c0305f4 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -785,10 +785,8 @@ virCgroupSetPartitionSuffix(const char *path, char **r= es) */ if (STRNEQ(tokens[i], "") && !strchr(tokens[i], '.')) { - if (VIR_REALLOC_N(tokens[i], - strlen(tokens[i]) + strlen(".partition") + 1= ) < 0) - goto cleanup; - strcat(tokens[i], ".partition"); + g_autofree char *oldtoken =3D tokens[i]; + tokens[i] =3D g_strdup_printf("%s.partition", oldtoken); } =20 if (virCgroupPartitionEscape(&(tokens[i])) < 0) --=20 2.26.2 From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602167256; cv=none; d=zohomail.com; s=zohoarc; b=ZM5a7OJrgntRj/I3rQ/IOKtOcttOSiljLpuwWXzrR3OQwO2mp0ILeFzhukCWf0UIUN5Iw7v+OHMVZjZn5Xu4iNfIjZEdi8l1XK8cz5u8n78nZoUJVklke9FyuwVRjCMu7qI4X0rTccLCCwDhDDztepMmrNCa1YniL8KUS5sq1yM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167256; 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=Hbz6dgKUDt7+Ppsm0NuaJdXJpM/bLI3dwBT+V0ZONdo=; b=hLoEp7Z14GGnetmFE+8pAVroZgdoYHizZf1CDPzALg2jRXjtk8K4hQ0XRj2e7GF50K/ubW/tSL4IKHCFSkhZWrqkBbVCvh8sRIAWijI/i/W1m0L2VPyE1PFOksbBe5S4QjxruI4pJDULlRa5ezMOcqfYBY68WfaASP18qZxBMsw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602167256931374.6986653633138; Thu, 8 Oct 2020 07:27:36 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-82-G-d3J9CbMCS0-dAichURcQ-1; Thu, 08 Oct 2020 10:27:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 64456D6880; Thu, 8 Oct 2020 14:27: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 43DB75D9F1; Thu, 8 Oct 2020 14:27:27 +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 0F83B1832FC4; Thu, 8 Oct 2020 14:27:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098ERAXR017192 for ; Thu, 8 Oct 2020 10:27:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3990C9F58; Thu, 8 Oct 2020 14:27:10 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F21A61176 for ; Thu, 8 Oct 2020 14:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167255; 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=Hbz6dgKUDt7+Ppsm0NuaJdXJpM/bLI3dwBT+V0ZONdo=; b=fn7c13SCFAitCJQ9oF6j0tmT0IZEa+LAFT5wFqaBQj0Kp6XsFlyQm4tRFKJGAIpD5/UAGX HfnXJ9UsfVc8n8LmnmlmnQL4uS1yTFRtPOm47Cw475I1VW9MAdPvR8qb1Myp9BwF8U862i exY1RqabSK/qFC3zfihn9qF/v8CWJ24= X-MC-Unique: G-d3J9CbMCS0-dAichURcQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 03/10] util: vircgroup: change virCgroupFree to take only virCgroupPtr Date: Thu, 8 Oct 2020 16:26:56 +0200 Message-Id: <8f98f57c4fba7f4bba69667a807643fc5dba8c8e.1602167149.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.79 on 10.5.11.14 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) Content-Type: text/plain; charset="utf-8" As preparation for g_autoptr() we need to change the function to take only virCgroupPtr. Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- src/libvirt-lxc.c | 4 +- src/lxc/lxc_cgroup.c | 4 +- src/lxc/lxc_container.c | 2 +- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_domain.c | 2 +- src/lxc/lxc_process.c | 11 +++--- src/qemu/qemu_cgroup.c | 12 +++--- src/qemu/qemu_domain.c | 3 +- src/qemu/qemu_driver.c | 32 +++++++-------- src/qemu/qemu_process.c | 2 +- src/util/vircgroup.c | 65 +++++++++++++++++-------------- src/util/vircgroup.h | 2 +- src/util/vircgroupv1.c | 2 +- tests/vircgrouptest.c | 48 +++++++++++------------ tools/virt-host-validate-common.c | 2 +- 15 files changed, 102 insertions(+), 91 deletions(-) diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c index 25f1cfc5f7..73daf123f0 100644 --- a/src/libvirt-lxc.c +++ b/src/libvirt-lxc.c @@ -307,12 +307,12 @@ int virDomainLxcEnterCGroup(virDomainPtr domain, if (virCgroupAddProcess(cgroup, getpid()) < 0) goto error; =20 - virCgroupFree(&cgroup); + virCgroupFree(cgroup); =20 return 0; =20 error: virDispatchError(NULL); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return -1; } diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index d13f2adde5..b80a8911f9 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -168,7 +168,7 @@ int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo) =20 ret =3D 0; cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -417,7 +417,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, def->idmap.uidmap[0].target, def->idmap.gidmap[0].target, (1 << VIR_CGROUP_CONTROLLER_SYSTEMD)) < 0) { - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return NULL; } } diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index d1aa622be4..913f4de26a 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1668,7 +1668,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr= vmDef, ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index f70731bc64..e6dee85ec7 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -310,7 +310,7 @@ static void virLXCControllerFree(virLXCControllerPtr ct= rl) g_free(ctrl->nbdpids); =20 g_free(ctrl->nsFDs); - virCgroupFree(&ctrl->cgroup); + virCgroupFree(ctrl->cgroup); =20 /* This must always be the last thing to be closed */ VIR_FORCE_CLOSE(ctrl->handshakeFd); diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index d8aebe06d9..df60519fca 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -168,7 +168,7 @@ virLXCDomainObjPrivateFree(void *data) { virLXCDomainObjPrivatePtr priv =3D data; =20 - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); virLXCDomainObjFreeJob(priv); g_free(priv); } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 16969dbf33..a98a090893 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -236,7 +236,8 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, =20 if (priv->cgroup) { virCgroupRemove(priv->cgroup); - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); + priv->cgroup =3D NULL; } =20 /* Get machined to terminate the machine as it may not have cleaned it @@ -1202,26 +1203,26 @@ int virLXCProcessStart(virConnectPtr conn, =20 if (!virCgroupHasController(selfcgroup, VIR_CGROUP_CONTROLLER_CPUACCT)) { - virCgroupFree(&selfcgroup); + virCgroupFree(selfcgroup); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find 'cpuacct' cgroups controller moun= t")); return -1; } if (!virCgroupHasController(selfcgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { - virCgroupFree(&selfcgroup); + virCgroupFree(selfcgroup); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find 'devices' cgroups controller moun= t")); return -1; } if (!virCgroupHasController(selfcgroup, VIR_CGROUP_CONTROLLER_MEMORY)) { - virCgroupFree(&selfcgroup); + virCgroupFree(selfcgroup); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find 'memory' cgroups controller mount= ")); return -1; } - virCgroupFree(&selfcgroup); + virCgroupFree(selfcgroup); =20 if (vm->def->nconsoles =3D=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 9017753053..473ca8a414 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -921,7 +921,8 @@ qemuInitCgroup(virDomainObjPtr vm, if (!virCgroupAvailable()) return 0; =20 - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); + priv->cgroup =3D NULL; =20 if (!vm->def->resource) { virDomainResourceDefPtr res; @@ -983,7 +984,7 @@ qemuRestoreCgroupThread(virCgroupPtr cgroup, =20 ret =3D 0; cleanup: - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); return ret; } =20 @@ -1054,7 +1055,8 @@ qemuConnectCgroup(virDomainObjPtr vm) if (!virCgroupAvailable()) return 0; =20 - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); + priv->cgroup =3D NULL; =20 if (virCgroupNewDetectMachine(vm->def->name, "qemu", @@ -1150,7 +1152,7 @@ qemuSetupCgroupForExtDevices(virDomainObjPtr vm, ret =3D qemuExtDevicesSetupCgroup(driver, vm, cgroup_temp); =20 cleanup: - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); =20 return ret; } @@ -1221,7 +1223,7 @@ qemuCgroupEmulatorAllNodesDataFree(qemuCgroupEmulator= AllNodesDataPtr data) if (!data) return; =20 - virCgroupFree(&data->emulatorCgroup); + virCgroupFree(data->emulatorCgroup); VIR_FREE(data->emulatorMemMask); VIR_FREE(data); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9623123d3c..2d7f61f5e9 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1725,7 +1725,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr= priv) g_strfreev(priv->qemuDevices); priv->qemuDevices =3D NULL; =20 - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); + priv->cgroup =3D NULL; =20 virPerfFree(priv->perf); priv->perf =3D NULL; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8ef812cd94..60e043115f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4583,7 +4583,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, =20 cleanup: virBitmapFree(tmpmap); - virCgroupFree(&cgroup_vcpu); + virCgroupFree(cgroup_vcpu); virObjectEventStateQueue(driver->domainEventState, event); return ret; } @@ -4809,7 +4809,7 @@ qemuDomainPinEmulator(virDomainPtr dom, =20 cleanup: if (cgroup_emulator) - virCgroupFree(&cgroup_emulator); + virCgroupFree(cgroup_emulator); virObjectEventStateQueue(driver->domainEventState, event); virBitmapFree(pcpumap); virDomainObjEndAPI(&vm); @@ -5287,7 +5287,7 @@ qemuDomainPinIOThread(virDomainPtr dom, =20 cleanup: if (cgroup_iothread) - virCgroupFree(&cgroup_iothread); + virCgroupFree(cgroup_iothread); virObjectEventStateQueue(driver->domainEventState, event); virBitmapFree(pcpumap); virDomainObjEndAPI(&vm); @@ -8717,7 +8717,7 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm, false, &cgroup_temp) < 0 || virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) goto cleanup; - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); =20 for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def); i++) { virDomainVcpuDefPtr vcpu =3D virDomainDefGetVcpu(vm->def, i); @@ -8729,7 +8729,7 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm, false, &cgroup_temp) < 0 || virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) goto cleanup; - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); } =20 for (i =3D 0; i < vm->def->niothreadids; i++) { @@ -8738,7 +8738,7 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm, false, &cgroup_temp) < 0 || virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) goto cleanup; - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); } =20 /* set nodeset for root cgroup */ @@ -8747,7 +8747,7 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm, =20 ret =3D 0; cleanup: - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); =20 return ret; } @@ -9164,13 +9164,13 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupPtr= cgroup, if (qemuSetupCgroupVcpuBW(cgroup_vcpu, period, quota) < 0) goto cleanup; =20 - virCgroupFree(&cgroup_vcpu); + virCgroupFree(cgroup_vcpu); } =20 return 0; =20 cleanup: - virCgroupFree(&cgroup_vcpu); + virCgroupFree(cgroup_vcpu); return -1; } =20 @@ -9191,11 +9191,11 @@ qemuSetEmulatorBandwidthLive(virCgroupPtr cgroup, if (qemuSetupCgroupVcpuBW(cgroup_emulator, period, quota) < 0) goto cleanup; =20 - virCgroupFree(&cgroup_emulator); + virCgroupFree(cgroup_emulator); return 0; =20 cleanup: - virCgroupFree(&cgroup_emulator); + virCgroupFree(cgroup_emulator); return -1; } =20 @@ -9222,13 +9222,13 @@ qemuSetIOThreadsBWLive(virDomainObjPtr vm, virCgrou= pPtr cgroup, if (qemuSetupCgroupVcpuBW(cgroup_iothread, period, quota) < 0) goto cleanup; =20 - virCgroupFree(&cgroup_iothread); + virCgroupFree(cgroup_iothread); } =20 return 0; =20 cleanup: - virCgroupFree(&cgroup_iothread); + virCgroupFree(cgroup_iothread); return -1; } =20 @@ -9601,7 +9601,7 @@ qemuGetVcpusBWLive(virDomainObjPtr vm, ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup_vcpu); + virCgroupFree(cgroup_vcpu); return ret; } =20 @@ -9624,7 +9624,7 @@ qemuGetEmulatorBandwidthLive(virCgroupPtr cgroup, ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup_emulator); + virCgroupFree(cgroup_emulator); return ret; } =20 @@ -9660,7 +9660,7 @@ qemuGetIOThreadsBWLive(virDomainObjPtr vm, ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup_iothread); + virCgroupFree(cgroup_iothread); return ret; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6b5de29fdb..5bc76a75e3 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2750,7 +2750,7 @@ qemuProcessSetupPid(virDomainObjPtr vm, if (cgroup) { if (ret < 0) virCgroupRemove(cgroup); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); } =20 return ret; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index d52c0305f4..04876c6596 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -680,7 +680,7 @@ virCgroupNew(pid_t pid, return 0; =20 error: - virCgroupFree(group); + virCgroupFree(*group); *group =3D NULL; =20 return -1; @@ -860,9 +860,11 @@ virCgroupNewPartition(const char *path, =20 ret =3D 0; cleanup: - if (ret !=3D 0) - virCgroupFree(group); - virCgroupFree(&parent); + if (ret !=3D 0) { + virCgroupFree(*group); + *group =3D NULL; + } + virCgroupFree(parent); return ret; } =20 @@ -923,7 +925,8 @@ virCgroupNewDomainPartition(virCgroupPtr partition, */ if (virCgroupMakeGroup(partition, *group, create, VIR_CGROUP_MEM_HIERACHY) < 0) { - virCgroupFree(group); + virCgroupFree(*group); + *group =3D NULL; return -1; } =20 @@ -976,7 +979,8 @@ virCgroupNewThread(virCgroupPtr domain, return -1; =20 if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_THREAD) < 0)= { - virCgroupFree(group); + virCgroupFree(*group); + *group =3D NULL; return -1; } =20 @@ -1019,7 +1023,8 @@ virCgroupNewDetectMachine(const char *name, machinename)) { VIR_DEBUG("Failed to validate machine name for '%s' driver '%s= '", name, drivername); - virCgroupFree(group); + virCgroupFree(*group); + *group =3D NULL; return 0; } } @@ -1059,13 +1064,13 @@ virCgroupEnableMissingControllers(char *path, goto cleanup; =20 if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0)= { - virCgroupFree(&tmp); + virCgroupFree(tmp); goto cleanup; } if (t) { *t =3D '/'; offset =3D t; - virCgroupFree(&parent); + virCgroupFree(parent); parent =3D tmp; } else { *group =3D tmp; @@ -1075,7 +1080,7 @@ virCgroupEnableMissingControllers(char *path, =20 ret =3D 0; cleanup: - virCgroupFree(&parent); + virCgroupFree(parent); return ret; } =20 @@ -1130,7 +1135,7 @@ virCgroupNewMachineSystemd(const char *name, break; } } - virCgroupFree(&init); + virCgroupFree(init); =20 if (!path || STREQ(path, "/") || path[0] !=3D '/') { VIR_DEBUG("Systemd didn't setup its controller, path=3D%s", @@ -1148,7 +1153,8 @@ virCgroupNewMachineSystemd(const char *name, =20 virErrorPreserveLast(&saved); virCgroupRemove(*group); - virCgroupFree(group); + virCgroupFree(*group); + *group =3D NULL; virErrorRestore(&saved); } =20 @@ -1199,7 +1205,8 @@ virCgroupNewMachineManual(const char *name, =20 virErrorPreserveLast(&saved); virCgroupRemove(*group); - virCgroupFree(group); + virCgroupFree(*group); + *group =3D NULL; virErrorRestore(&saved); } =20 @@ -1207,7 +1214,7 @@ virCgroupNewMachineManual(const char *name, ret =3D 0; =20 cleanup: - virCgroupFree(&parent); + virCgroupFree(parent); return ret; } =20 @@ -2059,12 +2066,12 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, sum_cpu_time[j] +=3D tmp; } =20 - virCgroupFree(&group_vcpu); + virCgroupFree(group_vcpu); } =20 ret =3D 0; cleanup: - virCgroupFree(&group_vcpu); + virCgroupFree(group_vcpu); return ret; } =20 @@ -2556,7 +2563,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, if (dormdir) virCgroupRemove(subgroup); =20 - virCgroupFree(&subgroup); + virCgroupFree(subgroup); } if (direrr < 0) goto cleanup; @@ -2565,7 +2572,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, ret =3D killedAny ? 1 : 0; =20 cleanup: - virCgroupFree(&subgroup); + virCgroupFree(subgroup); VIR_DIR_CLOSE(dp); return ret; } @@ -2767,7 +2774,7 @@ virCgroupControllerAvailable(int controller) return ret; =20 ret =3D virCgroupHasController(cgroup, controller); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -3534,24 +3541,24 @@ virCgroupControllerAvailable(int controller G_GNUC_= UNUSED) * @group: The group structure to free */ void -virCgroupFree(virCgroupPtr *group) +virCgroupFree(virCgroupPtr group) { size_t i; =20 - if (*group =3D=3D NULL) + if (group =3D=3D NULL) return; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_FREE((*group)->legacy[i].mountPoint); - VIR_FREE((*group)->legacy[i].linkPoint); - VIR_FREE((*group)->legacy[i].placement); + VIR_FREE(group->legacy[i].mountPoint); + VIR_FREE(group->legacy[i].linkPoint); + VIR_FREE(group->legacy[i].placement); } =20 - VIR_FREE((*group)->unified.mountPoint); - VIR_FREE((*group)->unified.placement); + VIR_FREE(group->unified.mountPoint); + VIR_FREE(group->unified.placement); =20 - VIR_FREE((*group)->path); - VIR_FREE(*group); + VIR_FREE(group->path); + VIR_FREE(group); } =20 =20 @@ -3568,7 +3575,7 @@ virCgroupDelThread(virCgroupPtr cgroup, =20 /* Remove the offlined cgroup */ virCgroupRemove(new_cgroup); - virCgroupFree(&new_cgroup); + virCgroupFree(new_cgroup); } =20 return 0; diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 1dcd0688f1..691bec610f 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -107,7 +107,7 @@ int virCgroupTerminateMachine(const char *name) =20 bool virCgroupNewIgnoreError(void); =20 -void virCgroupFree(virCgroupPtr *group); +void virCgroupFree(virCgroupPtr group); =20 bool virCgroupHasController(virCgroupPtr cgroup, int controller); int virCgroupPathOfController(virCgroupPtr group, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 5504441fa6..52d2a17d39 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1484,7 +1484,7 @@ virCgroupV1MemoryOnceInit(void) "memory.limit_in_bytes", &mem_unlimited)); cleanup: - virCgroupFree(&group); + virCgroupFree(group); virCgroupV1MemoryUnlimitedKB =3D mem_unlimited >> 10; } =20 diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index e5be556104..632d33efcd 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -217,7 +217,7 @@ testCgroupDetectMounts(const void *args) cleanup: g_unsetenv("VIR_CGROUP_MOCK_FILENAME"); VIR_FREE(parsed); - virCgroupFree(&group); + virCgroupFree(group); return result; } =20 @@ -245,7 +245,7 @@ static int testCgroupNewForSelf(const void *args G_GNUC= _UNUSED) ret =3D validateCgroup(cgroup, "", mountsFull, links, placement, NULL,= NULL, 0); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -322,7 +322,7 @@ static int testCgroupNewForPartition(const void *args G= _GNUC_UNUSED) goto cleanup; } ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsSma= ll, links, placementSmall, NULL, NULL, 0); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); =20 if ((rv =3D virCgroupNewPartition("/virtualmachines", true, -1, &cgrou= p)) !=3D 0) { fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv= ); @@ -331,7 +331,7 @@ static int testCgroupNewForPartition(const void *args G= _GNUC_UNUSED) ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsFul= l, links, placementFull, NULL, NULL, 0); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -371,7 +371,7 @@ static int testCgroupNewForPartitionNested(const void *= args G_GNUC_UNUSED) } =20 /* Should now work */ - virCgroupFree(&cgroup); + virCgroupFree(cgroup); if ((rv =3D virCgroupNewPartition("/deployment/production", true, -1, = &cgroup)) !=3D 0) { fprintf(stderr, "Failed to create /deployment/production cgroup: %= d\n", -rv); goto cleanup; @@ -381,7 +381,7 @@ static int testCgroupNewForPartitionNested(const void *= args G_GNUC_UNUSED) mountsFull, links, placementFull, NULL, NULL, 0); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -420,14 +420,14 @@ static int testCgroupNewForPartitionNestedDeep(const = void *args G_GNUC_UNUSED) goto cleanup; } =20 - virCgroupFree(&cgroup); + virCgroupFree(cgroup); if ((rv =3D virCgroupNewPartition("/user/berrange.user", true, -1, &cg= roup)) !=3D 0) { fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n= ", -rv); goto cleanup; } =20 /* Should now work */ - virCgroupFree(&cgroup); + virCgroupFree(cgroup); if ((rv =3D virCgroupNewPartition("/user/berrange.user/production", tr= ue, -1, &cgroup)) !=3D 0) { fprintf(stderr, "Failed to create /user/berrange.user/production c= group: %d\n", -rv); goto cleanup; @@ -437,7 +437,7 @@ static int testCgroupNewForPartitionNestedDeep(const vo= id *args G_GNUC_UNUSED) mountsFull, links, placementFull, NULL, NULL, 0); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -473,8 +473,8 @@ static int testCgroupNewForPartitionDomain(const void *= args G_GNUC_UNUSED) ret =3D validateCgroup(domaincgroup, "/production.partition/foo.libvir= t-lxc", mountsFull, links, placement, NULL, NULL, 0); =20 cleanup: - virCgroupFree(&partitioncgroup); - virCgroupFree(&domaincgroup); + virCgroupFree(partitioncgroup); + virCgroupFree(domaincgroup); return ret; } =20 @@ -524,10 +524,10 @@ static int testCgroupNewForPartitionDomainEscaped(con= st void *args G_GNUC_UNUSED ret =3D validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evi= l.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0); =20 cleanup: - virCgroupFree(&partitioncgroup3); - virCgroupFree(&partitioncgroup2); - virCgroupFree(&partitioncgroup1); - virCgroupFree(&domaincgroup); + virCgroupFree(partitioncgroup3); + virCgroupFree(partitioncgroup2); + virCgroupFree(partitioncgroup1); + virCgroupFree(domaincgroup); return ret; } =20 @@ -553,7 +553,7 @@ static int testCgroupNewForSelfAllInOne(const void *arg= s G_GNUC_UNUSED) ret =3D validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, plac= ement, NULL, NULL, 0); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -564,7 +564,7 @@ static int testCgroupNewForSelfLogind(const void *args = G_GNUC_UNUSED) =20 if (virCgroupNewSelf(&cgroup) >=3D 0) { fprintf(stderr, "Expected to fail, only systemd cgroup available.\= n"); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return -1; } =20 @@ -592,7 +592,7 @@ static int testCgroupNewForSelfUnified(const void *args= G_GNUC_UNUSED) ret =3D validateCgroup(cgroup, "", empty, empty, empty, "/not/really/sys/fs/cgroup", "/", controllers); cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -630,7 +630,7 @@ static int testCgroupNewForSelfHybrid(const void *args = G_GNUC_UNUSED) "/not/really/sys/fs/cgroup/unified", "/", control= lers); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -756,7 +756,7 @@ static int testCgroupGetPercpuStats(const void *args G_= GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); VIR_FREE(params); return ret; } @@ -789,7 +789,7 @@ static int testCgroupGetMemoryUsage(const void *args G_= GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -849,7 +849,7 @@ testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -900,7 +900,7 @@ static int testCgroupGetBlkioIoServiced(const void *arg= s G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -973,7 +973,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const voi= d *args G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index c3784bb91d..4d8ec38f88 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -315,7 +315,7 @@ int virHostValidateCGroupControllers(const char *hvname, } } =20 - virCgroupFree(&group); + virCgroupFree(group); =20 return ret; } --=20 2.26.2 From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1602167261; cv=none; d=zohomail.com; s=zohoarc; b=E+YfNC6LcvyfiU5mMmXHHPfGiMqAmms292+7TE7A+YyM9L4bTmMQcB6zu/VK1/R8IbjTioDP+qNuJ2yf8yb+TUDbfVWom9PQlXyBjRiwlUE6jglYpDZXzZnjwPkxmv+NZOC/6BZzfRk5NZedKxdmY7u/yvQxbAGSq/+/QOVzADY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167261; 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=s8s6azQdAHUWsmo8VCWkvDQy98lHDPBKTsCXCp4aILs=; b=AlBdWm3hta/LRxWZtyqlXka1JBrQQzWEjuHBty6RM0HlVNy64Rj6v675lT6JmeVKlpjOYT5E/t65EqjQV0vb9kL/iNzYIO1GVj8JE2l12zZXFHGb6IMbEO1N5klah/ZKPnMvQDnBc6EzJctdRMhjOTTyClHOdwShy9Zr+KJujg0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1602167261363186.64034702165475; Thu, 8 Oct 2020 07:27:41 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-11-coL32yVwOqOfWetLx5lYEg-1; Thu, 08 Oct 2020 10:27:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F128191E2AB; Thu, 8 Oct 2020 14:27:30 +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 0C4F26EF64; Thu, 8 Oct 2020 14:27:30 +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 CADFB8C7C4; Thu, 8 Oct 2020 14:27:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098ERBUm017204 for ; Thu, 8 Oct 2020 10:27:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1CF7D9F58; Thu, 8 Oct 2020 14:27:11 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EB1A61176 for ; Thu, 8 Oct 2020 14:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167260; 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=s8s6azQdAHUWsmo8VCWkvDQy98lHDPBKTsCXCp4aILs=; b=QcUtYVRTvRviB1c/ce2MP+bXRazJjplTEXOBwKJoVVYEOyJBZJw/XuW0kjC/8xMpEaZK5P Tf9pNkOdTfn20kKL5g0NClsbBf4JiLn5HPhv8/X0RsbsQsA2kgUbvHJ9DH4t7feshvkDVB nPGcri2c1kYCJCv5c1jkfrjB4zFHzI8= X-MC-Unique: coL32yVwOqOfWetLx5lYEg-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 04/10] util: vircgroup: introduce g_autoptr() for virCgroup Date: Thu, 8 Oct 2020 16:26:57 +0200 Message-Id: <8434845a60c446b10d8cbf494a4f0ec1067f6283.1602167149.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- src/util/vircgroup.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 691bec610f..78770f5d3b 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -109,6 +109,8 @@ bool virCgroupNewIgnoreError(void); =20 void virCgroupFree(virCgroupPtr group); =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCgroup, virCgroupFree); + bool virCgroupHasController(virCgroupPtr cgroup, int controller); int virCgroupPathOfController(virCgroupPtr group, unsigned int controller, --=20 2.26.2 From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602167265; cv=none; d=zohomail.com; s=zohoarc; b=fLjH+SZki0hyHYTOoBj9s3J/mAxd0LzqB5zpfLPq1Iu2Sbc63yr6gBuwvCY+4TMMF1PpwzPbaU7hZoI+o9ME+4rmeQL8Llp+p0nTGa6p//YEpiQIGYgl9sMv9bgaHWP2kdV5v8ikFRqdP/OaF5C8WMBJBrMHCy8hG4lifz9w1eE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167265; 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=f5L/EEeBlFW0kLOvKSEh1iALkmGxvRIB0O6Ow6/4AR8=; b=DWRh/Bw8Lx/0mxvq4bRZ2qTZiTISC8j/P4z2GjVcFjV9if5hXiN5lg04kAA+GULcc9pOSflWfdbwjhV6kEHm98XlriXknIhJBLpvbWoCK4cWhJJtZKqcbZDZZpYVWg4mT4Kol9F32Cb0Y9QGxQXrZypftzv6/P14ArzLkOiSmtU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602167265258760.672044427124; Thu, 8 Oct 2020 07:27:45 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-388-HKs7ZkeSNUy8kR1_Yn2UCQ-1; Thu, 08 Oct 2020 10:27:39 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3BAA510BBEC2; Thu, 8 Oct 2020 14:27:33 +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 193EE60CD1; Thu, 8 Oct 2020 14:27:33 +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 D8ACA1832FC6; Thu, 8 Oct 2020 14:27:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098ERCix017214 for ; Thu, 8 Oct 2020 10:27:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id F2D4960CD1; Thu, 8 Oct 2020 14:27:11 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7120561176 for ; Thu, 8 Oct 2020 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167264; 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=f5L/EEeBlFW0kLOvKSEh1iALkmGxvRIB0O6Ow6/4AR8=; b=ho3P1J4kJy59IdUmmCiB0Tr7gOu84vv4Scqohp6zX2ji1kKfPjnWSNs0AHjXC5XNbeIsq5 FtVr42tm4WnHMPO4ZCkFvznabHvuGOPVfzCbFxKwr6e335p2xS1sZKdTbgaTwHX195NhEx daNr41j3OD+bnVXB/iQcHfTZLHmAYpg= X-MC-Unique: HKs7ZkeSNUy8kR1_Yn2UCQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 05/10] libvirt-lxc: use g_autoptr for virCgroup Date: Thu, 8 Oct 2020 16:26:58 +0200 Message-Id: <478a0aa86e4438f2dd079be7af944226ad37be90.1602167149.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.79 on 10.5.11.12 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- src/libvirt-lxc.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c index 73daf123f0..f6391214be 100644 --- a/src/libvirt-lxc.c +++ b/src/libvirt-lxc.c @@ -289,7 +289,7 @@ int virDomainLxcEnterCGroup(virDomainPtr domain, unsigned int flags) { virConnectPtr conn; - virCgroupPtr cgroup =3D NULL; + g_autoptr(virCgroup) cgroup =3D NULL; =20 VIR_DOMAIN_DEBUG(domain, "flags=3D0x%x", flags); =20 @@ -307,12 +307,9 @@ int virDomainLxcEnterCGroup(virDomainPtr domain, if (virCgroupAddProcess(cgroup, getpid()) < 0) goto error; =20 - virCgroupFree(cgroup); - return 0; =20 error: virDispatchError(NULL); - virCgroupFree(cgroup); return -1; } --=20 2.26.2 From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602167260; cv=none; d=zohomail.com; s=zohoarc; b=g1tpqS9RsrpCBQqZebrIHhCj7yRW0ilOKHwJp3Za3KjwgH35xPKK96WAdNcx7f1D8cRpKlS9C8uuRV5fcUtVnoSrnC87v4u98La5axFDLxKOezDVXbipMwCi3KYZxbqb4dcy2DnifEwHXYa5vLKRBz8eXkNKPmi2dvpVPWbkA9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167260; 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=kdEAzU8vQBO241DWoNeURHfCcjSe/ncJbHZIxSju8Cc=; b=gWIXzfkJ+hu6o7etF7tcNxY62awLQRNguS/Fxw8+8pzvcdyCHew+rckVc8yY13HGDgP539zIo1U/i4JU4YbrgAPfmKZhpEG75iTgh//MVLU/7TXNupCf3h9zS3WPoKkR7YTqmsQVsGrqMsLn0jnEIl45cwy5df8kbSPM1yj68Cc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602167260177846.7665364818712; Thu, 8 Oct 2020 07:27:40 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-bHlFMgfCMkCvirpadlpgbg-1; Thu, 08 Oct 2020 10:27:36 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2CA5610BBECB; Thu, 8 Oct 2020 14:27:30 +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 09D076715F; Thu, 8 Oct 2020 14:27:30 +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 C86591832FD2; Thu, 8 Oct 2020 14:27:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098ERCBO017228 for ; Thu, 8 Oct 2020 10:27:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id D4EB36024C; Thu, 8 Oct 2020 14:27:12 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52BC960CD1 for ; Thu, 8 Oct 2020 14:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167259; 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=kdEAzU8vQBO241DWoNeURHfCcjSe/ncJbHZIxSju8Cc=; b=IWgCS5mYFdjvdOzBUcMw/fmMhjVVZWgvRkKQZaVD+27lwzWF8Yu7S2zBG62MuWpaMF5dAM ypbpdL3u+pbT3DhaX5Gl9+iU5kqwQhupjVY/yhe/ZJQnpLqJZCQG4jRYiwaCbM72WJVPeG YeHIMrtmNN7V2LuE6dwY1yYlKevHx1Y= X-MC-Unique: bHlFMgfCMkCvirpadlpgbg-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 06/10] lxc: use g_autoptr for virCgroup Date: Thu, 8 Oct 2020 16:26:59 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.79 on 10.5.11.12 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- src/lxc/lxc_cgroup.c | 18 +++++++----------- src/lxc/lxc_container.c | 37 ++++++++++++++++--------------------- src/lxc/lxc_process.c | 6 +----- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index b80a8911f9..3c546861f1 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -145,31 +145,27 @@ static int virLXCCgroupGetMemStat(virCgroupPtr cgroup, =20 int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo) { - int ret =3D -1; - virCgroupPtr cgroup; + g_autoptr(virCgroup) cgroup =3D NULL; =20 if (virCgroupNewSelf(&cgroup) < 0) return -1; =20 if (virLXCCgroupGetMemStat(cgroup, meminfo) < 0) - goto cleanup; + return -1; =20 if (virLXCCgroupGetMemTotal(cgroup, meminfo) < 0) - goto cleanup; + return -1; =20 if (virLXCCgroupGetMemUsage(cgroup, meminfo) < 0) - goto cleanup; + return -1; =20 if (virLXCCgroupGetMemSwapTotal(cgroup, meminfo) < 0) - goto cleanup; + return -1; =20 if (virLXCCgroupGetMemSwapUsage(cgroup, meminfo) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCgroupFree(cgroup); - return ret; + return 0; } =20 =20 diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 913f4de26a..2a5f8711c4 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1594,8 +1594,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr= vmDef, size_t nttyPaths, virSecurityManagerPtr securityDriver) { - virCgroupPtr cgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup =3D NULL; g_autofree char *sec_mount_options =3D NULL; g_autofree char *stateDir =3D NULL; =20 @@ -1607,69 +1606,65 @@ static int lxcContainerSetupPivotRoot(virDomainDefP= tr vmDef, /* Before pivoting we need to identify any * cgroups controllers that are mounted */ if (virCgroupNewSelf(&cgroup) < 0) - goto cleanup; + return -1; =20 if (virFileResolveAllLinks(LXC_STATE_DIR, &stateDir) < 0) - goto cleanup; + return -1; =20 /* Ensure the root filesystem is mounted */ if (lxcContainerPrepareRoot(vmDef, root, sec_mount_options) < 0) - goto cleanup; + return -1; =20 /* Gives us a private root, leaving all parent OS mounts on /.oldroot = */ if (lxcContainerPivotRoot(root) < 0) - goto cleanup; + return -1; =20 /* FIXME: we should find a way to unmount these mounts for container * even user namespace is enabled. */ if (STREQ(root->src->path, "/") && (!vmDef->idmap.nuidmap) && lxcContainerUnmountForSharedRoot(stateDir, vmDef->name) < 0) - goto cleanup; + return -1; =20 /* Mounts the core /proc, /sys, etc filesystems */ if (lxcContainerMountBasicFS(vmDef->idmap.nuidmap, !lxcNeedNetworkNamespace(vmDef)) < 0) - goto cleanup; + return -1; =20 /* Ensure entire root filesystem (except /.oldroot) is readonly */ if (root->readonly && lxcContainerSetReadOnly() < 0) - goto cleanup; + return -1; =20 /* Mounts /proc/meminfo etc sysinfo */ if (lxcContainerMountProcFuse(vmDef, stateDir) < 0) - goto cleanup; + return -1; =20 /* Now we can re-mount the cgroups controllers in the * same configuration as before */ if (virCgroupBindMount(cgroup, "/.oldroot/", sec_mount_options) < 0) - goto cleanup; + return -1; =20 /* Mounts /dev */ if (lxcContainerMountFSDev(vmDef, stateDir) < 0) - goto cleanup; + return -1; =20 /* Mounts /dev/pts */ if (lxcContainerMountFSDevPTS(vmDef, stateDir) < 0) - goto cleanup; + return -1; =20 /* Setup device nodes in /dev/ */ if (lxcContainerSetupDevices(ttyPaths, nttyPaths) < 0) - goto cleanup; + return -1; =20 /* Sets up any non-root mounts from guest config */ if (lxcContainerMountAllFS(vmDef, sec_mount_options) < 0) - goto cleanup; + return -1; =20 /* Gets rid of all remaining mounts from host OS, including /.oldroot i= tself */ if (lxcContainerUnmountSubtree("/.oldroot", true) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virCgroupFree(cgroup); - return ret; + return 0; } =20 static int lxcContainerResolveAllSymlinks(virDomainDefPtr vmDef) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index a98a090893..e392d98f5d 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1194,7 +1194,7 @@ int virLXCProcessStart(virConnectPtr conn, virCapsPtr caps =3D NULL; virErrorPtr err =3D NULL; virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); - virCgroupPtr selfcgroup; + g_autoptr(virCgroup) selfcgroup =3D NULL; int status; g_autofree char *pidfile =3D NULL; =20 @@ -1203,26 +1203,22 @@ int virLXCProcessStart(virConnectPtr conn, =20 if (!virCgroupHasController(selfcgroup, VIR_CGROUP_CONTROLLER_CPUACCT)) { - virCgroupFree(selfcgroup); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find 'cpuacct' cgroups controller moun= t")); return -1; } if (!virCgroupHasController(selfcgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { - virCgroupFree(selfcgroup); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find 'devices' cgroups controller moun= t")); return -1; } if (!virCgroupHasController(selfcgroup, VIR_CGROUP_CONTROLLER_MEMORY)) { - virCgroupFree(selfcgroup); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find 'memory' cgroups controller mount= ")); return -1; } - virCgroupFree(selfcgroup); =20 if (vm->def->nconsoles =3D=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", --=20 2.26.2 From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602167265; cv=none; d=zohomail.com; s=zohoarc; b=EaoCB88KmUe+G62XSfoI3poXqdiGH3QBfcFy43xAulOlz7IZGji8H82yB0UBZulrCYWHA5enhJodoYtFNk9MCz7ZtjpL0DZ0yJwBm9mW26s6xJEnswZp8fT+5DPqHCSxwlAOGYTFqyNtOcri9SCyd+F9NO511QRToRb2SUtaW8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167265; 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=c0TosCiyttyHBQhN8SIWqSfoWIVqqXI3r7/Wb+PtbVY=; b=Yj3v+CQHU6lNAgImRxx0Bf1QsDDOlxvx4zX5LG9e48GhJ3p9fE3KAi+5Fv3qnEnp0Ftwa80e36tj3eVnfEMF6yYhr+0kYExzKuxGRpuxKhNEG44PwodpUEFEHaSgxFlhMO7c7f72Y4fml/cix0onxfy/ycjE0rb+tUlUdFKs8io= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602167265142972.0311977561273; Thu, 8 Oct 2020 07:27:45 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-254-qd5Vbct4PhOO8lMpOKZPBA-1; Thu, 08 Oct 2020 10:27:40 -0400 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 DAAB31007B00; Thu, 8 Oct 2020 14:27:32 +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 B5D311000186; Thu, 8 Oct 2020 14:27:32 +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 7FA6E8C7C5; Thu, 8 Oct 2020 14:27:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098ERDGl017240 for ; Thu, 8 Oct 2020 10:27:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id B6F1B60CD1; Thu, 8 Oct 2020 14:27:13 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 351B261176 for ; Thu, 8 Oct 2020 14:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167263; 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=c0TosCiyttyHBQhN8SIWqSfoWIVqqXI3r7/Wb+PtbVY=; b=Sqv3KhoFyxx9WdSKy4IKu/IJkZZH1A5HGMHbtpT4IkLjBR+PnIfTD8dWInVYJJhRX58YOw 49eP+qdEKVlQRsE3NhlxEq1GCYQ+Qf8+CiYgINgPg4hjW3JrKMekP7gBR3Byy/+dyWq+nd ogxIlC0nyzZKRq8qQF5WMc0uzx1SN4A= X-MC-Unique: qd5Vbct4PhOO8lMpOKZPBA-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 07/10] qemu: use g_autoptr for virCgroup Date: Thu, 8 Oct 2020 16:27:00 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- src/qemu/qemu_cgroup.c | 28 +++------ src/qemu/qemu_driver.c | 139 ++++++++++++++--------------------------- 2 files changed, 57 insertions(+), 110 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 473ca8a414..210cac9866 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -966,26 +966,22 @@ qemuRestoreCgroupThread(virCgroupPtr cgroup, virCgroupThreadName thread, int id) { - virCgroupPtr cgroup_temp =3D NULL; + g_autoptr(virCgroup) cgroup_temp =3D NULL; g_autofree char *nodeset =3D NULL; - int ret =3D -1; =20 if (virCgroupNewThread(cgroup, thread, id, false, &cgroup_temp) < 0) - goto cleanup; + return -1; =20 if (virCgroupSetCpusetMemoryMigrate(cgroup_temp, true) < 0) - goto cleanup; + return -1; =20 if (virCgroupGetCpusetMems(cgroup_temp, &nodeset) < 0) - goto cleanup; + return -1; =20 if (virCgroupSetCpusetMems(cgroup_temp, nodeset) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCgroupFree(cgroup_temp); - return ret; + return 0; } =20 static void @@ -1129,8 +1125,7 @@ qemuSetupCgroupForExtDevices(virDomainObjPtr vm, virQEMUDriverPtr driver) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - virCgroupPtr cgroup_temp =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup_temp =3D NULL; =20 if (!qemuExtDevicesHasDevice(vm->def) || priv->cgroup =3D=3D NULL) @@ -1147,14 +1142,9 @@ qemuSetupCgroupForExtDevices(virDomainObjPtr vm, =20 if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, false, &cgroup_temp) < 0) - goto cleanup; + return -1; =20 - ret =3D qemuExtDevicesSetupCgroup(driver, vm, cgroup_temp); - - cleanup: - virCgroupFree(cgroup_temp); - - return ret; + return qemuExtDevicesSetupCgroup(driver, vm, cgroup_temp); } =20 =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 60e043115f..825bdd9119 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4519,7 +4519,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, virBitmapPtr tmpmap =3D NULL; virDomainVcpuDefPtr vcpuinfo; qemuDomainObjPrivatePtr priv =3D vm->privateData; - virCgroupPtr cgroup_vcpu =3D NULL; + g_autoptr(virCgroup) cgroup_vcpu =3D NULL; g_autofree char *str =3D NULL; virObjectEventPtr event =3D NULL; char paramField[VIR_TYPED_PARAM_FIELD_LENGTH] =3D ""; @@ -4583,7 +4583,6 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, =20 cleanup: virBitmapFree(tmpmap); - virCgroupFree(cgroup_vcpu); virObjectEventStateQueue(driver->domainEventState, event); return ret; } @@ -4720,7 +4719,7 @@ qemuDomainPinEmulator(virDomainPtr dom, { virQEMUDriverPtr driver =3D dom->conn->privateData; virDomainObjPtr vm; - virCgroupPtr cgroup_emulator =3D NULL; + g_autoptr(virCgroup) cgroup_emulator =3D NULL; virDomainDefPtr def; virDomainDefPtr persistentDef; int ret =3D -1; @@ -4808,8 +4807,6 @@ qemuDomainPinEmulator(virDomainPtr dom, qemuDomainObjEndJob(driver, vm); =20 cleanup: - if (cgroup_emulator) - virCgroupFree(cgroup_emulator); virObjectEventStateQueue(driver->domainEventState, event); virBitmapFree(pcpumap); virDomainObjEndAPI(&vm); @@ -5174,7 +5171,7 @@ qemuDomainPinIOThread(virDomainPtr dom, virDomainDefPtr persistentDef; virBitmapPtr pcpumap =3D NULL; qemuDomainObjPrivatePtr priv; - virCgroupPtr cgroup_iothread =3D NULL; + g_autoptr(virCgroup) cgroup_iothread =3D NULL; virObjectEventPtr event =3D NULL; char paramField[VIR_TYPED_PARAM_FIELD_LENGTH] =3D ""; g_autofree char *str =3D NULL; @@ -5286,8 +5283,6 @@ qemuDomainPinIOThread(virDomainPtr dom, qemuDomainObjEndJob(driver, vm); =20 cleanup: - if (cgroup_iothread) - virCgroupFree(cgroup_iothread); virObjectEventStateQueue(driver->domainEventState, event); virBitmapFree(pcpumap); virDomainObjEndAPI(&vm); @@ -8691,65 +8686,60 @@ static int qemuDomainSetNumaParamsLive(virDomainObjPtr vm, virBitmapPtr nodeset) { - virCgroupPtr cgroup_temp =3D NULL; + g_autoptr(virCgroup) cgroup_thread =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; g_autofree char *nodeset_str =3D NULL; virDomainNumatuneMemMode mode; size_t i =3D 0; - int ret =3D -1; =20 if (virDomainNumatuneGetMode(vm->def->numa, -1, &mode) =3D=3D 0 && mode !=3D VIR_DOMAIN_NUMATUNE_MEM_STRICT) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("change of nodeset for running domain " "requires strict numa mode")); - goto cleanup; + return -1; } =20 if (!virNumaNodesetIsAvailable(nodeset)) - goto cleanup; + return -1; =20 /* Ensure the cpuset string is formatted before passing to cgroup */ if (!(nodeset_str =3D virBitmapFormat(nodeset))) - goto cleanup; + return -1; =20 if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, - false, &cgroup_temp) < 0 || - virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) - goto cleanup; - virCgroupFree(cgroup_temp); + false, &cgroup_thread) < 0 || + virCgroupSetCpusetMems(cgroup_thread, nodeset_str) < 0) + return -1; =20 for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def); i++) { + g_autoptr(virCgroup) cgroup_vcpu =3D NULL; virDomainVcpuDefPtr vcpu =3D virDomainDefGetVcpu(vm->def, i); =20 if (!vcpu->online) continue; =20 if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, i, - false, &cgroup_temp) < 0 || - virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) - goto cleanup; - virCgroupFree(cgroup_temp); + false, &cgroup_vcpu) < 0 || + virCgroupSetCpusetMems(cgroup_vcpu, nodeset_str) < 0) + return -1; } =20 for (i =3D 0; i < vm->def->niothreadids; i++) { + g_autoptr(virCgroup) cgroup_iothread =3D NULL; + if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_IOTHREAD, vm->def->iothreadids[i]->iothread_id, - false, &cgroup_temp) < 0 || - virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) - goto cleanup; - virCgroupFree(cgroup_temp); + false, &cgroup_iothread) < 0 || + virCgroupSetCpusetMems(cgroup_iothread, nodeset_str) < 0) + return -1; } =20 /* set nodeset for root cgroup */ if (virCgroupSetCpusetMems(priv->cgroup, nodeset_str) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCgroupFree(cgroup_temp); - - return ret; + return 0; } =20 static int @@ -9143,7 +9133,6 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupPtr c= group, unsigned long long period, long long quota) { size_t i; - virCgroupPtr cgroup_vcpu =3D NULL; =20 if (period =3D=3D 0 && quota =3D=3D 0) return 0; @@ -9152,26 +9141,21 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupPtr= cgroup, return 0; =20 for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def); i++) { + g_autoptr(virCgroup) cgroup_vcpu =3D NULL; virDomainVcpuDefPtr vcpu =3D virDomainDefGetVcpu(vm->def, i); =20 if (!vcpu->online) - continue; + return -1; =20 if (virCgroupNewThread(cgroup, VIR_CGROUP_THREAD_VCPU, i, false, &cgroup_vcpu) < 0) - goto cleanup; + return -1; =20 if (qemuSetupCgroupVcpuBW(cgroup_vcpu, period, quota) < 0) - goto cleanup; - - virCgroupFree(cgroup_vcpu); + return -1; } =20 return 0; - - cleanup: - virCgroupFree(cgroup_vcpu); - return -1; } =20 static int @@ -9179,24 +9163,19 @@ qemuSetEmulatorBandwidthLive(virCgroupPtr cgroup, unsigned long long period, long long quota) { - virCgroupPtr cgroup_emulator =3D NULL; + g_autoptr(virCgroup) cgroup_emulator =3D NULL; =20 if (period =3D=3D 0 && quota =3D=3D 0) return 0; =20 if (virCgroupNewThread(cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, false, &cgroup_emulator) < 0) - goto cleanup; + return -1; =20 if (qemuSetupCgroupVcpuBW(cgroup_emulator, period, quota) < 0) - goto cleanup; + return -1; =20 - virCgroupFree(cgroup_emulator); return 0; - - cleanup: - virCgroupFree(cgroup_emulator); - return -1; } =20 =20 @@ -9205,7 +9184,6 @@ qemuSetIOThreadsBWLive(virDomainObjPtr vm, virCgroupP= tr cgroup, unsigned long long period, long long quota) { size_t i; - virCgroupPtr cgroup_iothread =3D NULL; =20 if (period =3D=3D 0 && quota =3D=3D 0) return 0; @@ -9214,22 +9192,18 @@ qemuSetIOThreadsBWLive(virDomainObjPtr vm, virCgrou= pPtr cgroup, return 0; =20 for (i =3D 0; i < vm->def->niothreadids; i++) { + g_autoptr(virCgroup) cgroup_iothread =3D NULL; + if (virCgroupNewThread(cgroup, VIR_CGROUP_THREAD_IOTHREAD, vm->def->iothreadids[i]->iothread_id, false, &cgroup_iothread) < 0) - goto cleanup; + return -1; =20 if (qemuSetupCgroupVcpuBW(cgroup_iothread, period, quota) < 0) - goto cleanup; - - virCgroupFree(cgroup_iothread); + return -1; } =20 return 0; - - cleanup: - virCgroupFree(cgroup_iothread); - return -1; } =20 =20 @@ -9571,38 +9545,32 @@ static int qemuGetVcpusBWLive(virDomainObjPtr vm, unsigned long long *period, long long *quota) { - virCgroupPtr cgroup_vcpu =3D NULL; + g_autoptr(virCgroup) cgroup_vcpu =3D NULL; qemuDomainObjPrivatePtr priv =3D NULL; int rc; - int ret =3D -1; =20 priv =3D vm->privateData; if (!qemuDomainHasVcpuPids(vm)) { /* We do not create sub dir for each vcpu */ rc =3D qemuGetVcpuBWLive(priv->cgroup, period, quota); if (rc < 0) - goto cleanup; + return -1; =20 if (*quota > 0) *quota /=3D virDomainDefGetVcpus(vm->def); - goto out; + return 0; } =20 /* get period and quota for vcpu0 */ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, 0, false, &cgroup_vcpu) < 0) - goto cleanup; + return -1; =20 rc =3D qemuGetVcpuBWLive(cgroup_vcpu, period, quota); if (rc < 0) - goto cleanup; + return -1; =20 - out: - ret =3D 0; - - cleanup: - virCgroupFree(cgroup_vcpu); - return ret; + return 0; } =20 static int @@ -9610,58 +9578,47 @@ qemuGetEmulatorBandwidthLive(virCgroupPtr cgroup, unsigned long long *period, long long *quota) { - virCgroupPtr cgroup_emulator =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup_emulator =3D NULL; =20 /* get period and quota for emulator */ if (virCgroupNewThread(cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, false, &cgroup_emulator) < 0) - goto cleanup; + return -1; =20 if (qemuGetVcpuBWLive(cgroup_emulator, period, quota) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virCgroupFree(cgroup_emulator); - return ret; + return 0; } =20 static int qemuGetIOThreadsBWLive(virDomainObjPtr vm, unsigned long long *period, long long *quota) { - virCgroupPtr cgroup_iothread =3D NULL; + g_autoptr(virCgroup) cgroup_iothread =3D NULL; qemuDomainObjPrivatePtr priv =3D NULL; int rc; - int ret =3D -1; =20 priv =3D vm->privateData; if (!vm->def->niothreadids) { /* We do not create sub dir for each iothread */ if ((rc =3D qemuGetVcpuBWLive(priv->cgroup, period, quota)) < 0) - goto cleanup; + return -1; =20 - goto out; + return 0; } =20 /* get period and quota for the "first" IOThread */ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_IOTHREAD, vm->def->iothreadids[0]->iothread_id, false, &cgroup_iothread) < 0) - goto cleanup; + return -1; =20 rc =3D qemuGetVcpuBWLive(cgroup_iothread, period, quota); if (rc < 0) - goto cleanup; + return -1; =20 - out: - ret =3D 0; - - cleanup: - virCgroupFree(cgroup_iothread); - return ret; + return 0; } =20 =20 --=20 2.26.2 From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1602167270; cv=none; d=zohomail.com; s=zohoarc; b=c3tg6XdYcOvgxxg3KhW9eQBE77PvevqgNZmraYXv4CmfvpnxBXYFtQ0d4mFnVdOLNODMmp8ApDW5rTd1w9bL9es+aad0KFJqnQCVot8geNlQpO+aSa58C5sTvW2hSDkx/jPbEsSDFuAI0TZS00Nwslmen/XGTmnvxCLZTAmjngU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167270; 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=alPJ39kvV/o54FOhWqsHl859Z+Vh8lBlUaUyHNvfjMU=; b=kOCVp478Kb9JdVBIbBPFuEZb/DxyJJwpnOVyEIpnucJzWdKUVY903w5IpPLVI0dWC/eK2wH5QxXK1DNVL3C20G+uDpVbpvl74PLiRLqVpNMrfgvM9yZufFJPKXQPSPOPNtfTdMDp+zEwWRHhQxalMnof/q3T9BdRl8E4WoTKHEI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1602167270661154.81136387278548; Thu, 8 Oct 2020 07:27:50 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-497-eIAqwW9uPtqUe9ax-t7LwQ-1; Thu, 08 Oct 2020 10:27:47 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C097B8064B6; Thu, 8 Oct 2020 14:27:35 +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 9990E19C4F; Thu, 8 Oct 2020 14:27:35 +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 662951832FC6; Thu, 8 Oct 2020 14:27:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098EREWL017248 for ; Thu, 8 Oct 2020 10:27:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9A8EE6024C; Thu, 8 Oct 2020 14:27:14 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1749360CD1 for ; Thu, 8 Oct 2020 14:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167269; 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=alPJ39kvV/o54FOhWqsHl859Z+Vh8lBlUaUyHNvfjMU=; b=R58zJscSwYDYZ5bXPASsuQiY4ojCW/1PEhxAjPQgRKybQ7o6wSGYRUwfuFk6soypatDMWV W3cEB0jzde2Fy5zquQjt2u4amkLkbqahEshRN1561/50mECrnVRFL0iR27mwSF/uHfKe97 ilLlAGFjOBKW+BNGsQp8rC8S9DQp8wA= X-MC-Unique: eIAqwW9uPtqUe9ax-t7LwQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 08/10] util: use g_autoptr for virCgroup Date: Thu, 8 Oct 2020 16:27:01 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.23 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- src/util/vircgroup.c | 179 ++++++++++++++++++----------------------- src/util/vircgroupv1.c | 9 +-- 2 files changed, 81 insertions(+), 107 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 04876c6596..d408e3366f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -662,28 +662,26 @@ virCgroupNew(pid_t pid, int controllers, virCgroupPtr *group) { + g_autoptr(virCgroup) newGroup =3D NULL; + VIR_DEBUG("pid=3D%lld path=3D%s parent=3D%p controllers=3D%d group=3D%= p", (long long) pid, path, parent, controllers, group); =20 - *group =3D g_new0(virCgroup, 1); + *group =3D NULL; + newGroup =3D g_new0(virCgroup, 1); =20 if (path[0] =3D=3D '/' || !parent) { - (*group)->path =3D g_strdup(path); + newGroup->path =3D g_strdup(path); } else { - (*group)->path =3D g_strdup_printf("%s%s%s", parent->path, + newGroup->path =3D g_strdup_printf("%s%s%s", parent->path, STREQ(parent->path, "") ? "" : "/= ", path); } =20 - if (virCgroupDetect(*group, pid, controllers, path, parent) < 0) - goto error; + if (virCgroupDetect(newGroup, pid, controllers, path, parent) < 0) + return -1; =20 + *group =3D g_steal_pointer(&newGroup); return 0; - - error: - virCgroupFree(*group); - *group =3D NULL; - - return -1; } =20 =20 @@ -821,13 +819,16 @@ virCgroupNewPartition(const char *path, int controllers, virCgroupPtr *group) { - int ret =3D -1; g_autofree char *parentPath =3D NULL; g_autofree char *newPath =3D NULL; - virCgroupPtr parent =3D NULL; + g_autoptr(virCgroup) parent =3D NULL; + g_autoptr(virCgroup) newGroup =3D NULL; + VIR_DEBUG("path=3D%s create=3D%d controllers=3D%x", path, create, controllers); =20 + *group =3D NULL; + if (path[0] !=3D '/') { virReportError(VIR_ERR_INTERNAL_ERROR, _("Partition path '%s' must start with '/'"), @@ -836,7 +837,7 @@ virCgroupNewPartition(const char *path, } =20 if (virCgroupSetPartitionSuffix(path, &newPath) < 0) - goto cleanup; + return -1; =20 if (STRNEQ(newPath, "/")) { char *tmp; @@ -847,25 +848,19 @@ virCgroupNewPartition(const char *path, *tmp =3D '\0'; =20 if (virCgroupNew(-1, parentPath, NULL, controllers, &parent) < 0) - goto cleanup; + return -1; } =20 - if (virCgroupNew(-1, newPath, parent, controllers, group) < 0) - goto cleanup; + if (virCgroupNew(-1, newPath, parent, controllers, &newGroup) < 0) + return -1; =20 if (parent) { - if (virCgroupMakeGroup(parent, *group, create, VIR_CGROUP_NONE) < = 0) - goto cleanup; + if (virCgroupMakeGroup(parent, newGroup, create, VIR_CGROUP_NONE) = < 0) + return -1; } =20 - ret =3D 0; - cleanup: - if (ret !=3D 0) { - virCgroupFree(*group); - *group =3D NULL; - } - virCgroupFree(parent); - return ret; + *group =3D g_steal_pointer(&newGroup); + return 0; } =20 =20 @@ -904,13 +899,14 @@ virCgroupNewDomainPartition(virCgroupPtr partition, virCgroupPtr *group) { g_autofree char *grpname =3D NULL; + g_autoptr(virCgroup) newGroup =3D NULL; =20 grpname =3D g_strdup_printf("%s.libvirt-%s", name, driver); =20 if (virCgroupPartitionEscape(&grpname) < 0) return -1; =20 - if (virCgroupNew(-1, grpname, partition, -1, group) < 0) + if (virCgroupNew(-1, grpname, partition, -1, &newGroup) < 0) return -1; =20 /* @@ -923,13 +919,12 @@ virCgroupNewDomainPartition(virCgroupPtr partition, * a group for driver, is to avoid overhead to track * cumulative usage that we don't need. */ - if (virCgroupMakeGroup(partition, *group, create, + if (virCgroupMakeGroup(partition, newGroup, create, VIR_CGROUP_MEM_HIERACHY) < 0) { - virCgroupFree(*group); - *group =3D NULL; return -1; } =20 + *group =3D g_steal_pointer(&newGroup); return 0; } =20 @@ -953,8 +948,11 @@ virCgroupNewThread(virCgroupPtr domain, virCgroupPtr *group) { g_autofree char *name =3D NULL; + g_autoptr(virCgroup) newGroup =3D NULL; int controllers; =20 + *group =3D NULL; + switch (nameval) { case VIR_CGROUP_THREAD_VCPU: name =3D g_strdup_printf("vcpu%d", id); @@ -975,15 +973,13 @@ virCgroupNewThread(virCgroupPtr domain, (1 << VIR_CGROUP_CONTROLLER_CPUACCT) | (1 << VIR_CGROUP_CONTROLLER_CPUSET)); =20 - if (virCgroupNew(-1, name, domain, controllers, group) < 0) + if (virCgroupNew(-1, name, domain, controllers, &newGroup) < 0) return -1; =20 - if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_THREAD) < 0)= { - virCgroupFree(*group); - *group =3D NULL; + if (virCgroupMakeGroup(domain, newGroup, create, VIR_CGROUP_THREAD) < = 0) return -1; - } =20 + *group =3D g_steal_pointer(&newGroup); return 0; } =20 @@ -1009,26 +1005,28 @@ virCgroupNewDetectMachine(const char *name, virCgroupPtr *group) { size_t i; + g_autoptr(virCgroup) newGroup =3D NULL; =20 - if (virCgroupNewDetect(pid, controllers, group) < 0) { + *group =3D NULL; + + if (virCgroupNewDetect(pid, controllers, &newGroup) < 0) { if (virCgroupNewIgnoreError()) return 0; return -1; } =20 for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { - if ((*group)->backends[i] && - !(*group)->backends[i]->validateMachineGroup(*group, name, + if (newGroup->backends[i] && + !newGroup->backends[i]->validateMachineGroup(newGroup, name, drivername, machinename)) { VIR_DEBUG("Failed to validate machine name for '%s' driver '%s= '", name, drivername); - virCgroupFree(*group); - *group =3D NULL; return 0; } } =20 + *group =3D g_steal_pointer(&newGroup); return 0; } =20 @@ -1039,19 +1037,18 @@ virCgroupEnableMissingControllers(char *path, int controllers, virCgroupPtr *group) { - virCgroupPtr parent =3D NULL; + g_autoptr(virCgroup) parent =3D NULL; char *offset =3D path; - int ret =3D -1; =20 if (virCgroupNew(pidleader, "/", NULL, controllers, &parent) < 0) - return ret; + return -1; =20 for (;;) { - virCgroupPtr tmp; + g_autoptr(virCgroup) tmp =3D NULL; char *t =3D strchr(offset + 1, '/'); if (t) *t =3D '\0'; @@ -1061,27 +1058,23 @@ virCgroupEnableMissingControllers(char *path, parent, controllers, &tmp) < 0) - goto cleanup; + return -1; + + if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0) + return -1; =20 - if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0)= { - virCgroupFree(tmp); - goto cleanup; - } if (t) { *t =3D '/'; offset =3D t; virCgroupFree(parent); - parent =3D tmp; + parent =3D g_steal_pointer(&tmp); } else { - *group =3D tmp; + *group =3D g_steal_pointer(&tmp); break; } } =20 - ret =3D 0; - cleanup: - virCgroupFree(parent); - return ret; + return 0; } =20 =20 @@ -1103,7 +1096,8 @@ virCgroupNewMachineSystemd(const char *name, virCgroupPtr *group) { int rv; - virCgroupPtr init; + g_autoptr(virCgroup) init =3D NULL; + g_autoptr(virCgroup) newGroup =3D NULL; g_autofree char *path =3D NULL; size_t i; =20 @@ -1135,7 +1129,6 @@ virCgroupNewMachineSystemd(const char *name, break; } } - virCgroupFree(init); =20 if (!path || STREQ(path, "/") || path[0] !=3D '/') { VIR_DEBUG("Systemd didn't setup its controller, path=3D%s", @@ -1144,20 +1137,20 @@ virCgroupNewMachineSystemd(const char *name, } =20 if (virCgroupEnableMissingControllers(path, pidleader, - controllers, group) < 0) { + controllers, &newGroup) < 0) { return -1; } =20 - if (virCgroupAddProcess(*group, pidleader) < 0) { + if (virCgroupAddProcess(newGroup, pidleader) < 0) { virErrorPtr saved; =20 virErrorPreserveLast(&saved); - virCgroupRemove(*group); - virCgroupFree(*group); - *group =3D NULL; + virCgroupRemove(newGroup); virErrorRestore(&saved); + return 0; } =20 + *group =3D g_steal_pointer(&newGroup); return 0; } =20 @@ -1179,8 +1172,8 @@ virCgroupNewMachineManual(const char *name, int controllers, virCgroupPtr *group) { - virCgroupPtr parent =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) parent =3D NULL; + g_autoptr(virCgroup) newGroup =3D NULL; =20 VIR_DEBUG("Fallback to non-systemd setup"); if (virCgroupNewPartition(partition, @@ -1188,34 +1181,28 @@ virCgroupNewMachineManual(const char *name, controllers, &parent) < 0) { if (virCgroupNewIgnoreError()) - goto done; + return 0; =20 - goto cleanup; + return -1; } =20 if (virCgroupNewDomainPartition(parent, drivername, name, true, - group) < 0) - goto cleanup; + &newGroup) < 0) + return -1; =20 - if (virCgroupAddProcess(*group, pidleader) < 0) { + if (virCgroupAddProcess(newGroup, pidleader) < 0) { virErrorPtr saved; =20 virErrorPreserveLast(&saved); - virCgroupRemove(*group); - virCgroupFree(*group); - *group =3D NULL; + virCgroupRemove(newGroup); virErrorRestore(&saved); } =20 - done: - ret =3D 0; - - cleanup: - virCgroupFree(parent); - return ret; + *group =3D g_steal_pointer(&newGroup); + return 0; } =20 =20 @@ -2037,22 +2024,21 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, size_t nsum, virBitmapPtr cpumap) { - int ret =3D -1; ssize_t i =3D -1; - virCgroupPtr group_vcpu =3D NULL; =20 while ((i =3D virBitmapNextSetBit(guestvcpus, i)) >=3D 0) { g_autofree char *buf =3D NULL; + g_autoptr(virCgroup) group_vcpu =3D NULL; char *pos; unsigned long long tmp; ssize_t j; =20 if (virCgroupNewThread(group, VIR_CGROUP_THREAD_VCPU, i, false, &group_vcpu) < 0) - goto cleanup; + return -1; =20 if (virCgroupGetCpuacctPercpuUsage(group_vcpu, &buf) < 0) - goto cleanup; + return -1; =20 pos =3D buf; for (j =3D virBitmapNextSetBit(cpumap, -1); @@ -2061,18 +2047,13 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, if (virStrToLong_ull(pos, &pos, 10, &tmp) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cpuacct parse error")); - goto cleanup; + return -1; } sum_cpu_time[j] +=3D tmp; } - - virCgroupFree(group_vcpu); } =20 - ret =3D 0; - cleanup: - virCgroupFree(group_vcpu); - return ret; + return 0; } =20 =20 @@ -2519,7 +2500,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, bool killedAny =3D false; g_autofree char *keypath =3D NULL; DIR *dp =3D NULL; - virCgroupPtr subgroup =3D NULL; struct dirent *ent; int direrr; VIR_DEBUG("group=3D%p path=3D%s signum=3D%d pids=3D%p", @@ -2546,6 +2526,8 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, } =20 while ((direrr =3D virDirRead(dp, &ent, keypath)) > 0) { + g_autoptr(virCgroup) subgroup =3D NULL; + if (ent->d_type !=3D DT_DIR) continue; =20 @@ -2562,8 +2544,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, =20 if (dormdir) virCgroupRemove(subgroup); - - virCgroupFree(subgroup); } if (direrr < 0) goto cleanup; @@ -2572,7 +2552,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, ret =3D killedAny ? 1 : 0; =20 cleanup: - virCgroupFree(subgroup); VIR_DIR_CLOSE(dp); return ret; } @@ -2767,15 +2746,12 @@ virCgroupHasEmptyTasks(virCgroupPtr cgroup, int con= troller) bool virCgroupControllerAvailable(int controller) { - virCgroupPtr cgroup; - bool ret =3D false; + g_autoptr(virCgroup) cgroup =3D NULL; =20 if (virCgroupNewSelf(&cgroup) < 0) - return ret; + return false; =20 - ret =3D virCgroupHasController(cgroup, controller); - virCgroupFree(cgroup); - return ret; + return virCgroupHasController(cgroup, controller); } =20 #else /* !__linux__ */ @@ -3567,7 +3543,7 @@ virCgroupDelThread(virCgroupPtr cgroup, virCgroupThreadName nameval, int idx) { - virCgroupPtr new_cgroup =3D NULL; + g_autoptr(virCgroup) new_cgroup =3D NULL; =20 if (cgroup) { if (virCgroupNewThread(cgroup, nameval, idx, false, &new_cgroup) <= 0) @@ -3575,7 +3551,6 @@ virCgroupDelThread(virCgroupPtr cgroup, =20 /* Remove the offlined cgroup */ virCgroupRemove(new_cgroup); - virCgroupFree(new_cgroup); } =20 return 0; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 52d2a17d39..a42b7750f9 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1470,21 +1470,20 @@ static virOnceControl virCgroupV1MemoryOnce =3D VIR= _ONCE_CONTROL_INITIALIZER; static void virCgroupV1MemoryOnceInit(void) { - virCgroupPtr group; + g_autoptr(virCgroup) group =3D NULL; unsigned long long int mem_unlimited =3D 0ULL; =20 if (virCgroupNew(-1, "/", NULL, -1, &group) < 0) - goto cleanup; + return; =20 if (!virCgroupV1HasController(group, VIR_CGROUP_CONTROLLER_MEMORY)) - goto cleanup; + return; =20 ignore_value(virCgroupGetValueU64(group, VIR_CGROUP_CONTROLLER_MEMORY, "memory.limit_in_bytes", &mem_unlimited)); - cleanup: - virCgroupFree(group); + virCgroupV1MemoryUnlimitedKB =3D mem_unlimited >> 10; } =20 --=20 2.26.2 From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602167302; cv=none; d=zohomail.com; s=zohoarc; b=dwEiWM0LXNT8CHWhaO8EoQWo1wjsTkaZbCxSyQP9DbpGmd4APAlHYGimeiIbX8XyEhNAoEWTum1c5LAg0uXQqKebtFfyLtNgpLoZsty/x6bDDroHQ3XtAmT6VcDV9/ZB+SBpJKMDH3iUDsW+Yv2HzGmpxdShCCXqNsf4JhCM/Lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167302; 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=gF4KFw+3Uei9vHNyT8SnEoQnZPe1tTQ4qku70IvkjJA=; b=kKbtHPR2U/qgOIXO0uMTM+VyN1K8xJr0a0nlg/VXgdKU74gmLnSp3QTf2ZamybwNut5Y3AMZecUY7jGYWiABm9hMY9Msvs7D3e/6H6tZ3DF9mCLjOA58l7gJDln7Eh6Gj1wPNWFRMUb6wjX6YioTEv+zl4xnpeXq8pcA+EyrWGs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602167302224738.9698117323602; Thu, 8 Oct 2020 07:28:22 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-sh4og4OGMqeVZLIuYUzJ9w-1; Thu, 08 Oct 2020 10:27:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78AE31008307; Thu, 8 Oct 2020 14:27:35 +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 5681D5D9F7; Thu, 8 Oct 2020 14:27:35 +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 1E2FB1832FD3; Thu, 8 Oct 2020 14:27:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098ERFra017256 for ; Thu, 8 Oct 2020 10:27:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id A648460CD1; Thu, 8 Oct 2020 14:27:15 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF38665F5E for ; Thu, 8 Oct 2020 14:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167300; 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=gF4KFw+3Uei9vHNyT8SnEoQnZPe1tTQ4qku70IvkjJA=; b=hwkAWo1YRhabb30gZd9kVD1l/4vXF8TnPoadKaunxtGOAgKEn+7oYgK7dEX5DbpRg0EZ1H uRUbcHL8AR4SJYDwr23eZrNuypSqCqPV1dkgVlvPOTiYfZgDz8GCI9zGeCRYHHiZJ6txe9 2yvw3tJMTocBAstLAQp/iBquLbNGnpw= X-MC-Unique: sh4og4OGMqeVZLIuYUzJ9w-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 09/10] tests: use g_autoptr for virCgroup Date: Thu, 8 Oct 2020 16:27:02 +0200 Message-Id: <6f5096474f2339f0cffeeeff708b177bfafd6be7.1602167149.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.79 on 10.5.11.14 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- tests/vircgrouptest.c | 228 +++++++++++++++--------------------------- 1 file changed, 80 insertions(+), 148 deletions(-) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 632d33efcd..6c1a766fa2 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -183,7 +183,7 @@ testCgroupDetectMounts(const void *args) const struct _detectMountsData *data =3D args; char *parsed =3D NULL; const char *actual; - virCgroupPtr group =3D NULL; + g_autoptr(virCgroup) group =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; size_t i; =20 @@ -217,15 +217,13 @@ testCgroupDetectMounts(const void *args) cleanup: g_unsetenv("VIR_CGROUP_MOCK_FILENAME"); VIR_FREE(parsed); - virCgroupFree(group); return result; } =20 =20 static int testCgroupNewForSelf(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup =3D NULL; const char *placement[VIR_CGROUP_CONTROLLER_LAST] =3D { [VIR_CGROUP_CONTROLLER_CPU] =3D "/system", [VIR_CGROUP_CONTROLLER_CPUACCT] =3D "/system", @@ -239,14 +237,10 @@ static int testCgroupNewForSelf(const void *args G_GN= UC_UNUSED) =20 if (virCgroupNewSelf(&cgroup) < 0) { fprintf(stderr, "Cannot create cgroup for self\n"); - goto cleanup; + return -1; } =20 - ret =3D validateCgroup(cgroup, "", mountsFull, links, placement, NULL,= NULL, 0); - - cleanup: - virCgroupFree(cgroup); - return ret; + return validateCgroup(cgroup, "", mountsFull, links, placement, NULL, = NULL, 0); } =20 =20 @@ -256,7 +250,7 @@ static int testCgroupNewForSelf(const void *args G_GNUC= _UNUSED) virErrorPtr err =3D virGetLastError(); \ fprintf(stderr, "Did not get " #en " error code: %d:%d\n", \ err ? err->code : 0, err ? err->int1 : 0); \ - goto cleanup; \ + return -1; \ } } while (0) =20 /* Asking for impossible combination since CPU is co-mounted */ @@ -264,8 +258,7 @@ static int testCgroupNewForSelf(const void *args G_GNUC= _UNUSED) =20 static int testCgroupNewForPartition(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup =3D NULL; int rv; const char *placementSmall[VIR_CGROUP_CONTROLLER_LAST] =3D { [VIR_CGROUP_CONTROLLER_CPU] =3D "/virtualmachines.partition", @@ -290,7 +283,7 @@ static int testCgroupNewForPartition(const void *args G= _GNUC_UNUSED) =20 if ((rv =3D virCgroupNewPartition("/virtualmachines", false, -1, &cgro= up)) !=3D -1) { fprintf(stderr, "Unexpected found /virtualmachines cgroup: %d\n", = -rv); - goto cleanup; + return -1; } ENSURE_ERRNO(ENOENT); =20 @@ -299,7 +292,7 @@ static int testCgroupNewForPartition(const void *args G= _GNUC_UNUSED) (1 << VIR_CGROUP_CONTROLLER_CPU), &cgroup)) !=3D -1) { fprintf(stderr, "Should not have created /virtualmachines cgroup: = %d\n", -rv); - goto cleanup; + return -1; } ENSURE_ERRNO(EINVAL); =20 @@ -308,7 +301,7 @@ static int testCgroupNewForPartition(const void *args G= _GNUC_UNUSED) (1 << VIR_CGROUP_CONTROLLER_DEVICES), &cgroup)) !=3D -1) { fprintf(stderr, "Should not have created /virtualmachines cgroup: = %d\n", -rv); - goto cleanup; + return -1; } ENSURE_ERRNO(ENXIO); =20 @@ -319,27 +312,22 @@ static int testCgroupNewForPartition(const void *args= G_GNUC_UNUSED) (1 << VIR_CGROUP_CONTROLLER_MEMORY), &cgroup)) !=3D 0) { fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv= ); - goto cleanup; + return -1; } - ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsSma= ll, links, placementSmall, NULL, NULL, 0); + rv =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsSmal= l, links, placementSmall, NULL, NULL, 0); virCgroupFree(cgroup); =20 if ((rv =3D virCgroupNewPartition("/virtualmachines", true, -1, &cgrou= p)) !=3D 0) { fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv= ); - goto cleanup; + return -1; } - ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsFul= l, links, placementFull, NULL, NULL, 0); - - cleanup: - virCgroupFree(cgroup); - return ret; + return validateCgroup(cgroup, "/virtualmachines.partition", mountsFull= , links, placementFull, NULL, NULL, 0); } =20 =20 static int testCgroupNewForPartitionNested(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup =3D NULL; int rv; const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] =3D { [VIR_CGROUP_CONTROLLER_CPU] =3D "/deployment.partition/production.= partition", @@ -354,42 +342,37 @@ static int testCgroupNewForPartitionNested(const void= *args G_GNUC_UNUSED) =20 if ((rv =3D virCgroupNewPartition("/deployment/production", false, -1,= &cgroup)) !=3D -1) { fprintf(stderr, "Unexpected found /deployment/production cgroup: %= d\n", -rv); - goto cleanup; + return -1; } ENSURE_ERRNO(ENOENT); =20 /* Should not work, since we require /deployment to be pre-created */ if ((rv =3D virCgroupNewPartition("/deployment/production", true, -1, = &cgroup)) !=3D -1) { fprintf(stderr, "Unexpected created /deployment/production cgroup:= %d\n", -rv); - goto cleanup; + return -1; } ENSURE_ERRNO(ENOENT); =20 if ((rv =3D virCgroupNewPartition("/deployment", true, -1, &cgroup)) != =3D 0) { fprintf(stderr, "Failed to create /deployment cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 /* Should now work */ virCgroupFree(cgroup); if ((rv =3D virCgroupNewPartition("/deployment/production", true, -1, = &cgroup)) !=3D 0) { fprintf(stderr, "Failed to create /deployment/production cgroup: %= d\n", -rv); - goto cleanup; + return -1; } =20 - ret =3D validateCgroup(cgroup, "/deployment.partition/production.parti= tion", - mountsFull, links, placementFull, NULL, NULL, 0); - - cleanup: - virCgroupFree(cgroup); - return ret; + return validateCgroup(cgroup, "/deployment.partition/production.partit= ion", + mountsFull, links, placementFull, NULL, NULL, 0); } =20 =20 static int testCgroupNewForPartitionNestedDeep(const void *args G_GNUC_UNU= SED) { - virCgroupPtr cgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup =3D NULL; int rv; const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] =3D { [VIR_CGROUP_CONTROLLER_CPU] =3D "/user/berrange.user/production.pa= rtition", @@ -404,50 +387,45 @@ static int testCgroupNewForPartitionNestedDeep(const = void *args G_GNUC_UNUSED) =20 if ((rv =3D virCgroupNewPartition("/user/berrange.user/production", fa= lse, -1, &cgroup)) !=3D -1) { fprintf(stderr, "Unexpected found /user/berrange.user/production c= group: %d\n", -rv); - goto cleanup; + return -1; } ENSURE_ERRNO(ENOENT); =20 /* Should not work, since we require /user/berrange.user to be pre-cre= ated */ if ((rv =3D virCgroupNewPartition("/user/berrange.user/production", tr= ue, -1, &cgroup)) !=3D -1) { fprintf(stderr, "Unexpected created /user/berrange.user/production= cgroup: %d\n", -rv); - goto cleanup; + return -1; } ENSURE_ERRNO(ENOENT); =20 if ((rv =3D virCgroupNewPartition("/user", true, -1, &cgroup)) !=3D 0)= { fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n= ", -rv); - goto cleanup; + return -1; } =20 virCgroupFree(cgroup); if ((rv =3D virCgroupNewPartition("/user/berrange.user", true, -1, &cg= roup)) !=3D 0) { fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n= ", -rv); - goto cleanup; + return -1; } =20 /* Should now work */ virCgroupFree(cgroup); if ((rv =3D virCgroupNewPartition("/user/berrange.user/production", tr= ue, -1, &cgroup)) !=3D 0) { fprintf(stderr, "Failed to create /user/berrange.user/production c= group: %d\n", -rv); - goto cleanup; + return -1; } =20 - ret =3D validateCgroup(cgroup, "/user/berrange.user/production.partiti= on", - mountsFull, links, placementFull, NULL, NULL, 0); - - cleanup: - virCgroupFree(cgroup); - return ret; + return validateCgroup(cgroup, "/user/berrange.user/production.partitio= n", + mountsFull, links, placementFull, NULL, NULL, 0); } =20 =20 =20 static int testCgroupNewForPartitionDomain(const void *args G_GNUC_UNUSED) { - virCgroupPtr partitioncgroup =3D NULL; - virCgroupPtr domaincgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) partitioncgroup =3D NULL; + g_autoptr(virCgroup) domaincgroup =3D NULL; int rv; const char *placement[VIR_CGROUP_CONTROLLER_LAST] =3D { [VIR_CGROUP_CONTROLLER_CPU] =3D "/production.partition/foo.libvirt= -lxc", @@ -462,29 +440,23 @@ static int testCgroupNewForPartitionDomain(const void= *args G_GNUC_UNUSED) =20 if ((rv =3D virCgroupNewPartition("/production", true, -1, &partitionc= group)) !=3D 0) { fprintf(stderr, "Failed to create /production cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 if ((rv =3D virCgroupNewDomainPartition(partitioncgroup, "lxc", "foo",= true, &domaincgroup)) !=3D 0) { fprintf(stderr, "Cannot create LXC cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 - ret =3D validateCgroup(domaincgroup, "/production.partition/foo.libvir= t-lxc", mountsFull, links, placement, NULL, NULL, 0); - - cleanup: - virCgroupFree(partitioncgroup); - virCgroupFree(domaincgroup); - return ret; + return validateCgroup(domaincgroup, "/production.partition/foo.libvirt= -lxc", mountsFull, links, placement, NULL, NULL, 0); } =20 static int testCgroupNewForPartitionDomainEscaped(const void *args G_GNUC_= UNUSED) { - virCgroupPtr partitioncgroup1 =3D NULL; - virCgroupPtr partitioncgroup2 =3D NULL; - virCgroupPtr partitioncgroup3 =3D NULL; - virCgroupPtr domaincgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) partitioncgroup1 =3D NULL; + g_autoptr(virCgroup) partitioncgroup2 =3D NULL; + g_autoptr(virCgroup) partitioncgroup3 =3D NULL; + g_autoptr(virCgroup) domaincgroup =3D NULL; int rv; const char *placement[VIR_CGROUP_CONTROLLER_LAST] =3D { [VIR_CGROUP_CONTROLLER_CPU] =3D "/_cgroup.evil/net_cls.evil/__evil= .evil/_cpu.foo.libvirt-lxc", @@ -499,42 +471,34 @@ static int testCgroupNewForPartitionDomainEscaped(con= st void *args G_GNUC_UNUSED =20 if ((rv =3D virCgroupNewPartition("/cgroup.evil", true, -1, &partition= cgroup1)) !=3D 0) { fprintf(stderr, "Failed to create /cgroup.evil cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 if ((rv =3D virCgroupNewPartition("/cgroup.evil/net_cls.evil", true, -= 1, &partitioncgroup2)) !=3D 0) { fprintf(stderr, "Failed to create /cgroup.evil/cpu.evil cgroup: %d= \n", -rv); - goto cleanup; + return -1; } =20 if ((rv =3D virCgroupNewPartition("/cgroup.evil/net_cls.evil/_evil.evi= l", true, -1, &partitioncgroup3)) !=3D 0) { fprintf(stderr, "Failed to create /cgroup.evil cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 if ((rv =3D virCgroupNewDomainPartition(partitioncgroup3, "lxc", "cpu.= foo", true, &domaincgroup)) !=3D 0) { fprintf(stderr, "Cannot create LXC cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 /* NB we're not expecting 'net_cls.evil' to be escaped, * since our fake /proc/cgroups pretends this controller * isn't compiled into the kernel */ - ret =3D validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evi= l.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0); - - cleanup: - virCgroupFree(partitioncgroup3); - virCgroupFree(partitioncgroup2); - virCgroupFree(partitioncgroup1); - virCgroupFree(domaincgroup); - return ret; + return validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evil= .evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0); } =20 static int testCgroupNewForSelfAllInOne(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup =3D NULL; const char *placement[VIR_CGROUP_CONTROLLER_LAST] =3D { [VIR_CGROUP_CONTROLLER_CPU] =3D "/", [VIR_CGROUP_CONTROLLER_CPUACCT] =3D "/", @@ -547,24 +511,19 @@ static int testCgroupNewForSelfAllInOne(const void *a= rgs G_GNUC_UNUSED) =20 if (virCgroupNewSelf(&cgroup) < 0) { fprintf(stderr, "Cannot create cgroup for self\n"); - goto cleanup; + return -1; } =20 - ret =3D validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, plac= ement, NULL, NULL, 0); - - cleanup: - virCgroupFree(cgroup); - return ret; + return validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, place= ment, NULL, NULL, 0); } =20 =20 static int testCgroupNewForSelfLogind(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; + g_autoptr(virCgroup) cgroup =3D NULL; =20 if (virCgroupNewSelf(&cgroup) >=3D 0) { fprintf(stderr, "Expected to fail, only systemd cgroup available.\= n"); - virCgroupFree(cgroup); return -1; } =20 @@ -574,8 +533,7 @@ static int testCgroupNewForSelfLogind(const void *args = G_GNUC_UNUSED) =20 static int testCgroupNewForSelfUnified(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup =3D NULL; const char *empty[VIR_CGROUP_CONTROLLER_LAST] =3D { 0 }; unsigned int controllers =3D (1 << VIR_CGROUP_CONTROLLER_CPU) | @@ -586,21 +544,17 @@ static int testCgroupNewForSelfUnified(const void *ar= gs G_GNUC_UNUSED) =20 if (virCgroupNewSelf(&cgroup) < 0) { fprintf(stderr, "Cannot create cgroup for self\n"); - goto cleanup; + return -1; } =20 - ret =3D validateCgroup(cgroup, "", empty, empty, empty, - "/not/really/sys/fs/cgroup", "/", controllers); - cleanup: - virCgroupFree(cgroup); - return ret; + return validateCgroup(cgroup, "", empty, empty, empty, + "/not/really/sys/fs/cgroup", "/", controllers); } =20 =20 static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; - int ret =3D -1; + g_autoptr(virCgroup) cgroup =3D NULL; const char *empty[VIR_CGROUP_CONTROLLER_LAST] =3D { 0 }; const char *mounts[VIR_CGROUP_CONTROLLER_LAST] =3D { [VIR_CGROUP_CONTROLLER_CPUSET] =3D "/not/really/sys/fs/cgroup/cpus= et", @@ -623,15 +577,11 @@ static int testCgroupNewForSelfHybrid(const void *arg= s G_GNUC_UNUSED) =20 if (virCgroupNewSelf(&cgroup) < 0) { fprintf(stderr, "Cannot create cgroup for self\n"); - goto cleanup; + return -1; } =20 - ret =3D validateCgroup(cgroup, "", mounts, empty, placement, - "/not/really/sys/fs/cgroup/unified", "/", control= lers); - - cleanup: - virCgroupFree(cgroup); - return ret; + return validateCgroup(cgroup, "", mounts, empty, placement, + "/not/really/sys/fs/cgroup/unified", "/", contro= llers); } =20 =20 @@ -679,7 +629,7 @@ static int testCgroupControllerAvailable(const void *ar= gs G_GNUC_UNUSED) =20 static int testCgroupGetPercpuStats(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; + g_autoptr(virCgroup) cgroup =3D NULL; size_t i; int rv, ret =3D -1; virTypedParameterPtr params =3D NULL; @@ -756,50 +706,44 @@ static int testCgroupGetPercpuStats(const void *args = G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(cgroup); VIR_FREE(params); return ret; } =20 static int testCgroupGetMemoryUsage(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; - int rv, ret =3D -1; + g_autoptr(virCgroup) cgroup =3D NULL; + int rv; unsigned long kb; =20 if ((rv =3D virCgroupNewPartition("/virtualmachines", true, (1 << VIR_CGROUP_CONTROLLER_MEMORY), &cgroup)) < 0) { fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", = -rv); - goto cleanup; + return -1; } =20 if ((rv =3D virCgroupGetMemoryUsage(cgroup, &kb)) < 0) { fprintf(stderr, "Could not retrieve GetMemoryUsage for /virtualmac= hines cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 if (kb !=3D 1421212UL) { fprintf(stderr, "Wrong value from virCgroupGetMemoryUsage (expected %ld)\n= ", 1421212UL); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virCgroupFree(cgroup); - return ret; + return 0; } =20 =20 static int testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; + g_autoptr(virCgroup) cgroup =3D NULL; int rv; - int ret =3D -1; size_t i; =20 const unsigned long long expected_values[] =3D { @@ -824,7 +768,7 @@ testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED) (1 << VIR_CGROUP_CONTROLLER_MEMORY), &cgroup)) < 0) { fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", = -rv); - goto cleanup; + return -1; } =20 if ((rv =3D virCgroupGetMemoryStat(cgroup, &values[0], @@ -832,7 +776,7 @@ testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED) &values[3], &values[4], &values[5])) < 0) { fprintf(stderr, "Could not retrieve GetMemoryStat for /virtualmach= ines cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 for (i =3D 0; i < G_N_ELEMENTS(expected_values); i++) { @@ -842,23 +786,19 @@ testCgroupGetMemoryStat(const void *args G_GNUC_UNUSE= D) "Wrong value (%llu) for %s from virCgroupGetMemoryStat= " "(expected %llu)\n", values[i], names[i], (expected_values[i] >> 10)); - goto cleanup; + return -1; } } =20 - ret =3D 0; - - cleanup: - virCgroupFree(cgroup); - return ret; + return 0; } =20 =20 static int testCgroupGetBlkioIoServiced(const void *args G_GNUC_UNUSED) { - virCgroupPtr cgroup =3D NULL; + g_autoptr(virCgroup) cgroup =3D NULL; size_t i; - int rv, ret =3D -1; + int rv; =20 const long long expected_values[] =3D { 119084214273ULL, @@ -878,14 +818,14 @@ static int testCgroupGetBlkioIoServiced(const void *a= rgs G_GNUC_UNUSED) (1 << VIR_CGROUP_CONTROLLER_BLKIO), &cgroup)) < 0) { fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", = -rv); - goto cleanup; + return -1; } =20 if ((rv =3D virCgroupGetBlkioIoServiced(cgroup, values, &values[1], &values[2], &values[3])) < 0) { fprintf(stderr, "Could not retrieve BlkioIoServiced for /virtualma= chines cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 for (i =3D 0; i < G_N_ELEMENTS(expected_values); i++) { @@ -893,22 +833,18 @@ static int testCgroupGetBlkioIoServiced(const void *a= rgs G_GNUC_UNUSED) fprintf(stderr, "Wrong value for %s from virCgroupBlkioIoServiced (exp= ected %lld)\n", names[i], expected_values[i]); - goto cleanup; + return -1; } } =20 - ret =3D 0; - - cleanup: - virCgroupFree(cgroup); - return ret; + return 0; } =20 static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUS= ED) { - virCgroupPtr cgroup =3D NULL; + g_autoptr(virCgroup) cgroup =3D NULL; size_t i; - int rv, ret =3D -1; + int rv; const long long expected_values0[] =3D { 59542107136ULL, 411440480256ULL, @@ -933,7 +869,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const voi= d *args G_GNUC_UNUSED) (1 << VIR_CGROUP_CONTROLLER_BLKIO), &cgroup)) < 0) { fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", = -rv); - goto cleanup; + return -1; } =20 if ((rv =3D virCgroupGetBlkioIoDeviceServiced(cgroup, @@ -941,7 +877,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const voi= d *args G_GNUC_UNUSED) values, &values[1], &values[2], &values[3])) <= 0) { fprintf(stderr, "Could not retrieve BlkioIoDeviceServiced for /vir= tualmachines cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 for (i =3D 0; i < G_N_ELEMENTS(expected_values0); i++) { @@ -949,7 +885,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const voi= d *args G_GNUC_UNUSED) fprintf(stderr, "Wrong value for %s from virCgroupGetBlkioIoDeviceServ= iced (expected %lld)\n", names[i], expected_values0[i]); - goto cleanup; + return -1; } } =20 @@ -958,7 +894,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const voi= d *args G_GNUC_UNUSED) values, &values[1], &values[2], &values[3])) <= 0) { fprintf(stderr, "Could not retrieve BlkioIoDeviceServiced for /vir= tualmachines cgroup: %d\n", -rv); - goto cleanup; + return -1; } =20 for (i =3D 0; i < G_N_ELEMENTS(expected_values1); i++) { @@ -966,15 +902,11 @@ static int testCgroupGetBlkioIoDeviceServiced(const v= oid *args G_GNUC_UNUSED) fprintf(stderr, "Wrong value for %s from virCgroupGetBlkioIoDeviceServ= iced (expected %lld)\n", names[i], expected_values1[i]); - goto cleanup; + return -1; } } =20 - ret =3D 0; - - cleanup: - virCgroupFree(cgroup); - return ret; + return 0; } =20 # define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX" --=20 2.26.2 From nobody Fri Apr 19 00:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1602167253; cv=none; d=zohomail.com; s=zohoarc; b=hKRGYj/ZjrgPUI1Ug+cQ5taWWg6cft3DrYuILOJChDaxMa+oRwPNNPSn8+N7SunjxKHeUuW60diU0A6BDIM7GuOy90JJ2MsqzK5vJwplw0pRi63T85GYyghSepA0pSgSF+Z74hq904+7zNStlJy82fOWBU0iODD1Gz5qwMwhxnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167253; 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=NGlqc1OWUavOOPomO9jdQJzEE+Q/tyawd+ayCAET7kQ=; b=ZTbkpociqrQ4Jz5YWGf+LywZa8PMNdRq8Js7JPxOZR559uIpOxbuAflxl6kHuYYZglH9Su70JGZIoeolMOptJ3bxeDjw9okOkRgqQp0X/p3gmCUqjj2TEPxG5F4ByHUmQQ/7HGSpkRJv9Dd5I41njOq8U1FPJZJYrQJ08HGZOww= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1602167253258759.2250853223086; Thu, 8 Oct 2020 07:27:33 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-477-WM9xZzrwOKunq5oSP78UrA-1; Thu, 08 Oct 2020 10:27:29 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA877191E2AA; Thu, 8 Oct 2020 14:27:21 +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 93D3919C4F; Thu, 8 Oct 2020 14:27:21 +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 5FF028C7C1; Thu, 8 Oct 2020 14:27:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098ERGjZ017261 for ; Thu, 8 Oct 2020 10:27:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 88F551EA; Thu, 8 Oct 2020 14:27:16 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0674B60CD1 for ; Thu, 8 Oct 2020 14:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602167252; 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=NGlqc1OWUavOOPomO9jdQJzEE+Q/tyawd+ayCAET7kQ=; b=Ngse6MG5X13q9kIpaslI6rZtlCa9kZVcV8BY+kQAoO1WZFh9LTJ4d97mHpbz4/WtqniYTl HyTA++kbzacD/n8qzHXmDPrqxxV1OHzBTibc3bPsvYlYufM53rddI7jZ+wBvbEo6fxW7Tm As0CxT5ae22lvVsxx5QOSbvID63E26c= X-MC-Unique: WM9xZzrwOKunq5oSP78UrA-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 10/10] tools: use g_autoptr for virCgroup Date: Thu, 8 Oct 2020 16:27:03 +0200 Message-Id: <8513f0f2a61c85973f0e588829250f2b59cbc09e.1602167149.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.23 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jonathon Jongsma --- tools/virt-host-validate-common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index 4d8ec38f88..9779eb7b3b 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -289,7 +289,7 @@ int virHostValidateCGroupControllers(const char *hvname, int controllers, virHostValidateLevel level) { - virCgroupPtr group =3D NULL; + g_autoptr(virCgroup) group =3D NULL; int ret =3D 0; size_t i; =20 @@ -315,8 +315,6 @@ int virHostValidateCGroupControllers(const char *hvname, } } =20 - virCgroupFree(group); - return ret; } #else /* !__linux__ */ --=20 2.26.2