谢谢你看这篇文章。我正在尝试修补网络块设备驱动程序。如果您需要查看http:// code.ximeta.com上的来源。有人可以帮我替换块设备驱动程序上的“lock_kernel”吗?
我注意到lock_kernel()从linux 2.6.37开始似乎不推荐使用。我读到“ioctl()的新方法”,并发现设备驱动程序现在应该在操作之前执行特定的锁定。
所以我想一些建议,如果可能的话取代这一点。
我在block文件夹部分找到了我认为相关的两段代码。
Source
block->io.c
->ctrldev.c
我把每个片段都考虑在内。
io.c中包含一个来电lock_kernel:
NDAS_SAL_API xbool sal_file_get_size(sal_file file, xuint64* size)
{
definitions and declarations etc..
lock_kernel();
#ifdef HAVE_UNLOCKED_IOCTL
if (filp->f_op->unlocked_ioctl) {
some small statements
error = filp->f_op->unlocked_ioctl(filp, BLKGETSIZE64, (unsigned long)size);
actions if error or not etc.
}
#endif
unlock_kernel();
return ret;
}
而且ctrldev.c包含主IO功能:
#include <linux/spinlock.h> // spinklock_t
#include <linux/semaphore.h> // struct semaphore
#include <asm/atomic.h> // atomic
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/ide.h>
#include <linux/smp_lock.h>
#include <linux/time.h>
......
int ndas_ctrldev_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
lots of operations and functions.
return result;
}
后来ndas_ctrldev_ioctl功能被设置为前.ioctl。
static struct file_operations ndasctrl_fops = {
.write = ndas_ctrldev_write,
.read = ndas_ctrldev_read,
.open = ndas_ctrldev_open,
.release = ndas_ctrldev_release,
.ioctl = ndas_ctrldev_ioctl,
};
现在我想转换这个以避免使用lock_kernel();
根据我的理解,我将修改前的部分如下:
NDAS_SAL_API xbool sal_file_get_size(sal_file file, xuint64* size)
{
definitions and declarations etc..
#ifndef HAVE_UNLOCKED_IOCTL
lock_kernel();
#endif
#ifdef HAVE_UNLOCKED_IOCTL
if (filp->f_op->unlocked_ioctl) {
some small statements
error = filp->f_op->unlocked_ioctl(filp, BLKGETSIZE64, (unsigned long)size);
actions if error or not etc.
}
#endif
#ifndef HAVE_UNLOCKED_IOCTL
unlock_kernel();
#endif
return ret;
}
#ifdef HAVE_UNLOCKED_IOCTL
long ndas_ctrldev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
#else
int ndas_ctrldev_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
#endif
{
#ifdef HAVE_UNLOCKED_IOCTL
! add some sort of lock here !
#endif
lots of operations and functions.
#ifdef HAVE_UNLOCKED_IOCTL
! add unlock statement here !
#endif
return result;
}
static struct file_operations ndasctrl_fops = {
.write = ndas_ctrldev_write,
.read = ndas_ctrldev_read,
.open = ndas_ctrldev_open,
.release = ndas_ctrldev_release,
#ifdef HAVE_UNLOCKED_IOCTL
.unlocked_ioctl = ndas_ctrldev_ioctl,
#else
.ioctl = ndas_ctrldev_ioctl,
#endif
};
所以,我提出以下建议。
这是否看起来像右边 proceedure?
我理解将 锁移入io函数是否正确?
基于对crtrldev.c的包括,可你 推荐任何脱锁 你的头顶? (我想研究一些 其他司机处理的filp和 lock_kernel,但我太 小白找到答案的时候了。)
此驱动程序中只有一个lock_kernel实例。我想这意味着没有递归,并且在io.c中替换它的可能性就足够了。至于用互斥锁代替lock_kernel,是否意味着我会写一个小函数,然后调用它而不是lock_kernel?或者我尝试链接到设备中现有的互斥锁?在ctrldev.c中有几个对互斥锁的引用。设备上还有一个自旋锁,但未被调用。如果我为ndas_ctrldev_ioctl函数中的每个可能的操作使用up()和down(),它会被认为是按设备样式吗? – ndasusers 2011-05-19 01:48:35