mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virsh: Reject negative numbers in vshCommandOptUL
To follow the new semantics of the vshCommandOptToU* functions convert this one to reject negative numbers too. To allow using -1 for "maximum" semantics for the two bandwidth functions that use this helper introduce vshCommandOptULWrap. Although currently the migrate-setspeed function for the qemu driver will reject -1 as maximum.
This commit is contained in:
parent
37e663adb6
commit
0e2d73051a
@ -1457,7 +1457,7 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
|
|||||||
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshCommandOptUL(cmd, "bandwidth", &bandwidth) < 0) {
|
if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) {
|
||||||
vshError(ctl, "%s", _("bandwidth must be a number"));
|
vshError(ctl, "%s", _("bandwidth must be a number"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -9229,7 +9229,7 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptUL(cmd, "bandwidth", &bandwidth) < 0) {
|
if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) {
|
||||||
vshError(ctl, "%s", _("migrate: Invalid bandwidth"));
|
vshError(ctl, "%s", _("migrate: Invalid bandwidth"));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -1547,6 +1547,28 @@ vshCommandOptUIntWrap(const vshCmd *cmd, const char *name, unsigned int *value)
|
|||||||
return vshCommandOptUIntInternal(cmd, name, value, true);
|
return vshCommandOptUIntInternal(cmd, name, value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vshCommandOptULInternal(const vshCmd *cmd,
|
||||||
|
const char *name,
|
||||||
|
unsigned long *value,
|
||||||
|
bool wrap)
|
||||||
|
{
|
||||||
|
vshCmdOpt *arg;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vshCommandOptUL:
|
* vshCommandOptUL:
|
||||||
@ -1560,16 +1582,22 @@ vshCommandOptUIntWrap(const vshCmd *cmd, const char *name, unsigned int *value)
|
|||||||
int
|
int
|
||||||
vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value)
|
vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value)
|
||||||
{
|
{
|
||||||
vshCmdOpt *arg;
|
return vshCommandOptULInternal(cmd, name, value, false);
|
||||||
int ret;
|
}
|
||||||
|
|
||||||
ret = vshCommandOpt(cmd, name, &arg, true);
|
/**
|
||||||
if (ret <= 0)
|
* vshCommandOptULWrap:
|
||||||
return ret;
|
* @cmd command reference
|
||||||
|
* @name option name
|
||||||
if (virStrToLong_ul(arg->data, NULL, 10, value) < 0)
|
* @value result
|
||||||
return -1;
|
*
|
||||||
return 1;
|
* Convert option to unsigned long, wraps negative numbers to positive
|
||||||
|
* See vshCommandOptInt()
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
vshCommandOptULWrap(const vshCmd *cmd, const char *name, unsigned long *value)
|
||||||
|
{
|
||||||
|
return vshCommandOptULInternal(cmd, name, value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -291,6 +291,9 @@ int vshCommandOptUIntWrap(const vshCmd *cmd, const char *name,
|
|||||||
int vshCommandOptUL(const vshCmd *cmd, const char *name,
|
int vshCommandOptUL(const vshCmd *cmd, const char *name,
|
||||||
unsigned long *value)
|
unsigned long *value)
|
||||||
ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
|
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,
|
int vshCommandOptString(const vshCmd *cmd, const char *name,
|
||||||
const char **value)
|
const char **value)
|
||||||
ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user