From 732a664ca90c2043a04eaf7f10a1cea99cca1b86 Mon Sep 17 00:00:00 2001
From: shadow <shadow>
Date: Thu, 17 May 2007 06:47:09 +0000
Subject: [PATCH] update patchless client for support 2.6.20, 2.6.21 and RHEL5
 kernels.

b=11647
i=green
i=adilger
---
 lustre/ChangeLog                              |  4 ++
 lustre/autoconf/lustre-core.m4                | 50 +++++++++++++------
 .../include/linux/lustre_patchless_compat.h   | 28 ++++++++++-
 lustre/llite/dir.c                            |  6 ++-
 lustre/llite/file.c                           |  2 +-
 lustre/llite/rw.c                             |  2 +-
 lustre/llite/super25.c                        |  2 +-
 lustre/lov/lov_ea.c                           |  2 +-
 lustre/obdclass/genops.c                      |  2 +-
 lustre/obdclass/linux/linux-sysctl.c          |  4 +-
 lustre/obdfilter/filter.c                     |  2 +-
 lustre/quota/quota_context.c                  |  2 +-
 lustre/quota/quota_master.c                   |  2 +-
 13 files changed, 81 insertions(+), 27 deletions(-)

diff --git a/lustre/ChangeLog b/lustre/ChangeLog
index 9d94e010a1..5760b930c2 100644
--- a/lustre/ChangeLog
+++ b/lustre/ChangeLog
@@ -140,6 +140,10 @@ Details    : ll_revalidate_it should uses de_inode instead of op_data.fid2
 	     to check whether it is stale, because sometimes, we want the 
 	     enqueue happened anyway, and op_data.fid2 will not be initialized.
      
+Severity   : enhancement
+Bugzilla   : 11647
+Description: update patchless client
+Details    : Add support for patchless client with 2.6.20, 2.6.21 and RHEL 5
 
 --------------------------------------------------------------------------------
 
diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4
index b1efd2af3c..3a5f84b1f0 100644
--- a/lustre/autoconf/lustre-core.m4
+++ b/lustre/autoconf/lustre-core.m4
@@ -1,4 +1,5 @@
 #* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+#* vim:expandtab:shiftwidth=8:tabstop=8:
 #
 # LC_CONFIG_SRCDIR
 #
@@ -7,7 +8,7 @@
 AC_DEFUN([LC_CONFIG_SRCDIR],
 [AC_CONFIG_SRCDIR([lustre/obdclass/obdo.c])
 ])
-
+                           
 #
 # LC_PATH_DEFAULTS
 #
@@ -1039,22 +1040,38 @@ LB_LINUX_TRY_COMPILE([
 ])
 ])
 
-# LC_WB_RANGE_START
-# 2.6.20 rename struct writeback fields
-AC_DEFUN([LC_WB_RANGE_START],
-[AC_MSG_CHECKING([kernel has range_start in struct writeback_control])
+# LC_CANCEL_DIRTY_PAGE
+# 2.6.20 introduse cancel_dirty_page instead of 
+# clear_page_dirty.
+AC_DEFUN([LC_CANCEL_DIRTY_PAGE],
+[AC_MSG_CHECKING([kernel has cancel_dirty_page])
 LB_LINUX_TRY_COMPILE([
-        #include <linux/fs.h>
-        #include <linux/sched.h>
-        #include <linux/writeback.h>
+        #include <linux/page-flags.h>
 ],[
-        struct writeback_control wb;
+        cancel_dirty_page(NULL, 0);
+],[
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_CANCEL_DIRTY_PAGE, 1,
+                  [kernel has cancel_dirty_page instead of clear_page_dirty])
+],[
+        AC_MSG_RESULT(NO)
+])
+])
 
-        wb.range_start = 0;
+# RHEL5 in FS-cache patch rename PG_checked flag
+# into PG_fs_misc
+AC_DEFUN([LC_PG_FS_MISC],
+[AC_MSG_CHECKING([kernel has PG_fs_misc])
+LB_LINUX_TRY_COMPILE([
+        #include <linux/page-flags.h>
+],[
+        #ifndef PG_fs_misc
+        #error PG_fs_misc not defined in kernel
+        #endif
 ],[
         AC_MSG_RESULT(yes)
-        AC_DEFINE(HAVE_WB_RANGE_START, 1,
-                  [writeback control has range_start field])
+        AC_DEFINE(HAVE_PG_FS_MISC, 1,
+                  [is kernel have PG_fs_misc])
 ],[
         AC_MSG_RESULT(NO)
 ])
@@ -1068,7 +1085,7 @@ LB_LINUX_TRY_COMPILE([
 AC_DEFUN([LC_PROG_LINUX],
 [ LC_LUSTRE_VERSION_H
 if test x$enable_server = xyes ; then
-	LC_CONFIG_BACKINGFS
+        LC_CONFIG_BACKINGFS
 fi
 LC_CONFIG_PINGER
 LC_CONFIG_LIBLUSTRE_RECOVERY
@@ -1117,13 +1134,18 @@ LC_STATFS_DENTRY_PARAM
 LC_VFS_KERN_MOUNT
 LC_INVALIDATEPAGE_RETURN_INT
 LC_UMOUNTBEGIN_HAS_VFSMOUNT
-LC_WB_RANGE_START
+
+#2.6.18 + RHEL5 (fc6)
+LC_PG_FS_MISC
 
 # 2.6.19
 LC_INODE_BLKSIZE
 LC_VFS_READDIR_U64_INO
 LC_GENERIC_FILE_READ
 LC_GENERIC_FILE_WRITE
+
+# 2.6.20
+LC_CANCEL_DIRTY_PAGE
 ])
 
 #
diff --git a/lustre/include/linux/lustre_patchless_compat.h b/lustre/include/linux/lustre_patchless_compat.h
index 6199c61b97..61c9ee7cca 100644
--- a/lustre/include/linux/lustre_patchless_compat.h
+++ b/lustre/include/linux/lustre_patchless_compat.h
@@ -1,3 +1,25 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef LUSTRE_PATCHLESS_COMPAT_H
 #define LUSTRE_PATCHLESS_COMPAT_H
 
@@ -46,7 +68,11 @@ truncate_complete_page(struct address_space *mapping, struct page *page)
         if (PagePrivate(page))
                 page->mapping->a_ops->invalidatepage(page, 0);
 
+#ifdef HAVE_CANCEL_DIRTY_PAGE
+        cancel_dirty_page(page, PAGE_SIZE);
+#else
         clear_page_dirty(page);
+#endif
         ClearPageUptodate(page);
         ClearPageMappedToDisk(page);
         ll_remove_from_page_cache(page);
@@ -67,7 +93,7 @@ static inline void d_rehash_cond(struct dentry * entry, int lock)
 }
 
 #define __d_rehash(dentry, lock) d_rehash_cond(dentry, lock)
-	
+
 #define LUSTRE_PATCHLESS
 
 #ifndef ATTR_FROM_OPEN
diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c
index df73032782..a6895d7a84 100644
--- a/lustre/llite/dir.c
+++ b/lustre/llite/dir.c
@@ -51,8 +51,10 @@
 
 typedef struct ext2_dir_entry_2 ext2_dirent;
 
-#define PageChecked(page)        test_bit(PG_checked, &(page)->flags)
-#define SetPageChecked(page)     set_bit(PG_checked, &(page)->flags)
+#ifdef HAVE_PG_FS_MISC
+#define PageChecked(page)        test_bit(PG_fs_misc, &(page)->flags)
+#define SetPageChecked(page)     set_bit(PG_fs_misc, &(page)->flags)
+#endif
 
 /* returns the page unlocked, but with a reference */
 static int ll_dir_readpage(struct file *file, struct page *page)
diff --git a/lustre/llite/file.c b/lustre/llite/file.c
index 947654f66c..45a74f3771 100644
--- a/lustre/llite/file.c
+++ b/lustre/llite/file.c
@@ -37,7 +37,7 @@ struct ll_file_data *ll_file_data_get(void)
 {
         struct ll_file_data *fd;
 
-        OBD_SLAB_ALLOC(fd, ll_file_data_slab, SLAB_KERNEL, sizeof *fd);
+        OBD_SLAB_ALLOC(fd, ll_file_data_slab, GFP_KERNEL, sizeof *fd);
         return fd;
 }
 
diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c
index 588bfeb63b..aefff58c8b 100644
--- a/lustre/llite/rw.c
+++ b/lustre/llite/rw.c
@@ -593,7 +593,7 @@ static struct ll_async_page *llap_from_page(struct page *page, unsigned origin)
         if (sbi->ll_async_page_count >= sbi->ll_async_page_max)
                 llap_shrink_cache(sbi, 0);
 
-        OBD_SLAB_ALLOC(llap, ll_async_page_slab, SLAB_KERNEL,
+        OBD_SLAB_ALLOC(llap, ll_async_page_slab, GFP_KERNEL,
                        ll_async_page_slab_size);
         if (llap == NULL)
                 RETURN(ERR_PTR(-ENOMEM));
diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c
index e56d77387d..14c191e4c4 100644
--- a/lustre/llite/super25.c
+++ b/lustre/llite/super25.c
@@ -41,7 +41,7 @@ static struct inode *ll_alloc_inode(struct super_block *sb)
 {
         struct ll_inode_info *lli;
         lprocfs_counter_incr((ll_s2sbi(sb))->ll_stats, LPROC_LL_ALLOC_INODE);
-        OBD_SLAB_ALLOC(lli, ll_inode_cachep, SLAB_KERNEL, sizeof *lli);
+        OBD_SLAB_ALLOC(lli, ll_inode_cachep, GFP_KERNEL, sizeof *lli);
         if (lli == NULL)
                 return NULL;
 
diff --git a/lustre/lov/lov_ea.c b/lustre/lov/lov_ea.c
index 07936e3651..7392d83f0f 100755
--- a/lustre/lov/lov_ea.c
+++ b/lustre/lov/lov_ea.c
@@ -95,7 +95,7 @@ struct lov_stripe_md *lsm_alloc_plain(int stripe_count, int *size)
                 return NULL;;
 
         for (i = 0; i < stripe_count; i++) {
-                OBD_SLAB_ALLOC(loi, lov_oinfo_slab, SLAB_NOFS, sizeof(*loi));
+                OBD_SLAB_ALLOC(loi, lov_oinfo_slab, GFP_NOFS, sizeof(*loi));
                 if (loi == NULL)
                         goto err;
                 lsm->lsm_oinfo[i] = loi;
diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c
index 34b137c182..f9ebae6f63 100644
--- a/lustre/obdclass/genops.c
+++ b/lustre/obdclass/genops.c
@@ -58,7 +58,7 @@ static struct obd_device *obd_device_alloc(void)
 {
         struct obd_device *obd;
 
-        OBD_SLAB_ALLOC(obd, obd_device_cachep, SLAB_KERNEL, sizeof(*obd));
+        OBD_SLAB_ALLOC(obd, obd_device_cachep, GFP_KERNEL, sizeof(*obd));
         if (obd != NULL) {
                 obd->obd_magic = OBD_DEVICE_MAGIC;
         }
diff --git a/lustre/obdclass/linux/linux-sysctl.c b/lustre/obdclass/linux/linux-sysctl.c
index f8e4800a4b..fcbd13a2da 100644
--- a/lustre/obdclass/linux/linux-sysctl.c
+++ b/lustre/obdclass/linux/linux-sysctl.c
@@ -110,7 +110,7 @@ void obd_sysctl_init (void)
 {
 #ifdef CONFIG_SYSCTL
         if ( !obd_table_header )
-                obd_table_header = register_sysctl_table(parent_table, 0);
+                obd_table_header = cfs_register_sysctl_table(parent_table, 0);
 #endif
 }
 
@@ -118,7 +118,7 @@ void obd_sysctl_clean (void)
 {
 #ifdef CONFIG_SYSCTL
         if ( obd_table_header )
-                unregister_sysctl_table(obd_table_header);
+                cfs_unregister_sysctl_table(obd_table_header);
         obd_table_header = NULL;
 #endif
 }
diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c
index 13f3f5c3bb..eaacf9d23b 100644
--- a/lustre/obdfilter/filter.c
+++ b/lustre/obdfilter/filter.c
@@ -474,7 +474,7 @@ struct filter_mod_data *filter_fmd_get(struct obd_export *exp,
         struct filter_export_data *fed = &exp->exp_filter_data;
         struct filter_mod_data *found = NULL, *fmd_new = NULL;
 
-        OBD_SLAB_ALLOC(fmd_new, ll_fmd_cachep, SLAB_NOFS, sizeof(*fmd_new));
+        OBD_SLAB_ALLOC(fmd_new, ll_fmd_cachep, GFP_NOFS, sizeof(*fmd_new));
 
         spin_lock(&fed->fed_lock);
         found = filter_fmd_find_nolock(&exp->exp_obd->u.filter,fed,objid,group);
diff --git a/lustre/quota/quota_context.c b/lustre/quota/quota_context.c
index f6340b3bb8..84e413dc3a 100644
--- a/lustre/quota/quota_context.c
+++ b/lustre/quota/quota_context.c
@@ -293,7 +293,7 @@ static struct lustre_qunit *alloc_qunit(struct lustre_quota_ctxt *qctxt,
         struct lustre_qunit *qunit = NULL;
         ENTRY;
 
-        OBD_SLAB_ALLOC(qunit, qunit_cachep, SLAB_NOFS, sizeof(*qunit));
+        OBD_SLAB_ALLOC(qunit, qunit_cachep, GFP_NOFS, sizeof(*qunit));
         if (qunit == NULL)
                 RETURN(NULL);
 
diff --git a/lustre/quota/quota_master.c b/lustre/quota/quota_master.c
index 86f4b724ef..b43522590c 100644
--- a/lustre/quota/quota_master.c
+++ b/lustre/quota/quota_master.c
@@ -116,7 +116,7 @@ static struct lustre_dquot *alloc_dquot(struct lustre_quota_info *lqi,
         struct lustre_dquot *dquot = NULL;
         ENTRY;
 
-        OBD_SLAB_ALLOC(dquot, lustre_dquot_cachep, SLAB_NOFS, sizeof(*dquot));
+        OBD_SLAB_ALLOC(dquot, lustre_dquot_cachep, GFP_NOFS, sizeof(*dquot));
         if (dquot == NULL)
                 RETURN(NULL);
 
-- 
GitLab