__block_commit_write 和bdflush 发生竞态怎么办?
aweii 2017-04-02 10:09:14 最近读2.4.18内核的文件和缓冲区高速缓存部分时。有了一个疑问。比如其中的一段代码:
ssize_t
generic_file_write(struct file *file,const char *buf,size_t count, loff_t *ppos)
{
……
status = mapping->a_ops->prepare_write(file, page, offset, offset+bytes);
if (status)
goto sync_failure;
page_fault = __copy_from_user(kaddr+offset, buf, bytes);
flush_dcache_page(page);
status = mapping->a_ops->commit_write(file, page, offset, offset+bytes);
……
}
假设页的其中一个缓冲区正被bdflush提交给块设备写出的时候, 与此同时__copy_from_user(kaddr+offset, buf, bytes); 写缓冲区
发生竞态怎么办?这段代码没有检查buffer的LOCK情况。