[libvirt] [PATCH 0/2] virsh: Further improve handling of integer options

As suggested by Michal: now that we have a generic error message for failures related to the parsing of integer options, it makes sense to perform the corresponding check in a single spot instead of replicating it every time vshCommandOpt*() is used. Andrea Bolognani (2): virsh: Pass vshControl to all vshCommandOpt*() calls. virsh: Move error messages inside vshCommandOpt*() functions. tests/vcpupin | 4 +- tools/virsh-domain-monitor.c | 97 +++--- tools/virsh-domain.c | 696 +++++++++++++++++++------------------------ tools/virsh-host.c | 87 ++---- tools/virsh-interface.c | 18 +- tools/virsh-network.c | 38 ++- tools/virsh-nodedev.c | 6 +- tools/virsh-pool.c | 26 +- tools/virsh-secret.c | 8 +- tools/virsh-snapshot.c | 88 +++--- tools/virsh-volume.c | 50 ++-- tools/virsh.c | 195 ++++++------ tools/virsh.h | 77 ++--- 13 files changed, 624 insertions(+), 766 deletions(-) -- 2.1.0

This will allow us to use vshError() to report errors from inside vshCommandOpt*(), instead of replicating the same logic and error messages all over the place. We also have more context inside the vshCommandOpt*() functions, for example the actual value used on the command line, which means we can produce more detailed error messages. --- tools/virsh-domain-monitor.c | 90 +++---- tools/virsh-domain.c | 598 +++++++++++++++++++++---------------------- tools/virsh-host.c | 46 ++-- tools/virsh-interface.c | 14 +- tools/virsh-network.c | 34 +-- tools/virsh-nodedev.c | 6 +- tools/virsh-pool.c | 26 +- tools/virsh-secret.c | 8 +- tools/virsh-snapshot.c | 88 +++---- tools/virsh-volume.c | 34 +-- tools/virsh.c | 113 ++++---- tools/virsh.h | 77 +++--- 12 files changed, 571 insertions(+), 563 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index a42c150..db7ef8b 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -317,9 +317,9 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) bool ret = false; int rv = 0; int period = -1; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -340,7 +340,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) /* Providing a period will adjust the balloon driver collection period. * This is not really an unsigned long, but it */ - if ((rv = vshCommandOptInt(cmd, "period", &period)) < 0) { + if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "period"); @@ -491,10 +491,10 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) size_t i; bool details = false; - if (vshCommandOptBool(cmd, "inactive")) + if (vshCommandOptBool(ctl, cmd, "inactive")) flags |= VIR_DOMAIN_XML_INACTIVE; - details = vshCommandOptBool(cmd, "details"); + details = vshCommandOptBool(ctl, cmd, "details"); if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -609,7 +609,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) xmlNodePtr *interfaces = NULL; size_t i; - if (vshCommandOptBool(cmd, "inactive")) + if (vshCommandOptBool(ctl, cmd, "inactive")) flags |= VIR_DOMAIN_XML_INACTIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -733,7 +733,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptBool(cmd, "config")) + if (vshCommandOptBool(ctl, cmd, "config")) flags = VIR_DOMAIN_XML_INACTIVE; if (!(desc = virDomainGetXMLDesc(dom, flags))) { @@ -929,7 +929,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) int rc, nparams = 0; size_t i; bool ret = false; - bool human = vshCommandOptBool(cmd, "human"); /* human readable output */ + bool human = vshCommandOptBool(ctl, cmd, "human"); /* human readable output */ if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; @@ -1352,7 +1352,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; bool ret = true; - bool showReason = vshCommandOptBool(cmd, "reason"); + bool showReason = vshCommandOptBool(ctl, cmd, "reason"); int state, reason; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -1420,9 +1420,9 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; bool ret = false; - bool now = vshCommandOptBool(cmd, "now"); - bool pretty = vshCommandOptBool(cmd, "pretty"); - bool rtcSync = vshCommandOptBool(cmd, "sync"); + bool now = vshCommandOptBool(ctl, cmd, "now"); + bool pretty = vshCommandOptBool(ctl, cmd, "pretty"); + bool rtcSync = vshCommandOptBool(ctl, cmd, "sync"); long long seconds = 0; unsigned int nseconds = 0; unsigned int flags = 0; @@ -1436,7 +1436,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - rv = vshCommandOptLongLong(cmd, "time", &seconds); + rv = vshCommandOptLongLong(ctl, cmd, "time", &seconds); if (rv < 0) { /* invalid integer format */ @@ -1856,17 +1856,17 @@ static const vshCmdOptDef opts_list[] = { {.name = NULL} }; -#define FILTER(NAME, FLAG) \ - if (vshCommandOptBool(cmd, NAME)) \ +#define FILTER(NAME, FLAG) \ + if (vshCommandOptBool(ctl, cmd, NAME)) \ flags |= (FLAG) static bool cmdList(vshControl *ctl, const vshCmd *cmd) { - bool managed = vshCommandOptBool(cmd, "managed-save"); - bool optTitle = vshCommandOptBool(cmd, "title"); - bool optTable = vshCommandOptBool(cmd, "table"); - bool optUUID = vshCommandOptBool(cmd, "uuid"); - bool optName = vshCommandOptBool(cmd, "name"); + bool managed = vshCommandOptBool(ctl, cmd, "managed-save"); + bool optTitle = vshCommandOptBool(ctl, cmd, "title"); + bool optTable = vshCommandOptBool(ctl, cmd, "table"); + bool optUUID = vshCommandOptBool(ctl, cmd, "uuid"); + bool optName = vshCommandOptBool(ctl, cmd, "name"); size_t i; char *title; char uuid[VIR_UUID_STRING_BUFLEN]; @@ -1879,10 +1879,10 @@ cmdList(vshControl *ctl, const vshCmd *cmd) unsigned int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; /* construct filter flags */ - if (vshCommandOptBool(cmd, "inactive")) + if (vshCommandOptBool(ctl, cmd, "inactive")) flags = VIR_CONNECT_LIST_DOMAINS_INACTIVE; - if (vshCommandOptBool(cmd, "all")) + if (vshCommandOptBool(ctl, cmd, "all")) flags = VIR_CONNECT_LIST_DOMAINS_INACTIVE | VIR_CONNECT_LIST_DOMAINS_ACTIVE; @@ -2107,65 +2107,65 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd) size_t ndoms = 0; virDomainStatsRecordPtr *records = NULL; virDomainStatsRecordPtr *next; - bool raw = vshCommandOptBool(cmd, "raw"); + bool raw = vshCommandOptBool(ctl, cmd, "raw"); int flags = 0; const vshCmdOpt *opt = NULL; bool ret = false; - if (vshCommandOptBool(cmd, "state")) + if (vshCommandOptBool(ctl, cmd, "state")) stats |= VIR_DOMAIN_STATS_STATE; - if (vshCommandOptBool(cmd, "cpu-total")) + if (vshCommandOptBool(ctl, cmd, "cpu-total")) stats |= VIR_DOMAIN_STATS_CPU_TOTAL; - if (vshCommandOptBool(cmd, "balloon")) + if (vshCommandOptBool(ctl, cmd, "balloon")) stats |= VIR_DOMAIN_STATS_BALLOON; - if (vshCommandOptBool(cmd, "vcpu")) + if (vshCommandOptBool(ctl, cmd, "vcpu")) stats |= VIR_DOMAIN_STATS_VCPU; - if (vshCommandOptBool(cmd, "interface")) + if (vshCommandOptBool(ctl, cmd, "interface")) stats |= VIR_DOMAIN_STATS_INTERFACE; - if (vshCommandOptBool(cmd, "block")) + if (vshCommandOptBool(ctl, cmd, "block")) stats |= VIR_DOMAIN_STATS_BLOCK; - if (vshCommandOptBool(cmd, "list-active")) + if (vshCommandOptBool(ctl, cmd, "list-active")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE; - if (vshCommandOptBool(cmd, "list-inactive")) + if (vshCommandOptBool(ctl, cmd, "list-inactive")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE; - if (vshCommandOptBool(cmd, "list-persistent")) + if (vshCommandOptBool(ctl, cmd, "list-persistent")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT; - if (vshCommandOptBool(cmd, "list-transient")) + if (vshCommandOptBool(ctl, cmd, "list-transient")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT; - if (vshCommandOptBool(cmd, "list-running")) + if (vshCommandOptBool(ctl, cmd, "list-running")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING; - if (vshCommandOptBool(cmd, "list-paused")) + if (vshCommandOptBool(ctl, cmd, "list-paused")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED; - if (vshCommandOptBool(cmd, "list-shutoff")) + if (vshCommandOptBool(ctl, cmd, "list-shutoff")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF; - if (vshCommandOptBool(cmd, "list-other")) + if (vshCommandOptBool(ctl, cmd, "list-other")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER; - if (vshCommandOptBool(cmd, "enforce")) + if (vshCommandOptBool(ctl, cmd, "enforce")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS; - if (vshCommandOptBool(cmd, "backing")) + if (vshCommandOptBool(ctl, cmd, "backing")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING; - if (vshCommandOptBool(cmd, "domain")) { + if (vshCommandOptBool(ctl, cmd, "domain")) { if (VIR_ALLOC_N(domlist, 1) < 0) goto cleanup; ndoms = 1; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (!(dom = vshLookupDomainBy(ctl, opt->data, VSH_BYID | VSH_BYUUID | VSH_BYNAME))) goto cleanup; @@ -2237,16 +2237,16 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) size_t i, j; int ifaces_count = 0; bool ret = false; - bool full = vshCommandOptBool(cmd, "full"); + bool full = vshCommandOptBool(ctl, cmd, "full"); const char *sourcestr = NULL; int source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptString(cmd, "interface", &ifacestr) < 0) + if (vshCommandOptString(ctl, cmd, "interface", &ifacestr) < 0) goto cleanup; - if (vshCommandOptString(cmd, "source", &sourcestr) < 0) + if (vshCommandOptString(ctl, cmd, "source", &sourcestr) < 0) goto cleanup; if (sourcestr) { diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 36f3e6c..bb8e20a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -239,10 +239,10 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) int rv; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -597,10 +597,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) virBuffer buf = VIR_BUFFER_INITIALIZER; char *xml = NULL; struct stat st; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -657,7 +657,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) isFile ? "file" : "block"); if (type) virBufferAsprintf(&buf, " device='%s'", type); - if (vshCommandOptBool(cmd, "rawio")) + if (vshCommandOptBool(ctl, cmd, "rawio")) virBufferAddLit(&buf, " rawio='yes'"); virBufferAddLit(&buf, ">\n"); virBufferAdjustIndent(&buf, 2); @@ -707,7 +707,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) " bus ='0x%02x' slot='0x%02x' function='0x%0x'", diskAddr.addr.pci.domain, diskAddr.addr.pci.bus, diskAddr.addr.pci.slot, diskAddr.addr.pci.function); - if (vshCommandOptBool(cmd, "multifunction")) + if (vshCommandOptBool(ctl, cmd, "multifunction")) virBufferAddLit(&buf, " multifunction='on'"); virBufferAddLit(&buf, "/>\n"); } else if (diskAddr.type == DISK_ADDR_TYPE_CCW) { @@ -756,7 +756,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) xml = virBufferContentAndReset(&buf); - if (vshCommandOptBool(cmd, "print-xml")) { + if (vshCommandOptBool(ctl, cmd, "print-xml")) { vshPrint(ctl, "%s", xml); functionReturn = true; goto cleanup; @@ -910,10 +910,10 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) virBuffer buf = VIR_BUFFER_INITIALIZER; char *xml; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -1098,7 +1098,7 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - autostart = !vshCommandOptBool(cmd, "disable"); + autostart = !vshCommandOptBool(ctl, cmd, "disable"); if (virDomainSetAutostart(dom, autostart) < 0) { if (autostart) @@ -1273,9 +1273,9 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; size_t i; int rv = 0; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); bool ret = false; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -1292,7 +1292,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "device", &disk) < 0) goto cleanup; - if ((rv = vshCommandOptULongLong(cmd, "total-bytes-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "total-bytes-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1301,7 +1301,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "read-bytes-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "read-bytes-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1310,7 +1310,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "write-bytes-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "write-bytes-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1319,7 +1319,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "total-bytes-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "total-bytes-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1328,7 +1328,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "read-bytes-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "read-bytes-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1337,7 +1337,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "write-bytes-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "write-bytes-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1346,7 +1346,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "total-iops-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "total-iops-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1355,7 +1355,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "read-iops-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "read-iops-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1364,7 +1364,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "write-iops-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "write-iops-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1373,7 +1373,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "write-iops-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "write-iops-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1382,7 +1382,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "read-iops-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "read-iops-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1391,7 +1391,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "total-iops-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "total-iops-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1400,7 +1400,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "size-iops-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "size-iops-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1536,9 +1536,9 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) virTypedParameterPtr params = NULL; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -1551,7 +1551,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if ((rv = vshCommandOptInt(cmd, "weight", &weight)) < 0) { + if ((rv = vshCommandOptInt(ctl, cmd, "weight", &weight)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "weight"); @@ -1566,7 +1566,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-weights", &device_weight); + rv = vshCommandOptString(ctl, cmd, "device-weights", &device_weight); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1577,7 +1577,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-read-iops-sec", &device_riops); + rv = vshCommandOptString(ctl, cmd, "device-read-iops-sec", &device_riops); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1588,7 +1588,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-write-iops-sec", &device_wiops); + rv = vshCommandOptString(ctl, cmd, "device-write-iops-sec", &device_wiops); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1599,7 +1599,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-read-bytes-sec", &device_rbps); + rv = vshCommandOptString(ctl, cmd, "device-read-bytes-sec", &device_rbps); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1610,7 +1610,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-write-bytes-sec", &device_wbps); + rv = vshCommandOptString(ctl, cmd, "device-write-bytes-sec", &device_wbps); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1692,7 +1692,7 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) goto cleanup; - if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) { + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "bandwidth"); @@ -1701,9 +1701,9 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, switch (mode) { case VSH_CMD_BLOCK_JOB_ABORT: - if (vshCommandOptBool(cmd, "async")) + if (vshCommandOptBool(ctl, cmd, "async")) flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; - if (vshCommandOptBool(cmd, "pivot")) + if (vshCommandOptBool(ctl, cmd, "pivot")) flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT; if (virDomainBlockJobAbort(dom, path, flags) < 0) goto cleanup; @@ -1715,7 +1715,7 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, case VSH_CMD_BLOCK_JOB_PULL: if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "keep-relative")) + if (vshCommandOptBool(ctl, cmd, "keep-relative")) flags |= VIR_DOMAIN_BLOCK_REBASE_RELATIVE; if (base || flags) { @@ -1731,15 +1731,15 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0 || vshCommandOptStringReq(ctl, cmd, "top", &top) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "shallow")) + if (vshCommandOptBool(ctl, cmd, "shallow")) flags |= VIR_DOMAIN_BLOCK_COMMIT_SHALLOW; - if (vshCommandOptBool(cmd, "delete")) + if (vshCommandOptBool(ctl, cmd, "delete")) flags |= VIR_DOMAIN_BLOCK_COMMIT_DELETE; - if (vshCommandOptBool(cmd, "active") || - vshCommandOptBool(cmd, "pivot") || - vshCommandOptBool(cmd, "keep-overlay")) + if (vshCommandOptBool(ctl, cmd, "active") || + vshCommandOptBool(ctl, cmd, "pivot") || + vshCommandOptBool(ctl, cmd, "keep-overlay")) flags |= VIR_DOMAIN_BLOCK_COMMIT_ACTIVE; - if (vshCommandOptBool(cmd, "keep-relative")) + if (vshCommandOptBool(ctl, cmd, "keep-relative")) flags |= VIR_DOMAIN_BLOCK_COMMIT_RELATIVE; if (virDomainBlockCommit(dom, path, base, top, bandwidth, flags) < 0) goto cleanup; @@ -1889,11 +1889,11 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom = NULL; bool ret = false; - bool verbose = vshCommandOptBool(cmd, "verbose"); - bool pivot = vshCommandOptBool(cmd, "pivot"); - bool finish = vshCommandOptBool(cmd, "keep-overlay"); - bool active = vshCommandOptBool(cmd, "active") || pivot || finish; - bool blocking = vshCommandOptBool(cmd, "wait"); + bool verbose = vshCommandOptBool(ctl, cmd, "verbose"); + bool pivot = vshCommandOptBool(ctl, cmd, "pivot"); + bool finish = vshCommandOptBool(ctl, cmd, "keep-overlay"); + bool active = vshCommandOptBool(ctl, cmd, "active") || pivot || finish; + bool blocking = vshCommandOptBool(ctl, cmd, "wait"); int timeout = 0; struct sigaction sig_action; struct sigaction old_sig_action; @@ -1906,7 +1906,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) int status = -1; int cb_id = -1; - blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish; + blocking |= vshCommandOptBool(ctl, cmd, "timeout") || pivot || finish; if (blocking) { if (pivot && finish) { vshError(ctl, "%s", _("cannot mix --pivot and --keep-overlay")); @@ -1916,7 +1916,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) return false; - if (vshCommandOptBool(cmd, "async")) + if (vshCommandOptBool(ctl, cmd, "async")) abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; sigemptyset(&sigmask); @@ -1929,7 +1929,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) sigaction(SIGINT, &sig_action, &old_sig_action); GETTIMEOFDAY(&start); - } else if (verbose || vshCommandOptBool(cmd, "async")) { + } else if (verbose || vshCommandOptBool(ctl, cmd, "async")) { vshError(ctl, "%s", _("missing --wait option")); return false; } @@ -2138,11 +2138,11 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) unsigned long long buf_size = 0; unsigned int flags = 0; bool ret = false; - bool blocking = vshCommandOptBool(cmd, "wait"); - bool verbose = vshCommandOptBool(cmd, "verbose"); - bool pivot = vshCommandOptBool(cmd, "pivot"); - bool finish = vshCommandOptBool(cmd, "finish"); - bool blockdev = vshCommandOptBool(cmd, "blockdev"); + bool blocking = vshCommandOptBool(ctl, cmd, "wait"); + bool verbose = vshCommandOptBool(ctl, cmd, "verbose"); + bool pivot = vshCommandOptBool(ctl, cmd, "pivot"); + bool finish = vshCommandOptBool(ctl, cmd, "finish"); + bool blockdev = vshCommandOptBool(ctl, cmd, "blockdev"); int timeout = 0; struct sigaction sig_action; struct sigaction old_sig_action; @@ -2161,18 +2161,18 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) return false; - if (vshCommandOptString(cmd, "dest", &dest) < 0) + if (vshCommandOptString(ctl, cmd, "dest", &dest) < 0) return false; - if (vshCommandOptString(cmd, "xml", &xml) < 0) + if (vshCommandOptString(ctl, cmd, "xml", &xml) < 0) return false; - if (vshCommandOptString(cmd, "format", &format) < 0) + if (vshCommandOptString(ctl, cmd, "format", &format) < 0) return false; VSH_EXCLUSIVE_OPTIONS_VAR(dest, xml); VSH_EXCLUSIVE_OPTIONS_VAR(format, xml); VSH_EXCLUSIVE_OPTIONS_VAR(blockdev, xml); - blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish; + blocking |= vshCommandOptBool(ctl, cmd, "timeout") || pivot || finish; if (blocking) { if (pivot && finish) { vshError(ctl, "%s", _("cannot mix --pivot and --finish")); @@ -2180,7 +2180,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) } if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; - if (vshCommandOptBool(cmd, "async")) + if (vshCommandOptBool(ctl, cmd, "async")) abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; sigemptyset(&sigmask); @@ -2193,7 +2193,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) sigaction(SIGINT, &sig_action, &old_sig_action); GETTIMEOFDAY(&start); - } else if (verbose || vshCommandOptBool(cmd, "async")) { + } else if (verbose || vshCommandOptBool(ctl, cmd, "async")) { vshError(ctl, "%s", _("missing --wait option")); return false; } @@ -2216,19 +2216,19 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) * MiB/s, and either reject negative input or treat it as 0 rather * than trying to guess which value will work well across both * APIs with their different sizes and scales. */ - if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) { + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "bandwidth"); goto cleanup; } - if (vshCommandOptUInt(cmd, "granularity", &granularity) < 0) { + if (vshCommandOptUInt(ctl, cmd, "granularity", &granularity) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "granularity"); goto cleanup; } - if (vshCommandOptULongLong(cmd, "buf-size", &buf_size) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "buf-size", &buf_size) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "buf-size"); @@ -2247,9 +2247,9 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) /* Exploit that some VIR_DOMAIN_BLOCK_REBASE_* and * VIR_DOMAIN_BLOCK_COPY_* flags have the same values. */ - if (vshCommandOptBool(cmd, "shallow")) + if (vshCommandOptBool(ctl, cmd, "shallow")) flags |= VIR_DOMAIN_BLOCK_REBASE_SHALLOW; - if (vshCommandOptBool(cmd, "reuse-external")) + if (vshCommandOptBool(ctl, cmd, "reuse-external")) flags |= VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT; if (granularity || buf_size || (format && STRNEQ(format, "raw")) || xml) { @@ -2304,7 +2304,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) } else { /* Old API */ flags |= VIR_DOMAIN_BLOCK_REBASE_COPY; - if (vshCommandOptBool(cmd, "blockdev")) + if (vshCommandOptBool(ctl, cmd, "blockdev")) flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_DEV; if (STREQ_NULLABLE(format, "raw")) flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_RAW; @@ -2473,13 +2473,13 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd) virDomainBlockJobInfo info; bool ret = false; int rc = -1; - bool raw = vshCommandOptBool(cmd, "raw"); - bool bytes = vshCommandOptBool(cmd, "bytes"); - bool abortMode = (vshCommandOptBool(cmd, "abort") || - vshCommandOptBool(cmd, "async") || - vshCommandOptBool(cmd, "pivot")); - bool infoMode = vshCommandOptBool(cmd, "info") || raw; - bool bandwidth = vshCommandOptBool(cmd, "bandwidth"); + bool raw = vshCommandOptBool(ctl, cmd, "raw"); + bool bytes = vshCommandOptBool(ctl, cmd, "bytes"); + bool abortMode = (vshCommandOptBool(ctl, cmd, "abort") || + vshCommandOptBool(ctl, cmd, "async") || + vshCommandOptBool(ctl, cmd, "pivot")); + bool infoMode = vshCommandOptBool(ctl, cmd, "info") || raw; + bool bandwidth = vshCommandOptBool(ctl, cmd, "bandwidth"); virDomainPtr dom = NULL; const char *path; unsigned int flags = 0; @@ -2639,8 +2639,8 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom = NULL; bool ret = false; - bool blocking = vshCommandOptBool(cmd, "wait"); - bool verbose = vshCommandOptBool(cmd, "verbose"); + bool blocking = vshCommandOptBool(ctl, cmd, "wait"); + bool verbose = vshCommandOptBool(ctl, cmd, "verbose"); int timeout = 0; struct sigaction sig_action; struct sigaction old_sig_action; @@ -2658,7 +2658,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) return false; - if (vshCommandOptBool(cmd, "async")) + if (vshCommandOptBool(ctl, cmd, "async")) abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; sigemptyset(&sigmask); @@ -2671,8 +2671,8 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) sigaction(SIGINT, &sig_action, &old_sig_action); GETTIMEOFDAY(&start); - } else if (verbose || vshCommandOptBool(cmd, "timeout") || - vshCommandOptBool(cmd, "async")) { + } else if (verbose || vshCommandOptBool(ctl, cmd, "timeout") || + vshCommandOptBool(ctl, cmd, "async")) { vshError(ctl, "%s", _("missing --wait option")); return false; } @@ -2800,7 +2800,7 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0) return false; - if (vshCommandOptScaledInt(cmd, "size", &size, 1024, ULLONG_MAX) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "size"); @@ -2901,8 +2901,8 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; bool ret = false; - bool force = vshCommandOptBool(cmd, "force"); - bool safe = vshCommandOptBool(cmd, "safe"); + bool force = vshCommandOptBool(ctl, cmd, "force"); + bool safe = vshCommandOptBool(ctl, cmd, "safe"); unsigned int flags = 0; const char *name = NULL; @@ -2993,7 +2993,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "state", &state) < 0) goto cleanup; - config = vshCommandOptBool(cmd, "config"); + config = vshCommandOptBool(ctl, cmd, "config"); if (STRNEQ(state, "up") && STRNEQ(state, "down")) { vshError(ctl, _("invalid link state '%s'"), state); @@ -3170,9 +3170,9 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd) int maxparams = 0; virTypedParameterPtr params = NULL; bool ret = false; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); virNetDevBandwidthRate inbound, outbound; size_t i; @@ -3406,7 +3406,7 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - if (vshCommandOptULongLong(cmd, "duration", &duration) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "duration"); @@ -3556,11 +3556,11 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) /* Flags to attempt. */ unsigned int flags = 0; /* User-requested actions. */ - bool managed_save = vshCommandOptBool(cmd, "managed-save"); - bool snapshots_metadata = vshCommandOptBool(cmd, "snapshots-metadata"); - bool wipe_storage = vshCommandOptBool(cmd, "wipe-storage"); - bool remove_all_storage = vshCommandOptBool(cmd, "remove-all-storage"); - bool nvram = vshCommandOptBool(cmd, "nvram"); + bool managed_save = vshCommandOptBool(ctl, cmd, "managed-save"); + bool snapshots_metadata = vshCommandOptBool(ctl, cmd, "snapshots-metadata"); + bool wipe_storage = vshCommandOptBool(ctl, cmd, "wipe-storage"); + bool remove_all_storage = vshCommandOptBool(ctl, cmd, "remove-all-storage"); + bool nvram = vshCommandOptBool(ctl, cmd, "nvram"); /* Positive if these items exist. */ int has_managed_save = 0; int has_snapshots_metadata = 0; @@ -3587,7 +3587,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) size_t i; size_t j; - ignore_value(vshCommandOptString(cmd, "storage", &vol_string)); + ignore_value(vshCommandOptString(ctl, cmd, "storage", &vol_string)); if (!(vol_string || remove_all_storage) && wipe_storage) { vshError(ctl, @@ -3966,7 +3966,7 @@ cmdStartGetFDs(vshControl *ctl, *nfdsret = 0; *fdsret = NULL; - if (vshCommandOptString(cmd, "pass-fds", &fdopt) <= 0) + if (vshCommandOptString(ctl, cmd, "pass-fds", &fdopt) <= 0) return 0; if (!(fdlist = virStringSplit(fdopt, ",", -1))) { @@ -4005,7 +4005,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; bool ret = false; #ifndef WIN32 - bool console = vshCommandOptBool(cmd, "console"); + bool console = vshCommandOptBool(ctl, cmd, "console"); #endif unsigned int flags = VIR_DOMAIN_NONE; int rc; @@ -4024,13 +4024,13 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_START_PAUSED; - if (vshCommandOptBool(cmd, "autodestroy")) + if (vshCommandOptBool(ctl, cmd, "autodestroy")) flags |= VIR_DOMAIN_START_AUTODESTROY; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DOMAIN_START_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "force-boot")) + if (vshCommandOptBool(ctl, cmd, "force-boot")) flags |= VIR_DOMAIN_START_FORCE_BOOT; /* We can emulate force boot, even for older servers that reject it. */ @@ -4152,11 +4152,11 @@ doSave(void *opaque) if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) goto out; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SAVE_PAUSED; if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0) @@ -4324,7 +4324,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "verbose")) + if (vshCommandOptBool(ctl, cmd, "verbose")) verbose = true; if (pipe(p) < 0) @@ -4386,7 +4386,7 @@ cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; char *xml = NULL; - if (vshCommandOptBool(cmd, "security-info")) + if (vshCommandOptBool(ctl, cmd, "security-info")) flags |= VIR_DOMAIN_XML_SECURE; if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0) @@ -4448,9 +4448,9 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) char *xml = NULL; unsigned int flags = 0; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SAVE_PAUSED; if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0) @@ -4513,9 +4513,9 @@ cmdSaveImageEdit(vshControl *ctl, const vshCmd *cmd) unsigned int getxml_flags = VIR_DOMAIN_XML_SECURE; unsigned int define_flags = 0; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) define_flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) define_flags |= VIR_DOMAIN_SAVE_PAUSED; /* Normally, we let the API reject mutually exclusive flags. @@ -4608,11 +4608,11 @@ doManagedsave(void *opaque) if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0) goto out_sig; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SAVE_PAUSED; if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) @@ -4646,7 +4646,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - if (vshCommandOptBool(cmd, "verbose")) + if (vshCommandOptBool(ctl, cmd, "verbose")) verbose = true; if (pipe(p) < 0) @@ -4834,7 +4834,7 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd, int ret = -1; int rv; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { set_field = vshStrdup(ctl, opt->data); if (!(set_val = strchr(set_field, '='))) { vshError(ctl, "%s", _("Invalid syntax for --set, " @@ -4892,9 +4892,9 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) int ret; bool ret_val = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -5034,11 +5034,11 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SAVE_PAUSED; if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0) @@ -5144,24 +5144,24 @@ doDump(void *opaque) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) goto out; - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) flags |= VIR_DUMP_LIVE; - if (vshCommandOptBool(cmd, "crash")) + if (vshCommandOptBool(ctl, cmd, "crash")) flags |= VIR_DUMP_CRASH; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DUMP_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "reset")) + if (vshCommandOptBool(ctl, cmd, "reset")) flags |= VIR_DUMP_RESET; - if (vshCommandOptBool(cmd, "memory-only")) + if (vshCommandOptBool(ctl, cmd, "memory-only")) flags |= VIR_DUMP_MEMORY_ONLY; - if (vshCommandOptBool(cmd, "format")) { + if (vshCommandOptBool(ctl, cmd, "format")) { if (!(flags & VIR_DUMP_MEMORY_ONLY)) { vshError(ctl, "%s", _("--format only works with --memory-only")); goto out; } - if (vshCommandOptString(cmd, "format", &format)) { + if (vshCommandOptString(ctl, cmd, "format", &format)) { if (STREQ(format, "kdump-zlib")) { dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB; } else if (STREQ(format, "kdump-lzo")) { @@ -5218,7 +5218,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "verbose")) + if (vshCommandOptBool(ctl, cmd, "verbose")) verbose = true; if (pipe(p) < 0) @@ -5330,7 +5330,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", (const char **) &file) < 0) return false; - if (vshCommandOptUInt(cmd, "screen", &screen) < 0) { + if (vshCommandOptUInt(ctl, cmd, "screen", &screen) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "screen"); @@ -5715,7 +5715,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptBool(cmd, "completed")) + if (vshCommandOptBool(ctl, cmd, "completed")) flags |= VIR_DOMAIN_JOB_STATS_COMPLETED; memset(&info, 0, sizeof(info)); @@ -6119,12 +6119,12 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; bool ret = false; - bool maximum = vshCommandOptBool(cmd, "maximum"); - bool active = vshCommandOptBool(cmd, "active"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); - bool guest = vshCommandOptBool(cmd, "guest"); + bool maximum = vshCommandOptBool(ctl, cmd, "maximum"); + bool active = vshCommandOptBool(ctl, cmd, "active"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool guest = vshCommandOptBool(ctl, cmd, "guest"); bool all = maximum + active + current + config + live + guest == 0; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -6226,7 +6226,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd) int ncpus, maxcpu; size_t cpumaplen; bool ret = false; - bool pretty = vshCommandOptBool(cmd, "pretty"); + bool pretty = vshCommandOptBool(ctl, cmd, "pretty"); int n, m; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -6406,9 +6406,9 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) int cpumaplen; int maxcpu, ncpus; size_t i; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); int got_vcpu; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -6429,7 +6429,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) if (!cpulist) VSH_EXCLUSIVE_OPTIONS_VAR(live, config); - if ((got_vcpu = vshCommandOptUInt(cmd, "vcpu", &vcpu)) < 0) { + if ((got_vcpu = vshCommandOptUInt(ctl, cmd, "vcpu", &vcpu)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "vcpu"); @@ -6552,9 +6552,9 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) unsigned char *cpumap = NULL; int cpumaplen; int maxcpu; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); bool query = false; /* Query mode if no cpulist */ unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -6673,11 +6673,11 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; int count = 0; bool ret = false; - bool maximum = vshCommandOptBool(cmd, "maximum"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); - bool guest = vshCommandOptBool(cmd, "guest"); + bool maximum = vshCommandOptBool(ctl, cmd, "maximum"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool guest = vshCommandOptBool(ctl, cmd, "guest"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -6698,7 +6698,7 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(cmd, "count", &count) < 0 || count <= 0) { + if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <= 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "count"); @@ -6758,9 +6758,9 @@ static bool cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); int niothreads = 0; virDomainIOThreadInfoPtr *info; size_t i; @@ -6857,9 +6857,9 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; const char *cpulist = NULL; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int iothread_id = 0; int maxcpu; bool ret = false; @@ -6878,14 +6878,14 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptUInt(cmd, "iothread", &iothread_id) < 0) { + if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "iothread"); goto cleanup; } - if (vshCommandOptString(cmd, "cpulist", &cpulist) < 0) { + if (vshCommandOptString(ctl, cmd, "cpulist", &cpulist) < 0) { vshError(ctl, "%s", _("iothreadpin: invalid cpulist.")); goto cleanup; } @@ -6953,9 +6953,9 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; int iothread_id = 0; bool ret = false; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -6969,7 +6969,7 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(cmd, "id", &iothread_id) < 0) { + if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "id"); @@ -7035,9 +7035,9 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; int iothread_id = 0; bool ret = false; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -7051,7 +7051,7 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(cmd, "id", &iothread_id) < 0) { + if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "id"); @@ -7111,7 +7111,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) xmlXPathContextPtr ctxt = NULL; xmlNodePtr node; - if (vshCommandOptBool(cmd, "error")) + if (vshCommandOptBool(ctl, cmd, "error")) flags |= VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -7220,9 +7220,9 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; - if (vshCommandOptBool(cmd, "features")) + if (vshCommandOptBool(ctl, cmd, "features")) flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES; - if (vshCommandOptBool(cmd, "migratable")) + if (vshCommandOptBool(ctl, cmd, "migratable")) flags |= VIR_CONNECT_BASELINE_CPU_MIGRATABLE; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -7338,9 +7338,9 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - show_total = vshCommandOptBool(cmd, "total"); + show_total = vshCommandOptBool(ctl, cmd, "total"); - if ((rv = vshCommandOptInt(cmd, "start", &cpu)) < 0) { + if ((rv = vshCommandOptInt(ctl, cmd, "start", &cpu)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "start"); @@ -7353,7 +7353,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) show_per_cpu = true; } - if ((rv = vshCommandOptInt(cmd, "count", &show_count)) < 0) { + if ((rv = vshCommandOptInt(ctl, cmd, "count", &show_count)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "count"); @@ -7536,7 +7536,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) bool ret = false; char *buffer; #ifndef WIN32 - bool console = vshCommandOptBool(cmd, "console"); + bool console = vshCommandOptBool(ctl, cmd, "console"); #endif unsigned int flags = 0; size_t nfds = 0; @@ -7551,11 +7551,11 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_START_PAUSED; - if (vshCommandOptBool(cmd, "autodestroy")) + if (vshCommandOptBool(ctl, cmd, "autodestroy")) flags |= VIR_DOMAIN_START_AUTODESTROY; - if (vshCommandOptBool(cmd, "validate")) + if (vshCommandOptBool(ctl, cmd, "validate")) flags |= VIR_DOMAIN_START_VALIDATE; if (nfds) @@ -7621,7 +7621,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; - if (vshCommandOptBool(cmd, "validate")) + if (vshCommandOptBool(ctl, cmd, "validate")) flags |= VIR_DOMAIN_DEFINE_VALIDATE; if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) @@ -7682,7 +7682,7 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - if (vshCommandOptBool(cmd, "graceful")) + if (vshCommandOptBool(ctl, cmd, "graceful")) flags |= VIR_DOMAIN_DESTROY_GRACEFUL; if (flags) @@ -7751,12 +7751,12 @@ static bool cmdDesc(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); - bool title = vshCommandOptBool(cmd, "title"); - bool edit = vshCommandOptBool(cmd, "edit"); + bool title = vshCommandOptBool(ctl, cmd, "title"); + bool edit = vshCommandOptBool(ctl, cmd, "edit"); int state; int type; @@ -7784,7 +7784,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) if ((state = vshDomainState(ctl, dom, NULL)) < 0) goto cleanup; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (pad) virBufferAddChar(&buf, ' '); pad = true; @@ -7959,11 +7959,11 @@ static bool cmdMetadata(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); - bool edit = vshCommandOptBool(cmd, "edit"); - bool rem = vshCommandOptBool(cmd, "remove"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool edit = vshCommandOptBool(ctl, cmd, "edit"); + bool rem = vshCommandOptBool(ctl, cmd, "remove"); const char *set = NULL; const char *uri = NULL; const char *key = NULL; @@ -8140,10 +8140,10 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptString(cmd, "codeset", &codeset_option) <= 0) + if (vshCommandOptString(ctl, cmd, "codeset", &codeset_option) <= 0) codeset_option = "linux"; - if (vshCommandOptUInt(cmd, "holdtime", &holdtime) < 0) { + if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "holdtime"); @@ -8156,7 +8156,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (count == VIR_DOMAIN_SEND_KEY_MAX_KEYS) { vshError(ctl, _("too many keycodes")); goto cleanup; @@ -8269,7 +8269,7 @@ cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptLongLong(cmd, "pid", &pid_value) < 0) { + if (vshCommandOptLongLong(ctl, cmd, "pid", &pid_value) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "pid"); @@ -8345,9 +8345,9 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) unsigned long long max; unsigned long kibibytes = 0; bool ret = true; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -8370,7 +8370,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) max = 1024ull * ULONG_MAX; else max = ULONG_MAX; - if (vshCommandOptScaledInt(cmd, "size", &bytes, 1024, max) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "size"); @@ -8442,9 +8442,9 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) unsigned long long max; unsigned long kibibytes = 0; bool ret = true; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT | VIR_DOMAIN_MEM_MAXIMUM; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -8467,7 +8467,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) max = 1024ull * ULONG_MAX; else max = ULONG_MAX; - if (vshCommandOptScaledInt(cmd, "size", &bytes, 1024, max) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "size"); @@ -8562,14 +8562,14 @@ static const vshCmdOptDef opts_memtune[] = { * <0 in all other cases */ static int -vshMemtuneGetSize(const vshCmd *cmd, const char *name, long long *value) +vshMemtuneGetSize(vshControl *ctl, const vshCmd *cmd, const char *name, long long *value) { int ret; unsigned long long tmp; const char *str; char *end; - ret = vshCommandOptString(cmd, name, &str); + ret = vshCommandOptString(ctl, cmd, name, &str); if (ret <= 0) return ret; if (virStrToLong_ll(str, &end, 10, value) < 0) @@ -8597,9 +8597,9 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd) virTypedParameterPtr params = NULL; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -8613,7 +8613,7 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd) return false; #define PARSE_MEMTUNE_PARAM(NAME, FIELD) \ - if ((rc = vshMemtuneGetSize(cmd, NAME, &tmpVal)) < 0) { \ + if ((rc = vshMemtuneGetSize(ctl, cmd, NAME, &tmpVal)) < 0) { \ vshError(ctl, _("Unable to parse integer parameter %s"), NAME); \ goto cleanup; \ } \ @@ -8738,9 +8738,9 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd) const char *nodeset = NULL; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); const char *mode = NULL; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -8884,7 +8884,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) if (dom == NULL) goto cleanup; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (pad) virBufferAddChar(&buf, ' '); pad = true; @@ -8896,8 +8896,8 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) } monitor_cmd = virBufferContentAndReset(&buf); - if (vshCommandOptBool(cmd, "hmp")) { - if (vshCommandOptBool(cmd, "pretty")) { + if (vshCommandOptBool(ctl, cmd, "hmp")) { + if (vshCommandOptBool(ctl, cmd, "pretty")) { vshError(ctl, _("--hmp and --pretty are not compatible")); goto cleanup; } @@ -8907,7 +8907,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "pretty")) { + if (vshCommandOptBool(ctl, cmd, "pretty")) { char *tmp; pretty = virJSONValueFromString(result); if (pretty && (tmp = virJSONValueToString(pretty, true))) { @@ -9021,21 +9021,21 @@ cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cmd) const char *event = NULL; vshQemuEventData data; - if (vshCommandOptBool(cmd, "regex")) + if (vshCommandOptBool(ctl, cmd, "regex")) flags |= VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX; - if (vshCommandOptBool(cmd, "no-case")) + if (vshCommandOptBool(ctl, cmd, "no-case")) flags |= VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE; data.ctl = ctl; - data.loop = vshCommandOptBool(cmd, "loop"); - data.pretty = vshCommandOptBool(cmd, "pretty"); + data.loop = vshCommandOptBool(ctl, cmd, "loop"); + data.pretty = vshCommandOptBool(ctl, cmd, "pretty"); data.count = 0; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; - if (vshCommandOptString(cmd, "event", &event) < 0) + if (vshCommandOptString(ctl, cmd, "event", &event) < 0) return false; - if (vshCommandOptBool(cmd, "domain")) + if (vshCommandOptBool(ctl, cmd, "domain")) dom = vshCommandOptDomain(ctl, cmd, NULL); if (vshEventStart(ctl, timeout) < 0) goto cleanup; @@ -9103,7 +9103,7 @@ cmdQemuAttach(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; unsigned int pid_value; /* API uses unsigned int, not pid_t */ - if (vshCommandOptUInt(cmd, "pid", &pid_value) <= 0) { + if (vshCommandOptUInt(ctl, cmd, "pid", &pid_value) <= 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "pid"); @@ -9187,7 +9187,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) if (dom == NULL) goto cleanup; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (pad) virBufferAddChar(&buf, ' '); pad = true; @@ -9199,7 +9199,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) } guest_agent_cmd = virBufferContentAndReset(&buf); - judge = vshCommandOptInt(cmd, "timeout", &timeout); + judge = vshCommandOptInt(ctl, cmd, "timeout", &timeout); if (judge < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), @@ -9213,11 +9213,11 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptBool(cmd, "async")) { + if (vshCommandOptBool(ctl, cmd, "async")) { timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT; judge++; } - if (vshCommandOptBool(cmd, "block")) { + if (vshCommandOptBool(ctl, cmd, "block")) { timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK; judge++; } @@ -9231,7 +9231,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) if (!result) goto cleanup; - if (vshCommandOptBool(cmd, "pretty")) { + if (vshCommandOptBool(ctl, cmd, "pretty")) { char *tmp; pretty = virJSONValueFromString(result); if (pretty && (tmp = virJSONValueToString(pretty, true))) { @@ -9306,10 +9306,10 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) if (dom == NULL) goto cleanup; - if (vshCommandOptBool(cmd, "noseclabel")) + if (vshCommandOptBool(ctl, cmd, "noseclabel")) setlabel = false; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (VIR_EXPAND_N(cmdargv, ncmdargv, 1) < 0) { vshError(ctl, _("%s: %d: failed to allocate argv"), __FILE__, __LINE__); @@ -9442,10 +9442,10 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) bool ret = true; char *dump; unsigned int flags = 0; - bool inactive = vshCommandOptBool(cmd, "inactive"); - bool secure = vshCommandOptBool(cmd, "security-info"); - bool update = vshCommandOptBool(cmd, "update-cpu"); - bool migratable = vshCommandOptBool(cmd, "migratable"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); + bool secure = vshCommandOptBool(ctl, cmd, "security-info"); + bool update = vshCommandOptBool(ctl, cmd, "update-cpu"); + bool migratable = vshCommandOptBool(ctl, cmd, "migratable"); if (inactive) flags |= VIR_DOMAIN_XML_INACTIVE; @@ -9898,49 +9898,49 @@ doMigrate(void *opaque) VIR_FREE(xml); } - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) flags |= VIR_MIGRATE_LIVE; - if (vshCommandOptBool(cmd, "p2p")) + if (vshCommandOptBool(ctl, cmd, "p2p")) flags |= VIR_MIGRATE_PEER2PEER; - if (vshCommandOptBool(cmd, "tunnelled")) + if (vshCommandOptBool(ctl, cmd, "tunnelled")) flags |= VIR_MIGRATE_TUNNELLED; - if (vshCommandOptBool(cmd, "persistent")) + if (vshCommandOptBool(ctl, cmd, "persistent")) flags |= VIR_MIGRATE_PERSIST_DEST; - if (vshCommandOptBool(cmd, "undefinesource")) + if (vshCommandOptBool(ctl, cmd, "undefinesource")) flags |= VIR_MIGRATE_UNDEFINE_SOURCE; - if (vshCommandOptBool(cmd, "suspend")) + if (vshCommandOptBool(ctl, cmd, "suspend")) flags |= VIR_MIGRATE_PAUSED; - if (vshCommandOptBool(cmd, "copy-storage-all")) + if (vshCommandOptBool(ctl, cmd, "copy-storage-all")) flags |= VIR_MIGRATE_NON_SHARED_DISK; - if (vshCommandOptBool(cmd, "copy-storage-inc")) + if (vshCommandOptBool(ctl, cmd, "copy-storage-inc")) flags |= VIR_MIGRATE_NON_SHARED_INC; - if (vshCommandOptBool(cmd, "change-protection")) + if (vshCommandOptBool(ctl, cmd, "change-protection")) flags |= VIR_MIGRATE_CHANGE_PROTECTION; - if (vshCommandOptBool(cmd, "unsafe")) + if (vshCommandOptBool(ctl, cmd, "unsafe")) flags |= VIR_MIGRATE_UNSAFE; - if (vshCommandOptBool(cmd, "compressed")) + if (vshCommandOptBool(ctl, cmd, "compressed")) flags |= VIR_MIGRATE_COMPRESSED; - if (vshCommandOptBool(cmd, "auto-converge")) + if (vshCommandOptBool(ctl, cmd, "auto-converge")) flags |= VIR_MIGRATE_AUTO_CONVERGE; - if (vshCommandOptBool(cmd, "rdma-pin-all")) + if (vshCommandOptBool(ctl, cmd, "rdma-pin-all")) flags |= VIR_MIGRATE_RDMA_PIN_ALL; - if (vshCommandOptBool(cmd, "offline")) + if (vshCommandOptBool(ctl, cmd, "offline")) flags |= VIR_MIGRATE_OFFLINE; - if (vshCommandOptBool(cmd, "abort-on-error")) + if (vshCommandOptBool(ctl, cmd, "abort-on-error")) flags |= VIR_MIGRATE_ABORT_ON_ERROR; - if (flags & VIR_MIGRATE_PEER2PEER || vshCommandOptBool(cmd, "direct")) { + if (flags & VIR_MIGRATE_PEER2PEER || vshCommandOptBool(ctl, cmd, "direct")) { if (virDomainMigrateToURI3(dom, desturi, params, nparams, flags) == 0) ret = '0'; } else { @@ -9992,10 +9992,10 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptBool(cmd, "verbose")) + if (vshCommandOptBool(ctl, cmd, "verbose")) verbose = true; - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) live_flag = true; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) { goto cleanup; @@ -10012,7 +10012,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) data.cmd = cmd; data.writefd = p[1]; - if (vshCommandOptBool(cmd, "p2p") || vshCommandOptBool(cmd, "direct")) { + if (vshCommandOptBool(ctl, cmd, "p2p") || vshCommandOptBool(ctl, cmd, "direct")) { data.dconn = NULL; } else { /* For traditional live migration, connect to the destination host. */ @@ -10085,7 +10085,7 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptLongLong(cmd, "downtime", &downtime) < 0) { + if (vshCommandOptLongLong(ctl, cmd, "downtime", &downtime) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "downtime"); @@ -10147,7 +10147,7 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - rc = vshCommandOptULongLong(cmd, "size", &size); + rc = vshCommandOptULongLong(ctl, cmd, "size", &size); if (rc < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), @@ -10208,7 +10208,7 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) { + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "bandwidth"); @@ -10332,7 +10332,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptBool(cmd, "include-password")) + if (vshCommandOptBool(ctl, cmd, "include-password")) flags |= VIR_DOMAIN_XML_SECURE; if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) @@ -10852,10 +10852,10 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) char *buffer = NULL; int ret; bool funcRet = false; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -10957,10 +10957,10 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) char *buffer = NULL; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -10987,7 +10987,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptBool(cmd, "force")) + if (vshCommandOptBool(ctl, cmd, "force")) flags |= VIR_DOMAIN_DEVICE_MODIFY_FORCE; if (virDomainUpdateDeviceFlags(dom, buffer, flags) < 0) { @@ -11068,10 +11068,10 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd) int ret; bool functionReturn = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -11431,10 +11431,10 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) int ret; bool functionReturn = false; xmlNodePtr disk_node = NULL; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -11533,7 +11533,7 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd) if (dom == NULL) goto cleanup; - if (vshCommandOptBool(cmd, "skip-validate")) + if (vshCommandOptBool(ctl, cmd, "skip-validate")) define_flags &= ~VIR_DOMAIN_DEFINE_VALIDATE; #define EDIT_GET_XML virDomainGetXMLDesc(dom, query_flags) @@ -12239,17 +12239,17 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) size_t i; const char *eventName = NULL; int event = -1; - bool all = vshCommandOptBool(cmd, "all"); - bool loop = vshCommandOptBool(cmd, "loop"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool loop = vshCommandOptBool(ctl, cmd, "loop"); int count = 0; - if (vshCommandOptBool(cmd, "list")) { + if (vshCommandOptBool(ctl, cmd, "list")) { for (event = 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) vshPrint(ctl, "%s\n", vshEventCallbacks[event].name); return true; } - if (vshCommandOptString(cmd, "event", &eventName) < 0) + if (vshCommandOptString(ctl, cmd, "event", &eventName) < 0) return false; if (eventName) { for (event = 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) @@ -12279,7 +12279,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) if (VIR_ALLOC_N(data, 1) < 0) goto cleanup; data[0].ctl = ctl; - data[0].loop = vshCommandOptBool(cmd, "loop"); + data[0].loop = vshCommandOptBool(ctl, cmd, "loop"); data[0].count = &count; data[0].cb = &vshEventCallbacks[event]; data[0].id = -1; @@ -12287,7 +12287,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "domain")) + if (vshCommandOptBool(ctl, cmd, "domain")) dom = vshCommandOptDomain(ctl, cmd, NULL); if (vshEventStart(ctl, timeout) < 0) goto cleanup; @@ -12421,14 +12421,14 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) vshUpdateDiskXMLType update_type; const char *action = NULL; const char *success_msg = NULL; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); - bool force = vshCommandOptBool(cmd, "force"); - bool eject = vshCommandOptBool(cmd, "eject"); - bool insert = vshCommandOptBool(cmd, "insert"); - bool update = vshCommandOptBool(cmd, "update"); - bool block = vshCommandOptBool(cmd, "block"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool force = vshCommandOptBool(ctl, cmd, "force"); + bool eject = vshCommandOptBool(ctl, cmd, "eject"); + bool insert = vshCommandOptBool(ctl, cmd, "insert"); + bool update = vshCommandOptBool(ctl, cmd, "update"); + bool block = vshCommandOptBool(ctl, cmd, "block"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(eject, insert); @@ -12488,7 +12488,7 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) update_type))) goto cleanup; - if (vshCommandOptBool(cmd, "print-xml")) { + if (vshCommandOptBool(ctl, cmd, "print-xml")) { vshPrint(ctl, "%s", disk_xml); } else { if (virDomainUpdateDeviceFlags(dom, disk_xml, flags) != 0) { @@ -12548,7 +12548,7 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return ret; - if (vshCommandOptULongLong(cmd, "minimum", &minimum) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "minimum"); @@ -12604,7 +12604,7 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (VIR_EXPAND_N(mountpoints, nmountpoints, 1) < 0) { vshError(ctl, _("%s: %d: failed to allocate mountpoints"), __FILE__, __LINE__); @@ -12661,7 +12661,7 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (VIR_EXPAND_N(mountpoints, nmountpoints, 1) < 0) { vshError(ctl, _("%s: %d: failed to allocate mountpoints"), __FILE__, __LINE__); diff --git a/tools/virsh-host.c b/tools/virsh-host.c index a72fd05..aa37aa6 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -167,8 +167,8 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) unsigned long nodes_cnt; unsigned long *nodes_id = NULL; unsigned long long *nodes_free = NULL; - bool all = vshCommandOptBool(cmd, "all"); - bool cellno = vshCommandOptBool(cmd, "cellno"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool cellno = vshCommandOptBool(ctl, cmd, "cellno"); size_t i; char *cap_xml = NULL; xmlDocPtr xml = NULL; @@ -176,7 +176,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (cellno && vshCommandOptInt(cmd, "cellno", &cell) < 0) { + if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cellno"); @@ -305,13 +305,13 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) char *cap_xml = NULL; xmlDocPtr doc = NULL; xmlXPathContextPtr ctxt = NULL; - bool all = vshCommandOptBool(cmd, "all"); - bool cellno = vshCommandOptBool(cmd, "cellno"); - bool pagesz = vshCommandOptBool(cmd, "pagesize"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool cellno = vshCommandOptBool(ctl, cmd, "cellno"); + bool pagesz = vshCommandOptBool(ctl, cmd, "pagesize"); VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (vshCommandOptScaledInt(cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "pagesize"); @@ -391,7 +391,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptInt(cmd, "cellno", &cell) < 0) { + if (vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cellno"); @@ -475,9 +475,9 @@ static bool cmdAllocpages(vshControl *ctl, const vshCmd *cmd) { bool ret = false; - bool add = vshCommandOptBool(cmd, "add"); - bool all = vshCommandOptBool(cmd, "all"); - bool cellno = vshCommandOptBool(cmd, "cellno"); + bool add = vshCommandOptBool(ctl, cmd, "add"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool cellno = vshCommandOptBool(ctl, cmd, "cellno"); int startCell = -1; int cellCount = 1; unsigned int pageSizes[1]; @@ -490,14 +490,14 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (cellno && vshCommandOptInt(cmd, "cellno", &startCell) < 0) { + if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &startCell) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cellno"); return false; } - if (vshCommandOptScaledInt(cmd, "pagesize", &tmp, 1024, UINT_MAX) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cellno"); @@ -505,7 +505,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) } pageSizes[0] = VIR_DIV_UP(tmp, 1024); - if (vshCommandOptULongLong(cmd, "pagecount", &pageCounts[0]) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "pagecount", &pageCounts[0]) < 0) { vshError(ctl, "%s", _("pagecount has to be a number")); return false; } @@ -666,7 +666,7 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) int cpu, cpunum; unsigned char *cpumap = NULL; unsigned int online; - bool pretty = vshCommandOptBool(cmd, "pretty"); + bool pretty = vshCommandOptBool(ctl, cmd, "pretty"); bool ret = false; cpunum = virNodeGetCPUMap(ctl->conn, &cpumap, &online, 0); @@ -756,7 +756,7 @@ static bool cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) { size_t i, j; - bool flag_percent = vshCommandOptBool(cmd, "percent"); + bool flag_percent = vshCommandOptBool(ctl, cmd, "percent"); int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS; virNodeCPUStatsPtr params; int nparams = 0; @@ -764,7 +764,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) unsigned long long cpu_stats[VSH_CPU_LAST] = { 0 }; bool present[VSH_CPU_LAST] = { false }; - if (vshCommandOptInt(cmd, "cpu", &cpuNum) < 0) { + if (vshCommandOptInt(ctl, cmd, "cpu", &cpuNum) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cpu"); @@ -875,7 +875,7 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) virNodeMemoryStatsPtr params = NULL; bool ret = false; - if (vshCommandOptInt(cmd, "cell", &cellNum) < 0) { + if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cell"); @@ -951,7 +951,7 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) return false; - if (vshCommandOptLongLong(cmd, "duration", &duration) < 0) { + if (vshCommandOptLongLong(ctl, cmd, "duration", &duration) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "duration"); @@ -1205,7 +1205,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) hvType, major, minor, rel); } - if (vshCommandOptBool(cmd, "daemon")) { + if (vshCommandOptBool(ctl, cmd, "daemon")) { ret = virConnectGetLibVersion(ctl->conn, &daemonVersion); if (ret < 0) { vshError(ctl, "%s", _("failed to get the daemon version")); @@ -1260,7 +1260,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) int rc = -1; size_t i; - if ((rc = vshCommandOptUInt(cmd, "shm-pages-to-scan", &value)) < 0) { + if ((rc = vshCommandOptUInt(ctl, cmd, "shm-pages-to-scan", &value)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "shm-pages-to-scan"); @@ -1272,7 +1272,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rc = vshCommandOptUInt(cmd, "shm-sleep-millisecs", &value)) < 0) { + if ((rc = vshCommandOptUInt(ctl, cmd, "shm-sleep-millisecs", &value)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "shm-sleep-millisecs"); @@ -1284,7 +1284,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rc = vshCommandOptUInt(cmd, "shm-merge-across-nodes", &value)) < 0) { + if ((rc = vshCommandOptUInt(ctl, cmd, "shm-merge-across-nodes", &value)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "shm-merge-across-nodes"); diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 7122bc5..0f8ea95 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -343,8 +343,8 @@ static const vshCmdOptDef opts_interface_list[] = { static bool cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) { - bool inactive = vshCommandOptBool(cmd, "inactive"); - bool all = vshCommandOptBool(cmd, "all"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); + bool all = vshCommandOptBool(ctl, cmd, "all"); unsigned int flags = VIR_CONNECT_LIST_INTERFACES_ACTIVE; vshInterfaceListPtr list = NULL; size_t i; @@ -480,7 +480,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd) bool ret = true; char *dump; unsigned int flags = 0; - bool inactive = vshCommandOptBool(cmd, "inactive"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); if (inactive) flags |= VIR_INTERFACE_XML_INACTIVE; @@ -841,16 +841,16 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) } /* use "no-stp" because we want "stp" to default true */ - stp = !vshCommandOptBool(cmd, "no-stp"); + stp = !vshCommandOptBool(ctl, cmd, "no-stp"); - if (vshCommandOptUInt(cmd, "delay", &delay) < 0) { + if (vshCommandOptUInt(ctl, cmd, "delay", &delay) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "delay"); goto cleanup; } - nostart = vshCommandOptBool(cmd, "no-start"); + nostart = vshCommandOptBool(ctl, cmd, "no-start"); /* Get the original interface into an xmlDoc */ if (!(if_xml = virInterfaceGetXMLDesc(if_handle, VIR_INTERFACE_XML_INACTIVE))) @@ -1054,7 +1054,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - nostart = vshCommandOptBool(cmd, "no-start"); + nostart = vshCommandOptBool(ctl, cmd, "no-start"); /* Get the bridge xml into an xmlDoc */ if (!(br_xml = virInterfaceGetXMLDesc(br_handle, VIR_INTERFACE_XML_INACTIVE))) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index a45367a..8a52834 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -106,7 +106,7 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd) if (!(network = vshCommandOptNetwork(ctl, cmd, &name))) return false; - autostart = !vshCommandOptBool(cmd, "disable"); + autostart = !vshCommandOptBool(ctl, cmd, "disable"); if (virNetworkSetAutostart(network, autostart) < 0) { if (autostart) @@ -308,7 +308,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd) if (!(network = vshCommandOptNetwork(ctl, cmd, NULL))) return false; - inactive = vshCommandOptBool(cmd, "inactive"); + inactive = vshCommandOptBool(ctl, cmd, "inactive"); if (inactive) flags |= VIR_NETWORK_XML_INACTIVE; @@ -652,12 +652,12 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) { vshNetworkListPtr list = NULL; size_t i; - bool inactive = vshCommandOptBool(cmd, "inactive"); - bool all = vshCommandOptBool(cmd, "all"); - bool persistent = vshCommandOptBool(cmd, "persistent"); - bool transient = vshCommandOptBool(cmd, "transient"); - bool autostart = vshCommandOptBool(cmd, "autostart"); - bool no_autostart = vshCommandOptBool(cmd, "no-autostart"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); + bool transient = vshCommandOptBool(ctl, cmd, "transient"); + bool autostart = vshCommandOptBool(ctl, cmd, "autostart"); + bool no_autostart = vshCommandOptBool(ctl, cmd, "no-autostart"); unsigned int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; if (inactive) @@ -904,9 +904,9 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) int command, section, parentIndex = -1; const char *xml = NULL; char *xmlFromFile = NULL; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); unsigned int flags = 0; const char *affected; @@ -936,7 +936,7 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptInt(cmd, "parent-index", &parentIndex) < 0) { + if (vshCommandOptInt(ctl, cmd, "parent-index", &parentIndex) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "parent-index"); @@ -1219,7 +1219,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) const char *eventName = NULL; int event; - if (vshCommandOptBool(cmd, "list")) { + if (vshCommandOptBool(ctl, cmd, "list")) { size_t i; for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) @@ -1227,7 +1227,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) return true; } - if (vshCommandOptString(cmd, "event", &eventName) < 0) + if (vshCommandOptString(ctl, cmd, "event", &eventName) < 0) return false; if (!eventName) { vshError(ctl, "%s", _("either --list or event type is required")); @@ -1239,12 +1239,12 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) } data.ctl = ctl; - data.loop = vshCommandOptBool(cmd, "loop"); + data.loop = vshCommandOptBool(ctl, cmd, "loop"); data.count = 0; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; - if (vshCommandOptBool(cmd, "network")) + if (vshCommandOptBool(ctl, cmd, "network")) net = vshCommandOptNetwork(ctl, cmd, NULL); if (vshEventStart(ctl, timeout) < 0) goto cleanup; @@ -1337,7 +1337,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; virNetworkPtr network = NULL; - if (vshCommandOptString(cmd, "mac", &mac) < 0) + if (vshCommandOptString(ctl, cmd, "mac", &mac) < 0) return false; if (!(network = vshCommandOptNetwork(ctl, cmd, &name))) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 0d7315c..c748c15 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -387,7 +387,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) { const char *cap_str = NULL; size_t i; - bool tree = vshCommandOptBool(cmd, "tree"); + bool tree = vshCommandOptBool(ctl, cmd, "tree"); bool ret = true; unsigned int flags = 0; char **caps = NULL; @@ -395,7 +395,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) vshNodeDeviceListPtr list = NULL; int cap_type = -1; - ignore_value(vshCommandOptString(cmd, "cap", &cap_str)); + ignore_value(vshCommandOptString(ctl, cmd, "cap", &cap_str)); if (cap_str) { if (tree) { @@ -610,7 +610,7 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) return false; - ignore_value(vshCommandOptString(cmd, "driver", &driverName)); + ignore_value(vshCommandOptString(ctl, cmd, "driver", &driverName)); if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { vshError(ctl, _("Could not find matching device '%s'"), name); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 4865831..98c3359 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -105,7 +105,7 @@ cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name))) return false; - autostart = !vshCommandOptBool(cmd, "disable"); + autostart = !vshCommandOptBool(ctl, cmd, "disable"); if (virStoragePoolSetAutostart(pool, autostart) < 0) { if (autostart) @@ -363,7 +363,7 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; const char *name; char *xml; - bool printXML = vshCommandOptBool(cmd, "print-xml"); + bool printXML = vshCommandOptBool(ctl, cmd, "print-xml"); if (!vshBuildPoolXML(ctl, cmd, &name, &xml)) return false; @@ -456,7 +456,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; const char *name; char *xml; - bool printXML = vshCommandOptBool(cmd, "print-xml"); + bool printXML = vshCommandOptBool(ctl, cmd, "print-xml"); if (!vshBuildPoolXML(ctl, cmd, &name, &xml)) return false; @@ -520,10 +520,10 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name))) return false; - if (vshCommandOptBool(cmd, "no-overwrite")) + if (vshCommandOptBool(ctl, cmd, "no-overwrite")) flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE; - if (vshCommandOptBool(cmd, "overwrite")) + if (vshCommandOptBool(ctl, cmd, "overwrite")) flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE; if (virStoragePoolBuild(pool, flags) == 0) { @@ -698,7 +698,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd) { virStoragePoolPtr pool; bool ret = true; - bool inactive = vshCommandOptBool(cmd, "inactive"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); unsigned int flags = 0; char *dump; @@ -1033,12 +1033,12 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE; vshStoragePoolListPtr list = NULL; const char *type = NULL; - bool details = vshCommandOptBool(cmd, "details"); + bool details = vshCommandOptBool(ctl, cmd, "details"); bool inactive, all; char *outputStr = NULL; - inactive = vshCommandOptBool(cmd, "inactive"); - all = vshCommandOptBool(cmd, "all"); + inactive = vshCommandOptBool(ctl, cmd, "inactive"); + all = vshCommandOptBool(ctl, cmd, "all"); if (inactive) flags = VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE; @@ -1047,16 +1047,16 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE | VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE; - if (vshCommandOptBool(cmd, "autostart")) + if (vshCommandOptBool(ctl, cmd, "autostart")) flags |= VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART; - if (vshCommandOptBool(cmd, "no-autostart")) + if (vshCommandOptBool(ctl, cmd, "no-autostart")) flags |= VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART; - if (vshCommandOptBool(cmd, "persistent")) + if (vshCommandOptBool(ctl, cmd, "persistent")) flags |= VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT; - if (vshCommandOptBool(cmd, "transient")) + if (vshCommandOptBool(ctl, cmd, "transient")) flags |= VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT; if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index c6ceabd..7a9134c 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -508,16 +508,16 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) bool ret = false; unsigned int flags = 0; - if (vshCommandOptBool(cmd, "ephemeral")) + if (vshCommandOptBool(ctl, cmd, "ephemeral")) flags |= VIR_CONNECT_LIST_SECRETS_EPHEMERAL; - if (vshCommandOptBool(cmd, "no-ephemeral")) + if (vshCommandOptBool(ctl, cmd, "no-ephemeral")) flags |= VIR_CONNECT_LIST_SECRETS_NO_EPHEMERAL; - if (vshCommandOptBool(cmd, "private")) + if (vshCommandOptBool(ctl, cmd, "private")) flags |= VIR_CONNECT_LIST_SECRETS_PRIVATE; - if (vshCommandOptBool(cmd, "no-private")) + if (vshCommandOptBool(ctl, cmd, "no-private")) flags |= VIR_CONNECT_LIST_SECRETS_NO_PRIVATE; if (!(list = vshSecretListCollect(ctl, flags))) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 459a8a8..b52254d 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -180,23 +180,23 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) char *buffer = NULL; unsigned int flags = 0; - if (vshCommandOptBool(cmd, "redefine")) + if (vshCommandOptBool(ctl, cmd, "redefine")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE; - if (vshCommandOptBool(cmd, "current")) + if (vshCommandOptBool(ctl, cmd, "current")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT; - if (vshCommandOptBool(cmd, "no-metadata")) + if (vshCommandOptBool(ctl, cmd, "no-metadata")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA; - if (vshCommandOptBool(cmd, "halt")) + if (vshCommandOptBool(ctl, cmd, "halt")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT; - if (vshCommandOptBool(cmd, "disk-only")) + if (vshCommandOptBool(ctl, cmd, "disk-only")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY; - if (vshCommandOptBool(cmd, "reuse-external")) + if (vshCommandOptBool(ctl, cmd, "reuse-external")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT; - if (vshCommandOptBool(cmd, "quiesce")) + if (vshCommandOptBool(ctl, cmd, "quiesce")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE; - if (vshCommandOptBool(cmd, "atomic")) + if (vshCommandOptBool(ctl, cmd, "atomic")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC; - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -398,25 +398,25 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; const vshCmdOpt *opt = NULL; - if (vshCommandOptBool(cmd, "no-metadata")) { - if (vshCommandOptBool(cmd, "print-xml")) { + if (vshCommandOptBool(ctl, cmd, "no-metadata")) { + if (vshCommandOptBool(ctl, cmd, "print-xml")) { vshError(ctl, "%s", _("--print-xml is incompatible with --no-metadata")); return false; } flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA; } - if (vshCommandOptBool(cmd, "halt")) + if (vshCommandOptBool(ctl, cmd, "halt")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT; - if (vshCommandOptBool(cmd, "disk-only")) + if (vshCommandOptBool(ctl, cmd, "disk-only")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY; - if (vshCommandOptBool(cmd, "reuse-external")) + if (vshCommandOptBool(ctl, cmd, "reuse-external")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT; - if (vshCommandOptBool(cmd, "quiesce")) + if (vshCommandOptBool(ctl, cmd, "quiesce")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE; - if (vshCommandOptBool(cmd, "atomic")) + if (vshCommandOptBool(ctl, cmd, "atomic")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC; - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -437,10 +437,10 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) if (memspec && vshParseSnapshotMemspec(ctl, &buf, memspec) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "diskspec")) { + if (vshCommandOptBool(ctl, cmd, "diskspec")) { virBufferAddLit(&buf, "<disks>\n"); virBufferAdjustIndent(&buf, 2); - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (vshParseSnapshotDiskspec(ctl, &buf, opt->data) < 0) goto cleanup; } @@ -457,7 +457,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) buffer = virBufferContentAndReset(&buf); - if (vshCommandOptBool(cmd, "print-xml")) { + if (vshCommandOptBool(ctl, cmd, "print-xml")) { vshPrint(ctl, "%s\n", buffer); ret = true; goto cleanup; @@ -482,7 +482,7 @@ vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd, const char *arg, bool exclusive, virDomainPtr dom, virDomainSnapshotPtr *snap, const char **name) { - bool current = vshCommandOptBool(cmd, "current"); + bool current = vshCommandOptBool(ctl, cmd, "current"); const char *snapname = NULL; if (vshCommandOptStringReq(ctl, cmd, arg, &snapname) < 0) @@ -559,13 +559,13 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) bool ret = false; unsigned int getxml_flags = VIR_DOMAIN_XML_SECURE; unsigned int define_flags = VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE; - bool rename_okay = vshCommandOptBool(cmd, "rename"); - bool clone_okay = vshCommandOptBool(cmd, "clone"); + bool rename_okay = vshCommandOptBool(ctl, cmd, "rename"); + bool clone_okay = vshCommandOptBool(ctl, cmd, "clone"); VSH_EXCLUSIVE_OPTIONS_EXPR("rename", rename_okay, "clone", clone_okay) - if (vshCommandOptBool(cmd, "current") && - vshCommandOptBool(cmd, "snapshotname")) + if (vshCommandOptBool(ctl, cmd, "current") && + vshCommandOptBool(ctl, cmd, "snapshotname")) define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -677,7 +677,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; const char *domname; - if (vshCommandOptBool(cmd, "security-info")) + if (vshCommandOptBool(ctl, cmd, "security-info")) flags |= VIR_DOMAIN_XML_SECURE; VSH_EXCLUSIVE_OPTIONS("name", "snapshotname"); @@ -723,7 +723,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) if (!(snapshot = virDomainSnapshotCurrent(dom, 0))) goto cleanup; - if (vshCommandOptBool(cmd, "name")) { + if (vshCommandOptBool(ctl, cmd, "name")) { const char *name; if (!(name = virDomainSnapshotGetName(snapshot))) goto cleanup; @@ -1527,12 +1527,12 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) time_t creation_time_t; char timestr[100]; struct tm time_info; - bool tree = vshCommandOptBool(cmd, "tree"); - bool name = vshCommandOptBool(cmd, "name"); - bool from = vshCommandOptBool(cmd, "from"); - bool parent = vshCommandOptBool(cmd, "parent"); - bool roots = vshCommandOptBool(cmd, "roots"); - bool current = vshCommandOptBool(cmd, "current"); + bool tree = vshCommandOptBool(ctl, cmd, "tree"); + bool name = vshCommandOptBool(ctl, cmd, "name"); + bool from = vshCommandOptBool(ctl, cmd, "from"); + bool parent = vshCommandOptBool(ctl, cmd, "parent"); + bool roots = vshCommandOptBool(ctl, cmd, "roots"); + bool current = vshCommandOptBool(ctl, cmd, "current"); const char *from_snap = NULL; char *parent_snap = NULL; virDomainSnapshotPtr start = NULL; @@ -1547,7 +1547,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) #define FILTER(option, flag) \ do { \ - if (vshCommandOptBool(cmd, option)) { \ + if (vshCommandOptBool(ctl, cmd, option)) { \ if (tree) { \ vshError(ctl, \ _("--%s and --tree are mutually exclusive"), \ @@ -1570,13 +1570,13 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) if (roots) flags |= VIR_DOMAIN_SNAPSHOT_LIST_ROOTS; - if (vshCommandOptBool(cmd, "metadata")) + if (vshCommandOptBool(ctl, cmd, "metadata")) flags |= VIR_DOMAIN_SNAPSHOT_LIST_METADATA; - if (vshCommandOptBool(cmd, "no-metadata")) + if (vshCommandOptBool(ctl, cmd, "no-metadata")) flags |= VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA; - if (vshCommandOptBool(cmd, "descendants")) { + if (vshCommandOptBool(ctl, cmd, "descendants")) { if (!from && !current) { vshError(ctl, "%s", _("--descendants requires either --from or --current")); @@ -1729,7 +1729,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd) char *xml = NULL; unsigned int flags = 0; - if (vshCommandOptBool(cmd, "security-info")) + if (vshCommandOptBool(ctl, cmd, "security-info")) flags |= VIR_DOMAIN_XML_SECURE; if (vshCommandOptStringReq(ctl, cmd, "snapshotname", &name) < 0) @@ -1877,15 +1877,15 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd) bool force = false; int result; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED; /* We want virsh snapshot-revert --force to work even when talking * to older servers that did the unsafe revert by default but * reject the flag, so we probe without the flag, and only use it * when the error says it will make a difference. */ - if (vshCommandOptBool(cmd, "force")) + if (vshCommandOptBool(ctl, cmd, "force")) force = true; dom = vshCommandOptDomain(ctl, cmd, NULL); @@ -1976,11 +1976,11 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd) &snapshot, &name) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "children")) + if (vshCommandOptBool(ctl, cmd, "children")) flags |= VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN; - if (vshCommandOptBool(cmd, "children-only")) + if (vshCommandOptBool(ctl, cmd, "children-only")) flags |= VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY; - if (vshCommandOptBool(cmd, "metadata")) + if (vshCommandOptBool(ctl, cmd, "metadata")) flags |= VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY; /* XXX If we wanted, we could emulate DELETE_CHILDREN_ONLY even on diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 5d6cc6a..07dfd67 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -202,7 +202,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) virBuffer buf = VIR_BUFFER_INITIALIZER; unsigned long flags = 0; - if (vshCommandOptBool(cmd, "prealloc-metadata")) + if (vshCommandOptBool(ctl, cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL))) @@ -219,7 +219,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptString(cmd, "allocation", &allocationStr) > 0 && + if (vshCommandOptString(ctl, cmd, "allocation", &allocationStr) > 0 && vshVolSize(allocationStr, &allocation) < 0) { vshError(ctl, _("Malformed size %s"), allocationStr); goto cleanup; @@ -377,7 +377,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; char *buffer = NULL; - if (vshCommandOptBool(cmd, "prealloc-metadata")) + if (vshCommandOptBool(ctl, cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL))) @@ -463,10 +463,10 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL))) goto cleanup; - if (vshCommandOptBool(cmd, "prealloc-metadata")) + if (vshCommandOptBool(ctl, cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; - if (vshCommandOptBool(cmd, "reflink")) + if (vshCommandOptBool(ctl, cmd, "reflink")) flags |= VIR_STORAGE_VOL_CREATE_REFLINK; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -584,10 +584,10 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) if (!(origvol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) goto cleanup; - if (vshCommandOptBool(cmd, "prealloc-metadata")) + if (vshCommandOptBool(ctl, cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; - if (vshCommandOptBool(cmd, "reflink")) + if (vshCommandOptBool(ctl, cmd, "reflink")) flags |= VIR_STORAGE_VOL_CREATE_REFLINK; origpool = virStoragePoolLookupByVolume(origvol); @@ -693,14 +693,14 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) const char *name = NULL; unsigned long long offset = 0, length = 0; - if (vshCommandOptULongLong(cmd, "offset", &offset) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "offset"); return false; } - if (vshCommandOptULongLongWrap(cmd, "length", &length) < 0) { + if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "length"); @@ -806,14 +806,14 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) unsigned long long offset = 0, length = 0; bool created = false; - if (vshCommandOptULongLong(cmd, "offset", &offset) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "offset"); return false; } - if (vshCommandOptULongLongWrap(cmd, "length", &length) < 0) { + if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "length"); @@ -1126,13 +1126,13 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd) bool ret = false; bool delta = false; - if (vshCommandOptBool(cmd, "allocate")) + if (vshCommandOptBool(ctl, cmd, "allocate")) flags |= VIR_STORAGE_VOL_RESIZE_ALLOCATE; - if (vshCommandOptBool(cmd, "delta")) { + if (vshCommandOptBool(ctl, cmd, "delta")) { delta = true; flags |= VIR_STORAGE_VOL_RESIZE_DELTA; } - if (vshCommandOptBool(cmd, "shrink")) + if (vshCommandOptBool(ctl, cmd, "shrink")) flags |= VIR_STORAGE_VOL_RESIZE_SHRINK; if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) @@ -1144,7 +1144,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd) if (*capacityStr == '-') { /* The API always requires a positive value; but we allow a * negative value for convenience. */ - if (delta && vshCommandOptBool(cmd, "shrink")) { + if (delta && vshCommandOptBool(ctl, cmd, "shrink")) { capacityStr++; } else { vshError(ctl, "%s", @@ -1384,7 +1384,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) char *outputStr = NULL; const char *unit; double val; - bool details = vshCommandOptBool(cmd, "details"); + bool details = vshCommandOptBool(ctl, cmd, "details"); size_t i; bool ret = false; int stringLength = 0; @@ -1676,7 +1676,7 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd) } /* Return the requested details of the parent storage pool */ - if (vshCommandOptBool(cmd, "uuid")) { + if (vshCommandOptBool(ctl, cmd, "uuid")) { /* Retrieve and return pool UUID string */ if (virStoragePoolGetUUIDString(pool, &uuid[0]) == 0) vshPrint(ctl, "%s\n", uuid); diff --git a/tools/virsh.c b/tools/virsh.c index 4425774..9f94b75 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -439,7 +439,7 @@ static const vshCmdOptDef opts_connect[] = { static bool cmdConnect(vshControl *ctl, const vshCmd *cmd) { - bool ro = vshCommandOptBool(cmd, "readonly"); + bool ro = vshCommandOptBool(ctl, cmd, "readonly"); const char *name = NULL; if (ctl->conn) { @@ -607,7 +607,7 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd) { const char *name = NULL; - if (vshCommandOptString(cmd, "command", &name) <= 0) { + if (vshCommandOptString(ctl, cmd, "command", &name) <= 0) { const vshCmdGrp *grp; const vshCmdDef *def; @@ -875,7 +875,7 @@ cmdCd(vshControl *ctl, const vshCmd *cmd) return false; } - if (vshCommandOptString(cmd, "dir", &dir) <= 0) + if (vshCommandOptString(ctl, cmd, "dir", &dir) <= 0) dir = dir_malloced = virGetUserDirectory(); if (!dir) dir = "/"; @@ -973,12 +973,12 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) char *arg; virBuffer buf = VIR_BUFFER_INITIALIZER; - if (vshCommandOptBool(cmd, "shell")) + if (vshCommandOptBool(ctl, cmd, "shell")) shell = true; - if (vshCommandOptBool(cmd, "xml")) + if (vshCommandOptBool(ctl, cmd, "xml")) xml = true; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { char *str; virBuffer xmlbuf = VIR_BUFFER_INITIALIZER; @@ -1471,7 +1471,8 @@ vshCommandFree(vshCmd *cmd) * issued if a value is returned. */ static int -vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt, +vshCommandOpt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, vshCmdOpt **opt, bool needData) { vshCmdOpt *candidate = cmd->opts; @@ -1515,12 +1516,13 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt, * <0 in all other cases (@value untouched) */ int -vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) +vshCommandOptInt(vshControl *ctl, const vshCmd *cmd, + const char *name, int *value) { vshCmdOpt *arg; int ret; - ret = vshCommandOpt(cmd, name, &arg, true); + ret = vshCommandOpt(ctl, cmd, name, &arg, true); if (ret <= 0) return ret; @@ -1530,15 +1532,14 @@ vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) } static int -vshCommandOptUIntInternal(const vshCmd *cmd, - const char *name, - unsigned int *value, +vshCommandOptUIntInternal(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned int *value, bool wrap) { vshCmdOpt *arg; int ret; - if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) + if ((ret = vshCommandOpt(ctl, cmd, name, &arg, true)) <= 0) return ret; if (wrap) { @@ -1562,9 +1563,10 @@ vshCommandOptUIntInternal(const vshCmd *cmd, * See vshCommandOptInt() */ int -vshCommandOptUInt(const vshCmd *cmd, const char *name, unsigned int *value) +vshCommandOptUInt(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned int *value) { - return vshCommandOptUIntInternal(cmd, name, value, false); + return vshCommandOptUIntInternal(ctl, cmd, name, value, false); } /** @@ -1577,21 +1579,21 @@ vshCommandOptUInt(const vshCmd *cmd, const char *name, unsigned int *value) * See vshCommandOptInt() */ int -vshCommandOptUIntWrap(const vshCmd *cmd, const char *name, unsigned int *value) +vshCommandOptUIntWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned int *value) { - return vshCommandOptUIntInternal(cmd, name, value, true); + return vshCommandOptUIntInternal(ctl, cmd, name, value, true); } static int -vshCommandOptULInternal(const vshCmd *cmd, - const char *name, - unsigned long *value, +vshCommandOptULInternal(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long *value, bool wrap) { vshCmdOpt *arg; int ret; - if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) + if ((ret = vshCommandOpt(ctl, cmd, name, &arg, true)) <= 0) return ret; if (wrap) { @@ -1615,9 +1617,10 @@ vshCommandOptULInternal(const vshCmd *cmd, * See vshCommandOptInt() */ int -vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value) +vshCommandOptUL(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long *value) { - return vshCommandOptULInternal(cmd, name, value, false); + return vshCommandOptULInternal(ctl, cmd, name, value, false); } /** @@ -1630,9 +1633,10 @@ vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value) * See vshCommandOptInt() */ int -vshCommandOptULWrap(const vshCmd *cmd, const char *name, unsigned long *value) +vshCommandOptULWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long *value) { - return vshCommandOptULInternal(cmd, name, value, true); + return vshCommandOptULInternal(ctl, cmd, name, value, true); } /** @@ -1648,12 +1652,13 @@ vshCommandOptULWrap(const vshCmd *cmd, const char *name, unsigned long *value) * <0 in all other cases (@value untouched) */ int -vshCommandOptString(const vshCmd *cmd, const char *name, const char **value) +vshCommandOptString(vshControl *ctl, const vshCmd *cmd, + const char *name, const char **value) { vshCmdOpt *arg; int ret; - ret = vshCommandOpt(cmd, name, &arg, true); + ret = vshCommandOpt(ctl, cmd, name, &arg, true); if (ret <= 0) return ret; @@ -1677,10 +1682,8 @@ vshCommandOptString(const vshCmd *cmd, const char *name, const char **value) * returned and error message printed. */ int -vshCommandOptStringReq(vshControl *ctl, - const vshCmd *cmd, - const char *name, - const char **value) +vshCommandOptStringReq(vshControl *ctl, const vshCmd *cmd, + const char *name, const char **value) { vshCmdOpt *arg; int ret; @@ -1689,7 +1692,7 @@ vshCommandOptStringReq(vshControl *ctl, /* clear out the value */ *value = NULL; - ret = vshCommandOpt(cmd, name, &arg, true); + ret = vshCommandOpt(ctl, cmd, name, &arg, true); /* option is not required and not present */ if (ret == 0) return 0; @@ -1718,13 +1721,13 @@ vshCommandOptStringReq(vshControl *ctl, * See vshCommandOptInt() */ int -vshCommandOptLongLong(const vshCmd *cmd, const char *name, - long long *value) +vshCommandOptLongLong(vshControl *ctl, const vshCmd *cmd, + const char *name, long long *value) { vshCmdOpt *arg; int ret; - ret = vshCommandOpt(cmd, name, &arg, true); + ret = vshCommandOpt(ctl, cmd, name, &arg, true); if (ret <= 0) return ret; @@ -1734,15 +1737,14 @@ vshCommandOptLongLong(const vshCmd *cmd, const char *name, } static int -vshCommandOptULongLongInternal(const vshCmd *cmd, - const char *name, - unsigned long long *value, +vshCommandOptULongLongInternal(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value, bool wrap) { vshCmdOpt *arg; int ret; - if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) + if ((ret = vshCommandOpt(ctl, cmd, name, &arg, true)) <= 0) return ret; if (wrap) { @@ -1766,10 +1768,10 @@ vshCommandOptULongLongInternal(const vshCmd *cmd, * See vshCommandOptInt() */ int -vshCommandOptULongLong(const vshCmd *cmd, const char *name, - unsigned long long *value) +vshCommandOptULongLong(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value) { - return vshCommandOptULongLongInternal(cmd, name, value, false); + return vshCommandOptULongLongInternal(ctl, cmd, name, value, false); } /** @@ -1782,10 +1784,10 @@ vshCommandOptULongLong(const vshCmd *cmd, const char *name, * See vshCommandOptInt() */ int -vshCommandOptULongLongWrap(const vshCmd *cmd, const char *name, - unsigned long long *value) +vshCommandOptULongLongWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value) { - return vshCommandOptULongLongInternal(cmd, name, value, true); + return vshCommandOptULongLongInternal(ctl, cmd, name, value, true); } /** @@ -1800,15 +1802,15 @@ vshCommandOptULongLongWrap(const vshCmd *cmd, const char *name, * See vshCommandOptInt() */ int -vshCommandOptScaledInt(const vshCmd *cmd, const char *name, - unsigned long long *value, int scale, - unsigned long long max) +vshCommandOptScaledInt(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value, + int scale, unsigned long long max) { const char *str; int ret; char *end; - ret = vshCommandOptString(cmd, name, &str); + ret = vshCommandOptString(ctl, cmd, name, &str); if (ret <= 0) return ret; if (virStrToLong_ull(str, &end, 10, value) < 0 || @@ -1829,11 +1831,12 @@ vshCommandOptScaledInt(const vshCmd *cmd, const char *name, * option is present without actually using that data. */ bool -vshCommandOptBool(const vshCmd *cmd, const char *name) +vshCommandOptBool(vshControl *ctl, const vshCmd *cmd, + const char *name) { vshCmdOpt *dummy; - return vshCommandOpt(cmd, name, &dummy, false) == 1; + return vshCommandOpt(ctl, cmd, name, &dummy, false) == 1; } /** @@ -1848,7 +1851,8 @@ vshCommandOptBool(const vshCmd *cmd, const char *name) * list of supported options in CMD->def->opts. */ const vshCmdOpt * -vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt) +vshCommandOptArgv(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const vshCmdOpt *opt) { opt = opt ? opt->next : cmd->opts; @@ -1864,9 +1868,10 @@ vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt) * value of the timeout in milliseconds. Return -1 on error, 0 if * no timeout was requested, and 1 if timeout was set. */ int -vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout) +vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, + int *timeout) { - int rv = vshCommandOptInt(cmd, "timeout", timeout); + int rv = vshCommandOptInt(ctl, cmd, "timeout", timeout); if (rv < 0 || (rv > 0 && *timeout < 1)) { vshError(ctl, "%s", _("invalid timeout")); diff --git a/tools/virsh.h b/tools/virsh.h index 32b1c91..ce9c733 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -279,44 +279,47 @@ bool vshCmddefHelp(vshControl *ctl, const char *name); const vshCmdGrp *vshCmdGrpSearch(const char *grpname); bool vshCmdGrpHelp(vshControl *ctl, const char *name); -int vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptUInt(const vshCmd *cmd, const char *name, - unsigned int *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptUIntWrap(const vshCmd *cmd, const char *name, - unsigned int *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptUL(const vshCmd *cmd, const char *name, - unsigned long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptULWrap(const vshCmd *cmd, const char *name, - unsigned long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptString(const vshCmd *cmd, const char *name, - const char **value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptInt(vshControl *ctl, const vshCmd *cmd, + const char *name, int *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptUInt(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned int *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptUIntWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned int *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptUL(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptULWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptString(vshControl *ctl, const vshCmd *cmd, + const char *name, const char **value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; int vshCommandOptStringReq(vshControl *ctl, const vshCmd *cmd, const char *name, const char **value) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptLongLong(const vshCmd *cmd, const char *name, - long long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptULongLong(const vshCmd *cmd, const char *name, - unsigned long long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptULongLongWrap(const vshCmd *cmd, const char *name, - unsigned long long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptScaledInt(const vshCmd *cmd, const char *name, - unsigned long long *value, int scale, - unsigned long long max) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -bool vshCommandOptBool(const vshCmd *cmd, const char *name); -const vshCmdOpt *vshCommandOptArgv(const vshCmd *cmd, +int vshCommandOptLongLong(vshControl *ctl, const vshCmd *cmd, + const char *name, long long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptULongLong(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptULongLongWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptScaledInt(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value, + int scale, unsigned long long max) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +bool vshCommandOptBool(vshControl *ctl, const vshCmd *cmd, + const char *name); +const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd, const vshCmdOpt *opt); -int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout); +int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, + int *timeout); /* Filter flags for various vshCommandOpt*By() functions */ typedef enum { @@ -452,8 +455,8 @@ char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, * before anything that would require cleanup. */ # define VSH_EXCLUSIVE_OPTIONS(NAME1, NAME2) \ - VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, vshCommandOptBool(cmd, NAME1), \ - NAME2, vshCommandOptBool(cmd, NAME2)) + VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, vshCommandOptBool(ctl, cmd, NAME1), \ + NAME2, vshCommandOptBool(ctl, cmd, NAME2)) /* VSH_EXCLUSIVE_OPTIONS_VAR: * @@ -505,8 +508,8 @@ char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, * before anything that would require cleanup. */ # define VSH_REQUIRE_OPTION(NAME1, NAME2) \ - VSH_REQUIRE_OPTION_EXPR(NAME1, vshCommandOptBool(cmd, NAME1), \ - NAME2, vshCommandOptBool(cmd, NAME2)) + VSH_REQUIRE_OPTION_EXPR(NAME1, vshCommandOptBool(ctl, cmd, NAME1), \ + NAME2, vshCommandOptBool(ctl, cmd, NAME2)) /* VSH_REQUIRE_OPTION_VAR: * -- 2.1.0

On Thu, May 21, 2015 at 11:40:26 +0200, Andrea Bolognani wrote:
This will allow us to use vshError() to report errors from inside vshCommandOpt*(), instead of replicating the same logic and error messages all over the place.
We also have more context inside the vshCommandOpt*() functions, for example the actual value used on the command line, which means we can produce more detailed error messages. --- tools/virsh-domain-monitor.c | 90 +++---- tools/virsh-domain.c | 598 +++++++++++++++++++++---------------------- tools/virsh-host.c | 46 ++-- tools/virsh-interface.c | 14 +- tools/virsh-network.c | 34 +-- tools/virsh-nodedev.c | 6 +- tools/virsh-pool.c | 26 +- tools/virsh-secret.c | 8 +- tools/virsh-snapshot.c | 88 +++---- tools/virsh-volume.c | 34 +-- tools/virsh.c | 113 ++++---- tools/virsh.h | 77 +++--- 12 files changed, 571 insertions(+), 563 deletions(-)
...
diff --git a/tools/virsh.c b/tools/virsh.c index 4425774..9f94b75 100644 --- a/tools/virsh.c +++ b/tools/virsh.c
...
-vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt, +vshCommandOpt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, vshCmdOpt **opt, bool needData)
So this helper is not using ctl nor reporting any errors. Even in the next patch.
{ vshCmdOpt *candidate = cmd->opts;
...
@@ -1829,11 +1831,12 @@ vshCommandOptScaledInt(const vshCmd *cmd, const char *name, * option is present without actually using that data. */ bool -vshCommandOptBool(const vshCmd *cmd, const char *name) +vshCommandOptBool(vshControl *ctl, const vshCmd *cmd, + const char *name) { vshCmdOpt *dummy;
- return vshCommandOpt(cmd, name, &dummy, false) == 1; + return vshCommandOpt(ctl, cmd, name, &dummy, false) == 1;
And vshCommandOptBool is designed not to report any error. I'm not a big fan of changing half of virsh by changing the prototype and then not using the parameter at all.
}
/**
I didn't go through the rest of the changes, but reporting malformed integers right in the parser makes sense to me. Peter

On Thu, 2015-05-21 at 13:22 +0200, Peter Krempa wrote:
-vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt, +vshCommandOpt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, vshCmdOpt **opt, bool needData)
So this helper is not using ctl nor reporting any errors. Even in the next patch.
It did, when I first wrote the patch, when the value for a required option was not found; then I realized that error condition was already taken care of in vshCommandCheckOpts() and I removed the check. I agree that the vshControl argument can be removed. I'll get rid of it.
-vshCommandOptBool(const vshCmd *cmd, const char *name) +vshCommandOptBool(vshControl *ctl, const vshCmd *cmd, + const char *name) { vshCmdOpt *dummy;
- return vshCommandOpt(cmd, name, &dummy, false) == 1; + return vshCommandOpt(ctl, cmd, name, &dummy, false) == 1;
And vshCommandOptBool is designed not to report any error. I'm not a big fan of changing half of virsh by changing the prototype and then not using the parameter at all.
I'd rather keep it so that after the change all vshCommandOpt*() calls are consistent. I don't see the harm in doing so, but maybe I'm missing something? Cheers. -- Andrea Bolognani <abologna@redhat.com>

--- tests/vcpupin | 4 +- tools/virsh-domain-monitor.c | 9 +-- tools/virsh-domain.c | 134 +++++++------------------------------------ tools/virsh-host.c | 57 +++--------------- tools/virsh-interface.c | 6 +- tools/virsh-network.c | 6 +- tools/virsh-volume.c | 24 ++------ tools/virsh.c | 88 ++++++++++++++++------------ 8 files changed, 89 insertions(+), 239 deletions(-) diff --git a/tests/vcpupin b/tests/vcpupin index ab0d38f..b6b8b31 100755 --- a/tests/vcpupin +++ b/tests/vcpupin @@ -34,7 +34,7 @@ fail=0 $abs_top_builddir/tools/virsh --connect test:///default vcpupin test a 0,1 > out 2>&1 test $? = 1 || fail=1 cat <<\EOF > exp || fail=1 -error: Numeric value for <vcpu> option is malformed or out of range +error: Numeric value 'a' for <vcpu> option is malformed or out of range EOF compare exp out || fail=1 @@ -52,7 +52,7 @@ compare exp out || fail=1 $abs_top_builddir/tools/virsh --connect test:///default vcpupin test -100 0,1 > out 2>&1 test $? = 1 || fail=1 cat <<\EOF > exp || fail=1 -error: Numeric value for <vcpu> option is malformed or out of range +error: Numeric value '-100' for <vcpu> option is malformed or out of range EOF compare exp out || fail=1 diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index db7ef8b..5b17505 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -340,12 +340,8 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) /* Providing a period will adjust the balloon driver collection period. * This is not really an unsigned long, but it */ - if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "period"); + if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0) goto cleanup; - } if (rv > 0) { if (period < 0) { vshError(ctl, _("Invalid collection period value '%d'"), period); @@ -1440,9 +1436,6 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (rv < 0) { /* invalid integer format */ - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "time"); goto cleanup; } else if (rv > 0) { /* valid integer to set */ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index bb8e20a..5094b2a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1552,9 +1552,6 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) return false; if ((rv = vshCommandOptInt(ctl, cmd, "weight", &weight)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "weight"); goto cleanup; } else if (rv > 0) { if (weight <= 0) { @@ -1692,12 +1689,8 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) goto cleanup; - if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "bandwidth"); + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) goto cleanup; - } switch (mode) { case VSH_CMD_BLOCK_JOB_ABORT: @@ -2216,24 +2209,12 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) * MiB/s, and either reject negative input or treat it as 0 rather * than trying to guess which value will work well across both * APIs with their different sizes and scales. */ - if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "bandwidth"); + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) goto cleanup; - } - if (vshCommandOptUInt(ctl, cmd, "granularity", &granularity) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "granularity"); + if (vshCommandOptUInt(ctl, cmd, "granularity", &granularity) < 0) goto cleanup; - } - if (vshCommandOptULongLong(ctl, cmd, "buf-size", &buf_size) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "buf-size"); + if (vshCommandOptULongLong(ctl, cmd, "buf-size", &buf_size) < 0) goto cleanup; - } if (xml) { if (virFileReadAll(xml, VSH_MAX_XML_FILE, &xmlstr) < 0) { @@ -2800,12 +2781,8 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0) return false; - if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "size"); + if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) < 0) return false; - } /* Prefer the older interface of KiB. */ if (size % 1024 == 0) @@ -3406,12 +3383,8 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "duration"); + if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0) goto cleanup; - } if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) goto cleanup; @@ -5330,12 +5303,8 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", (const char **) &file) < 0) return false; - if (vshCommandOptUInt(ctl, cmd, "screen", &screen) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "screen"); + if (vshCommandOptUInt(ctl, cmd, "screen", &screen) < 0) return false; - } if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; @@ -6429,12 +6398,8 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) if (!cpulist) VSH_EXCLUSIVE_OPTIONS_VAR(live, config); - if ((got_vcpu = vshCommandOptUInt(ctl, cmd, "vcpu", &vcpu)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "vcpu"); + if ((got_vcpu = vshCommandOptUInt(ctl, cmd, "vcpu", &vcpu)) < 0) return false; - } /* In pin mode, "vcpu" is necessary */ if (cpulist && got_vcpu == 0) { @@ -6698,12 +6663,8 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <= 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "count"); + if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <= 0) goto cleanup; - } /* none of the options were specified */ if (!current && flags == 0) { @@ -6878,12 +6839,8 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "iothread"); + if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0) goto cleanup; - } if (vshCommandOptString(ctl, cmd, "cpulist", &cpulist) < 0) { vshError(ctl, "%s", _("iothreadpin: invalid cpulist.")); @@ -6969,12 +6926,8 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "id"); + if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) goto cleanup; - } if (iothread_id <= 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); goto cleanup; @@ -7051,12 +7004,8 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "id"); + if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) goto cleanup; - } if (iothread_id <= 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); goto cleanup; @@ -7341,9 +7290,6 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) show_total = vshCommandOptBool(ctl, cmd, "total"); if ((rv = vshCommandOptInt(ctl, cmd, "start", &cpu)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "start"); goto cleanup; } else if (rv > 0) { if (cpu < 0) { @@ -7354,9 +7300,6 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) } if ((rv = vshCommandOptInt(ctl, cmd, "count", &show_count)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "count"); goto cleanup; } else if (rv > 0) { if (show_count < 0) { @@ -8143,12 +8086,8 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(ctl, cmd, "codeset", &codeset_option) <= 0) codeset_option = "linux"; - if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "holdtime"); + if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0) goto cleanup; - } codeset = virKeycodeSetTypeFromString(codeset_option); if (codeset < 0) { @@ -8269,12 +8208,8 @@ cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptLongLong(ctl, cmd, "pid", &pid_value) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "pid"); + if (vshCommandOptLongLong(ctl, cmd, "pid", &pid_value) < 0) goto cleanup; - } if (vshCommandOptStringReq(ctl, cmd, "signame", &signame) < 0) goto cleanup; @@ -8371,9 +8306,6 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "size"); virDomainFree(dom); return false; } @@ -8468,9 +8400,6 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "size"); virDomainFree(dom); return false; } @@ -9103,12 +9032,8 @@ cmdQemuAttach(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; unsigned int pid_value; /* API uses unsigned int, not pid_t */ - if (vshCommandOptUInt(ctl, cmd, "pid", &pid_value) <= 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "pid"); + if (vshCommandOptUInt(ctl, cmd, "pid", &pid_value) <= 0) goto cleanup; - } if (!(dom = virDomainQemuAttach(ctl->conn, pid_value, flags))) { vshError(ctl, _("Failed to attach to pid %u"), pid_value); @@ -9200,14 +9125,10 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) guest_agent_cmd = virBufferContentAndReset(&buf); judge = vshCommandOptInt(ctl, cmd, "timeout", &timeout); - if (judge < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "timeout"); + if (judge < 0) goto cleanup; - } else if (judge > 0) { + else if (judge > 0) judge = 1; - } if (judge && timeout < 1) { vshError(ctl, "%s", _("timeout must be positive")); goto cleanup; @@ -10085,12 +10006,8 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptLongLong(ctl, cmd, "downtime", &downtime) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "downtime"); + if (vshCommandOptLongLong(ctl, cmd, "downtime", &downtime) < 0) goto done; - } if (downtime < 1) { vshError(ctl, "%s", _("migrate: Invalid downtime")); goto done; @@ -10149,9 +10066,6 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) rc = vshCommandOptULongLong(ctl, cmd, "size", &size); if (rc < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "size"); goto cleanup; } else if (rc != 0) { if (virDomainMigrateSetCompressionCache(dom, size, 0) < 0) @@ -10208,12 +10122,8 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "bandwidth"); + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) goto done; - } if (virDomainMigrateSetMaxSpeed(dom, bandwidth, 0) < 0) goto done; @@ -12548,12 +12458,8 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return ret; - if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "minimum"); + if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0) goto cleanup; - } if (vshCommandOptStringReq(ctl, cmd, "mountpoint", &mountPoint) < 0) goto cleanup; diff --git a/tools/virsh-host.c b/tools/virsh-host.c index aa37aa6..7ec9373 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -176,12 +176,8 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cellno"); + if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) return false; - } if (all) { if (!(cap_xml = virConnectGetCapabilities(ctl->conn))) { @@ -311,12 +307,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "pagesize"); + if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) goto cleanup; - } kibibytes = VIR_DIV_UP(bytes, 1024); if (all) { @@ -391,12 +383,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cellno"); + if (vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) goto cleanup; - } if (cell < -1) { vshError(ctl, "%s", @@ -490,19 +478,11 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &startCell) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cellno"); + if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &startCell) < 0) return false; - } - if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cellno"); + if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX) < 0) return false; - } pageSizes[0] = VIR_DIV_UP(tmp, 1024); if (vshCommandOptULongLong(ctl, cmd, "pagecount", &pageCounts[0]) < 0) { @@ -764,12 +744,8 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) unsigned long long cpu_stats[VSH_CPU_LAST] = { 0 }; bool present[VSH_CPU_LAST] = { false }; - if (vshCommandOptInt(ctl, cmd, "cpu", &cpuNum) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cpu"); + if (vshCommandOptInt(ctl, cmd, "cpu", &cpuNum) < 0) return false; - } if (virNodeGetCPUStats(ctl->conn, cpuNum, NULL, &nparams, 0) != 0) { vshError(ctl, "%s", @@ -875,12 +851,8 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) virNodeMemoryStatsPtr params = NULL; bool ret = false; - if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cell"); + if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) return false; - } /* get the number of memory parameters */ if (virNodeGetMemoryStats(ctl->conn, cellNum, NULL, &nparams, 0) != 0) { @@ -951,12 +923,8 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) return false; - if (vshCommandOptLongLong(ctl, cmd, "duration", &duration) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "duration"); + if (vshCommandOptLongLong(ctl, cmd, "duration", &duration) < 0) return false; - } if (STREQ(target, "mem")) { suspendTarget = VIR_NODE_SUSPEND_TARGET_MEM; @@ -1261,9 +1229,6 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) size_t i; if ((rc = vshCommandOptUInt(ctl, cmd, "shm-pages-to-scan", &value)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "shm-pages-to-scan"); goto cleanup; } else if (rc > 0) { if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams, @@ -1273,9 +1238,6 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) } if ((rc = vshCommandOptUInt(ctl, cmd, "shm-sleep-millisecs", &value)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "shm-sleep-millisecs"); goto cleanup; } else if (rc > 0) { if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams, @@ -1285,9 +1247,6 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) } if ((rc = vshCommandOptUInt(ctl, cmd, "shm-merge-across-nodes", &value)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "shm-merge-across-nodes"); goto cleanup; } else if (rc > 0) { if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams, diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 0f8ea95..671facc 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -843,12 +843,8 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) /* use "no-stp" because we want "stp" to default true */ stp = !vshCommandOptBool(ctl, cmd, "no-stp"); - if (vshCommandOptUInt(ctl, cmd, "delay", &delay) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "delay"); + if (vshCommandOptUInt(ctl, cmd, "delay", &delay) < 0) goto cleanup; - } nostart = vshCommandOptBool(ctl, cmd, "no-start"); diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 8a52834..58d7906 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -936,12 +936,8 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptInt(ctl, cmd, "parent-index", &parentIndex) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "parent-index"); + if (vshCommandOptInt(ctl, cmd, "parent-index", &parentIndex) < 0) goto cleanup; - } /* The goal is to have a full xml element in the "xml" * string. This is provided in the --xml option, either directly diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 07dfd67..640ecb3 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -693,19 +693,11 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) const char *name = NULL; unsigned long long offset = 0, length = 0; - if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "offset"); + if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) return false; - } - if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "length"); + if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) return false; - } if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; @@ -806,19 +798,11 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) unsigned long long offset = 0, length = 0; bool created = false; - if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "offset"); + if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) return false; - } - if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "length"); + if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) return false; - } if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; diff --git a/tools/virsh.c b/tools/virsh.c index 9f94b75..b5da6fe 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1522,13 +1522,17 @@ vshCommandOptInt(vshControl *ctl, const vshCmd *cmd, vshCmdOpt *arg; int ret; - ret = vshCommandOpt(ctl, cmd, name, &arg, true); - if (ret <= 0) + if ((ret = vshCommandOpt(ctl, cmd, name, &arg, true)) <= 0) return ret; - if (virStrToLong_i(arg->data, NULL, 10, value) < 0) - return -1; - return 1; + if ((ret = virStrToLong_i(arg->data, NULL, 10, value)) < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; + + return ret; } static int @@ -1542,15 +1546,18 @@ vshCommandOptUIntInternal(vshControl *ctl, const vshCmd *cmd, if ((ret = vshCommandOpt(ctl, cmd, name, &arg, true)) <= 0) return ret; - if (wrap) { - if (virStrToLong_ui(arg->data, NULL, 10, value) < 0) - return -1; - } else { - if (virStrToLong_uip(arg->data, NULL, 10, value) < 0) - return -1; - } + if (wrap) + ret = virStrToLong_ui(arg->data, NULL, 10, value); + else + ret = virStrToLong_uip(arg->data, NULL, 10, value); + if (ret < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; - return 1; + return ret; } /** @@ -1596,15 +1603,18 @@ vshCommandOptULInternal(vshControl *ctl, const vshCmd *cmd, if ((ret = vshCommandOpt(ctl, cmd, name, &arg, true)) <= 0) return ret; - if (wrap) { - if (virStrToLong_ul(arg->data, NULL, 10, value) < 0) - return -1; - } else { - if (virStrToLong_ulp(arg->data, NULL, 10, value) < 0) - return -1; - } + if (wrap) + ret = virStrToLong_ul(arg->data, NULL, 10, value); + else + ret = virStrToLong_ulp(arg->data, NULL, 10, value); + if (ret < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; - return 1; + return ret; } /* @@ -1658,8 +1668,7 @@ vshCommandOptString(vshControl *ctl, const vshCmd *cmd, vshCmdOpt *arg; int ret; - ret = vshCommandOpt(ctl, cmd, name, &arg, true); - if (ret <= 0) + if ((ret = vshCommandOpt(ctl, cmd, name, &arg, true)) <= 0) return ret; if (!*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK)) @@ -1727,13 +1736,17 @@ vshCommandOptLongLong(vshControl *ctl, const vshCmd *cmd, vshCmdOpt *arg; int ret; - ret = vshCommandOpt(ctl, cmd, name, &arg, true); - if (ret <= 0) + if ((ret = vshCommandOpt(ctl, cmd, name, &arg, true)) <= 0) return ret; - if (virStrToLong_ll(arg->data, NULL, 10, value) < 0) - return -1; - return 1; + if ((ret = virStrToLong_ll(arg->data, NULL, 10, value)) < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; + + return ret; } static int @@ -1747,15 +1760,18 @@ vshCommandOptULongLongInternal(vshControl *ctl, const vshCmd *cmd, if ((ret = vshCommandOpt(ctl, cmd, name, &arg, true)) <= 0) return ret; - if (wrap) { - if (virStrToLong_ull(arg->data, NULL, 10, value) < 0) - return -1; - } else { - if (virStrToLong_ullp(arg->data, NULL, 10, value) < 0) - return -1; - } + if (wrap) + ret = virStrToLong_ull(arg->data, NULL, 10, value); + else + ret = virStrToLong_ullp(arg->data, NULL, 10, value); + if (ret < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; - return 1; + return ret; } /** -- 2.1.0

Changes from v1: * remove vshControl parameter from vshCommandOpt(), as suggested by Peter * document @ctl parameter for all other functions * update vshCommandOptScaledInt(), which I had missed the first time Cheers. Andrea Bolognani (3): virsh: Make vshCommandOptScaledInt() use vshCommandOpt(). virsh: Pass vshControl to all vshCommandOpt*() calls. virsh: Move error messages inside vshCommandOpt*() functions. tests/vcpupin | 4 +- tools/virsh-domain-monitor.c | 97 +++--- tools/virsh-domain.c | 696 +++++++++++++++++++------------------------ tools/virsh-host.c | 87 ++---- tools/virsh-interface.c | 18 +- tools/virsh-network.c | 38 ++- tools/virsh-nodedev.c | 6 +- tools/virsh-pool.c | 26 +- tools/virsh-secret.c | 8 +- tools/virsh-snapshot.c | 88 +++--- tools/virsh-volume.c | 50 ++-- tools/virsh.c | 217 ++++++++------ tools/virsh.h | 77 ++--- 13 files changed, 645 insertions(+), 767 deletions(-) -- 2.1.0

This aligns it to the other vshCommandOpt*() functions. --- tools/virsh.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 4425774..11c2c30 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1804,16 +1804,17 @@ vshCommandOptScaledInt(const vshCmd *cmd, const char *name, unsigned long long *value, int scale, unsigned long long max) { - const char *str; - int ret; + vshCmdOpt *arg; char *end; + int ret; - ret = vshCommandOptString(cmd, name, &str); - if (ret <= 0) + if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) return ret; - if (virStrToLong_ull(str, &end, 10, value) < 0 || + + if (virStrToLong_ull(arg->data, &end, 10, value) < 0 || virScaleInteger(value, end, scale, max) < 0) return -1; + return 1; } -- 2.1.0

On 22.05.2015 10:59, Andrea Bolognani wrote:
This aligns it to the other vshCommandOpt*() functions. --- tools/virsh.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c index 4425774..11c2c30 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1804,16 +1804,17 @@ vshCommandOptScaledInt(const vshCmd *cmd, const char *name, unsigned long long *value, int scale, unsigned long long max) { - const char *str; - int ret; + vshCmdOpt *arg; char *end; + int ret;
- ret = vshCommandOptString(cmd, name, &str); - if (ret <= 0) + if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0)
This cancels check of arg->def->flags & VSH_OFLAG_EMPTY_OK; but since this flag makes sense only for string arguments, it's okay.
return ret; - if (virStrToLong_ull(str, &end, 10, value) < 0 || + + if (virStrToLong_ull(arg->data, &end, 10, value) < 0 || virScaleInteger(value, end, scale, max) < 0) return -1; + return 1; }
ACK Michal

This will allow us to use vshError() to report errors from inside vshCommandOpt*(), instead of replicating the same logic and error messages all over the place. We also have more context inside the vshCommandOpt*() functions, for example the actual value used on the command line, which means we can produce more detailed error messages. --- tools/virsh-domain-monitor.c | 90 +++---- tools/virsh-domain.c | 598 +++++++++++++++++++++---------------------- tools/virsh-host.c | 46 ++-- tools/virsh-interface.c | 14 +- tools/virsh-network.c | 34 +-- tools/virsh-nodedev.c | 6 +- tools/virsh-pool.c | 26 +- tools/virsh-secret.c | 8 +- tools/virsh-snapshot.c | 88 +++---- tools/virsh-volume.c | 34 +-- tools/virsh.c | 107 ++++---- tools/virsh.h | 77 +++--- 12 files changed, 574 insertions(+), 554 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index a42c150..db7ef8b 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -317,9 +317,9 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) bool ret = false; int rv = 0; int period = -1; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -340,7 +340,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) /* Providing a period will adjust the balloon driver collection period. * This is not really an unsigned long, but it */ - if ((rv = vshCommandOptInt(cmd, "period", &period)) < 0) { + if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "period"); @@ -491,10 +491,10 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) size_t i; bool details = false; - if (vshCommandOptBool(cmd, "inactive")) + if (vshCommandOptBool(ctl, cmd, "inactive")) flags |= VIR_DOMAIN_XML_INACTIVE; - details = vshCommandOptBool(cmd, "details"); + details = vshCommandOptBool(ctl, cmd, "details"); if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -609,7 +609,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) xmlNodePtr *interfaces = NULL; size_t i; - if (vshCommandOptBool(cmd, "inactive")) + if (vshCommandOptBool(ctl, cmd, "inactive")) flags |= VIR_DOMAIN_XML_INACTIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -733,7 +733,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptBool(cmd, "config")) + if (vshCommandOptBool(ctl, cmd, "config")) flags = VIR_DOMAIN_XML_INACTIVE; if (!(desc = virDomainGetXMLDesc(dom, flags))) { @@ -929,7 +929,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) int rc, nparams = 0; size_t i; bool ret = false; - bool human = vshCommandOptBool(cmd, "human"); /* human readable output */ + bool human = vshCommandOptBool(ctl, cmd, "human"); /* human readable output */ if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; @@ -1352,7 +1352,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; bool ret = true; - bool showReason = vshCommandOptBool(cmd, "reason"); + bool showReason = vshCommandOptBool(ctl, cmd, "reason"); int state, reason; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -1420,9 +1420,9 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; bool ret = false; - bool now = vshCommandOptBool(cmd, "now"); - bool pretty = vshCommandOptBool(cmd, "pretty"); - bool rtcSync = vshCommandOptBool(cmd, "sync"); + bool now = vshCommandOptBool(ctl, cmd, "now"); + bool pretty = vshCommandOptBool(ctl, cmd, "pretty"); + bool rtcSync = vshCommandOptBool(ctl, cmd, "sync"); long long seconds = 0; unsigned int nseconds = 0; unsigned int flags = 0; @@ -1436,7 +1436,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - rv = vshCommandOptLongLong(cmd, "time", &seconds); + rv = vshCommandOptLongLong(ctl, cmd, "time", &seconds); if (rv < 0) { /* invalid integer format */ @@ -1856,17 +1856,17 @@ static const vshCmdOptDef opts_list[] = { {.name = NULL} }; -#define FILTER(NAME, FLAG) \ - if (vshCommandOptBool(cmd, NAME)) \ +#define FILTER(NAME, FLAG) \ + if (vshCommandOptBool(ctl, cmd, NAME)) \ flags |= (FLAG) static bool cmdList(vshControl *ctl, const vshCmd *cmd) { - bool managed = vshCommandOptBool(cmd, "managed-save"); - bool optTitle = vshCommandOptBool(cmd, "title"); - bool optTable = vshCommandOptBool(cmd, "table"); - bool optUUID = vshCommandOptBool(cmd, "uuid"); - bool optName = vshCommandOptBool(cmd, "name"); + bool managed = vshCommandOptBool(ctl, cmd, "managed-save"); + bool optTitle = vshCommandOptBool(ctl, cmd, "title"); + bool optTable = vshCommandOptBool(ctl, cmd, "table"); + bool optUUID = vshCommandOptBool(ctl, cmd, "uuid"); + bool optName = vshCommandOptBool(ctl, cmd, "name"); size_t i; char *title; char uuid[VIR_UUID_STRING_BUFLEN]; @@ -1879,10 +1879,10 @@ cmdList(vshControl *ctl, const vshCmd *cmd) unsigned int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; /* construct filter flags */ - if (vshCommandOptBool(cmd, "inactive")) + if (vshCommandOptBool(ctl, cmd, "inactive")) flags = VIR_CONNECT_LIST_DOMAINS_INACTIVE; - if (vshCommandOptBool(cmd, "all")) + if (vshCommandOptBool(ctl, cmd, "all")) flags = VIR_CONNECT_LIST_DOMAINS_INACTIVE | VIR_CONNECT_LIST_DOMAINS_ACTIVE; @@ -2107,65 +2107,65 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd) size_t ndoms = 0; virDomainStatsRecordPtr *records = NULL; virDomainStatsRecordPtr *next; - bool raw = vshCommandOptBool(cmd, "raw"); + bool raw = vshCommandOptBool(ctl, cmd, "raw"); int flags = 0; const vshCmdOpt *opt = NULL; bool ret = false; - if (vshCommandOptBool(cmd, "state")) + if (vshCommandOptBool(ctl, cmd, "state")) stats |= VIR_DOMAIN_STATS_STATE; - if (vshCommandOptBool(cmd, "cpu-total")) + if (vshCommandOptBool(ctl, cmd, "cpu-total")) stats |= VIR_DOMAIN_STATS_CPU_TOTAL; - if (vshCommandOptBool(cmd, "balloon")) + if (vshCommandOptBool(ctl, cmd, "balloon")) stats |= VIR_DOMAIN_STATS_BALLOON; - if (vshCommandOptBool(cmd, "vcpu")) + if (vshCommandOptBool(ctl, cmd, "vcpu")) stats |= VIR_DOMAIN_STATS_VCPU; - if (vshCommandOptBool(cmd, "interface")) + if (vshCommandOptBool(ctl, cmd, "interface")) stats |= VIR_DOMAIN_STATS_INTERFACE; - if (vshCommandOptBool(cmd, "block")) + if (vshCommandOptBool(ctl, cmd, "block")) stats |= VIR_DOMAIN_STATS_BLOCK; - if (vshCommandOptBool(cmd, "list-active")) + if (vshCommandOptBool(ctl, cmd, "list-active")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE; - if (vshCommandOptBool(cmd, "list-inactive")) + if (vshCommandOptBool(ctl, cmd, "list-inactive")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE; - if (vshCommandOptBool(cmd, "list-persistent")) + if (vshCommandOptBool(ctl, cmd, "list-persistent")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT; - if (vshCommandOptBool(cmd, "list-transient")) + if (vshCommandOptBool(ctl, cmd, "list-transient")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT; - if (vshCommandOptBool(cmd, "list-running")) + if (vshCommandOptBool(ctl, cmd, "list-running")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING; - if (vshCommandOptBool(cmd, "list-paused")) + if (vshCommandOptBool(ctl, cmd, "list-paused")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED; - if (vshCommandOptBool(cmd, "list-shutoff")) + if (vshCommandOptBool(ctl, cmd, "list-shutoff")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF; - if (vshCommandOptBool(cmd, "list-other")) + if (vshCommandOptBool(ctl, cmd, "list-other")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER; - if (vshCommandOptBool(cmd, "enforce")) + if (vshCommandOptBool(ctl, cmd, "enforce")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS; - if (vshCommandOptBool(cmd, "backing")) + if (vshCommandOptBool(ctl, cmd, "backing")) flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING; - if (vshCommandOptBool(cmd, "domain")) { + if (vshCommandOptBool(ctl, cmd, "domain")) { if (VIR_ALLOC_N(domlist, 1) < 0) goto cleanup; ndoms = 1; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (!(dom = vshLookupDomainBy(ctl, opt->data, VSH_BYID | VSH_BYUUID | VSH_BYNAME))) goto cleanup; @@ -2237,16 +2237,16 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) size_t i, j; int ifaces_count = 0; bool ret = false; - bool full = vshCommandOptBool(cmd, "full"); + bool full = vshCommandOptBool(ctl, cmd, "full"); const char *sourcestr = NULL; int source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptString(cmd, "interface", &ifacestr) < 0) + if (vshCommandOptString(ctl, cmd, "interface", &ifacestr) < 0) goto cleanup; - if (vshCommandOptString(cmd, "source", &sourcestr) < 0) + if (vshCommandOptString(ctl, cmd, "source", &sourcestr) < 0) goto cleanup; if (sourcestr) { diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 36f3e6c..bb8e20a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -239,10 +239,10 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) int rv; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -597,10 +597,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) virBuffer buf = VIR_BUFFER_INITIALIZER; char *xml = NULL; struct stat st; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -657,7 +657,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) isFile ? "file" : "block"); if (type) virBufferAsprintf(&buf, " device='%s'", type); - if (vshCommandOptBool(cmd, "rawio")) + if (vshCommandOptBool(ctl, cmd, "rawio")) virBufferAddLit(&buf, " rawio='yes'"); virBufferAddLit(&buf, ">\n"); virBufferAdjustIndent(&buf, 2); @@ -707,7 +707,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) " bus ='0x%02x' slot='0x%02x' function='0x%0x'", diskAddr.addr.pci.domain, diskAddr.addr.pci.bus, diskAddr.addr.pci.slot, diskAddr.addr.pci.function); - if (vshCommandOptBool(cmd, "multifunction")) + if (vshCommandOptBool(ctl, cmd, "multifunction")) virBufferAddLit(&buf, " multifunction='on'"); virBufferAddLit(&buf, "/>\n"); } else if (diskAddr.type == DISK_ADDR_TYPE_CCW) { @@ -756,7 +756,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) xml = virBufferContentAndReset(&buf); - if (vshCommandOptBool(cmd, "print-xml")) { + if (vshCommandOptBool(ctl, cmd, "print-xml")) { vshPrint(ctl, "%s", xml); functionReturn = true; goto cleanup; @@ -910,10 +910,10 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) virBuffer buf = VIR_BUFFER_INITIALIZER; char *xml; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -1098,7 +1098,7 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - autostart = !vshCommandOptBool(cmd, "disable"); + autostart = !vshCommandOptBool(ctl, cmd, "disable"); if (virDomainSetAutostart(dom, autostart) < 0) { if (autostart) @@ -1273,9 +1273,9 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; size_t i; int rv = 0; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); bool ret = false; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -1292,7 +1292,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "device", &disk) < 0) goto cleanup; - if ((rv = vshCommandOptULongLong(cmd, "total-bytes-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "total-bytes-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1301,7 +1301,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "read-bytes-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "read-bytes-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1310,7 +1310,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "write-bytes-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "write-bytes-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1319,7 +1319,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "total-bytes-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "total-bytes-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1328,7 +1328,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "read-bytes-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "read-bytes-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1337,7 +1337,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "write-bytes-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "write-bytes-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1346,7 +1346,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "total-iops-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "total-iops-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1355,7 +1355,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "read-iops-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "read-iops-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1364,7 +1364,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "write-iops-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "write-iops-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1373,7 +1373,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "write-iops-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "write-iops-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1382,7 +1382,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "read-iops-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "read-iops-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1391,7 +1391,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "total-iops-sec-max", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "total-iops-sec-max", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1400,7 +1400,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rv = vshCommandOptULongLong(cmd, "size-iops-sec", &value)) < 0) { + if ((rv = vshCommandOptULongLong(ctl, cmd, "size-iops-sec", &value)) < 0) { goto interror; } else if (rv > 0) { if (virTypedParamsAddULLong(¶ms, &nparams, &maxparams, @@ -1536,9 +1536,9 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) virTypedParameterPtr params = NULL; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -1551,7 +1551,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if ((rv = vshCommandOptInt(cmd, "weight", &weight)) < 0) { + if ((rv = vshCommandOptInt(ctl, cmd, "weight", &weight)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "weight"); @@ -1566,7 +1566,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-weights", &device_weight); + rv = vshCommandOptString(ctl, cmd, "device-weights", &device_weight); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1577,7 +1577,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-read-iops-sec", &device_riops); + rv = vshCommandOptString(ctl, cmd, "device-read-iops-sec", &device_riops); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1588,7 +1588,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-write-iops-sec", &device_wiops); + rv = vshCommandOptString(ctl, cmd, "device-write-iops-sec", &device_wiops); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1599,7 +1599,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-read-bytes-sec", &device_rbps); + rv = vshCommandOptString(ctl, cmd, "device-read-bytes-sec", &device_rbps); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1610,7 +1610,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) goto save_error; } - rv = vshCommandOptString(cmd, "device-write-bytes-sec", &device_wbps); + rv = vshCommandOptString(ctl, cmd, "device-write-bytes-sec", &device_wbps); if (rv < 0) { vshError(ctl, "%s", _("Unable to parse string parameter")); goto cleanup; @@ -1692,7 +1692,7 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) goto cleanup; - if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) { + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "bandwidth"); @@ -1701,9 +1701,9 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, switch (mode) { case VSH_CMD_BLOCK_JOB_ABORT: - if (vshCommandOptBool(cmd, "async")) + if (vshCommandOptBool(ctl, cmd, "async")) flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; - if (vshCommandOptBool(cmd, "pivot")) + if (vshCommandOptBool(ctl, cmd, "pivot")) flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT; if (virDomainBlockJobAbort(dom, path, flags) < 0) goto cleanup; @@ -1715,7 +1715,7 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, case VSH_CMD_BLOCK_JOB_PULL: if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "keep-relative")) + if (vshCommandOptBool(ctl, cmd, "keep-relative")) flags |= VIR_DOMAIN_BLOCK_REBASE_RELATIVE; if (base || flags) { @@ -1731,15 +1731,15 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0 || vshCommandOptStringReq(ctl, cmd, "top", &top) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "shallow")) + if (vshCommandOptBool(ctl, cmd, "shallow")) flags |= VIR_DOMAIN_BLOCK_COMMIT_SHALLOW; - if (vshCommandOptBool(cmd, "delete")) + if (vshCommandOptBool(ctl, cmd, "delete")) flags |= VIR_DOMAIN_BLOCK_COMMIT_DELETE; - if (vshCommandOptBool(cmd, "active") || - vshCommandOptBool(cmd, "pivot") || - vshCommandOptBool(cmd, "keep-overlay")) + if (vshCommandOptBool(ctl, cmd, "active") || + vshCommandOptBool(ctl, cmd, "pivot") || + vshCommandOptBool(ctl, cmd, "keep-overlay")) flags |= VIR_DOMAIN_BLOCK_COMMIT_ACTIVE; - if (vshCommandOptBool(cmd, "keep-relative")) + if (vshCommandOptBool(ctl, cmd, "keep-relative")) flags |= VIR_DOMAIN_BLOCK_COMMIT_RELATIVE; if (virDomainBlockCommit(dom, path, base, top, bandwidth, flags) < 0) goto cleanup; @@ -1889,11 +1889,11 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom = NULL; bool ret = false; - bool verbose = vshCommandOptBool(cmd, "verbose"); - bool pivot = vshCommandOptBool(cmd, "pivot"); - bool finish = vshCommandOptBool(cmd, "keep-overlay"); - bool active = vshCommandOptBool(cmd, "active") || pivot || finish; - bool blocking = vshCommandOptBool(cmd, "wait"); + bool verbose = vshCommandOptBool(ctl, cmd, "verbose"); + bool pivot = vshCommandOptBool(ctl, cmd, "pivot"); + bool finish = vshCommandOptBool(ctl, cmd, "keep-overlay"); + bool active = vshCommandOptBool(ctl, cmd, "active") || pivot || finish; + bool blocking = vshCommandOptBool(ctl, cmd, "wait"); int timeout = 0; struct sigaction sig_action; struct sigaction old_sig_action; @@ -1906,7 +1906,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) int status = -1; int cb_id = -1; - blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish; + blocking |= vshCommandOptBool(ctl, cmd, "timeout") || pivot || finish; if (blocking) { if (pivot && finish) { vshError(ctl, "%s", _("cannot mix --pivot and --keep-overlay")); @@ -1916,7 +1916,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) return false; - if (vshCommandOptBool(cmd, "async")) + if (vshCommandOptBool(ctl, cmd, "async")) abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; sigemptyset(&sigmask); @@ -1929,7 +1929,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) sigaction(SIGINT, &sig_action, &old_sig_action); GETTIMEOFDAY(&start); - } else if (verbose || vshCommandOptBool(cmd, "async")) { + } else if (verbose || vshCommandOptBool(ctl, cmd, "async")) { vshError(ctl, "%s", _("missing --wait option")); return false; } @@ -2138,11 +2138,11 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) unsigned long long buf_size = 0; unsigned int flags = 0; bool ret = false; - bool blocking = vshCommandOptBool(cmd, "wait"); - bool verbose = vshCommandOptBool(cmd, "verbose"); - bool pivot = vshCommandOptBool(cmd, "pivot"); - bool finish = vshCommandOptBool(cmd, "finish"); - bool blockdev = vshCommandOptBool(cmd, "blockdev"); + bool blocking = vshCommandOptBool(ctl, cmd, "wait"); + bool verbose = vshCommandOptBool(ctl, cmd, "verbose"); + bool pivot = vshCommandOptBool(ctl, cmd, "pivot"); + bool finish = vshCommandOptBool(ctl, cmd, "finish"); + bool blockdev = vshCommandOptBool(ctl, cmd, "blockdev"); int timeout = 0; struct sigaction sig_action; struct sigaction old_sig_action; @@ -2161,18 +2161,18 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) return false; - if (vshCommandOptString(cmd, "dest", &dest) < 0) + if (vshCommandOptString(ctl, cmd, "dest", &dest) < 0) return false; - if (vshCommandOptString(cmd, "xml", &xml) < 0) + if (vshCommandOptString(ctl, cmd, "xml", &xml) < 0) return false; - if (vshCommandOptString(cmd, "format", &format) < 0) + if (vshCommandOptString(ctl, cmd, "format", &format) < 0) return false; VSH_EXCLUSIVE_OPTIONS_VAR(dest, xml); VSH_EXCLUSIVE_OPTIONS_VAR(format, xml); VSH_EXCLUSIVE_OPTIONS_VAR(blockdev, xml); - blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish; + blocking |= vshCommandOptBool(ctl, cmd, "timeout") || pivot || finish; if (blocking) { if (pivot && finish) { vshError(ctl, "%s", _("cannot mix --pivot and --finish")); @@ -2180,7 +2180,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) } if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; - if (vshCommandOptBool(cmd, "async")) + if (vshCommandOptBool(ctl, cmd, "async")) abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; sigemptyset(&sigmask); @@ -2193,7 +2193,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) sigaction(SIGINT, &sig_action, &old_sig_action); GETTIMEOFDAY(&start); - } else if (verbose || vshCommandOptBool(cmd, "async")) { + } else if (verbose || vshCommandOptBool(ctl, cmd, "async")) { vshError(ctl, "%s", _("missing --wait option")); return false; } @@ -2216,19 +2216,19 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) * MiB/s, and either reject negative input or treat it as 0 rather * than trying to guess which value will work well across both * APIs with their different sizes and scales. */ - if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) { + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "bandwidth"); goto cleanup; } - if (vshCommandOptUInt(cmd, "granularity", &granularity) < 0) { + if (vshCommandOptUInt(ctl, cmd, "granularity", &granularity) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "granularity"); goto cleanup; } - if (vshCommandOptULongLong(cmd, "buf-size", &buf_size) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "buf-size", &buf_size) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "buf-size"); @@ -2247,9 +2247,9 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) /* Exploit that some VIR_DOMAIN_BLOCK_REBASE_* and * VIR_DOMAIN_BLOCK_COPY_* flags have the same values. */ - if (vshCommandOptBool(cmd, "shallow")) + if (vshCommandOptBool(ctl, cmd, "shallow")) flags |= VIR_DOMAIN_BLOCK_REBASE_SHALLOW; - if (vshCommandOptBool(cmd, "reuse-external")) + if (vshCommandOptBool(ctl, cmd, "reuse-external")) flags |= VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT; if (granularity || buf_size || (format && STRNEQ(format, "raw")) || xml) { @@ -2304,7 +2304,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) } else { /* Old API */ flags |= VIR_DOMAIN_BLOCK_REBASE_COPY; - if (vshCommandOptBool(cmd, "blockdev")) + if (vshCommandOptBool(ctl, cmd, "blockdev")) flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_DEV; if (STREQ_NULLABLE(format, "raw")) flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_RAW; @@ -2473,13 +2473,13 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd) virDomainBlockJobInfo info; bool ret = false; int rc = -1; - bool raw = vshCommandOptBool(cmd, "raw"); - bool bytes = vshCommandOptBool(cmd, "bytes"); - bool abortMode = (vshCommandOptBool(cmd, "abort") || - vshCommandOptBool(cmd, "async") || - vshCommandOptBool(cmd, "pivot")); - bool infoMode = vshCommandOptBool(cmd, "info") || raw; - bool bandwidth = vshCommandOptBool(cmd, "bandwidth"); + bool raw = vshCommandOptBool(ctl, cmd, "raw"); + bool bytes = vshCommandOptBool(ctl, cmd, "bytes"); + bool abortMode = (vshCommandOptBool(ctl, cmd, "abort") || + vshCommandOptBool(ctl, cmd, "async") || + vshCommandOptBool(ctl, cmd, "pivot")); + bool infoMode = vshCommandOptBool(ctl, cmd, "info") || raw; + bool bandwidth = vshCommandOptBool(ctl, cmd, "bandwidth"); virDomainPtr dom = NULL; const char *path; unsigned int flags = 0; @@ -2639,8 +2639,8 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom = NULL; bool ret = false; - bool blocking = vshCommandOptBool(cmd, "wait"); - bool verbose = vshCommandOptBool(cmd, "verbose"); + bool blocking = vshCommandOptBool(ctl, cmd, "wait"); + bool verbose = vshCommandOptBool(ctl, cmd, "verbose"); int timeout = 0; struct sigaction sig_action; struct sigaction old_sig_action; @@ -2658,7 +2658,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) return false; - if (vshCommandOptBool(cmd, "async")) + if (vshCommandOptBool(ctl, cmd, "async")) abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; sigemptyset(&sigmask); @@ -2671,8 +2671,8 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) sigaction(SIGINT, &sig_action, &old_sig_action); GETTIMEOFDAY(&start); - } else if (verbose || vshCommandOptBool(cmd, "timeout") || - vshCommandOptBool(cmd, "async")) { + } else if (verbose || vshCommandOptBool(ctl, cmd, "timeout") || + vshCommandOptBool(ctl, cmd, "async")) { vshError(ctl, "%s", _("missing --wait option")); return false; } @@ -2800,7 +2800,7 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0) return false; - if (vshCommandOptScaledInt(cmd, "size", &size, 1024, ULLONG_MAX) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "size"); @@ -2901,8 +2901,8 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; bool ret = false; - bool force = vshCommandOptBool(cmd, "force"); - bool safe = vshCommandOptBool(cmd, "safe"); + bool force = vshCommandOptBool(ctl, cmd, "force"); + bool safe = vshCommandOptBool(ctl, cmd, "safe"); unsigned int flags = 0; const char *name = NULL; @@ -2993,7 +2993,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "state", &state) < 0) goto cleanup; - config = vshCommandOptBool(cmd, "config"); + config = vshCommandOptBool(ctl, cmd, "config"); if (STRNEQ(state, "up") && STRNEQ(state, "down")) { vshError(ctl, _("invalid link state '%s'"), state); @@ -3170,9 +3170,9 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd) int maxparams = 0; virTypedParameterPtr params = NULL; bool ret = false; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); virNetDevBandwidthRate inbound, outbound; size_t i; @@ -3406,7 +3406,7 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - if (vshCommandOptULongLong(cmd, "duration", &duration) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "duration"); @@ -3556,11 +3556,11 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) /* Flags to attempt. */ unsigned int flags = 0; /* User-requested actions. */ - bool managed_save = vshCommandOptBool(cmd, "managed-save"); - bool snapshots_metadata = vshCommandOptBool(cmd, "snapshots-metadata"); - bool wipe_storage = vshCommandOptBool(cmd, "wipe-storage"); - bool remove_all_storage = vshCommandOptBool(cmd, "remove-all-storage"); - bool nvram = vshCommandOptBool(cmd, "nvram"); + bool managed_save = vshCommandOptBool(ctl, cmd, "managed-save"); + bool snapshots_metadata = vshCommandOptBool(ctl, cmd, "snapshots-metadata"); + bool wipe_storage = vshCommandOptBool(ctl, cmd, "wipe-storage"); + bool remove_all_storage = vshCommandOptBool(ctl, cmd, "remove-all-storage"); + bool nvram = vshCommandOptBool(ctl, cmd, "nvram"); /* Positive if these items exist. */ int has_managed_save = 0; int has_snapshots_metadata = 0; @@ -3587,7 +3587,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) size_t i; size_t j; - ignore_value(vshCommandOptString(cmd, "storage", &vol_string)); + ignore_value(vshCommandOptString(ctl, cmd, "storage", &vol_string)); if (!(vol_string || remove_all_storage) && wipe_storage) { vshError(ctl, @@ -3966,7 +3966,7 @@ cmdStartGetFDs(vshControl *ctl, *nfdsret = 0; *fdsret = NULL; - if (vshCommandOptString(cmd, "pass-fds", &fdopt) <= 0) + if (vshCommandOptString(ctl, cmd, "pass-fds", &fdopt) <= 0) return 0; if (!(fdlist = virStringSplit(fdopt, ",", -1))) { @@ -4005,7 +4005,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; bool ret = false; #ifndef WIN32 - bool console = vshCommandOptBool(cmd, "console"); + bool console = vshCommandOptBool(ctl, cmd, "console"); #endif unsigned int flags = VIR_DOMAIN_NONE; int rc; @@ -4024,13 +4024,13 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_START_PAUSED; - if (vshCommandOptBool(cmd, "autodestroy")) + if (vshCommandOptBool(ctl, cmd, "autodestroy")) flags |= VIR_DOMAIN_START_AUTODESTROY; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DOMAIN_START_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "force-boot")) + if (vshCommandOptBool(ctl, cmd, "force-boot")) flags |= VIR_DOMAIN_START_FORCE_BOOT; /* We can emulate force boot, even for older servers that reject it. */ @@ -4152,11 +4152,11 @@ doSave(void *opaque) if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) goto out; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SAVE_PAUSED; if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0) @@ -4324,7 +4324,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "verbose")) + if (vshCommandOptBool(ctl, cmd, "verbose")) verbose = true; if (pipe(p) < 0) @@ -4386,7 +4386,7 @@ cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; char *xml = NULL; - if (vshCommandOptBool(cmd, "security-info")) + if (vshCommandOptBool(ctl, cmd, "security-info")) flags |= VIR_DOMAIN_XML_SECURE; if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0) @@ -4448,9 +4448,9 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) char *xml = NULL; unsigned int flags = 0; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SAVE_PAUSED; if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0) @@ -4513,9 +4513,9 @@ cmdSaveImageEdit(vshControl *ctl, const vshCmd *cmd) unsigned int getxml_flags = VIR_DOMAIN_XML_SECURE; unsigned int define_flags = 0; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) define_flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) define_flags |= VIR_DOMAIN_SAVE_PAUSED; /* Normally, we let the API reject mutually exclusive flags. @@ -4608,11 +4608,11 @@ doManagedsave(void *opaque) if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0) goto out_sig; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SAVE_PAUSED; if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) @@ -4646,7 +4646,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - if (vshCommandOptBool(cmd, "verbose")) + if (vshCommandOptBool(ctl, cmd, "verbose")) verbose = true; if (pipe(p) < 0) @@ -4834,7 +4834,7 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd, int ret = -1; int rv; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { set_field = vshStrdup(ctl, opt->data); if (!(set_val = strchr(set_field, '='))) { vshError(ctl, "%s", _("Invalid syntax for --set, " @@ -4892,9 +4892,9 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) int ret; bool ret_val = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -5034,11 +5034,11 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SAVE_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SAVE_PAUSED; if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0) @@ -5144,24 +5144,24 @@ doDump(void *opaque) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) goto out; - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) flags |= VIR_DUMP_LIVE; - if (vshCommandOptBool(cmd, "crash")) + if (vshCommandOptBool(ctl, cmd, "crash")) flags |= VIR_DUMP_CRASH; - if (vshCommandOptBool(cmd, "bypass-cache")) + if (vshCommandOptBool(ctl, cmd, "bypass-cache")) flags |= VIR_DUMP_BYPASS_CACHE; - if (vshCommandOptBool(cmd, "reset")) + if (vshCommandOptBool(ctl, cmd, "reset")) flags |= VIR_DUMP_RESET; - if (vshCommandOptBool(cmd, "memory-only")) + if (vshCommandOptBool(ctl, cmd, "memory-only")) flags |= VIR_DUMP_MEMORY_ONLY; - if (vshCommandOptBool(cmd, "format")) { + if (vshCommandOptBool(ctl, cmd, "format")) { if (!(flags & VIR_DUMP_MEMORY_ONLY)) { vshError(ctl, "%s", _("--format only works with --memory-only")); goto out; } - if (vshCommandOptString(cmd, "format", &format)) { + if (vshCommandOptString(ctl, cmd, "format", &format)) { if (STREQ(format, "kdump-zlib")) { dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB; } else if (STREQ(format, "kdump-lzo")) { @@ -5218,7 +5218,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "verbose")) + if (vshCommandOptBool(ctl, cmd, "verbose")) verbose = true; if (pipe(p) < 0) @@ -5330,7 +5330,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", (const char **) &file) < 0) return false; - if (vshCommandOptUInt(cmd, "screen", &screen) < 0) { + if (vshCommandOptUInt(ctl, cmd, "screen", &screen) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "screen"); @@ -5715,7 +5715,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptBool(cmd, "completed")) + if (vshCommandOptBool(ctl, cmd, "completed")) flags |= VIR_DOMAIN_JOB_STATS_COMPLETED; memset(&info, 0, sizeof(info)); @@ -6119,12 +6119,12 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; bool ret = false; - bool maximum = vshCommandOptBool(cmd, "maximum"); - bool active = vshCommandOptBool(cmd, "active"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); - bool guest = vshCommandOptBool(cmd, "guest"); + bool maximum = vshCommandOptBool(ctl, cmd, "maximum"); + bool active = vshCommandOptBool(ctl, cmd, "active"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool guest = vshCommandOptBool(ctl, cmd, "guest"); bool all = maximum + active + current + config + live + guest == 0; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -6226,7 +6226,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd) int ncpus, maxcpu; size_t cpumaplen; bool ret = false; - bool pretty = vshCommandOptBool(cmd, "pretty"); + bool pretty = vshCommandOptBool(ctl, cmd, "pretty"); int n, m; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -6406,9 +6406,9 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) int cpumaplen; int maxcpu, ncpus; size_t i; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); int got_vcpu; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -6429,7 +6429,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) if (!cpulist) VSH_EXCLUSIVE_OPTIONS_VAR(live, config); - if ((got_vcpu = vshCommandOptUInt(cmd, "vcpu", &vcpu)) < 0) { + if ((got_vcpu = vshCommandOptUInt(ctl, cmd, "vcpu", &vcpu)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "vcpu"); @@ -6552,9 +6552,9 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) unsigned char *cpumap = NULL; int cpumaplen; int maxcpu; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); bool query = false; /* Query mode if no cpulist */ unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -6673,11 +6673,11 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; int count = 0; bool ret = false; - bool maximum = vshCommandOptBool(cmd, "maximum"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); - bool guest = vshCommandOptBool(cmd, "guest"); + bool maximum = vshCommandOptBool(ctl, cmd, "maximum"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool guest = vshCommandOptBool(ctl, cmd, "guest"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -6698,7 +6698,7 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(cmd, "count", &count) < 0 || count <= 0) { + if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <= 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "count"); @@ -6758,9 +6758,9 @@ static bool cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); int niothreads = 0; virDomainIOThreadInfoPtr *info; size_t i; @@ -6857,9 +6857,9 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; const char *cpulist = NULL; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int iothread_id = 0; int maxcpu; bool ret = false; @@ -6878,14 +6878,14 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptUInt(cmd, "iothread", &iothread_id) < 0) { + if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "iothread"); goto cleanup; } - if (vshCommandOptString(cmd, "cpulist", &cpulist) < 0) { + if (vshCommandOptString(ctl, cmd, "cpulist", &cpulist) < 0) { vshError(ctl, "%s", _("iothreadpin: invalid cpulist.")); goto cleanup; } @@ -6953,9 +6953,9 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; int iothread_id = 0; bool ret = false; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -6969,7 +6969,7 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(cmd, "id", &iothread_id) < 0) { + if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "id"); @@ -7035,9 +7035,9 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; int iothread_id = 0; bool ret = false; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -7051,7 +7051,7 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(cmd, "id", &iothread_id) < 0) { + if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "id"); @@ -7111,7 +7111,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) xmlXPathContextPtr ctxt = NULL; xmlNodePtr node; - if (vshCommandOptBool(cmd, "error")) + if (vshCommandOptBool(ctl, cmd, "error")) flags |= VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -7220,9 +7220,9 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; - if (vshCommandOptBool(cmd, "features")) + if (vshCommandOptBool(ctl, cmd, "features")) flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES; - if (vshCommandOptBool(cmd, "migratable")) + if (vshCommandOptBool(ctl, cmd, "migratable")) flags |= VIR_CONNECT_BASELINE_CPU_MIGRATABLE; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -7338,9 +7338,9 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - show_total = vshCommandOptBool(cmd, "total"); + show_total = vshCommandOptBool(ctl, cmd, "total"); - if ((rv = vshCommandOptInt(cmd, "start", &cpu)) < 0) { + if ((rv = vshCommandOptInt(ctl, cmd, "start", &cpu)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "start"); @@ -7353,7 +7353,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) show_per_cpu = true; } - if ((rv = vshCommandOptInt(cmd, "count", &show_count)) < 0) { + if ((rv = vshCommandOptInt(ctl, cmd, "count", &show_count)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "count"); @@ -7536,7 +7536,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) bool ret = false; char *buffer; #ifndef WIN32 - bool console = vshCommandOptBool(cmd, "console"); + bool console = vshCommandOptBool(ctl, cmd, "console"); #endif unsigned int flags = 0; size_t nfds = 0; @@ -7551,11 +7551,11 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_START_PAUSED; - if (vshCommandOptBool(cmd, "autodestroy")) + if (vshCommandOptBool(ctl, cmd, "autodestroy")) flags |= VIR_DOMAIN_START_AUTODESTROY; - if (vshCommandOptBool(cmd, "validate")) + if (vshCommandOptBool(ctl, cmd, "validate")) flags |= VIR_DOMAIN_START_VALIDATE; if (nfds) @@ -7621,7 +7621,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; - if (vshCommandOptBool(cmd, "validate")) + if (vshCommandOptBool(ctl, cmd, "validate")) flags |= VIR_DOMAIN_DEFINE_VALIDATE; if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) @@ -7682,7 +7682,7 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - if (vshCommandOptBool(cmd, "graceful")) + if (vshCommandOptBool(ctl, cmd, "graceful")) flags |= VIR_DOMAIN_DESTROY_GRACEFUL; if (flags) @@ -7751,12 +7751,12 @@ static bool cmdDesc(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); - bool title = vshCommandOptBool(cmd, "title"); - bool edit = vshCommandOptBool(cmd, "edit"); + bool title = vshCommandOptBool(ctl, cmd, "title"); + bool edit = vshCommandOptBool(ctl, cmd, "edit"); int state; int type; @@ -7784,7 +7784,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) if ((state = vshDomainState(ctl, dom, NULL)) < 0) goto cleanup; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (pad) virBufferAddChar(&buf, ' '); pad = true; @@ -7959,11 +7959,11 @@ static bool cmdMetadata(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); - bool edit = vshCommandOptBool(cmd, "edit"); - bool rem = vshCommandOptBool(cmd, "remove"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool edit = vshCommandOptBool(ctl, cmd, "edit"); + bool rem = vshCommandOptBool(ctl, cmd, "remove"); const char *set = NULL; const char *uri = NULL; const char *key = NULL; @@ -8140,10 +8140,10 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptString(cmd, "codeset", &codeset_option) <= 0) + if (vshCommandOptString(ctl, cmd, "codeset", &codeset_option) <= 0) codeset_option = "linux"; - if (vshCommandOptUInt(cmd, "holdtime", &holdtime) < 0) { + if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "holdtime"); @@ -8156,7 +8156,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (count == VIR_DOMAIN_SEND_KEY_MAX_KEYS) { vshError(ctl, _("too many keycodes")); goto cleanup; @@ -8269,7 +8269,7 @@ cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptLongLong(cmd, "pid", &pid_value) < 0) { + if (vshCommandOptLongLong(ctl, cmd, "pid", &pid_value) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "pid"); @@ -8345,9 +8345,9 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) unsigned long long max; unsigned long kibibytes = 0; bool ret = true; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -8370,7 +8370,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) max = 1024ull * ULONG_MAX; else max = ULONG_MAX; - if (vshCommandOptScaledInt(cmd, "size", &bytes, 1024, max) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "size"); @@ -8442,9 +8442,9 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) unsigned long long max; unsigned long kibibytes = 0; bool ret = true; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT | VIR_DOMAIN_MEM_MAXIMUM; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -8467,7 +8467,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) max = 1024ull * ULONG_MAX; else max = ULONG_MAX; - if (vshCommandOptScaledInt(cmd, "size", &bytes, 1024, max) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "size"); @@ -8562,14 +8562,14 @@ static const vshCmdOptDef opts_memtune[] = { * <0 in all other cases */ static int -vshMemtuneGetSize(const vshCmd *cmd, const char *name, long long *value) +vshMemtuneGetSize(vshControl *ctl, const vshCmd *cmd, const char *name, long long *value) { int ret; unsigned long long tmp; const char *str; char *end; - ret = vshCommandOptString(cmd, name, &str); + ret = vshCommandOptString(ctl, cmd, name, &str); if (ret <= 0) return ret; if (virStrToLong_ll(str, &end, 10, value) < 0) @@ -8597,9 +8597,9 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd) virTypedParameterPtr params = NULL; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -8613,7 +8613,7 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd) return false; #define PARSE_MEMTUNE_PARAM(NAME, FIELD) \ - if ((rc = vshMemtuneGetSize(cmd, NAME, &tmpVal)) < 0) { \ + if ((rc = vshMemtuneGetSize(ctl, cmd, NAME, &tmpVal)) < 0) { \ vshError(ctl, _("Unable to parse integer parameter %s"), NAME); \ goto cleanup; \ } \ @@ -8738,9 +8738,9 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd) const char *nodeset = NULL; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); const char *mode = NULL; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -8884,7 +8884,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) if (dom == NULL) goto cleanup; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (pad) virBufferAddChar(&buf, ' '); pad = true; @@ -8896,8 +8896,8 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) } monitor_cmd = virBufferContentAndReset(&buf); - if (vshCommandOptBool(cmd, "hmp")) { - if (vshCommandOptBool(cmd, "pretty")) { + if (vshCommandOptBool(ctl, cmd, "hmp")) { + if (vshCommandOptBool(ctl, cmd, "pretty")) { vshError(ctl, _("--hmp and --pretty are not compatible")); goto cleanup; } @@ -8907,7 +8907,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "pretty")) { + if (vshCommandOptBool(ctl, cmd, "pretty")) { char *tmp; pretty = virJSONValueFromString(result); if (pretty && (tmp = virJSONValueToString(pretty, true))) { @@ -9021,21 +9021,21 @@ cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cmd) const char *event = NULL; vshQemuEventData data; - if (vshCommandOptBool(cmd, "regex")) + if (vshCommandOptBool(ctl, cmd, "regex")) flags |= VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX; - if (vshCommandOptBool(cmd, "no-case")) + if (vshCommandOptBool(ctl, cmd, "no-case")) flags |= VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE; data.ctl = ctl; - data.loop = vshCommandOptBool(cmd, "loop"); - data.pretty = vshCommandOptBool(cmd, "pretty"); + data.loop = vshCommandOptBool(ctl, cmd, "loop"); + data.pretty = vshCommandOptBool(ctl, cmd, "pretty"); data.count = 0; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; - if (vshCommandOptString(cmd, "event", &event) < 0) + if (vshCommandOptString(ctl, cmd, "event", &event) < 0) return false; - if (vshCommandOptBool(cmd, "domain")) + if (vshCommandOptBool(ctl, cmd, "domain")) dom = vshCommandOptDomain(ctl, cmd, NULL); if (vshEventStart(ctl, timeout) < 0) goto cleanup; @@ -9103,7 +9103,7 @@ cmdQemuAttach(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; unsigned int pid_value; /* API uses unsigned int, not pid_t */ - if (vshCommandOptUInt(cmd, "pid", &pid_value) <= 0) { + if (vshCommandOptUInt(ctl, cmd, "pid", &pid_value) <= 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "pid"); @@ -9187,7 +9187,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) if (dom == NULL) goto cleanup; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (pad) virBufferAddChar(&buf, ' '); pad = true; @@ -9199,7 +9199,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) } guest_agent_cmd = virBufferContentAndReset(&buf); - judge = vshCommandOptInt(cmd, "timeout", &timeout); + judge = vshCommandOptInt(ctl, cmd, "timeout", &timeout); if (judge < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), @@ -9213,11 +9213,11 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptBool(cmd, "async")) { + if (vshCommandOptBool(ctl, cmd, "async")) { timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT; judge++; } - if (vshCommandOptBool(cmd, "block")) { + if (vshCommandOptBool(ctl, cmd, "block")) { timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK; judge++; } @@ -9231,7 +9231,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) if (!result) goto cleanup; - if (vshCommandOptBool(cmd, "pretty")) { + if (vshCommandOptBool(ctl, cmd, "pretty")) { char *tmp; pretty = virJSONValueFromString(result); if (pretty && (tmp = virJSONValueToString(pretty, true))) { @@ -9306,10 +9306,10 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) if (dom == NULL) goto cleanup; - if (vshCommandOptBool(cmd, "noseclabel")) + if (vshCommandOptBool(ctl, cmd, "noseclabel")) setlabel = false; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (VIR_EXPAND_N(cmdargv, ncmdargv, 1) < 0) { vshError(ctl, _("%s: %d: failed to allocate argv"), __FILE__, __LINE__); @@ -9442,10 +9442,10 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) bool ret = true; char *dump; unsigned int flags = 0; - bool inactive = vshCommandOptBool(cmd, "inactive"); - bool secure = vshCommandOptBool(cmd, "security-info"); - bool update = vshCommandOptBool(cmd, "update-cpu"); - bool migratable = vshCommandOptBool(cmd, "migratable"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); + bool secure = vshCommandOptBool(ctl, cmd, "security-info"); + bool update = vshCommandOptBool(ctl, cmd, "update-cpu"); + bool migratable = vshCommandOptBool(ctl, cmd, "migratable"); if (inactive) flags |= VIR_DOMAIN_XML_INACTIVE; @@ -9898,49 +9898,49 @@ doMigrate(void *opaque) VIR_FREE(xml); } - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) flags |= VIR_MIGRATE_LIVE; - if (vshCommandOptBool(cmd, "p2p")) + if (vshCommandOptBool(ctl, cmd, "p2p")) flags |= VIR_MIGRATE_PEER2PEER; - if (vshCommandOptBool(cmd, "tunnelled")) + if (vshCommandOptBool(ctl, cmd, "tunnelled")) flags |= VIR_MIGRATE_TUNNELLED; - if (vshCommandOptBool(cmd, "persistent")) + if (vshCommandOptBool(ctl, cmd, "persistent")) flags |= VIR_MIGRATE_PERSIST_DEST; - if (vshCommandOptBool(cmd, "undefinesource")) + if (vshCommandOptBool(ctl, cmd, "undefinesource")) flags |= VIR_MIGRATE_UNDEFINE_SOURCE; - if (vshCommandOptBool(cmd, "suspend")) + if (vshCommandOptBool(ctl, cmd, "suspend")) flags |= VIR_MIGRATE_PAUSED; - if (vshCommandOptBool(cmd, "copy-storage-all")) + if (vshCommandOptBool(ctl, cmd, "copy-storage-all")) flags |= VIR_MIGRATE_NON_SHARED_DISK; - if (vshCommandOptBool(cmd, "copy-storage-inc")) + if (vshCommandOptBool(ctl, cmd, "copy-storage-inc")) flags |= VIR_MIGRATE_NON_SHARED_INC; - if (vshCommandOptBool(cmd, "change-protection")) + if (vshCommandOptBool(ctl, cmd, "change-protection")) flags |= VIR_MIGRATE_CHANGE_PROTECTION; - if (vshCommandOptBool(cmd, "unsafe")) + if (vshCommandOptBool(ctl, cmd, "unsafe")) flags |= VIR_MIGRATE_UNSAFE; - if (vshCommandOptBool(cmd, "compressed")) + if (vshCommandOptBool(ctl, cmd, "compressed")) flags |= VIR_MIGRATE_COMPRESSED; - if (vshCommandOptBool(cmd, "auto-converge")) + if (vshCommandOptBool(ctl, cmd, "auto-converge")) flags |= VIR_MIGRATE_AUTO_CONVERGE; - if (vshCommandOptBool(cmd, "rdma-pin-all")) + if (vshCommandOptBool(ctl, cmd, "rdma-pin-all")) flags |= VIR_MIGRATE_RDMA_PIN_ALL; - if (vshCommandOptBool(cmd, "offline")) + if (vshCommandOptBool(ctl, cmd, "offline")) flags |= VIR_MIGRATE_OFFLINE; - if (vshCommandOptBool(cmd, "abort-on-error")) + if (vshCommandOptBool(ctl, cmd, "abort-on-error")) flags |= VIR_MIGRATE_ABORT_ON_ERROR; - if (flags & VIR_MIGRATE_PEER2PEER || vshCommandOptBool(cmd, "direct")) { + if (flags & VIR_MIGRATE_PEER2PEER || vshCommandOptBool(ctl, cmd, "direct")) { if (virDomainMigrateToURI3(dom, desturi, params, nparams, flags) == 0) ret = '0'; } else { @@ -9992,10 +9992,10 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptBool(cmd, "verbose")) + if (vshCommandOptBool(ctl, cmd, "verbose")) verbose = true; - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) live_flag = true; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) { goto cleanup; @@ -10012,7 +10012,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) data.cmd = cmd; data.writefd = p[1]; - if (vshCommandOptBool(cmd, "p2p") || vshCommandOptBool(cmd, "direct")) { + if (vshCommandOptBool(ctl, cmd, "p2p") || vshCommandOptBool(ctl, cmd, "direct")) { data.dconn = NULL; } else { /* For traditional live migration, connect to the destination host. */ @@ -10085,7 +10085,7 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptLongLong(cmd, "downtime", &downtime) < 0) { + if (vshCommandOptLongLong(ctl, cmd, "downtime", &downtime) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "downtime"); @@ -10147,7 +10147,7 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - rc = vshCommandOptULongLong(cmd, "size", &size); + rc = vshCommandOptULongLong(ctl, cmd, "size", &size); if (rc < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), @@ -10208,7 +10208,7 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) { + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "bandwidth"); @@ -10332,7 +10332,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptBool(cmd, "include-password")) + if (vshCommandOptBool(ctl, cmd, "include-password")) flags |= VIR_DOMAIN_XML_SECURE; if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) @@ -10852,10 +10852,10 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) char *buffer = NULL; int ret; bool funcRet = false; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -10957,10 +10957,10 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) char *buffer = NULL; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -10987,7 +10987,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptBool(cmd, "force")) + if (vshCommandOptBool(ctl, cmd, "force")) flags |= VIR_DOMAIN_DEVICE_MODIFY_FORCE; if (virDomainUpdateDeviceFlags(dom, buffer, flags) < 0) { @@ -11068,10 +11068,10 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd) int ret; bool functionReturn = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -11431,10 +11431,10 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) int ret; bool functionReturn = false; xmlNodePtr disk_node = NULL; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool persistent = vshCommandOptBool(cmd, "persistent"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); @@ -11533,7 +11533,7 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd) if (dom == NULL) goto cleanup; - if (vshCommandOptBool(cmd, "skip-validate")) + if (vshCommandOptBool(ctl, cmd, "skip-validate")) define_flags &= ~VIR_DOMAIN_DEFINE_VALIDATE; #define EDIT_GET_XML virDomainGetXMLDesc(dom, query_flags) @@ -12239,17 +12239,17 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) size_t i; const char *eventName = NULL; int event = -1; - bool all = vshCommandOptBool(cmd, "all"); - bool loop = vshCommandOptBool(cmd, "loop"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool loop = vshCommandOptBool(ctl, cmd, "loop"); int count = 0; - if (vshCommandOptBool(cmd, "list")) { + if (vshCommandOptBool(ctl, cmd, "list")) { for (event = 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) vshPrint(ctl, "%s\n", vshEventCallbacks[event].name); return true; } - if (vshCommandOptString(cmd, "event", &eventName) < 0) + if (vshCommandOptString(ctl, cmd, "event", &eventName) < 0) return false; if (eventName) { for (event = 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) @@ -12279,7 +12279,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) if (VIR_ALLOC_N(data, 1) < 0) goto cleanup; data[0].ctl = ctl; - data[0].loop = vshCommandOptBool(cmd, "loop"); + data[0].loop = vshCommandOptBool(ctl, cmd, "loop"); data[0].count = &count; data[0].cb = &vshEventCallbacks[event]; data[0].id = -1; @@ -12287,7 +12287,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "domain")) + if (vshCommandOptBool(ctl, cmd, "domain")) dom = vshCommandOptDomain(ctl, cmd, NULL); if (vshEventStart(ctl, timeout) < 0) goto cleanup; @@ -12421,14 +12421,14 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) vshUpdateDiskXMLType update_type; const char *action = NULL; const char *success_msg = NULL; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); - bool force = vshCommandOptBool(cmd, "force"); - bool eject = vshCommandOptBool(cmd, "eject"); - bool insert = vshCommandOptBool(cmd, "insert"); - bool update = vshCommandOptBool(cmd, "update"); - bool block = vshCommandOptBool(cmd, "block"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool force = vshCommandOptBool(ctl, cmd, "force"); + bool eject = vshCommandOptBool(ctl, cmd, "eject"); + bool insert = vshCommandOptBool(ctl, cmd, "insert"); + bool update = vshCommandOptBool(ctl, cmd, "update"); + bool block = vshCommandOptBool(ctl, cmd, "block"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(eject, insert); @@ -12488,7 +12488,7 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) update_type))) goto cleanup; - if (vshCommandOptBool(cmd, "print-xml")) { + if (vshCommandOptBool(ctl, cmd, "print-xml")) { vshPrint(ctl, "%s", disk_xml); } else { if (virDomainUpdateDeviceFlags(dom, disk_xml, flags) != 0) { @@ -12548,7 +12548,7 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return ret; - if (vshCommandOptULongLong(cmd, "minimum", &minimum) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "minimum"); @@ -12604,7 +12604,7 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (VIR_EXPAND_N(mountpoints, nmountpoints, 1) < 0) { vshError(ctl, _("%s: %d: failed to allocate mountpoints"), __FILE__, __LINE__); @@ -12661,7 +12661,7 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (VIR_EXPAND_N(mountpoints, nmountpoints, 1) < 0) { vshError(ctl, _("%s: %d: failed to allocate mountpoints"), __FILE__, __LINE__); diff --git a/tools/virsh-host.c b/tools/virsh-host.c index a72fd05..aa37aa6 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -167,8 +167,8 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) unsigned long nodes_cnt; unsigned long *nodes_id = NULL; unsigned long long *nodes_free = NULL; - bool all = vshCommandOptBool(cmd, "all"); - bool cellno = vshCommandOptBool(cmd, "cellno"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool cellno = vshCommandOptBool(ctl, cmd, "cellno"); size_t i; char *cap_xml = NULL; xmlDocPtr xml = NULL; @@ -176,7 +176,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (cellno && vshCommandOptInt(cmd, "cellno", &cell) < 0) { + if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cellno"); @@ -305,13 +305,13 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) char *cap_xml = NULL; xmlDocPtr doc = NULL; xmlXPathContextPtr ctxt = NULL; - bool all = vshCommandOptBool(cmd, "all"); - bool cellno = vshCommandOptBool(cmd, "cellno"); - bool pagesz = vshCommandOptBool(cmd, "pagesize"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool cellno = vshCommandOptBool(ctl, cmd, "cellno"); + bool pagesz = vshCommandOptBool(ctl, cmd, "pagesize"); VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (vshCommandOptScaledInt(cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "pagesize"); @@ -391,7 +391,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptInt(cmd, "cellno", &cell) < 0) { + if (vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cellno"); @@ -475,9 +475,9 @@ static bool cmdAllocpages(vshControl *ctl, const vshCmd *cmd) { bool ret = false; - bool add = vshCommandOptBool(cmd, "add"); - bool all = vshCommandOptBool(cmd, "all"); - bool cellno = vshCommandOptBool(cmd, "cellno"); + bool add = vshCommandOptBool(ctl, cmd, "add"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool cellno = vshCommandOptBool(ctl, cmd, "cellno"); int startCell = -1; int cellCount = 1; unsigned int pageSizes[1]; @@ -490,14 +490,14 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (cellno && vshCommandOptInt(cmd, "cellno", &startCell) < 0) { + if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &startCell) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cellno"); return false; } - if (vshCommandOptScaledInt(cmd, "pagesize", &tmp, 1024, UINT_MAX) < 0) { + if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cellno"); @@ -505,7 +505,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) } pageSizes[0] = VIR_DIV_UP(tmp, 1024); - if (vshCommandOptULongLong(cmd, "pagecount", &pageCounts[0]) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "pagecount", &pageCounts[0]) < 0) { vshError(ctl, "%s", _("pagecount has to be a number")); return false; } @@ -666,7 +666,7 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) int cpu, cpunum; unsigned char *cpumap = NULL; unsigned int online; - bool pretty = vshCommandOptBool(cmd, "pretty"); + bool pretty = vshCommandOptBool(ctl, cmd, "pretty"); bool ret = false; cpunum = virNodeGetCPUMap(ctl->conn, &cpumap, &online, 0); @@ -756,7 +756,7 @@ static bool cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) { size_t i, j; - bool flag_percent = vshCommandOptBool(cmd, "percent"); + bool flag_percent = vshCommandOptBool(ctl, cmd, "percent"); int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS; virNodeCPUStatsPtr params; int nparams = 0; @@ -764,7 +764,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) unsigned long long cpu_stats[VSH_CPU_LAST] = { 0 }; bool present[VSH_CPU_LAST] = { false }; - if (vshCommandOptInt(cmd, "cpu", &cpuNum) < 0) { + if (vshCommandOptInt(ctl, cmd, "cpu", &cpuNum) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cpu"); @@ -875,7 +875,7 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) virNodeMemoryStatsPtr params = NULL; bool ret = false; - if (vshCommandOptInt(cmd, "cell", &cellNum) < 0) { + if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "cell"); @@ -951,7 +951,7 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) return false; - if (vshCommandOptLongLong(cmd, "duration", &duration) < 0) { + if (vshCommandOptLongLong(ctl, cmd, "duration", &duration) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "duration"); @@ -1205,7 +1205,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) hvType, major, minor, rel); } - if (vshCommandOptBool(cmd, "daemon")) { + if (vshCommandOptBool(ctl, cmd, "daemon")) { ret = virConnectGetLibVersion(ctl->conn, &daemonVersion); if (ret < 0) { vshError(ctl, "%s", _("failed to get the daemon version")); @@ -1260,7 +1260,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) int rc = -1; size_t i; - if ((rc = vshCommandOptUInt(cmd, "shm-pages-to-scan", &value)) < 0) { + if ((rc = vshCommandOptUInt(ctl, cmd, "shm-pages-to-scan", &value)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "shm-pages-to-scan"); @@ -1272,7 +1272,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rc = vshCommandOptUInt(cmd, "shm-sleep-millisecs", &value)) < 0) { + if ((rc = vshCommandOptUInt(ctl, cmd, "shm-sleep-millisecs", &value)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "shm-sleep-millisecs"); @@ -1284,7 +1284,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if ((rc = vshCommandOptUInt(cmd, "shm-merge-across-nodes", &value)) < 0) { + if ((rc = vshCommandOptUInt(ctl, cmd, "shm-merge-across-nodes", &value)) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "shm-merge-across-nodes"); diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 7122bc5..0f8ea95 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -343,8 +343,8 @@ static const vshCmdOptDef opts_interface_list[] = { static bool cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) { - bool inactive = vshCommandOptBool(cmd, "inactive"); - bool all = vshCommandOptBool(cmd, "all"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); + bool all = vshCommandOptBool(ctl, cmd, "all"); unsigned int flags = VIR_CONNECT_LIST_INTERFACES_ACTIVE; vshInterfaceListPtr list = NULL; size_t i; @@ -480,7 +480,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd) bool ret = true; char *dump; unsigned int flags = 0; - bool inactive = vshCommandOptBool(cmd, "inactive"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); if (inactive) flags |= VIR_INTERFACE_XML_INACTIVE; @@ -841,16 +841,16 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) } /* use "no-stp" because we want "stp" to default true */ - stp = !vshCommandOptBool(cmd, "no-stp"); + stp = !vshCommandOptBool(ctl, cmd, "no-stp"); - if (vshCommandOptUInt(cmd, "delay", &delay) < 0) { + if (vshCommandOptUInt(ctl, cmd, "delay", &delay) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "delay"); goto cleanup; } - nostart = vshCommandOptBool(cmd, "no-start"); + nostart = vshCommandOptBool(ctl, cmd, "no-start"); /* Get the original interface into an xmlDoc */ if (!(if_xml = virInterfaceGetXMLDesc(if_handle, VIR_INTERFACE_XML_INACTIVE))) @@ -1054,7 +1054,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - nostart = vshCommandOptBool(cmd, "no-start"); + nostart = vshCommandOptBool(ctl, cmd, "no-start"); /* Get the bridge xml into an xmlDoc */ if (!(br_xml = virInterfaceGetXMLDesc(br_handle, VIR_INTERFACE_XML_INACTIVE))) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index a45367a..8a52834 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -106,7 +106,7 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd) if (!(network = vshCommandOptNetwork(ctl, cmd, &name))) return false; - autostart = !vshCommandOptBool(cmd, "disable"); + autostart = !vshCommandOptBool(ctl, cmd, "disable"); if (virNetworkSetAutostart(network, autostart) < 0) { if (autostart) @@ -308,7 +308,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd) if (!(network = vshCommandOptNetwork(ctl, cmd, NULL))) return false; - inactive = vshCommandOptBool(cmd, "inactive"); + inactive = vshCommandOptBool(ctl, cmd, "inactive"); if (inactive) flags |= VIR_NETWORK_XML_INACTIVE; @@ -652,12 +652,12 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) { vshNetworkListPtr list = NULL; size_t i; - bool inactive = vshCommandOptBool(cmd, "inactive"); - bool all = vshCommandOptBool(cmd, "all"); - bool persistent = vshCommandOptBool(cmd, "persistent"); - bool transient = vshCommandOptBool(cmd, "transient"); - bool autostart = vshCommandOptBool(cmd, "autostart"); - bool no_autostart = vshCommandOptBool(cmd, "no-autostart"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); + bool all = vshCommandOptBool(ctl, cmd, "all"); + bool persistent = vshCommandOptBool(ctl, cmd, "persistent"); + bool transient = vshCommandOptBool(ctl, cmd, "transient"); + bool autostart = vshCommandOptBool(ctl, cmd, "autostart"); + bool no_autostart = vshCommandOptBool(ctl, cmd, "no-autostart"); unsigned int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; if (inactive) @@ -904,9 +904,9 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) int command, section, parentIndex = -1; const char *xml = NULL; char *xmlFromFile = NULL; - bool current = vshCommandOptBool(cmd, "current"); - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config"); + bool live = vshCommandOptBool(ctl, cmd, "live"); unsigned int flags = 0; const char *affected; @@ -936,7 +936,7 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptInt(cmd, "parent-index", &parentIndex) < 0) { + if (vshCommandOptInt(ctl, cmd, "parent-index", &parentIndex) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "parent-index"); @@ -1219,7 +1219,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) const char *eventName = NULL; int event; - if (vshCommandOptBool(cmd, "list")) { + if (vshCommandOptBool(ctl, cmd, "list")) { size_t i; for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) @@ -1227,7 +1227,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) return true; } - if (vshCommandOptString(cmd, "event", &eventName) < 0) + if (vshCommandOptString(ctl, cmd, "event", &eventName) < 0) return false; if (!eventName) { vshError(ctl, "%s", _("either --list or event type is required")); @@ -1239,12 +1239,12 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) } data.ctl = ctl; - data.loop = vshCommandOptBool(cmd, "loop"); + data.loop = vshCommandOptBool(ctl, cmd, "loop"); data.count = 0; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; - if (vshCommandOptBool(cmd, "network")) + if (vshCommandOptBool(ctl, cmd, "network")) net = vshCommandOptNetwork(ctl, cmd, NULL); if (vshEventStart(ctl, timeout) < 0) goto cleanup; @@ -1337,7 +1337,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; virNetworkPtr network = NULL; - if (vshCommandOptString(cmd, "mac", &mac) < 0) + if (vshCommandOptString(ctl, cmd, "mac", &mac) < 0) return false; if (!(network = vshCommandOptNetwork(ctl, cmd, &name))) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 0d7315c..c748c15 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -387,7 +387,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) { const char *cap_str = NULL; size_t i; - bool tree = vshCommandOptBool(cmd, "tree"); + bool tree = vshCommandOptBool(ctl, cmd, "tree"); bool ret = true; unsigned int flags = 0; char **caps = NULL; @@ -395,7 +395,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) vshNodeDeviceListPtr list = NULL; int cap_type = -1; - ignore_value(vshCommandOptString(cmd, "cap", &cap_str)); + ignore_value(vshCommandOptString(ctl, cmd, "cap", &cap_str)); if (cap_str) { if (tree) { @@ -610,7 +610,7 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) return false; - ignore_value(vshCommandOptString(cmd, "driver", &driverName)); + ignore_value(vshCommandOptString(ctl, cmd, "driver", &driverName)); if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { vshError(ctl, _("Could not find matching device '%s'"), name); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 4865831..98c3359 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -105,7 +105,7 @@ cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name))) return false; - autostart = !vshCommandOptBool(cmd, "disable"); + autostart = !vshCommandOptBool(ctl, cmd, "disable"); if (virStoragePoolSetAutostart(pool, autostart) < 0) { if (autostart) @@ -363,7 +363,7 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; const char *name; char *xml; - bool printXML = vshCommandOptBool(cmd, "print-xml"); + bool printXML = vshCommandOptBool(ctl, cmd, "print-xml"); if (!vshBuildPoolXML(ctl, cmd, &name, &xml)) return false; @@ -456,7 +456,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; const char *name; char *xml; - bool printXML = vshCommandOptBool(cmd, "print-xml"); + bool printXML = vshCommandOptBool(ctl, cmd, "print-xml"); if (!vshBuildPoolXML(ctl, cmd, &name, &xml)) return false; @@ -520,10 +520,10 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name))) return false; - if (vshCommandOptBool(cmd, "no-overwrite")) + if (vshCommandOptBool(ctl, cmd, "no-overwrite")) flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE; - if (vshCommandOptBool(cmd, "overwrite")) + if (vshCommandOptBool(ctl, cmd, "overwrite")) flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE; if (virStoragePoolBuild(pool, flags) == 0) { @@ -698,7 +698,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd) { virStoragePoolPtr pool; bool ret = true; - bool inactive = vshCommandOptBool(cmd, "inactive"); + bool inactive = vshCommandOptBool(ctl, cmd, "inactive"); unsigned int flags = 0; char *dump; @@ -1033,12 +1033,12 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE; vshStoragePoolListPtr list = NULL; const char *type = NULL; - bool details = vshCommandOptBool(cmd, "details"); + bool details = vshCommandOptBool(ctl, cmd, "details"); bool inactive, all; char *outputStr = NULL; - inactive = vshCommandOptBool(cmd, "inactive"); - all = vshCommandOptBool(cmd, "all"); + inactive = vshCommandOptBool(ctl, cmd, "inactive"); + all = vshCommandOptBool(ctl, cmd, "all"); if (inactive) flags = VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE; @@ -1047,16 +1047,16 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE | VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE; - if (vshCommandOptBool(cmd, "autostart")) + if (vshCommandOptBool(ctl, cmd, "autostart")) flags |= VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART; - if (vshCommandOptBool(cmd, "no-autostart")) + if (vshCommandOptBool(ctl, cmd, "no-autostart")) flags |= VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART; - if (vshCommandOptBool(cmd, "persistent")) + if (vshCommandOptBool(ctl, cmd, "persistent")) flags |= VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT; - if (vshCommandOptBool(cmd, "transient")) + if (vshCommandOptBool(ctl, cmd, "transient")) flags |= VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT; if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index c6ceabd..7a9134c 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -508,16 +508,16 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) bool ret = false; unsigned int flags = 0; - if (vshCommandOptBool(cmd, "ephemeral")) + if (vshCommandOptBool(ctl, cmd, "ephemeral")) flags |= VIR_CONNECT_LIST_SECRETS_EPHEMERAL; - if (vshCommandOptBool(cmd, "no-ephemeral")) + if (vshCommandOptBool(ctl, cmd, "no-ephemeral")) flags |= VIR_CONNECT_LIST_SECRETS_NO_EPHEMERAL; - if (vshCommandOptBool(cmd, "private")) + if (vshCommandOptBool(ctl, cmd, "private")) flags |= VIR_CONNECT_LIST_SECRETS_PRIVATE; - if (vshCommandOptBool(cmd, "no-private")) + if (vshCommandOptBool(ctl, cmd, "no-private")) flags |= VIR_CONNECT_LIST_SECRETS_NO_PRIVATE; if (!(list = vshSecretListCollect(ctl, flags))) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 459a8a8..b52254d 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -180,23 +180,23 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) char *buffer = NULL; unsigned int flags = 0; - if (vshCommandOptBool(cmd, "redefine")) + if (vshCommandOptBool(ctl, cmd, "redefine")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE; - if (vshCommandOptBool(cmd, "current")) + if (vshCommandOptBool(ctl, cmd, "current")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT; - if (vshCommandOptBool(cmd, "no-metadata")) + if (vshCommandOptBool(ctl, cmd, "no-metadata")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA; - if (vshCommandOptBool(cmd, "halt")) + if (vshCommandOptBool(ctl, cmd, "halt")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT; - if (vshCommandOptBool(cmd, "disk-only")) + if (vshCommandOptBool(ctl, cmd, "disk-only")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY; - if (vshCommandOptBool(cmd, "reuse-external")) + if (vshCommandOptBool(ctl, cmd, "reuse-external")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT; - if (vshCommandOptBool(cmd, "quiesce")) + if (vshCommandOptBool(ctl, cmd, "quiesce")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE; - if (vshCommandOptBool(cmd, "atomic")) + if (vshCommandOptBool(ctl, cmd, "atomic")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC; - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -398,25 +398,25 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; const vshCmdOpt *opt = NULL; - if (vshCommandOptBool(cmd, "no-metadata")) { - if (vshCommandOptBool(cmd, "print-xml")) { + if (vshCommandOptBool(ctl, cmd, "no-metadata")) { + if (vshCommandOptBool(ctl, cmd, "print-xml")) { vshError(ctl, "%s", _("--print-xml is incompatible with --no-metadata")); return false; } flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA; } - if (vshCommandOptBool(cmd, "halt")) + if (vshCommandOptBool(ctl, cmd, "halt")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT; - if (vshCommandOptBool(cmd, "disk-only")) + if (vshCommandOptBool(ctl, cmd, "disk-only")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY; - if (vshCommandOptBool(cmd, "reuse-external")) + if (vshCommandOptBool(ctl, cmd, "reuse-external")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT; - if (vshCommandOptBool(cmd, "quiesce")) + if (vshCommandOptBool(ctl, cmd, "quiesce")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE; - if (vshCommandOptBool(cmd, "atomic")) + if (vshCommandOptBool(ctl, cmd, "atomic")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC; - if (vshCommandOptBool(cmd, "live")) + if (vshCommandOptBool(ctl, cmd, "live")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -437,10 +437,10 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) if (memspec && vshParseSnapshotMemspec(ctl, &buf, memspec) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "diskspec")) { + if (vshCommandOptBool(ctl, cmd, "diskspec")) { virBufferAddLit(&buf, "<disks>\n"); virBufferAdjustIndent(&buf, 2); - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (vshParseSnapshotDiskspec(ctl, &buf, opt->data) < 0) goto cleanup; } @@ -457,7 +457,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) buffer = virBufferContentAndReset(&buf); - if (vshCommandOptBool(cmd, "print-xml")) { + if (vshCommandOptBool(ctl, cmd, "print-xml")) { vshPrint(ctl, "%s\n", buffer); ret = true; goto cleanup; @@ -482,7 +482,7 @@ vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd, const char *arg, bool exclusive, virDomainPtr dom, virDomainSnapshotPtr *snap, const char **name) { - bool current = vshCommandOptBool(cmd, "current"); + bool current = vshCommandOptBool(ctl, cmd, "current"); const char *snapname = NULL; if (vshCommandOptStringReq(ctl, cmd, arg, &snapname) < 0) @@ -559,13 +559,13 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) bool ret = false; unsigned int getxml_flags = VIR_DOMAIN_XML_SECURE; unsigned int define_flags = VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE; - bool rename_okay = vshCommandOptBool(cmd, "rename"); - bool clone_okay = vshCommandOptBool(cmd, "clone"); + bool rename_okay = vshCommandOptBool(ctl, cmd, "rename"); + bool clone_okay = vshCommandOptBool(ctl, cmd, "clone"); VSH_EXCLUSIVE_OPTIONS_EXPR("rename", rename_okay, "clone", clone_okay) - if (vshCommandOptBool(cmd, "current") && - vshCommandOptBool(cmd, "snapshotname")) + if (vshCommandOptBool(ctl, cmd, "current") && + vshCommandOptBool(ctl, cmd, "snapshotname")) define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) @@ -677,7 +677,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; const char *domname; - if (vshCommandOptBool(cmd, "security-info")) + if (vshCommandOptBool(ctl, cmd, "security-info")) flags |= VIR_DOMAIN_XML_SECURE; VSH_EXCLUSIVE_OPTIONS("name", "snapshotname"); @@ -723,7 +723,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) if (!(snapshot = virDomainSnapshotCurrent(dom, 0))) goto cleanup; - if (vshCommandOptBool(cmd, "name")) { + if (vshCommandOptBool(ctl, cmd, "name")) { const char *name; if (!(name = virDomainSnapshotGetName(snapshot))) goto cleanup; @@ -1527,12 +1527,12 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) time_t creation_time_t; char timestr[100]; struct tm time_info; - bool tree = vshCommandOptBool(cmd, "tree"); - bool name = vshCommandOptBool(cmd, "name"); - bool from = vshCommandOptBool(cmd, "from"); - bool parent = vshCommandOptBool(cmd, "parent"); - bool roots = vshCommandOptBool(cmd, "roots"); - bool current = vshCommandOptBool(cmd, "current"); + bool tree = vshCommandOptBool(ctl, cmd, "tree"); + bool name = vshCommandOptBool(ctl, cmd, "name"); + bool from = vshCommandOptBool(ctl, cmd, "from"); + bool parent = vshCommandOptBool(ctl, cmd, "parent"); + bool roots = vshCommandOptBool(ctl, cmd, "roots"); + bool current = vshCommandOptBool(ctl, cmd, "current"); const char *from_snap = NULL; char *parent_snap = NULL; virDomainSnapshotPtr start = NULL; @@ -1547,7 +1547,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) #define FILTER(option, flag) \ do { \ - if (vshCommandOptBool(cmd, option)) { \ + if (vshCommandOptBool(ctl, cmd, option)) { \ if (tree) { \ vshError(ctl, \ _("--%s and --tree are mutually exclusive"), \ @@ -1570,13 +1570,13 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) if (roots) flags |= VIR_DOMAIN_SNAPSHOT_LIST_ROOTS; - if (vshCommandOptBool(cmd, "metadata")) + if (vshCommandOptBool(ctl, cmd, "metadata")) flags |= VIR_DOMAIN_SNAPSHOT_LIST_METADATA; - if (vshCommandOptBool(cmd, "no-metadata")) + if (vshCommandOptBool(ctl, cmd, "no-metadata")) flags |= VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA; - if (vshCommandOptBool(cmd, "descendants")) { + if (vshCommandOptBool(ctl, cmd, "descendants")) { if (!from && !current) { vshError(ctl, "%s", _("--descendants requires either --from or --current")); @@ -1729,7 +1729,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd) char *xml = NULL; unsigned int flags = 0; - if (vshCommandOptBool(cmd, "security-info")) + if (vshCommandOptBool(ctl, cmd, "security-info")) flags |= VIR_DOMAIN_XML_SECURE; if (vshCommandOptStringReq(ctl, cmd, "snapshotname", &name) < 0) @@ -1877,15 +1877,15 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd) bool force = false; int result; - if (vshCommandOptBool(cmd, "running")) + if (vshCommandOptBool(ctl, cmd, "running")) flags |= VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING; - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(ctl, cmd, "paused")) flags |= VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED; /* We want virsh snapshot-revert --force to work even when talking * to older servers that did the unsafe revert by default but * reject the flag, so we probe without the flag, and only use it * when the error says it will make a difference. */ - if (vshCommandOptBool(cmd, "force")) + if (vshCommandOptBool(ctl, cmd, "force")) force = true; dom = vshCommandOptDomain(ctl, cmd, NULL); @@ -1976,11 +1976,11 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd) &snapshot, &name) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "children")) + if (vshCommandOptBool(ctl, cmd, "children")) flags |= VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN; - if (vshCommandOptBool(cmd, "children-only")) + if (vshCommandOptBool(ctl, cmd, "children-only")) flags |= VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY; - if (vshCommandOptBool(cmd, "metadata")) + if (vshCommandOptBool(ctl, cmd, "metadata")) flags |= VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY; /* XXX If we wanted, we could emulate DELETE_CHILDREN_ONLY even on diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 5d6cc6a..07dfd67 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -202,7 +202,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) virBuffer buf = VIR_BUFFER_INITIALIZER; unsigned long flags = 0; - if (vshCommandOptBool(cmd, "prealloc-metadata")) + if (vshCommandOptBool(ctl, cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL))) @@ -219,7 +219,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptString(cmd, "allocation", &allocationStr) > 0 && + if (vshCommandOptString(ctl, cmd, "allocation", &allocationStr) > 0 && vshVolSize(allocationStr, &allocation) < 0) { vshError(ctl, _("Malformed size %s"), allocationStr); goto cleanup; @@ -377,7 +377,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; char *buffer = NULL; - if (vshCommandOptBool(cmd, "prealloc-metadata")) + if (vshCommandOptBool(ctl, cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL))) @@ -463,10 +463,10 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL))) goto cleanup; - if (vshCommandOptBool(cmd, "prealloc-metadata")) + if (vshCommandOptBool(ctl, cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; - if (vshCommandOptBool(cmd, "reflink")) + if (vshCommandOptBool(ctl, cmd, "reflink")) flags |= VIR_STORAGE_VOL_CREATE_REFLINK; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -584,10 +584,10 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) if (!(origvol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) goto cleanup; - if (vshCommandOptBool(cmd, "prealloc-metadata")) + if (vshCommandOptBool(ctl, cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; - if (vshCommandOptBool(cmd, "reflink")) + if (vshCommandOptBool(ctl, cmd, "reflink")) flags |= VIR_STORAGE_VOL_CREATE_REFLINK; origpool = virStoragePoolLookupByVolume(origvol); @@ -693,14 +693,14 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) const char *name = NULL; unsigned long long offset = 0, length = 0; - if (vshCommandOptULongLong(cmd, "offset", &offset) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "offset"); return false; } - if (vshCommandOptULongLongWrap(cmd, "length", &length) < 0) { + if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "length"); @@ -806,14 +806,14 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) unsigned long long offset = 0, length = 0; bool created = false; - if (vshCommandOptULongLong(cmd, "offset", &offset) < 0) { + if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "offset"); return false; } - if (vshCommandOptULongLongWrap(cmd, "length", &length) < 0) { + if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) { vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "length"); @@ -1126,13 +1126,13 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd) bool ret = false; bool delta = false; - if (vshCommandOptBool(cmd, "allocate")) + if (vshCommandOptBool(ctl, cmd, "allocate")) flags |= VIR_STORAGE_VOL_RESIZE_ALLOCATE; - if (vshCommandOptBool(cmd, "delta")) { + if (vshCommandOptBool(ctl, cmd, "delta")) { delta = true; flags |= VIR_STORAGE_VOL_RESIZE_DELTA; } - if (vshCommandOptBool(cmd, "shrink")) + if (vshCommandOptBool(ctl, cmd, "shrink")) flags |= VIR_STORAGE_VOL_RESIZE_SHRINK; if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) @@ -1144,7 +1144,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd) if (*capacityStr == '-') { /* The API always requires a positive value; but we allow a * negative value for convenience. */ - if (delta && vshCommandOptBool(cmd, "shrink")) { + if (delta && vshCommandOptBool(ctl, cmd, "shrink")) { capacityStr++; } else { vshError(ctl, "%s", @@ -1384,7 +1384,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) char *outputStr = NULL; const char *unit; double val; - bool details = vshCommandOptBool(cmd, "details"); + bool details = vshCommandOptBool(ctl, cmd, "details"); size_t i; bool ret = false; int stringLength = 0; @@ -1676,7 +1676,7 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd) } /* Return the requested details of the parent storage pool */ - if (vshCommandOptBool(cmd, "uuid")) { + if (vshCommandOptBool(ctl, cmd, "uuid")) { /* Retrieve and return pool UUID string */ if (virStoragePoolGetUUIDString(pool, &uuid[0]) == 0) vshPrint(ctl, "%s\n", uuid); diff --git a/tools/virsh.c b/tools/virsh.c index 11c2c30..9f44793 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -439,7 +439,7 @@ static const vshCmdOptDef opts_connect[] = { static bool cmdConnect(vshControl *ctl, const vshCmd *cmd) { - bool ro = vshCommandOptBool(cmd, "readonly"); + bool ro = vshCommandOptBool(ctl, cmd, "readonly"); const char *name = NULL; if (ctl->conn) { @@ -607,7 +607,7 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd) { const char *name = NULL; - if (vshCommandOptString(cmd, "command", &name) <= 0) { + if (vshCommandOptString(ctl, cmd, "command", &name) <= 0) { const vshCmdGrp *grp; const vshCmdDef *def; @@ -875,7 +875,7 @@ cmdCd(vshControl *ctl, const vshCmd *cmd) return false; } - if (vshCommandOptString(cmd, "dir", &dir) <= 0) + if (vshCommandOptString(ctl, cmd, "dir", &dir) <= 0) dir = dir_malloced = virGetUserDirectory(); if (!dir) dir = "/"; @@ -973,12 +973,12 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) char *arg; virBuffer buf = VIR_BUFFER_INITIALIZER; - if (vshCommandOptBool(cmd, "shell")) + if (vshCommandOptBool(ctl, cmd, "shell")) shell = true; - if (vshCommandOptBool(cmd, "xml")) + if (vshCommandOptBool(ctl, cmd, "xml")) xml = true; - while ((opt = vshCommandOptArgv(cmd, opt))) { + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { char *str; virBuffer xmlbuf = VIR_BUFFER_INITIALIZER; @@ -1471,7 +1471,8 @@ vshCommandFree(vshCmd *cmd) * issued if a value is returned. */ static int -vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt, +vshCommandOpt(const vshCmd *cmd, + const char *name, vshCmdOpt **opt, bool needData) { vshCmdOpt *candidate = cmd->opts; @@ -1504,6 +1505,7 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt, /** * vshCommandOptInt: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1515,7 +1517,8 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt, * <0 in all other cases (@value untouched) */ int -vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) +vshCommandOptInt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, int *value) { vshCmdOpt *arg; int ret; @@ -1530,9 +1533,8 @@ vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) } static int -vshCommandOptUIntInternal(const vshCmd *cmd, - const char *name, - unsigned int *value, +vshCommandOptUIntInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, unsigned int *value, bool wrap) { vshCmdOpt *arg; @@ -1554,6 +1556,7 @@ vshCommandOptUIntInternal(const vshCmd *cmd, /** * vshCommandOptUInt: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1562,13 +1565,15 @@ vshCommandOptUIntInternal(const vshCmd *cmd, * See vshCommandOptInt() */ int -vshCommandOptUInt(const vshCmd *cmd, const char *name, unsigned int *value) +vshCommandOptUInt(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned int *value) { - return vshCommandOptUIntInternal(cmd, name, value, false); + return vshCommandOptUIntInternal(ctl, cmd, name, value, false); } /** * vshCommandOptUIntWrap: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1577,15 +1582,15 @@ vshCommandOptUInt(const vshCmd *cmd, const char *name, unsigned int *value) * See vshCommandOptInt() */ int -vshCommandOptUIntWrap(const vshCmd *cmd, const char *name, unsigned int *value) +vshCommandOptUIntWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned int *value) { - return vshCommandOptUIntInternal(cmd, name, value, true); + return vshCommandOptUIntInternal(ctl, cmd, name, value, true); } static int -vshCommandOptULInternal(const vshCmd *cmd, - const char *name, - unsigned long *value, +vshCommandOptULInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, unsigned long *value, bool wrap) { vshCmdOpt *arg; @@ -1607,6 +1612,7 @@ vshCommandOptULInternal(const vshCmd *cmd, /* * vshCommandOptUL: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1615,13 +1621,15 @@ vshCommandOptULInternal(const vshCmd *cmd, * See vshCommandOptInt() */ int -vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value) +vshCommandOptUL(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long *value) { - return vshCommandOptULInternal(cmd, name, value, false); + return vshCommandOptULInternal(ctl, cmd, name, value, false); } /** * vshCommandOptULWrap: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1630,13 +1638,15 @@ vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value) * See vshCommandOptInt() */ int -vshCommandOptULWrap(const vshCmd *cmd, const char *name, unsigned long *value) +vshCommandOptULWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long *value) { - return vshCommandOptULInternal(cmd, name, value, true); + return vshCommandOptULInternal(ctl, cmd, name, value, true); } /** * vshCommandOptString: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1648,7 +1658,8 @@ vshCommandOptULWrap(const vshCmd *cmd, const char *name, unsigned long *value) * <0 in all other cases (@value untouched) */ int -vshCommandOptString(const vshCmd *cmd, const char *name, const char **value) +vshCommandOptString(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, const char **value) { vshCmdOpt *arg; int ret; @@ -1677,10 +1688,8 @@ vshCommandOptString(const vshCmd *cmd, const char *name, const char **value) * returned and error message printed. */ int -vshCommandOptStringReq(vshControl *ctl, - const vshCmd *cmd, - const char *name, - const char **value) +vshCommandOptStringReq(vshControl *ctl, const vshCmd *cmd, + const char *name, const char **value) { vshCmdOpt *arg; int ret; @@ -1710,6 +1719,7 @@ vshCommandOptStringReq(vshControl *ctl, /** * vshCommandOptLongLong: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1718,8 +1728,8 @@ vshCommandOptStringReq(vshControl *ctl, * See vshCommandOptInt() */ int -vshCommandOptLongLong(const vshCmd *cmd, const char *name, - long long *value) +vshCommandOptLongLong(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, long long *value) { vshCmdOpt *arg; int ret; @@ -1734,9 +1744,8 @@ vshCommandOptLongLong(const vshCmd *cmd, const char *name, } static int -vshCommandOptULongLongInternal(const vshCmd *cmd, - const char *name, - unsigned long long *value, +vshCommandOptULongLongInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, unsigned long long *value, bool wrap) { vshCmdOpt *arg; @@ -1758,6 +1767,7 @@ vshCommandOptULongLongInternal(const vshCmd *cmd, /** * vshCommandOptULongLong: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1766,14 +1776,15 @@ vshCommandOptULongLongInternal(const vshCmd *cmd, * See vshCommandOptInt() */ int -vshCommandOptULongLong(const vshCmd *cmd, const char *name, - unsigned long long *value) +vshCommandOptULongLong(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value) { - return vshCommandOptULongLongInternal(cmd, name, value, false); + return vshCommandOptULongLongInternal(ctl, cmd, name, value, false); } /** * vshCommandOptULongLongWrap: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1782,14 +1793,15 @@ vshCommandOptULongLong(const vshCmd *cmd, const char *name, * See vshCommandOptInt() */ int -vshCommandOptULongLongWrap(const vshCmd *cmd, const char *name, - unsigned long long *value) +vshCommandOptULongLongWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value) { - return vshCommandOptULongLongInternal(cmd, name, value, true); + return vshCommandOptULongLongInternal(ctl, cmd, name, value, true); } /** * vshCommandOptScaledInt: + * @ctl virsh control structure * @cmd command reference * @name option name * @value result @@ -1800,9 +1812,9 @@ vshCommandOptULongLongWrap(const vshCmd *cmd, const char *name, * See vshCommandOptInt() */ int -vshCommandOptScaledInt(const vshCmd *cmd, const char *name, - unsigned long long *value, int scale, - unsigned long long max) +vshCommandOptScaledInt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name, unsigned long long *value, + int scale, unsigned long long max) { vshCmdOpt *arg; char *end; @@ -1821,6 +1833,7 @@ vshCommandOptScaledInt(const vshCmd *cmd, const char *name, /** * vshCommandOptBool: + * @ctl virsh control structure * @cmd command reference * @name option name * @@ -1830,7 +1843,8 @@ vshCommandOptScaledInt(const vshCmd *cmd, const char *name, * option is present without actually using that data. */ bool -vshCommandOptBool(const vshCmd *cmd, const char *name) +vshCommandOptBool(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const char *name) { vshCmdOpt *dummy; @@ -1839,6 +1853,7 @@ vshCommandOptBool(const vshCmd *cmd, const char *name) /** * vshCommandOptArgv: + * @ctl virsh control structure * @cmd command reference * @opt starting point for the search * @@ -1849,7 +1864,8 @@ vshCommandOptBool(const vshCmd *cmd, const char *name) * list of supported options in CMD->def->opts. */ const vshCmdOpt * -vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt) +vshCommandOptArgv(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, + const vshCmdOpt *opt) { opt = opt ? opt->next : cmd->opts; @@ -1865,9 +1881,10 @@ vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt) * value of the timeout in milliseconds. Return -1 on error, 0 if * no timeout was requested, and 1 if timeout was set. */ int -vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout) +vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, + int *timeout) { - int rv = vshCommandOptInt(cmd, "timeout", timeout); + int rv = vshCommandOptInt(ctl, cmd, "timeout", timeout); if (rv < 0 || (rv > 0 && *timeout < 1)) { vshError(ctl, "%s", _("invalid timeout")); diff --git a/tools/virsh.h b/tools/virsh.h index 32b1c91..ce9c733 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -279,44 +279,47 @@ bool vshCmddefHelp(vshControl *ctl, const char *name); const vshCmdGrp *vshCmdGrpSearch(const char *grpname); bool vshCmdGrpHelp(vshControl *ctl, const char *name); -int vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptUInt(const vshCmd *cmd, const char *name, - unsigned int *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptUIntWrap(const vshCmd *cmd, const char *name, - unsigned int *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptUL(const vshCmd *cmd, const char *name, - unsigned long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptULWrap(const vshCmd *cmd, const char *name, - unsigned long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptString(const vshCmd *cmd, const char *name, - const char **value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptInt(vshControl *ctl, const vshCmd *cmd, + const char *name, int *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptUInt(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned int *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptUIntWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned int *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptUL(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptULWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptString(vshControl *ctl, const vshCmd *cmd, + const char *name, const char **value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; int vshCommandOptStringReq(vshControl *ctl, const vshCmd *cmd, const char *name, const char **value) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptLongLong(const vshCmd *cmd, const char *name, - long long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptULongLong(const vshCmd *cmd, const char *name, - unsigned long long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptULongLongWrap(const vshCmd *cmd, const char *name, - unsigned long long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -int vshCommandOptScaledInt(const vshCmd *cmd, const char *name, - unsigned long long *value, int scale, - unsigned long long max) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -bool vshCommandOptBool(const vshCmd *cmd, const char *name); -const vshCmdOpt *vshCommandOptArgv(const vshCmd *cmd, +int vshCommandOptLongLong(vshControl *ctl, const vshCmd *cmd, + const char *name, long long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptULongLong(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptULongLongWrap(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptScaledInt(vshControl *ctl, const vshCmd *cmd, + const char *name, unsigned long long *value, + int scale, unsigned long long max) + ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK; +bool vshCommandOptBool(vshControl *ctl, const vshCmd *cmd, + const char *name); +const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd, const vshCmdOpt *opt); -int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout); +int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, + int *timeout); /* Filter flags for various vshCommandOpt*By() functions */ typedef enum { @@ -452,8 +455,8 @@ char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, * before anything that would require cleanup. */ # define VSH_EXCLUSIVE_OPTIONS(NAME1, NAME2) \ - VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, vshCommandOptBool(cmd, NAME1), \ - NAME2, vshCommandOptBool(cmd, NAME2)) + VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, vshCommandOptBool(ctl, cmd, NAME1), \ + NAME2, vshCommandOptBool(ctl, cmd, NAME2)) /* VSH_EXCLUSIVE_OPTIONS_VAR: * @@ -505,8 +508,8 @@ char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, * before anything that would require cleanup. */ # define VSH_REQUIRE_OPTION(NAME1, NAME2) \ - VSH_REQUIRE_OPTION_EXPR(NAME1, vshCommandOptBool(cmd, NAME1), \ - NAME2, vshCommandOptBool(cmd, NAME2)) + VSH_REQUIRE_OPTION_EXPR(NAME1, vshCommandOptBool(ctl, cmd, NAME1), \ + NAME2, vshCommandOptBool(ctl, cmd, NAME2)) /* VSH_REQUIRE_OPTION_VAR: * -- 2.1.0

On 22.05.2015 10:59, Andrea Bolognani wrote:
This will allow us to use vshError() to report errors from inside vshCommandOpt*(), instead of replicating the same logic and error messages all over the place.
We also have more context inside the vshCommandOpt*() functions, for example the actual value used on the command line, which means we can produce more detailed error messages. --- tools/virsh-domain-monitor.c | 90 +++---- tools/virsh-domain.c | 598 +++++++++++++++++++++---------------------- tools/virsh-host.c | 46 ++-- tools/virsh-interface.c | 14 +- tools/virsh-network.c | 34 +-- tools/virsh-nodedev.c | 6 +- tools/virsh-pool.c | 26 +- tools/virsh-secret.c | 8 +- tools/virsh-snapshot.c | 88 +++---- tools/virsh-volume.c | 34 +-- tools/virsh.c | 107 ++++---- tools/virsh.h | 77 +++--- 12 files changed, 574 insertions(+), 554 deletions(-)
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index a42c150..db7ef8b 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -317,9 +317,9 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) bool ret = false; int rv = 0; int period = -1; - bool config = vshCommandOptBool(cmd, "config"); - bool live = vshCommandOptBool(cmd, "live"); - bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(ctl, cmd, "config");
I don't think this is needed. vshCommandOptBool should never return an error. Well, it's returning just if a flag was specified or not.
+ bool live = vshCommandOptBool(ctl, cmd, "live"); + bool current = vshCommandOptBool(ctl, cmd, "current"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
VSH_EXCLUSIVE_OPTIONS_VAR(current, live); @@ -340,7 +340,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) /* Providing a period will adjust the balloon driver collection period. * This is not really an unsigned long, but it */ - if ((rv = vshCommandOptInt(cmd, "period", &period)) < 0) { + if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0) {
This is of course different, specified value may not be a number in which case we want an error to be reported.
vshError(ctl, _("Numeric value for <%s> option is malformed or out of range"), "period");
ACK modulo the OptBool() change. Michal

On Wed, 2015-05-27 at 16:47 +0200, Michal Privoznik wrote:
- bool config = vshCommandOptBool(cmd, "config"); + bool config = vshCommandOptBool(ctl, cmd, "config");
I don't think this is needed. vshCommandOptBool should never return an error. Well, it's returning just if a flag was specified or not.
I added it in to keep all vshCommandOpt*() calls consistent, but since both you and Peter feel like it shouldn't be there I'll get rid of it. Cheers. -- Andrea Bolognani Software Engineer - Virtualization Team $ python -c "print('a'.join(['', 'bologn', '@redh', 't.com']))"

--- tests/vcpupin | 4 +- tools/virsh-domain-monitor.c | 9 +-- tools/virsh-domain.c | 134 +++++++------------------------------------ tools/virsh-host.c | 57 +++--------------- tools/virsh-interface.c | 6 +- tools/virsh-network.c | 6 +- tools/virsh-volume.c | 24 ++------ tools/virsh.c | 111 +++++++++++++++++++++-------------- 8 files changed, 104 insertions(+), 247 deletions(-) diff --git a/tests/vcpupin b/tests/vcpupin index ab0d38f..b6b8b31 100755 --- a/tests/vcpupin +++ b/tests/vcpupin @@ -34,7 +34,7 @@ fail=0 $abs_top_builddir/tools/virsh --connect test:///default vcpupin test a 0,1 > out 2>&1 test $? = 1 || fail=1 cat <<\EOF > exp || fail=1 -error: Numeric value for <vcpu> option is malformed or out of range +error: Numeric value 'a' for <vcpu> option is malformed or out of range EOF compare exp out || fail=1 @@ -52,7 +52,7 @@ compare exp out || fail=1 $abs_top_builddir/tools/virsh --connect test:///default vcpupin test -100 0,1 > out 2>&1 test $? = 1 || fail=1 cat <<\EOF > exp || fail=1 -error: Numeric value for <vcpu> option is malformed or out of range +error: Numeric value '-100' for <vcpu> option is malformed or out of range EOF compare exp out || fail=1 diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index db7ef8b..5b17505 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -340,12 +340,8 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) /* Providing a period will adjust the balloon driver collection period. * This is not really an unsigned long, but it */ - if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "period"); + if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0) goto cleanup; - } if (rv > 0) { if (period < 0) { vshError(ctl, _("Invalid collection period value '%d'"), period); @@ -1440,9 +1436,6 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (rv < 0) { /* invalid integer format */ - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "time"); goto cleanup; } else if (rv > 0) { /* valid integer to set */ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index bb8e20a..5094b2a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1552,9 +1552,6 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) return false; if ((rv = vshCommandOptInt(ctl, cmd, "weight", &weight)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "weight"); goto cleanup; } else if (rv > 0) { if (weight <= 0) { @@ -1692,12 +1689,8 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) goto cleanup; - if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "bandwidth"); + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) goto cleanup; - } switch (mode) { case VSH_CMD_BLOCK_JOB_ABORT: @@ -2216,24 +2209,12 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) * MiB/s, and either reject negative input or treat it as 0 rather * than trying to guess which value will work well across both * APIs with their different sizes and scales. */ - if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "bandwidth"); + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) goto cleanup; - } - if (vshCommandOptUInt(ctl, cmd, "granularity", &granularity) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "granularity"); + if (vshCommandOptUInt(ctl, cmd, "granularity", &granularity) < 0) goto cleanup; - } - if (vshCommandOptULongLong(ctl, cmd, "buf-size", &buf_size) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "buf-size"); + if (vshCommandOptULongLong(ctl, cmd, "buf-size", &buf_size) < 0) goto cleanup; - } if (xml) { if (virFileReadAll(xml, VSH_MAX_XML_FILE, &xmlstr) < 0) { @@ -2800,12 +2781,8 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0) return false; - if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "size"); + if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) < 0) return false; - } /* Prefer the older interface of KiB. */ if (size % 1024 == 0) @@ -3406,12 +3383,8 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; - if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "duration"); + if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0) goto cleanup; - } if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) goto cleanup; @@ -5330,12 +5303,8 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", (const char **) &file) < 0) return false; - if (vshCommandOptUInt(ctl, cmd, "screen", &screen) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "screen"); + if (vshCommandOptUInt(ctl, cmd, "screen", &screen) < 0) return false; - } if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; @@ -6429,12 +6398,8 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) if (!cpulist) VSH_EXCLUSIVE_OPTIONS_VAR(live, config); - if ((got_vcpu = vshCommandOptUInt(ctl, cmd, "vcpu", &vcpu)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "vcpu"); + if ((got_vcpu = vshCommandOptUInt(ctl, cmd, "vcpu", &vcpu)) < 0) return false; - } /* In pin mode, "vcpu" is necessary */ if (cpulist && got_vcpu == 0) { @@ -6698,12 +6663,8 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <= 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "count"); + if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <= 0) goto cleanup; - } /* none of the options were specified */ if (!current && flags == 0) { @@ -6878,12 +6839,8 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "iothread"); + if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0) goto cleanup; - } if (vshCommandOptString(ctl, cmd, "cpulist", &cpulist) < 0) { vshError(ctl, "%s", _("iothreadpin: invalid cpulist.")); @@ -6969,12 +6926,8 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "id"); + if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) goto cleanup; - } if (iothread_id <= 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); goto cleanup; @@ -7051,12 +7004,8 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "id"); + if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) goto cleanup; - } if (iothread_id <= 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); goto cleanup; @@ -7341,9 +7290,6 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) show_total = vshCommandOptBool(ctl, cmd, "total"); if ((rv = vshCommandOptInt(ctl, cmd, "start", &cpu)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "start"); goto cleanup; } else if (rv > 0) { if (cpu < 0) { @@ -7354,9 +7300,6 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) } if ((rv = vshCommandOptInt(ctl, cmd, "count", &show_count)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "count"); goto cleanup; } else if (rv > 0) { if (show_count < 0) { @@ -8143,12 +8086,8 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(ctl, cmd, "codeset", &codeset_option) <= 0) codeset_option = "linux"; - if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "holdtime"); + if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0) goto cleanup; - } codeset = virKeycodeSetTypeFromString(codeset_option); if (codeset < 0) { @@ -8269,12 +8208,8 @@ cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptLongLong(ctl, cmd, "pid", &pid_value) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "pid"); + if (vshCommandOptLongLong(ctl, cmd, "pid", &pid_value) < 0) goto cleanup; - } if (vshCommandOptStringReq(ctl, cmd, "signame", &signame) < 0) goto cleanup; @@ -8371,9 +8306,6 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "size"); virDomainFree(dom); return false; } @@ -8468,9 +8400,6 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "size"); virDomainFree(dom); return false; } @@ -9103,12 +9032,8 @@ cmdQemuAttach(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; unsigned int pid_value; /* API uses unsigned int, not pid_t */ - if (vshCommandOptUInt(ctl, cmd, "pid", &pid_value) <= 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "pid"); + if (vshCommandOptUInt(ctl, cmd, "pid", &pid_value) <= 0) goto cleanup; - } if (!(dom = virDomainQemuAttach(ctl->conn, pid_value, flags))) { vshError(ctl, _("Failed to attach to pid %u"), pid_value); @@ -9200,14 +9125,10 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) guest_agent_cmd = virBufferContentAndReset(&buf); judge = vshCommandOptInt(ctl, cmd, "timeout", &timeout); - if (judge < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "timeout"); + if (judge < 0) goto cleanup; - } else if (judge > 0) { + else if (judge > 0) judge = 1; - } if (judge && timeout < 1) { vshError(ctl, "%s", _("timeout must be positive")); goto cleanup; @@ -10085,12 +10006,8 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptLongLong(ctl, cmd, "downtime", &downtime) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "downtime"); + if (vshCommandOptLongLong(ctl, cmd, "downtime", &downtime) < 0) goto done; - } if (downtime < 1) { vshError(ctl, "%s", _("migrate: Invalid downtime")); goto done; @@ -10149,9 +10066,6 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) rc = vshCommandOptULongLong(ctl, cmd, "size", &size); if (rc < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "size"); goto cleanup; } else if (rc != 0) { if (virDomainMigrateSetCompressionCache(dom, size, 0) < 0) @@ -10208,12 +10122,8 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; - if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "bandwidth"); + if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) goto done; - } if (virDomainMigrateSetMaxSpeed(dom, bandwidth, 0) < 0) goto done; @@ -12548,12 +12458,8 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return ret; - if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "minimum"); + if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0) goto cleanup; - } if (vshCommandOptStringReq(ctl, cmd, "mountpoint", &mountPoint) < 0) goto cleanup; diff --git a/tools/virsh-host.c b/tools/virsh-host.c index aa37aa6..7ec9373 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -176,12 +176,8 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cellno"); + if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) return false; - } if (all) { if (!(cap_xml = virConnectGetCapabilities(ctl->conn))) { @@ -311,12 +307,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "pagesize"); + if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) goto cleanup; - } kibibytes = VIR_DIV_UP(bytes, 1024); if (all) { @@ -391,12 +383,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cellno"); + if (vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0) goto cleanup; - } if (cell < -1) { vshError(ctl, "%s", @@ -490,19 +478,11 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); - if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &startCell) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cellno"); + if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &startCell) < 0) return false; - } - if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cellno"); + if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX) < 0) return false; - } pageSizes[0] = VIR_DIV_UP(tmp, 1024); if (vshCommandOptULongLong(ctl, cmd, "pagecount", &pageCounts[0]) < 0) { @@ -764,12 +744,8 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) unsigned long long cpu_stats[VSH_CPU_LAST] = { 0 }; bool present[VSH_CPU_LAST] = { false }; - if (vshCommandOptInt(ctl, cmd, "cpu", &cpuNum) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cpu"); + if (vshCommandOptInt(ctl, cmd, "cpu", &cpuNum) < 0) return false; - } if (virNodeGetCPUStats(ctl->conn, cpuNum, NULL, &nparams, 0) != 0) { vshError(ctl, "%s", @@ -875,12 +851,8 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) virNodeMemoryStatsPtr params = NULL; bool ret = false; - if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "cell"); + if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) return false; - } /* get the number of memory parameters */ if (virNodeGetMemoryStats(ctl->conn, cellNum, NULL, &nparams, 0) != 0) { @@ -951,12 +923,8 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) return false; - if (vshCommandOptLongLong(ctl, cmd, "duration", &duration) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "duration"); + if (vshCommandOptLongLong(ctl, cmd, "duration", &duration) < 0) return false; - } if (STREQ(target, "mem")) { suspendTarget = VIR_NODE_SUSPEND_TARGET_MEM; @@ -1261,9 +1229,6 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) size_t i; if ((rc = vshCommandOptUInt(ctl, cmd, "shm-pages-to-scan", &value)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "shm-pages-to-scan"); goto cleanup; } else if (rc > 0) { if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams, @@ -1273,9 +1238,6 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) } if ((rc = vshCommandOptUInt(ctl, cmd, "shm-sleep-millisecs", &value)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "shm-sleep-millisecs"); goto cleanup; } else if (rc > 0) { if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams, @@ -1285,9 +1247,6 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) } if ((rc = vshCommandOptUInt(ctl, cmd, "shm-merge-across-nodes", &value)) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "shm-merge-across-nodes"); goto cleanup; } else if (rc > 0) { if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams, diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 0f8ea95..671facc 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -843,12 +843,8 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) /* use "no-stp" because we want "stp" to default true */ stp = !vshCommandOptBool(ctl, cmd, "no-stp"); - if (vshCommandOptUInt(ctl, cmd, "delay", &delay) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "delay"); + if (vshCommandOptUInt(ctl, cmd, "delay", &delay) < 0) goto cleanup; - } nostart = vshCommandOptBool(ctl, cmd, "no-start"); diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 8a52834..58d7906 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -936,12 +936,8 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptInt(ctl, cmd, "parent-index", &parentIndex) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "parent-index"); + if (vshCommandOptInt(ctl, cmd, "parent-index", &parentIndex) < 0) goto cleanup; - } /* The goal is to have a full xml element in the "xml" * string. This is provided in the --xml option, either directly diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 07dfd67..640ecb3 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -693,19 +693,11 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) const char *name = NULL; unsigned long long offset = 0, length = 0; - if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "offset"); + if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) return false; - } - if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "length"); + if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) return false; - } if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; @@ -806,19 +798,11 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) unsigned long long offset = 0, length = 0; bool created = false; - if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "offset"); + if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) return false; - } - if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) { - vshError(ctl, - _("Numeric value for <%s> option is malformed or out of range"), - "length"); + if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0) return false; - } if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; diff --git a/tools/virsh.c b/tools/virsh.c index 9f44793..db9354c 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1517,23 +1517,27 @@ vshCommandOpt(const vshCmd *cmd, * <0 in all other cases (@value untouched) */ int -vshCommandOptInt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, +vshCommandOptInt(vshControl *ctl, const vshCmd *cmd, const char *name, int *value) { vshCmdOpt *arg; int ret; - ret = vshCommandOpt(cmd, name, &arg, true); - if (ret <= 0) + if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) return ret; - if (virStrToLong_i(arg->data, NULL, 10, value) < 0) - return -1; - return 1; + if ((ret = virStrToLong_i(arg->data, NULL, 10, value)) < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; + + return ret; } static int -vshCommandOptUIntInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, +vshCommandOptUIntInternal(vshControl *ctl, const vshCmd *cmd, const char *name, unsigned int *value, bool wrap) { @@ -1543,15 +1547,18 @@ vshCommandOptUIntInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) return ret; - if (wrap) { - if (virStrToLong_ui(arg->data, NULL, 10, value) < 0) - return -1; - } else { - if (virStrToLong_uip(arg->data, NULL, 10, value) < 0) - return -1; - } + if (wrap) + ret = virStrToLong_ui(arg->data, NULL, 10, value); + else + ret = virStrToLong_uip(arg->data, NULL, 10, value); + if (ret < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; - return 1; + return ret; } /** @@ -1589,7 +1596,7 @@ vshCommandOptUIntWrap(vshControl *ctl, const vshCmd *cmd, } static int -vshCommandOptULInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, +vshCommandOptULInternal(vshControl *ctl, const vshCmd *cmd, const char *name, unsigned long *value, bool wrap) { @@ -1599,15 +1606,18 @@ vshCommandOptULInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) return ret; - if (wrap) { - if (virStrToLong_ul(arg->data, NULL, 10, value) < 0) - return -1; - } else { - if (virStrToLong_ulp(arg->data, NULL, 10, value) < 0) - return -1; - } + if (wrap) + ret = virStrToLong_ul(arg->data, NULL, 10, value); + else + ret = virStrToLong_ulp(arg->data, NULL, 10, value); + if (ret < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; - return 1; + return ret; } /* @@ -1664,8 +1674,7 @@ vshCommandOptString(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, vshCmdOpt *arg; int ret; - ret = vshCommandOpt(cmd, name, &arg, true); - if (ret <= 0) + if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) return ret; if (!*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK)) @@ -1728,23 +1737,27 @@ vshCommandOptStringReq(vshControl *ctl, const vshCmd *cmd, * See vshCommandOptInt() */ int -vshCommandOptLongLong(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, +vshCommandOptLongLong(vshControl *ctl, const vshCmd *cmd, const char *name, long long *value) { vshCmdOpt *arg; int ret; - ret = vshCommandOpt(cmd, name, &arg, true); - if (ret <= 0) + if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) return ret; - if (virStrToLong_ll(arg->data, NULL, 10, value) < 0) - return -1; - return 1; + if ((ret = virStrToLong_ll(arg->data, NULL, 10, value)) < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; + + return ret; } static int -vshCommandOptULongLongInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, +vshCommandOptULongLongInternal(vshControl *ctl, const vshCmd *cmd, const char *name, unsigned long long *value, bool wrap) { @@ -1754,15 +1767,18 @@ vshCommandOptULongLongInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *c if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) return ret; - if (wrap) { - if (virStrToLong_ull(arg->data, NULL, 10, value) < 0) - return -1; - } else { - if (virStrToLong_ullp(arg->data, NULL, 10, value) < 0) - return -1; - } + if (wrap) + ret = virStrToLong_ull(arg->data, NULL, 10, value); + else + ret = virStrToLong_ullp(arg->data, NULL, 10, value); + if (ret < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; - return 1; + return ret; } /** @@ -1812,7 +1828,7 @@ vshCommandOptULongLongWrap(vshControl *ctl, const vshCmd *cmd, * See vshCommandOptInt() */ int -vshCommandOptScaledInt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, +vshCommandOptScaledInt(vshControl *ctl, const vshCmd *cmd, const char *name, unsigned long long *value, int scale, unsigned long long max) { @@ -1825,9 +1841,16 @@ vshCommandOptScaledInt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, if (virStrToLong_ull(arg->data, &end, 10, value) < 0 || virScaleInteger(value, end, scale, max) < 0) - return -1; + { + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + ret = -1; + } else { + ret = 1; + } - return 1; + return ret; } -- 2.1.0

On 22.05.2015 10:59, Andrea Bolognani wrote:
--- tests/vcpupin | 4 +- tools/virsh-domain-monitor.c | 9 +-- tools/virsh-domain.c | 134 +++++++------------------------------------ tools/virsh-host.c | 57 +++--------------- tools/virsh-interface.c | 6 +- tools/virsh-network.c | 6 +- tools/virsh-volume.c | 24 ++------ tools/virsh.c | 111 +++++++++++++++++++++-------------- 8 files changed, 104 insertions(+), 247 deletions(-)
Nice cleanup.
diff --git a/tools/virsh.c b/tools/virsh.c index 9f44793..db9354c 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1517,23 +1517,27 @@ vshCommandOpt(const vshCmd *cmd, * <0 in all other cases (@value untouched) */
Does it makes sense to note in comments that this function (and others that you're fixing) is reporting an error?
int -vshCommandOptInt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, +vshCommandOptInt(vshControl *ctl, const vshCmd *cmd, const char *name, int *value) { vshCmdOpt *arg; int ret;
- ret = vshCommandOpt(cmd, name, &arg, true); - if (ret <= 0) + if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) return ret;
- if (virStrToLong_i(arg->data, NULL, 10, value) < 0) - return -1; - return 1; + if ((ret = virStrToLong_i(arg->data, NULL, 10, value)) < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1; + + return ret; }
While reworking this, you've missed vshCommandOptTimeoutToMs() which in case of something like following '--timeout blah' will report error twice: from both OptInt() and OptTimeoutToMs(): error: Numeric value 'blah' for <timeout> option is malformed or out of range error: invalid timeout I think this should be squashed in: @@ -1906,11 +1907,13 @@ vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, { int rv = vshCommandOptInt(ctl, cmd, "timeout", timeout); - if (rv < 0 || (rv > 0 && *timeout < 1)) { - vshError(ctl, "%s", _("invalid timeout")); + if (rv < 0) return -1; - } if (rv > 0) { + if (*timeout < 1) { + vshError(ctl, "%s", _("invalid timeout")); + return -1; + } /* Ensure that we can multiply by 1000 without overflowing. */ if (*timeout > INT_MAX / 1000) { vshError(ctl, "%s", _("timeout is too big"));
static int -vshCommandOptULongLongInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, +vshCommandOptULongLongInternal(vshControl *ctl, const vshCmd *cmd, const char *name, unsigned long long *value, bool wrap) { @@ -1754,15 +1767,18 @@ vshCommandOptULongLongInternal(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *c if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0) return ret;
- if (wrap) { - if (virStrToLong_ull(arg->data, NULL, 10, value) < 0) - return -1; - } else { - if (virStrToLong_ullp(arg->data, NULL, 10, value) < 0) - return -1; - } + if (wrap) + ret = virStrToLong_ull(arg->data, NULL, 10, value); + else + ret = virStrToLong_ullp(arg->data, NULL, 10, value); + if (ret < 0) + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + else + ret = 1;
- return 1; + return ret; }
You've missed one ocurrance of vshCommandOptULongLong in cmdAllocpages().
/** @@ -1812,7 +1828,7 @@ vshCommandOptULongLongWrap(vshControl *ctl, const vshCmd *cmd, * See vshCommandOptInt() */ int -vshCommandOptScaledInt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd, +vshCommandOptScaledInt(vshControl *ctl, const vshCmd *cmd, const char *name, unsigned long long *value, int scale, unsigned long long max) { @@ -1825,9 +1841,16 @@ vshCommandOptScaledInt(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd,
if (virStrToLong_ull(arg->data, &end, 10, value) < 0 || virScaleInteger(value, end, scale, max) < 0) - return -1; + { + vshError(ctl, + _("Numeric value '%s' for <%s> option is malformed or out of range"), + arg->data, name); + ret = -1; + } else { + ret = 1; + }
- return 1; + return ret; }
Interestingly vshCommandOptString() is missing. So far, the only way for the function to fail is if one uses --option "" and VSH_OFLAG_EMPTY_OK is not specified. So if we come up with good error message for that case, we are okay to drop all the other error messages. Otherwise looking good. Michal

On Wed, 2015-05-27 at 16:47 +0200, Michal Privoznik wrote:
diff --git a/tools/virsh.c b/tools/virsh.c index 9f44793..db9354c 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1517,23 +1517,27 @@ vshCommandOpt(const vshCmd *cmd, * <0 in all other cases (@value untouched) */
Does it makes sense to note in comments that this function (and others that you're fixing) is reporting an error?
Done. I've only updated the comments for vshCommandOptInt() because all other functions explicitly refer to that one in their comments.
While reworking this, you've missed vshCommandOptTimeoutToMs() which in case of something like following '--timeout blah' will report error twice: from both OptInt() and OptTimeoutToMs():
error: Numeric value 'blah' for <timeout> option is malformed or out of range error: invalid timeout
I think this should be squashed in:
@@ -1906,11 +1907,13 @@ vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, { int rv = vshCommandOptInt(ctl, cmd, "timeout", timeout);
- if (rv < 0 || (rv > 0 && *timeout < 1)) { - vshError(ctl, "%s", _("invalid timeout")); + if (rv < 0) return -1; - } if (rv > 0) { + if (*timeout < 1) { + vshError(ctl, "%s", _("invalid timeout")); + return -1; + } /* Ensure that we can multiply by 1000 without overflowing. */ if (*timeout > INT_MAX / 1000) { vshError(ctl, "%s", _("timeout is too big"));
Agreed, two error messages for a single failure is not something the user should run into. I've gone for a slightly different implementation here, which adds two small commits at the beginning of the series. Please check it out.
You've missed one ocurrance of vshCommandOptULongLong in cmdAllocpages().
I'd actually missed it the first time around, when I unified all the error messages. Great catch!
Interestingly vshCommandOptString() is missing. So far, the only way for the function to fail is if one uses --option "" and VSH_OFLAG_EMPTY_OK is not specified. So if we come up with good error message for that case, we are okay to drop all the other error messages.
I will look into it next, see what I can do :) Cheers. -- Andrea Bolognani Software Engineer - Virtualization Team $ python -c "print('a'.join(['', 'bologn', '@redh', 't.com']))"
participants (3)
-
Andrea Bolognani
-
Michal Privoznik
-
Peter Krempa