<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#44546A">Hello,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">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).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">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.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">(We have RHEL 7.2 installed on our system)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">We found below references:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><a href="https://www.freedesktop.org/wiki/Software/systemd/dbus/"><span style="color:#44546A">https://www.freedesktop.org/wiki/Software/systemd/dbus/</span></a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><a href="http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html"><span style="color:#44546A">http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html</span></a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">We downloaded system-221 package, compiled and ran some sample programs.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">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:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">SetUnitProperties(in s name, in b runtime, a(sv) properties);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">We used below .slice unit file and tried below program:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="color:#44546A">Sample.slice</span></b><span style="color:#44546A"> (created in /etc/system/system):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">------- <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">[Unit]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">Description=Gold Cg Slice<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">[Slice]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">BlockIOWeight=200<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">[Install]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">WantedBy=default.target<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">------------<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">Then we started this using:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"># systemctl daemon-reload<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"># systemctl start sample.slice<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="color:#44546A">Sdbus.c:<o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">#include <stdio.h><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">#include <stdlib.h><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">#include <systemd/sd-bus.h><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">int main(int argc, char *argv[]) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> sd_bus_error error = SD_BUS_ERROR_NULL;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> sd_bus_message *reply = NULL;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> const char *path = NULL;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> const char *p = NULL;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> sd_bus *bus = NULL;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> int r;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> /* Connect to the system bus */<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> r=sd_bus_open_system(&bus);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> r = sd_bus_call_method(bus,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> "org.freedesktop.systemd1",<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> "/org/freedesktop/systemd1",<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> "org.freedesktop.systemd1.Manager",<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> "GetUnit", &error,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> &reply,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> "s", "sample.slice");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> if(r < 0) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> fprintf(stderr, "Failed to issue method call: %s\n", error.message);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> r = sd_bus_message_read(reply, "s", &p);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> if(r < 0)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> fprintf(stderr, "Failed to parse response message: %s\n", strerror(-r));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> else<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> printf("sd bus message read = %s \n", p);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> r = sd_bus_call_method(bus,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> "org/freedesktop/systemd1",<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> "/org/freedesktop/systemd1",<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> "org.freedesktop.systemd1.Manager",<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> "SetUnitProperties", &error,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> &reply, "s", "sample.slice",0, ("BlockIOWeight", 500));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-indent:.5in"><span style="color:#44546A">//SetUnitProperties("sample.slice",0, ("BlockIOWeight", 500) );<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> if(r < 0)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> fprintf(stderr, "SetUnitProperties() failed: %s \n", error.message);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> else<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"> printf("SetUnitPropreties suceeded \n");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">Ran this program and seeing below error:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">#./a.out <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A;background:yellow;mso-highlight:yellow">Failed to parse response message: No such device or address<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A;background:yellow;mso-highlight:yellow">SetUnitProperties() failed: (null)</span><span style="color:#44546A"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">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.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">As we are beginners of systemd programming it will help if there is any material related to sdbus programming.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">Could you please help us?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#44546A">Soumya. <o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>