Return-Path: linux-nfs-owner@vger.kernel.org Received: from mail-ie0-f182.google.com ([209.85.223.182]:54351 "EHLO mail-ie0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753822AbaDRSpW (ORCPT ); Fri, 18 Apr 2014 14:45:22 -0400 Received: by mail-ie0-f182.google.com with SMTP id y20so1881068ier.41 for ; Fri, 18 Apr 2014 11:45:22 -0700 (PDT) From: Trond Myklebust To: Bruce Fields Cc: linux-nfs@vger.kernel.org Subject: [PATCH 11/70] NFSd: Ensure delegation setup is safe w.r.t. break_lease() Date: Fri, 18 Apr 2014 14:44:05 -0400 Message-Id: <1397846704-14567-12-git-send-email-trond.myklebust@primarydata.com> In-Reply-To: <1397846704-14567-11-git-send-email-trond.myklebust@primarydata.com> References: <1397846704-14567-1-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-2-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-3-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-4-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-5-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-6-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-7-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-8-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-9-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-10-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-11-git-send-email-trond.myklebust@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org List-ID: Ensure that we add/remove the dl_perfile under the inode->i_lock Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4state.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 85fcbc9ebd40..3656980b5d19 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -441,7 +441,9 @@ static void hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp) { dp->dl_stid.sc_type = NFS4_DELEG_STID; + spin_lock(&fp->fi_inode->i_lock); list_add(&dp->dl_perfile, &fp->fi_delegations); + spin_unlock(&fp->fi_inode->i_lock); list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations); } @@ -449,13 +451,19 @@ hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp) static void unhash_delegation(struct nfs4_delegation *dp) { + struct nfs4_file *fp = dp->dl_file; + spin_lock(&state_lock); list_del_init(&dp->dl_perclnt); - list_del_init(&dp->dl_perfile); list_del_init(&dp->dl_recall_lru); + if (!list_empty(&dp->dl_perfile)) { + spin_lock(&fp->fi_inode->i_lock); + list_del_init(&dp->dl_perfile); + spin_unlock(&fp->fi_inode->i_lock); + } spin_unlock(&state_lock); - nfs4_put_deleg_lease(dp->dl_file); - put_nfs4_file(dp->dl_file); + nfs4_put_deleg_lease(fp); + put_nfs4_file(fp); dp->dl_file = NULL; } -- 1.9.0