Protect truncate_inode_pages when called from osi_VM_FlushPages
authorRainer Toebbicke <rtb@pclella.cern.ch>
Wed, 23 Jun 2010 13:10:46 +0000 (15:10 +0200)
committerDerrick Brashear <shadow@dementia.org>
Fri, 2 Jul 2010 12:14:00 +0000 (05:14 -0700)
truncate_inode_pages requires the mapping to be protected using
i_mutex / i_sem, which is not held whereever osi_FlushPages is called.

Change-Id: I2ca59cf75633368efb7f6a17fd01c7c517a8f609
Reviewed-on: http://gerrit.openafs.org/2244
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/afs/LINUX/osi_compat.h
src/afs/LINUX/osi_vm.c

index 2d7382f..342cdb8 100644 (file)
@@ -342,3 +342,21 @@ afs_init_sb_export_ops(struct super_block *sb) {
        sb->s_export_op->find_exported_dentry = find_exported_dentry;
 #endif
 }
+
+static inline void
+afs_linux_lock_inode(struct inode *ip) {
+#ifdef STRUCT_INODE_HAS_I_MUTEX
+    mutex_lock(&ip->i_mutex);
+#else
+    down(&ip->i_sem);
+#endif
+}
+
+static inline void
+afs_linux_unlock_inode(struct inode *ip) {
+#ifdef STRUCT_INODE_HAS_I_MUTEX
+    mutex_unlock(&ip->i_mutex);
+#else
+    up(&ip->i_sem);
+#endif
+}
index 99d72c3..2cd34f9 100644 (file)
@@ -15,6 +15,8 @@
 #include "afsincludes.h"       /* Afs-based standard headers */
 #include "afs/afs_stats.h"     /* statistics */
 
+#include "osi_compat.h"
+
 /* Linux VM operations
  *
  * The general model for Linux is to treat vm as a cache that's:
@@ -116,7 +118,9 @@ osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
 {
     struct inode *ip = AFSTOV(avc);
     
+    afs_linux_lock_inode(ip);
     truncate_inode_pages(&ip->i_data, 0);
+    afs_linux_unlock_inode(ip);
 }
 
 /* Purge pages beyond end-of-file, when truncating a file.