libct/cgroups/fscommon: add openat2() support#2598
Conversation
|
Funny, |
d025fc2 to
a9e93d6
Compare
|
Just wanted to mentioned that my long-term plan is to make it easier to use openat2 for this use-case from userspace with libpathrs -- |
39a5c06 to
802f92e
Compare
|
Pushed a new patchset, slightly better organized/splitted, and with more users converted. Test failures are supposed to be fixed, too. At this point I'm thinking about maybe changing the whole libct/cg to use per-cgroup fd (rather than fd opened to /sys/fs/cgroup) and |
802f92e to
218cb7f
Compare
1. Don't reconstruct file name, use existing one since it's available. 2. Don't put file name when wrapping the error from ioutil.ReadFile since it already has it. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2. Fix wrapping the error to not have the value as it's already part of the error returned from ParseUint. 3. Fix/improve doc. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1. Use own ReadFile wrapper instead of ioutils.ReadFile. This makes it use the security measures of ReadFile. 2. Improve doc. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1. Use GetCgroupParamString as the initial part of both functions are the same and we can reuse it. This also gives us whatever security measures GetCgroupParamString has (see previous commit). 2. Fix the error wrapping to not add the value, as it is already a part of the error returned by ParseUint. 3. Improve docstring. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Document ReadFile and WriteFile. Fix doc for ParseUint to be in canonical form. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
fscommon.WriteFile is added specifically to work with cgroup files, and the error it returns does not need to be wrapped. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
fscommon's ReadFile and WriteFile are tailored to cgroupfs, so let's use them here. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
While at it, change some functions to not be methods of CpusetCgroup as they don't use any members. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
The code to find out memory cgroup root is not really needed, as 99% of test envrionments will have it at /sys/fs/cgroup/memory. If not, that means we're either on cgroupv2 or on some very custom system, so just skip the test. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This can easily be done on top of this one, so later. For now, I am going to split this into smaller more digestible PRs. |
218cb7f to
6fae524
Compare
Move the functionality of opening a cgroup file into a separate function, OpenFile, which, similar to ReadFile and WriteFile, use separate dir and file arguments. Change ReadFile and WriteFile to rely on OpenFile, and use lower-level read and write instead of ones from ioutil. It changes the semantics of WriteFile a bit -- it no longer uses O_CREAT flag. This is good for real cgroup as there is no need to try creating the files in there, but can potentially break WriteFile users -- previosly, EPERM error was returned for non-existing files, and now it's ENOENT. This also breaks the fs/fs2 unit tests since they write to pseudo-cgroup files inside a test directory (not to a real cgroup fs), and now fscommon.WriteFile do not create or truncate files, so we have to add a variable that is set by the unit tests. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
...and drop os.O_CREATE|os.O_TRUNC as those are definitely not needed. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
In case openat2 is available, it will be used to guarantee that we're not accessing anything other than cgroupfs[2] files. In cases when openat2 is not available, or when cgroup has a non-standard prefix (not "/sys/fs/cgroup", might theoretically happen on some very old installs and/or very custom systems), fall back to using securejoin + os.Open like we did before. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
6fae524 to
9e448c9
Compare
|
needs rebase |
|
Closed as this is now splitted into
and the only last one is not yet merged |
This is a naive initial attempt to add openat2 support to libct/cgroups/fscommon, and switch libct/cgroups to use it.
This is now being split into a few more digestible PRs: