chcpu: refactor#4396
Draft
cgoesche wants to merge 11 commits into
Draft
Conversation
This patch makes it possible to configure the CPUs on a Linux system other than the one on which the chcpu command is called. To achieve this users can simply define the root directory of the sys/ directory with the --sysroot command line option. It is also beneficial for regression tests, as these make use of sysfs tar archive dumps. To properly implement this new feature, the syspath initialization had to be deferred until after all option arguments, especially --sysroot, have been parsed, which simplified the path access check. Along the way a small refactoring of the enable,disable,configure & deconfigure option parsing had been done, more precisely the CPU list option argument is now saved in a variable 'cpu_list_arg' to defer the CPU list validity check until after all option arguments have been parsed to simplify the logic. Lastly, getopt(3)'s 'optarg' variable is used instead of argv[optind-1] to store the options argument, which is more idiomatic and readable. Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Previously, cpu_enable() and cpu_configure() compared the number of fails with ctx->maxcpus and if equal it returned -1, which culminated over to an exit code of 1 (failure). Otherwise, if there were fails but less than ctx->maxcpus the fucntions return code 1 would result in an exit code 64 indicating partial success. Since ctx->maxcpus describes the maximum number of CPUs supported by the kernel, in practice, this failure mode isn't really useful as it means that a user would need to fail the configuration of every possible CPU. This is why chcpu(8) almost always returns 64. It is better to store the actual amount of requested CPUs and then compare the amount of fails to it and provide more meaningful exit codes. Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Let's stay consistent with the function contract and return -1 and print a warning with warn[x]() in case of failure. Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
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 a temporary copy of my
chcpu_testsbranch which saved the refactor work and bug fixes that were initially added to PR #4390 . However, as suggested by @karelzak it is better to keep it simple and introduce these fixes in another iteration. Once the initial PR is merged, this branch will be rebased and commits will be adjusted accordingly to properly implement the changes.