From nobody Mon Feb 9 12:15:30 2026 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; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612173386; cv=none; d=zohomail.com; s=zohoarc; b=CRI5CmUYiesXaCaXLyZL9Mm+YlzQD+UmmyGboye3htnxyS7W3eSM3AHb/6RD+xpwvYCIEXch6pywjroEA6X15GHDx5S+iQvxwc86zL6rugxnSnDZRef1TGDq5BB6nigERQuVdc0VDLzI2O6Z5uU2+GWBNAU+KFKQ+atno+a9VlM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612173386; 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=o09Hk5VoJYsg38GBjFevkovZ/b/KapmNbfGo5GrHVks=; b=c2jD8f4LaMtNC0G+znVm7k2F4/fH1Uk0cGXKYS1wyYahiEeyElMX5ZZMHKNVjtIgykLzjgLRWSvt/eS0fR078Lbs/yzROjmhL7csFBo7Xh/ncsMJyGwzuWOUPlQ4nbdS4LIoxJT02jmx4LtYSTJu8ZoPSze9tscMQwS9W2Ssb2g= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1612173386307649.2804300478125; Mon, 1 Feb 2021 01:56:26 -0800 (PST) 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-38-jvTp6bBSOMmaBnRbyHe5vw-1; Mon, 01 Feb 2021 04:56:23 -0500 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 44820803630; Mon, 1 Feb 2021 09:56:15 +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 0D0E060C68; Mon, 1 Feb 2021 09:56:15 +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 C95CF1809CA2; Mon, 1 Feb 2021 09:56:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1119uA78021935 for ; Mon, 1 Feb 2021 04:56:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 633871004026; Mon, 1 Feb 2021 09:56:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EB15100402E for ; Mon, 1 Feb 2021 09:56:10 +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-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4CA7E811E76 for ; Mon, 1 Feb 2021 09:56:10 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-451-OUSZ6lvEOf2uUBFHxM4gIg-1; Mon, 01 Feb 2021 04:55:57 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DTjwC6qJqzjHQL; Mon, 1 Feb 2021 17:54:35 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Mon, 1 Feb 2021 17:55:44 +0800 X-MC-Unique: jvTp6bBSOMmaBnRbyHe5vw-1 X-MC-Unique: OUSZ6lvEOf2uUBFHxM4gIg-1 From: Hao Wang To: Subject: [PATCH v5 1/5] migration/dirtyrate: Introduce DomainGetDirtyRateInfo API Date: Mon, 1 Feb 2021 17:55:39 +0800 Message-ID: <20210201095543.936333-2-wanghao232@huawei.com> In-Reply-To: <20210201095543.936333-1-wanghao232@huawei.com> References: <20210201095543.936333-1-wanghao232@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected 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.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1119uA78021935 X-loop: libvir-list@redhat.com Cc: yubihong@huawei.com, zhengchuan@huawei.com, pkrempa@redhat.com, zhang.zhanghailiang@huawei.com, mprivozn@redhat.com, danielhb413@gmail.com, xiexiangyou@huawei.com, alex.chen@huawei.com, hhan@redhat.com, wanghao232@huawei.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 Content-Type: text/plain; charset="utf-8" Introduce DomainGetDirtyRateInfo API to get domain's memory dirty rate info which may be expected by user in order to decide whether it's proper to be migrated out or not. Using flags to control the action of the API: If the VIR_DOMAIN_DIRTYRATE_CALC flag is set, this will calculate domain's memory dirty rate within specific time. If the VIR_DOMAIN_DIRTYRATE_QUERY flag is set, this will query the dirty rate info calculated last time. The VIR_DOMAIN_DIRTYRATE_DEFAULT flag is equal to both VIR_DOMAIN_DIRTYRATE_CALC and VIR_DOMAIN_DIRTYRATE_QUERY. Signed-off-by: Hao Wang Signed-off-by: Zhou Yimin Reviewed-by: Chuan Zheng --- include/libvirt/libvirt-domain.h | 59 ++++++++++++++++++++++++++++++++ src/driver-hypervisor.h | 7 ++++ src/libvirt-domain.c | 56 ++++++++++++++++++++++++++++++ src/libvirt_public.syms | 5 +++ src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 21 +++++++++++- 6 files changed, 148 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index de2456812c..77b46c2018 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -5119,4 +5119,63 @@ int virDomainAuthorizedSSHKeysSet(virDomainPtr domai= n, unsigned int nkeys, unsigned int flags); =20 +/** + * virDomainDirtyRateStatus: + * + * Details on the cause of a dirty rate calculation status. + */ +typedef enum { + VIR_DOMAIN_DIRTYRATE_UNSTARTED =3D 0, /* the dirtyrate calculation has + not been started */ + VIR_DOMAIN_DIRTYRATE_MEASURING =3D 1, /* the dirtyrate calculation is + measuring */ + VIR_DOMAIN_DIRTYRATE_MEASURED =3D 2, /* the dirtyrate calculation is + completed */ + +# ifdef VIR_ENUM_SENTINELS + VIR_DOMAIN_DIRTYRATE_LAST +# endif +} virDomainDirtyRateStatus; + +/** + * virDomainDirtyRateInfo: + * + * a virDomainDirtyRateInfo is a structure filled by virDomainGetDirtyRate= () + * and extracting dirty rate infomation for a given active Domain. + */ + +typedef struct _virDomainDirtyRateInfo virDomainDirtyRateInfo; +struct _virDomainDirtyRateInfo { + int status; /* the status of dirtyrate calculation, one of + virDomainDirtyRateStatus */ + long long dirtyRate; /* the dirtyrate in MB/s */ + long long startTime; /* the start time of dirtyrate calculation */ + int calcTime; /* the period of dirtyrate calculation */ +}; + +/** + * virDomainDirtyRateInfoPtr: + * + * a virDomainDirtyRateInfoPtr is a pointer to a virDomainDirtyRateInfo st= ructure. + */ + +typedef virDomainDirtyRateInfo *virDomainDirtyRateInfoPtr; + +/** + * virDomainDirtyRateFlags: + * + * Details on the flags used by getdirtyrate api. + */ +typedef enum { + VIR_DOMAIN_DIRTYRATE_DEFAULT =3D 0, /* default domdirtyrate behav= ior: + calculate and query */ + VIR_DOMAIN_DIRTYRATE_CALC =3D 1 << 0, /* calculate domain's dirtyra= te */ + VIR_DOMAIN_DIRTYRATE_QUERY =3D 1 << 1, /* query domain's dirtyrate */ +} virDomainDirtyRateFlags; + +int virDomainGetDirtyRateInfo(virDomainPtr domain, + virDomainDirtyRateInfoPtr info, + int sec, + unsigned int flags); + #endif /* LIBVIRT_DOMAIN_H */ diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 9e8fe89921..5ad681997b 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1400,6 +1400,12 @@ typedef int unsigned int nkeys, unsigned int flags); =20 +typedef int +(*virDrvDomainGetDirtyRateInfo)(virDomainPtr domain, + virDomainDirtyRateInfoPtr info, + int sec, + unsigned int flags); + typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; =20 @@ -1665,4 +1671,5 @@ struct _virHypervisorDriver { virDrvDomainBackupGetXMLDesc domainBackupGetXMLDesc; virDrvDomainAuthorizedSSHKeysGet domainAuthorizedSSHKeysGet; virDrvDomainAuthorizedSSHKeysSet domainAuthorizedSSHKeysSet; + virDrvDomainGetDirtyRateInfo domainGetDirtyRateInfo; }; diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index c9f8ffdb56..777028c499 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -13102,3 +13102,59 @@ virDomainAuthorizedSSHKeysSet(virDomainPtr domain, virDispatchError(conn); return -1; } + + +/** + * virDomainGetDirtyRateInfo: + * @domain: a domain object + * @info: pointer to current domain's memory dirty rate info + * @sec: show dirty rate within specified seconds + * @flags: extra flags; binary-OR of virDomainGetDirtyRateInfoFlags + * + * Get the current domain's memory dirty rate info. + * + * If the VIR_DOMAIN_DIRTYRATE_CALC flag is set, this will calculate + * domain's memory dirty rate within specific time (sec). + * + * If the VIR_DOMAIN_DIRTYRATE_QUERY flag is set, this will query the + * dirty rate info calculated last time and stored in 'info'. + * + * The VIR_DOMAIN_DIRTYRATE_DEFAULT flag is equal to both + * VIR_DOMAIN_DIRTYRATE_CALC and VIR_DOMAIN_DIRTYRATE_QUERY. + * + * Returns 0 in case of success, -1 otherwise. + */ +int +virDomainGetDirtyRateInfo(virDomainPtr domain, + virDomainDirtyRateInfoPtr info, + int sec, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "info=3D%p, sec=3D%d, flags=3D0x%x", + info, sec, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + virCheckNonNullArgGoto(info, error); + memset(info, 0, sizeof(*info)); + + virCheckReadOnlyGoto(conn->flags, error); + + if (conn->driver->domainGetDirtyRateInfo) { + int ret; + ret =3D conn->driver->domainGetDirtyRateInfo(domain, info, sec, fl= ags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index cf31f937d5..155b75713b 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -879,4 +879,9 @@ LIBVIRT_6.10.0 { virDomainAuthorizedSSHKeysSet; } LIBVIRT_6.0.0; =20 +LIBVIRT_7.1.0 { + global: + virDomainGetDirtyRateInfo; +} LIBVIRT_6.10.0; + # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 1b784e61c7..4460d2c7ce 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8531,6 +8531,7 @@ static virHypervisorDriver hypervisor_driver =3D { .domainBackupGetXMLDesc =3D remoteDomainBackupGetXMLDesc, /* 6.0.0 */ .domainAuthorizedSSHKeysGet =3D remoteDomainAuthorizedSSHKeysGet, /* 6= .10.0 */ .domainAuthorizedSSHKeysSet =3D remoteDomainAuthorizedSSHKeysSet, /* 6= .10.0 */ + .domainGetDirtyRateInfo =3D remoteDomainGetDirtyRateInfo, /* 7.1.0 */ }; =20 static virNetworkDriver network_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 2df38cef77..965d05f68f 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3799,6 +3799,19 @@ struct remote_domain_authorized_ssh_keys_set_args { unsigned int flags; }; =20 +struct remote_domain_get_dirty_rate_info_args { + remote_nonnull_domain dom; + int sec; + unsigned int flags; +}; + +struct remote_domain_get_dirty_rate_info_ret { /* insert@1 */ + int status; + hyper dirtyRate; + hyper startTime; + int calcTime; +}; + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -6714,5 +6727,11 @@ enum remote_procedure { * @generate: none * @acl: domain:write */ - REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET =3D 425 + REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET =3D 425, + + /** + * @generate: both + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_GET_DIRTY_RATE_INFO =3D 426 }; --=20 2.23.0