关于BIO结构分析
struct bio {
sector_t bi_sector; /* 本次IO操作的其实扇区,扇区都是512字节大小 */
struct bio *bi_next; /* 用于链接处于同一个request中的BIO */
struct block_device *bi_bdev; /* 该bio所请求的块设备 */
unsigned long bi_flags; /* 状态和命令标志 */
unsigned long bi_rw; /* 标志位,主要用于区分读写*/
unsigned short bi_vcnt; /* vec向量数组中向量的个数 */
unsigned short bi_idx; /* vec数组中当前处理的向量索引 */
/* Number of segments in this BIO after
* physical address coalescing is performed.
*/
unsigned int bi_phys_segments; /* 合并后的片段数目 */
unsigned int bi_size; /* 本BIO数据量,以字节为单位 */
/*
* 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; /* 第一个可合并段的大小,与request合并相关 */
unsigned int bi_seg_back_size; /* 最后一个可合并段的大小,与request合并相关 */
unsigned int bi_max_vecs; /* vec向量数组中向量元素个数的上限 */
atomic_t bi_cnt; /* 使用计数 */
struct bio_vec *bi_io_vec; /* vec向量数组指针 */
bio_end_io_t *bi_end_io; /* 该bio结束时的回调函数,一般用于通知调用者该bio的完成情况 */
void *bi_private; /* 私有指针,通用bio代码不会使用该成员,一般供底层驱动程序使用 */
#if defined(CONFIG_BLK_DEV_INTEGRITY)
struct bio_integrity_payload *bi_integrity; /* data integrity */
#endif
bio_destructor_t *bi_destructor; /* 析构函数,用于在删除一个bio实例时调用 */
/*
* 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];
};
有几个重点:
第一:
一个BIO所请求的数据在块设备中是连续的,对于不连续的数据块需要放到多个BIO中。
第二:
一个BIO所携带的数据大小是有上限的,该上限值由bi_max_vecs间接指定,超过上限的数据块必须放到多个BIO中。
第三:
使用bio_for_each_segment来遍历 bio_vec
第四:
BIO、bi_io_vec、page之间的关系