QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 886|回复: 3

buffer_head的同步问题请教

[复制链接]
发表于 2003-9-2 13:18:23 | 显示全部楼层 |阅读模式
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
发表于 2003-9-3 11:28:40 | 显示全部楼层
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.
回复

使用道具 举报

 楼主| 发表于 2003-9-4 09:10:20 | 显示全部楼层
Dragonfly,你说的我明白,我现在已经实现了一个虚拟驱动,在my_make_request(q,rw,rbh)像md中那样实现了映射.我现在想增加以下功能:在my_make_request()中操作rbh以前先载入(即从磁盘上读入)其所标识的数据块的位图(自己建立的).所以我才想到要建立一个自己的buffer_head,还有就是想在位图载入完成后才开始rbh的操作,即同步操作.能否实现呢?我感觉好像不行
回复

使用道具 举报

发表于 2003-9-5 08:33:53 | 显示全部楼层
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?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-12-4 18:02 , Processed in 0.061112 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表