模块编写的怪问题,请大家帮个忙!
我遇到的怪问题:我写了一个模块,功能是替换指定块设备的请求处理函数.
在模块初始化时,通过如下函数实现
blk_queue_make_request(BLK_DEFAULT_QUEUE(3),own_make_request);
blk_queue_make_request(BLK_DEFAULT_QUEUE(2),own_make_request);
3是ide0的主设备号,2是软盘的主设备号
结果是:只有对软盘操作时显示我的请求函数被调用了,但是对ide0操作时没有显示我的请求处理函数被调用.
own_make_request()中有一些printk语句.
我觉得不可理解:若是程序写的不对的话,则应该对软盘操作时也无效;现在只是对ide0无效,请大家指点一下,
是否我需要一些别的设置才能对ide0起作用.
在几台机器上测试,都是如此,环境Redhat8,内核2.4.18-14 :cry: try to replace a sd device, and use scsi_debug as a fake scsi device if u do not have real scsi device.
yes, it is strange, but i always succ because i never replace the ide, i always work on my own block device with own number. 我没有用过SCSI设备,现在用scsi_debug模拟的话,我显式的把/lib/modules/2.4.18-14/kernel/drivers/scsi/下的scsi_mod.o和scsi_debug.o插入,但是从/proc/devices中看不到有SCSI设备产生,从dmesg看到
scsi : 0 hosts left.
SCSI subsystem driver Revision: 1.00
scsi0 : scsi_debug, Version: 0.58 (20020302), num_devs=1, dev_size_mb=8, opts=0x0
Vendor: Linux Model: scsi_debug Rev: 0003
Type: Direct-Access ANSI SCSI revision: 03
Attached scsi disk sda at scsi0, channel 0, id 0, lun 0
SCSI device sda: 16384 512-byte hdwr sectors (8 MB)
sda: unknown partition table
所以mkfs -t ext2 /dev/sda
然后在/proc/devices中就会显示
8sd
65 sd
66 sd
然后在我的模块中blk_queue_make_request(BLK_DEFAULT_QUEUE(8),own_make_request);
blk_queue_make_request(BLK_DEFAULT_QUEUE(65),own_make_request);
blk_queue_make_request(BLK_DEFAULT_QUEUE(66),own_make_request);
结果还是没有效果,是否scsi_debug设备的实现不通过__make_request() no, all block devices go through this part.
240 void blk_queue_make_request(request_queue_t * q, make_request_fn * mfn)
241 {
242 q->make_request_fn = mfn;
243 }
244
195 #define BLK_DEFAULT_QUEUE(_MAJOR)&blk_dev.request_queue
so u can handle them directly. save old one to a pointer, replace with u new one, and restore when u finish u handling. 我就是这么做的,但是问题依旧!一位网友说他已经实现了这种对IDE硬盘的控制,就是用我说的这种方法.
只可惜他不愿详细指点.我真是快郁闷死了. send me your code (everything, .c .h and makefile, then i can compile and debug it) in a tgz file via [email protected]
i will try to have a look but i am not sure when i can find time.:-D
页:
[1]