[libvirt] [PATCH 15/16] conf: Simplify cputune parameter retrieval

Peter Krempa pkrempa at redhat.com
Mon Mar 4 10:10:48 UTC 2013


On 03/01/13 20:29, Laine Stump wrote:
> On 02/20/2013 12:06 PM, Peter Krempa wrote:
>> The parameters are initialized already so no need to do it again.
>> ---
>>   src/conf/domain_conf.c | 29 ++++++++---------------------
>>   1 file changed, 8 insertions(+), 21 deletions(-)
>>
>> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>> index 3c3172d..da04b7b 100644
>> --- a/src/conf/domain_conf.c
>> +++ b/src/conf/domain_conf.c
>> @@ -9485,29 +9485,16 @@ virDomainDefParseXML(virCapsPtr caps,
>>       }
>>
>>       /* Extract cpu tunables. */
>> -    if (virXPathULong("string(./cputune/shares[1])", ctxt,
>> -                      &def->cputune.shares) < 0)
>> -        def->cputune.shares = 0;
>> +    virXPathULong("string(./cputune/shares[1])", ctxt, &def->cputune.shares);
>> +    virXPathULongLong("string(./cputune/period[1])", ctxt, &def->cputune.period);
>> +    virXPathLongLong("string(./cputune/quota[1])", ctxt, &def->cputune.quota);
>> +    virXPathULongLong("string(./cputune/emulator_period[1])", ctxt,
>> +                      &def->cputune.emulator_period);
>> +    virXPathLongLong("string(./cputune/emulator_quota[1])", ctxt,
>> +                     &def->cputune.emulator_quota);
>
> You're not doing anything to check for invalid data here. If somebody
> sets one of them to "blorg", you'll just set it to 0.

For my defense, it used to be this way and I just simplified the code. I 
agree we should actually change this to provide meaningful errors.

v2 coming soon.

>
>>
>> -    if (virXPathULongLong("string(./cputune/period[1])", ctxt,
>> -                          &def->cputune.period) < 0)
>> -        def->cputune.period = 0;
>> -
>> -    if (virXPathLongLong("string(./cputune/quota[1])", ctxt,
>> -                         &def->cputune.quota) < 0)
>> -        def->cputune.quota = 0;
>> -
>> -    if (virXPathULongLong("string(./cputune/emulator_period[1])", ctxt,
>> -                          &def->cputune.emulator_period) < 0)
>> -        def->cputune.emulator_period = 0;
>> -
>> -    if (virXPathLongLong("string(./cputune/emulator_quota[1])", ctxt,
>> -                         &def->cputune.emulator_quota) < 0)
>> -        def->cputune.emulator_quota = 0;
>> -
>> -    if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0) {
>> +    if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0)
>>           goto error;
>> -    }
>>
>>       if (n && VIR_ALLOC_N(def->cputune.vcpupin, n) < 0)
>>           goto no_memory;
>

Peter




More information about the libvir-list mailing list