[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libvir] [PATCH] setmem checks



On Fri, Jun 15, 2007 at 11:30:02AM -0400, Mark Johnson wrote:
> Which of these does folks prefer (same would apply to SetMaxMem).

I prefer the first. Full error checking & reporting. GetInfo should
never fail under any reasonable scenario. If it does fail its very
unlikely that a SetMemory would then work, so its pointless continuing

> 
> ONE
> ------
> cmdSetmem(vshControl * ctl, vshCmd * cmd)
> {
> ...
>    kilobytes = vshCommandOptInt(cmd, "kilobytes", &kilobytes);
>    if (kilobytes <= 0) {
>        virDomainFree(dom);
>        vshError(ctl, FALSE, _("Invalid value of %d for memory size"),
> kilobytes);
>        return FALSE;
>    }
> 
>    if (virDomainGetInfo(dom, &info) != 0) {
>        virDomainFree(dom);
>        vshError(ctl, FALSE, _("Unable to verify MaxMemorySize"));
>        return FALSE;
>    }
>    if (kilobytes > info.maxMem) {
>        virDomainFree(dom);
>        vshError(ctl, FALSE, _("Invalid value of %d for memory size"),
> kilobytes);
>        return FALSE;
>    }
> ...
> }
> 

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]