Need help on Dbus API's
N, Soumya P
soumya.p.n at hpe.com
Mon Mar 28 06:40:58 UTC 2016
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)
We found below references:
https://www.freedesktop.org/wiki/Software/systemd/dbus/
http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html
We downloaded system-221 package, compiled and ran some sample programs.
We tried few API's like GetUnit(), StartUnit() seems to be working. Then we tried below API to set property on a cgroup which did not succeed:
SetUnitProperties(in s name, in b runtime, a(sv) properties);
We used below .slice unit file and tried below program:
Sample.slice (created in /etc/system/system):
-------
[Unit]
Description=Gold Cg Slice
[Slice]
BlockIOWeight=200
[Install]
WantedBy=default.target
------------
Then we started this using:
# systemctl daemon-reload
# systemctl start sample.slice
Sdbus.c:
#include <stdio.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>
int main(int argc, char *argv[]) {
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *reply = NULL;
const char *path = NULL;
const char *p = NULL;
sd_bus *bus = NULL;
int r;
/* Connect to the system bus */
r=sd_bus_open_system(&bus);
r = sd_bus_call_method(bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"GetUnit", &error,
&reply,
"s", "sample.slice");
if(r < 0) {
fprintf(stderr, "Failed to issue method call: %s\n", error.message);
}
r = sd_bus_message_read(reply, "s", &p);
if(r < 0)
fprintf(stderr, "Failed to parse response message: %s\n", strerror(-r));
else
printf("sd bus message read = %s \n", p);
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));
//SetUnitProperties("sample.slice",0, ("BlockIOWeight", 500) );
if(r < 0)
fprintf(stderr, "SetUnitProperties() failed: %s \n", error.message);
else
printf("SetUnitPropreties suceeded \n");
}
Ran this program and seeing below error:
#./a.out
Failed to parse response message: No such device or address
SetUnitProperties() failed: (null)
Looking at this error seems like ENXIO is the error and we saw in the sources that this error is returned in case of sd_bus_message_read() in several places.
Looking at the failure of SetUnitProperties() API, we are not sure about the usage of these API's. We even tried calling the API SetUnitProperties() directly but got "undefined reference" error.
As we are beginners of systemd programming it will help if there is any material related to sdbus programming.
Could you please help us?
Thanks,
Soumya.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20160328/16aa03dc/attachment.html>
More information about the dbus
mailing list