From 8ee22413bbcab1ac89758ac2dedbcfd696e75205 Mon Sep 17 00:00:00 2001 From: Lai Siyao Date: Tue, 21 Feb 2012 15:40:55 +0800 Subject: [PATCH] LU-506 kernel: remove BKL 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 Change-Id: I8a3432ad56b7a1fcdbf74be4b7819edb31bf6272 Reviewed-on: http://review.whamcloud.com/2169 Reviewed-by: Andreas Dilger Reviewed-by: Yang Sheng Tested-by: Hudson Tested-by: Maloo Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/linux/linux-lock.h | 9 --------- libcfs/include/libcfs/user-prim.h | 1 - libcfs/include/libcfs/winnt/winnt-prim.h | 3 --- lustre/autoconf/lustre-core.m4 | 21 +++++++++++++++++++++ lustre/include/liblustre.h | 2 -- lustre/llite/dir.c | 9 --------- lustre/llite/file.c | 18 ------------------ lustre/lvfs/fsfilt_ext3.c | 15 +++++++++------ lustre/obdclass/obd_mount.c | 17 ++++++++++------- lustre/obdecho/echo_client.c | 8 -------- 10 files changed, 40 insertions(+), 63 deletions(-) diff --git a/libcfs/include/libcfs/linux/linux-lock.h b/libcfs/include/libcfs/linux/linux-lock.h index cfefe45..b2d2213 100644 --- a/libcfs/include/libcfs/linux/linux-lock.h +++ b/libcfs/include/libcfs/linux/linux-lock.h @@ -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 /************************************************************************** diff --git a/libcfs/include/libcfs/user-prim.h b/libcfs/include/libcfs/user-prim.h index a5d0231..655e209 100644 --- a/libcfs/include/libcfs/user-prim.h +++ b/libcfs/include/libcfs/user-prim.h @@ -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 */ diff --git a/libcfs/include/libcfs/winnt/winnt-prim.h b/libcfs/include/libcfs/winnt/winnt-prim.h index 998ca81..cd98a23 100644 --- a/libcfs/include/libcfs/winnt/winnt-prim.h +++ b/libcfs/include/libcfs/winnt/winnt-prim.h @@ -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) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index a63a2fc..1e12c28 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -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 +],[ + 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 diff --git a/lustre/include/liblustre.h b/lustre/include/liblustre.h index 6485b70..8afeaaa 100644 --- a/lustre/include/liblustre.h +++ b/lustre/include/liblustre.h @@ -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) diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index e063532..2cbad3f 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -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, }; diff --git a/lustre/llite/file.c b/lustre/llite/file.c index de0a436..35b1e1a 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -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, diff --git a/lustre/lvfs/fsfilt_ext3.c b/lustre/lvfs/fsfilt_ext3.c index 55cd269..1ca271f 100644 --- a/lustre/lvfs/fsfilt_ext3.c +++ b/lustre/lvfs/fsfilt_ext3.c @@ -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) diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 5392644..fc23461 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -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); diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index 1484037..2c21917 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -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; } -- 1.8.3.1