如何在内核模块中使用sysfs? [英] How to use sysfs inside kernel module?
问题描述
在用户空间中,我只能echo noop > /sys/block/sda/queue/scheduler
.
In userspace I can just echo noop > /sys/block/sda/queue/scheduler
.
如何在内核模块中执行相同的操作?
How to do the same inside a kernel module?
我希望这样的东西(伪代码):
I expect something like this (pseudocode):
struct dentry* e = sysfs_get_root();
vfs_path_lookup(e, ????, "block/sda/queue/scheduler", ???);
????;
struct something* q = ????;
????->store(q, "noop", 1);
/* some cleanup */
如何正确实施?
我的内核模块仅注册SysRQ处理程序,并应在触发SysRQ时配置io调度程序(由于io-scheduler错误,此时可以挂载用户空间程序)
My kernel module just registers SysRQ handler and should configure the io scheduler when that SysRQ is triggered (userspace programs can be hung at that time because of the bad io-scheduler)
推荐答案
无法正确实现.如果您仍然想这样做,并且 了解为什么它是一个坏主意(tm)的原因,请参见此文章
There is just no way to implement it properly. If you want to do it anyway, and also understand the reason why it is a Bad Idea (tm), see this article
这篇关于如何在内核模块中使用sysfs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!