Commit Graph

17 Commits

Author SHA1 Message Date
Kir Kolyshkin be1d5f83c0 ci: enable unconvert linter, fix its warnings
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-07-07 10:42:48 -07:00
Kir Kolyshkin adbac31d88 libct: fix errorlint warning about strconv.NumError
This one is tough as errorlint insists on using errors.Is, and the
latter is known to not work for Go 1.13 which we still support.

So, add a nolint annotation to suppress the warning, and a TODO to
address it later.

For intelrdt, we can do the same, but it is easier to reuse the very
same function from fscommon (note we can't use fscommon for other stuff
as it expects cgroupfs).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 16:09:47 -07:00
Kir Kolyshkin f813174d5e libct/cg/fscommon: introduce and use ParseError
1. Introduce ParseError type as a way to unify error messages related to
   file parsing. Use it from GetCgroup* functions.

2. Do not discard the error from strconv.Parse{Int,Uint} -- it contains
   the value being parsed, and the details about the error.

2. As the error above already contains the value, drop it from format.

[v2: use path.Join in Error]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:52:26 -07:00
Kir Kolyshkin fdf4e90e89 libct/cg/fscommon.ParseKeyValue: no need to wrap err
The error returned from strconv.ParseUint is already pretty descriptive,
something like:

	strconv.ParseUint: parsing "000d": invalid syntax

So, there is no need to add more context to it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:42:59 -07:00
Kir Kolyshkin 242b3283fd libct/cg/fscommon: rm unused var
It is not used since commit 494f900e91

Fixes: 494f900e91
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-22 11:42:00 -07:00
Kir Kolyshkin d7fc302860 libct/cg/fs*: mark {Open,Read,Write}File as deprecated
... and switch to using the ones from cgroups.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-13 17:17:48 -07:00
Kir Kolyshkin 8f1b4d4a6f libct/cg: mv fscommon.{Open,Read,Write}File to cgroups
This is a better place as cgroups itself is using these.
Should help with moving more stuff common in between fs and fs2 to
fscommon.

Looks big, but this is just moving the code around:

 fscommon/{fscommon,open}.go -> cgroups/file.go
 fscommon/fscommon_test.go   -> cgroups/file_test.go

and fixes for TestMode moved to a different package.

There's no functional change.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-13 12:38:21 -07:00
Kir Kolyshkin e6048715e4 Use gofumpt to format code
gofumpt (mvdan.cc/gofumpt) is a fork of gofmt with stricter rules.

Brought to you by

	git ls-files \*.go | grep -v ^vendor/ | xargs gofumpt -s -w

Looking at the diff, all these changes make sense.

Also, replace gofmt with gofumpt in golangci.yml.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-06-01 12:17:27 -07:00
Kir Kolyshkin 9fa65f6607 libct/cg/fscommon: add GetValueByKey
Generalize the libct/getValueFromCgroup() as fscommon.GetValueByKey(),
and document it.

No changes other than using fscommon.ParseUint to convert the value.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Kir Kolyshkin 494f900e91 libct/cg/fscommon: rename/facelift GetCgroupParamKeyValue
1. This is the only function in the package with Get prefix
   that does not read a file (but parses a string). Rename
   accordingly, and convert the callers.

	GetCgroupParamKeyValue -> ParseKeyValue

2. Use strings.Split rather than strings.Fields. Split by a space
   is 2x faster, plus we can limit the splitting. The downside is
   we have to strip a newline in one of the callers.

3. Improve the doc and the code flow.

4. Fix a test case with invalid data (spaces at BOL).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-23 16:11:55 -08:00
Piotr Wagner ab27e12ceb Implement GetStat for cpuset cgroup.
Co-authored-by: Piotr Wagner <piotr.wagner@intel.com>
Signed-off-by: Paweł Szulik <pawel.szulik@intel.com>
2021-01-19 18:02:11 +01:00
Sebastiaan van Stijn b3a8b0742c libcontainer: prefer bytes.TrimSpace() over strings.TrimSpace()
Perform trimming before converting to a string, which should be
somewhat more performant.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-10-01 18:36:53 +02:00
Kir Kolyshkin 6c83d23ffc libcontainer/cgroups/fscommon: improve doc
Document ReadFile and WriteFile. Fix doc for ParseUint to be in
canonical form.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-29 11:58:14 -07:00
Kir Kolyshkin 31f0f5b7e0 libct/cg/fscommon.GetCgroupParamUint: improve
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>
2020-09-29 11:58:14 -07:00
Kir Kolyshkin e76ac1c054 libct/cg/fscommon.GetCgroupParamString: use ReadFile
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>
2020-09-29 11:58:14 -07:00
Kir Kolyshkin aac4d1f5c3 libct/cg/fscommon/GetCgroupParamKeyValue: nits
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>
2020-09-29 11:57:49 -07:00
Akihiro Suda 88e8350de2 cgroup2: split fs2 from fs
split fs2 package from fs, as mixing up fs and fs2 is very likely to result in
unmaintainable code.

Inspired by containerd/cgroups#109

Fix #2157

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2019-12-06 15:42:10 +09:00