关于BIO结构分析
struct bio {
??????? sector_t??????? bi_sector;?? /* 本次IO操作的其實(shí)扇區(qū),扇區(qū)都是512字節(jié)大小 */
??????? struct bio??????? *bi_next;??? /* 用于鏈接處于同一個(gè)request中的BIO */
??????? struct block_device??? *bi_bdev; /* 該bio所請(qǐng)求的塊設(shè)備 */
??????? unsigned long??????? bi_flags;??? /* 狀態(tài)和命令標(biāo)志 */
??????? unsigned long??????? bi_rw;??????? /* 標(biāo)志位,主要用于區(qū)分讀寫*/
??????? unsigned short??????? bi_vcnt;??? /* vec向量數(shù)組中向量的個(gè)數(shù) */
??????? unsigned short??????? bi_idx;??????? /* vec數(shù)組中當(dāng)前處理的向量索引 */
??????? /* Number of segments in this BIO after
???????? * physical address coalescing is performed.
???????? */
??????? unsigned int??????? bi_phys_segments;? /* 合并后的片段數(shù)目 */
??????? unsigned int??????? bi_size;??? /* 本BIO數(shù)據(jù)量,以字節(jié)為單位 */
??????? /*
???????? * 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; /* 第一個(gè)可合并段的大小,與request合并相關(guān) */
??????? unsigned int??????? bi_seg_back_size; /* 最后一個(gè)可合并段的大小,與request合并相關(guān) */
??????? unsigned int??????? bi_max_vecs;??? /* vec向量數(shù)組中向量元素個(gè)數(shù)的上限 */
??????? atomic_t??????? bi_cnt;??????? /* 使用計(jì)數(shù) */
??????? struct bio_vec??????? *bi_io_vec;??? /* vec向量數(shù)組指針 */
??????? bio_end_io_t??????? *bi_end_io;? /* 該bio結(jié)束時(shí)的回調(diào)函數(shù),一般用于通知調(diào)用者該bio的完成情況 */
??????? void??????????? *bi_private; /* 私有指針,通用bio代碼不會(huì)使用該成員,一般供底層驅(qū)動(dòng)程序使用 */
??? #if defined(CONFIG_BLK_DEV_INTEGRITY)
??????? struct bio_integrity_payload *bi_integrity; /* data integrity */
??? #endif
??????? bio_destructor_t??? *bi_destructor;??? /* 析構(gòu)函數(shù),用于在刪除一個(gè)bio實(shí)例時(shí)調(diào)用 */
??????? /*
???????? * 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.
???????? */
??????? struct bio_vec??????? bi_inline_vecs[0];
??? };
?
有幾個(gè)重點(diǎn):
第一:
一個(gè)BIO所請(qǐng)求的數(shù)據(jù)在塊設(shè)備中是連續(xù)的,對(duì)于不連續(xù)的數(shù)據(jù)塊需要放到多個(gè)BIO中。
第二:
一個(gè)BIO所攜帶的數(shù)據(jù)大小是有上限的,該上限值由bi_max_vecs間接指定,超過上限的數(shù)據(jù)塊必須放到多個(gè)BIO中。
第三:
使用bio_for_each_segment來遍歷 bio_vec
第四:
BIO、bi_io_vec、page之間的關(guān)系
?
總結(jié)
- 上一篇: 从一副漫画说编码思维,编码习惯,编码风格
- 下一篇: Linux kernel block d