Hello, ----- Original Message ----- > From: "Jan Chaloupka" <jchal...@redhat.com> > To: libcg-devel@lists.sourceforge.net > Cc: jchal...@redhat.com, varek...@redhat.com > Sent: Wednesday, August 6, 2014 1:46:16 PM > Subject: [PATCH] api.c: retry to set control file in cgroup_modify_cgroup > > For memory controller, cgset --copy-from test_cgrp1/ test_cgrp2/ > sets memory.memsw.limit_in_bytes and memory.limit_in_bytes in a random order > based on reading of the corresponding directory. > > https://bugzilla.redhat.com/show_bug.cgi?id=1080281 > > memory.limit_in_bytes has to be set before memory.memsw.limit_in_bytes. If > it is set in opposite way, memory.memsw.limit_in_bytes is not set. This > can be set in the second try. In the first round, both control files are set. > memory.limit_in_bytes is garanteed to be set. If memory.memsw.limit_in_byte > is set before, in the second round we manage to set it too. > > In the first round, indeces off all unsuccesfully set control files are > stored. > In the second round, all those indexes are tried to be set for the second > time. > > On my local machine, after running cgset --copy-from test_cgrp1/ test_cgrp2/, > both memory.memsw.limit_in_bytes and memory.memsw.limit_in_bytes are set. > Hello, this solution is an overwork, I prefer to do some system solution which take account of variable properties. Ivana
> Signed-off-by: Jan Chaloupka <jchal...@redhat.com> > --- > src/api.c | 35 +++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/src/api.c b/src/api.c > index 5751b8f..d7c9024 100644 > --- a/src/api.c > +++ b/src/api.c > @@ -1555,6 +1555,8 @@ static int cg_set_control_value(char *path, const char > *val) > return 0; > } > > + > + > /** cgroup_modify_cgroup modifies the cgroup control files. > * struct cgroup *cgroup: The name will be the cgroup to be modified. > * The values will be the values to be modified, those not mentioned > @@ -1572,6 +1574,9 @@ int cgroup_modify_cgroup(struct cgroup *cgroup) > int i; > int error = 0; > int ret; > + int retry_list[CG_CONTROLLER_MAX]; > + int retry_index; > + struct control_value **cvalues; > > if (!cgroup_initialized) > return ECGROUPNOTINITIALIZED; > @@ -1592,6 +1597,8 @@ int cgroup_modify_cgroup(struct cgroup *cgroup) > if (!cg_build_path(cgroup->name, base, > cgroup->controller[i]->name)) > continue; > + > + retry_index = -1; > for (j = 0; j < cgroup->controller[i]->index; j++) { > ret = asprintf(&path, "%s%s", base, > cgroup->controller[i]->values[j]->name); > @@ -1608,12 +1615,40 @@ int cgroup_modify_cgroup(struct cgroup *cgroup) > * the user as fatal */ > if (error && !cgroup->controller[i]->values[j]->dirty) { > error = 0; > + /* Let's retry to set it in the second round */ > + ++retry_index; > + retry_list[retry_index] = j; > continue; > } > if (error) > goto err; > cgroup->controller[i]->values[j]->dirty = false; > } > + if (retry_index > -1) { > + for (j = 0; j <= retry_index; j++) { > + cvalues = cgroup->controller[i]->values; > + ret = asprintf(&path, "%s%s", base, > + cvalues[retry_list[j]]->name); > + if (ret < 0) { > + last_errno = errno; > + error = ECGOTHER; > + goto err; > + } > + error = cg_set_control_value(path, > + cvalues[retry_list[j]]->value); > + free(path); > + path = NULL; > + /* don't consider error in files directly > + * written by the user as fatal */ > + if (error && !cvalues[retry_list[j]]->dirty) { > + error = 0; > + continue; > + } > + if (error) > + goto err; > + cgroup->controller[i]->values[j]->dirty = false; > + } > + } > } > err: > return error; > > ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel