在 IO 系统中保存信息
我需要编写一个使用 /proc 文件系统模拟“多播器”的内核模块。
基本上需要支持以下场景:
1) 允许对 /proc 文件进行一次写入访问,并允许对 /proc 文件进行多次读取访问。
2) 模块应该有一个包含上次成功写入内容的缓冲区。 每次写入都应该与所有读取器的读取相匹配。
考虑场景2,一个写入器写了一些东西,有两个读取器(A和B),A读取缓冲区的内容,然后A尝试再次读取,在这种情况下它应该进入wait_queue并等待下一条消息,它不应该再次获得相同的缓冲区。
我需要保留已读取当前缓冲区的所有 pid 的映射,如果它们尝试再次读取并且缓冲区未更改,则应阻止它们,直到有新的缓冲区为止。我试图弄清楚有一种方法可以在没有地图的情况下保存该信息。 我听说 I/O 系统中有一些冗余字段,如果某个进程已经读取了当前缓冲区,我可以用它们来标记该进程。
有人可以给我提示我应该在哪里寻找该字段吗?如何在不保留 pid 和缓冲区的“映射”的情况下保存当前进程的信息?
谢谢!
I need to write a kernel module that simulate a "multicaster" Using the /proc file system.
Basically it need to support the following scenarios:
1) allow one write access to the /proc file and many read accesses to the /proc file.
2) The module should have a buffer of the contents last successful write.
Each write should be matched by a read from all reader.
Consider scenario 2, a writer wrote something and there are two readers (A and B), A read the content of the buffer, and then A tried to read again, in this case it should go into a wait_queue and wait for the next message, it should not get the same buffer again.
I need to keep a map of all the pid's that already read the current buffer, and in case they try to read again and the buffer was not changed, they should be blocked until there is a new buffer. I'm trying to figure it there is a way i can save that info without a map.
I heard there are some redundant fields inside the I/O system the I can use to flag a process if it already read the current buffer.
Can someone give me a tip where should i look for that field ? how can i save info on the current process without keeping a "map" of pid's and buffers ?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要尝试根据 PID 来保持它 - 这只是错误的抽象级别。
每次打开文件时,都会创建一个新的
struct file
,该文件引用打开文件的实例。将信息(给定结构文件读取的最新缓冲区)存储在结构文件本身中。您可以使用
struct file
中的private_data
指针来存储您需要的信息。这就是它的用途。Don't try and keep it based on the PID - that's simply the wrong level of abstraction.
Each time the file is opened there will be a new
struct file
created that references that instance of the open file. Store the information (the most recent buffer that was read by a givenstruct file
) within thestruct file
itself.You can use the
private_data
pointer withinstruct file
to store the information you need. That's what it's there for.