From patchwork Thu Jun 26 19:12:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4430591 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0542F9F2C8 for ; Thu, 26 Jun 2014 19:14:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 242B0201BB for ; Thu, 26 Jun 2014 19:14:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 35D612024D for ; Thu, 26 Jun 2014 19:14:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751790AbaFZTOv (ORCPT ); Thu, 26 Jun 2014 15:14:51 -0400 Received: from mail-qc0-f169.google.com ([209.85.216.169]:52979 "EHLO mail-qc0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751511AbaFZTOu (ORCPT ); Thu, 26 Jun 2014 15:14:50 -0400 Received: by mail-qc0-f169.google.com with SMTP id c9so3645035qcz.0 for ; Thu, 26 Jun 2014 12:14:50 -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=Ae8eVP2LgKd29cioBoPTodq861xiRxpBCjA77Gw+Jck=; b=K8H3BPn7q8eR1GGMYdyS4697W5IcvxkH0rFeMwSzdqjN42mTomvKFON/hrmjvyDdIW +KZBJi4JBZHZFdtXwaZJdfOMyhVHAoCFQ9EVTSemV2j4NuF4bZUYrNew4nvSyUkmtNYU OkgMKVK6jPA6xPn0Ntj/NSvxtHE27wB6P/iQfzMYVSlKlS7ReLCTWE7+E9HNNso5XlVO GMEr0oSvFIy39KYYd22n1t44M5Up2drQZ9c5o6Vc9MUMesLGMhtIaAfCpOddeT7UV6WA ScsHSjmZQ/ClzsGVtqHAL4gJf4uzRb0PQ2Z8qMot2MenmuMe+9PmcXH56a9DSzycMh0F o6CQ== X-Gm-Message-State: ALoCoQn2srgRA1WjtcDzTPV+yu/asx8X5uj4SgFtayZ0LpAJXsxsMVe1ZgLSy8bR2/exqz9WWApg X-Received: by 10.140.23.134 with SMTP id 6mr24702279qgp.84.1403810090068; Thu, 26 Jun 2014 12:14:50 -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.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jun 2014 12:14:49 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 047/117] nfsd: Add locking to protect the state owner lists Date: Thu, 26 Jun 2014 15:12:27 -0400 Message-Id: <1403810017-16062-48-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 Change to using the clp->cl_lock for this. For now, there's a lot of cl_lock thrashing, but in later patches we'll eliminate that and close the potential races that can occur when releasing the cl_lock while walking the lists. For now, the client_mutex prevents those races. Signed-off-by: Trond Myklebust Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 93876dc366cc..a3413cb4ac46 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -885,6 +885,8 @@ static void unhash_generic_stateid(struct nfs4_ol_stateid *stp) { struct nfs4_file *fp = stp->st_stid.sc_file; + lockdep_assert_held(&stp->st_stateowner->so_client->cl_lock); + spin_lock(&fp->fi_lock); list_del(&stp->st_perfile); spin_unlock(&fp->fi_lock); @@ -918,9 +920,13 @@ static void put_generic_stateid(struct nfs4_ol_stateid *stp) static void __release_lock_stateid(struct nfs4_ol_stateid *stp) { + struct nfs4_openowner *oo = openowner(stp->st_openstp->st_stateowner); + + spin_lock(&oo->oo_owner.so_client->cl_lock); list_del(&stp->st_locks); unhash_generic_stateid(stp); unhash_stid(&stp->st_stid); + spin_unlock(&oo->oo_owner.so_client->cl_lock); put_generic_stateid(stp); } @@ -964,20 +970,26 @@ static void release_lock_stateid(struct nfs4_ol_stateid *stp) } static void release_open_stateid_locks(struct nfs4_ol_stateid *open_stp) + __releases(&open_stp->st_stateowner->so_client->cl_lock) + __acquires(&open_stp->st_stateowner->so_client->cl_lock) { struct nfs4_ol_stateid *stp; while (!list_empty(&open_stp->st_locks)) { stp = list_entry(open_stp->st_locks.next, struct nfs4_ol_stateid, st_locks); + spin_unlock(&open_stp->st_stateowner->so_client->cl_lock); release_lock_stateid(stp); + spin_lock(&open_stp->st_stateowner->so_client->cl_lock); } } static void unhash_open_stateid(struct nfs4_ol_stateid *stp) { + spin_lock(&stp->st_stateowner->so_client->cl_lock); unhash_generic_stateid(stp); release_open_stateid_locks(stp); + spin_unlock(&stp->st_stateowner->so_client->cl_lock); } static void release_open_stateid(struct nfs4_ol_stateid *stp) @@ -2987,7 +2999,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); stp->st_stateowner = &oo->oo_owner; get_nfs4_file(fp); stp->st_stid.sc_file = fp; @@ -2996,9 +3007,12 @@ 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(&oo->oo_owner.so_client->cl_lock); + list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids); spin_lock(&fp->fi_lock); list_add(&stp->st_perfile, &fp->fi_stateids); spin_unlock(&fp->fi_lock); + spin_unlock(&oo->oo_owner.so_client->cl_lock); } static void @@ -4669,6 +4683,7 @@ alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, str static struct nfs4_ol_stateid * alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, struct nfs4_ol_stateid *open_stp) { + struct nfs4_openowner *oo = openowner(open_stp->st_stateowner); struct nfs4_ol_stateid *stp; struct nfs4_client *clp = lo->lo_owner.so_client; @@ -4676,7 +4691,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_perstateowner, &lo->lo_owner.so_stateids); stp->st_stateowner = &lo->lo_owner; get_nfs4_file(fp); stp->st_stid.sc_file = fp; @@ -4684,10 +4698,13 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, struct stp->st_access_bmap = 0; stp->st_deny_bmap = open_stp->st_deny_bmap; stp->st_openstp = open_stp; + spin_lock(&oo->oo_owner.so_client->cl_lock); list_add(&stp->st_locks, &open_stp->st_locks); + list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); spin_lock(&fp->fi_lock); list_add(&stp->st_perfile, &fp->fi_stateids); spin_unlock(&fp->fi_lock); + spin_unlock(&oo->oo_owner.so_client->cl_lock); return stp; }