[libvirt] [PATCH 02/17] Introduce the function virCgroupMoveTask
Hu Tao
hutao at cn.fujitsu.com
Wed Aug 8 02:25:09 UTC 2012
On Mon, Aug 06, 2012 at 03:09:51PM -0600, Eric Blake wrote:
> On 08/03/2012 12:36 AM, Hu Tao wrote:
> > From: Wen Congyang <wency at cn.fujitsu.com>
> >
> > Introduce a new API to move tasks of one controller from a cgroup to another cgroup
> >
> > Signed-off-by: Wen Congyang <wency at cn.fujitsu.com>
> > Signed-off-by: Tang Chen <tangchen at cn.fujitsu.com>
> > Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
> > ---
>
> > +static int virCgroupAddTaskStrController(virCgroupPtr group,
> > + const char *pidstr,
> > + int controller)
> > +{
> > + char *str = NULL, *cur = NULL, *next = NULL;
> > + unsigned long long p = 0;
> > + int rc = 0;
> > +
> > + if (virAsprintf(&str, "%s", pidstr) < 0)
> > + return -1;
> > +
> > + cur = str;
> > + while ((next = strchr(cur, '\n')) != NULL) {
> > + *next = '\0';
> > + rc = virStrToLong_ull(cur, NULL, 10, &p);
> > + if (rc != 0)
> > + goto cleanup;
> > + cur = next + 1;
> > +
> > + rc = virCgroupAddTaskController(group, p, controller);
> > + if (rc != 0)
> > + goto cleanup;
> > + }
> > + if (cur != '\0') {
> > + rc = virStrToLong_ull(cur, NULL, 10, &p);
> > + if (rc != 0)
> > + goto cleanup;
> > + rc = virCgroupAddTaskController(group, p, controller);
> > + if (rc != 0)
> > + goto cleanup;
> > + }
>
> Can this last if statement be folded into the while loop for less code
> duplication? If the series passes review now, then I'm probably not
> worried enough to change it and would probably push as is; but if we
> need a v2, then it's worth improving.
OK, I'll improve it.
--
Thanks,
Hu Tao
More information about the libvir-list
mailing list