diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4
index 0e9779f..b4c622b 100644
--- a/libcfs/autoconf/lustre-libcfs.m4
+++ b/libcfs/autoconf/lustre-libcfs.m4
@@ -128,6 +128,7 @@ LB_LINUX_TRY_COMPILE([
 	__u64 *data2 = NULL;
 
 	data1 = data2;
+	*data1 = 1;
 ],[
 	AC_MSG_RESULT([yes])
         AC_DEFINE(HAVE_KERN__U64_LONG_LONG, 1,
@@ -487,6 +488,7 @@ AC_DEFUN([LIBCFS_FUNC_DUMP_TRACE],
 	],[
 		struct stacktrace_ops ops;
 		ops.address = print_addr;
+		ops.address(NULL, 0, 0);
 	],[
 		AC_MSG_RESULT(yes)
 		AC_DEFINE(HAVE_TRACE_ADDRESS_RELIABLE, 1,
@@ -702,6 +704,72 @@ LB_LINUX_TRY_COMPILE([
 ])
 ])
 
+# 2.6.38 ctl_name field is removed from ctl_table
+AC_DEFUN([LC_CTL_NAME],
+[AC_MSG_CHECKING([struct ctl_table has ctl_name field])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/sysctl.h>
+],[
+        struct ctl_table tmp = { .ctl_name = 0 };
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_CTL_NAME, 1,
+                  [struct ctl_table has ctl_name field])
+],[
+        AC_MSG_RESULT(no)
+])
+])
+
+# 2.6.38 ctl_name field is removed from ctl_table
+AC_DEFUN([LC_CTL_NAME],
+[AC_MSG_CHECKING([struct ctl_table has ctl_name field])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/sysctl.h>
+],[
+        struct ctl_table tmp = { .ctl_name = 0 };
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_CTL_NAME, 1,
+                  [struct ctl_table has ctl_name field])
+],[
+        AC_MSG_RESULT(no)
+])
+])
+
+# 2.6.38 fsync removes dentry argument
+AC_DEFUN([LC_FSYNC_TWO_ARGS],
+[AC_MSG_CHECKING([fsync has two arguments])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/fs.h>
+],[
+        struct file_operations fops;
+	fops.fsync(NULL, 1);
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_FSYNC_TWO_ARGS, 1,
+                  [fsync has two arguments])
+],[
+        AC_MSG_RESULT(no)
+])
+])
+
+# 2.6.38 tcp_sendpage first argument type is struct sock
+AC_DEFUN([LC_SOCK_TCP_SENDPAGE],
+[AC_MSG_CHECKING([tcp_sendpage first argument type is struct sock])
+LB_LINUX_TRY_COMPILE([
+        #include <net/tcp.h>
+],[
+	struct sock *sk;
+	tcp_sendpage(sk, NULL, 0, 0, 0);
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_SOCK_TCP_SENDPAGE, 1,
+                  [tcp_sendpage first argument type is struct sock])
+],[
+        AC_MSG_RESULT(no)
+])
+])
+
 #
 # LIBCFS_PROG_LINUX
 #
@@ -754,6 +822,10 @@ LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
 LC_SHRINKER_WANT_SHRINK_PTR
 # 2.6.34
 LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE
+# 2.6.38
+LC_CTL_NAME
+LC_FSYNC_TWO_ARGS
+LC_SOCK_TCP_SENDPAGE
 ])
 
 #
@@ -852,6 +924,7 @@ AC_COMPILE_IFELSE([
 		__u64 *data2 = NULL;
 
 		data1 = data2;
+		*data1 = 1;
 		return 0;
 	}
 ],[
diff --git a/libcfs/include/libcfs/libcfs_fail.h b/libcfs/include/libcfs/libcfs_fail.h
index b9dcd6b..add0208 100644
--- a/libcfs/include/libcfs/libcfs_fail.h
+++ b/libcfs/include/libcfs/libcfs_fail.h
@@ -127,14 +127,14 @@ static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
  * the first and continues. */
 static inline void cfs_race(__u32 id)
 {
-        int rc;
-
         if (CFS_FAIL_PRECHECK(id)) {
                 if (unlikely(__cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET))) {
+                        int rc;
+
                         cfs_race_state = 0;
                         CERROR("cfs_race id %x sleeping\n", id);
                         cfs_wait_event_interruptible(cfs_race_waitq, cfs_race_state != 0, rc);
-                        CERROR("cfs_fail_race id %x awake\n", id);
+                        CERROR("cfs_fail_race id %x awake: %d\n", id, rc);
                 } else {
                         CERROR("cfs_fail_race id %x waking\n", id);
                         cfs_race_state = 1;
diff --git a/libcfs/include/libcfs/linux/kp30.h b/libcfs/include/libcfs/linux/kp30.h
index 122a506..59aa9ba 100644
--- a/libcfs/include/libcfs/linux/kp30.h
+++ b/libcfs/include/libcfs/linux/kp30.h
@@ -39,7 +39,12 @@
 
 
 #ifndef AUTOCONF_INCLUDED
-# include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/kernel.h>
 #include <linux/mm.h>
diff --git a/libcfs/include/libcfs/linux/linux-fs.h b/libcfs/include/libcfs/linux/linux-fs.h
index 9d42a6c..5510553 100644
--- a/libcfs/include/libcfs/linux/linux-fs.h
+++ b/libcfs/include/libcfs/linux/linux-fs.h
@@ -69,7 +69,11 @@ cfs_file_t *cfs_filp_open (const char *name, int flags, int mode, int *err);
 #define cfs_filp_close(f)                   filp_close(f, NULL)
 #define cfs_filp_read(fp, buf, size, pos)   (fp)->f_op->read((fp), (buf), (size), pos)
 #define cfs_filp_write(fp, buf, size, pos)  (fp)->f_op->write((fp), (buf), (size), pos)
-#define cfs_filp_fsync(fp)                  (fp)->f_op->fsync((fp), (fp)->f_dentry, 1)
+#ifdef HAVE_FSYNC_TWO_ARGS
+#  define cfs_filp_fsync(fp)                  (fp)->f_op->fsync((fp), 1)
+#else
+#  define cfs_filp_fsync(fp)                  (fp)->f_op->fsync((fp), (fp)->f_dentry, 1)
+#endif
 
 #define cfs_get_file(f)                     get_file(f)
 #define cfs_get_fd(x)                       fget(x)
diff --git a/libcfs/include/libcfs/linux/linux-lock.h b/libcfs/include/libcfs/linux/linux-lock.h
index e3a8e66..af268ce 100644
--- a/libcfs/include/libcfs/linux/linux-lock.h
+++ b/libcfs/include/libcfs/linux/linux-lock.h
@@ -208,11 +208,17 @@ typedef struct completion cfs_completion_t;
 typedef struct mutex cfs_mutex_t;
 
 #define CFS_DEFINE_MUTEX(name)             DEFINE_MUTEX(name)
-#define CFS_DECLARE_MUTEX(name)            DECLARE_MUTEX(name)
 
 #define cfs_mutex_init(x)                   mutex_init(x)
+#ifdef DEFINE_SEMAPHORE
+#define CFS_DECLARE_MUTEX(name)             DEFINE_SEMAPHORE(name)
+#define cfs_init_mutex(x)                   sema_init(x, 1)
+#define cfs_init_mutex_locked(x)            sema_init(x, 0)
+#else
+#define CFS_DECLARE_MUTEX(name)             DECLARE_MUTEX(name)
 #define cfs_init_mutex(x)                   init_MUTEX(x)
 #define cfs_init_mutex_locked(x)            init_MUTEX_LOCKED(x)
+#endif
 #define cfs_mutex_up(x)                     up(x)
 #define cfs_mutex_down(x)                   down(x)
 #define cfs_up(x)                           up(x)
diff --git a/libcfs/include/libcfs/linux/linux-prim.h b/libcfs/include/libcfs/linux/linux-prim.h
index 19fbca1..06442d8 100644
--- a/libcfs/include/libcfs/linux/linux-prim.h
+++ b/libcfs/include/libcfs/linux/linux-prim.h
@@ -50,7 +50,12 @@
 #endif
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/init.h>
diff --git a/libcfs/include/libcfs/linux/linux-time.h b/libcfs/include/libcfs/linux/linux-time.h
index 43c1f34..efb5845 100644
--- a/libcfs/include/libcfs/linux/linux-time.h
+++ b/libcfs/include/libcfs/linux/linux-time.h
@@ -99,7 +99,12 @@
 #endif
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/libcfs/libcfs/linux/linux-debug.c b/libcfs/libcfs/linux/linux-debug.c
index 7b2d3a9..f70a7c0 100644
--- a/libcfs/libcfs/linux/linux-debug.c
+++ b/libcfs/libcfs/linux/linux-debug.c
@@ -43,7 +43,12 @@
 #endif
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kmod.h>
diff --git a/libcfs/libcfs/linux/linux-module.c b/libcfs/libcfs/linux/linux-module.c
index d290172..b4a10cf 100644
--- a/libcfs/libcfs/linux/linux-module.c
+++ b/libcfs/libcfs/linux/linux-module.c
@@ -131,9 +131,14 @@ libcfs_psdev_release(struct inode * inode, struct file * file)
 	return rc;
 }
 
+#ifdef HAVE_COMPAT_IOCTL
+static long
+libcfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+#else
 static int
-libcfs_ioctl(struct inode *inode, struct file *file,
-	     unsigned int cmd, unsigned long arg)
+libcfs_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
+             unsigned long arg)
+#endif
 {
 	struct cfs_psdev_file	 pfile;
 	int    rc = 0;
@@ -172,7 +177,11 @@ libcfs_ioctl(struct inode *inode, struct file *file,
 }
 
 static struct file_operations libcfs_fops = {
+#ifdef HAVE_COMPAT_IOCTL
+	compat_ioctl:   libcfs_ioctl,
+#else
 	ioctl:   libcfs_ioctl,
+#endif
 	open:    libcfs_psdev_open,
 	release: libcfs_psdev_release
 };
diff --git a/libcfs/libcfs/linux/linux-prim.c b/libcfs/libcfs/linux/linux-prim.c
index 1b59e0b..11c19de 100644
--- a/libcfs/libcfs/linux/linux-prim.c
+++ b/libcfs/libcfs/linux/linux-prim.c
@@ -36,7 +36,12 @@
 
 #define DEBUG_SUBSYSTEM S_LNET
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/libcfs/libcfs/linux/linux-proc.c b/libcfs/libcfs/linux/linux-proc.c
index 9777ffb..6800684 100644
--- a/libcfs/libcfs/linux/linux-proc.c
+++ b/libcfs/libcfs/linux/linux-proc.c
@@ -45,7 +45,12 @@
 #endif
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -362,7 +367,9 @@ static cfs_sysctl_table_t lnet_table[] = {
          * to go via /proc for portability.
          */
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_DEBUG,
+#endif
                 .procname = "debug",
                 .data     = &libcfs_debug,
                 .maxlen   = sizeof(int),
@@ -370,7 +377,9 @@ static cfs_sysctl_table_t lnet_table[] = {
                 .proc_handler = &proc_dobitmasks,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_SUBSYSTEM_DEBUG,
+#endif
                 .procname = "subsystem_debug",
                 .data     = &libcfs_subsystem_debug,
                 .maxlen   = sizeof(int),
@@ -378,7 +387,9 @@ static cfs_sysctl_table_t lnet_table[] = {
                 .proc_handler = &proc_dobitmasks,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_PRINTK,
+#endif
                 .procname = "printk",
                 .data     = &libcfs_printk,
                 .maxlen   = sizeof(int),
@@ -386,7 +397,9 @@ static cfs_sysctl_table_t lnet_table[] = {
                 .proc_handler = &proc_dobitmasks,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_CONSOLE_RATELIMIT,
+#endif
                 .procname = "console_ratelimit",
                 .data     = &libcfs_console_ratelimit,
                 .maxlen   = sizeof(int),
@@ -394,21 +407,27 @@ static cfs_sysctl_table_t lnet_table[] = {
                 .proc_handler = &proc_dointvec
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_CONSOLE_MAX_DELAY_CS,
+#endif
                 .procname = "console_max_delay_centisecs",
                 .maxlen   = sizeof(int),
                 .mode     = 0644,
                 .proc_handler = &proc_console_max_delay_cs
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_CONSOLE_MIN_DELAY_CS,
+#endif
                 .procname = "console_min_delay_centisecs",
                 .maxlen   = sizeof(int),
                 .mode     = 0644,
                 .proc_handler = &proc_console_min_delay_cs
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_CONSOLE_BACKOFF,
+#endif
                 .procname = "console_backoff",
                 .maxlen   = sizeof(int),
                 .mode     = 0644,
@@ -416,7 +435,9 @@ static cfs_sysctl_table_t lnet_table[] = {
         },
 
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_DEBUG_PATH,
+#endif
                 .procname = "debug_path",
                 .data     = libcfs_debug_file_path_arr,
                 .maxlen   = sizeof(libcfs_debug_file_path_arr),
@@ -425,7 +446,9 @@ static cfs_sysctl_table_t lnet_table[] = {
         },
 
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_UPCALL,
+#endif
                 .procname = "upcall",
                 .data     = lnet_upcall,
                 .maxlen   = sizeof(lnet_upcall),
@@ -433,7 +456,9 @@ static cfs_sysctl_table_t lnet_table[] = {
                 .proc_handler = &proc_dostring,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_DEBUG_LOG_UPCALL,
+#endif
                 .procname = "debug_log_upcall",
                 .data     = lnet_debug_log_upcall,
                 .maxlen   = sizeof(lnet_debug_log_upcall),
@@ -441,54 +466,68 @@ static cfs_sysctl_table_t lnet_table[] = {
                 .proc_handler = &proc_dostring,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_MEMUSED,
+                .strategy = &sysctl_intvec,
+#endif
                 .procname = "lnet_memused",
                 .data     = (int *)&libcfs_kmemory.counter,
                 .maxlen   = sizeof(int),
                 .mode     = 0444,
                 .proc_handler = &proc_dointvec,
-                .strategy = &sysctl_intvec,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_CATASTROPHE,
+                .strategy = &sysctl_intvec,
+#endif
                 .procname = "catastrophe",
                 .data     = &libcfs_catastrophe,
                 .maxlen   = sizeof(int),
                 .mode     = 0444,
                 .proc_handler = &proc_dointvec,
-                .strategy = &sysctl_intvec,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_PANIC_ON_LBUG,
+                .strategy = &sysctl_intvec,
+#endif
                 .procname = "panic_on_lbug",
                 .data     = &libcfs_panic_on_lbug,
                 .maxlen   = sizeof(int),
                 .mode     = 0644,
                 .proc_handler = &proc_dointvec,
-                .strategy = &sysctl_intvec,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_DUMP_KERNEL,
+#endif
                 .procname = "dump_kernel",
                 .maxlen   = 256,
                 .mode     = 0200,
                 .proc_handler = &proc_dump_kernel,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_DAEMON_FILE,
+#endif
                 .procname = "daemon_file",
                 .mode     = 0644,
                 .maxlen   = 256,
                 .proc_handler = &proc_daemon_file,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_DEBUG_MB,
+#endif
                 .procname = "debug_mb",
                 .mode     = 0644,
                 .proc_handler = &proc_debug_mb,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_WATCHDOG_RATELIMIT,
+#endif
                 .procname = "watchdog_ratelimit",
                 .data     = &libcfs_watchdog_ratelimit,
                 .maxlen   = sizeof(int),
@@ -497,7 +536,10 @@ static cfs_sysctl_table_t lnet_table[] = {
                 .extra1   = &min_watchdog_ratelimit,
                 .extra2   = &max_watchdog_ratelimit,
         },
-        {       .ctl_name = PSDEV_LNET_FORCE_LBUG,
+        {
+#ifdef HAVE_CTL_NAME
+                .ctl_name = PSDEV_LNET_FORCE_LBUG,
+#endif
                 .procname = "force_lbug",
                 .data     = NULL,
                 .maxlen   = 0,
@@ -505,7 +547,9 @@ static cfs_sysctl_table_t lnet_table[] = {
                 .proc_handler = &libcfs_force_lbug
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_FAIL_LOC,
+#endif
                 .procname = "fail_loc",
                 .data     = &cfs_fail_loc,
                 .maxlen   = sizeof(cfs_fail_loc),
@@ -513,7 +557,9 @@ static cfs_sysctl_table_t lnet_table[] = {
                 .proc_handler = &proc_fail_loc
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_FAIL_VAL,
+#endif
                 .procname = "fail_val",
                 .data     = &cfs_fail_val,
                 .maxlen   = sizeof(int),
@@ -526,7 +572,9 @@ static cfs_sysctl_table_t lnet_table[] = {
 #ifdef CONFIG_SYSCTL
 static cfs_sysctl_table_t top_table[] = {
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = CTL_LNET,
+#endif
                 .procname = "lnet",
                 .mode     = 0555,
                 .data     = NULL,
@@ -534,7 +582,9 @@ static cfs_sysctl_table_t top_table[] = {
                 .child    = lnet_table,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = 0
+#endif
         }
 };
 
diff --git a/libcfs/libcfs/linux/linux-tcpip.c b/libcfs/libcfs/linux/linux-tcpip.c
index 9d673f0..17895e2 100644
--- a/libcfs/libcfs/linux/linux-tcpip.c
+++ b/libcfs/libcfs/linux/linux-tcpip.c
@@ -84,8 +84,12 @@ libcfs_sock_ioctl(int cmd, unsigned long arg)
 #endif
              {
                 lock_kernel();
+#ifdef HAVE_COMPAT_IOCTL
+                rc =sock_filp->f_op->compat_ioctl(sock_filp, cmd, arg);
+#else
                 rc =sock_filp->f_op->ioctl(sock_filp->f_dentry->d_inode,
                                            sock_filp, cmd, arg);
+#endif
                 unlock_kernel();
              }
         set_fs(oldmm);
@@ -597,6 +601,13 @@ int sock_create_lite(int family, int type, int protocol, struct socket **res)
 }
 #endif
 
+#ifndef HAVE_SK_SLEEP_HELPER
+static inline wait_queue_head_t *sk_sleep(struct sock *sk)
+{
+        return sk->sk_sleep;
+}
+#endif
+
 int
 libcfs_sock_accept (struct socket **newsockp, struct socket *sock)
 {
@@ -617,7 +628,7 @@ libcfs_sock_accept (struct socket **newsockp, struct socket *sock)
         newsock->ops = sock->ops;
 
         set_current_state(TASK_INTERRUPTIBLE);
-        add_wait_queue(sock->sk->sk_sleep, &wait);
+        add_wait_queue(sk_sleep(sock->sk), &wait);
 
         rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
         if (rc == -EAGAIN) {
@@ -626,7 +637,7 @@ libcfs_sock_accept (struct socket **newsockp, struct socket *sock)
                 rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
         }
 
-        remove_wait_queue(sock->sk->sk_sleep, &wait);
+        remove_wait_queue(sk_sleep(sock->sk), &wait);
         set_current_state(TASK_RUNNING);
 
         if (rc != 0)
@@ -645,7 +656,7 @@ EXPORT_SYMBOL(libcfs_sock_accept);
 void
 libcfs_sock_abort_accept (struct socket *sock)
 {
-        wake_up_all(sock->sk->sk_sleep);
+        wake_up_all(sk_sleep(sock->sk));
 }
 
 EXPORT_SYMBOL(libcfs_sock_abort_accept);
diff --git a/libcfs/libcfs/nidstrings.c b/libcfs/libcfs/nidstrings.c
index d5b03ed..9269423 100644
--- a/libcfs/libcfs/nidstrings.c
+++ b/libcfs/libcfs/nidstrings.c
@@ -78,15 +78,17 @@ void libcfs_init_nidstrings (void)
 # define NIDSTR_LOCK(f)   cfs_spin_lock_irqsave(&libcfs_nidstring_lock, f)
 # define NIDSTR_UNLOCK(f) cfs_spin_unlock_irqrestore(&libcfs_nidstring_lock, f)
 #else
-# define NIDSTR_LOCK(f)   (f=0)                 /* avoid unused var warnings */
-# define NIDSTR_UNLOCK(f) (f=0)
+# define NIDSTR_LOCK(f)   do {} while (0)
+# define NIDSTR_UNLOCK(f) do {} while (0)
 #endif
 
 static char *
 libcfs_next_nidstring (void)
 {
         char          *str;
+#ifdef __KERNEL__
         unsigned long  flags;
+#endif
 
         NIDSTR_LOCK(flags);
 
diff --git a/lnet/klnds/mxlnd/mxlnd.h b/lnet/klnds/mxlnd/mxlnd.h
index 236c0e4..b18b1ee 100644
--- a/lnet/klnds/mxlnd/mxlnd.h
+++ b/lnet/klnds/mxlnd/mxlnd.h
@@ -45,7 +45,12 @@
 #define EXPORT_SYMTAB
 #endif
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>       /* module */
 #include <linux/kernel.h>       /* module */
diff --git a/lnet/klnds/o2iblnd/o2iblnd.h b/lnet/klnds/o2iblnd/o2iblnd.h
index 4538b11..b3891b1 100644
--- a/lnet/klnds/o2iblnd/o2iblnd.h
+++ b/lnet/klnds/o2iblnd/o2iblnd.h
@@ -42,7 +42,12 @@
 # define EXPORT_SYMTAB
 #endif
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/lnet/klnds/ptllnd/ptllnd.h b/lnet/klnds/ptllnd/ptllnd.h
index 6ee5bd7..d187aac 100755
--- a/lnet/klnds/ptllnd/ptllnd.h
+++ b/lnet/klnds/ptllnd/ptllnd.h
@@ -42,7 +42,12 @@
 # define EXPORT_SYMTAB
 #endif
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/lnet/klnds/qswlnd/qswlnd.h b/lnet/klnds/qswlnd/qswlnd.h
index d4a6964..c3d104d 100644
--- a/lnet/klnds/qswlnd/qswlnd.h
+++ b/lnet/klnds/qswlnd/qswlnd.h
@@ -47,7 +47,12 @@
 #include <qsnet/kernel.h>
 #undef printf                                   /* nasty QSW #define */
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 
diff --git a/lnet/klnds/ralnd/ralnd.h b/lnet/klnds/ralnd/ralnd.h
index ce52c00..32934c6 100644
--- a/lnet/klnds/ralnd/ralnd.h
+++ b/lnet/klnds/ralnd/ralnd.h
@@ -42,7 +42,12 @@
 # define EXPORT_SYMTAB
 #endif
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/lnet/klnds/socklnd/socklnd_lib-linux.c b/lnet/klnds/socklnd/socklnd_lib-linux.c
index 6907ab2..30c9669 100644
--- a/lnet/klnds/socklnd/socklnd_lib-linux.c
+++ b/lnet/klnds/socklnd/socklnd_lib-linux.c
@@ -601,7 +601,13 @@ ksocknal_lib_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx)
                         rc = sk->sk_prot->sendpage(sk, page,
                                                    offset, fragsize, msgflg);
                 } else {
-                        rc = tcp_sendpage(sock, page, offset, fragsize, msgflg);
+                        rc = tcp_sendpage(
+#ifdef HAVE_SOCK_TCP_SENDPAGE
+                                          sk,
+#else
+                                          sock,
+#endif
+                                          page, offset, fragsize, msgflg);
                 }
         } else {
 #if SOCKNAL_SINGLE_FRAG_TX || !SOCKNAL_RISK_KMAP_DEADLOCK
diff --git a/lnet/klnds/socklnd/socklnd_lib-linux.h b/lnet/klnds/socklnd/socklnd_lib-linux.h
index 494ce8e..7b3e8a4 100644
--- a/lnet/klnds/socklnd/socklnd_lib-linux.h
+++ b/lnet/klnds/socklnd/socklnd_lib-linux.h
@@ -43,7 +43,12 @@
 #define __LINUX_SOCKNAL_LIB_H__
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/lnet/lnet/router.c b/lnet/lnet/router.c
index 7fe9a0d..f438657 100644
--- a/lnet/lnet/router.c
+++ b/lnet/lnet/router.c
@@ -1127,13 +1127,10 @@ lnet_router_checker(void *arg)
         int                rc;
         lnet_peer_t       *rtr;
         cfs_list_t        *entry;
-        lnet_process_id_t  rtr_id;
 
         cfs_daemonize("router_checker");
         cfs_block_allsigs();
 
-        rtr_id.pid = LUSTRE_SRV_LNET_PID;
-
         LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
 
         while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/router_proc.c
index fde0e0a..2fc07a1 100644
--- a/lnet/lnet/router_proc.c
+++ b/lnet/lnet/router_proc.c
@@ -691,37 +691,49 @@ static cfs_sysctl_table_t lnet_table[] = {
          * to go via /proc for portability.
          */
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_STATS,
+#endif
                 .procname = "stats",
                 .mode     = 0644,
                 .proc_handler = &proc_lnet_stats,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_ROUTES,
+#endif
                 .procname = "routes",
                 .mode     = 0444,
                 .proc_handler = &proc_lnet_routes,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_ROUTERS,
+#endif
                 .procname = "routers",
                 .mode     = 0444,
                 .proc_handler = &proc_lnet_routers,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_PEERS,
+#endif
                 .procname = "peers",
                 .mode     = 0444,
                 .proc_handler = &proc_lnet_peers,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_PEERS,
+#endif
                 .procname = "buffers",
                 .mode     = 0444,
                 .proc_handler = &proc_lnet_buffers,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = PSDEV_LNET_NIS,
+#endif
                 .procname = "nis",
                 .mode     = 0444,
                 .proc_handler = &proc_lnet_nis,
@@ -731,7 +743,9 @@ static cfs_sysctl_table_t lnet_table[] = {
 
 static cfs_sysctl_table_t top_table[] = {
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = CTL_LNET,
+#endif
                 .procname = "lnet",
                 .mode     = 0555,
                 .data     = NULL,
@@ -739,7 +753,9 @@ static cfs_sysctl_table_t top_table[] = {
                 .child    = lnet_table,
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = 0
+#endif
         }
 };
 
diff --git a/lnet/selftest/conrpc.c b/lnet/selftest/conrpc.c
index 94074ae..bd9aa92 100644
--- a/lnet/selftest/conrpc.c
+++ b/lnet/selftest/conrpc.c
@@ -427,7 +427,6 @@ void
 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
 {
         lstcon_rpc_t      *crpc;
-        srpc_client_rpc_t *rpc;
         srpc_msg_t        *rep;
         int                error;
 
@@ -439,8 +438,6 @@ lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
                                       lstcon_rpc_t, crp_link) {
                 lstcon_rpc_stat_total(stat, 1);
 
-                rpc = crpc->crp_rpc;
-
                 LASSERT (crpc->crp_stamp != 0);
 
                 error = lstcon_rpc_get_reply(crpc, &rep);
@@ -478,7 +475,6 @@ lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
         cfs_list_t           *next;
         lstcon_rpc_ent_t     *ent;
         srpc_generic_reply_t *rep;
-        srpc_client_rpc_t    *rpc;
         lstcon_rpc_t         *crpc;
         srpc_msg_t           *msg;
         lstcon_node_t        *nd;
@@ -503,8 +499,6 @@ lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
 
                 ent = cfs_list_entry(next, lstcon_rpc_ent_t, rpe_link);
 
-                rpc = crpc->crp_rpc;
-
                 LASSERT (crpc->crp_stamp != 0);
 
                 error = lstcon_rpc_get_reply(crpc, &msg);
diff --git a/lnet/selftest/timer.c b/lnet/selftest/timer.c
index b4e5d52..094c95d 100644
--- a/lnet/selftest/timer.c
+++ b/lnet/selftest/timer.c
@@ -191,6 +191,8 @@ stt_timer_main (void *arg)
                                    stt_data.stt_shuttingdown,
                                    cfs_time_seconds(STTIMER_SLOTTIME),
                                    rc);
+                if (rc != -ETIMEDOUT)
+                        CDEBUG(D_INFO, "wait return %d\n", rc);
         }
 
         cfs_spin_lock(&stt_data.stt_lock);
diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4
index 822af2a..ab77548 100644
--- a/lustre/autoconf/lustre-core.m4
+++ b/lustre/autoconf/lustre-core.m4
@@ -1315,6 +1315,7 @@ LB_LINUX_TRY_COMPILE([
 	filldir_t filter;
 
 	filter = fillonedir;
+        filter(NULL, NULL, 0, 0, 0, 0);
 	return 1;
 ],[
         AC_MSG_RESULT(yes)
@@ -2174,6 +2175,152 @@ LB_LINUX_TRY_COMPILE([
 ])
 ])
 
+#
+# LC_SK_SLEEP_HELPER
+# 2.6.35 kernel has sk_sleep helper function
+#
+AC_DEFUN([LC_SK_SLEEP_HELPER],
+[AC_MSG_CHECKING([if kernel has sk_sleep helper])
+LB_LINUX_TRY_COMPILE([
+        #include <net/sock.h>
+],[
+        sk_sleep(NULL);
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_SK_SLEEP_HELPER, 1,
+                  [kernel has sk_sleep helper])
+],[
+        AC_MSG_RESULT(no)
+])
+])
+
+#
+# LC_DCACHE_LOCK
+# 2.6.38 introduces dcache RCU-walk
+#
+AC_DEFUN([LC_DCACHE_LOCK],
+[AC_MSG_CHECKING([if kernel has dcache_lock])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/dcache.h>
+],[
+        spin_lock(&dcache_lock);
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_DCACHE_LOCK, 1,
+                  [kernel has dcache_lock])
+],[
+        AC_MSG_RESULT(no)
+])
+])
+
+#
+# LC_FS_STRUCT_SPINLOCK
+# 2.6.38 fs_struct.lock is spinlock
+#
+AC_DEFUN([LC_FS_STRUCT_SPINLOCK],
+[AC_MSG_CHECKING([if fs_struct.lock is spinlock])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/fs_struct.h>
+],[
+        struct fs_struct fss;
+        spin_lock(&fss.lock);
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
+                  [fs_struct.lock is spinlock])
+],[
+        AC_MSG_RESULT(no)
+])
+])
+
+#
+# LC_BLKDEV_GET_BY_DEV
+# 2.6.38 export blkdev_get_by_dev
+#
+AC_DEFUN([LC_BLKDEV_GET_BY_DEV],
+[LB_CHECK_SYMBOL_EXPORT([blkdev_get_by_dev],
+[fs/block_dev.c],[
+AC_DEFINE(HAVE_BLKDEV_GET_BY_DEV, 1,
+            [blkdev_get_by_dev is exported by the kernel])
+],[
+])
+])
+
+#
+# LC_CHECK_ACL_THREE_ARGS
+# 2.6.38 check_acl has three args
+#
+AC_DEFUN([LC_CHECK_ACL_THREE_ARGS],
+[AC_MSG_CHECKING([if check_acl has three args])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/fs.h>
+],[
+        struct inode_operations iops;
+
+        iops.check_acl(NULL, 0, 0);
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_CHECK_ACL_THREE_ARGS, 1,
+                  [check_acl has three args])
+],[
+        AC_MSG_RESULT(no)
+])
+])
+
+#
+# LC_PERMISSION_FLAGS_ARG
+# 2.6.38 permission has flags argument
+#
+AC_DEFUN([LC_PERMISSION_FLAGS_ARG],
+[AC_MSG_CHECKING([if permission has flags argument])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/fs.h>
+],[
+        struct inode_operations iops;
+
+        iops.permission(NULL, 1, 1);
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_PERMISSION_FLAGS_ARG, 1,
+                  [permission has flags argument])
+],[
+        AC_MSG_RESULT(no)
+])
+])
+
+#
+# LC_EXPORT_SIMPLE_SETATTR
+# 2.6.38 export simple_setattr
+#
+AC_DEFUN([LC_EXPORT_SIMPLE_SETATTR],
+[LB_CHECK_SYMBOL_EXPORT([simple_setattr],
+[fs/libfs.c],[
+AC_DEFINE(HAVE_SIMPLE_SETATTR, 1,
+            [simple_setattr is exported by the kernel])
+],[
+])
+])
+
+#
+# LC_EVICT_INODE
+# 2.6.38 evict_inode replaces delete_inode
+#
+AC_DEFUN([LC_EVICT_INODE],
+[AC_MSG_CHECKING([if evict_inode replaces delete_inode])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/fs.h>
+],[
+        struct super_operations sops;
+
+        sops.evict_inode(NULL);
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_EVICT_INODE, 1,
+                  [evict_inode replaces delete_inode])
+],[
+        AC_MSG_RESULT(no)
+])
+])
 
 #
 # LC_PROG_LINUX
@@ -2330,6 +2477,18 @@ AC_DEFUN([LC_PROG_LINUX],
          LC_EXT4_SINGLEDATA_TRANS_BLOCKS_SB
          LC_WALK_SPACE_HAS_DATA_SEM
 
+         # 2.6.35
+         LC_SK_SLEEP_HELPER
+
+         # 2.6.38
+         LC_DCACHE_LOCK
+         LC_FS_STRUCT_SPINLOCK
+         LC_BLKDEV_GET_BY_DEV
+         LC_CHECK_ACL_THREE_ARGS
+         LC_PERMISSION_FLAGS_ARG
+         LC_EXPORT_SIMPLE_SETATTR
+         LC_EVICT_INODE
+
          #
          if test x$enable_server = xyes ; then
              AC_DEFINE(HAVE_SERVER_SUPPORT, 1, [support server])
diff --git a/lustre/fid/fid_store.c b/lustre/fid/fid_store.c
index 2226d5e..0525053 100644
--- a/lustre/fid/fid_store.c
+++ b/lustre/fid/fid_store.c
@@ -113,12 +113,10 @@ int seq_store_write(struct lu_server_seq *seq,
 {
         struct dt_object *dt_obj = seq->lss_obj;
         struct seq_thread_info *info;
-        struct dt_device *dt_dev;
         loff_t pos = 0;
         int rc;
         ENTRY;
 
-        dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev);
         info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
         LASSERT(info != NULL);
 
diff --git a/lustre/fld/fld_index.c b/lustre/fld/fld_index.c
index dd7b1de..997e781 100644
--- a/lustre/fld/fld_index.c
+++ b/lustre/fld/fld_index.c
@@ -153,7 +153,6 @@ int fld_index_create(struct lu_server_fld *fld,
                      struct thandle *th)
 {
         struct dt_object *dt_obj = fld->lsf_obj;
-        struct dt_device *dt_dev;
         seqno_t start;
         int rc;
 
@@ -161,7 +160,6 @@ int fld_index_create(struct lu_server_fld *fld,
 
         start = range->lsr_start;
         LASSERT(range_is_sane(range));
-        dt_dev = lu2dt_dev(fld->lsf_obj->do_lu.lo_dev);
 
         rc = dt_obj->do_index_ops->dio_insert(env, dt_obj,
                                               fld_rec(env, range),
@@ -189,13 +187,11 @@ int fld_index_delete(struct lu_server_fld *fld,
                      struct thandle   *th)
 {
         struct dt_object *dt_obj = fld->lsf_obj;
-        struct dt_device *dt_dev;
         seqno_t seq = range->lsr_start;
         int rc;
 
         ENTRY;
 
-        dt_dev = lu2dt_dev(fld->lsf_obj->do_lu.lo_dev);
         rc = dt_obj->do_index_ops->dio_delete(env, dt_obj,
                                               fld_key(env, seq), th,
                                               BYPASS_CAPA);
diff --git a/lustre/include/linux/lprocfs_status.h b/lustre/include/linux/lprocfs_status.h
index b9f52cc..43e730a 100644
--- a/lustre/include/linux/lprocfs_status.h
+++ b/lustre/include/linux/lprocfs_status.h
@@ -48,7 +48,12 @@
 
 #ifdef __KERNEL__
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/autoconf.h>
 #include <linux/proc_fs.h>
diff --git a/lustre/include/linux/lustre_compat25.h b/lustre/include/linux/lustre_compat25.h
index a1291c9..80e8fda 100644
--- a/lustre/include/linux/lustre_compat25.h
+++ b/lustre/include/linux/lustre_compat25.h
@@ -65,6 +65,14 @@ struct ll_iattr {
 #define ll_iattr iattr
 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14) */
 
+#ifdef HAVE_FS_STRUCT_SPINLOCK
+#  define LOCK_FS_STRUCT(fs)   cfs_spin_lock(&(fs)->lock)
+#  define UNLOCK_FS_STRUCT(fs) cfs_spin_unlock(&(fs)->lock)
+#else
+#  define LOCK_FS_STRUCT(fs)   cfs_write_lock(&(fs)->lock)
+#  define UNLOCK_FS_STRUCT(fs) cfs_write_unlock(&(fs)->lock)
+#endif
+
 #ifdef HAVE_FS_STRUCT_USE_PATH
 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
                                  struct dentry *dentry)
@@ -74,11 +82,11 @@ static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
 
         path.mnt = mnt;
         path.dentry = dentry;
-        write_lock(&fs->lock);
+        LOCK_FS_STRUCT(fs);
         old_pwd = fs->pwd;
         path_get(&path);
         fs->pwd = path;
-        write_unlock(&fs->lock);
+        UNLOCK_FS_STRUCT(fs);
 
         if (old_pwd.dentry)
                 path_put(&old_pwd);
@@ -92,12 +100,12 @@ static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
         struct dentry *old_pwd;
         struct vfsmount *old_pwdmnt;
 
-        cfs_write_lock(&fs->lock);
+        LOCK_FS_STRUCT(fs);
         old_pwd = fs->pwd;
         old_pwdmnt = fs->pwdmnt;
         fs->pwdmnt = mntget(mnt);
         fs->pwd = dget(dentry);
-        cfs_write_unlock(&fs->lock);
+        UNLOCK_FS_STRUCT(fs);
 
         if (old_pwd) {
                 dput(old_pwd);
@@ -255,9 +263,15 @@ static inline int cfs_cleanup_group_info(void)
 
 #include <linux/proc_fs.h>
 
-#if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
-#define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
-extern void __d_rehash(struct dentry *dentry, int lock);
+#ifdef HAVE_D_REHASH_COND
+#  define ll_d_rehash_cond(dentry, lock) d_rehash_cond(dentry, lock)
+#elif defined(HAVE___D_REHASH)
+#  define ll_d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
+   extern void __d_rehash(struct dentry *dentry, int lock);
+#endif
+
+#ifndef HAVE_DCACHE_LOCK
+#  define ll_d_rehash_cond(dentry, lock) d_rehash(dentry)
 #endif
 
 #ifdef HAVE_CAN_SLEEP_ARG
@@ -646,6 +660,7 @@ static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
 #define ll_crypto_tfm_alg_max_keysize	crypto_tfm_alg_max_keysize
 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
 
+#define HAVE_SYNCHRONIZE_RCU 1
 #ifndef HAVE_SYNCHRONIZE_RCU
 /* Linux 2.6.32 provides define when !CONFIG_TREE_PREEMPT_RCU */
 #ifndef synchronize_rcu
@@ -749,39 +764,14 @@ static inline long labs(long x)
 #define ll_sb_has_quota_active(sb, type) sb_has_quota_enabled(sb, type)
 #endif
 
-#ifdef HAVE_SB_ANY_QUOTA_ACTIVE
+#ifdef DQUOT_USAGE_ENABLED
+#define ll_sb_any_quota_active(sb) sb_any_quota_loaded(sb)
+#elif defined(HAVE_SB_ANY_QUOTA_ACTIVE)
 #define ll_sb_any_quota_active(sb) sb_any_quota_active(sb)
 #else
 #define ll_sb_any_quota_active(sb) sb_any_quota_enabled(sb)
 #endif
 
-static inline int
-ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
-{
-        if (sb->s_qcop->quota_on) {
-                return sb->s_qcop->quota_on(sb, off, ver, name
-#ifdef HAVE_QUOTA_ON_5ARGS
-                                            , remount
-#endif
-                                           );
-        }
-        else
-                return -ENOSYS;
-}
-
-static inline int ll_quota_off(struct super_block *sb, int off, int remount)
-{
-        if (sb->s_qcop->quota_off) {
-                return sb->s_qcop->quota_off(sb, off
-#ifdef HAVE_QUOTA_OFF_3ARGS
-                                             , remount
-#endif
-                                            );
-        }
-        else
-                return -ENOSYS;
-}
-
 #ifndef HAVE_BLK_QUEUE_LOG_BLK_SIZE /* added in 2.6.31 */
 #define blk_queue_logical_block_size(q, sz) blk_queue_hardsect_size(q, sz)
 #endif
@@ -837,5 +827,39 @@ static inline int ll_quota_off(struct super_block *sb, int off, int remount)
 #define bio_hw_segments(q, bio) 0
 #endif
 
+#ifdef HAVE_DCACHE_LOCK
+#define LOCK_DCACHE     cfs_spin_lock(&dcache_lock)
+#define UNLOCK_DCACHE   cfs_spin_unlock(&dcache_lock)
+#define LL_LOCK_DCACHE                                  \
+        do {                                            \
+                cfs_spin_lock(&ll_lookup_lock);         \
+                LOCK_DCACHE;                            \
+        } while (0)
+#define LL_UNLOCK_DCACHE                                \
+        do {                                            \
+                UNLOCK_DCACHE;                          \
+                cfs_spin_unlock(&ll_lookup_lock);       \
+        } while (0)
+#define dget_dlock(d)   dget_locked(d)
+#define d_refcount(d)   atomic_read(&(d)->d_count)
+#else
+#define LOCK_DCACHE      do {} while (0)
+#define UNLOCK_DCACHE    do {} while (0)
+#define LL_LOCK_DCACHE   do {} while (0)
+#define LL_UNLOCK_DCACHE do {} while (0)
+#define d_refcount(d)   ((d)->d_count)
+#endif
+
+#ifndef HAVE_BLKDEV_GET_BY_DEV
+#define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
+#endif
+
+#ifndef QUOTA_OK
+#define QUOTA_OK 0
+#endif
+#ifndef NO_QUOTA
+#define NO_QUOTA 1
+#endif
+
 #endif /* __KERNEL__ */
 #endif /* _COMPAT25_H */
diff --git a/lustre/include/linux/lustre_patchless_compat.h b/lustre/include/linux/lustre_patchless_compat.h
index 17fbc5c..8eedb3b 100644
--- a/lustre/include/linux/lustre_patchless_compat.h
+++ b/lustre/include/linux/lustre_patchless_compat.h
@@ -93,9 +93,10 @@ truncate_complete_page(struct address_space *mapping, struct page *page)
 }
 #endif /* HAVE_TRUNCATE_COMPLETE_PAGE */
 
-#if !defined(HAVE_D_REHASH_COND) && !defined(HAVE___D_REHASH)
+#if defined(HAVE_DCACHE_LOCK) && !defined(HAVE_D_REHASH_COND) && \
+   !defined(HAVE___D_REHASH)
 /* megahack */
-static inline void d_rehash_cond(struct dentry * entry, int lock)
+static inline void ll_d_rehash_cond(struct dentry * entry, int lock)
 {
 	if (!lock)
 		spin_unlock(&dcache_lock);
@@ -105,8 +106,6 @@ static inline void d_rehash_cond(struct dentry * entry, int lock)
 	if (!lock)
 		spin_lock(&dcache_lock);
 }
-
-#define __d_rehash(dentry, lock) d_rehash_cond(dentry, lock)
 #endif /* !HAVE_D_REHASH_COND && !HAVE___D_REHASH*/
 
 #ifdef ATTR_OPEN
diff --git a/lustre/include/linux/lvfs.h b/lustre/include/linux/lvfs.h
index 020e039..9004058 100644
--- a/lustre/include/linux/lvfs.h
+++ b/lustre/include/linux/lvfs.h
@@ -113,7 +113,7 @@ static inline void l_dput(struct dentry *de)
         if (!de || IS_ERR(de))
                 return;
         //shrink_dcache_parent(de);
-        LASSERT(cfs_atomic_read(&de->d_count) > 0);
+        LASSERT(d_refcount(de) > 0);
         dput(de);
 }
 
diff --git a/lustre/include/linux/obd_support.h b/lustre/include/linux/obd_support.h
index beae348..ef5a5b9 100644
--- a/lustre/include/linux/obd_support.h
+++ b/lustre/include/linux/obd_support.h
@@ -43,7 +43,12 @@
 
 #ifdef __KERNEL__
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/seq_file.h>
 #include <linux/module.h>
diff --git a/lustre/ldlm/ldlm_flock.c b/lustre/ldlm/ldlm_flock.c
index 55117d1..46c5e05 100644
--- a/lustre/ldlm/ldlm_flock.c
+++ b/lustre/ldlm/ldlm_flock.c
@@ -650,14 +650,11 @@ EXPORT_SYMBOL(ldlm_flock_completion_ast);
 int ldlm_flock_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
                             void *data, int flag)
 {
-        struct ldlm_namespace *ns;
         ENTRY;
 
         LASSERT(lock);
         LASSERT(flag == LDLM_CB_CANCELING);
 
-        ns = ldlm_lock_to_ns(lock);
-
         /* take lock off the deadlock detection waitq. */
         cfs_spin_lock(&ldlm_flock_waitq_lock);
         cfs_list_del_init(&lock->l_flock_waitq);
diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c
index e2b0410..a344aef 100644
--- a/lustre/ldlm/ldlm_lib.c
+++ b/lustre/ldlm/ldlm_lib.c
@@ -2129,7 +2129,6 @@ void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
 {
         int                        netrc;
         struct ptlrpc_reply_state *rs;
-        struct obd_device         *obd;
         struct obd_export         *exp;
         struct ptlrpc_service     *svc;
         ENTRY;
@@ -2163,7 +2162,6 @@ void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
         LASSERT (cfs_list_empty(&rs->rs_exp_list));
 
         exp = class_export_get (req->rq_export);
-        obd = exp->exp_obd;
 
         /* disable reply scheduling while I'm setting up */
         rs->rs_scheduled = 1;
diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c
index 6234ccf..dff0c57 100644
--- a/lustre/ldlm/ldlm_lockd.c
+++ b/lustre/ldlm/ldlm_lockd.c
@@ -276,7 +276,7 @@ static int ldlm_lock_busy(struct ldlm_lock *lock)
 /* This is called from within a timer interrupt and cannot schedule */
 static void waiting_locks_callback(unsigned long unused)
 {
-        struct ldlm_lock *lock, *last = NULL;
+        struct ldlm_lock *lock;
 
 repeat:
         cfs_spin_lock_bh(&waiting_locks_spinlock);
@@ -352,8 +352,6 @@ repeat:
                            libcfs_nid2str(
                                    lock->l_export->exp_connection->c_peer.nid));
 
-                last = lock;
-
                 /* no needs to take an extra ref on the lock since it was in
                  * the waiting_locks_list and ldlm_add_waiting_lock()
                  * already grabbed a ref */
diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c
index 767ca01..9a14654 100644
--- a/lustre/ldlm/ldlm_request.c
+++ b/lustre/ldlm/ldlm_request.c
@@ -700,7 +700,7 @@ int ldlm_prep_elc_req(struct obd_export *exp, struct ptlrpc_request *req,
         struct ldlm_namespace   *ns = exp->exp_obd->obd_namespace;
         struct req_capsule      *pill = &req->rq_pill;
         struct ldlm_request     *dlm = NULL;
-        int flags, avail, to_free, bufcount, pack = 0;
+        int flags, avail, to_free, pack = 0;
         CFS_LIST_HEAD(head);
         int rc;
         ENTRY;
@@ -709,7 +709,6 @@ int ldlm_prep_elc_req(struct obd_export *exp, struct ptlrpc_request *req,
                 cancels = &head;
         if (exp_connect_cancelset(exp)) {
                 /* Estimate the amount of available space in the request. */
-                bufcount = req_capsule_filled_sizes(pill, RCL_CLIENT);
                 avail = ldlm_capsule_handles_avail(pill, RCL_CLIENT, canceloff);
 
                 flags = ns_connect_lru_resize(ns) ?
@@ -1115,8 +1114,6 @@ int ldlm_cli_cancel_req(struct obd_export *exp, cfs_list_t *cancels,
                 count = free;
 
         while (1) {
-                int bufcount;
-
                 imp = class_exp2cliimp(exp);
                 if (imp == NULL || imp->imp_invalid) {
                         CDEBUG(D_DLMTRACE,
@@ -1128,7 +1125,6 @@ int ldlm_cli_cancel_req(struct obd_export *exp, cfs_list_t *cancels,
                 if (req == NULL)
                         GOTO(out, rc = -ENOMEM);
 
-                bufcount = req_capsule_filled_sizes(&req->rq_pill, RCL_CLIENT);
                 req_capsule_set_size(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT,
                                      ldlm_request_bufsize(count, LDLM_CANCEL));
 
@@ -1191,7 +1187,7 @@ static inline struct ldlm_pool *ldlm_imp2pl(struct obd_import *imp)
 int ldlm_cli_update_pool(struct ptlrpc_request *req)
 {
         struct obd_device *obd;
-        __u64 old_slv, new_slv;
+        __u64 new_slv;
         __u32 new_limit;
         ENTRY;
         if (unlikely(!req->rq_import || !req->rq_import->imp_obd ||
@@ -1231,7 +1227,6 @@ int ldlm_cli_update_pool(struct ptlrpc_request *req)
          * oops in that time.
          */
         cfs_write_lock(&obd->obd_pool_lock);
-        old_slv = obd->obd_pool_slv;
         obd->obd_pool_slv = new_slv;
         obd->obd_pool_limit = new_limit;
         cfs_write_unlock(&obd->obd_pool_lock);
diff --git a/lustre/llite/dcache.c b/lustre/llite/dcache.c
index 3f202c9..9136e01 100644
--- a/lustre/llite/dcache.c
+++ b/lustre/llite/dcache.c
@@ -82,24 +82,35 @@ static void ll_release(struct dentry *de)
  * an AST before calling d_revalidate_it().  The dentry still exists (marked
  * INVALID) so d_lookup() matches it, but we have no lock on it (so
  * lock_match() fails) and we spin around real_lookup(). */
+#if 1
+int ll_dcompare(const struct dentry *parent, const struct inode *pinode,
+                const struct dentry *dentry, const struct inode *inode,
+                unsigned int len, const char *str, const struct qstr *d_name)
+#else
 int ll_dcompare(struct dentry *parent, struct qstr *d_name, struct qstr *name)
+#endif
 {
         struct dentry *dchild;
         ENTRY;
 
+#if 0
         if (d_name->len != name->len)
                 RETURN(1);
 
         if (memcmp(d_name->name, name->name, name->len))
                 RETURN(1);
+#else
+        if (memcmp(d_name->name, str, d_name->len))
+                RETURN(1);
+#endif
 
         /* XXX: d_name must be in-dentry structure */
         dchild = container_of(d_name, struct dentry, d_name); /* ugh */
 
         CDEBUG(D_DENTRY,"found name %.*s(%p) - flags %d/%x - refc %d\n",
-               name->len, name->name, dchild,
+               d_name->len, d_name->name, dchild,
                d_mountpoint(dchild), dchild->d_flags & DCACHE_LUSTRE_INVALID,
-               atomic_read(&dchild->d_count));
+               d_refcount(dchild));
 
          /* mountpoint is always valid */
         if (d_mountpoint(dchild))
@@ -149,7 +160,7 @@ static int find_cbdata(struct inode *inode)
  * - return 0 to cache the dentry
  * Should NOT be called with the dcache lock, see fs/dcache.c
  */
-static int ll_ddelete(struct dentry *de)
+static int ll_ddelete(const struct dentry *de)
 {
         ENTRY;
         LASSERT(de);
@@ -157,12 +168,12 @@ static int ll_ddelete(struct dentry *de)
         CDEBUG(D_DENTRY, "%s dentry %.*s (%p, parent %p, inode %p) %s%s\n",
                (de->d_flags & DCACHE_LUSTRE_INVALID ? "deleting" : "keeping"),
                de->d_name.len, de->d_name.name, de, de->d_parent, de->d_inode,
-               d_unhashed(de) ? "" : "hashed,",
+               d_unhashed((struct dentry *)de) ? "" : "hashed,",
                list_empty(&de->d_subdirs) ? "" : "subdirs");
 
         /* if not ldlm lock for this inode, set i_nlink to 0 so that
          * this inode can be recycled later b=20433 */
-        LASSERT(atomic_read(&de->d_count) == 0);
+        LASSERT(d_refcount(de) == 0);
         if (de->d_inode && !find_cbdata(de->d_inode))
                 de->d_inode->i_nlink = 0;
 
@@ -179,7 +190,7 @@ static int ll_set_dd(struct dentry *de)
 
         CDEBUG(D_DENTRY, "ldd on dentry %.*s (%p) parent %p inode %p refc %d\n",
                de->d_name.len, de->d_name.name, de, de->d_parent, de->d_inode,
-               atomic_read(&de->d_count));
+               d_refcount(de));
 
         if (de->d_fsdata == NULL) {
                 struct ll_dentry_data *lld;
@@ -262,19 +273,17 @@ void ll_intent_release(struct lookup_intent *it)
 int ll_drop_dentry(struct dentry *dentry)
 {
         lock_dentry(dentry);
-        if (atomic_read(&dentry->d_count) == 0) {
+        if (d_refcount(dentry) == 0) {
                 CDEBUG(D_DENTRY, "deleting dentry %.*s (%p) parent %p "
                        "inode %p\n", dentry->d_name.len,
                        dentry->d_name.name, dentry, dentry->d_parent,
                        dentry->d_inode);
-                dget_locked(dentry);
+                dget_dlock(dentry);
                 __d_drop(dentry);
                 unlock_dentry(dentry);
-                spin_unlock(&dcache_lock);
-                cfs_spin_unlock(&ll_lookup_lock);
+                LL_UNLOCK_DCACHE;
                 dput(dentry);
-                cfs_spin_lock(&ll_lookup_lock);
-                spin_lock(&dcache_lock);
+                LL_LOCK_DCACHE;
                 return 1;
         }
         /* disconected dentry can not be find without lookup, because we
@@ -288,7 +297,7 @@ int ll_drop_dentry(struct dentry *dentry)
                 CDEBUG(D_DENTRY, "unhashing dentry %.*s (%p) parent %p "
                        "inode %p refc %d\n", dentry->d_name.len,
                        dentry->d_name.name, dentry, dentry->d_parent,
-                       dentry->d_inode, atomic_read(&dentry->d_count));
+                       dentry->d_inode, d_refcount(dentry));
                 /* actually we don't unhash the dentry, rather just
                  * mark it inaccessible for to __d_lookup(). otherwise
                  * sys_getcwd() could return -ENOENT -bzzz */
@@ -314,8 +323,10 @@ void ll_unhash_aliases(struct inode *inode)
                inode->i_ino, inode->i_generation, inode);
 
         head = &inode->i_dentry;
-        cfs_spin_lock(&ll_lookup_lock);
-        spin_lock(&dcache_lock);
+        LL_LOCK_DCACHE;
+#ifndef HAVE_DCACHE_LOCK
+        cfs_spin_lock(&inode->i_lock);
+#endif
 restart:
         tmp = head;
         while ((tmp = tmp->next) != head) {
@@ -336,8 +347,10 @@ restart:
                 if (ll_drop_dentry(dentry))
                           goto restart;
         }
-        spin_unlock(&dcache_lock);
-        cfs_spin_unlock(&ll_lookup_lock);
+#ifndef HAVE_DCACHE_LOCK
+        cfs_spin_unlock(&inode->i_lock);
+#endif
+        LL_UNLOCK_DCACHE;
 
         EXIT;
 }
@@ -455,7 +468,7 @@ int ll_revalidate_it(struct dentry *de, int lookup_flags,
                 struct inode *inode = de->d_inode;
                 struct ll_inode_info *lli = ll_i2info(inode);
                 struct obd_client_handle **och_p;
-                __u64 *och_usecount;
+/*                __u64 *och_usecount; */
 
                 /*
                  * We used to check for MDS_INODELOCK_OPEN here, but in fact
@@ -470,13 +483,13 @@ int ll_revalidate_it(struct dentry *de, int lookup_flags,
 
                 if (it->it_flags & FMODE_WRITE) {
                         och_p = &lli->lli_mds_write_och;
-                        och_usecount = &lli->lli_open_fd_write_count;
+/*                        och_usecount = &lli->lli_open_fd_write_count; */
                 } else if (it->it_flags & FMODE_EXEC) {
                         och_p = &lli->lli_mds_exec_och;
-                        och_usecount = &lli->lli_open_fd_exec_count;
+/*                        och_usecount = &lli->lli_open_fd_exec_count; */
                 } else {
                         och_p = &lli->lli_mds_read_och;
-                        och_usecount = &lli->lli_open_fd_read_count;
+/*                        och_usecount = &lli->lli_open_fd_read_count; */
                 }
                 /* Check for the proper lock. */
                 if (!ll_have_md_lock(inode, MDS_INODELOCK_LOOKUP, LCK_MINMODE))
@@ -552,14 +565,12 @@ revalidate_finish:
 
         /* unfortunately ll_intent_lock may cause a callback and revoke our
          * dentry */
-        cfs_spin_lock(&ll_lookup_lock);
-        spin_lock(&dcache_lock);
+        LL_LOCK_DCACHE;
         lock_dentry(de);
         __d_drop(de);
         unlock_dentry(de);
-        d_rehash_cond(de, 0);
-        spin_unlock(&dcache_lock);
-        cfs_spin_unlock(&ll_lookup_lock);
+        ll_d_rehash_cond(de, 0);
+        LL_UNLOCK_DCACHE;
 
 out:
         /* We do not free request as it may be reused during following lookup
@@ -576,7 +587,7 @@ out:
                 CDEBUG(D_DENTRY, "revalidated dentry %.*s (%p) parent %p "
                        "inode %p refc %d\n", de->d_name.len,
                        de->d_name.name, de, de->d_parent, de->d_inode,
-                       atomic_read(&de->d_count));
+                       d_refcount(de));
                 if (de->d_flags & DCACHE_LUSTRE_INVALID) {
                         lock_dentry(de);
                         de->d_flags &= ~DCACHE_LUSTRE_INVALID;
diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c
index ff0e92d..178c504 100644
--- a/lustre/llite/dir.c
+++ b/lustre/llite/dir.c
@@ -57,6 +57,8 @@
 #include <lustre_fid.h>
 #include "llite_internal.h"
 
+#define HAVE_PAGE_CHECKED 1
+
 #ifndef HAVE_PAGE_CHECKED
 #ifdef HAVE_PG_FS_MISC
 #define PageChecked(page)        test_bit(PG_fs_misc, &(page)->flags)
@@ -451,7 +453,6 @@ int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
         struct page          *page;
         struct ll_dir_chain   chain;
         int                   done;
-        int                   shift;
         int                   rc;
         ENTRY;
 
@@ -467,7 +468,6 @@ int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
 
         rc    = 0;
         done  = 0;
-        shift = 0;
         ll_dir_chain_init(&chain);
 
         fd->fd_dir.lfd_next = pos;
@@ -825,9 +825,14 @@ static int copy_and_ioctl(int cmd, struct obd_export *exp, void *data, int len)
         return rc;
 }
 
-static int ll_dir_ioctl(struct inode *inode, struct file *file,
+#ifdef HAVE_COMPAT_IOCTL
+static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+#else
+static int ll_dir_ioctl(struct inode *unused, 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);
         struct obd_ioctl_data *data;
         int rc = 0;
@@ -1448,5 +1453,9 @@ struct file_operations ll_dir_operations = {
         .release  = ll_dir_release,
         .read     = generic_read_dir,
         .readdir  = ll_readdir,
+#ifdef HAVE_COMPAT_IOCTL
+        .compat_ioctl    = ll_dir_ioctl
+#else
         .ioctl    = ll_dir_ioctl
+#endif
 };
diff --git a/lustre/llite/file.c b/lustre/llite/file.c
index c186b5a..4262b0d 100644
--- a/lustre/llite/file.c
+++ b/lustre/llite/file.c
@@ -892,7 +892,7 @@ static ssize_t ll_file_io_generic(const struct lu_env *env,
 out:
         cl_io_fini(env, io);
         if (iot == CIT_WRITE)
-                lli->lli_write_rc = result < 0 ? : 0;
+                lli->lli_write_rc = result < 0 ? result : 0;
         return result;
 }
 
@@ -1864,10 +1864,13 @@ loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_LLSEEK, 1);
 
         if (origin == 2) { /* SEEK_END */
-                int nonblock = 0, rc;
+                int rc;
+#if 0
+                int nonblock = 0;
 
                 if (file->f_flags & O_NONBLOCK)
                         nonblock = LDLM_FL_BLOCK_NOWAIT;
+#endif
 
                 rc = cl_glimpse_size(inode);
                 if (rc != 0)
@@ -1917,9 +1920,13 @@ int ll_flush(struct file *file)
         return rc ? -EIO : 0;
 }
 
-int ll_fsync(struct file *file, struct dentry *dentry, int data)
+int ll_fsync(struct file *file,
+#ifndef HAVE_FSYNC_TWO_ARGS
+             struct dentry *dentry,
+#endif
+             int data)
 {
-        struct inode *inode = dentry->d_inode;
+        struct inode *inode = file->f_dentry->d_inode;
         struct ll_inode_info *lli = ll_i2info(inode);
         struct lov_stripe_md *lsm = lli->lli_smd;
         struct ptlrpc_request *req;
@@ -1982,7 +1989,7 @@ int ll_fsync(struct file *file, struct dentry *dentry, int data)
                         rc = err;
                 OBDO_FREE(oinfo->oi_oa);
                 OBD_FREE_PTR(oinfo);
-                lli->lli_write_rc = err < 0 ? : 0;
+                lli->lli_write_rc = err < 0 ? err : 0;
         }
 
         RETURN(rc);
@@ -2175,7 +2182,6 @@ int __ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it,
 {
         struct inode *inode = dentry->d_inode;
         struct ptlrpc_request *req = NULL;
-        struct ll_sb_info *sbi;
         struct obd_export *exp;
         int rc = 0;
         ENTRY;
@@ -2184,7 +2190,6 @@ int __ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it,
                 CERROR("REPORT THIS LINE TO PETER\n");
                 RETURN(0);
         }
-        sbi = ll_i2sbi(inode);
 
         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),name=%s\n",
                inode->i_ino, inode->i_generation, inode, dentry->d_name.name);
@@ -2232,11 +2237,9 @@ int __ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it,
                    here to preserve get_cwd functionality on 2.6.
                    Bug 10503 */
                 if (!dentry->d_inode->i_nlink) {
-                        cfs_spin_lock(&ll_lookup_lock);
-                        spin_lock(&dcache_lock);
+                        LL_LOCK_DCACHE;
                         ll_drop_dentry(dentry);
-                        spin_unlock(&dcache_lock);
-                        cfs_spin_unlock(&ll_lookup_lock);
+                        LL_UNLOCK_DCACHE;
                 }
 
                 ll_lookup_finish_locks(&oit, dentry);
@@ -2386,7 +2389,11 @@ int ll_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 
 
 static
-int lustre_check_acl(struct inode *inode, int mask)
+int lustre_check_acl(struct inode *inode, int mask
+#ifdef HAVE_CHECK_ACL_THREE_ARGS
+                     , unsigned int flags
+#endif
+)
 {
 #ifdef CONFIG_FS_POSIX_ACL
         struct ll_inode_info *lli = ll_i2info(inode);
@@ -2411,10 +2418,12 @@ int lustre_check_acl(struct inode *inode, int mask)
 }
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10))
-#ifndef HAVE_INODE_PERMISION_2ARGS
-int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd)
-#else
+#ifdef HAVE_PERMISSION_FLAGS_ARG
+int ll_inode_permission(struct inode *inode, int mask, unsigned int flags)
+#elif defined(HAVE_INODE_PERMISION_2ARGS)
 int ll_inode_permission(struct inode *inode, int mask)
+#else
+int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd)
 #endif
 {
         int rc = 0;
@@ -2439,7 +2448,7 @@ int ll_inode_permission(struct inode *inode, int mask)
                 return lustre_check_remote_perm(inode, mask);
 
         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_INODE_PERM, 1);
-        rc = generic_permission(inode, mask, lustre_check_acl);
+        rc = generic_permission(inode, mask, flags, lustre_check_acl);
 
         RETURN(rc);
 }
diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h
index a9fdab1..0aabc48 100644
--- a/lustre/llite/llite_internal.h
+++ b/lustre/llite/llite_internal.h
@@ -660,8 +660,6 @@ void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data);
 int ll_som_update(struct inode *inode, struct md_op_data *op_data);
 int ll_inode_getattr(struct inode *inode, struct obdo *obdo,
                      __u64 ioepoch, int sync);
-int ll_md_setattr(struct inode *inode, struct md_op_data *op_data,
-                  struct md_open_data **mod);
 void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
                           struct lustre_handle *fh);
 extern void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
@@ -671,10 +669,12 @@ int ll_getattr_it(struct vfsmount *mnt, struct dentry *de,
                struct lookup_intent *it, struct kstat *stat);
 int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat);
 struct ll_file_data *ll_file_data_get(void);
-#ifndef HAVE_INODE_PERMISION_2ARGS
-int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
-#else
+#ifdef HAVE_PERMISSION_FLAGS_ARG
+int ll_inode_permission(struct inode *inode, int mask, unsigned int);
+#elif defined(HAVE_INODE_PERMISSION_2ARGS)
 int ll_inode_permission(struct inode *inode, int mask);
+#else
+int ll_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
 #endif
 int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
                              int flags, struct lov_user_md *lum,
@@ -686,7 +686,11 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
                      int set_default);
 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmm,
                      int *lmm_size, struct ptlrpc_request **request);
-int ll_fsync(struct file *file, struct dentry *dentry, int data);
+int ll_fsync(struct file *file,
+#ifndef HAVE_FSYNC_TWO_ARGS
+             struct dentry *dentry,
+#endif
+             int data);
 int ll_do_fiemap(struct inode *inode, struct ll_user_fiemap *fiemap,
               int num_bytes);
 int ll_merge_lvb(struct inode *inode);
@@ -709,7 +713,13 @@ int ll_drop_dentry(struct dentry *dentry);
 void ll_unhash_aliases(struct inode *);
 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft);
 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry);
+#if 1
+int ll_dcompare(const struct dentry *parent, const struct inode *pinode,
+                const struct dentry *dentry, const struct inode *inode,
+                unsigned int len, const char *str, const struct qstr *d_name);
+#else
 int ll_dcompare(struct dentry *parent, struct qstr *d_name, struct qstr *name);
+#endif
 int ll_revalidate_it_finish(struct ptlrpc_request *request,
                             struct lookup_intent *it, struct dentry *de);
 
@@ -723,8 +733,8 @@ void ll_put_super(struct super_block *sb);
 void ll_kill_super(struct super_block *sb);
 struct inode *ll_inode_from_lock(struct ldlm_lock *lock);
 void ll_clear_inode(struct inode *inode);
-int ll_setattr_raw(struct inode *inode, struct iattr *attr);
 int ll_setattr(struct dentry *de, struct iattr *attr);
+#define HAVE_STATFS_DENTRY_PARAM 1
 #ifndef HAVE_STATFS_DENTRY_PARAM
 int ll_statfs(struct super_block *sb, struct kstatfs *sfs);
 #else
diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c
index d9635a1..d36aea2 100644
--- a/lustre/llite/llite_lib.c
+++ b/lustre/llite/llite_lib.c
@@ -585,7 +585,7 @@ void lustre_dump_dentry(struct dentry *dentry, int recur)
                " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
                dentry->d_name.len, dentry->d_name.name,
                dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
-               dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
+               dentry->d_parent, dentry->d_inode, d_refcount(dentry),
                dentry->d_flags, dentry->d_fsdata, subdirs);
         if (dentry->d_inode != NULL)
                 ll_dump_inode(dentry->d_inode);
@@ -1109,13 +1109,13 @@ void ll_clear_inode(struct inode *inode)
                 lli->lli_smd = NULL;
         }
 
-
         EXIT;
 }
 
-int ll_md_setattr(struct inode *inode, struct md_op_data *op_data,
-                  struct md_open_data **mod)
+static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data,
+                         struct md_open_data **mod)
 {
+        struct inode *inode = dentry->d_inode;
         struct lustre_md md;
         struct ll_sb_info *sbi = ll_i2sbi(inode);
         struct ptlrpc_request *request = NULL;
@@ -1137,7 +1137,11 @@ int ll_md_setattr(struct inode *inode, struct md_op_data *op_data,
                          * Pretend we done everything. */
                         if (!S_ISREG(inode->i_mode) &&
                             !S_ISDIR(inode->i_mode))
+#ifdef HAVE_SIMPLE_SETATTR
+                                rc = simple_setattr(dentry, &op_data->op_attr);
+#else
                                 rc = inode_setattr(inode, &op_data->op_attr);
+#endif
                 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
                         CERROR("md_setattr fails: rc = %d\n", rc);
                 }
@@ -1156,7 +1160,11 @@ int ll_md_setattr(struct inode *inode, struct md_op_data *op_data,
          * above to avoid invoking vmtruncate, otherwise it is important
          * to call vmtruncate in inode_setattr to update inode->i_size
          * (bug 6196) */
+#ifdef HAVE_SIMPLE_SETATTR
+        rc = simple_setattr(dentry, &op_data->op_attr);
+#else
         rc = inode_setattr(inode, &op_data->op_attr);
+#endif
 
         /* Extract epoch data if obtained. */
         op_data->op_handle = md.body->handle;
@@ -1233,8 +1241,9 @@ static int ll_setattr_ost(struct inode *inode, struct iattr *attr)
  * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
  * at the same time.
  */
-int ll_setattr_raw(struct inode *inode, struct iattr *attr)
+static int ll_setattr_raw(struct dentry *dentry, struct iattr *attr)
 {
+        struct inode *inode = dentry->d_inode;
         struct ll_inode_info *lli = ll_i2info(inode);
         struct lov_stripe_md *lsm = lli->lli_smd;
         struct md_op_data *op_data = NULL;
@@ -1310,7 +1319,7 @@ int ll_setattr_raw(struct inode *inode, struct iattr *attr)
             (ia_valid & (ATTR_SIZE | ATTR_MTIME | ATTR_MTIME_SET)))
                 op_data->op_flags = MF_EPOCH_OPEN;
 
-        rc = ll_md_setattr(inode, op_data, &mod);
+        rc = ll_md_setattr(dentry, op_data, &mod);
         if (rc)
                 GOTO(out, rc);
 
@@ -1368,7 +1377,7 @@ int ll_setattr(struct dentry *de, struct iattr *attr)
             !(attr->ia_valid & ATTR_KILL_SGID))
                 attr->ia_valid |= ATTR_KILL_SGID;
 
-        return ll_setattr_raw(de->d_inode, attr);
+        return ll_setattr_raw(de, attr);
 }
 
 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
@@ -1748,7 +1757,12 @@ void ll_delete_inode(struct inode *inode)
         }
         /* Workaround end */
 
+#ifdef HAVE_EVICT_INODE
+        ll_clear_inode(inode);
+        end_writeback(inode);
+#else
         clear_inode(inode);
+#endif
 
         EXIT;
 }
diff --git a/lustre/llite/llite_mmap.c b/lustre/llite/llite_mmap.c
index 81ee3fb..3d03c8e 100644
--- a/lustre/llite/llite_mmap.c
+++ b/lustre/llite/llite_mmap.c
@@ -35,7 +35,12 @@
  */
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/kernel.h>
 #include <linux/mm.h>
diff --git a/lustre/llite/lloop.c b/lustre/llite/lloop.c
index 6975c85..52aa32a 100644
--- a/lustre/llite/lloop.c
+++ b/lustre/llite/lloop.c
@@ -80,7 +80,12 @@
  */
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 
@@ -737,7 +742,7 @@ static enum llioc_iter lloop_ioctl(struct inode *unused, struct file *file,
                 if (put_user((long)old_encode_dev(dev), (long*)arg))
                         GOTO(out, err = -EFAULT);
 
-                bdev = open_by_devnum(dev, file->f_mode);
+                bdev = blkdev_get_by_dev(dev, file->f_mode, NULL);
                 if (IS_ERR(bdev))
                         GOTO(out, err = PTR_ERR(bdev));
 
diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c
index ad98239..6c6282b 100644
--- a/lustre/llite/namei.c
+++ b/lustre/llite/namei.c
@@ -154,8 +154,10 @@ static void ll_drop_negative_dentry(struct inode *dir)
 {
         struct dentry *dentry, *tmp_alias, *tmp_subdir;
 
-        cfs_spin_lock(&ll_lookup_lock);
-        spin_lock(&dcache_lock);
+        LL_LOCK_DCACHE;
+#ifndef HAVE_DCACHE_LOCK
+        cfs_spin_lock(&dir->i_lock);
+#endif
 restart:
         list_for_each_entry_safe(dentry, tmp_alias,
                                  &dir->i_dentry,d_alias) {
@@ -174,8 +176,10 @@ restart:
                         }
                 }
         }
-        spin_unlock(&dcache_lock);
-        cfs_spin_unlock(&ll_lookup_lock);
+#ifndef HAVE_DCACHE_LOCK
+        cfs_spin_unlock(&dir->i_lock);
+#endif
+        LL_UNLOCK_DCACHE;
 }
 
 
@@ -322,7 +326,7 @@ static void ll_d_add(struct dentry *de, struct inode *inode)
         CDEBUG(D_DENTRY, "adding inode %p to dentry %p\n", inode, de);
         /* d_instantiate */
         if (!list_empty(&de->d_alias)) {
-                spin_unlock(&dcache_lock);
+                LOCK_DCACHE;
                 CERROR("dentry %.*s %p alias next %p, prev %p\n",
                        de->d_name.len, de->d_name.name, de,
                        de->d_alias.next, de->d_alias.prev);
@@ -334,12 +338,12 @@ static void ll_d_add(struct dentry *de, struct inode *inode)
 
         /* d_rehash */
         if (!d_unhashed(de)) {
-                spin_unlock(&dcache_lock);
+                UNLOCK_DCACHE;
                 CERROR("dentry %.*s %p hash next %p\n",
                        de->d_name.len, de->d_name.name, de, de->d_hash.next);
                 LBUG();
         }
-        d_rehash_cond(de, 0);
+        ll_d_rehash_cond(de, 0);
 }
 
 /* Search "inode"'s alias list for a dentry that has the same name and parent
@@ -354,8 +358,7 @@ static struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
         struct dentry *dentry;
         struct dentry *last_discon = NULL;
 
-        cfs_spin_lock(&ll_lookup_lock);
-        spin_lock(&dcache_lock);
+        LL_LOCK_DCACHE;
         list_for_each(tmp, &inode->i_dentry) {
                 dentry = list_entry(tmp, struct dentry, d_alias);
 
@@ -384,31 +387,33 @@ static struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
                            de->d_name.len) != 0)
                         continue;
 
-                dget_locked(dentry);
+                dget_dlock(dentry);
+
                 lock_dentry(dentry);
                 __d_drop(dentry);
                 unlock_dentry(dentry);
+
                 ll_dops_init(dentry, 0, 1);
-                d_rehash_cond(dentry, 0); /* avoid taking dcache_lock inside */
-                spin_unlock(&dcache_lock);
-                cfs_spin_unlock(&ll_lookup_lock);
+                ll_d_rehash_cond(dentry, 0); /* avoid taking dcache_lock inside */
+                LL_UNLOCK_DCACHE;
                 iput(inode);
                 CDEBUG(D_DENTRY, "alias dentry %.*s (%p) parent %p inode %p "
                        "refc %d\n", de->d_name.len, de->d_name.name, de,
-                       de->d_parent, de->d_inode, atomic_read(&de->d_count));
+                       de->d_parent, de->d_inode, d_refcount(de));
                 return dentry;
         }
 
         if (last_discon) {
                 CDEBUG(D_DENTRY, "Reuse disconnected dentry %p inode %p "
                         "refc %d\n", last_discon, last_discon->d_inode,
-                        atomic_read(&last_discon->d_count));
-                dget_locked(last_discon);
+                        d_refcount(last_discon));
+                dget_dlock(last_discon);
+
                 lock_dentry(last_discon);
                 last_discon->d_flags |= DCACHE_LUSTRE_INVALID;
                 unlock_dentry(last_discon);
-                spin_unlock(&dcache_lock);
-                cfs_spin_unlock(&ll_lookup_lock);
+
+                LL_UNLOCK_DCACHE;
                 ll_dops_init(last_discon, 1, 1);
                 d_rehash(de);
                 d_move(last_discon, de);
@@ -420,8 +425,7 @@ static struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
         unlock_dentry(de);
         ll_d_add(de, inode);
 
-        spin_unlock(&dcache_lock);
-        cfs_spin_unlock(&ll_lookup_lock);
+        LL_UNLOCK_DCACHE;
 
         return de;
 }
@@ -481,9 +485,9 @@ int ll_lookup_it_finish(struct ptlrpc_request *request,
                    cannot afford to hash this dentry (done by ll_d_add) as it
                    might get picked up later when UPDATE lock will appear */
                 if (ll_have_md_lock(parent, MDS_INODELOCK_UPDATE, LCK_MINMODE)) {
-                        spin_lock(&dcache_lock);
+                        LOCK_DCACHE;
                         ll_d_add(*de, NULL);
-                        spin_unlock(&dcache_lock);
+                        UNLOCK_DCACHE;
                 } else {
                         /* negative lookup - and don't have update lock to
                          * parent */
@@ -793,10 +797,10 @@ static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode,
         /* Negative dentry may be unhashed if parent does not have UPDATE lock,
          * but some callers, e.g. do_coredump, expect dentry to be hashed after
          * successful create. Hash it here. */
-        spin_lock(&dcache_lock);
+        LOCK_DCACHE;
         if (d_unhashed(dentry))
-                d_rehash_cond(dentry, 0);
-        spin_unlock(&dcache_lock);
+                ll_d_rehash_cond(dentry, 0);
+        UNLOCK_DCACHE;
         RETURN(0);
 }
 
diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c
index 25f45fb..e07bbed 100644
--- a/lustre/llite/rw.c
+++ b/lustre/llite/rw.c
@@ -150,7 +150,6 @@ static struct ll_cl_context *ll_cl_init(struct file *file,
         cio = ccc_env_io(env);
         io = cio->cui_cl.cis_io;
         if (io == NULL && create) {
-                struct vvp_io *vio;
                 loff_t pos;
 
                 /*
@@ -160,7 +159,6 @@ static struct ll_cl_context *ll_cl_init(struct file *file,
                  */
 
                 io = ccc_env_thread_io(env);
-                vio = vvp_env_io(env);
                 ll_io_init(io, file, 1);
 
                 /* No lock at all for this kind of IO - we can't do it because
diff --git a/lustre/llite/rw26.c b/lustre/llite/rw26.c
index aba93e5..9eb378d 100644
--- a/lustre/llite/rw26.c
+++ b/lustre/llite/rw26.c
@@ -39,7 +39,12 @@
  */
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/kernel.h>
 #include <linux/mm.h>
diff --git a/lustre/llite/statahead.c b/lustre/llite/statahead.c
index 0385649..5cd1856 100644
--- a/lustre/llite/statahead.c
+++ b/lustre/llite/statahead.c
@@ -459,15 +459,13 @@ static int do_statahead_interpret(struct ll_statahead_info *sai)
                         GOTO(out, rc);
                 }
 
-                cfs_spin_lock(&ll_lookup_lock);
-                spin_lock(&dcache_lock);
+                LL_LOCK_DCACHE;
                 lock_dentry(dentry);
                 __d_drop(dentry);
                 dentry->d_flags &= ~DCACHE_LUSTRE_INVALID;
                 unlock_dentry(dentry);
-                d_rehash_cond(dentry, 0);
-                spin_unlock(&dcache_lock);
-                cfs_spin_unlock(&ll_lookup_lock);
+                ll_d_rehash_cond(dentry, 0);
+                LL_UNLOCK_DCACHE;
 
                 ll_lookup_finish_locks(it, dentry);
         }
diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c
index 5f27094..f534340 100644
--- a/lustre/llite/super25.c
+++ b/lustre/llite/super25.c
@@ -92,8 +92,12 @@ struct super_operations lustre_super_operations =
 {
         .alloc_inode   = ll_alloc_inode,
         .destroy_inode = ll_destroy_inode,
+#ifdef HAVE_EVICT_INODE
+        .evict_inode   = ll_delete_inode,
+#else
         .clear_inode   = ll_clear_inode,
         .delete_inode  = ll_delete_inode,
+#endif
         .put_super     = ll_put_super,
         .statfs        = ll_statfs,
         .umount_begin  = ll_umount_begin,
diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c
index cd4ab9d..03e36ac 100644
--- a/lustre/lmv/lmv_obd.c
+++ b/lustre/lmv/lmv_obd.c
@@ -2071,7 +2071,6 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
         struct obd_device       *obd = exp->exp_obd;
         struct lmv_obd          *lmv = &obd->u.lmv;
         struct lmv_tgt_desc     *src_tgt;
-        struct lmv_tgt_desc     *tgt_tgt;
         int                      rc;
         int                      sidx;
         int                      loop = 0;
@@ -2131,7 +2130,6 @@ repeat:
         op_data->op_cap = cfs_curproc_cap_pack();
 
         src_tgt = lmv_get_target(lmv, mds1);
-        tgt_tgt = lmv_get_target(lmv, mds2);
 
         /*
          * LOOKUP lock on src child (fid3) should also be cancelled for
diff --git a/lustre/lov/lov_qos.c b/lustre/lov/lov_qos.c
index c1f8c96..42182cf 100644
--- a/lustre/lov/lov_qos.c
+++ b/lustre/lov/lov_qos.c
@@ -790,7 +790,6 @@ static int alloc_qos(struct obd_export *exp, int *idx_arr, int *stripe_cnt,
         int stripe_cnt_min = min_stripe_count(*stripe_cnt, flags);
         struct pool_desc *pool;
         struct ost_pool *osts;
-        struct lov_qos_rr *lqr;
         ENTRY;
 
         if (stripe_cnt_min < 1)
@@ -799,11 +798,9 @@ static int alloc_qos(struct obd_export *exp, int *idx_arr, int *stripe_cnt,
         pool = lov_find_pool(lov, poolname);
         if (pool == NULL) {
                 osts = &(lov->lov_packed);
-                lqr = &(lov->lov_qos.lq_rr);
         } else {
                 cfs_down_read(&pool_tgt_rw_sem(pool));
                 osts = &(pool->pool_obds);
-                lqr = &(pool->pool_rr);
         }
 
         obd_getref(exp->exp_obd);
diff --git a/lustre/lov/lovsub_lock.c b/lustre/lov/lovsub_lock.c
index 4810da4..263adff 100644
--- a/lustre/lov/lovsub_lock.c
+++ b/lustre/lov/lovsub_lock.c
@@ -205,7 +205,6 @@ int lov_sublock_modify(const struct lu_env *env, struct lov_lock *lov,
                        const struct cl_lock_descr *d, int idx)
 {
         struct cl_lock       *parent;
-        struct cl_lock       *child;
         struct lovsub_object *subobj;
         struct cl_lock_descr *pd;
         struct cl_lock_descr *parent_descr;
@@ -215,7 +214,6 @@ int lov_sublock_modify(const struct lu_env *env, struct lov_lock *lov,
         parent_descr = &parent->cll_descr;
         LASSERT(cl_lock_mode_match(d->cld_mode, parent_descr->cld_mode));
 
-        child  = sublock->lss_cl.cls_lock;
         subobj = cl2lovsub(sublock->lss_cl.cls_obj);
         pd     = &lov_env_info(env)->lti_ldescr;
 
diff --git a/lustre/lvfs/fsfilt_ext3.c b/lustre/lvfs/fsfilt_ext3.c
index 880041d..7cc0ccb 100644
--- a/lustre/lvfs/fsfilt_ext3.c
+++ b/lustre/lvfs/fsfilt_ext3.c
@@ -1521,6 +1521,33 @@ do {                                            \
         Q_COPY(out, in, dqb_valid);             \
 } while (0)
 
+static inline int
+ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
+{
+        if (sb->s_qcop->quota_on) {
+                return sb->s_qcop->quota_on(sb, off, ver, name
+#ifdef HAVE_QUOTA_ON_5ARGS
+                                            , remount
+#endif
+                                           );
+        }
+        else
+                return -ENOSYS;
+}
+
+static inline int ll_quota_off(struct super_block *sb, int off, int remount)
+{
+        if (sb->s_qcop->quota_off) {
+                return sb->s_qcop->quota_off(sb, off
+#ifdef HAVE_QUOTA_OFF_3ARGS
+                                             , remount
+#endif
+                                            );
+        }
+        else
+                return -ENOSYS;
+}
+
 static int fsfilt_ext3_quotactl(struct super_block *sb,
                                 struct obd_quotactl *oqc)
 {
diff --git a/lustre/lvfs/lvfs_linux.c b/lustre/lvfs/lvfs_linux.c
index 4269afe..b610b21 100644
--- a/lustre/lvfs/lvfs_linux.c
+++ b/lustre/lvfs/lvfs_linux.c
@@ -125,8 +125,8 @@ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
         OBD_SET_CTXT_MAGIC(save);
 
         save->fs = get_fs();
-        LASSERT(cfs_atomic_read(&cfs_fs_pwd(current->fs)->d_count));
-        LASSERT(cfs_atomic_read(&new_ctx->pwd->d_count));
+        LASSERT(d_refcount(cfs_fs_pwd(current->fs)));
+        LASSERT(d_refcount(new_ctx->pwd));
         save->pwd = dget(cfs_fs_pwd(current->fs));
         save->pwdmnt = mntget(cfs_fs_mnt(current->fs));
         save->luc.luc_umask = cfs_curproc_umask();
@@ -375,7 +375,12 @@ int lustre_fsync(struct file *file)
         if (!file || !file->f_op || !file->f_op->fsync)
                 RETURN(-ENOSYS);
 
-        RETURN(file->f_op->fsync(file, file->f_dentry, 0));
+        RETURN(file->f_op->fsync(file,
+#ifndef HAVE_FSYNC_TWO_ARGS
+                                 file->f_dentry,
+#endif
+                                 0));
+
 }
 EXPORT_SYMBOL(lustre_fsync);
 
diff --git a/lustre/mdc/mdc_locks.c b/lustre/mdc/mdc_locks.c
index 7ec8408..da0ef44 100644
--- a/lustre/mdc/mdc_locks.c
+++ b/lustre/mdc/mdc_locks.c
@@ -635,7 +635,6 @@ int mdc_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
 {
         struct obd_device     *obddev = class_exp2obd(exp);
         struct ptlrpc_request *req = NULL;
-        struct req_capsule    *pill;
         int                    flags = extra_lock_flags;
         int                    rc;
         struct ldlm_res_id res_id;
@@ -686,7 +685,6 @@ int mdc_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
 
         if (IS_ERR(req))
                 RETURN(PTR_ERR(req));
-        pill = &req->rq_pill;
 
         /* It is important to obtain rpc_lock first (if applicable), so that
          * threads that are serialised with rpc_lock are not polluting our
diff --git a/lustre/mdc/mdc_reint.c b/lustre/mdc/mdc_reint.c
index 89cd5be..e5e40ae 100644
--- a/lustre/mdc/mdc_reint.c
+++ b/lustre/mdc/mdc_reint.c
@@ -41,7 +41,12 @@
 
 #ifdef __KERNEL__
 #ifndef AUTOCONF_INCLUDED
-# include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 # include <linux/module.h>
 # include <linux/kernel.h>
diff --git a/lustre/mds/mds_log.c b/lustre/mds/mds_log.c
index 70aac6e..86f9576 100644
--- a/lustre/mds/mds_log.c
+++ b/lustre/mds/mds_log.c
@@ -43,7 +43,12 @@
 #define DEBUG_SUBSYSTEM S_MDS
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/version.h>
diff --git a/lustre/mdt/mdt_identity.c b/lustre/mdt/mdt_identity.c
index f731044..b632bba 100644
--- a/lustre/mdt/mdt_identity.c
+++ b/lustre/mdt/mdt_identity.c
@@ -45,7 +45,12 @@
 #define DEBUG_SUBSYSTEM S_MDS
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/lustre/mdt/mdt_idmap.c b/lustre/mdt/mdt_idmap.c
index 1d1005c..e7e0e4c 100644
--- a/lustre/mdt/mdt_idmap.c
+++ b/lustre/mdt/mdt_idmap.c
@@ -45,7 +45,12 @@
 #define DEBUG_SUBSYSTEM S_MDS
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/lustre/obdclass/cl_lock.c b/lustre/obdclass/cl_lock.c
index 21919b3..12aed1f 100644
--- a/lustre/obdclass/cl_lock.c
+++ b/lustre/obdclass/cl_lock.c
@@ -295,14 +295,12 @@ static void cl_lock_free(const struct lu_env *env, struct cl_lock *lock)
 void cl_lock_put(const struct lu_env *env, struct cl_lock *lock)
 {
         struct cl_object        *obj;
-        struct cl_object_header *head;
         struct cl_site          *site;
 
         LINVRNT(cl_lock_invariant(env, lock));
         ENTRY;
         obj = lock->cll_descr.cld_obj;
         LINVRNT(obj != NULL);
-        head = cl_object_header(obj);
         site = cl_object_site(obj);
 
         CDEBUG(D_TRACE, "releasing reference: %d %p %lu\n",
diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c
index e0a9416..fc2c0fe 100644
--- a/lustre/obdclass/genops.c
+++ b/lustre/obdclass/genops.c
@@ -1554,8 +1554,7 @@ static void obd_zombie_export_add(struct obd_export *exp) {
         cfs_list_add(&exp->exp_obd_chain, &obd_zombie_exports);
         cfs_spin_unlock(&obd_zombie_impexp_lock);
 
-        if (obd_zombie_impexp_notify != NULL)
-                obd_zombie_impexp_notify();
+        obd_zombie_impexp_notify();
 }
 
 /**
@@ -1569,8 +1568,7 @@ static void obd_zombie_import_add(struct obd_import *imp) {
         cfs_list_add(&imp->imp_zombie_chain, &obd_zombie_imports);
         cfs_spin_unlock(&obd_zombie_impexp_lock);
 
-        if (obd_zombie_impexp_notify != NULL)
-                obd_zombie_impexp_notify();
+        obd_zombie_impexp_notify();
 }
 
 /**
diff --git a/lustre/obdclass/linux/linux-module.c b/lustre/obdclass/linux/linux-module.c
index d893f16..6ff5e37 100644
--- a/lustre/obdclass/linux/linux-module.c
+++ b/lustre/obdclass/linux/linux-module.c
@@ -47,7 +47,12 @@
 
 #ifdef __KERNEL__
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h> /* for CONFIG_PROC_FS */
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/errno.h>
diff --git a/lustre/obdclass/linux/linux-sysctl.c b/lustre/obdclass/linux/linux-sysctl.c
index db6edd8..61af63c 100644
--- a/lustre/obdclass/linux/linux-sysctl.c
+++ b/lustre/obdclass/linux/linux-sysctl.c
@@ -313,7 +313,9 @@ int LL_PROC_PROTO(proc_at_history)
 #ifdef CONFIG_SYSCTL
 static cfs_sysctl_table_t obd_table[] = {
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_TIMEOUT,
+#endif
                 .procname = "timeout",
                 .data     = &obd_timeout,
                 .maxlen   = sizeof(int),
@@ -321,7 +323,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_set_timeout
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_DEBUG_PEER_ON_TIMEOUT,
+#endif
                 .procname = "debug_peer_on_timeout",
                 .data     = &obd_debug_peer_on_timeout,
                 .maxlen   = sizeof(int),
@@ -329,7 +333,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_dointvec
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_DUMP_ON_TIMEOUT,
+#endif
                 .procname = "dump_on_timeout",
                 .data     = &obd_dump_on_timeout,
                 .maxlen   = sizeof(int),
@@ -337,7 +343,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_dointvec
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_DUMP_ON_EVICTION,
+#endif
                 .procname = "dump_on_eviction",
                 .data     = &obd_dump_on_eviction,
                 .maxlen   = sizeof(int),
@@ -345,7 +353,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_dointvec
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_MEMUSED,
+#endif
                 .procname = "memused",
                 .data     = NULL,
                 .maxlen   = 0,
@@ -353,7 +363,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_memory_alloc
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_PAGESUSED,
+#endif
                 .procname = "pagesused",
                 .data     = NULL,
                 .maxlen   = 0,
@@ -361,7 +373,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_pages_alloc
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_MAXMEMUSED,
+#endif
                 .procname = "memused_max",
                 .data     = NULL,
                 .maxlen   = 0,
@@ -369,7 +383,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_mem_max
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_MAXPAGESUSED,
+#endif
                 .procname = "pagesused_max",
                 .data     = NULL,
                 .maxlen   = 0,
@@ -377,7 +393,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_pages_max
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_LDLM_TIMEOUT,
+#endif
                 .procname = "ldlm_timeout",
                 .data     = &ldlm_timeout,
                 .maxlen   = sizeof(int),
@@ -386,7 +404,9 @@ static cfs_sysctl_table_t obd_table[] = {
         },
 #ifdef RANDOM_FAIL_ALLOC
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_ALLOC_FAIL_RATE,
+#endif
                 .procname = "alloc_fail_rate",
                 .data     = &obd_alloc_fail_rate,
                 .maxlen   = sizeof(int),
@@ -395,7 +415,9 @@ static cfs_sysctl_table_t obd_table[] = {
         },
 #endif
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_MAX_DIRTY_PAGES,
+#endif
                 .procname = "max_dirty_mb",
                 .data     = &obd_max_dirty_pages,
                 .maxlen   = sizeof(int),
@@ -403,7 +425,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_max_dirty_pages_in_mb
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_AT_MIN,
+#endif
                 .procname = "at_min",
                 .data     = &at_min,
                 .maxlen   = sizeof(int),
@@ -411,7 +435,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_at_min
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_AT_MAX,
+#endif
                 .procname = "at_max",
                 .data     = &at_max,
                 .maxlen   = sizeof(int),
@@ -419,7 +445,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_at_max
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_AT_EXTRA,
+#endif
                 .procname = "at_extra",
                 .data     = &at_extra,
                 .maxlen   = sizeof(int),
@@ -427,7 +455,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_at_extra
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_AT_EARLY_MARGIN,
+#endif
                 .procname = "at_early_margin",
                 .data     = &at_early_margin,
                 .maxlen   = sizeof(int),
@@ -435,7 +465,9 @@ static cfs_sysctl_table_t obd_table[] = {
                 .proc_handler = &proc_at_early_margin
         },
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_AT_HISTORY,
+#endif
                 .procname = "at_history",
                 .data     = &at_history,
                 .maxlen   = sizeof(int),
@@ -447,7 +479,9 @@ static cfs_sysctl_table_t obd_table[] = {
 
 static cfs_sysctl_table_t parent_table[] = {
         {
+#ifdef HAVE_CTL_NAME
                 .ctl_name = OBD_SYSCTL,
+#endif
                 .procname = "lustre",
                 .data     = NULL,
                 .maxlen   = 0,
diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c
index e92d1c2..40d5ea1 100644
--- a/lustre/obdclass/obd_mount.c
+++ b/lustre/obdclass/obd_mount.c
@@ -80,6 +80,22 @@ static struct lustre_mount_info *server_find_mount(const char *name)
         RETURN(NULL);
 }
 
+static unsigned int mnt_get_count(struct vfsmount *mnt)
+{
+#ifdef CONFIG_SMP
+        unsigned int count = 0;
+        int cpu;
+
+        for_each_possible_cpu(cpu) {
+                count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_count;
+        }
+
+        return count;
+#else
+        return mnt->mnt_count;
+#endif
+}
+
 /* we must register an obd for a mount before we call the setup routine.
    *_setup will call lustre_get_mount to get the mnt struct
    by obd_name, since we can't pass the pointer to setup. */
@@ -120,7 +136,7 @@ static int server_register_mount(const char *name, struct super_block *sb,
         cfs_up(&lustre_mount_info_lock);
 
         CDEBUG(D_MOUNT, "reg_mnt %p from %s, vfscount=%d\n",
-               lmi->lmi_mnt, name, cfs_atomic_read(&lmi->lmi_mnt->mnt_count));
+               lmi->lmi_mnt, name, mnt_get_count(lmi->lmi_mnt));
 
         RETURN(0);
 }
@@ -140,7 +156,7 @@ static int server_deregister_mount(const char *name)
         }
 
         CDEBUG(D_MOUNT, "dereg_mnt %p from %s, vfscount=%d\n",
-               lmi->lmi_mnt, name, cfs_atomic_read(&lmi->lmi_mnt->mnt_count));
+               lmi->lmi_mnt, name, mnt_get_count(lmi->lmi_mnt));
 
         OBD_FREE(lmi->lmi_name, strlen(lmi->lmi_name) + 1);
         cfs_list_del(&lmi->lmi_list_chain);
@@ -172,7 +188,7 @@ struct lustre_mount_info *server_get_mount(const char *name)
 
         CDEBUG(D_MOUNT, "get_mnt %p from %s, refs=%d, vfscount=%d\n",
                lmi->lmi_mnt, name, cfs_atomic_read(&lsi->lsi_mounts),
-               cfs_atomic_read(&lmi->lmi_mnt->mnt_count));
+               mnt_get_count(lmi->lmi_mnt));
 
         RETURN(lmi);
 }
@@ -196,6 +212,8 @@ struct lustre_mount_info *server_get_mount_2(const char *name)
         RETURN(lmi);
 }
 
+#define kernel_locked()         (current->lock_depth >= 0)
+
 static void unlock_mntput(struct vfsmount *mnt)
 {
         if (kernel_locked()) {
@@ -214,7 +232,7 @@ int server_put_mount(const char *name, struct vfsmount *mnt)
 {
         struct lustre_mount_info *lmi;
         struct lustre_sb_info *lsi;
-        int count = atomic_read(&mnt->mnt_count) - 1;
+        int count = mnt_get_count(mnt) - 1;
         ENTRY;
 
         /* This might be the last one, can't deref after this */
@@ -1422,25 +1440,25 @@ static void server_wait_finished(struct vfsmount *mnt)
 
        cfs_waitq_init(&waitq);
 
-       while (atomic_read(&mnt->mnt_count) > 1) {
+       while (mnt_get_count(mnt) > 1) {
                if (waited && (waited % 30 == 0))
                        LCONSOLE_WARN("Mount still busy with %d refs after "
                                       "%d secs.\n",
-                                      atomic_read(&mnt->mnt_count),
+                                      mnt_get_count(mnt),
                                       waited);
                /* Cannot use l_event_wait() for an interruptible sleep. */
                waited += 3;
                blocked = cfs_block_sigsinv(sigmask(SIGKILL));
                cfs_waitq_wait_event_interruptible_timeout(
                        waitq,
-                       (atomic_read(&mnt->mnt_count) == 1),
+                       (mnt_get_count(mnt) == 1),
                        cfs_time_seconds(3),
                        rc);
                cfs_block_sigs(blocked);
                if (rc < 0) {
                        LCONSOLE_EMERG("Danger: interrupted umount %s with "
                                       "%d refs!\n", mnt->mnt_devname,
-                                      atomic_read(&mnt->mnt_count));
+                                      mnt_get_count(mnt));
                        break;
                }
 
@@ -1569,6 +1587,8 @@ static void server_umount_begin(struct super_block *sb)
         EXIT;
 }
 
+#define HAVE_STATFS_DENTRY_PARAM 1
+
 #ifndef HAVE_STATFS_DENTRY_PARAM
 static int server_statfs (struct super_block *sb, cfs_kstatfs_t *buf)
 {
diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c
index f05b13b..981f100 100644
--- a/lustre/obdfilter/filter.c
+++ b/lustre/obdfilter/filter.c
@@ -52,7 +52,12 @@
 #define DEBUG_SUBSYSTEM S_FILTER
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/fs.h>
diff --git a/lustre/obdfilter/filter_io.c b/lustre/obdfilter/filter_io.c
index 859e290..d6b763b 100644
--- a/lustre/obdfilter/filter_io.c
+++ b/lustre/obdfilter/filter_io.c
@@ -43,7 +43,12 @@
 #define DEBUG_SUBSYSTEM S_FILTER
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/pagemap.h> // XXX kill me soon
diff --git a/lustre/obdfilter/filter_io_26.c b/lustre/obdfilter/filter_io_26.c
index 806734b..4fe398b 100644
--- a/lustre/obdfilter/filter_io_26.c
+++ b/lustre/obdfilter/filter_io_26.c
@@ -41,7 +41,12 @@
  */
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/pagemap.h> // XXX kill me soon
diff --git a/lustre/obdfilter/filter_log.c b/lustre/obdfilter/filter_log.c
index 7ae5f88..4a8542d 100644
--- a/lustre/obdfilter/filter_log.c
+++ b/lustre/obdfilter/filter_log.c
@@ -43,7 +43,12 @@
 #define DEBUG_SUBSYSTEM S_FILTER
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/version.h>
diff --git a/lustre/obdfilter/filter_lvb.c b/lustre/obdfilter/filter_lvb.c
index 080db86..a650c85 100644
--- a/lustre/obdfilter/filter_lvb.c
+++ b/lustre/obdfilter/filter_lvb.c
@@ -43,7 +43,12 @@
 #define DEBUG_SUBSYSTEM S_FILTER
 
 #ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 #endif
 #include <linux/module.h>
 #include <linux/version.h>
diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c
index a6dd7cc..2a1a9f1 100644
--- a/lustre/osc/osc_request.c
+++ b/lustre/osc/osc_request.c
@@ -2284,10 +2284,8 @@ static struct ptlrpc_request *osc_build_req(const struct lu_env *env,
         struct osc_brw_async_args *aa;
         struct obdo *oa = NULL;
         const struct obd_async_page_ops *ops = NULL;
-        void *caller_data = NULL;
         struct osc_async_page *oap;
         struct osc_async_page *tmp;
-        struct ost_body *body;
         struct cl_req *clerq = NULL;
         enum cl_req_type crt = (cmd & OBD_BRW_WRITE) ? CRT_WRITE : CRT_READ;
         struct ldlm_lock *lock = NULL;
@@ -2314,7 +2312,6 @@ static struct ptlrpc_request *osc_build_req(const struct lu_env *env,
                 struct cl_page *page = osc_oap2cl_page(oap);
                 if (ops == NULL) {
                         ops = oap->oap_caller_ops;
-                        caller_data = oap->oap_caller_data;
 
                         clerq = cl_req_alloc(env, page, crt,
                                              1 /* only 1-object rpcs for
@@ -2363,7 +2360,6 @@ static struct ptlrpc_request *osc_build_req(const struct lu_env *env,
          * later setattr before earlier BRW (as determined by the request xid),
          * the OST will not use BRW timestamps.  Sadly, there is no obvious
          * way to do this in a single call.  bug 10150 */
-        body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
         cl_req_attr_set(env, clerq, &crattr,
                         OBD_MD_FLMTIME|OBD_MD_FLCTIME|OBD_MD_FLATIME);
 
diff --git a/lustre/ptlrpc/llog_server.c b/lustre/ptlrpc/llog_server.c
index 3929127..e673548 100644
--- a/lustre/ptlrpc/llog_server.c
+++ b/lustre/ptlrpc/llog_server.c
@@ -127,7 +127,6 @@ int llog_origin_handle_destroy(struct ptlrpc_request *req)
         struct lvfs_run_ctxt  saved;
         struct llog_logid    *logid = NULL;
         struct llog_ctxt     *ctxt;
-        __u32                 flags;
         int                   rc;
         ENTRY;
 
@@ -155,7 +154,6 @@ int llog_origin_handle_destroy(struct ptlrpc_request *req)
 
         body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
         body->lgd_logid = loghandle->lgh_id;
-        flags = body->lgd_llh_flags;
         rc = llog_init_handle(loghandle, LLOG_F_IS_PLAIN, NULL);
         if (rc)
                 GOTO(out_close, rc);
diff --git a/lustre/ptlrpc/sec_config.c b/lustre/ptlrpc/sec_config.c
index 5af3690..1c7c866 100644
--- a/lustre/ptlrpc/sec_config.c
+++ b/lustre/ptlrpc/sec_config.c
@@ -795,14 +795,13 @@ EXPORT_SYMBOL(sptlrpc_conf_log_update_end);
 
 void sptlrpc_conf_log_start(const char *logname)
 {
-        struct sptlrpc_conf *conf;
-        char                 fsname[16];
+        char fsname[16];
 
         if (logname2fsname(logname, fsname, sizeof(fsname)))
                 return;
 
         cfs_mutex_lock(&sptlrpc_conf_lock);
-        conf = sptlrpc_conf_get(fsname, 1);
+        sptlrpc_conf_get(fsname, 1);
         cfs_mutex_unlock(&sptlrpc_conf_lock);
 }
 EXPORT_SYMBOL(sptlrpc_conf_log_start);
diff --git a/lustre/ptlrpc/sec_plain.c b/lustre/ptlrpc/sec_plain.c
index b0b9035..283c489 100644
--- a/lustre/ptlrpc/sec_plain.c
+++ b/lustre/ptlrpc/sec_plain.c
@@ -351,8 +351,8 @@ int plain_cli_unwrap_bulk(struct ptlrpc_cli_ctx *ctx,
                           struct ptlrpc_request *req,
                           struct ptlrpc_bulk_desc *desc)
 {
-        struct ptlrpc_bulk_sec_desc *bsdr, *bsdv;
-        struct plain_bulk_token     *tokenr, *tokenv;
+        struct ptlrpc_bulk_sec_desc *bsdv;
+        struct plain_bulk_token     *tokenv;
         int                          rc;
 #ifdef __KERNEL__
         int                          i, nob;
@@ -362,8 +362,6 @@ int plain_cli_unwrap_bulk(struct ptlrpc_cli_ctx *ctx,
         LASSERT(req->rq_reqbuf->lm_bufcount == PLAIN_PACK_SEGMENTS);
         LASSERT(req->rq_repdata->lm_bufcount == PLAIN_PACK_SEGMENTS);
 
-        bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0);
-        tokenr = (struct plain_bulk_token *) bsdr->bsd_data;
         bsdv = lustre_msg_buf(req->rq_repdata, PLAIN_PACK_BULK_OFF, 0);
         tokenv = (struct plain_bulk_token *) bsdv->bsd_data;
 
@@ -911,7 +909,7 @@ int plain_svc_unwrap_bulk(struct ptlrpc_request *req,
 {
         struct ptlrpc_reply_state   *rs = req->rq_reply_state;
         struct ptlrpc_bulk_sec_desc *bsdr, *bsdv;
-        struct plain_bulk_token     *tokenr, *tokenv;
+        struct plain_bulk_token     *tokenr;
         int                          rc;
 
         LASSERT(req->rq_bulk_write);
@@ -920,7 +918,6 @@ int plain_svc_unwrap_bulk(struct ptlrpc_request *req,
         bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0);
         tokenr = (struct plain_bulk_token *) bsdr->bsd_data;
         bsdv = lustre_msg_buf(rs->rs_repbuf, PLAIN_PACK_BULK_OFF, 0);
-        tokenv = (struct plain_bulk_token *) bsdv->bsd_data;
 
         bsdv->bsd_version = 0;
         bsdv->bsd_type = SPTLRPC_BULK_DEFAULT;
@@ -946,14 +943,13 @@ int plain_svc_wrap_bulk(struct ptlrpc_request *req,
 {
         struct ptlrpc_reply_state   *rs = req->rq_reply_state;
         struct ptlrpc_bulk_sec_desc *bsdr, *bsdv;
-        struct plain_bulk_token     *tokenr, *tokenv;
+        struct plain_bulk_token     *tokenv;
         int                          rc;
 
         LASSERT(req->rq_bulk_read);
         LASSERT(req->rq_pack_bulk);
 
         bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0);
-        tokenr = (struct plain_bulk_token *) bsdr->bsd_data;
         bsdv = lustre_msg_buf(rs->rs_repbuf, PLAIN_PACK_BULK_OFF, 0);
         tokenv = (struct plain_bulk_token *) bsdv->bsd_data;
 
diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c
index 902cdfd..5a26216 100644
--- a/lustre/ptlrpc/service.c
+++ b/lustre/ptlrpc/service.c
@@ -1591,7 +1591,7 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc,
         struct timeval         work_start;
         struct timeval         work_end;
         long                   timediff;
-        int                    opc, rc;
+        int                    rc;
         int                    fail_opc = 0;
         ENTRY;
 
@@ -1611,7 +1611,6 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc,
                 RETURN(0);
         }
 
-        opc = lustre_msg_get_opc(request->rq_reqmsg);
         if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT))
                 fail_opc = OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT;
         else if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_TIMEOUT))
@@ -1783,13 +1782,11 @@ ptlrpc_handle_rs (struct ptlrpc_reply_state *rs)
 {
         struct ptlrpc_service     *svc = rs->rs_service;
         struct obd_export         *exp;
-        struct obd_device         *obd;
         int                        nlocks;
         int                        been_handled;
         ENTRY;
 
         exp = rs->rs_export;
-        obd = exp->exp_obd;
 
         LASSERT (rs->rs_difficult);
         LASSERT (rs->rs_scheduled);
diff --git a/lustre/ptlrpc/wirehdr.c b/lustre/ptlrpc/wirehdr.c
index 0c39cce..5c4ec35 100644
--- a/lustre/ptlrpc/wirehdr.c
+++ b/lustre/ptlrpc/wirehdr.c
@@ -41,7 +41,12 @@
 
 #ifdef __KERNEL__
 # ifndef AUTOCONF_INCLUDED
-#  include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 # endif
 # ifdef CONFIG_FS_POSIX_ACL
 #  include <linux/fs.h>
diff --git a/lustre/ptlrpc/wiretest.c b/lustre/ptlrpc/wiretest.c
index 452327c..3f7ecae 100644
--- a/lustre/ptlrpc/wiretest.c
+++ b/lustre/ptlrpc/wiretest.c
@@ -41,7 +41,12 @@
 
 #ifdef __KERNEL__
 # ifndef AUTOCONF_INCLUDED
-#  include <linux/config.h>
+#  include <linux/version.h>
+#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37)
+#    include <generated/autoconf.h>
+#  else
+#    include <linux/config.h>
+#  endif
 # endif
 # ifdef CONFIG_FS_POSIX_ACL
 #  include <linux/fs.h>
diff --git a/lustre/quota/lproc_quota.c b/lustre/quota/lproc_quota.c
index 828a7c1..df99540 100644
--- a/lustre/quota/lproc_quota.c
+++ b/lustre/quota/lproc_quota.c
@@ -181,12 +181,9 @@ int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
         struct obd_device *obd = (struct obd_device *)data;
         char stype[MAX_STYPE_SIZE + 1] = "";
         int oq_type;
-        struct obd_device_target *obt;
 
         LASSERT(obd != NULL);
 
-        obt = &obd->u.obt;
-
         /* Collect the needed information */
         oq_type = obd->u.obt.obt_qctxt.lqc_flags;
 
@@ -291,17 +288,12 @@ int lprocfs_quota_wr_type(struct file *file, const char *buffer,
                           unsigned long count, void *data)
 {
         struct obd_device *obd = (struct obd_device *)data;
-        struct obd_device_target *obt;
-        int type = 0, is_mds;
+        int type = 0;
         unsigned long i;
         char stype[MAX_STYPE_SIZE + 1] = "";
 
         LASSERT(obd != NULL);
 
-        obt = &obd->u.obt;
-
-        is_mds = !strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME);
-
         if (count > MAX_STYPE_SIZE)
                 return -EINVAL;
 
diff --git a/lustre/tests/writeme.c b/lustre/tests/writeme.c
index 837552d..e511af4 100644
--- a/lustre/tests/writeme.c
+++ b/lustre/tests/writeme.c
@@ -47,7 +47,7 @@ void usage(char *prog)
 
 int main(int argc, char **argv)
 {
-        int fd, rc;
+        int fd;
 	int do_sync = 0;
         int i = 0;
 	int file_arg = 1;
@@ -73,7 +73,7 @@ int main(int argc, char **argv)
 
         while (1) {
                 sprintf(buf, "write %d\n", i);
-                rc = write(fd, buf, sizeof(buf));
+                write(fd, buf, sizeof(buf));
 		if (do_sync)
 			sync();
                 sleep(1);
diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c
index dc989a7..d353111 100644
--- a/lustre/utils/liblustreapi.c
+++ b/lustre/utils/liblustreapi.c
@@ -2438,7 +2438,6 @@ int llapi_target_iterate(int type_num, char **obd_type,void *args,llapi_cb_t cb)
                 char *obd_name = NULL;
                 char *obd_uuid = NULL;
                 char *bufp = buf;
-                struct obd_ioctl_data datal = { 0, };
                 struct obd_statfs osfs_buffer;
 
                 while(bufp[0] == ' ')
@@ -2452,9 +2451,6 @@ int llapi_target_iterate(int type_num, char **obd_type,void *args,llapi_cb_t cb)
 
                 memset(&osfs_buffer, 0, sizeof (osfs_buffer));
 
-                datal.ioc_pbuf1 = (char *)&osfs_buffer;
-                datal.ioc_plen1 = sizeof(osfs_buffer);
-
                 for (i = 0; i < type_num; i++) {
                         if (strcmp(obd_type_name, obd_type[i]) != 0)
                                 continue;
diff --git a/lustre/utils/ll_decode_filter_fid.c b/lustre/utils/ll_decode_filter_fid.c
index ac14f25..a394a4c 100644
--- a/lustre/utils/ll_decode_filter_fid.c
+++ b/lustre/utils/ll_decode_filter_fid.c
@@ -51,12 +51,9 @@
 
 int main(int argc, char *argv[])
 {
-	char *prog;
 	int rc = 0;
 	int i;
 
-	prog = basename(argv[0]);
-
 	for (i = 1; i < argc; i++) {
 		char buf[1024]; /* allow xattr that may be larger */
 		struct filter_fid *ff = (void *)buf;
