From patchwork Mon Jun 30 15:49:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4451501 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 11C79BEEAA for ; Mon, 30 Jun 2014 15:51:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 27D67201C0 for ; Mon, 30 Jun 2014 15:51:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C12F2021F for ; Mon, 30 Jun 2014 15:51:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754431AbaF3Pve (ORCPT ); Mon, 30 Jun 2014 11:51:34 -0400 Received: from mail-qg0-f46.google.com ([209.85.192.46]:46031 "EHLO mail-qg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750897AbaF3Pvd (ORCPT ); Mon, 30 Jun 2014 11:51:33 -0400 Received: by mail-qg0-f46.google.com with SMTP id q107so2136622qgd.33 for ; Mon, 30 Jun 2014 08:51:33 -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=uBJG+eH9GRDVGESmak8ZMxrenBhOAkqQgdPskJ3nhZ0=; b=hYvZjGe+T/CZQvmi51UlYCNWQxjDVqvVCe02lGZvLsvK5pGdtyUSXht9d4TumBoowa 0UeWDeu9hSKc7UoZTT11//Zcbr0G0zr1267RYS6pgEzm81IP4dR2f9gHN4opg9eH6yr+ adaW8rWMHl3jm1ZXX4dQDlSwz3bNoQBGb5PFZYjp1hRumxaF7V5Kr9kA4OxSJwREYX5h 9XGhAG4o3i6RkoId+xSQiC0BY+YhlkdNdfiaBksvdkk7gRhFsk8Q+znnb5s5tgXtCd5J lrsuiQDJ+mogfj7o+LIK50CoaOBnZ9wHI2uNzwvJ/eDq34cvOgb3OPQ+o+tfHM99RXO4 M3pQ== X-Gm-Message-State: ALoCoQkOhb0h3zNsqC5tbu1u5klS84+7eTExxvKlep0AfX8e2uAkg+hk01LF+onTUnK5gg8rMbV2 X-Received: by 10.224.98.197 with SMTP id r5mr57934913qan.57.1404143493187; Mon, 30 Jun 2014 08:51:33 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id m1sm32584105qaz.27.2014.06.30.08.51.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jun 2014 08:51:32 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 043/114] nfsd: Add locking to protect the state owner lists Date: Mon, 30 Jun 2014 11:49:12 -0400 Message-Id: <1404143423-24381-44-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1404143423-24381-1-git-send-email-jlayton@primarydata.com> References: <1404143423-24381-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 aea256264266..05d0fac2e50a 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -863,6 +863,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); @@ -896,9 +898,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); } @@ -942,20 +948,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) @@ -2965,7 +2977,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; @@ -2974,9 +2985,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 @@ -4641,6 +4655,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; @@ -4648,7 +4663,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; @@ -4656,10 +4670,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; }