Don't think this particular patch is good or useful.
Have you ever built Lustre in a "clean-room" (i.e. with mock)? That's one case where it's useful.
To be contrarian, does adding another element to the list of places searched for kernel source cause any harm?
In the common case where links in /lib/modules are missing and it would go to picking one from /usr/src/kernels, the one it picks is fairly arbitrary.
It's not actually. Even in the case of there being multiple entries in /usr/src/kernels/ – which I don't think is actually all that common at all for the use-cases that this patch is targeting – but in any case, it will pick the highest versioned kernel, which seems like the least surprising choice to me. If that is not what the user wants, then he can still use --with-linux to point at the one he wants, but using the most recent seems like a reasonable default when all other selection mechanisms have been exhausted.
It isn't the case that there is only one most of the time.
Even in environments where all of the other search locations have not found kernel source? I am doubtful that your assertion is true. I suspect environments that this patch is targeting are few and are particular, typically about clean-room isolated build environments.
If you must pick from there it would be better to first look for a match on 'uname -r',
As has been discussed previously in this ticket, if there was a match for $(uname -r) then the targeted kernel is what would be installed and booted already and the /lib/modules/$(uname -r)/{build,source} symlinks would be present. This patch is specifically targeting build environments where the booted kernel (the one that responds to $(uname -r)) is not the kernel you want to build for in your build chroot.
In general I think putting in appropriate symlinks in /lib/modules as Dmitry suggests even if the correct kernel-devel isn't installed would be better.
In a "clean-room" build system (or BaaS – Builder as a Service) you are usually not allowed to mess with the "clean" room.
btw, kernel-devel of pristine, unpatched upstream linux is insufficient for building ldiskfs. In RHEL distros it doesn't include ext4 sources, needed for building ldiskfs. kernel source or debuginfo is needed
This is not for building patched servers. It's for building the patchless client.
On a test with symlinks deleted from /lib/modules to see what would happen this patch doesn't even work. I get the following failure:
Bah. Good catch. That was due to an unfortunate nastiness with m4 macros. I've updated the patch. Now I get this:
It appears the current logic looks in /usr/src/linux first and if there is no such dir it doesn't even get as far as looking in /usr/src/kernels.
That's not how the code reads:
for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux $(find /usr/src/kernels/ -maxdepth 1 -name [0-9]\* | xargs -r ls -d | tail -n 1); do
AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
done
That says to iterate through the list of /lib/modules/$(uname -r)/{source,build} /usr/src/linux $(find /usr/src/kernels/ -maxdepth 1 -name [0-9]* | xargs -r ls -d | tail -n 1) and stop (break) when a list item is valid. If /usr/src/linux is not valid, whatever $(find /usr/src/kernels/ -maxdepth 1 -name [0-9]* | xargs -r ls -d | tail -n 1) evaluates to will be tried next.
removed unrelated gerrit upload message