绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
看块设备驱动部分的笔记(2)
2020-06-28 15:46:22

bio

相关数据结构:

/*
* main unit of I/O for the block layer and lower layers (ie drivers and
* stacking drivers)
*/
struct bio {
        sector_t                bi_sector;
        struct bio                *bi_next;        /* request queue link */
        struct block_device        *bi_bdev;
        unsigned long                bi_flags;        /* status, command, etc */
        unsigned long                bi_rw;                /* bottom bits READ/WRITE,
                                                 * top bits priority
                                                 */

        unsigned short                bi_vcnt;        /* how many bio_vec's */
        unsigned short                bi_idx;                /* current index into bvl_vec */

        /* Number of segments in this BIO after
         * physical address coalescing is performed.
         */
        unsigned short                bi_phys_segments;

        /* Number of segments after physical and DMA remapping
         * hardware coalescing is performed.
         */
        unsigned short                bi_hw_segments;

        unsigned int                bi_size;        /* residual I/O count */

        /*
         * To keep track of the max hw size, we account for the
         * sizes of the first and last virtually mergeable segments
         * in this bio
         */
        unsigned int                bi_hw_front_size;
        unsigned int                bi_hw_back_size;

        unsigned int                bi_max_vecs;        /* max bvl_vecs we can hold */

        struct bio_vec                *bi_io_vec;        /* the actual vec list */

        bio_end_io_t                *bi_end_io;
        atomic_t                bi_cnt;                /* pin count */

        void                        *bi_private;

        bio_destructor_t        *bi_destructor;        /* destructor */
        struct bio_set                *bi_set;        /* memory pools set */
};




/*
* was unsigned short, but we might as well be ready for > 64kB I/O pages
*/
struct bio_vec {
        struct page        *bv_page;
        unsigned int        bv_len;
        unsigned int        bv_offset;
};


bio是 Generic block layer(通用块层) 的核心数据结构。

bio中的段(segment)是由bio_vec数据结构表示的。 bio相关的段被放在bio_vec的数组中,他们的关系表示如下:

 


其中bio的bi_idx字段会不断保持更新,内核中提供了宏 bio_for_each_segment 用来遍历bio中的bio_vec  


文章来源CU社区:看块设备驱动部分的笔记

分享好友

分享这个小栈给你的朋友们,一起进步吧。

内核源码
创建时间:2020-05-18 13:36:55
内核源码精华帖内容汇总
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • 飘絮絮絮丶
    专家
戳我,来吐槽~