问题
Im wrinting a kernel module and i found a problem testing my LKM again centos 7.
uname -a print 3.10.0-123.13.2.el7.x86_64, and i'm compiling my KM with this kernel-headers /usr/src/kernels/3.10.0-123.13.2.el7.x86_64/ and using LINUX_VERSION_CODE to define my code sections.
my problem is, the compilation fail because the kernel-headers include code added in more new kernel version but LINUX_VERSION_CODE returns 3.10.
for example, nf_hookfn was modify in kernel 3.13 and i have this modification already in my headers.
what can i do?
回答1:
the LINUX_VERSION_CODE
return the Linux version 3.10 and not the CentOS Linux version 3.10.0-123.13.2.el7. Theoretically, they should not apply patch with API changes ... you just discovered the reason :)
If on CentOS is possible to change stable API, they should provide something similar to LINUX_VERSION_CODE
for CentOS.
You can define your own pre-processor variable and at compile-time assert or de-assert it according to the kernel version that you want to use (standard 3.10 or CentOS 3.10)
#ifdef CENTOS_PATCH /* CentOS 3.10 */
....
#else /* Standard 3.10 */
....
#endif
But then you have to manage two different binaries
回答2:
Centos provides some useful macro for that purpose:
#if RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(7,2)
//
#else
//
#endif
And yep, Centos custom kernel pull up some changes from recent Linux kernels.
来源:https://stackoverflow.com/questions/27761061/understanding-linux-version-code