[libvirt] [PATCH] virsh: fix no error when pass a count <= 0 to setvcpus
Peter Krempa
pkrempa at redhat.com
Thu Jul 30 07:45:22 UTC 2015
On Thu, Jul 30, 2015 at 09:29:15 +0200, Andrea Bolognani wrote:
> On Thu, 2015-07-30 at 10:57 +0800, Luyao Huang wrote:
> > https://bugzilla.redhat.com/show_bug.cgi?id=1248277
> >
> > When count <= 0, the client exit without set an error.
> >
> > Signed-off-by: Luyao Huang <lhuang at redhat.com>
> > ---
> > tools/virsh-domain.c | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> > index f7edeeb..b6da684 100644
> > --- a/tools/virsh-domain.c
> > +++ b/tools/virsh-domain.c
> > @@ -6744,8 +6744,12 @@ cmdSetvcpus(vshControl *ctl, const vshCmd
> > *cmd)
> > if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
> > return false;
> >
> > - if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <=
> > 0)
> > + if (vshCommandOptInt(ctl, cmd, "count", &count) < 0)
> > goto cleanup;
> > + if (count <= 0) {
> > + vshError(ctl, _("Invalid value '%d' for number of virtual
> > CPUs"), count);
> > + goto cleanup;
> > + }
> >
> > /* none of the options were specified */
> > if (!current && flags == 0) {
>
> Nice catch, but I would go for the following diff instead:
>
> -----8<-----
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index a61656f..4b8ebbd 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -6819,7 +6819,7 @@ static bool
> cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
> {
> virDomainPtr dom;
> - int count = 0;
> + unsigned int count = 0;
> bool ret = false;
> bool maximum = vshCommandOptBool(cmd, "maximum");
> bool config = vshCommandOptBool(cmd, "config");
> @@ -6846,8 +6846,15 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
> if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
> return false;
>
> - if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <= 0)
> + if (vshCommandOptUInt(ctl, cmd, "count", &count) < 0)
> + goto cleanup;
> +
> + if (count == 0) {
> + vshError(ctl,
> + _("Numeric value '%s' for <%s> option is malformed or
> out of range"),
Since we know that here we are trying to set 0 cpus which is wrong we
can also say that explicitly in the error message rather than copying
the generic one.
Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150730/ec682cb9/attachment-0001.sig>
More information about the libvir-list
mailing list