From patchwork Thu Jun 26 19:12:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4430401 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4F108BEECB for ; Thu, 26 Jun 2014 19:14:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 729D02028D for ; Thu, 26 Jun 2014 19:14:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 942632024D for ; Thu, 26 Jun 2014 19:14:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751745AbaFZTO0 (ORCPT ); Thu, 26 Jun 2014 15:14:26 -0400 Received: from mail-qc0-f174.google.com ([209.85.216.174]:37290 "EHLO mail-qc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751749AbaFZTOZ (ORCPT ); Thu, 26 Jun 2014 15:14:25 -0400 Received: by mail-qc0-f174.google.com with SMTP id x13so3548281qcv.33 for ; Thu, 26 Jun 2014 12:14:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qVaR+39uHMH9bWjkoQnu9d7+hA9+rQNOP2zthWGnrig=; b=NCyGSn7z/FcV2zHHVL8aKhHvmbt3Ffw6mehqlChi9bE4iYoKTvQEePE24KlTyNHu+E 2Zso2v62KK/vMPIzEFEzbEfd9OKS9M6/HKiMl3NX1XUC6fhXrIOrL/EL/GS2q/+OXAXG RpBIfTKiApYuD7aLYYdg8n486hAOpAO2yMgsHIUBIFZdCj3GbmXVCVr34A/Mya+3FyOY GeihsVEtOGXjTUEKa9Av9NThjFyZMuOSlyWNG/lsqyhy4ghxeUJenScIKckr4aSYIptl kTLLI8n3Ft8VFtL9/IN433CmiPf8UZk8KI387IhIV7Mn1+SpF3ixpZ5XSytJbn6K0ZKi olNQ== X-Gm-Message-State: ALoCoQmSzrophP2oh4dUJGICEpi96fUnbsocgVXHsQhRWZSNLSZQLJ/jGnpvNS8qbpuZhiwkRWTj X-Received: by 10.224.165.70 with SMTP id h6mr25701532qay.78.1403810064865; Thu, 26 Jun 2014 12:14:24 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id 88sm4763039qgh.5.2014.06.26.12.14.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jun 2014 12:14:24 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, Trond Myklebust Subject: [PATCH v2 028/117] nfsd: Add fine grained protection for the nfs4_file->fi_stateids list Date: Thu, 26 Jun 2014 15:12:08 -0400 Message-Id: <1403810017-16062-29-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1403810017-16062-1-git-send-email-jlayton@primarydata.com> References: <1403810017-16062-1-git-send-email-jlayton@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Trond Myklebust Access to this list is currently serialized by the client_mutex. Add finer grained locking around this list in preparation for its removal. Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4state.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index a2b4f2cbab42..8793d9ec8311 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -719,7 +719,11 @@ release_all_access(struct nfs4_ol_stateid *stp) static void unhash_generic_stateid(struct nfs4_ol_stateid *stp) { + struct nfs4_file *fp = stp->st_file; + + spin_lock(&fp->fi_lock); list_del(&stp->st_perfile); + spin_unlock(&fp->fi_lock); list_del(&stp->st_perstateowner); } @@ -2812,7 +2816,6 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp, stp->st_stid.sc_type = NFS4_OPEN_STID; INIT_LIST_HEAD(&stp->st_locks); list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids); - list_add(&stp->st_perfile, &fp->fi_stateids); stp->st_stateowner = &oo->oo_owner; get_nfs4_file(fp); stp->st_file = fp; @@ -2821,6 +2824,9 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp, set_access(open->op_share_access, stp); set_deny(open->op_share_deny, stp); stp->st_openstp = NULL; + spin_lock(&fp->fi_lock); + list_add(&stp->st_perfile, &fp->fi_stateids); + spin_unlock(&fp->fi_lock); } static void @@ -2928,6 +2934,7 @@ nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type) return nfs_ok; ret = nfserr_locked; /* Search for conflicting share reservations */ + spin_lock(&fp->fi_lock); list_for_each_entry(stp, &fp->fi_stateids, st_perfile) { if (test_deny(deny_type, stp) || test_deny(NFS4_SHARE_DENY_BOTH, stp)) @@ -2935,6 +2942,7 @@ nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type) } ret = nfs_ok; out: + spin_unlock(&fp->fi_lock); put_nfs4_file(fp); return ret; } @@ -3134,6 +3142,7 @@ nfs4_check_open(struct nfs4_file *fp, struct nfsd4_open *open, struct nfs4_ol_st struct nfs4_ol_stateid *local; struct nfs4_openowner *oo = open->op_openowner; + spin_lock(&fp->fi_lock); list_for_each_entry(local, &fp->fi_stateids, st_perfile) { /* ignore lock owners */ if (local->st_stateowner->so_is_open_owner == 0) @@ -3142,9 +3151,12 @@ nfs4_check_open(struct nfs4_file *fp, struct nfsd4_open *open, struct nfs4_ol_st if (local->st_stateowner == &oo->oo_owner) *stpp = local; /* check for conflicting share reservations */ - if (!test_share(local, open)) + if (!test_share(local, open)) { + spin_unlock(&fp->fi_lock); return nfserr_share_denied; + } } + spin_unlock(&fp->fi_lock); return nfs_ok; } @@ -4420,7 +4432,6 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, struct if (stp == NULL) return NULL; stp->st_stid.sc_type = NFS4_LOCK_STID; - list_add(&stp->st_perfile, &fp->fi_stateids); list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); stp->st_stateowner = &lo->lo_owner; get_nfs4_file(fp); @@ -4429,6 +4440,9 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, struct stp->st_deny_bmap = open_stp->st_deny_bmap; stp->st_openstp = open_stp; list_add(&stp->st_locks, &open_stp->st_locks); + spin_lock(&fp->fi_lock); + list_add(&stp->st_perfile, &fp->fi_stateids); + spin_unlock(&fp->fi_lock); return stp; }