From nobody Tue Apr 16 15:15:02 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602749149; cv=none; d=zohomail.com; s=zohoarc; b=GRrwHCSFmj3GWw4nqYog0zdfBN/y7gPykWQ1pf2YNaMh3xKSo+LZPgv9F5Org10UuKo8VkVWCBnVbSxr+GcCELLuW7Mbg7iOISQJCGS4y54ENFbNQlrh/tfHgmLziH0kb22ay1wHjGMPZT9xa6uw//T8WZ6eBnmfGrXhTc23HBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602749149; 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=rOC7mA6ozmUng2QcGntIFqEJNYKwN7/icFg9ArB1vao=; b=gfYM7og8rLQYyWZ/V7j5UKFwSuWxZYrdCstRv+0Pc0YnTD/fQzsIMaTsnav3NPCd73d5Iu6XUbHNb9PQ0Lo+oXt0h7kUPPIboQIf2UVCVGu3YjtR0rBqE/v/nroxTaHnIYB3CChhchEu+5lYmn6zvW9OZ0VMisn71ksAZm0sm/Q= ARC-Authentication-Results: i=1; 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 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 SMTP id 1602749149343975.038238017106; Thu, 15 Oct 2020 01:05:49 -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-427-9YUaSs__OHyrGneNuCHEaw-1; Thu, 15 Oct 2020 04:00:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2CE53803631; Thu, 15 Oct 2020 08:00: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 0B7CF76674; Thu, 15 Oct 2020 08:00: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 C8BF958112; Thu, 15 Oct 2020 08:00:30 +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 09F7xK9g010116 for ; Thu, 15 Oct 2020 03:59:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 982232166B28; Thu, 15 Oct 2020 07:59:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 932412166B27 for ; Thu, 15 Oct 2020 07:59:20 +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-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6AAD980D623 for ; Thu, 15 Oct 2020 07:59:20 +0000 (UTC) Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-358-8PUG1shCMCCkGT2IVGWPPA-1; Thu, 15 Oct 2020 03:59:17 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4BA0FC32356F0F5754BE; Thu, 15 Oct 2020 15:59:13 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 15 Oct 2020 15:59:03 +0800 X-MC-Unique: 9YUaSs__OHyrGneNuCHEaw-1 X-MC-Unique: 8PUG1shCMCCkGT2IVGWPPA-1 From: Hao Wang To: Subject: [[RESEND] 8/8] migration/dirtyrate: Introduce getdirtyrate virsh api Date: Thu, 15 Oct 2020 15:49:46 +0800 Message-ID: <20201015074946.2740968-9-wanghao232@huawei.com> In-Reply-To: <20201015074946.2740968-1-wanghao232@huawei.com> References: <20201015074946.2740968-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.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 09F7xK9g010116 X-loop: libvir-list@redhat.com Cc: yubihong@huawei.com, alex.chen@huawei.com, zhouyimin@huawei.com, zhang.zhanghailiang@huawei.com, dgilbert@redhat.com, xiexiangyou@huawei.com, david.edmondson@oracle.com, jdenemar@redhat.com, zhengchuan@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.11 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" Signed-off-by: Hao Wang Signed-off-by: Zhou Yimin Reviewed-by: Chuan Zheng --- tools/virsh-domain.c | 112 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 909864c940..4b2ee3f8e3 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -14334,6 +14334,112 @@ cmdGuestInfo(vshControl *ctl, const vshCmd *cmd) return ret; } =20 +/* + * "querydirtyrate" command + */ +static const vshCmdInfo info_getdirtyrate[] =3D { + {.name =3D "help", + .data =3D N_("Get a vm's memory dirty rate") + }, + {.name =3D "desc", + .data =3D N_("Get memory dirty rate of a domain in order to decide" + " whether it's proper to be migrated out or not.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_getdirtyrate[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "seconds", + .type =3D VSH_OT_INT, + .help =3D N_("calculate memory dirty rate within specified seconds," + " a valid range of values is [1, 60], and would default to= 1s.") + }, + {.name =3D "calculate", + .type =3D VSH_OT_BOOL, + .help =3D N_("calculate dirty rate only, can be used together with --= query," + " either or both is expected, otherwise would default to b= oth.") + }, + {.name =3D "query", + .type =3D VSH_OT_BOOL, + .help =3D N_("query dirty rate only, can be used together with --calc= ulate," + " either or both is expected, otherwise would default to b= oth.") + }, + {.name =3D NULL} +}; + +static bool +cmdGetDirtyRateInfo(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + virDomainDirtyRateInfo info; + long long sec =3D 0; + const char *status =3D NULL; + unsigned int flags =3D 0; + int rc; + bool ret =3D false; + bool calc =3D vshCommandOptBool(cmd, "calculate"); + bool query =3D vshCommandOptBool(cmd, "query"); + + if (calc) + flags |=3D VIR_DOMAIN_DIRTYRATE_CALC; + if (query) + flags |=3D VIR_DOMAIN_DIRTYRATE_QUERY; + + /* if flag option is missing, default to both --calculate and --query = */ + if (!calc && !query) + flags |=3D VIR_DOMAIN_DIRTYRATE_CALC | VIR_DOMAIN_DIRTYRATE_QUERY; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + rc =3D vshCommandOptLongLong(ctl, cmd, "seconds", &sec); + if (rc < 0) + goto done; + + /* if --seconds option is missing, default to 1s */ + if (!rc) + sec =3D 1; + + if (virDomainGetDirtyRateInfo(dom, &info, sec, flags) < 0) { + vshError(ctl, "%s", _("Get memory dirty-rate failed.")); + goto done; + } + + if (flags & VIR_DOMAIN_DIRTYRATE_QUERY) { + switch (info.status) { + case VIR_DOMAIN_DIRTYRATE_UNSTARTED: + status =3D _("unstarted"); + break; + case VIR_DOMAIN_DIRTYRATE_MEASURING: + status =3D _("measuring"); + break; + case VIR_DOMAIN_DIRTYRATE_MEASURED: + status =3D _("measured"); + break; + default: + status =3D _("unknown"); + } + + vshPrint(ctl, _("status: %s\n"), status); + vshPrint(ctl, _("startTime: %lld\n"), info.startTime); + vshPrint(ctl, _("calcTime: %lld s\n"), info.calcTime); + + if (info.status =3D=3D VIR_DOMAIN_DIRTYRATE_MEASURED) + vshPrint(ctl, _("dirtyRate: %lld MB/s\n"), info.dirtyRate); + else + vshPrint(ctl, _("dirtyRate: the calculation is %s, please = query results later\n"), + status); + } else { + vshPrint(ctl, _("Memory dirty rate is calculating, use --query opt= ion to display results.\n")); + } + + ret =3D true; + done: + virDomainFree(dom); + return ret; +} + const vshCmdDef domManagementCmds[] =3D { {.name =3D "attach-device", .handler =3D cmdAttachDevice, @@ -14961,5 +15067,11 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_guestinfo, .flags =3D 0 }, + {.name =3D "getdirtyrate", + .handler =3D cmdGetDirtyRateInfo, + .opts =3D opts_getdirtyrate, + .info =3D info_getdirtyrate, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.23.0