Polling a loop device through a kernel module

谁说我不能喝 提交于 2019-12-04 19:31:58

Reading files is fairly complex, as there are many corner cases to handle. (What if the VM mappings need to be extended? What if you have to suspend the thread while waiting for the disk? etc.)

This article talks about what you should do instead: http://www.linuxjournal.com/article/8110

Unfortunately, the article gives some sample code for hacking around the problem which gives people hope. But the sample code ONLY works in the context of "user process calls into the kernel". In this case, the kernel can re-use the current user process context, but it's a hack.

In the general case (interrupts, timers, etch), you can't just "grab a random user context" because that will lead to massive problems.

Instead, you should make a user-space process that hands the kernel the data it needs.

Kernel timer functions should be atomic. File operations need a process context. Your crash is due to file operations present in you read operation.

Linux device drivers - chapter 7 should get you going on kernel timers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!