From nobody Tue Feb 10 13:33:00 2026 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com 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 1628765559781498.41304332497964; Thu, 12 Aug 2021 03:52:39 -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-585-NmLY7pPbNdSU381hl_kLkQ-1; Thu, 12 Aug 2021 06:52:37 -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 E6A9692500; Thu, 12 Aug 2021 10:52:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3EEA12C82; Thu, 12 Aug 2021 10:52:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8F5DD4A7CA; Thu, 12 Aug 2021 10:52:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CAofrW015224 for ; Thu, 12 Aug 2021 06:50:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 83A9C202879E; Thu, 12 Aug 2021 10:50:41 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E33C202879D for ; Thu, 12 Aug 2021 10:50:38 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D5F31800182 for ; Thu, 12 Aug 2021 10:50:38 +0000 (UTC) Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-309-QkcPQ8fmNHemcbXG2hlv6A-1; Thu, 12 Aug 2021 06:50:37 -0400 Received: by mail-pj1-f45.google.com with SMTP id g12-20020a17090a7d0cb0290178f80de3d8so9948580pjl.2 for ; Thu, 12 Aug 2021 03:50:36 -0700 (PDT) Received: from localhost ([38.94.109.214]) by smtp.gmail.com with ESMTPSA id s20sm1738833pfw.143.2021.08.12.03.50.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 03:50:35 -0700 (PDT) X-MC-Unique: NmLY7pPbNdSU381hl_kLkQ-1 X-MC-Unique: QkcPQ8fmNHemcbXG2hlv6A-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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uaCGAkk5hk3OxRNjHwBB7owMojQSbZSMh3CyPtDPsyQ=; b=CopXVtFbS+CX4D/l6yeKWyPmt2gMcJQVX1iET6ObAB6vjGSnAicZ/0jV4sH9c9KzWK 3+nWAXdniCuCBjYHA4C2BLa0nz4RKLSKIQHa7b7ASwdnyMhDOOoNNUDXqhEjIKFw21FZ lTrSH58DPPFGJTbl8+j0QGXq4Pb8IrHCaWYhsc8QU9d+esV8Ra2CjiURrol/pDIMEZT7 1/1XpskScboZVpfFNwKZQZvXdM6JGI4MlpxJFYx1NY+jVQMbW24WaAEBl6N/1XaKKVF1 wmB8UIlGhU/E59ZvoGnKIwBWgopo+LfdSVOw6UYRSxJ/mLYG0eAA7CeZwPmK/IPXRzir dlcA== X-Gm-Message-State: AOAM532pdYFtQ49svg5dqXDK5KT0JYsMBJtcHSx6qeJcTAb6NIgaJg96 oG8W5HOUQ9Irypk6rpKB9HWLWc+EhxZcO2uTph8= X-Google-Smtp-Source: ABdhPJx1mk/7VPPNT4Jap/+zG2uAjGUsPP9Eh+Lbwzq9nQh/diCYa5GJTQH53TaXjdTFbvgMd9kCDw== X-Received: by 2002:a17:90a:2e88:: with SMTP id r8mr6415210pjd.169.1628765435764; Thu, 12 Aug 2021 03:50:35 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v3 09/11] test_driver: Implement virConnectGetAllDomainStats Date: Thu, 12 Aug 2021 18:50:00 +0800 Message-Id: <20210812105002.197134-10-lukedyue@gmail.com> In-Reply-To: <20210812105002.197134-1-lukedyue@gmail.com> References: <20210812105002.197134-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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-ZM-MESSAGEID: 1628765561082100001 Content-Type: text/plain; charset="utf-8" Implement virConnectGetAllDomainStats in a modular way just like QEMU driver, though remove some params in GetStatsWorker that we don't need in test driver currently. Only add the worker to get state so far, more worker will be added in the future. Signed-off-by: Luke Yue --- src/test/test_driver.c | 135 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 1d439a89b6..6eebd85cf3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9785,6 +9785,140 @@ testDomainSetIOThreadParams(virDomainPtr dom, return ret; } =20 +static int +testDomainGetStatsState(virDomainObj *dom, + virTypedParamList *params) +{ + if (virTypedParamListAddInt(params, dom->state.state, "state.state") <= 0) + return -1; + + if (virTypedParamListAddInt(params, dom->state.reason, "state.reason")= < 0) + return -1; + + return 0; +} + +typedef int +(*testDomainGetStatsFunc)(virDomainObj *dom, + virTypedParamList *list); + +struct testDomainGetStatsWorker { + testDomainGetStatsFunc func; + unsigned int stats; +}; + +static struct testDomainGetStatsWorker testDomainGetStatsWorkers[] =3D { + { testDomainGetStatsState, VIR_DOMAIN_STATS_STATE }, + { NULL, 0 } +}; + +static int +testDomainGetStats(virConnectPtr conn, + virDomainObj *dom, + unsigned int stats, + virDomainStatsRecordPtr *record) +{ + g_autofree virDomainStatsRecordPtr tmp =3D NULL; + g_autoptr(virTypedParamList) params =3D NULL; + size_t i; + + params =3D g_new0(virTypedParamList, 1); + + for (i =3D 0; testDomainGetStatsWorkers[i].func; i++) { + if (stats & testDomainGetStatsWorkers[i].stats) { + if (testDomainGetStatsWorkers[i].func(dom, params) < 0) + return -1; + } + } + + tmp =3D g_new0(virDomainStatsRecord, 1); + + if (!(tmp->dom =3D virGetDomain(conn, dom->def->name, + dom->def->uuid, dom->def->id))) + return -1; + + tmp->nparams =3D virTypedParamListStealParams(params, &tmp->params); + *record =3D g_steal_pointer(&tmp); + return 0; +} + +static int +testConnectGetAllDomainStats(virConnectPtr conn, + virDomainPtr *doms, + unsigned int ndoms, + unsigned int stats, + virDomainStatsRecordPtr **retStats, + unsigned int flags) +{ + testDriver *driver =3D conn->privateData; + unsigned int lflags =3D flags & (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTI= VE | + VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSIS= TENT | + VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE); + + unsigned int supported =3D VIR_DOMAIN_STATS_STATE; + virDomainObj **vms =3D NULL; + size_t nvms; + virDomainStatsRecordPtr *tmpstats =3D NULL; + int nstats =3D 0; + int ret =3D -1; + size_t i; + + virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT | + VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE | + VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT | + VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING | + VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS, -1); + + if (!stats) { + stats =3D supported; + } else if ((flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS) && + (stats & ~supported)) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, + _("Stats types bits 0x%x are not supported by this = daemon"), + stats & ~supported); + return -1; + } + + if (ndoms) { + if (virDomainObjListConvert(driver->domains, conn, doms, ndoms, &v= ms, + &nvms, NULL, lflags, true) < 0) + return -1; + } else { + if (virDomainObjListCollect(driver->domains, conn, &vms, &nvms, + NULL, lflags) < 0) + return -1; + } + + tmpstats =3D g_new0(virDomainStatsRecordPtr, nvms + 1); + + for (i =3D 0; i < nvms; i++) { + virDomainStatsRecordPtr tmp =3D NULL; + virDomainObj *vm =3D vms[i]; + + virObjectLock(vm); + + if ((testDomainGetStats(conn, vm, stats, &tmp)) < 0) + goto cleanup; + + virObjectUnlock(vm); + + if (!tmp) + goto cleanup; + + tmpstats[nstats++] =3D tmp; + } + + *retStats =3D g_steal_pointer(&tmpstats); + ret =3D nstats; + + cleanup: + virDomainStatsRecordListFree(tmpstats); + virObjectListFreeCount(vms, nvms); + + return ret; +} + /* * Test driver */ @@ -9799,6 +9933,7 @@ static virHypervisorDriver testHypervisorDriver =3D { .nodeGetCPUStats =3D testNodeGetCPUStats, /* 2.3.0 */ .nodeGetFreeMemory =3D testNodeGetFreeMemory, /* 2.3.0 */ .nodeGetFreePages =3D testNodeGetFreePages, /* 2.3.0 */ + .connectGetAllDomainStats =3D testConnectGetAllDomainStats, /* 7.7.0 */ .connectGetCapabilities =3D testConnectGetCapabilities, /* 0.2.1 */ .connectGetSysinfo =3D testConnectGetSysinfo, /* 2.3.0 */ .connectGetType =3D testConnectGetType, /* 2.3.0 */ --=20 2.32.0