diff options
author | Trond Myklebust <trondmy@gmail.com> | 2019-04-07 13:59:10 -0400 |
---|---|---|
committer | Anna Schumaker <Anna.Schumaker@Netapp.com> | 2019-04-25 14:18:15 -0400 |
commit | 154945112dac10b7109d816275f3e4896b0b064e (patch) | |
tree | 91733947622b31660a7de05a2c3c92f9bc6fe075 /fs/nfs | |
parent | 0688e64bc60038971253485d92bc3d6c816f915d (diff) |
NFS: Ensure that all nfs lock contexts have a valid open context
Force the lock context to keep a reference to the parent open
context so that we can guarantee the validity of the latter.
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r-- | fs/nfs/inode.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 414a90d48493..efc45f22c581 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -885,10 +885,14 @@ struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx) | |||
885 | spin_lock(&inode->i_lock); | 885 | spin_lock(&inode->i_lock); |
886 | res = __nfs_find_lock_context(ctx); | 886 | res = __nfs_find_lock_context(ctx); |
887 | if (res == NULL) { | 887 | if (res == NULL) { |
888 | list_add_tail_rcu(&new->list, &ctx->lock_context.list); | 888 | new->open_context = get_nfs_open_context(ctx); |
889 | new->open_context = ctx; | 889 | if (new->open_context) { |
890 | res = new; | 890 | list_add_tail_rcu(&new->list, |
891 | new = NULL; | 891 | &ctx->lock_context.list); |
892 | res = new; | ||
893 | new = NULL; | ||
894 | } else | ||
895 | res = ERR_PTR(-EBADF); | ||
892 | } | 896 | } |
893 | spin_unlock(&inode->i_lock); | 897 | spin_unlock(&inode->i_lock); |
894 | kfree(new); | 898 | kfree(new); |
@@ -906,6 +910,7 @@ void nfs_put_lock_context(struct nfs_lock_context *l_ctx) | |||
906 | return; | 910 | return; |
907 | list_del_rcu(&l_ctx->list); | 911 | list_del_rcu(&l_ctx->list); |
908 | spin_unlock(&inode->i_lock); | 912 | spin_unlock(&inode->i_lock); |
913 | put_nfs_open_context(ctx); | ||
909 | kfree_rcu(l_ctx, rcu_head); | 914 | kfree_rcu(l_ctx, rcu_head); |
910 | } | 915 | } |
911 | EXPORT_SYMBOL_GPL(nfs_put_lock_context); | 916 | EXPORT_SYMBOL_GPL(nfs_put_lock_context); |