From: Rainer Toebbicke Date: Wed, 23 Jun 2010 13:10:46 +0000 (+0200) Subject: Protect truncate_inode_pages when called from osi_VM_FlushPages X-Git-Tag: openafs-devel-1_5_75~23 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=b0ed5a7facb1951f2f4ef8ed3da29a6a80cb7d49;p=packages%2Fo%2Fopenafs.git Protect truncate_inode_pages when called from osi_VM_FlushPages 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 Tested-by: Derrick Brashear --- diff --git a/src/afs/LINUX/osi_compat.h b/src/afs/LINUX/osi_compat.h index 2d7382f1d..342cdb830 100644 --- a/src/afs/LINUX/osi_compat.h +++ b/src/afs/LINUX/osi_compat.h @@ -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 +} diff --git a/src/afs/LINUX/osi_vm.c b/src/afs/LINUX/osi_vm.c index 99d72c372..2cd34f963 100644 --- a/src/afs/LINUX/osi_vm.c +++ b/src/afs/LINUX/osi_vm.c @@ -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.