初涉Bcache(3)
这篇文章讲解如何编译bcache-tools与编译bcache.ko。
编译bcache-tools
第一步 下载源码
此处提供一处下载地址:git clone http://evilpiepirate.org/git/bcache-tools.git
第二步 make
[root@mongodb bcache-tools]# make
cc -O2 -Wall -g `pkg-config --cflags uuid blkid` -c -o bcache.o bcache.c
cc -O2 -Wall -g `pkg-config --cflags uuid blkid` make-bcache.c bcache.o `pkg-config --libs uuid blkid` -o make-bcache
cc -O2 -Wall -g `pkg-config --cflags uuid blkid` probe-bcache.c `pkg-config --libs uuid blkid` -o probe-bcache
cc -O2 -Wall -g -std=gnu99 bcache-super-show.c bcache.o `pkg-config --libs uuid` -o bcache-super-show
cc -O2 -Wall -g -c -o bcache-register.o bcache-register.c
cc bcache-register.o -o bcache-register
[root@mongodb bcache-tools]#
第三步 make install
[root@mongodb bcache-tools]# make install
install -m0755 make-bcache bcache-super-show /usr/sbin/
install -m0755 probe-bcache bcache-register /lib/udev/
install -m0644 69-bcache.rules /lib/udev/rules.d/
install -m0644 -- *.8 /usr/share/man/man8/
install -D -m0755 initramfs/hook /usr/share/initramfs-tools/hooks/bcache
install -D -m0755 initcpio/install /usr/lib/initcpio/install/bcache
install -D -m0755 dracut/module-setup.sh /lib/dracut/modules.d/90bcache/module-setup.sh
[root@mongodb bcache-tools]#
最后生成了四个工具:
make-bcache
bcache-register
bcache-super-show
probe-bcache
编译bcache.ko(此处以centos为例)
第一步 下载bcache内核源码
自行上网下载(无法找到,私信我)
第二步 解压源码包
[root@AutoCloud bcache]# tar -xf src_bache.tar.gz
[root@AutoCloud bcache]#
第三步 拷贝文件到指定目录
[root@AutoCloud src_bcache]# cp include/uapi/linux/bcache.h /usr/src/kernels/3.10.0-1127.el7.x86_64/include/uapi/linux/
[root@AutoCloud src_bcache]#
[root@AutoCloud src_bcache]# cp include/trace/events/bcache.h /usr/src/kernels/3.10.0-1127.el7.x86_64/include/trace/events/
cp: overwrite ‘/usr/src/kernels/3.10.0-1127.el7.x86_64/include/trace/events/bcache.h’? y
[root@AutoCloud src_bcache]#
第四步 生成Makefile
[root@AutoCloud src_bcache]# vi Makefile
KDIR:=/lib/modules/$(shell uname -r)/build
PWD:=$(shell pwd)/drivers/md/bcache
default:
$(MAKE) -e CONFIG_BCACHE=m -C $(KDIR) M=$(PWD) modules
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions *.order *symvers *Module.markers
第五步 make
[root@AutoCloud src_bcache]# make
make -e CONFIG_BCACHE=m -C /lib/modules/3.10.0-1127.el7.x86_64/build M=/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
make[2]: Entering directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/alloc.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/bset.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/btree.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/closure.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/debug.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/extents.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/io.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/journal.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/movinggc.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.o
In file included from /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/bset.h:8:0,
from /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/bcache.h:190,
from /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:9:
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c: In function ‘add_sequential’:
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:357:12: error: ‘struct task_struct’ has no member named ‘sequential_io_avg’
ewma_add(t->sequential_io_avg,
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/util.h:440:3: note: in definition of macro ‘ewma_add’
(ewma) *= (weight) - 1; \
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:357:12: error: ‘struct task_struct’ has no member named ‘sequential_io_avg’
ewma_add(t->sequential_io_avg,
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/util.h:441:3: note: in definition of macro ‘ewma_add’
(ewma) += (val) << factor; \
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:358:5: error: ‘struct task_struct’ has no member named ‘sequential_io’
t->sequential_io, 8, 0);
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/util.h:441:13: note: in definition of macro ‘ewma_add’
(ewma) += (val) << factor; \
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:357:12: error: ‘struct task_struct’ has no member named ‘sequential_io_avg’
ewma_add(t->sequential_io_avg,
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/util.h:442:3: note: in definition of macro ‘ewma_add’
(ewma) /= (weight); \
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:357:12: error: ‘struct task_struct’ has no member named ‘sequential_io_avg’
ewma_add(t->sequential_io_avg,
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/util.h:443:3: note: in definition of macro ‘ewma_add’
(ewma) >> factor; \
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:360:3: error: ‘struct task_struct’ has no member named ‘sequential_io’
t->sequential_io = 0;
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c: In function ‘check_should_bypass’:
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:425:6: error: ‘struct task_struct’ has no member named ‘sequential_io’
task->sequential_io = i->sequential;
^
In file included from include/asm-generic/bug.h:15:0,
from ./arch/x86/include/asm/bug.h:38,
from include/linux/bug.h:4,
from include/linux/thread_info.h:11,
from include/linux/preempt.h:9,
from include/linux/spinlock.h:50,
from include/linux/wait.h:7,
from include/linux/fs.h:6,
from include/linux/highmem.h:4,
from include/linux/bio.h:23,
from /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/bcache.h:181,
from /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:9:
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:433:20: error: ‘struct task_struct’ has no member named ‘sequential_i’
sectors = max(task->sequential_io,
^
include/linux/kernel.h:793:9: note: in definition of macro ‘max’
typeof(x) _max1 = (x); \
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:433:20: error: ‘struct task_struct’ has no member named ‘sequential_i’
sectors = max(task->sequential_io,
^
include/linux/kernel.h:793:21: note: in definition of macro ‘max’
typeof(x) _max1 = (x); \
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:434:13: error: ‘struct task_struct’ has no member named ‘sequential_io_avg’
task->sequential_io_avg) >> 9;
^
include/linux/kernel.h:794:9: note: in definition of macro ‘max’
typeof(y) _max2 = (y); \
^
/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.c:434:13: error: ‘struct task_struct’ has no member named ‘sequential_io_avg’
task->sequential_io_avg) >> 9;
^
include/linux/kernel.h:794:21: note: in definition of macro ‘max’
typeof(y) _max2 = (y); \
^
make[2]: *** [/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.o] Error 1
make[2]: Leaving directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
make[1]: *** [_module_/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache] Error 2
make[1]: Leaving directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
make: *** [default] Error 2
[root@AutoCloud src_bcache]#
直接编译发现错误,没有发现sequential_io_avg。如何解决呢?
编辑drivers/md/bcache/Makefile文件
[root@AutoCloud src_bcache]# vi drivers/md/bcache/Makefile
obj-$(CONFIG_BCACHE) += bcache.o
bcache-y := alloc.o bset.o btree.o closure.o debug.o extents.o\
io.o journal.o movinggc.o request.o stats.o super.o sysfs.o trace.o\
util.o writeback.o
CFLAGS_request.o += -Iblock -DCONFIG_BCACHE
加上-DCONFIG_BCACHE。
再进行编译
[root@AutoCloud src_bcache]# make
make -e CONFIG_BCACHE=m -C /lib/modules/3.10.0-1127.el7.x86_64/build M=/opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
make[2]: Entering directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/request.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/stats.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/super.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/sysfs.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/trace.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/util.o
CC [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/writeback.o
LD [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/bcache.o
make[2]: Leaving directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
Building modules, stage 2.
make[2]: Entering directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
MODPOST 1 modules
CC /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/bcache.mod.o
LD [M] /opt/zone/sdc1/bcache/src_bcache/drivers/md/bcache/bcache.ko
make[2]: Leaving directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
make[1]: Leaving directory `/usr/src/kernels/3.10.0-1127.el7.x86_64'
[root@AutoCloud src_bcache]#
发现编译成功了,让我们查看一下:
[root@AutoCloud src_bcache]# ls drivers/md/bcache/bcache.ko
drivers/md/bcache/bcache.ko
[root@AutoCloud src_bcache]#
总结
至此,此篇文章结束,希望大家有所收获。
注意:低版本bcache有挺多bug,可能导致系统崩溃,使用时注意。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)