rpm2cpio kernel-3.10.0-957.el7.src.rpm |cpio -div xz -d linux-3.10.0-957.el7.tar.xz cd linux-3.10.0-957.el7/drivers/block/
默认编译不会通过 报错如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
[root@lab201 block]# make CONFIG_BLK_DEV_NBD=m -C /lib/modules/3.10.0-957.el7.x86_64/build M=`pwd` modules make: Entering directory `/usr/src/kernels/3.10.0-957.el7.x86_64' CC [M] /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/floppy.o CC [M] /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/brd.o CC [M] /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/loop.o CC [M] /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/pktcdvd.o CC [M] /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/osdblk.o CC [M] /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/nbd.o /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/nbd.c: In function ‘__nbd_ioctl’: /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/nbd.c:619:19: error: ‘REQ_TYPE_SPECIAL’ undeclared (first use in this function) sreq.cmd_type = REQ_TYPE_SPECIAL; ^ /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/nbd.c:619:19: note: each undeclared identifier is reported only once for each function it appears in make[1]: *** [/root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/nbd.o] Error 1 make: *** [_module_/root/rbd/kernel/linux-3.10.0-957.el7/drivers/block] Error 2 make: Leaving directory `/usr/src/kernels/3.10.0-957.el7.x86_64'
修改代码 增加下面内容 这个是从../../include/linux/blkdev.h里面提取的
1 2 3 4 5 6 7 8 9
mutex_lock(&nbd->tx_lock); blk_rq_init(NULL, &sreq); #ifdef __GENKSYMS__ REQ_TYPE_SPECIAL, /* driver defined type */ #else REQ_TYPE_DRV_PRIV, /* driver defined type */ #endif sreq.cmd_type = REQ_TYPE_SPECIAL; nbd_cmd(&sreq) = NBD_CMD_DISC;
修改makefile
1 2 3 4 5 6 7 8
[root@lab201 block]# cat Makefile # # Makefile for the kernel block device drivers. # # 12 June 2000, Christoph Hellwig <[email protected]> # Rewritten to use lists instead of if-statements. # obj-$(CONFIG_BLK_DEV_NBD) += nbd.o
只保留一个需要的
再次编译
1 2 3 4 5 6 7
[root@lab201 block]# make CONFIG_BLK_DEV_NBD=m -C /lib/modules/3.10.0-957.el7.x86_64/build M=`pwd` modules make: Entering directory `/usr/src/kernels/3.10.0-957.el7.x86_64' Building modules, stage 2. MODPOST 1 modules CC /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/nbd.mod.o LD [M] /root/rbd/kernel/linux-3.10.0-957.el7/drivers/block/nbd.ko make: Leaving directory `/usr/src/kernels/3.10.0-957.el7.x86_64'