From: Marc Dionne <marc.c.dionne@gmail.com>
Date: Thu, 10 Jan 2013 02:22:27 +0000 (-0500)
Subject: Linux 3.8: vmtruncate removal
X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=731c69439ab24655574a6a71e188685bae8acb1a;hp=8b840d4265a2361672ce0b40d5c5dc8c50485fea

Linux 3.8: vmtruncate removal

vmtruncate had been deprecated for a while and has now been
removed.  Do things the new way based on truncate_setsize.

Reviewed-on: http://gerrit.openafs.org/8906
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
(cherry picked from commit d0479bbaf43900d6733c3f7517926ee9813c9610)

Change-Id: Iafc64e19544dec9fcaefad5ad274eac4133f4083
---

diff --git a/acinclude.m4 b/acinclude.m4
index 0a05caa..4223bb1 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -824,6 +824,7 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
 		 AC_CHECK_LINUX_STRUCT([file_operations], [sendfile], [fs.h])
 		 AC_CHECK_LINUX_STRUCT([file_system_type], [mount], [fs.h])
 		 AC_CHECK_LINUX_STRUCT([filename], [name], [fs.h])
+		 AC_CHECK_LINUX_STRUCT([inode_operations], [truncate], [fs.h])
 		 AC_CHECK_LINUX_STRUCT([key_type], [preparse], [key-type.h])
 		 AC_CHECK_LINUX_STRUCT([nameidata], [path], [namei.h])
 		 AC_CHECK_LINUX_STRUCT([proc_dir_entry], [owner], [proc_fs.h])
diff --git a/src/afs/LINUX/osi_compat.h b/src/afs/LINUX/osi_compat.h
index a777542..e8bf003 100644
--- a/src/afs/LINUX/osi_compat.h
+++ b/src/afs/LINUX/osi_compat.h
@@ -537,4 +537,18 @@ afs_set_session_keyring(struct key *keyring)
     return old;
 }
 
+static inline int
+afs_truncate(struct inode *inode, int len)
+{
+    int code;
+#if defined(STRUCT_INODE_OPERATIONS_HAS_TRUNCATE)
+    code = vmtruncate(inode, len);
+#else
+    code = inode_newsize_ok(inode, len);
+    if (!code)
+        truncate_setsize(inode, len);
+#endif
+    return code;
+}
+
 #endif /* AFS_LINUX_OSI_COMPAT_H */
diff --git a/src/afs/LINUX/osi_vm.c b/src/afs/LINUX/osi_vm.c
index 2cd34f9..8bc792e 100644
--- a/src/afs/LINUX/osi_vm.c
+++ b/src/afs/LINUX/osi_vm.c
@@ -51,8 +51,7 @@ osi_VM_FlushVCache(struct vcache *avc, int *slept)
     if (avc->opens != 0)
 	return EBUSY;
 
-    return vmtruncate(ip, 0);
-    return 0;
+    return afs_truncate(ip, 0);
 }
 
 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
@@ -132,5 +131,5 @@ osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
 void
 osi_VM_Truncate(struct vcache *avc, int alen, afs_ucred_t *acred)
 {
-    vmtruncate(AFSTOV(avc), alen);
+    afs_truncate(AFSTOV(avc), alen);
 }
