Linux内核设计与实现 总结笔记(第十四章)块I/O层

123

struct buffer_head {
unsigned long b_state; /* buffer state bitmap (see above)缓冲区状态标志位 */
struct buffer_head *b_this_page;/* circular list of page's buffers页面中的缓冲区 */
struct page *b_page; /* the page this bh is mapped to 存储缓冲区的页面*/
sector_t b_blocknr; /* start block number 其实块号*/
size_t b_size; /* size of mapping 映像的大小*/
char *b_data; /* pointer to data within the page 页面内的数据指针*/
struct block_device *b_bdev; /* 相关联的块设备 */
bh_end_io_t *b_end_io; /* I/O completion I/O完成方法*/
  void *b_private; /* reserved for b_end_io io完成方法*/
struct list_head b_assoc_buffers; /* associated with another mapping 相关的映射链表*/
struct address_space *b_assoc_map; /* mapping this buffer is

   associated with 相关的地址空间*/

atomic_t b_count; /* users using this buffer_head 缓冲区使用计数*/

};
struct buffer_head
enum bh_state_bits {
BH_Uptodate, /* Contains valid data 包含可用数据*/
BH_Dirty, /* Is dirty 脏数据*/
BH_Lock, /* Is locked */
BH_Req, /* Has been submitted for I/O 有IO操作请求*/
BH_Uptodate_Lock,/* Used by the first bh in a page, to serialise
  * IO completion of other buffers in the page 被IO操作占用
  */
BH_Mapped, /* Has a disk mapping 映射了磁盘块*/
BH_New, /* Disk mapping was newly created by get_block 缓冲区用get_block刚刚获取的,还不能使用*/
BH_Async_Read, /* Is under end_buffer_async_read I/O 正在被异步读*/
BH_Async_Write, /* Is under end_buffer_async_write I/O 正在被异步写*/
BH_Delay, /* Buffer is not yet allocated on disk 尚未与磁盘关联*/
BH_Boundary, /* Block is followed by a discontiguity 缓冲区在连续块边缘*/
BH_Write_EIO, /* I/O error on write 写入时遇到错误*/
BH_Unwritten, /* Buffer is allocated on disk but not written */
BH_Quiet, /* Buffer Error Prinks to be quiet 禁止错误*/
BH_Meta, /* Buffer contains metadata */
BH_Prio, /* Buffer should be submitted with REQ_PRIO */
BH_Defer_Completion, /* Defer AIO completion to workqueue */
BH_PrivateStart,/* not a state bit, but the first bit available
 * for private allocation by other entities
 */

};
enum bh_state_bits
struct buffer_head {
    unsigned long b_state;        /* buffer state bitmap (see above)缓冲区状态标志位 */
    struct buffer_head *b_this_page;/* circular list of page's buffers页面中的缓冲区 */
    struct page *b_page;        /* the page this bh is mapped to 存储缓冲区的页面*/

    sector_t b_blocknr;        /* start block number 其实块号*/
    size_t b_size;            /* size of mapping 映像的大小*/
    char *b_data;            /* pointer to data within the page 页面内的数据指针*/

    struct block_device *b_bdev;        /* 相关联的块设备 */
    bh_end_io_t *b_end_io;        /* I/O completion I/O完成方法*/
     void *b_private;        /* reserved for b_end_io io完成方法*/
    struct list_head b_assoc_buffers; /* associated with another mapping 相关的映射链表*/
    struct address_space *b_assoc_map;    /* mapping this buffer is
                           associated with 相关的地址空间*/
    atomic_t b_count;        /* users using this buffer_head 缓冲区使用计数*/
};



enum bh_state_bits {
    BH_Uptodate,    /* Contains valid data 包含可用数据*/
    BH_Dirty,    /* Is dirty 脏数据*/
    BH_Lock,    /* Is locked */
    BH_Req,        /* Has been submitted for I/O 有IO操作请求*/
    BH_Uptodate_Lock,/* Used by the first bh in a page, to serialise
              * IO completion of other buffers in the page 被IO操作占用
              */

    BH_Mapped,    /* Has a disk mapping 映射了磁盘块*/
    BH_New,        /* Disk mapping was newly created by get_block 缓冲区用get_block刚刚获取的,还不能使用*/
    BH_Async_Read,    /* Is under end_buffer_async_read I/O 正在被异步读*/
    BH_Async_Write,    /* Is under end_buffer_async_write I/O 正在被异步写*/
    BH_Delay,    /* Buffer is not yet allocated on disk 尚未与磁盘关联*/
    BH_Boundary,    /* Block is followed by a discontiguity 缓冲区在连续块边缘*/
    BH_Write_EIO,    /* I/O error on write 写入时遇到错误*/
    BH_Unwritten,    /* Buffer is allocated on disk but not written */
    BH_Quiet,    /* Buffer Error Prinks to be quiet 禁止错误*/
    BH_Meta,    /* Buffer contains metadata */
    BH_Prio,    /* Buffer should be submitted with REQ_PRIO */
    BH_Defer_Completion, /* Defer AIO completion to workqueue */

    BH_PrivateStart,/* not a state bit, but the first bit available
             * for private allocation by other entities
             */
};



/*
 * main unit of I/O for the block layer and lower layers (ie drivers and
 * stacking drivers)
 */
struct bio {
    struct bio        *bi_next;    /* request queue link 请求链表*/
    struct block_device    *bi_bdev;        /* 相关的块设备 */
    unsigned int        bi_flags;    /* status, command, etc 状态和命令标志 */
    int            bi_error;
    unsigned long        bi_rw;        /* bottom bits READ/WRITE,
                         * top bits priority 读还是写
                         */

    struct bvec_iter    bi_iter;

    /* Number of segments in this BIO after
     * physical address coalescing is performed. 结合后的片段数目
     */
    unsigned int        bi_phys_segments;

    /*
     * To keep track of the max segment size, we account for the
     * sizes of the first and last mergeable segments in this bio. 第一个可合并的段大小,最后一个可合并的段大小
     */
    unsigned int        bi_seg_front_size;
    unsigned int        bi_seg_back_size;

    atomic_t        __bi_remaining;

    bio_end_io_t        *bi_end_io;        /* bi io完成方法 */

    void            *bi_private;        /* 拥有者的私有方法 */
#ifdef CONFIG_BLK_CGROUP
    /*
     * Optional ioc and css associated with this bio.  Put on bio
     * release.  Read comment on top of bio_associate_current().
     */
    struct io_context    *bi_ioc;
    struct cgroup_subsys_state *bi_css;
#endif
    union {
#if defined(CONFIG_BLK_DEV_INTEGRITY)
        struct bio_integrity_payload *bi_integrity; /* data integrity */
#endif
    };

    unsigned short        bi_vcnt;    /* how many bio_vec's bio链表个数*/

    /*
     * Everything starting with bi_max_vecs will be preserved by bio_reset()
     */

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

    atomic_t        __bi_cnt;    /* pin count */

    struct bio_vec        *bi_io_vec;    /* the actual vec list bio链表*/

    struct bio_set        *bi_pool;

    /*
     * We can inline a number of vecs at the end of the bio, to avoid
     * double allocations for a small number of bio_vecs. This member
     * MUST obviously be kept at the very end of the bio.内嵌bio向量
     */
    struct bio_vec        bi_inline_vecs[0];
};
struct buffer_head
/*
 * 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;
};
struct bio_vec

猜你喜欢

转载自www.cnblogs.com/ch122633/p/11725660.html
今日推荐