sbull在新內核編譯

《linux設備驅動程序》(ldd3)中的實例程序是在linux-2.6.10版本內核中開發的,我的linux內核版本是linux-2.6.32.16,許多函數和結構都相對2.6.10發生了變化,所以必須自己對源碼進行修改。從oreilly官網download示例代碼,進入sbul文件夾,開始第一次make:結果如下:

root@ubuntu:/home/shevarey/ssdd/sbull# make
make -C /lib/modules/2.6.32.16/build M=/home/shevarey/ssdd/sbull modules
make[1]: Entering directory `/usr/src/linux-2.6.32.16'
scripts/Makefile.build:49: *** CFLAGS was changed in "/home/shevarey/ssdd/sbull/Makefile". Fix it to use EXTRA_CFLAGS. Stop.
make[1]: *** [_module_/home/shevarey/ssdd/sbull] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.32.16'
make: *** [default] Error 2

告訴我們用EXTRA_CFLAGS替代CFLAGS,打開Makefile,修改。再次make:

root@ubuntu:/home/shevarey/ssdd/sbull# make
make -C /lib/modules/2.6.32.16/build M=/home/shevarey/ssdd/sbull modules
make[1]: Entering directory `/usr/src/linux-2.6.32.16'
CC [M] /home/shevarey/ssdd/sbull/sbull.o
/home/shevarey/ssdd/sbull/sbull.c:5:26: error: linux/config.h: No such file or directory
/home/shevarey/ssdd/sbull/sbull.c:104: error: expected ')'before '*' token
/home/shevarey/ssdd/sbull/sbull.c: In function sbull_xfer_bio  

/home/shevarey/ssdd/sbull/sbull.c:138: error: implicit declaration of function bio_cur_sectors鈥?/home/shevarey/ssdd/sbull/sbull.c: In function sbull_xfer_request 
/home/shevarey/ssdd/sbull/sbull.c:154: error: implicit declaration of function rq_for_each_bio鈥?/home/shevarey/ssdd/sbull/sbull.c:154: error: expected ')' before '*'token
/home/shevarey/ssdd/sbull/sbull.c:152: warning: unused variable nrsect鈥?/home/shevarey/ssdd/sbull/sbull.c:159: warning: no return statement in function returning non-void
/home/shevarey/ssdd/sbull/sbull.c: At top level:
/home/shevarey/ssdd/sbull/sbull.c:166: error: expected ')'before '*' token
/home/shevarey/ssdd/sbull/sbull.c:191: error: expected ')'before '*' token
/home/shevarey/ssdd/sbull/sbull.c:316: warning: initialization from incompatible pointer type
/home/shevarey/ssdd/sbull/sbull.c:317: warning: initialization from incompatible pointer type
/home/shevarey/ssdd/sbull/sbull.c:321: warning: initialization from incompatible pointer type
/home/shevarey/ssdd/sbull/sbull.c: In function setup_device
/home/shevarey/ssdd/sbull/sbull.c:357: error: sbull_make_request undeclared (first use in this function)
/home/shevarey/ssdd/sbull/sbull.c:357: error: (Each undeclared identifier is reported only once
/home/shevarey/ssdd/sbull/sbull.c:357: error: for each function it appears in.)
/home/shevarey/ssdd/sbull/sbull.c:361: error: sbull_full_request undeclared (first use in this function)
/home/shevarey/ssdd/sbull/sbull.c:371: error: sbull_request undeclared (first use in this function)
/home/shevarey/ssdd/sbull/sbull.c:376: error: implicit declaration of function blk_queue_hardsect_size make[2]: *** [/home/shevarey/ssdd/sbull/sbull.o] Error 1
make[1]: *** [_module_/home/shevarey/ssdd/sbull] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.32.16'
make: *** [default] Error 2

1.刪除#include<linux/config>;

2.對於三處expected ')'before '*' token這個貌似語法錯誤的報錯困擾了我很久,觀察這三處錯誤,這三個函數都使用了request_queue_t*這個參數,對照2.6.10和2.6.32的源碼發現,在2.6.32中取消了typedef struct request_queue request_queue_t這個結構定義。那就自己在sbull.c源碼中加入這一句。

3.bio_cur_sectors不存在,在2.6.10源碼中發現這個宏的定義是#define bio_cur_sectors(bio) (bio_iovec(bio)->bv_len>>9),在2.6.32中已經刪除該宏,函數bio_cur_bytes返回bio_iovec(bio)->bv_len,所以將其改爲bio_cur_bytes(bio)>>9;

4.rq_for_each_bio未定義,發現改成了__rq_for_each_bio,修改之~;

此時這些錯誤已經修改完畢,重新make:

root@ubuntu:/home/shevarey/ssdd/sbull# make
make -C /lib/modules/2.6.32.16/build M=/home/shevarey/ssdd/sbull modules
make[1]: Entering directory `/usr/src/linux-2.6.32.16'
CC [M] /home/shevarey/ssdd/sbull/sbull.o
/home/shevarey/ssdd/sbull/sbull.c: In function sbull_request 
/home/shevarey/ssdd/sbull/sbull.c:109: error: implicit declaration of function elv_next_request

/home/shevarey/ssdd/sbull/sbull.c:109: warning: assignment makes pointer from integer without a cast
/home/shevarey/ssdd/sbull/sbull.c:113: error: implicit declaration of function end_request

/home/shevarey/ssdd/sbull/sbull.c:120: error: struct request has no member named sector

/home/shevarey/ssdd/sbull/sbull.c:120: error: struct request has no member named current_nr_sectors

/home/shevarey/ssdd/sbull/sbull.c: In function sbull_full_request

/home/shevarey/ssdd/sbull/sbull.c:173: warning: assignment makes pointer from integer without a cast
/home/shevarey/ssdd/sbull/sbull.c:180: error: implicit declaration of function end_that_request_first ?/home/shevarey/ssdd/sbull/sbull.c:181: error: implicit declaration of function

blkdev_dequeue_request

/home/shevarey/ssdd/sbull/sbull.c:182: error: implicit declaration of function 鈥榚nd_that_request_last鈥?/home/shevarey/ssdd/sbull/sbull.c: In function sbull_make_request /home/shevarey/ssdd/sbull/sbull.c:198: error: too many arguments to function io_endio

/home/shevarey/ssdd/sbull/sbull.c: At top level:
/home/shevarey/ssdd/sbull/sbull.c:317: warning: initialization from incompatible pointer type
/home/shevarey/ssdd/sbull/sbull.c:318: warning: initialization from incompatible pointer type
/home/shevarey/ssdd/sbull/sbull.c:322: warning: initialization from incompatible pointer type
/home/shevarey/ssdd/sbull/sbull.c: In function setup_devices

/home/shevarey/ssdd/sbull/sbull.c:377: error: implicit declaration of function blk_queue_hardsect_size

make[2]: *** [/home/shevarey/ssdd/sbull/sbull.o] Error 1
make[1]: *** [_module_/home/shevarey/ssdd/sbull] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.32.16'
make: *** [default] Error 2

1.elv_next_request不存在,改成了blk_fetch_request,有兩處,改之~

2.end_request,改成了blk_end_request_all,改之~

3.現在不能直接獲取request結構的sector和current_nr_sector;而是通過函數blk_rq_pos和blk_rq_cur_sectors獲得,所以將對用兩處改爲:

sbull_transfer(dev, blk_rq_pos(req), blk_rq_cur_sectors(req), req->buffer, rq_data_dir(req));

4.end_that_request_first,end_that_request_last,blk_dequeque_request已經不存在,被blk_fetch_request,blk_end_request_cur,blk_start_request代替所以要做一下修改在sbull_full_request中:

if (!__blk_end_request_cur(req, 0)) {
blk_start_request(req);
blk_fetch_request(q);

5.bio_endio參數過多,發現6.32.16中少了中間那個參數,去掉~

6.blk_queue_hardsect_size未定義,在2.6.10中找到定義,直接修改如下:

blk_queue_logical_block_size(dev->queue, hardsect_size);

make之後些許warning,執行insmod,出錯了,顯示blk_put_queue未定義,直接刪掉。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章