-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Anolis OS in a more elegant way #1368
Conversation
This commit is tested under kernel 5.10.134-14.an8.x86_64. Anolis kernel. In my commit, I dont change the original command because this is the bug of an8(Anolis kernel),but not the bug of yum downloader. |
kpatch-build/kpatch-build
Outdated
@@ -65,6 +65,15 @@ LLD="${CROSS_COMPILE:-}ld.lld" | |||
READELF="${CROSS_COMPILE:-}readelf" | |||
OBJCOPY="${CROSS_COMPILE:-}objcopy" | |||
|
|||
SUPPORTED_DISTRO=" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make it plural: SUPPORTED_DISTROS. Or even better, SUPPORTED_RPM_DISTROS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your patient review, I have move this variable to SUPPORTED_RPM_DISTROS.
kpatch-build/kpatch-build
Outdated
centos | ||
openEuler | ||
photon | ||
Anolis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be lowercase: anolis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This problme is fixed associated shell return value bug.
kpatch-build/kpatch-build
Outdated
@@ -649,6 +658,26 @@ module_name_string() { | |||
echo "${1//[^a-zA-Z0-9_-]/-}" | cut -c 1-55 | |||
} | |||
|
|||
is_supported_distro(){ | |||
distro=$1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a local variable: "local distro=$1"
kpatch-build/kpatch-build
Outdated
return 1; | ||
fi | ||
done; | ||
return 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return values are backwards. Bash functions return 0 for "true" and 1 for "false". This only works because "anolis" != "Anolis" so the two bugs cancel each other out :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for catching this bug....lol... I fix it in the new commit, please review it when you are free. Thanks~~
kpatch-build/kpatch-build
Outdated
if [[ $distro == $each_distro ]]; then | ||
return 1; | ||
fi | ||
done; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary semicolon (here and elsewhere)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, in my new commit, I deleted this unnecessary semicolon~~
kpatch-build/kpatch-build
Outdated
@@ -649,6 +658,26 @@ module_name_string() { | |||
echo "${1//[^a-zA-Z0-9_-]/-}" | cut -c 1-55 | |||
} | |||
|
|||
is_supported_distro(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ubuntu and debian are also supported, which isn't reflected here. Better to call it is_supported_rpm_distro()
or so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I move ubuntu and debian into SUPPORTED_RPM_DISTROS. The vmlinux location is different of these tow release. Therefore, I made some changes from line 901 to line 918. :-)
Please squash into a single commit and force push the branch to update the PR. Also, make sure "make check" works. Thanks. |
I am sorry for my limited experience. I had squash those two commit into single. And I use "make check" in local and seems to be good. Please review this commit to check if it is eligible. Thanks~~~ |
Hi @wardenjohn , Apologies for the long delay, I think everyone was busy with end of year holidays and festivities. For this commit, I think that leveraging Bash associative arrays would simplify the code even further. For example, the distribution and its description can be defined all in one place: declare -rA SUPPORTED_RPM_DISTROS=(
["anolis"]="Anolis OS"
["centos"]="CentOS"
["debian"]="Debian OS"
["fedora"]="Fedora"
["openEuler"]="OpenEuler"
["photon"]="Photon OS"
["rhel"]="RHEL"
["ubuntu"]="Ubuntu OS") Then verifying whether a given string matches a supported distribution key is a simple one line condition: is_supported_rpm_distro() {
[[ -v "SUPPORTED_RPM_DISTROS[$1]" ]]
} and printing out the distribution string need not be a full blown function, as it is also just a one liner: echo "${SUPPORTED_RPM_DISTROS[$DISTRO]} distribution detected" Finally, for the commit message, I would reduce it down to something like:
Notice:
PS - I'm confused by the "rpm" part of these changes. Neither Ubuntu or Debian are rpm-based distributions and if I read the changes correctly, lumping them into is_supported_rpm_distro() will introduce a behavioral change just before the call to print_supported_rpm_distro(). (Previously the script only executed this for Fedora, RHEL, OL, CentOS, openEuler, and Photon. Not Ubuntu or Debian.) I think a refactor will need to treat these two distribution lists separately, or simplify the supported distro variable to include all distributions and later check for non-rpm exceptions. |
@joe-lawrence Thanks~Your comment looks good to me. I will fix my commit ASAP : ) |
To the "rpm" distributions, this commit integrate the supported distributions. Therefore, I think rename SUPPORTED_RPM_DISTROS to SUPPORTED_DISTROS may be better. @jpoimboe |
@jpoimboe @joe-lawrence I had rename the SUPPORTED_RPM_DISTROS to SUPPORTED_DISTROS. And rewrite the commit log in the case you gave me. Now, I rebased my commit and push it again, please review my changes when you are free. Thanks~~ : ) |
kpatch-build/kpatch-build
Outdated
[[ "$DISTRO" = centos ]] && echo "CentOS distribution detected" | ||
[[ "$DISTRO" = openEuler ]] && echo "OpenEuler distribution detected" | ||
[[ "$DISTRO" = photon ]] && echo "Photon OS distribution detected" | ||
if is_supported_distro "$DISTRO"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following code only applies to RPM-based distros. So this will break debian/ubuntu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh~~I apologize for my carelessness! The previous code will break the judgment of debian/ubuntu.
Now I try an other way to fix this problem.
I declear a new list of SUPPORTED_RPM_DISTRO which exclude debian and ubunto while SUPPORTED_DISTRO contains all the supported distrobution.
Then, we just need to judge if this release is RPM-base or not.
For the print function, it can apply to all release, I think.
Please check my newer version of the commit. Thanks~~ :)
Taking a step back for a second, can you tell us more about Anolis (vs. OpenAnolis) distribution? If it's not a downstream respin of an existing, kpatch-supported distribution (like CentOS), then we should put it through the integration test paces before declaring support in kpatch-build. For example, is #1370 related to this distro? |
#1370 is not related to this distro. Anolis is OpenAnolis distribution which is a linux kernel based distribution. I just call it Anolis becase I watched the /etc/os-release, it id is "anolis" and its name is "Anolis OS". The description from /etc/os-release is as follows: For this kernel packages, you can visit this link: https://mirrors.openanolis.cn/anolis/23/os/x86_64/os/Packages/ |
To #1370 , I should mention the background of this issuse. This is a kernel built by my colleague using -fPIE feature, leading to the unsupported relocation type to kpatch. For this issuse, I want to know what should I do to support R_X86_64_GOTPCREL becase kpatch do not consider this relocation type's offset or addend. This feature is not support by upstream kernel. So, I asked for help. This issuse have nothing about Anolis(OpenAnolis) kernel. I am sorry my description makes you confused. |
Ah ok, thanks for the explanation of Anolis. For this MR, it would probably be cleaner to split it into two commits: 1) refactor the code, and 2) add Anolis. I think the last push for this MR drops "Oracle Linux" from the list of rpm distros, so we can see how annoying the original code can be. Here's what (1) might look like (completely untested): fcf58ad Note that I didn't have to re-indent or move around any of the conditionally blocked code... this refactoring only abstracts out those big A follow up commit (2) should add the Anolis entry to the
Does that mean Anolis requires a special yumdownloader invocation? Or can it be configured with the repofrompath option somehow? If not, we may also need to (2) to add a special Anolis case under "Downloading kernel source for $ARCHVERSION" to do this for the user. |
OK, split this commit into two commits is fine. I found the commit fcf58ad divide the supported distro into deb/rpm distrobution. Is deleting the SUPPORTED_DISTRO which contains all supported distribution a good idea? SUPPORTED_DISTRO show all the supported distribution of kpatch, and we can simply reuse the same print function. For deb judgment, we can move it into SUPPORTED_DEB_DISTRO for its condiction. For the |
Ideally we could have something like: declare -rA SUPPORTED_DEB_DISTROS=(
...
declare -rA SUPPORTED_RPM_DISTROS=(
...
# Full support list is the union of rpm and deb based arrays
declare -rA SUPPORTED_DISTROS=( SUPPORTED_RPM_DISTROS SUPPORTED_DEB_DISTROS ) but unfortunately it seems that bash does not support copying associative arrays so easily. So what do do?
is_supported_distro() {
is_supported_deb_distro "$1" || is_supported_rpm_distro "$1"
} Re: common print function - just needs to check each array, like: print_supported_distro() {
local full_distro
if is_supported_deb_distro "$DISTRO"; then
full_distro="${SUPPORTED_DEB_DISTROS[$DISTRO]}"
elif is_supported_deb_distro "$DISTRO"; then
full_distro="${SUPPORTED_RPM_DISTROS[$DISTRO]}"
else
full_distro="Unsupported ${DISTRO}"
fi
echo "${full_distro} distribution detected"
} Re: |
572c8a9
to
bbceedc
Compare
I agree with this commit. Since nowhere kpatch-build actually need to check against the full support list, I use SUPPORTED_RPM_DISTRO and SUPPORTED_DEB_DISTRO separately. I divided the original commit into 2 commits while the 2th commit is used to add the support of Anolis OS. What's more, I found I broke the support of Oracle. I fix it in my newer commit. For the print function, the name still Please review my newer commit. Thanks ~~ :) |
Hi @wardenjohn : my turn to apologize for breaking something :) Our internal integration tests failed on rhel-7.9 for the latest PR push. Looking into it, the associative array key check I suggested for the is_supported_deb|rpm_distro() functions don't work for older versions of bash. Newer versions are ok: (fedora 37) $ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-redhat-linux-gnu)
(fedora 37) $ declare -rA SUPPORTED_RPM_DISTROS=( ["rhel"]="RHEL" )
(fedora 37) $ [[ -v "SUPPORTED_RPM_DISTROS[rhel]" ]] && echo "supported"
supported Older 4.2 based versions are not: (rhel-7.9) $ bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
(rhel-7.9) $ declare -rA SUPPORTED_RPM_DISTROS=( ["rhel"]="RHEL" )
(rhel-7.9) $ [[ -v "SUPPORTED_RPM_DISTROS[rhel]" ]] && echo "supported" That said, we could use
Apologies about that, I should have tried this out on the older bash version before suggesting it. |
@joe-lawrence : I am sorry for not finding out this problem in older version of bash for lacking testing environment...lol. Thank you for pointing out this potential problem. I have followed your suggestion and fix it in the newer commit. Please double check my submission to prevent any undiscovered issues. This commit is tested on I found that the previous version you mentioned about associative array key check is supported in bash version 4.4.20 cause the environment I tested is under this version...lol. |
Alright, I think the internal tests were happier with the latest push. A few small nitpicks and maybe @jpoimboe has some final review comments?
to:
it's probably effectively equivalent, but if so, why not just leave the existing conditional in place, only replace the "fedora, rhel, et. al" with the rpm_distro check and likewise for the deb based ones:
It would simplify the diff and the review.
Thanks for iterating on this one! |
Rather than adding yet another set of conditionals to handle the Anolis OS distribution, refactor the SUPPORTED_DISTROS code using an associative array. The array is keyed by the short distro name, and contains the longer distribution description. Signed-off-by: Wardenjohn<[email protected]>
Support Anolis OS Signed-off-by: Wardenjohn<[email protected]>
@joe-lawrence : OK, to your further suggestion, I make some changes: 2: I have sort the key in order. (see the newer commit) 3: Space indentation in the is_supported_distro functions is replaced by tab. 4: I add the dependencies code to lib. However, to enable yum download the kernel package successfully. Users may should enable the yum repo in /etc/yum.repo.d. So, please review my commit again. Thanks~ :) |
There are many different distribution of linux kernel. However, it may not be good to support one new distribution just by adding a judgment condition. Therefore, I move it into a function. In the future, if a new distribution need to be supported, it may be more elegant.