在我的驱动程序的file_operations结构中,我有:
struct file_operations Fops = {
read: device_read,
write: device_write,
unlocked_ioctl: device_ioctl,
...
};即没有使用ioctl字段。这是否足以避免大内核锁并在没有任何同步的情况下进入device_ioctl()?或者,我是否也必须在代码的用户空间中更改ioctl()调用?
发布于 2009-06-30 13:08:33
嗯,我解决了这个问题。还需要更改device_ioctl函数的签名。没有inode参数,函数也应该返回long。就像下面的补丁一样:
-static int st_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd_in, unsigned long arg)
+static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
{(来自:http://linux.derkeiler.com/Mailing-Lists/Kernel/2008-01/msg06799.html)
发布于 2010-07-13 02:37:34
阅读这篇LWN文章:http://lwn.net/Articles/119652/
此外,在2.6.33和2.6.35RC之间的某些时候(使用git-diff来找出哪个提交),当只定义了.ioctl时,内核会发出警告。
这是向更显式和更细粒度的锁定迈进的一步。还要注意,只需更改函数签名和指针即可编译,但会引入竞争条件的可能性(两个用户空间应用程序同时执行ioctl调用)。
发布于 2011-03-03 06:37:33
Andi Kleem在Linux内核邮件列表上发布了一个使用ioctl到unlocked_ioctl的快速和肮脏的代码转换方法:
[JANITOR PROPOSAL] Switch ioctl functions to ->unlocked_ioctl
该方法解释了如何调整函数的参数以及插入锁定和解锁调用。
https://stackoverflow.com/questions/1063564
复制相似问题