有人可以帮我替换"lock_kernel"吗?在块设备驱动程序上? [英] Can someone help me replace "lock_kernel" on a block device driver?

查看:85
本文介绍了有人可以帮我替换"lock_kernel"吗?在块设备驱动程序上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您阅读这篇文章.我正在尝试修补网络块设备驱动程序.如果您需要查看源代码,请访问http://code.ximeta.com.

Thank you for looking at this post. I am trying to patch up a network block device driver. If you need to see the sources they are at http : / / code.ximeta.com.

我注意到,从linux 2.6.37开始,lock_kernel()似乎已被弃用.我阅读了"ioctl()的新方法",发现设备驱动程序现在应该在操作之前执行特定的锁定.

I noticed that lock_kernel() seems deprecated as of linux 2.6.37. I read "The new way of ioctl()" and found that device drivers now should perform a specific lock before operating.

因此,我想提出一些建议,如果可能的话,将其替换.

So I would like some advice replacing this if possible.

我在当前代码中的块文件夹部分中找到了我认为相关的两个部分.

I have found two sections in the current code that I think are related, in the block folder section.

Source 
      block->io.c
           ->ctrldev.c

我将每个代码段中的内容供您考虑.

I put snippets from each for your consideration.

io.c包含一个对lock_kernel的调用:

io.c contains one call to 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函数:

And ctrldev.c contains the main io function:

#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.

Later ndas_ctrldev_ioctl function is set as the former .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();

Now I want to convert this to avoid using lock_kernel();

根据我的理解,我将对之前的部分进行如下修改:

According to my understanding I will modified the former sections as below:

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
};

所以,我想问以下建议.

So, I would ask the following advice.

  1. 这看起来像右边吗 进行?

  1. Does this look like the right proceedure?

我是否理解正确移动 锁定io功能了吗?

Do I understand correct to move the lock into the io function?

基于crtrldev.c中的包含内容,您可以 建议关闭顶部的任何锁 你的头? (我试图研究一些 其他处理filp和 lock_kernel,但是我太多了 新手可以立即找到答案.)

Based on the includes in crtrldev.c, can you recommend any lock off the top of your head? (I tried to research some other drivers dealing with filp and lock_kernel, but I am too much a noob to find the answer right away.)

推荐答案

这是解决方案.

#if HAVE_UNLOCKED_IOCTL
    #include <linux/mutex.h>
#else
    #include <linux/smp_lock.h>
#endif

.
. 
. 

#if HAVE_UNLOCKED_IOCTL
   mutex_lock(&fs_mutex);
#else
   lock_kernel();
#endif

这仅显示替换锁定调用.正如我在上述问题部分所猜到的关于unlocked_ioctl一样,其他部分已经解决了.感谢您的检查和帮助.

This only shows replacing the lock call. The other parts worked out as I guessed in the question part above concerning unlocked_ioctl. Thanks for checking and for helping.

这篇关于有人可以帮我替换"lock_kernel"吗?在块设备驱动程序上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆