From nobody Fri Dec 19 20:14:30 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1587477020; cv=none; d=zohomail.com; s=zohoarc; b=g7j1fhSTJDnpMPsh6wJTLBKUfmgvvJm0Z72415KemLmMG6AGWyPb4Vwsxbx1W083iRHq7FK65+yYZIk6iM+VeJxj4W7YLavZ6D7CBA0u+YmMQGU18OAldzlcmFjyFc29WeVynRrWbSY9XvO0gopHbxf+UnG97cNqSVe3wEVdFTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587477020; h=Content-Type:Content-Transfer-Encoding:Cc: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=7oHoQtsIkfGHzgvO9INxHKVS6PiUt6UZUNPnQEOZeSU=; b=b1iLo9ivOdRAs8VkTzwJtr8icpM8An8Fe7YHiS3QVJp6KleTpZZugb9i3UqwJW050/gdZ4hSy2Zsic0NVfV0rmW8vPuzzpE8kx4zDmcvrqLbH6ajH6mkhMRo+52cAGuAZa9zNS4Dm8qACYG4sncKAMEyjUyFCrib8D+f5N7Y2Z4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1587477020079832.101404008644; Tue, 21 Apr 2020 06:50:20 -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-208-2R-VWIMaPJeqy_E9Fm_FnA-1; Tue, 21 Apr 2020 09:50:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A2F81B2C980; Tue, 21 Apr 2020 13:50:10 +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 6B6505C1B2; Tue, 21 Apr 2020 13:50:09 +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 CB3C6941A1; Tue, 21 Apr 2020 13:50:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03LDo2Oe003201 for ; Tue, 21 Apr 2020 09:50:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id B708C1C0EEB; Tue, 21 Apr 2020 13:50:02 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B248E9D60 for ; Tue, 21 Apr 2020 13:50:00 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C3C91019E13 for ; Tue, 21 Apr 2020 13:50:00 +0000 (UTC) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-471-7aJn3rF1OmihD6jexOVgEA-1; Tue, 21 Apr 2020 09:49:58 -0400 Received: by mail-wm1-f65.google.com with SMTP id u127so3775741wmg.1 for ; Tue, 21 Apr 2020 06:49:57 -0700 (PDT) Received: from localhost.localdomain (public-gprs377075.centertel.pl. [37.47.104.52]) by smtp.gmail.com with ESMTPSA id q10sm3981826wrv.95.2020.04.21.06.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 06:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587477018; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=7oHoQtsIkfGHzgvO9INxHKVS6PiUt6UZUNPnQEOZeSU=; b=GvN6amdGSa79NIeL/KwQd33xb82wxfTFQg2HOkd89QS8oHSB+xKDlWeLng7xL1Fu+IaErI nv0nD7gkzTV8NlrRVYMXyLmjw2j79vulNHbLs9Uk/gaJI7/wRA8UyJ9Et5rtNQxf+3JuBg 7vcbloypfLWKhFz4yISZ/CQaeBZPGxE= X-MC-Unique: 2R-VWIMaPJeqy_E9Fm_FnA-1 X-MC-Unique: 7aJn3rF1OmihD6jexOVgEA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P9tRI8edfkoms4Da9N2fYh86OzaYVKV0p/WcfRqoq3Q=; b=DgFvLg6lTCj0BopLmHj8gO8ASwYZeipyKgLDwQzBv7/rn/GUayq9rO06f7Zd06i783 xHkfxELTvUuAVnGOyY4SMkykdxyn9VbYNfqSKyzTCi3cDsJtRgnZYVmazajH7HyLCEnh h/wvxCj6RrE9aM1W/JEnI8ZmZds1jv0HXZQN6QNxfZx4/8RxN9Mhwz2+L4rlCzTIXkHk wgA3cmfxarMrJfUyMNSbcilOHj1gg45417taQtlQgFn9l+rlNasKNEOEiE4voEy14EI3 eypgVBKsJxlRRCZbXTH+DBrRNIwV7RzDoOY2i5MPbuUiXjQhaeylaGyrWN1948jx8Wvz 2bsg== X-Gm-Message-State: AGi0Pua4nwmN0EBA/ovuIORI7ABH5Iwq/wGM0bFD41r2W+9dpIBux+Ok P+wJaimIFcpiGI71jbFdU8ThHNHFJPk= X-Google-Smtp-Source: APiQypKd47T17msTpfInSTQnL0o4laF5MpJhhQF3SGfaoAE7SY/CaRL6mMelbi+xOvnfGwhiodzgsA== X-Received: by 2002:a7b:c5d8:: with SMTP id n24mr4933096wmk.158.1587476996100; Tue, 21 Apr 2020 06:49:56 -0700 (PDT) From: Rafael Fonseca To: libvir-list@redhat.com Subject: [PATCH v2 01/40] util: virresctrl: convert classes to GObject Date: Tue, 21 Apr 2020 15:48:42 +0200 Message-Id: <20200421134921.3717019-2-r4f4rfs@gmail.com> In-Reply-To: <20200421134921.3717019-1-r4f4rfs@gmail.com> References: <20200421134921.3717019-1-r4f4rfs@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03LDo2Oe003201 X-loop: libvir-list@redhat.com Cc: Rafael Fonseca 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.16 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" This patch changes virResctrlInfo, virResctrlAlloc and virResctrlMonitor from virObject to GObject. Signed-off-by: Rafael Fonseca --- src/conf/capabilities.c | 2 +- src/conf/domain_conf.c | 19 ++--- src/libvirt_private.syms | 3 + src/util/virresctrl.c | 164 ++++++++++++++++++++------------------- src/util/virresctrl.h | 15 ++-- tests/virresctrltest.c | 3 +- 6 files changed, 107 insertions(+), 99 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 99b69aebb5..0741d76731 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -266,7 +266,7 @@ virCapsDispose(void *object) VIR_FREE(caps->host.netprefix); VIR_FREE(caps->host.pagesSize); virCPUDefFree(caps->host.cpu); - virObjectUnref(caps->host.resctrl); + g_clear_object(&caps->host.resctrl); } =20 /** diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8700d56761..674cfa408e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3304,7 +3304,7 @@ virDomainResctrlMonDefFree(virDomainResctrlMonDefPtr = domresmon) return; =20 virBitmapFree(domresmon->vcpus); - virObjectUnref(domresmon->instance); + g_clear_object(&domresmon->instance); VIR_FREE(domresmon); } =20 @@ -3320,7 +3320,7 @@ virDomainResctrlDefFree(virDomainResctrlDefPtr resctr= l) for (i =3D 0; i < resctrl->nmonitors; i++) virDomainResctrlMonDefFree(resctrl->monitors[i]); =20 - virObjectUnref(resctrl->alloc); + g_clear_object(&resctrl->alloc); virBitmapFree(resctrl->vcpus); VIR_FREE(resctrl->monitors); VIR_FREE(resctrl); @@ -19950,11 +19950,6 @@ virDomainResctrlMonDefParse(virDomainDefPtr def, domresmon->tag =3D tag; =20 domresmon->instance =3D virResctrlMonitorNew(); - if (!domresmon->instance) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not create monitor")); - goto cleanup; - } =20 if (tag =3D=3D VIR_RESCTRL_MONITOR_TYPE_CACHE) { tmp =3D virXMLPropString(nodes[i], "level"); @@ -20064,7 +20059,7 @@ virDomainResctrlNew(xmlNodePtr node, goto cleanup; } =20 - resctrl->alloc =3D virObjectRef(alloc); + resctrl->alloc =3D g_object_ref(alloc); =20 ret =3D g_steal_pointer(&resctrl); cleanup: @@ -20111,8 +20106,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def, return -1; } =20 - if (!(alloc =3D virResctrlAllocNew())) - return -1; + alloc =3D virResctrlAllocNew(); =20 for (i =3D 0; i < n; i++) { if (virDomainCachetuneDefParseCache(ctxt, nodes[i], alloc) < 0) @@ -20297,10 +20291,9 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, return -1; =20 if (resctrl) { - alloc =3D virObjectRef(resctrl->alloc); + alloc =3D g_object_ref(resctrl->alloc); } else { - if (!(alloc =3D virResctrlAllocNew())) - return -1; + alloc =3D virResctrlAllocNew(); } =20 /* First, parse element if any element exists= */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 182a570382..7bba191b03 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2916,6 +2916,9 @@ virRandomInt; =20 =20 # util/virresctrl.h +vir_resctrl_alloc_get_type; +vir_resctrl_info_get_type; +vir_resctrl_monitor_get_type; virCacheKernelTypeFromString; virCacheKernelTypeToString; virCacheTypeFromString; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index c537d606cc..ce11a24a54 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -112,12 +112,6 @@ typedef struct _virResctrlAllocMemBW virResctrlAllocMe= mBW; typedef virResctrlAllocMemBW *virResctrlAllocMemBWPtr; =20 =20 -/* Class definitions and initializations */ -static virClassPtr virResctrlInfoClass; -static virClassPtr virResctrlAllocClass; -static virClassPtr virResctrlMonitorClass; - - /* virResctrlInfo */ struct _virResctrlInfoPerType { /* Kernel-provided information */ @@ -182,7 +176,7 @@ struct _virResctrlInfoMongrp { }; =20 struct _virResctrlInfo { - virObject parent; + GObject parent; =20 virResctrlInfoPerLevelPtr *levels; size_t nlevels; @@ -192,14 +186,17 @@ struct _virResctrlInfo { virResctrlInfoMongrpPtr monitor_info; }; =20 +/* Class definitions and initializations */ +G_DEFINE_TYPE(virResctrlInfo, vir_resctrl_info, G_TYPE_OBJECT); + =20 static void -virResctrlInfoDispose(void *obj) +virResctrlInfoFinalize(GObject *obj) { size_t i =3D 0; size_t j =3D 0; =20 - virResctrlInfoPtr resctrl =3D obj; + virResctrlInfoPtr resctrl =3D VIR_RESCTRL_INFO(obj); =20 for (i =3D 0; i < resctrl->nlevels; i++) { virResctrlInfoPerLevelPtr level =3D resctrl->levels[i]; @@ -221,6 +218,8 @@ virResctrlInfoDispose(void *obj) VIR_FREE(resctrl->membw_info); VIR_FREE(resctrl->levels); VIR_FREE(resctrl->monitor_info); + + G_OBJECT_CLASS(vir_resctrl_info_parent_class)->finalize(obj); } =20 =20 @@ -334,7 +333,7 @@ struct _virResctrlAllocMemBW { }; =20 struct _virResctrlAlloc { - virObject parent; + GObject parent; =20 virResctrlAllocPerLevelPtr *levels; size_t nlevels; @@ -355,7 +354,7 @@ struct _virResctrlAlloc { * memory bandwidth. */ struct _virResctrlMonitor { - virObject parent; + GObject parent; =20 /* Each virResctrlMonitor is associated with one specific allocation, * either the root directory allocation under /sys/fs/resctrl or a @@ -372,15 +371,20 @@ struct _virResctrlMonitor { char *path; }; =20 +/* Class definitions and initializations */ +G_DEFINE_TYPE(virResctrlAlloc, vir_resctrl_alloc, G_TYPE_OBJECT); +G_DEFINE_TYPE(virResctrlMonitor, vir_resctrl_monitor, G_TYPE_OBJECT); + + =20 static void -virResctrlAllocDispose(void *obj) +virResctrlAllocFinalize(GObject *obj) { size_t i =3D 0; size_t j =3D 0; size_t k =3D 0; =20 - virResctrlAllocPtr alloc =3D obj; + virResctrlAllocPtr alloc =3D VIR_RESCTRL_ALLOC(obj); =20 for (i =3D 0; i < alloc->nlevels; i++) { virResctrlAllocPerLevelPtr level =3D alloc->levels[i]; @@ -419,38 +423,71 @@ virResctrlAllocDispose(void *obj) VIR_FREE(alloc->id); VIR_FREE(alloc->path); VIR_FREE(alloc->levels); + + G_OBJECT_CLASS(vir_resctrl_alloc_parent_class)->finalize(obj); } =20 =20 static void -virResctrlMonitorDispose(void *obj) +virResctrlMonitorDispose(GObject *obj) { - virResctrlMonitorPtr monitor =3D obj; + virResctrlMonitorPtr monitor =3D VIR_RESCTRL_MONITOR(obj); + + g_clear_object(&monitor->alloc); + + G_OBJECT_CLASS(vir_resctrl_alloc_parent_class)->dispose(obj); +} + +static void +virResctrlMonitorFinalize(GObject *obj) +{ + virResctrlMonitorPtr monitor =3D VIR_RESCTRL_MONITOR(obj); =20 - virObjectUnref(monitor->alloc); VIR_FREE(monitor->id); VIR_FREE(monitor->path); + + G_OBJECT_CLASS(vir_resctrl_monitor_parent_class)->finalize(obj); } =20 +static void +vir_resctrl_info_init(virResctrlInfo *resctrlinfo G_GNUC_UNUSED) +{ +} =20 -/* Global initialization for classes */ -static int -virResctrlOnceInit(void) +static void +vir_resctrl_info_class_init(virResctrlInfoClass *klass) { - if (!VIR_CLASS_NEW(virResctrlInfo, virClassForObject())) - return -1; + GObjectClass *obj =3D G_OBJECT_CLASS(klass); =20 - if (!VIR_CLASS_NEW(virResctrlAlloc, virClassForObject())) - return -1; + obj->finalize =3D virResctrlInfoFinalize; +} =20 - if (!VIR_CLASS_NEW(virResctrlMonitor, virClassForObject())) - return -1; +static void +vir_resctrl_alloc_init(virResctrlAlloc *resctrlalloc G_GNUC_UNUSED) +{ +} =20 - return 0; +static void +vir_resctrl_alloc_class_init(virResctrlAllocClass *klass) +{ + GObjectClass *obj =3D G_OBJECT_CLASS(klass); + + obj->finalize =3D virResctrlAllocFinalize; +} + +static void +vir_resctrl_monitor_init(virResctrlMonitor *resctrlmon G_GNUC_UNUSED) +{ } =20 -VIR_ONCE_GLOBAL_INIT(virResctrl); +static void +vir_resctrl_monitor_class_init(virResctrlMonitorClass *klass) +{ + GObjectClass *obj =3D G_OBJECT_CLASS(klass); =20 + obj->dispose =3D virResctrlMonitorDispose; + obj->finalize =3D virResctrlMonitorFinalize; +} =20 /* Common functions */ static int @@ -793,21 +830,13 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) virResctrlInfoPtr virResctrlInfoNew(void) { - virResctrlInfoPtr ret =3D NULL; - - if (virResctrlInitialize() < 0) - return NULL; - - ret =3D virObjectNew(virResctrlInfoClass); - if (!ret) - return NULL; + g_autoptr(virResctrlInfo) ret =3D VIR_RESCTRL_INFO(g_object_new(VIR_TY= PE_RESCTRL_INFO, NULL)); =20 if (virResctrlGetInfo(ret) < 0) { - virObjectUnref(ret); return NULL; } =20 - return ret; + return g_steal_pointer(&ret); } =20 =20 @@ -1034,10 +1063,7 @@ virResctrlInfoGetMonitorPrefix(virResctrlInfoPtr res= ctrl, virResctrlAllocPtr virResctrlAllocNew(void) { - if (virResctrlInitialize() < 0) - return NULL; - - return virObjectNew(virResctrlAllocClass); + return VIR_RESCTRL_ALLOC(g_object_new(VIR_TYPE_RESCTRL_ALLOC, NULL)); } =20 =20 @@ -1769,8 +1795,7 @@ virResctrlAllocGetGroup(virResctrlInfoPtr resctrl, =20 error: VIR_FREE(schemata); - virObjectUnref(*alloc); - *alloc =3D NULL; + g_clear_object(alloc); return -1; } =20 @@ -1779,9 +1804,7 @@ static virResctrlAllocPtr virResctrlAllocGetDefault(virResctrlInfoPtr resctrl) { virResctrlAllocPtr ret =3D NULL; - int rv =3D virResctrlAllocGetGroup(resctrl, ".", &ret); - - if (rv =3D=3D -2) { + if (virResctrlAllocGetGroup(resctrl, ".", &ret) =3D=3D -2) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not read schemata file for the default gro= up")); } @@ -1836,9 +1859,6 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) virResctrlAllocPtr ret =3D virResctrlAllocNew(); virBitmapPtr mask =3D NULL; =20 - if (!ret) - return NULL; - for (i =3D 0; i < info->nlevels; i++) { virResctrlInfoPerLevelPtr i_level =3D info->levels[i]; =20 @@ -1884,8 +1904,7 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) virBitmapFree(mask); return ret; error: - virObjectUnref(ret); - ret =3D NULL; + g_clear_object(&ret); goto cleanup; } =20 @@ -1907,7 +1926,7 @@ virResctrlAllocPtr virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) { virResctrlAllocPtr ret =3D NULL; - virResctrlAllocPtr alloc =3D NULL; + g_autoptr(virResctrlAlloc) alloc =3D NULL; struct dirent *ent =3D NULL; DIR *dirp =3D NULL; int rv =3D -1; @@ -1927,7 +1946,7 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) goto error; =20 virResctrlAllocSubtract(ret, alloc); - virObjectUnref(alloc); + g_clear_object(&alloc); =20 if (virDirOpen(&dirp, SYSFS_RESCTRL_PATH) < 0) goto error; @@ -1948,20 +1967,17 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) } =20 virResctrlAllocSubtract(ret, alloc); - virObjectUnref(alloc); - alloc =3D NULL; + g_clear_object(&alloc); } if (rv < 0) goto error; =20 cleanup: - virObjectUnref(alloc); VIR_DIR_CLOSE(dirp); return ret; =20 error: - virObjectUnref(ret); - ret =3D NULL; + g_clear_object(&ret); goto cleanup; } =20 @@ -2229,10 +2245,9 @@ static int virResctrlAllocAssign(virResctrlInfoPtr resctrl, virResctrlAllocPtr alloc) { - int ret =3D -1; unsigned int level =3D 0; - virResctrlAllocPtr alloc_free =3D NULL; - virResctrlAllocPtr alloc_default =3D NULL; + g_autoptr(virResctrlAlloc) alloc_free =3D NULL; + g_autoptr(virResctrlAlloc) alloc_default =3D NULL; =20 alloc_free =3D virResctrlAllocGetUnused(resctrl); if (!alloc_free) @@ -2240,16 +2255,16 @@ virResctrlAllocAssign(virResctrlInfoPtr resctrl, =20 alloc_default =3D virResctrlAllocGetDefault(resctrl); if (!alloc_default) - goto cleanup; + return -1; =20 if (virResctrlAllocMemoryBandwidth(resctrl, alloc) < 0) - goto cleanup; + return -1; =20 if (virResctrlAllocCopyMasks(alloc, alloc_default) < 0) - goto cleanup; + return -1; =20 if (virResctrlAllocCopyMemBW(alloc, alloc_default) < 0) - goto cleanup; + return -1; =20 for (level =3D 0; level < alloc->nlevels; level++) { virResctrlAllocPerLevelPtr a_level =3D alloc->levels[level]; @@ -2266,7 +2281,7 @@ virResctrlAllocAssign(virResctrlInfoPtr resctrl, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Cache level %d does not support tuning"), level); - goto cleanup; + return -1; } =20 for (type =3D 0; type < VIR_CACHE_TYPE_LAST; type++) { @@ -2282,7 +2297,7 @@ virResctrlAllocAssign(virResctrlInfoPtr resctrl, _("Cache level %d does not support tuning f= or " "scope type '%s'"), level, virCacheTypeToString(type)); - goto cleanup; + return -1; } =20 for (cache =3D 0; cache < a_type->nsizes; cache++) { @@ -2290,16 +2305,12 @@ virResctrlAllocAssign(virResctrlInfoPtr resctrl, virResctrlInfoPerTypePtr i_type =3D i_level->types[type]; =20 if (virResctrlAllocFindUnused(alloc, i_type, f_type, level= , type, cache) < 0) - goto cleanup; + return -1; } } } =20 - ret =3D 0; - cleanup: - virObjectUnref(alloc_free); - virObjectUnref(alloc_default); - return ret; + return 0; } =20 =20 @@ -2506,10 +2517,7 @@ virResctrlAllocRemove(virResctrlAllocPtr alloc) virResctrlMonitorPtr virResctrlMonitorNew(void) { - if (virResctrlInitialize() < 0) - return NULL; - - return virObjectNew(virResctrlMonitorClass); + return VIR_RESCTRL_MONITOR(g_object_new(VIR_TYPE_RESCTRL_MONITOR, NULL= )); } =20 =20 @@ -2623,7 +2631,7 @@ void virResctrlMonitorSetAlloc(virResctrlMonitorPtr monitor, virResctrlAllocPtr alloc) { - monitor->alloc =3D virObjectRef(alloc); + monitor->alloc =3D g_object_ref(alloc); } =20 =20 diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index dcd9ca2bb2..6724d904d1 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -19,8 +19,8 @@ #pragma once =20 #include "internal.h" +#include =20 -#include "virobject.h" #include "virbitmap.h" #include "virenum.h" =20 @@ -93,7 +93,9 @@ struct _virResctrlInfoMon { unsigned int cache_level; }; =20 -typedef struct _virResctrlInfo virResctrlInfo; +#define VIR_TYPE_RESCTRL_INFO vir_resctrl_info_get_type() +G_DECLARE_FINAL_TYPE(virResctrlInfo, vir_resctrl_info, VIR, RESCTRL_INFO, = GObject); + typedef virResctrlInfo *virResctrlInfoPtr; =20 virResctrlInfoPtr @@ -111,10 +113,11 @@ virResctrlInfoGetMemoryBandwidth(virResctrlInfoPtr re= sctrl, unsigned int level, virResctrlInfoMemBWPerNodePtr control); /* Alloc-related things */ -typedef struct _virResctrlAlloc virResctrlAlloc; +#define VIR_TYPE_RESCTRL_ALLOC vir_resctrl_alloc_get_type() +G_DECLARE_FINAL_TYPE(virResctrlAlloc, vir_resctrl_alloc, VIR, RESCTRL_ALLO= C, GObject); + typedef virResctrlAlloc *virResctrlAllocPtr; =20 -G_DEFINE_AUTOPTR_CLEANUP_FUNC(virResctrlAlloc, virObjectUnref); =20 =20 typedef int virResctrlAllocForeachCacheCallback(unsigned int level, @@ -190,7 +193,9 @@ virResctrlInfoGetMonitorPrefix(virResctrlInfoPtr resctr= l, =20 /* Monitor-related things */ =20 -typedef struct _virResctrlMonitor virResctrlMonitor; +#define VIR_TYPE_RESCTRL_MONITOR vir_resctrl_monitor_get_type() +G_DECLARE_FINAL_TYPE(virResctrlMonitor, vir_resctrl_monitor, VIR, RESCTRL_= MONITOR, GObject); + typedef virResctrlMonitor *virResctrlMonitorPtr; =20 typedef struct _virResctrlMonitorStats virResctrlMonitorStats; diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c index bb6d0fe48e..91baef506d 100644 --- a/tests/virresctrltest.c +++ b/tests/virresctrltest.c @@ -21,7 +21,7 @@ test_virResctrlGetUnused(const void *opaque) char *system_dir =3D NULL; char *resctrl_dir =3D NULL; int ret =3D -1; - virResctrlAllocPtr alloc =3D NULL; + g_autoptr(virResctrlAlloc) alloc =3D NULL; char *schemata_str =3D NULL; char *schemata_file; virCapsPtr caps =3D NULL; @@ -66,7 +66,6 @@ test_virResctrlGetUnused(const void *opaque) ret =3D 0; cleanup: virObjectUnref(caps); - virObjectUnref(alloc); VIR_FREE(system_dir); VIR_FREE(resctrl_dir); VIR_FREE(schemata_str); --=20 2.25.3