nfs: use change attribute for NFS re-exports
authorJ. Bruce Fields <bfields@redhat.com>
Fri, 29 Jan 2021 19:26:29 +0000 (14:26 -0500)
committerChuck Lever <chuck.lever@oracle.com>
Sat, 30 Jan 2021 16:47:12 +0000 (11:47 -0500)
When exporting NFS, we may as well use the real change attribute
returned by the original server instead of faking up a change attribute
from the ctime.

Note we can't do that by setting I_VERSION--that would also turn on the
logic in iversion.h which treats the lower bit specially, and that
doesn't make sense for NFS.

So instead we define a new export operation for filesystems like NFS
that want to manage the change attribute themselves.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfs/export.c
fs/nfsd/nfsfh.h
include/linux/exportfs.h

index 7412bb164fa777371e1f1e1a1e3c154cdb69a4fa..f2b34cfe286c2b6d348ea81d3091e2cd06011ead 100644 (file)
@@ -167,10 +167,28 @@ out:
        return parent;
 }
 
+static u64 nfs_fetch_iversion(struct inode *inode)
+{
+       struct nfs_server *server = NFS_SERVER(inode);
+
+       /* Is this the right call?: */
+       nfs_revalidate_inode(server, inode);
+       /*
+        * Also, note we're ignoring any returned error.  That seems to be
+        * the practice for cache consistency information elsewhere in
+        * the server, but I'm not sure why.
+        */
+       if (server->nfs_client->rpc_ops->version >= 4)
+               return inode_peek_iversion_raw(inode);
+       else
+               return time_to_chattr(&inode->i_ctime);
+}
+
 const struct export_operations nfs_export_ops = {
        .encode_fh = nfs_encode_fh,
        .fh_to_dentry = nfs_fh_to_dentry,
        .get_parent = nfs_get_parent,
+       .fetch_iversion = nfs_fetch_iversion,
        .flags = EXPORT_OP_NOWCC|EXPORT_OP_NOSUBTREECHK|
                EXPORT_OP_CLOSE_BEFORE_UNLINK|EXPORT_OP_REMOTE_FS|
                EXPORT_OP_NOATOMIC_ATTR,
index cb20c2cd346959df6744e3a84ad8e77aae7b973c..f58933519f3806d159939d0295f3f9601aa38625 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/sunrpc/svc.h>
 #include <uapi/linux/nfsd/nfsfh.h>
 #include <linux/iversion.h>
+#include <linux/exportfs.h>
 
 static inline __u32 ino_t_to_u32(ino_t ino)
 {
@@ -264,7 +265,9 @@ fh_clear_wcc(struct svc_fh *fhp)
 static inline u64 nfsd4_change_attribute(struct kstat *stat,
                                         struct inode *inode)
 {
-       if (IS_I_VERSION(inode)) {
+       if (inode->i_sb->s_export_op->fetch_iversion)
+               return inode->i_sb->s_export_op->fetch_iversion(inode);
+       else if (IS_I_VERSION(inode)) {
                u64 chattr;
 
                chattr =  stat->ctime.tv_sec;
index 9f4d4bcbf251d27dde00d0ac1414564f9d303d24..fe848901fcc3acb04a732b82df95c86fbad93ddc 100644 (file)
@@ -213,6 +213,7 @@ struct export_operations {
                          bool write, u32 *device_generation);
        int (*commit_blocks)(struct inode *inode, struct iomap *iomaps,
                             int nr_iomaps, struct iattr *iattr);
+       u64 (*fetch_iversion)(struct inode *);
 #define        EXPORT_OP_NOWCC                 (0x1) /* don't collect v3 wcc data */
 #define        EXPORT_OP_NOSUBTREECHK          (0x2) /* no subtree checking */
 #define        EXPORT_OP_CLOSE_BEFORE_UNLINK   (0x4) /* close files before unlink */