Whamcloud - gitweb
LU-506 kernel: remove BKL
authorLai Siyao <laisiyao@whamcloud.com>
Tue, 21 Feb 2012 07:40:55 +0000 (15:40 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 28 May 2012 09:55:10 +0000 (05:55 -0400)
Late kernel removes BKL completely; do so for lustre:
* replace BKL with inode->i_lock in ldiskfs.
* HAVE_UNLOCKED_IOCTL is defined after 2.6.12, so this check can be
  removed from lustre code now.
* remove all lock/unlock_kernel definition/usage from lustre code.
* check kernel_locked() in configure, which is removed in 2.6.37.

Signed-off-by: Lai Siyao <laisiyao@whamcloud.com>
Change-Id: I8a3432ad56b7a1fcdbf74be4b7819edb31bf6272
Reviewed-on: http://review.whamcloud.com/2169
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/linux/linux-lock.h
libcfs/include/libcfs/user-prim.h
libcfs/include/libcfs/winnt/winnt-prim.h
lustre/autoconf/lustre-core.m4
lustre/include/liblustre.h
lustre/llite/dir.c
lustre/llite/file.c
lustre/lvfs/fsfilt_ext3.c
lustre/obdclass/obd_mount.c
lustre/obdecho/echo_client.c

index cfefe45..b2d2213 100644 (file)
@@ -227,15 +227,6 @@ typedef struct mutex cfs_mutex_t;
 #define cfs_mutex_is_locked(x)              mutex_is_locked(x)
 #define cfs_mutex_destroy(x)                mutex_destroy(x)
 
-/*
- * Kernel locking primitives
- *
- * - lock_kernel
- * - unlock_kernel
- */
-#define cfs_lock_kernel()      lock_kernel()
-#define cfs_unlock_kernel()    unlock_kernel()
-
 #ifndef lockdep_set_class
 
 /**************************************************************************
index a5d0231..655e209 100644 (file)
@@ -136,7 +136,6 @@ static inline int cfs_psdev_deregister(cfs_psdev_t *foo)
         return 0;
 }
 
-#define cfs_lock_kernel()               do {} while (0)
 #define cfs_sigfillset(l)               do {} while (0)
 #define cfs_recalc_sigpending(l)        do {} while (0)
 /* Fine, crash, but stop giving me compile warnings */
index 998ca81..cd98a23 100644 (file)
@@ -899,9 +899,6 @@ libcfs_arch_cleanup(void);
 #define unlikely(exp) (exp)
 #endif
 
-#define cfs_lock_kernel()               do {} while(0)
-#define cfs_unlock_kernel()             do {} while(0)
-
 #define local_irq_save(x)
 #define local_irq_restore(x)
 
index a63a2fc..1e12c28 100644 (file)
@@ -1865,6 +1865,24 @@ LB_LINUX_TRY_COMPILE([
 ])
 
 #
+# 2.6.37 remove kernel_locked
+#
+AC_DEFUN([LC_KERNEL_LOCKED],
+[AC_MSG_CHECKING([if kernel_locked is defined])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/smp_lock.h>
+],[
+        kernel_locked();
+],[
+        AC_MSG_RESULT([yes])
+        AC_DEFINE(HAVE_KERNEL_LOCKED, 1,
+                [kernel_locked is defined])
+],[
+        AC_MSG_RESULT([no])
+])
+])
+
+#
 # 2.6.38 export blkdev_get_by_dev
 #
 AC_DEFUN([LC_BLKDEV_GET_BY_DEV],
@@ -2117,6 +2135,9 @@ AC_DEFUN([LC_PROG_LINUX],
          LC_FS_STRUCT_RWLOCK
          LC_SBOPS_EVICT_INODE
 
+         # 2.6.37
+         LC_KERNEL_LOCKED
+
          # 2.6.38
          LC_ATOMIC_MNT_COUNT
          LC_BLKDEV_GET_BY_DEV
index 6485b70..8afeaaa 100644 (file)
@@ -292,8 +292,6 @@ int cfs_curproc_is_in_groups(gid_t gid);
         ret;                                                            \
 }
 
-#define cfs_lock_kernel() do {} while (0)
-#define cfs_unlock_kernel() do {} while (0)
 #define daemonize(l) do {} while (0)
 #define sigfillset(l) do {} while (0)
 #define recalc_sigpending(l) do {} while (0)
index e063532..2cbad3f 100644 (file)
@@ -1031,12 +1031,7 @@ out:
         RETURN(rc);
 }
 
-#ifdef HAVE_UNLOCKED_IOCTL
 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
-#else
-static int  ll_dir_ioctl(struct inode *unuse, struct file *file,
-                        unsigned int cmd, unsigned long arg)
-#endif
 {
         struct inode *inode = file->f_dentry->d_inode;
         struct ll_sb_info *sbi = ll_i2sbi(inode);
@@ -1616,10 +1611,6 @@ struct file_operations ll_dir_operations = {
         .release  = ll_dir_release,
         .read     = generic_read_dir,
         .readdir  = ll_readdir,
-#ifdef HAVE_UNLOCKED_IOCTL
         .unlocked_ioctl   = ll_dir_ioctl,
-#else
-        .ioctl          = ll_dir_ioctl,
-#endif
         .fsync    = ll_fsync,
 };
index de0a436..35b1e1a 100644 (file)
@@ -1788,15 +1788,9 @@ static int ll_data_version(struct inode *inode, __u64 *data_version,
         RETURN(rc);
 }
 
-#ifdef HAVE_UNLOCKED_IOCTL
 long ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
         struct inode *inode = file->f_dentry->d_inode;
-#else
-int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
-                  unsigned long arg)
-{
-#endif
         struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
         int flags;
 
@@ -2586,11 +2580,7 @@ struct file_operations ll_file_operations = {
         .READ_METHOD    = READ_FUNCTION,
         .write          = ll_file_write,
         .WRITE_METHOD   = WRITE_FUNCTION,
-#ifdef HAVE_UNLOCKED_IOCTL
         .unlocked_ioctl = ll_file_ioctl,
-#else
-        .ioctl          = ll_file_ioctl,
-#endif
         .open           = ll_file_open,
         .release        = ll_file_release,
         .mmap           = ll_file_mmap,
@@ -2610,11 +2600,7 @@ struct file_operations ll_file_operations_flock = {
         .READ_METHOD    = READ_FUNCTION,
         .write          = ll_file_write,
         .WRITE_METHOD   = WRITE_FUNCTION,
-#ifdef HAVE_UNLOCKED_IOCTL
         .unlocked_ioctl = ll_file_ioctl,
-#else
-        .ioctl          = ll_file_ioctl,
-#endif
         .open           = ll_file_open,
         .release        = ll_file_release,
         .mmap           = ll_file_mmap,
@@ -2637,11 +2623,7 @@ struct file_operations ll_file_operations_noflock = {
         .READ_METHOD    = READ_FUNCTION,
         .write          = ll_file_write,
         .WRITE_METHOD   = WRITE_FUNCTION,
-#ifdef HAVE_UNLOCKED_IOCTL
         .unlocked_ioctl = ll_file_ioctl,
-#else
-        .ioctl          = ll_file_ioctl,
-#endif
         .open           = ll_file_open,
         .release        = ll_file_release,
         .mmap           = ll_file_mmap,
index 55cd269..1ca271f 100644 (file)
@@ -1288,10 +1288,10 @@ int fsfilt_ext3_read(struct inode *inode, void *buf, int size, loff_t *offs)
         int err, blocksize, csize, boffs, osize = size;
 
         /* prevent reading after eof */
-        cfs_lock_kernel();
+       spin_lock(&inode->i_lock);
         if (i_size_read(inode) < *offs + size) {
                 size = i_size_read(inode) - *offs;
-                cfs_unlock_kernel();
+               spin_unlock(&inode->i_lock);
                 if (size < 0) {
                         CDEBUG(D_EXT2, "size %llu is too short for read @%llu\n",
                                i_size_read(inode), *offs);
@@ -1300,7 +1300,7 @@ int fsfilt_ext3_read(struct inode *inode, void *buf, int size, loff_t *offs)
                         return 0;
                 }
         } else {
-                cfs_unlock_kernel();
+               spin_unlock(&inode->i_lock);
         }
 
         blocksize = 1 << inode->i_blkbits;
@@ -1383,14 +1383,17 @@ int fsfilt_ext3_write_handle(struct inode *inode, void *buf, int bufsize,
 
         /* correct in-core and on-disk sizes */
         if (new_size > i_size_read(inode)) {
-                cfs_lock_kernel();
+               spin_lock(&inode->i_lock);
                 if (new_size > i_size_read(inode))
                         i_size_write(inode, new_size);
                 if (i_size_read(inode) > EXT3_I(inode)->i_disksize)
                         EXT3_I(inode)->i_disksize = i_size_read(inode);
-                if (i_size_read(inode) > old_size)
+                if (i_size_read(inode) > old_size) {
+                       spin_unlock(&inode->i_lock);
                         mark_inode_dirty(inode);
-                cfs_unlock_kernel();
+                } else {
+                       spin_unlock(&inode->i_lock);
+                }
         }
 
         if (err == 0)
index 5392644..fc23461 100644 (file)
@@ -198,13 +198,16 @@ struct lustre_mount_info *server_get_mount_2(const char *name)
 
 static void unlock_mntput(struct vfsmount *mnt)
 {
-        if (kernel_locked()) {
-                cfs_unlock_kernel();
-                mntput(mnt);
-                cfs_lock_kernel();
-        } else {
-                mntput(mnt);
-        }
+#if HAVE_KERNEL_LOCKED
+       /* for kernel < 2.6.37 */
+       if (kernel_locked()) {
+               unlock_kernel();
+               mntput(mnt);
+               lock_kernel();
+       }
+#else
+       mntput(mnt);
+#endif
 }
 
 static int lustre_put_lsi(struct super_block *sb);
index 1484037..2c21917 100644 (file)
@@ -2595,10 +2595,6 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
         int                     i;
         ENTRY;
 
-#ifndef HAVE_UNLOCKED_IOCTL
-        cfs_unlock_kernel();
-#endif
-
         memset(&dummy_oti, 0, sizeof(dummy_oti));
 
         oa = &data->ioc_obdo1;
@@ -2803,10 +2799,6 @@ out:
                 ldlm_lock_decref(&ack_lock->lock, ack_lock->mode);
         }
 
-#ifndef HAVE_UNLOCKED_IOCTL
-        cfs_lock_kernel();
-#endif
-
         return rc;
 }