Need help on Dbus API's

N, Soumya P soumya.p.n at hpe.com
Tue Apr 5 11:38:08 UTC 2016


Hi Lennart,



It is working now. Thanks a lot for your help.



We are working on cgroups blkio subsystem, where we would require more info on this areas( ex: setting some cgroup parameters per device, using one unit file for one cgroups but managing per device level etc).

As we are new to sd-bus programming, any documentation related to these areas of programming if you can share will be helpful.



We will also be subscribing to system-devel mailing list.



Thanks,

Soumya.



-----Original Message-----
From: Lennart Poettering [mailto:mzqohf at 0pointer.de]
Sent: Friday, April 01, 2016 11:43 PM
To: N, Soumya P <soumya.p.n at hpe.com<mailto:soumya.p.n at hpe.com>>
Cc: dbus at lists.freedesktop.org<mailto:dbus at lists.freedesktop.org>; A M, Ashalatha <ashalatha-a.a at hpe.com<mailto:ashalatha-a.a at hpe.com>>
Subject: Re: Need help on Dbus API's



On Mon, 28.03.16 06:40, N, Soumya P (soumya.p.n at hpe.com<mailto:soumya.p.n at hpe.com>) wrote:



> Hello,

>

> We have a requirement to get/set some properties on /sys/fs/cgroup/blkio and also child cgroups under this (ex: /sys/fs/cgroup/blkio/Gold_cg).

> We found that libcgroups are going to be obsoleted from RHEL 7 onwards and hence we started with systemd cgroups and we found that we need to use sdbus API's.

> (We have RHEL 7.2 installed on our system)



You sent your message to the dbus mailing list, which is only for issues in the dbus protocol and the dbus reference implementation. However, you are using the sd-bus implementation and systemd as service, hence systemd-devel would be the right place to discuss this.



>

>         r = sd_bus_call_method(bus,

>                         "org/freedesktop/systemd1",

>                         "/org/freedesktop/systemd1",

>                         "org.freedesktop.systemd1.Manager",

>                         "SetUnitProperties", &error,

>                         &reply, "s", "sample.slice",0,

>                         ("BlockIOWeight", 500));



Please read up on the sd_bus_message_append(3) man page. You need to specify the full signature string for SetUnitProperties() instead of just "s". (i.e. the right signature argument is "sba(sv)"). Then you need to follow with the matching arguments.



Something like this should work (untested):



         r = sd_bus_call_method(bus,

                         "org/freedesktop/systemd1",

                         "/org/freedesktop/systemd1",

                         "org.freedesktop.systemd1.Manager",

                         "SetUnitProperties", &error,

                         &reply,

                         "sba(sv)",

                         "sample.slice",   /* this is the unit name string */

                         0,                /* this is the "runtime" bool */

                         1,                /* number of array entries */

                         "BlockIOWeight",  /* Property name */

                         "t",              /* Property variant type */

                         UINT64_C(500));   /* Property value */



Basically, the parameters you specifiy in the signature strings must follow the signature string immediately. For arrays, you need to specify the number of entries following first, and for variants you need to specify the type of the variant first.



It's important to use the UINT64_C() macro for the 500 argument, since this is a varargs function, and if you don't fix the type, then C will push this onto the stack as the smallest type that is at least "int", and that's int32_t. However, as we specify "t" as variant type (which is a unsigned 64bit type), we need to make sure C gets that right, and explicitly request a 64bit unsigned constant to be put on the stack, hence the UINT64_C() macro...



Lennart



--

Lennart Poettering, Red Hat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20160405/c1f87002/attachment.html>


More information about the dbus mailing list