From c079cd7484d5e7e656eae050003075e30f7f88cc Mon Sep 17 00:00:00 2001
From: shadow <shadow>
Date: Tue, 6 Nov 2007 19:06:10 +0000
Subject: [PATCH] support for sles10 kernel in lustre.

b=12052
i=johann
i=nikita
---
 lustre/autoconf/lustre-core.m4         | 107 ++++++++++++++++++++++++-
 lustre/include/linux/lustre_acl.h      |  19 ++---
 lustre/include/linux/lustre_compat25.h |  18 +++++
 lustre/include/lu_object.h             |   2 +-
 lustre/include/lustre_mdc.h            |   7 +-
 lustre/llite/dir.c                     |   6 +-
 lustre/mdc/mdc_internal.h              |   3 -
 lustre/obdclass/lu_time.c              |   1 -
 lustre/ptlrpc/layout.c                 |  11 +--
 9 files changed, 146 insertions(+), 28 deletions(-)

diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4
index 1074d5013c..34f43f6726 100644
--- a/lustre/autoconf/lustre-core.m4
+++ b/lustre/autoconf/lustre-core.m4
@@ -1176,6 +1176,99 @@ LB_LINUX_TRY_COMPILE([
 ])
 ])
 
+AC_DEFUN([LC_S_TIME_GRAN],
+[AC_MSG_CHECKING([if super block has s_time_gran member])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/fs.h>
+],[
+	struct super_block sb;
+
+        return sb.s_time_gran;
+],[
+	AC_MSG_RESULT([yes])
+	AC_DEFINE(HAVE_S_TIME_GRAN, 1, [super block has s_time_gran member])
+],[
+        AC_MSG_RESULT([no])
+])
+])
+
+AC_DEFUN([LC_SB_TIME_GRAN],
+[AC_MSG_CHECKING([if kernel has old get_sb_time_gran])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/fs.h>
+],[
+	return get_sb_time_gran(NULL);
+],[
+        AC_MSG_RESULT([yes])
+	AC_DEFINE(HAVE_SB_TIME_GRAN, 1, [kernel has old get_sb_time_gran])
+],[
+        AC_MSG_RESULT([no])
+])
+])
+
+
+# ~2.6.12 merge patch from oracle to convert tree_lock from spinlock to rwlock
+AC_DEFUN([LC_RW_TREE_LOCK],
+[AC_MSG_CHECKING([if kernel has tree_lock as rwlock])
+tmp_flags="$EXTRA_KCFLAGS"
+EXTRA_KCFLAGS="-Werror"
+LB_LINUX_TRY_COMPILE([
+        #include <linux/fs.h>
+],[
+	struct address_space a;
+
+	write_lock(&a.tree_lock);
+],[
+        AC_MSG_RESULT([yes])
+	AC_DEFINE(HAVE_RW_TREE_LOCK, 1, [kernel has tree_lock as rw_lock])
+],[
+        AC_MSG_RESULT([no])
+])
+EXTRA_KCFLAGS="$tmp_flags"
+])
+
+AC_DEFUN([LC_CONST_ACL_SIZE],
+[AC_MSG_CHECKING([calc acl size])
+tmp_flags="$CFLAGS"
+CFLAGS="$CFLAGS -I $LINUX/include $EXTRA_KCFLAGS"
+AC_TRY_RUN([
+#include <linux/autoconf.h>
+#include <linux/types.h>
+// block include 
+#define __LINUX_POSIX_ACL_H
+
+# ifdef CONFIG_FS_POSIX_ACL
+#  ifdef HAVE_XATTR_ACL
+#   include <linux/xattr_acl.h>
+#  endif
+#  ifdef HAVE_LINUX_POSIX_ACL_XATTR_H
+#   include <linux/posix_acl_xattr.h>
+#  endif
+# endif
+
+#include <linux/lustre_acl.h>
+
+#include <stdio.h>
+
+main(void)
+{
+    int size = mds_xattr_acl_size(LUSTRE_POSIX_ACL_MAX_ENTRIES);
+    FILE *f = fopen("acl.size","w+");
+    fprintf(f,"%d", size);
+    fclose(f);
+}
+
+],[
+	acl_size=`cat acl.size`
+	AC_MSG_RESULT([ACL size $acl_size])
+        AC_DEFINE_UNQUOTED(XATTR_ACL_SIZE, AS_TR_SH([$acl_size]), [size of xattr acl])
+],[
+        AC_ERROR([ACL size can't computed])
+])
+CFLAGS="$tmp_flags"
+])
+
+
 #
 # LC_PROG_LINUX
 #
@@ -1193,6 +1286,7 @@ LC_CONFIG_QUOTA
 LC_CONFIG_HEALTH_CHECK_WRITE
 LC_CONFIG_LRU_RESIZE
 
+
 LC_TASK_PPTR
 # RHEL4 patches
 LC_EXPORT_TRUNCATE_COMPLETE
@@ -1217,9 +1311,13 @@ LC_STRUCT_FILE_OPS_UNLOCKED_IOCTL
 LC_FILEMAP_POPULATE
 LC_D_ADD_UNIQUE
 LC_BIT_SPINLOCK_H
+
 LC_XATTR_ACL
-LC_STRUCT_INTENT_FILE
 LC_POSIX_ACL_XATTR_H
+LC_CONST_ACL_SIZE
+
+LC_STRUCT_INTENT_FILE
+
 LC_FUNC_SET_FS_PWD
 LC_CAPA_CRYPTO
 LC_CONFIG_GSS
@@ -1233,6 +1331,13 @@ LC_FUNC_RCU
 # does the kernel have VFS intent patches?
 LC_VFS_INTENT_PATCHES
 
+# ~2.6.11
+LC_S_TIME_GRAN
+LC_SB_TIME_GRAN
+
+# 2.6.12
+LC_RW_TREE_LOCK
+
 # 2.6.15
 LC_INODE_I_MUTEX
 
diff --git a/lustre/include/linux/lustre_acl.h b/lustre/include/linux/lustre_acl.h
index bfa393e0df..bbf6471aca 100644
--- a/lustre/include/linux/lustre_acl.h
+++ b/lustre/include/linux/lustre_acl.h
@@ -14,7 +14,15 @@
 # include <linux/fs.h>
 # include <linux/dcache.h>
 # ifdef CONFIG_FS_POSIX_ACL
-# include <linux/xattr_acl.h>
+#  ifdef HAVE_XATTR_ACL
+#   include <linux/xattr_acl.h>
+#  endif
+#  ifdef HAVE_LINUX_POSIX_ACL_XATTR_H
+#   include <linux/posix_acl_xattr.h>
+#  endif
+# endif
+# ifndef HAVE_VFS_INTENT_PATCHES
+#  include <linux/lustre_intent.h>
 # endif
 #endif
 
@@ -30,14 +38,7 @@
 
 # define LUSTRE_POSIX_ACL_MAX_ENTRIES   (32)
 
-# ifdef __KERNEL__
-# define LUSTRE_POSIX_ACL_MAX_SIZE              \
-                (sizeof(xattr_acl_header) +     \
-                LUSTRE_POSIX_ACL_MAX_ENTRIES *  \
-                sizeof(xattr_acl_entry))
-# else /* __KERNEL__ */
-#  define LUSTRE_POSIX_ACL_MAX_SIZE      0
-# endif /* __KERNEL__ */
+# define LUSTRE_POSIX_ACL_MAX_SIZE   XATTR_ACL_SIZE
 
 #else /* CONFIG_FS_POSIX_ACL */
 # define LUSTRE_POSIX_ACL_MAX_SIZE      0
diff --git a/lustre/include/linux/lustre_compat25.h b/lustre/include/linux/lustre_compat25.h
index e294e3f6e2..b72ea7f7d5 100644
--- a/lustre/include/linux/lustre_compat25.h
+++ b/lustre/include/linux/lustre_compat25.h
@@ -336,5 +336,23 @@ generic_file_write(struct file *filp, const char __user *buf, size_t len, loff_t
 #define p_pptr parent
 #endif
 
+#ifndef HAVE_SB_TIME_GRAN
+#ifndef HAVE_S_TIME_GRAN
+#error Need s_time_gran patch!
+#endif
+static inline u32 get_sb_time_gran(struct super_block *sb)
+{
+        return sb->s_time_gran;
+}
+#endif
+
+#ifdef HAVE_RW_TREE_LOCK
+#define TREE_READ_LOCK_IRQ(mapping)	read_lock_irq(&(mapping)->tree_lock)
+#define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
+#else
+#define TREE_READ_LOCK_IRQ(mapping) spin_lock_irq(&(mapping)->tree_lock)
+#define TREE_READ_UNLOCK_IRQ(mapping) spin_unlock_irq(&(mapping)->tree_lock)
+#endif
+
 #endif /* __KERNEL__ */
 #endif /* _COMPAT25_H */
diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h
index 698caf1f2e..9c070e68db 100644
--- a/lustre/include/lu_object.h
+++ b/lustre/include/lu_object.h
@@ -827,7 +827,7 @@ static inline int lu_object_assert_not_exists(const struct lu_object *o)
 /*
  * Attr of this object.
  */
-static inline const __u32 lu_object_attr(const struct lu_object *o)
+static inline __u32 lu_object_attr(const struct lu_object *o)
 {
         LASSERT(lu_object_exists(o) > 0);
         return o->lo_header->loh_attr;
diff --git a/lustre/include/lustre_mdc.h b/lustre/include/lustre_mdc.h
index d2c30d3c22..7b43f4febb 100644
--- a/lustre/include/lustre_mdc.h
+++ b/lustre/include/lustre_mdc.h
@@ -14,7 +14,12 @@
 # include <linux/fs.h>
 # include <linux/dcache.h>
 # ifdef CONFIG_FS_POSIX_ACL
-# include <linux/xattr_acl.h>
+#  ifdef HAVE_XATTR_ACL
+#   include <linux/xattr_acl.h>
+#  endif
+#  ifdef HAVE_LINUX_POSIX_ACL_XATTR_H
+#   include <linux/posix_acl_xattr.h>
+#  endif
 # endif
 #endif
 #include <lustre_handles.h>
diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c
index da23ebfa44..42c2da66cc 100644
--- a/lustre/llite/dir.c
+++ b/lustre/llite/dir.c
@@ -219,14 +219,14 @@ static struct page *ll_dir_page_locate(struct inode *dir, unsigned long hash,
         struct page *page;
         int found;
 
-	spin_lock_irq(&mapping->tree_lock);
+        TREE_READ_LOCK_IRQ(mapping);
 	found = radix_tree_gang_lookup(&mapping->page_tree,
                                        (void **)&page, offset, 1);
 	if (found > 0) {
                 struct lu_dirpage *dp;
 
 		page_cache_get(page);
-                spin_unlock_irq(&mapping->tree_lock);
+                TREE_READ_UNLOCK_IRQ(mapping);
                 /*
                  * In contrast to find_lock_page() we are sure that directory
                  * page cannot be truncated (while DLM lock is held) and,
@@ -255,7 +255,7 @@ static struct page *ll_dir_page_locate(struct inode *dir, unsigned long hash,
                 }
 
 	} else {
-                spin_unlock_irq(&mapping->tree_lock);
+                TREE_READ_UNLOCK_IRQ(mapping);
                 page = NULL;
         }
         return page;
diff --git a/lustre/mdc/mdc_internal.h b/lustre/mdc/mdc_internal.h
index f982152c44..65df5fc37a 100644
--- a/lustre/mdc/mdc_internal.h
+++ b/lustre/mdc/mdc_internal.h
@@ -83,9 +83,6 @@ static inline int client_is_remote(struct obd_export *exp)
         }
 }
 
-/* Quota stuff */
-extern quota_interface_t *quota_interface;
-
 /* mdc/mdc_locks.c */
 int mdc_set_lock_data(struct obd_export *exp,
                       __u64 *lockh, void *data);
diff --git a/lustre/obdclass/lu_time.c b/lustre/obdclass/lu_time.c
index 3883c779b6..5a11f00791 100644
--- a/lustre/obdclass/lu_time.c
+++ b/lustre/obdclass/lu_time.c
@@ -151,7 +151,6 @@ unsigned long long lu_time_stamp_get(void)
 	 * do_gettimeofday() goes backwards sometimes :(.  Usethe TSC
 	 */
 	unsigned long long ret;
-	extern unsigned long cpu_khz;
 
 	rdtscll(ret);
 	do_div(ret, cpu_khz / 1000);
diff --git a/lustre/ptlrpc/layout.c b/lustre/ptlrpc/layout.c
index d014180ab9..e223d5f207 100644
--- a/lustre/ptlrpc/layout.c
+++ b/lustre/ptlrpc/layout.c
@@ -54,13 +54,6 @@
 #include <lustre_req_layout.h>
 #include <linux/lustre_acl.h>
 
-#if __KERNEL__
-#define __POSIX_ACL_MAX_SIZE \
-        (sizeof(xattr_acl_header) + 32 * sizeof(xattr_acl_entry))
-#else
-#define __POSIX_ACL_MAX_SIZE 0
-#endif
-
 /*
  * empty set of fields... for suitable definition of emptiness.
  */
@@ -540,8 +533,8 @@ EXPORT_SYMBOL(RMF_REC_SETATTR);
 const struct req_msg_field RMF_EADATA = DEFINE_MSGF("eadata", 0, -1, NULL);
 EXPORT_SYMBOL(RMF_EADATA);
 
-const struct req_msg_field RMF_ACL = DEFINE_MSGF("acl", 0,
-                                     __POSIX_ACL_MAX_SIZE, NULL);
+const struct req_msg_field RMF_ACL = 
+        DEFINE_MSGF("acl", 0, LUSTRE_POSIX_ACL_MAX_SIZE, NULL);
 EXPORT_SYMBOL(RMF_ACL);
 
 const struct req_msg_field RMF_LOGCOOKIES =
-- 
GitLab