orangefs: Implement inode_operations->permission().

Thus d_revalidate is not obliged to check on as much, which will
eventually lead the way to hammering the filesystem servers much less.

Signed-off-by: Martin Brandenburg <martin@omnibond.com>
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
diff --git a/fs/orangefs/dcache.c b/fs/orangefs/dcache.c
index e8fb79d..a6911db 100644
--- a/fs/orangefs/dcache.c
+++ b/fs/orangefs/dcache.c
@@ -119,8 +119,9 @@
 		goto out;
 
 	/* Now we must perform a getattr to validate the inode contents. */
+
 	ret = orangefs_inode_getattr(dentry->d_inode,
-	    ORANGEFS_ATTR_SYS_ALL_NOHINT, 1);
+	    ORANGEFS_ATTR_SYS_TYPE|ORANGEFS_ATTR_SYS_LNK_TARGET, 1);
 	if (ret < 0) {
 		gossip_debug(GOSSIP_DCACHE_DEBUG, "%s:%s:%d getattr failure.\n",
 		    __FILE__, __func__, __LINE__);
diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
index 040cd95..e9688f0 100644
--- a/fs/orangefs/inode.c
+++ b/fs/orangefs/inode.c
@@ -291,6 +291,24 @@
 	return ret;
 }
 
+int orangefs_permission(struct inode *inode, int mask)
+{
+	int ret;
+
+	if (mask & MAY_NOT_BLOCK)
+		return -ECHILD;
+
+	gossip_debug(GOSSIP_INODE_DEBUG, "%s: refreshing\n", __func__);
+
+	/* Make sure the permission (and other common attrs) are up to date. */
+	ret = orangefs_inode_getattr(inode,
+	    ORANGEFS_ATTR_SYS_ALL_NOHINT_NOSIZE, 0);
+	if (ret < 0)
+		return ret;
+
+	return generic_permission(inode, mask);
+}
+
 /* ORANGEDS2 implementation of VFS inode operations for files */
 struct inode_operations orangefs_file_inode_operations = {
 	.get_acl = orangefs_get_acl,
@@ -301,6 +319,7 @@
 	.getxattr = generic_getxattr,
 	.listxattr = orangefs_listxattr,
 	.removexattr = generic_removexattr,
+	.permission = orangefs_permission,
 };
 
 static int orangefs_init_iops(struct inode *inode)
diff --git a/fs/orangefs/namei.c b/fs/orangefs/namei.c
index 50bc45d..8fc55c6 100644
--- a/fs/orangefs/namei.c
+++ b/fs/orangefs/namei.c
@@ -443,4 +443,5 @@
 	.getxattr = generic_getxattr,
 	.removexattr = generic_removexattr,
 	.listxattr = orangefs_listxattr,
+	.permission = orangefs_permission,
 };
diff --git a/fs/orangefs/orangefs-kernel.h b/fs/orangefs/orangefs-kernel.h
index d4db962..a8cde90 100644
--- a/fs/orangefs/orangefs-kernel.h
+++ b/fs/orangefs/orangefs-kernel.h
@@ -493,6 +493,8 @@
 		  struct dentry *dentry,
 		  struct kstat *kstat);
 
+int orangefs_permission(struct inode *inode, int mask);
+
 /*
  * defined in xattr.c
  */
diff --git a/fs/orangefs/protocol.h b/fs/orangefs/protocol.h
index 56dd65a..6ac0c60 100644
--- a/fs/orangefs/protocol.h
+++ b/fs/orangefs/protocol.h
@@ -205,6 +205,15 @@
 	 ORANGEFS_ATTR_SYS_MIRROR_COPIES_COUNT	|	\
 	 ORANGEFS_ATTR_SYS_DIRENT_COUNT		|	\
 	 ORANGEFS_ATTR_SYS_BLKSIZE)
+
+#define ORANGEFS_ATTR_SYS_ALL_NOHINT_NOSIZE		\
+	(ORANGEFS_ATTR_SYS_COMMON_ALL		|	\
+	 ORANGEFS_ATTR_SYS_LNK_TARGET		|	\
+	 ORANGEFS_ATTR_SYS_DFILE_COUNT		|	\
+	 ORANGEFS_ATTR_SYS_MIRROR_COPIES_COUNT	|	\
+	 ORANGEFS_ATTR_SYS_DIRENT_COUNT		|	\
+	 ORANGEFS_ATTR_SYS_BLKSIZE)
+
 #define ORANGEFS_XATTR_REPLACE 0x2
 #define ORANGEFS_XATTR_CREATE  0x1
 #define ORANGEFS_MAX_SERVER_ADDR_LEN 256
diff --git a/fs/orangefs/symlink.c b/fs/orangefs/symlink.c
index 1b3ae63..2b8541a 100644
--- a/fs/orangefs/symlink.c
+++ b/fs/orangefs/symlink.c
@@ -28,4 +28,5 @@
 	.getattr = orangefs_getattr,
 	.listxattr = orangefs_listxattr,
 	.setxattr = generic_setxattr,
+	.permission = orangefs_permission,
 };