linux kernel - Can someone help me replace "lock_kernel" on a block device driver? -


thank looking @ post. trying patch network block device driver. if need see sources @ http : / / code.ximeta.com.

i noticed lock_kernel() seems deprecated of linux 2.6.37. read "the new way of ioctl()" , found device drivers should perform specific lock before operating.

so advice replacing if possible.

i have found 2 sections in current code think related, in block folder section.

source        block->io.c            ->ctrldev.c 

i put snippets each consideration.

io.c contains 1 call lock_kernel:

ndas_sal_api xbool     sal_file_get_size(sal_file file, xuint64* size) {     definitions , declarations etc..  lock_kernel();  #ifdef have_unlocked_ioctl     if (filp->f_op->unlocked_ioctl) {           small statements         error = filp->f_op->unlocked_ioctl(filp, blkgetsize64, (unsigned long)size);         actions if error or not etc.    } #endif     unlock_kernel();     return ret; } 

and ctrldev.c contains 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 , functions.     return result; } 

later ndas_ctrldev_ioctl function set 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,  }; 

now want convert avoid using lock_kernel();

according understanding modified former sections below:

ndas_sal_api xbool     sal_file_get_size(sal_file file, xuint64* size) {     definitions , declarations etc..  #ifndef have_unlocked_ioctl     lock_kernel(); #endif  #ifdef have_unlocked_ioctl     if (filp->f_op->unlocked_ioctl) {           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 sort of lock here ! #endif    lots of operations , 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, ask following advice.

  1. does right proceedure?

  2. do understand correct move lock io function?

  3. based on includes in crtrldev.c, can recommend lock off top of head? (i tried research other drivers dealing filp , lock_kernel, noob find answer right away.)

the big kernel lock (bkl) more deprecated - of 2.6.39, not exist anymore.

the way lock_kernel() conversion done replace per-driver mutexes. if driver simple enough, can create mutex driver, , replace uses of lock_kernel() , unlock_kernel() mutex lock/unlock calls. note, however, functions used called bkl (the lock lock_kernel() used lock) held; have add lock/unlock calls these functions too.

this not work if driver acquire bkl recursively; if case, have track avoid deadlocks (this done in conversion of reiserfs, depended heavily both in recursive bkl behavior , in fact dropped when sleeping).

the next step after conversion per-driver mutex change use per-device mutex instead of per-driver mutex.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -