This patch uses the new helper to avoid the more complex check for domain state modification flags. --- tools/virsh-domain.c | 260 ++++++++++++++++++++++----------------------------- 1 file changed, 111 insertions(+), 149 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 8dad85d..4c00db3 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1068,18 +1068,15 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) bool live = vshCommandOptBool(cmd, "live"); bool ret = false; - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - } + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) goto cleanup; @@ -1256,18 +1253,15 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - } + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -2570,18 +2564,15 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd) virNetDevBandwidthRate inbound, outbound; int i; - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - } + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; @@ -4146,18 +4137,15 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - } + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -5618,21 +5606,18 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) bool query = false; /* Query mode if no cpulist */ unsigned int flags = 0; - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - /* neither option is specified */ - if (!live && !config) - flags = -1; - } + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + /* neither option is specified */ + if (!current && !live && !config) + flags = -1; if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0) return false; @@ -5855,21 +5840,18 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) bool query = false; /* Query mode if no cpulist */ unsigned int flags = 0; - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - /* neither option is specified */ - if (!live && !config) - flags = -1; - } + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + /* neither option is specified */ + if (!current && !live && !config) + flags = -1; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -6058,21 +6040,18 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) bool current = vshCommandOptBool(cmd, "current"); unsigned int flags = 0; - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - /* neither option is specified */ - if (!live && !config && !maximum) - flags = -1; - } + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + /* neither option is specified */ + if (!current && !live && !config && !maximum) + flags = -1; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -6766,18 +6745,13 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } - flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -7189,21 +7163,18 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) bool current = vshCommandOptBool(cmd, "current"); unsigned int flags = 0; - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - /* neither option is specified */ - if (!live && !config) - flags = -1; - } + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + /* neither option is specified */ + if (!current && !live && !config) + flags = -1; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -7295,20 +7266,18 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) bool current = vshCommandOptBool(cmd, "current"); unsigned int flags = VIR_DOMAIN_MEM_MAXIMUM; - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - /* neither option is specified */ - if (!live && !config) - flags = -1; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) + flags = VIR_DOMAIN_AFFECT_CURRENT; + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + /* neither option is specified */ + if (!current && !live && !config) + flags = -1; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -7619,18 +7588,15 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd) bool live = vshCommandOptBool(cmd, "live"); const char *mode = NULL; - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (current) flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - } + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -10318,19 +10284,15 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) action = "update"; } - if (current) { - if (live || config) { - vshError(ctl, "%s", _("--current must be specified exclusively")); - return false; - } - flags = VIR_DOMAIN_AFFECT_CURRENT; - } else { - if (config) - flags |= VIR_DOMAIN_AFFECT_CONFIG; - if (live) - flags |= VIR_DOMAIN_AFFECT_LIVE; - } + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + if (current) + flags = VIR_DOMAIN_AFFECT_CURRENT; + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; if (force) flags |= VIR_DOMAIN_DEVICE_MODIFY_FORCE; -- 1.8.1.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list