[libvirt] [PATCH 1/2] cgroup: Add accessors for cpuset.memory_migrate

Eric Blake eblake at redhat.com
Thu Mar 19 23:25:28 UTC 2015


On 03/19/2015 05:11 PM, John Ferlan wrote:

>> +int
>> +virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate)
>> +{
>> +    return virCgroupSetValueStr(group,
>> +                                VIR_CGROUP_CONTROLLER_CPUSET,
>> +                                "cpuset.memory_migrate",
>> +                                migrate ? "1" : "0");
>> +}
> 
> are my eyes deceiving me?...  boolean here (1 or 0)

No, the kernel really works this way - it takes the human-readable
string "1" or "0" rather than the C byte '\1' or '\0', so this is the
lowest level in the stack where we convert our convenient bool for
everyone above us into the string literal the kernel cgroup interface
expects.

>> +int
>> +virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate)
>> +{
>> +    unsigned long long value = 0;
>> +    int ret = virCgroupGetValueU64(group,
> 
> But we're getting a U64 here? for what's documented as "contains a flag
> (0 or 1)
> 
>> +                                   VIR_CGROUP_CONTROLLER_CPUSET,
>> +                                   "cpuset.memory_migrate",
>> +                                   &value);
>> +    *migrate = !!value;

And here, this is one easy way to turn the kernel's string back into a
bool (it might also be possible to read as a string, and then do
*str=='1', rather than going through an intermediate integer conversion,
but I'm not sure it is worth the micro-optimization).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150319/280e5093/attachment-0001.sig>


More information about the libvir-list mailing list