buffer_head的同步问题请教
buffer_head是通过lock标志来同步的吗?我想实现以下目标:
在模块中申明一个buffer_head,存放自己的数据,然后在my_make_request()中先通过generic_make_request()完成此buffer_head的读写;当监测到buffer_head的buffer_locked(buffer_head)=0时再完成其它的请求.
代码框架如下:
static int hdpro_make_request(request_queue_t *q, int rw, struct buffer_head *bh)
{
..........................................
//flagbh为我自己申明的buffer_head,在模块初始化时已经通过
do {
flagbh = kmem_cache_alloc(bh_cachep, SLAB_NOIO);
if (flagbh)
break;
run_task_queue(&tq_disk);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ);
} while (1);分派了
flagbh->b_rdev=; //真实设备号
flagbh->b_blocknr=; //逻辑块号
flagbh->b_rsector=; //真实设备上的块号
flagbh->b_size=512; //缓冲区大小
flagbh->b_data=mybuffer; //数据区
flagbh->b_state=(1 << BH_Req)|(1 << BH_Mapped)|(1 << BH_Lock);//缓冲区状态
flagbh->b_dev=; //逻辑设备号
generic_make_request(READ,flagbh); //
generic_make_request(rw,bh);
return 0;
}
我这样做,插入模块操作时提示错误: NULL pointer,具体的dmesg显示是bh_action()->...->generic_make_request()错.请大家帮忙分析一下,或给个更好的实现方法.3X there are so many fields in bh, so if u want to allocate u own one, u had better set most of the fields. how u detect the lock=0? polling? will be slow. u may want to check md code, for example, raid1 mirroring, for each write request from upper layer, there are two bh in md for two devices, i read that code long ago and already froget the detail workflow. but md code is a good example on how to oeprate on bh structure. Dragonfly,你说的我明白,我现在已经实现了一个虚拟驱动,在my_make_request(q,rw,rbh)像md中那样实现了映射.我现在想增加以下功能:在my_make_request()中操作rbh以前先载入(即从磁盘上读入)其所标识的数据块的位图(自己建立的).所以我才想到要建立一个自己的buffer_head,还有就是想在位图载入完成后才开始rbh的操作,即同步操作.能否实现呢?我感觉好像不行 u can not sleep in my_make_request. so u can not use simple wait till finish method. u have to do async operation. basically u need to generate a new op to read that bitmap, and mark the current bh to let it come again later, and in the end handler of u read bitmap bh, update a global flag to know data is ready, u also need a kind of hash tabel to save the bitmap u read... trouble.
btw, recently there are sb ask me bh question in email, why so many people have interest on it now? :-D
页:
[1]