ITPub博客

首页 > 自动化运维 > > 看块设备驱动部分的笔记(2)

看块设备驱动部分的笔记(2)

作者:飘絮絮絮丶 时间:2020-06-28 15:46:22 0 删除 编辑

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社区:看块设备驱动部分的笔记

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69946831/viewspace-3145473/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-09

  • 博文量
    2646
  • 访问量
    42235