From nobody Mon Feb 9 09:32:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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 [170.10.129.124]) by mx.zohomail.com with SMTPS id 1631719891972697.2571722929746; Wed, 15 Sep 2021 08:31:31 -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-43-kXski1R4OtyRYSVwxsfnmA-1; Wed, 15 Sep 2021 11:31:29 -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 0F74E100CCC9; Wed, 15 Sep 2021 15:31:24 +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 E09BF60C81; Wed, 15 Sep 2021 15:31:23 +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 AB4C1181A1CF; Wed, 15 Sep 2021 15:31:23 +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 18FFVLrd028996 for ; Wed, 15 Sep 2021 11:31:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 091BB2121C37; Wed, 15 Sep 2021 15:31:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 029032121C39 for ; Wed, 15 Sep 2021 15:31:18 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 2103A8934E1 for ; Wed, 15 Sep 2021 15:31:18 +0000 (UTC) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-iS5eHfOjPVemfggvloZ_6g-1; Wed, 15 Sep 2021 11:31:14 -0400 Received: by mail-pf1-f174.google.com with SMTP id y17so2935269pfl.13 for ; Wed, 15 Sep 2021 08:31:14 -0700 (PDT) Received: from localhost ([103.149.249.103]) by smtp.gmail.com with ESMTPSA id b20sm298910pfl.9.2021.09.15.08.31.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 08:31:12 -0700 (PDT) X-MC-Unique: kXski1R4OtyRYSVwxsfnmA-1 X-MC-Unique: iS5eHfOjPVemfggvloZ_6g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ezW5zRfspp1V/4FmiQQS+v9DncJeA+0XL2quRzc1iFU=; b=DIp+rIi+8V1gpVEyBIaJbC7q08ZfqNNqg7cuCZwIKZLVHkBkPhi9w+51HfQgQgtVU7 lZezoCY6lc7hKO6CXWPk3+Bmx6WU5IVVec5yEkzJaohYCFh6E1F/uLK2fI5EGBfl8Dyf +UA5GxlJK143dLdx37sfBcea8Q8APTsPrJUiDngKN8STs9w4gx1V2eMe0z48KSjWO8Km iiSHGuECk6TtexPo2j5wxY6QyR8DGrBSU3qkHZATWsY70HpHg5ObqEuyqsPO9HKBmxx4 dpNvUP7LuPRUnW0cj/J3f27en5UfxS3RyG8y0eKUPQEJ9L3H75EPgI8toyRvPcm7IHp0 15tw== X-Gm-Message-State: AOAM533GPBUnodkipnMzGRbr0DOZmR9YUKwSEVBG3wloqVVBn/734D6r Nykfmyue6USjVrYpvlSC7S0GrnDN4OangN61atw= X-Google-Smtp-Source: ABdhPJz6r95rWkC+7Kvfb8Rz7aX23/rJkMipFarBr4idA3tb/0mSE6cffVblfDCKX9dtUSNNn097CQ== X-Received: by 2002:a63:3587:: with SMTP id c129mr318105pga.127.1631719873291; Wed, 15 Sep 2021 08:31:13 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v4 09/11] test_driver: Implement virConnectGetAllDomainStats Date: Wed, 15 Sep 2021 23:30:30 +0800 Message-Id: <20210915153032.121221-10-lukedyue@gmail.com> In-Reply-To: <20210915153032.121221-1-lukedyue@gmail.com> References: <20210915153032.121221-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.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-ZM-MESSAGEID: 1631719894394100001 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 | 137 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 7cff26776a..a6f7de2ccd 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9881,6 +9881,142 @@ 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) { + virObjectUnlock(vm); + 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 */ @@ -9895,6 +10031,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.8.0 */ .connectGetCapabilities =3D testConnectGetCapabilities, /* 0.2.1 */ .connectGetSysinfo =3D testConnectGetSysinfo, /* 2.3.0 */ .connectGetType =3D testConnectGetType, /* 2.3.0 */ --=20 2.33.0