libct/cg: introduce and use fscommon.OpenFile#2635
Merged
mrunalp merged 4 commits intoopencontainers:masterfrom Oct 23, 2020
Merged
libct/cg: introduce and use fscommon.OpenFile#2635mrunalp merged 4 commits intoopencontainers:masterfrom
mrunalp merged 4 commits intoopencontainers:masterfrom
Conversation
4 tasks
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 -- previously, 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>
f1303ed to
002c92f
Compare
AkihiroSuda
reviewed
Oct 6, 2020
AkihiroSuda
approved these changes
Oct 9, 2020
mrunalp
approved these changes
Oct 23, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is part III from #2598, preparing the code to use
openat2()Move the functionality of opening a cgroup file into a separate
function,
OpenFile, which, similar toReadFileandWriteFile,use separate dir and file arguments.
Change
ReadFileandWriteFileto rely onOpenFile, and use lower-levelread and write instead of ones from ioutil.
It changes the semantics of
WriteFilea bit -- it no longer usesO_CREATflag. This is good for real cgroup as there is no need to trycreating the files in there, but can potentially break WriteFile users
-- previously,
EPERMerror was returned for non-existing files, andnow 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.WriteFiledo not create or truncate files, so we have to add avariable that is set by the unit tests to emulate the old behavior.
Use the new interface where possible.