lvmteam / lvm2

Mirror of upstream LVM2 repository
https://gitlab.com/lvmteam/lvm2
GNU General Public License v2.0
133 stars 73 forks source link

lib/cache_segtype/cache.c scans for the symbol smq_exit, but this symbol is not present if smq is compiled into the kernel #138

Closed soulsource closed 8 months ago

soulsource commented 10 months ago

I might misunderstand something, so, sorry in advance if this is the case here.

I think there is a bug in the code that checks if modprobe should be skipped, by looking at the symbols built into the kernel. For the dm-cache-smq module this code tries to find the smq_exit symbol, and if this symbol is found in the kernel, it skips the modprobe.

I just checked my /proc/kallsyms file and there is no symbol named smq_exit in my kernel. I am 100% certain that smq is compiled into the kernel, and related symbols like smq_init are indeed present.

My knowledge of the kernel build process is limited, but since the smq_exit function has no usages if the driver is built directly into the kernel, and is marked as static, the compiler probably removes it during optimization.

If I understood this correctly, I would suggest to change the _features array in the _target_present function in lib/cache_segtype/cache.c to check for another symbol from smq, maybe smq_init.

zkabelac commented 9 months ago

Pushed upstream this fix:

https://gitlab.com/lvmteam/lvm2/-/commit/d19235993e1aac7befe19beb4a274b56a9ab4def

Which should be possibly solving the issue with built-in module better as parsing kallsyms takes quite some times. So please check upstream head whether this solves the problem for your systems.

soulsource commented 8 months ago

Sorry for the late reply.

I think this issue can be closed then, as it is no longer applicable to the latest version.

I have one (small) remark however: The new code relies on the presence of the /lib/modules directory, while the previous code only relied on kernel virtual file systems. This could render existing initramfs images un-bootable. I stumbled across the missing symbol when I worked a minimal initramfs, and got error messages about a missing modprobe executable. That was why I started digging in the lvm source code to find out why it would even try to call modprobe, even though I had built all required modules into the kernel.

Thinking a bit more about this, I am now slightly confused, because I would expect module_present() to find the /sys/module/dm_cache folder before even reaching the part that calls modprobe...

zkabelac commented 8 months ago

The reason, why there is no 'dm_cache' module entry is - that this module doesn't have any parameter - so it will not have anything there for 'compiled-in' version - which then leads to these unrortunate hacks.

And yes - I've considered the case of missing these files in ramdisk - but that should be seen as pure bug on 'ramdisk' building software - as other tools like modprobe simply do rely on this file.

Also whoever is 'minimazing' ramdisk in such an obscure way to drop failrly minimalistic files - is likely not in the position of using cache anyway - so overal the performance gains from parsing just this file over parsing 9M strings... was clear win here...