[libvirt] [PATCHv2] virsh: fix no error when pass a count <= 0 to setvcpus

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@redhat.com> --- v2: - use vshCommandOptUInt to forbid negative number, and check if count is zero. (thanks Peter and Andrea) tools/virsh-domain.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 4191548..3f032f4 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6873,7 +6873,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"); @@ -6900,9 +6900,14 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) if (!(dom = virshCommandOptDomain(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, _("Can't set 0 processors for a VM")); + goto cleanup; + } + /* none of the options were specified */ if (!current && flags == 0) { if (virDomainSetVcpus(dom, count) != 0) -- 1.8.3.1

On Thu, 2015-10-22 at 11:27 +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@redhat.com> --- v2: - use vshCommandOptUInt to forbid negative number, and check if count is zero. (thanks Peter and Andrea)
tools/virsh-domain.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Pushed after improving the commit message. Cheers. -- Andrea Bolognani Software Engineer - Virtualization Team

On 10/22/2015 03:32 PM, Andrea Bolognani wrote:
On Thu, 2015-10-22 at 11:27 +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@redhat.com> --- v2: - use vshCommandOptUInt to forbid negative number, and check if count is zero. (thanks Peter and Andrea)
tools/virsh-domain.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) Pushed after improving the commit message.
Thanks a lot for your quick review and help !
Cheers.
Luyao
participants (3)
-
Andrea Bolognani
-
lhuang
-
Luyao Huang