From patchwork Wed Jul 30 01:34: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: 4644071 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 2C63C9F36A for ; Wed, 30 Jul 2014 01:35:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 32C5D2012B for ; Wed, 30 Jul 2014 01:35:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C6E42012D for ; Wed, 30 Jul 2014 01:35:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754571AbaG3BfB (ORCPT ); Tue, 29 Jul 2014 21:35:01 -0400 Received: from mail-qg0-f49.google.com ([209.85.192.49]:49286 "EHLO mail-qg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754491AbaG3BfA (ORCPT ); Tue, 29 Jul 2014 21:35:00 -0400 Received: by mail-qg0-f49.google.com with SMTP id j107so661637qga.8 for ; Tue, 29 Jul 2014 18:35:00 -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=OkGYyFH7ik8AqiJvoTaSEpHLxuliJeBTt5kVu0cdZQw=; b=ASAQA229DLie40S336J6PkIyNOJp12fXPLW+Y63iciGgkNchrP7oy//EU/uCE1AaRB MTiJ/CXsJcCIpOz7Sl6HzHGf+Ir9KrjFbLAbUeukaT3HqVgxM9nvXGQFWDQf6v8/3/qm ik9AWlVEjPt8AnaB6wA+mtsnAQOe5RFzSB+3mS8yIkcOiUDGnYEwbLruP9SPOuzXMsAv 52zqTJbsGrcp64c8BLR8rwKEcSR0bO+KMB7fZR+7R54qgw/02YJmb7X7qmsz8lyCi3Dv Z2L3wEhhZBd3/HXkf81w4RCDZtLtEM0/JbCDRzhX5pJpVnPRcyGy8uf6CQghHVoaK2Ps hylg== X-Gm-Message-State: ALoCoQkcCT4i1aSHlfCGRbUdKhw+imJP4U4bqzIeYA1h+5u5Nf4TL+9zq36EI0lWev0Ac9a6tcYK X-Received: by 10.224.114.134 with SMTP id e6mr1081758qaq.71.1406684099973; Tue, 29 Jul 2014 18:34:59 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id 81sm860946qgw.21.2014.07.29.18.34.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jul 2014 18:34:58 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, hch@infradead.org Subject: [PATCH v3 07/38] nfsd: Add locking to protect the state owner lists Date: Tue, 29 Jul 2014 21:34:12 -0400 Message-Id: <1406684083-19736-8-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1406684083-19736-1-git-send-email-jlayton@primarydata.com> References: <1406684083-19736-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=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 8ce5894133aa..3ac6e2fdabe5 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -893,6 +893,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); @@ -921,9 +923,13 @@ static void nfs4_free_lock_stateid(struct nfs4_stid *stid) 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); nfs4_put_stid(&stp->st_stid); } @@ -967,20 +973,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) @@ -2996,16 +3008,18 @@ 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; stp->st_access_bmap = 0; stp->st_deny_bmap = 0; 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 @@ -4711,6 +4725,7 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, struct nfs4_ol_stateid *open_stp) { struct nfs4_stid *s; + struct nfs4_openowner *oo = openowner(open_stp->st_stateowner); struct nfs4_ol_stateid *stp; struct nfs4_client *clp = lo->lo_owner.so_client; @@ -4719,7 +4734,6 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, return NULL; stp = openlockstateid(s); 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; @@ -4727,10 +4741,13 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, 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; }