[PATCH v6 7/8] virsh: Add mode option to domdirtyrate-calc virsh api
Michal Prívozník
mprivozn at redhat.com
Mon Feb 21 12:34:53 UTC 2022
On 2/20/22 14:28, huangy81 at chinatelecom.cn wrote:
> From: Hyman Huang(黄勇) <huangy81 at chinatelecom.cn>
>
> Extend domdirtyrate-calc virsh api with mode option, either
> of these three options "page-sampling,dirty-bitmap,dirty-ring"
> can be specified when calculating dirty page rate.
>
> Signed-off-by: Hyman Huang(黄勇) <huangy81 at chinatelecom.cn>
> ---
> docs/manpages/virsh.rst | 7 +++++--
> src/libvirt-domain.c | 12 +++++++++++-
> tools/virsh-completer-domain.c | 17 +++++++++++++++++
> tools/virsh-completer-domain.h | 4 ++++
> tools/virsh-domain.c | 42 +++++++++++++++++++++++++++++++++++++++++-
> tools/virsh-domain.h | 9 +++++++++
> 6 files changed, 87 insertions(+), 4 deletions(-)
>
> diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
> index 429879d..00d21a1 100644
> --- a/docs/manpages/virsh.rst
> +++ b/docs/manpages/virsh.rst
> @@ -1717,13 +1717,16 @@ domdirtyrate-calc
> ::
>
> domdirtyrate-calc <domain> [--seconds <sec>]
> + --mode=[page-sampling | dirty-bitmap | dirty-ring]
>
> Calculate an active domain's memory dirty rate which may be expected by
> user in order to decide whether it's proper to be migrated out or not.
> The ``seconds`` parameter can be used to calculate dirty rate in a
> specific time which allows 60s at most now and would be default to 1s
> -if missing. The calculated dirty rate information is available by calling
> -'domstats --dirtyrate'.
> +if missing. These three *page-sampling, dirty-bitmap, dirty-ring* modes
> +are mutually exclusive and alternative when specify calculation mode,
> +*page-sampling* is the default mode if missing. The calculated dirty
> +rate information is available by calling 'domstats --dirtyrate'.
>
>
> domdisplay
> diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
> index 8be2c21..7be4e02 100644
> --- a/src/libvirt-domain.c
> +++ b/src/libvirt-domain.c
> @@ -13337,7 +13337,7 @@ virDomainGetMessages(virDomainPtr domain,
> * virDomainStartDirtyRateCalc:
> * @domain: a domain object
> * @seconds: specified calculating time in seconds
> - * @flags: extra flags; not used yet, so callers should always pass 0
> + * @flags: bitwise-OR of supported virDomainDirtyRateCalcFlags
> *
> * Calculate the current domain's memory dirty rate in next @seconds.
> * The calculated dirty rate information is available by calling
> @@ -13361,6 +13361,16 @@ virDomainStartDirtyRateCalc(virDomainPtr domain,
>
> virCheckReadOnlyGoto(conn->flags, error);
>
> + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_DIRTYRATE_MODE_PAGE_SAMPLING,
> + VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_BITMAP,
> + error);
> + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_DIRTYRATE_MODE_PAGE_SAMPLING,
> + VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_RING,
> + error);
> + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_BITMAP,
> + VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_RING,
> + error);
> +
> if (conn->driver->domainStartDirtyRateCalc) {
> int ret;
> ret = conn->driver->domainStartDirtyRateCalc(domain, seconds, flags);
> diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
> index b4e744c..1c2df56 100644
> --- a/tools/virsh-completer-domain.c
> +++ b/tools/virsh-completer-domain.c
> @@ -1150,3 +1150,20 @@ virshDomainNumatuneModeCompleter(vshControl *ctl G_GNUC_UNUSED,
>
> return ret;
> }
> +
> +
> +char **
> +virshDomainDirtyRateCalcModeCompleter(vshControl *ctl,
> + const vshCmd *cmd,
> + unsigned int flags)
> +{
> + const char *modes[] = {"page-sampling", "dirty-bitmap", "dirty-ring", NULL};
> + const char *mode = NULL;
> +
> + virCheckFlags(0, NULL);
> +
> + if (vshCommandOptStringQuiet(ctl, cmd, "mode", &mode) < 0)
> + return NULL;
> +
> + return virshCommaStringListComplete(mode, modes);
No, the --mode argument supports only one value. It doesn't support
--mode page-sampling,dirty-bitmap,dirty-ring.
> +}
> diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
> index 94bb3b5..044c675 100644
> --- a/tools/virsh-completer-domain.h
> +++ b/tools/virsh-completer-domain.h
> @@ -186,3 +186,7 @@ char **
> virshDomainNumatuneModeCompleter(vshControl *ctl,
> const vshCmd *cmd,
> unsigned int flags);
> +char **
> +virshDomainDirtyRateCalcModeCompleter(vshControl *ctl,
> + const vshCmd *cmd,
> + unsigned int flags);
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 433ea67..256258b 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -14486,14 +14486,28 @@ static const vshCmdOptDef opts_domdirtyrate_calc[] = {
> .help = N_("calculate memory dirty rate within specified seconds, "
> "the supported value range from 1 to 60, default to 1.")
> },
> + {.name = "mode",
> + .type = VSH_OT_STRING,
> + .completer = virshDomainDirtyRateCalcModeCompleter,
> + .help = N_("dirty page rate calculation mode, either of these 3 options "
> + "'page-sampling,dirty-bitmap,dirty-ring' can be specified.")
> + },
> {.name = NULL}
> };
>
> +VIR_ENUM_IMPL(virshDomainDirtyRateCalcMode,
> + VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_LAST,
> + "page-sampling",
> + "dirty-bitmap",
> + "dirty-ring");
> +
> static bool
> cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd)
> {
> g_autoptr(virshDomain) dom = NULL;
> int seconds = 1; /* the default value is 1 */
> + const char *modestr = NULL;
> + unsigned int flags = 0;
>
> if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
> return false;
> @@ -14501,7 +14515,33 @@ cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd)
> if (vshCommandOptInt(ctl, cmd, "seconds", &seconds) < 0)
> return false;
>
> - if (virDomainStartDirtyRateCalc(dom, seconds, 0) < 0)
> + if (vshCommandOptStringReq(ctl, cmd, "mode", &modestr) < 0)
> + return false;
> +
> + if (modestr) {
> + int mode = virshDomainDirtyRateCalcModeTypeFromString(modestr);
> +
> + if (mode < 0) {
> + vshError(ctl, _("Unknown calculation mode '%s'"), modestr);
> + return false;
> + }
> +
> + switch ((virshDomainDirtyRateCalcMode) mode) {
> + case VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_PAGE_SAMPLING:
> + flags |= VIR_DOMAIN_DIRTYRATE_MODE_PAGE_SAMPLING;
> + break;
> + case VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_DIRTY_BITMAP:
> + flags |= VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_BITMAP;;
One semicolon is enough :-)
> + break;
> + case VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_DIRTY_RING:
> + flags |= VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_RING;;
> + break;
> + case VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_LAST:
> + break;
> + }
> + }
> +
> + if (virDomainStartDirtyRateCalc(dom, seconds, flags) < 0)
> return false;
>
> vshPrintExtra(ctl, _("Start to calculate domain's memory "
Michal
More information about the libvir-list
mailing list