From: Hyman Huang(黄勇) <huangy81(a)chinatelecom.cn>
Add cancel option to vcpudirtylimit api to cancel dirty
page rate limit for virtual CPUs.
Signed-off-by: Hyman Huang(黄勇) <huangy81(a)chinatelecom.cn>
---
tools/virsh-domain.c | 64 ++++++++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 20 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index dbdd46e..199913d 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13785,7 +13785,6 @@ static const vshCmdOptDef opts_vcpu_dirty_limit[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
{.name = "rate",
.type = VSH_OT_INT,
- .flags = VSH_OFLAG_REQ,
.help = N_("Upper limit of dirty page rate (MB/s) for "
"virtual CPUs.")
},
@@ -13793,6 +13792,10 @@ static const vshCmdOptDef opts_vcpu_dirty_limit[] = {
.type = VSH_OT_INT,
.help = N_("Index of a virtual CPU.")
},
+ {.name = "cancel",
+ .type = VSH_OT_BOOL,
+ .help = N_("Cancel dirty page rate limit.")
+ },
{.name = NULL}
};
@@ -13803,8 +13806,11 @@ cmdVcpuDirtyLimit(vshControl *ctl, const vshCmd *cmd)
int vcpu_idx = -1;
unsigned long long rate = 0;
bool vcpu = vshCommandOptBool(cmd, "vcpu");
+ bool cancel = vshCommandOptBool(cmd, "cancel");
unsigned int flags = 0;
+ VSH_EXCLUSIVE_OPTIONS("cancel", "rate");
+
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
@@ -13819,28 +13825,46 @@ cmdVcpuDirtyLimit(vshControl *ctl, const vshCmd *cmd)
}
}
- if (vshCommandOptULongLong(ctl, cmd, "rate", &rate) < 0)
- return false;
-
- if (!rate) {
- vshError(ctl, "%s", _("Invalid dirty page rate limit"));
- return false;
- }
+ if (!cancel) {
+ if (vshCommandOptULongLong(ctl, cmd, "rate", &rate) < 0)
+ return false;
- if (vcpu) {
- /* set specified vcpu dirty page rate limit of vm */
- if (virDomainSetVcpuDirtyLimit(dom, vcpu_idx,
- rate, flags | VIR_DOMAIN_DIRTYLIMIT_VCPU) < 0)
+ if (!rate) {
+ vshError(ctl, "%s", _("Invalid dirty page rate limit"));
return false;
- vshPrintExtra(ctl, _("Set vcpu[%d] dirty page rate limit "
- "%lld successfully.\n"), vcpu_idx, rate);
+ }
+
+ if (vcpu) {
+ /* set specified vcpu dirty page rate limit of vm */
+ if (virDomainSetVcpuDirtyLimit(dom, vcpu_idx,
+ rate, flags | VIR_DOMAIN_DIRTYLIMIT_VCPU) < 0)
+ return false;
+ vshPrintExtra(ctl, _("Set vcpu[%d] dirty page rate limit "
+ "%lld successfully.\n"), vcpu_idx, rate);
+ } else {
+ /* set all vcpu dirty page rate limit of vm */
+ if (virDomainSetVcpuDirtyLimit(dom, -1,
+ rate, flags | VIR_DOMAIN_DIRTYLIMIT_ALL) < 0)
+ return false;
+ vshPrintExtra(ctl, _("Set dirty page rate limit %lld on all "
+ "virtual CPUs successfully.\n"), rate);
+ }
} else {
- /* set all vcpu dirty page rate limit of vm */
- if (virDomainSetVcpuDirtyLimit(dom, -1,
- rate, flags | VIR_DOMAIN_DIRTYLIMIT_ALL) < 0)
- return false;
- vshPrintExtra(ctl, _("Set dirty page rate limit %lld on all "
- "virtual CPUs successfully.\n"), rate);
+ if (vcpu) {
+ /* cancel specified vcpu dirty page rate limit of vm */
+ if (virDomainCancelVcpuDirtyLimit(dom, vcpu_idx,
+ flags | VIR_DOMAIN_DIRTYLIMIT_VCPU) < 0)
+ return false;
+ vshPrintExtra(ctl, _("Cancel vcpu[%d] dirty page rate limit "
+ "successfully.\n"), vcpu);
+ } else {
+ /* cancel all vcpu dirty page rate limit of vm */
+ if (virDomainCancelVcpuDirtyLimit(dom, -1,
+ flags | VIR_DOMAIN_DIRTYLIMIT_ALL) < 0)
+ return false;
+ vshPrintExtra(ctl, _("Cancel dirty page rate limit on all "
+ "virtual CPUs successfully.\n"));
+ }
}
return true;
--
1.8.3.1