diff mbox

[RFC] nfs: ensure cached data is correct before using delegation

Message ID 1402683488-23725-2-git-send-email-smayhew@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Scott Mayhew June 13, 2014, 6:18 p.m. UTC
nfs_write_pageuptodate()  bypasses the cache_validity flags whenever we
have a delegation... but in order to do that we need to be sure our
cached data is correct to begin with.
---
 fs/nfs/delegation.c | 1 +
 fs/nfs/inode.c      | 1 +
 fs/nfs/nfs4proc.c   | 5 +++--
 3 files changed, 5 insertions(+), 2 deletions(-)

Comments

Trond Myklebust June 13, 2014, 9:19 p.m. UTC | #1
On Fri, Jun 13, 2014 at 2:18 PM, Scott Mayhew <smayhew@redhat.com> wrote:
> nfs_write_pageuptodate()  bypasses the cache_validity flags whenever we
> have a delegation... but in order to do that we need to be sure our
> cached data is correct to begin with.
> ---
>  fs/nfs/delegation.c | 1 +
>  fs/nfs/inode.c      | 1 +
>  fs/nfs/nfs4proc.c   | 5 +++--
>  3 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
> index 5d8ccec..12f3eca 100644
> --- a/fs/nfs/delegation.c
> +++ b/fs/nfs/delegation.c
> @@ -167,6 +167,7 @@ void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
>                         spin_unlock(&delegation->lock);
>                         rcu_read_unlock();
>                         nfs_inode_set_delegation(inode, cred, res);
> +                       nfs_revalidate_mapping(inode, inode->i_mapping);

If you are reclaiming a delegation after a server reboot, then nobody
is supposed to have changed the file.

>                 }
>         } else {
>                 rcu_read_unlock();
> diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
> index c496f8a..95a9d21 100644
> --- a/fs/nfs/inode.c
> +++ b/fs/nfs/inode.c
> @@ -1090,6 +1090,7 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
>  out:
>         return ret;
>  }
> +EXPORT_SYMBOL_GPL(nfs_revalidate_mapping);
>
>  static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
>  {
> diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> index 285ad53..a538aac 100644
> --- a/fs/nfs/nfs4proc.c
> +++ b/fs/nfs/nfs4proc.c
> @@ -1361,11 +1361,12 @@ nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state)
>                                    "returning a delegation for "
>                                    "OPEN(CLAIM_DELEGATE_CUR)\n",
>                                    clp->cl_hostname);
> -       } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
> +       } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) {
>                 nfs_inode_set_delegation(state->inode,
>                                          data->owner->so_cred,
>                                          &data->o_res);
> -       else
> +               nfs_revalidate_mapping(state->inode, state->inode->i_mapping);
> +       } else
>                 nfs_inode_reclaim_delegation(state->inode,
>                                              data->owner->so_cred,
>                                              &data->o_res);

I'd really prefer to fix this in the part of the code that is actually broken.

I agree that we should ignore the NFS_INO_REVAL_PAGECACHE flag if we
have a delegation and the NFS_INO_REVAL_FORCED is unset. However is it
right to ignore NFS_INO_INVALID_DATA?

Cheers
  Trond
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 5d8ccec..12f3eca 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -167,6 +167,7 @@  void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
 			spin_unlock(&delegation->lock);
 			rcu_read_unlock();
 			nfs_inode_set_delegation(inode, cred, res);
+			nfs_revalidate_mapping(inode, inode->i_mapping);
 		}
 	} else {
 		rcu_read_unlock();
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index c496f8a..95a9d21 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -1090,6 +1090,7 @@  int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
 out:
 	return ret;
 }
+EXPORT_SYMBOL_GPL(nfs_revalidate_mapping);
 
 static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 {
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 285ad53..a538aac 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1361,11 +1361,12 @@  nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state)
 				   "returning a delegation for "
 				   "OPEN(CLAIM_DELEGATE_CUR)\n",
 				   clp->cl_hostname);
-	} else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
+	} else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) {
 		nfs_inode_set_delegation(state->inode,
 					 data->owner->so_cred,
 					 &data->o_res);
-	else
+		nfs_revalidate_mapping(state->inode, state->inode->i_mapping);
+	} else
 		nfs_inode_reclaim_delegation(state->inode,
 					     data->owner->so_cred,
 					     &data->o_res);