]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
api.c: Adding support for loading configuration files from cgrules.d directory
authorJan Chaloupka <jchaloup@redhat.com>
Thu, 31 Jul 2014 09:21:19 +0000 (11:21 +0200)
committerJan Chaloupka <jchaloup@redhat.com>
Thu, 31 Jul 2014 09:21:19 +0000 (11:21 +0200)
commitf0356d97e69f0eb993e72b38829c91e10b927a4a
treea69185d127d2f3f96af1cc948e18acc4364774b9
parent1cf69a968c753b42d7cf816f129a2962f5f87a2a
api.c: Adding support for loading configuration files from cgrules.d directory

Implementation of loading rules from /etc/cgrules.d/. Explanation is in the
cover letter. New function cgroup_parse_rules_file created,
calling cgroup_parse_rules. cgroup_parse_rules is invoked only in
cgroup_change_cgroup_flags, cgroup_init_rules_cache and
cgroup_reload_cached_rules functions. For them the change in cgroup_parse_rules
implementation is transpart.

Tested with two configuration files in /etc/cgrules.d/ and all rules
in /etc/cgrules.conf commented out:

$ cat /etc/cgrules.conf
#*:ls       cpu             strom/%u
#*:sleep    memory          les/%g

$ cat /etc/cgrules.d/cgrules1.conf
*:ls       cpu             strom/%u

$ cat /etc/cgrules.d/cgrules2.conf
*:sleep    memory          les/%g

plus cgconfig.[c|d/*] files:
$ cat /etc/cgconfig.conf
mount {
        cpuset  = /cgroup/cpuset;
        cpu     = /cgroup/cpu;
        cpuacct = /cgroup/cpuacct;
        memory  = /cgroup/memory;
        devices = /cgroup/devices;
        freezer = /cgroup/freezer;
        net_cls = /cgroup/net_cls;
        blkio   = /cgroup/blkio;
}

$ cat /etc/cgconfig.d/small.conf
template strom/%u {
        cpu {}
}

group vetev {
        cpu {}
}

$ cat /etc/cgconfig.d/medium.conf
template les/%g {
        memory {}
}

group drevo/listi {
        memory {}
}

Tested to cache reload as well by sending SIGUSR2 signal to running
cgrulesengd process. After first reload I commented out all rules => no
rules match after invoking ls command. After second reload I uncommented
out ls rule => rule match after invoking ls command. After third reload
I uncommented out ls and sleep rule => debug output of cgrulesengd shows
both rules loaded in the cache

Changelog:
* CGROUP_PARSE_STATE_UNLOCK removed
* reformulation of comment to "Cannot read directory. However,
  CGRULES_CONF_FILE is succesfully parsed. Thus return as a success for
  back compatibility."
* errno = 0 removed, once it is not zero, function returns, so need to set
  it to 0 in every iteration
* fprintf replaced by cgroup_err
* added missing unlocks + new label unlock_list for all returns

This
- * finds a rule matching the given UID or GID.  It will store this rule in rl,
+ * finds a rule matching the given UID or GID.  It will store this rule in trl,
is valid correction. "It will store this rule in rl" talks about cache being
disabled. In this case, it is  stored into trl.

Signed-off-by: Jan Chaloupka <jchaloup@redhat.com>
Acked-by: Ivana Hutarova Varekova <varekova@redhat.com>
src/api.c
src/libcgroup-internal.h