From 58bffd741cdc917f164f19b4621aa2567e6a5b3e Mon Sep 17 00:00:00 2001
From: Marc Dionne <marc.c.dionne@gmail.com>
Date: Fri, 28 May 2010 17:48:12 -0400
Subject: [PATCH 1/6] Linux: 2.6.35 - fsync no longer takes a dentry

In 2.6.35, the fsync file operations drops the dentry argument.
Add a configure test and cope.

Reviewed-on: http://gerrit.openafs.org/2064
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Simon Wilkinson <sxw@inf.ed.ac.uk>
Tested-by: Derrick Brashear <shadow@dementia.org>

(cherry-picked from commit 4d89ce0a89e9b9e2709e6f6d730f245b5bce744b)

Change-Id: Ifa1f6d2d3c7de03346ba509fab03040ef4f7f26e
Reviewed-on: http://gerrit.openafs.org/2549
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
---
 acinclude.m4                 |    1 +
 src/afs/LINUX/osi_vnodeops.c |    4 +++-
 src/cf/linux-test4.m4        |   17 +++++++++++++++++
 3 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index d4a175c..984b7ff 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -781,6 +781,7 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
 	  	 LINUX_IOP_I_PUT_LINK_TAKES_COOKIE
 	  	 LINUX_DOP_D_REVALIDATE_TAKES_NAMEIDATA
 	  	 LINUX_FOP_F_FLUSH_TAKES_FL_OWNER_T
+		 LINUX_FOP_F_FSYNC_TAKES_DENTRY
 	  	 LINUX_AOP_WRITEBACK_CONTROL
 		 LINUX_FS_STRUCT_FOP_HAS_FLOCK
 		 LINUX_FS_STRUCT_FOP_HAS_SENDFILE
diff --git a/src/afs/LINUX/osi_vnodeops.c b/src/afs/LINUX/osi_vnodeops.c
index ceeba94..ebabc72 100644
--- a/src/afs/LINUX/osi_vnodeops.c
+++ b/src/afs/LINUX/osi_vnodeops.c
@@ -447,8 +447,10 @@ afs_linux_release(struct inode *ip, struct file *fp)
 }
 
 static int
-#if defined(AFS_LINUX24_ENV)
+#if defined(AFS_LINUX24_ENV) && defined(FOP_FSYNC_TAKES_DENTRY)
 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
+#elif defined(AFS_LINUX24_ENV)
+afs_linux_fsync(struct file *fp, int datasync)
 #else
 afs_linux_fsync(struct file *fp, struct dentry *dp)
 #endif
diff --git a/src/cf/linux-test4.m4 b/src/cf/linux-test4.m4
index 2677f04..3e200b0 100644
--- a/src/cf/linux-test4.m4
+++ b/src/cf/linux-test4.m4
@@ -929,6 +929,23 @@ fl_owner_t id;
       ac_cv_linux_func_f_flush_takes_fl_owner_t=no)])
   AC_MSG_RESULT($ac_cv_linux_func_f_flush_takes_fl_owner_t)])
 
+AC_DEFUN([LINUX_FOP_F_FSYNC_TAKES_DENTRY], [
+  AC_MSG_CHECKING([whether file_operations.fsync takes a dentry argument])
+  AC_CACHE_VAL([ac_cv_linux_func_f_fsync_takes_dentry], [
+    AC_TRY_KBUILD(
+[#include <linux/fs.h>],
+[struct inode _inode;
+struct file _file;
+struct dentry _d;
+(void)_inode.i_fop->fsync(&_file, &_d, 0);],
+      ac_cv_linux_func_f_fsync_takes_dentry=yes,
+      ac_cv_linux_func_f_fsync_takes_dentry=no)])
+  AC_MSG_RESULT($ac_cv_linux_func_f_fsync_takes_dentry)
+  if test "x$ac_cv_linux_func_f_fsync_takes_dentry" = "xyes"; then
+    AC_DEFINE([FOP_FSYNC_TAKES_DENTRY], 1, [define if your fops.fsync takes an dentry argument])
+  fi
+])
+
 AC_DEFUN([LINUX_HAVE_KMEM_CACHE_T], [
   AC_MSG_CHECKING([whether kmem_cache_t exists])
   AC_CACHE_VAL([ac_cv_linux_have_kmem_cache_t], [
-- 
1.7.3.2

From 58e56d080b8d19117b60f04ecb37af0c6dcafc1a Mon Sep 17 00:00:00 2001
From: Marc Dionne <marc.c.dionne@gmail.com>
Date: Wed, 11 Aug 2010 18:20:59 -0400
Subject: [PATCH 2/6] Linux: adapt to truncate sequence changes

As part of changes to the truncate sequence, inode_setattr() no
longer exists, and all filesystems have to define the setattr op
so we can assume that it is not NULL.

Introduce a compat inline function afs_inode_setattr that hides
the tests and the different versions from the main code.

Note that the existing test for the inode_setattr() return type
will fail, but the value is no longer used in that case.

This is required for 2.6.36

Reviewed-on: http://gerrit.openafs.org/2543
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

(cherry-picked from commit eaf3378f537935f6b9843886b43d)

Change-Id: I1261e1e67d54409276d8b3530f9ec4f879604733
Reviewed-on: http://gerrit.openafs.org/2550
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
---
 acinclude.m4               |    1 +
 src/afs/LINUX/osi_compat.h |   20 ++++++++++++++++++++
 src/afs/LINUX/osi_file.c   |   13 ++-----------
 src/cf/linux-test4.m4      |   16 ++++++++++++++++
 4 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 984b7ff..bbbe938 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -828,6 +828,7 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
 		 LINUX_STRUCT_CTL_TABLE_HAS_CTL_NAME
 		 LINUX_HAVE_IGET
 		 LINUX_HAVE_I_SIZE_READ
+		 LINUX_HAVE_INODE_SETATTR
 		 LINUX_FS_STRUCT_NAMEIDATA_HAS_PATH
 	         LINUX_EXPORTS_INIT_MM
                  LINUX_EXPORTS_SYS_CHDIR
diff --git a/src/afs/LINUX/osi_compat.h b/src/afs/LINUX/osi_compat.h
index 54b985a..078c6c3 100644
--- a/src/afs/LINUX/osi_compat.h
+++ b/src/afs/LINUX/osi_compat.h
@@ -119,3 +119,23 @@ init_once_func(void * foo) {
 # endif
 #endif
 #endif
+
+static inline int
+afs_inode_setattr(struct osi_file *afile, struct iattr *newattrs) {
+
+    int code = 0;
+    struct inode *inode = OSIFILE_INODE(afile);
+#if !defined(HAVE_LINUX_INODE_SETATTR)
+    code = inode->i_op->setattr(afile->filp->f_dentry, newattrs);
+#elif defined(INODE_SETATTR_NOT_VOID)
+#if defined(AFS_LINUX26_ENV)
+    if (inode->i_op && inode->i_op->setattr)
+	code = inode->i_op->setattr(afile->filp->f_dentry, newattrs);
+    else
+#endif
+	code = inode_setattr(inode, newattrs);
+#else
+    inode_setattr(inode, newattrs);
+#endif
+    return code;
+}
diff --git a/src/afs/LINUX/osi_file.c b/src/afs/LINUX/osi_file.c
index 1f9e8cf..1fc583b 100644
--- a/src/afs/LINUX/osi_file.c
+++ b/src/afs/LINUX/osi_file.c
@@ -21,6 +21,7 @@
 #if !defined(HAVE_IGET)
 #include "h/exportfs.h"
 #endif
+#include "osi_compat.h"
 
 int afs_osicred_initialized = 0;
 struct AFS_UCRED afs_osi_cred;
@@ -237,17 +238,7 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
     lock_kernel();
     code = inode_change_ok(inode, &newattrs);
     if (!code)
-#ifdef INODE_SETATTR_NOT_VOID
-#if defined(AFS_LINUX26_ENV)
-	if (inode->i_op && inode->i_op->setattr)
-	    code = inode->i_op->setattr(afile->filp->f_dentry, &newattrs);
-	else
-#endif
-	    code = inode_setattr(inode, &newattrs);
-#else
-        inode_setattr(inode, &newattrs);
-#endif
-    unlock_kernel();
+	code = afs_inode_setattr(afile, &newattrs);
     if (!code)
 	truncate_inode_pages(&inode->i_data, asize);
 #else
diff --git a/src/cf/linux-test4.m4 b/src/cf/linux-test4.m4
index 3e200b0..5603b21 100644
--- a/src/cf/linux-test4.m4
+++ b/src/cf/linux-test4.m4
@@ -1278,3 +1278,19 @@ _bdi.name = NULL;],
   if test "x$ac_cv_linux_struct_bdi_has_name" = "xyes"; then
     AC_DEFINE([STRUCT_BDI_HAS_NAME], 1, [define if struct backing_dev_info has a name member])
   fi])
+
+AC_DEFUN([LINUX_HAVE_INODE_SETATTR], [
+  AC_MSG_CHECKING([for linux inode_setattr()])
+  AC_CACHE_VAL([ac_cv_linux_inode_setattr], [
+    save_CPPFLAGS="$CPPFLAGS"
+    CPPFLAGS="$CPPFLAGS -Werror-implicit-function-declaration"
+    AC_TRY_KBUILD(
+[#include <linux/fs.h>],
+[inode_setattr(NULL);],
+      ac_cv_linux_inode_setattr=yes,
+      ac_cv_linux_inode_setattr=no)
+    CPPFLAGS="$save_CPPFLAGS"])
+  AC_MSG_RESULT($ac_cv_linux_inode_setattr)
+  if test "x$ac_cv_linux_inode_setattr" = "xyes"; then
+    AC_DEFINE([HAVE_LINUX_INODE_SETATTR], 1, [define if your kernel has inode_setattr()])
+  fi])
-- 
1.7.3.2

From e2e8881db7757ccac5ce3d5fc5603c40c5b47a43 Mon Sep 17 00:00:00 2001
From: Marc Dionne <marc.c.dionne@gmail.com>
Date: Wed, 11 Aug 2010 17:18:32 -0400
Subject: [PATCH 3/6] Linux: use %pI4 if NIPQUAD is not available

The definition of NIPQUAD has been removed from the kernel headers
in the mainline kernel.  Replace it by using the %pI4 format
specifier which takes the IP address as a single argument.

There should be no change in the output.

This fix is required for 2.6.36.

Reviewed-on: http://gerrit.openafs.org/2542
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

(cherry-picked from commit d4018b2673e6532543984838290ffb891b970fea)

Change-Id: I49a4f55f71857c5a95df174bf017e27b5bcd0a95
Reviewed-on: http://gerrit.openafs.org/2551
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
---
 src/afs/LINUX/osi_module.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/afs/LINUX/osi_module.c b/src/afs/LINUX/osi_module.c
index ed9be8a..de8da52 100644
--- a/src/afs/LINUX/osi_module.c
+++ b/src/afs/LINUX/osi_module.c
@@ -134,8 +134,12 @@ static int c_show(struct seq_file *m, void *p)
 		if (!tc->cellHosts[j]) break;
 
 		addr = tc->cellHosts[j]->addr->sa_ip;
+#if defined(NIPQUAD)
 		seq_printf(m, "%u.%u.%u.%u #%u.%u.%u.%u\n",
 			   NIPQUAD(addr), NIPQUAD(addr));
+#else
+		seq_printf(m, "%pI4 #%pI4\n", &addr, &addr);
+#endif
 	}
 
 	return 0;
-- 
1.7.3.2

From e05b5937201ec313d2c8fa863f4dacec87ab687d Mon Sep 17 00:00:00 2001
From: Marc Dionne <marc.c.dionne@gmail.com>
Date: Wed, 11 Aug 2010 18:55:29 -0400
Subject: [PATCH 4/6] Linux: switch to evict_inode

In 2.6.36, the delete_inode and clear_inode inode operations
are replaced by evict_inode.
Rename our current clear_inode to evict_inode, and add a few
things that were previously handled by the generic delete_inode.

This is required for 2.6.36.

Reviewed-on: http://gerrit.openafs.org/2544
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

(cherry-picked from commit fb01fbd7cd2d396df8a4605eaad9febc52ef3b61)

Change-Id: I7ad09be8183d2503e89f7f64a1208b1dbb5fef9e
Reviewed-on: http://gerrit.openafs.org/2552
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
---
 acinclude.m4               |    4 ++++
 src/afs/LINUX/osi_vfsops.c |   24 ++++++++++++++++++++++++
 src/cf/linux-test4.m4      |   12 ++++++++++++
 3 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index bbbe938..f94205a 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -757,6 +757,7 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
 		 LINUX_DEFINES_FOR_EACH_PROCESS
 		 LINUX_DEFINES_PREV_TASK
 		 LINUX_FS_STRUCT_SUPER_HAS_ALLOC_INODE
+		 LINUX_FS_STRUCT_SUPER_HAS_EVICT_INODE
 		 LINUX_FS_STRUCT_SUPER_BLOCK_HAS_S_BDI
 		 LINUX_STRUCT_BDI_HAS_NAME
 	         LINUX_FS_STRUCT_ADDRESS_SPACE_HAS_PAGE_LOCK
@@ -922,6 +923,9 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
 		 if test "x$ac_cv_linux_fs_struct_super_has_alloc_inode" = "xyes" ; then
 		  AC_DEFINE(STRUCT_SUPER_HAS_ALLOC_INODE, 1, [define if your struct super_operations has alloc_inode])
 		 fi
+		 if test "x$ac_cv_linux_fs_struct_super_has_evict_inode" = "xyes" ; then
+		  AC_DEFINE(STRUCT_SUPER_OPERATIONS_HAS_EVICT_INODE, 1, [define if your struct super_operations has evict_inode])
+		 fi
 		 if test "x$ac_cv_linux_fs_struct_address_space_has_page_lock" = "xyes"; then 
 		  AC_DEFINE(STRUCT_ADDRESS_SPACE_HAS_PAGE_LOCK, 1, [define if your struct address_space has page_lock])
 		 fi
diff --git a/src/afs/LINUX/osi_vfsops.c b/src/afs/LINUX/osi_vfsops.c
index 49bfbee..e46c3eb 100644
--- a/src/afs/LINUX/osi_vfsops.c
+++ b/src/afs/LINUX/osi_vfsops.c
@@ -342,6 +342,25 @@ afs_destroy_inodecache(void)
 }
 #endif
 
+#if defined(STRUCT_SUPER_OPERATIONS_HAS_EVICT_INODE)
+static void
+afs_evict_inode(struct inode *ip)
+{
+    struct vcache *vcp = VTOAFS(ip);
+
+    if (vcp->vlruq.prev || vcp->vlruq.next)
+	osi_Panic("inode freed while on LRU");
+    if (vcp->hnext)
+	osi_Panic("inode freed while still hashed");
+
+    truncate_inode_pages(&ip->i_data, 0);
+    end_writeback(ip);
+
+#if !defined(STRUCT_SUPER_HAS_ALLOC_INODE)
+    afs_osi_Free(ip->u.generic_ip, sizeof(struct vcache));
+#endif
+}
+#else
 static void
 afs_clear_inode(struct inode *ip)
 {
@@ -356,6 +375,7 @@ afs_clear_inode(struct inode *ip)
     afs_osi_Free(ip->u.generic_ip, sizeof(struct vcache));
 #endif
 }
+#endif
 
 /* afs_put_super
  * Called from unmount to release super_block. */
@@ -456,7 +476,11 @@ struct super_operations afs_sops = {
   .alloc_inode =	afs_alloc_inode,
   .destroy_inode =	afs_destroy_inode,
 #endif
+#if defined(STRUCT_SUPER_OPERATIONS_HAS_EVICT_INODE)
+  .evict_inode =	afs_evict_inode,
+#else
   .clear_inode =	afs_clear_inode,
+#endif
   .put_super =		afs_put_super,
   .statfs =		afs_statfs,
 #if !defined(AFS_LINUX24_ENV)
diff --git a/src/cf/linux-test4.m4 b/src/cf/linux-test4.m4
index 5603b21..66b21e3 100644
--- a/src/cf/linux-test4.m4
+++ b/src/cf/linux-test4.m4
@@ -467,6 +467,18 @@ printk("%p\n", _super.alloc_inode);],
   AC_MSG_RESULT($ac_cv_linux_fs_struct_super_has_alloc_inode)])
 
 
+AC_DEFUN([LINUX_FS_STRUCT_SUPER_HAS_EVICT_INODE], [
+  AC_MSG_CHECKING([for evict_inode in struct super_operations])
+  AC_CACHE_VAL([ac_cv_linux_fs_struct_super_has_evict_inode], [
+    AC_TRY_KBUILD(
+[#include <linux/fs.h>],
+[struct super_operations _super;
+printk("%p\n", _super.evict_inode);],
+      ac_cv_linux_fs_struct_super_has_evict_inode=yes,
+      ac_cv_linux_fs_struct_super_has_evict_inode=no)])
+  AC_MSG_RESULT($ac_cv_linux_fs_struct_super_has_evict_inode)])
+
+
 AC_DEFUN([LINUX_KERNEL_POSIX_LOCK_FILE_WAIT_ARG], [
   AC_MSG_CHECKING([for 3rd argument in posix_lock_file found in new kernels])
   AC_CACHE_VAL([ac_cv_linux_kernel_posix_lock_file_wait_arg], [
-- 
1.7.3.2

From b8b708fc416aa281fe1d1ce1d498cc381c81679c Mon Sep 17 00:00:00 2001
From: Marc Dionne <marc.c.dionne@gmail.com>
Date: Wed, 11 Aug 2010 19:28:53 -0400
Subject: [PATCH 5/6] Linux: Rework statfs super block operations configure test

The configure test to detect if the statfs super block operation
needs a dentry argument is based on vfs_statfs, and assumes that
its signature matches the one of the operation.  In 2.6.36 this is
no longer true and the test fails.

Rework the test to actually test the operation we're interested in.

This change is required for 2.6.36.

Reviewed-on: http://gerrit.openafs.org/2545
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

(cherry-picked from commit 08552ad8a94f7cc5908aabe8385711e09a6418e4)

Change-Id: Ia690ea9de03790a8f576f99249fad8a7a7ba8bad
Reviewed-on: http://gerrit.openafs.org/2553
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
---
 src/cf/linux-test4.m4 |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/cf/linux-test4.m4 b/src/cf/linux-test4.m4
index 66b21e3..5eabaa9 100644
--- a/src/cf/linux-test4.m4
+++ b/src/cf/linux-test4.m4
@@ -734,9 +734,10 @@ AC_DEFUN([LINUX_STATFS_TAKES_DENTRY], [
     AC_TRY_KBUILD(
 [#include <linux/fs.h>
 #include <linux/statfs.h>],
-[
-extern int vfs_statfs(struct dentry *, struct kstatfs *);
-],
+[struct super_block _sb;
+struct dentry _dentry;
+struct kstatfs _kstatfs;
+(void)_sb.s_op->statfs(&_dentry, &_kstatfs);],
       ac_cv_linux_statfs_takes_dentry=yes,
       ac_cv_linux_statfs_takes_dentry=no)])
   AC_MSG_RESULT($ac_cv_linux_statfs_takes_dentry)])
-- 
1.7.3.2

