我修改了[linux-kernel-location]/block/blk-core.c(原始)的代码:
...
#include <custom/custom-buffer.h>
...
blk_qt_t submit_bio(int rw, struct bio *bio)
{
...
if(rw & WRITE)
{
unsigned long cntUnit = bio->bi_bdev->bd_super->s_blocks / bdev_logical_block_size(bio->bi_bdev);
unsigned long blk_no = bio->bi_iter.bi_sector / cntUnit;
count_vm_events(PGPGOUT, count);
custom_buf_write_blk_no(blk_no);
}
...
}
...
[linux-kernel-location]/block/Makefile (原链接):
请确认以上内容是否正确,谢谢!...
obj-y += custom/
[linux-kernel-location]/block/Kconfig (original):
...
source "block/custom/Kconfig"
我创建了目录[linux-kernel-location]/include/custom, [linux-kernel-location]/block/custom。接着,我创建了文件[linux-kernel-location]/include/custom/custom-buffer.h:
#ifndef _CUSTOM_BUFFER_H_
#define _CUSTOM_BUFFER_H_
extern int custom_buf_write_blk_no(unsigned long blk_no);
#endif
[linux-kernel-location]/block/custom/Makefile: (该文件路径)
obj-y += custom-buffer.o
[linux-kernel-location]/block/custom/Kconfig:
config CUSTOM_BUFFER
tristate
depends on BLOCK
default y
[linux-kernel-location]/block/custom/custom-buffer.c(包括使用EXPORT_SYMBOL
宏定义的custom_buf_write_blk_no(unsigned long blk_no)
)。
我在Linux内核位置的shell中输入了make
命令,得到了以下结果:
...
LD init/built-in.o
block/built-in.o: In function `submit_bio':
[linux-kernel-location]/block/blk-core.c:2117: undefined reference to `custom_buf_write_blk_no'
block/built-in.o:(___ksymtab+custom_buf_write_blk_no+0x0): undefined reference to `custom_buf_write_blk_no'
Makefile:927: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1
我的猜测是我需要修复Makefile,如何修复?
编辑:我也知道这是因为链接器在链接过程中找不到符号。但我不知道如何在Kbuild系统应用的Makefile中修复它。
自己解决:custom-buffer.c有一个错误的字母。我正确修复了它,所以编译成功了。
找错别字太难了...
CC block/custom/custom-buffer.o
、LD block/custom/built-in.o
和LD block/built-in.o
中,没有发生任何事情。但是在下一步LD init/built-in.o
中出现了一个错误。 - monadefgit clone --depth 1 --single-branch --branch v4.4 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
,添加了你描述的完全相同的文件。使用虚拟实现:int custom_buf_write_blk_no(unsigned long blk_no) { printk(KERN_INFO "WIP NUMBER %lu\n", blk_no); return 0; } EXPORT_SYMBOL(custom_buf_write_blk_no);
。它可以编译。 - Jakub Piskorz