From patchwork Thu Sep 26 18:41:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benny Halevy X-Patchwork-Id: 2950251 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 88F9E9F288 for ; Thu, 26 Sep 2013 18:41:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8A11520258 for ; Thu, 26 Sep 2013 18:41:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7495E20164 for ; Thu, 26 Sep 2013 18:41:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753985Ab3IZSlJ (ORCPT ); Thu, 26 Sep 2013 14:41:09 -0400 Received: from mail-qe0-f52.google.com ([209.85.128.52]:60356 "EHLO mail-qe0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753553Ab3IZSlI (ORCPT ); Thu, 26 Sep 2013 14:41:08 -0400 Received: by mail-qe0-f52.google.com with SMTP id i11so1094294qej.39 for ; Thu, 26 Sep 2013 11:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7/OGPQbQVm0uOfEx0eKoEzTGXsT6oC1c+KY6+ipcrWU=; b=m8uUGDQxq8OQu/wMRLoWdbXnEuoDGTG9CyjW8u1GKu4/npj/hFuF01FwWZoB8UHZf+ 3bn97TpGKdukltLCK/10kNn+V8VA48wCe+XIl06XaZGKysGC9uNKhKpaneOMwcOe+sDu bE0jU+28eW6+G0CmWpy7vCT6nGUgucxEsBUioX5h1ReS7zoTibZlAX4HR/ppNnxnjnz2 F7nG2Sl1xDc2m7zv0vKhuHcXP70diuR4lFiNrQhPdPTHsMZ1n+ZFC1IwE0b0m2OvaGvl oqjFqDOqy5SBrr13vVzoTEFlsc2G/vCJ8sH65geL5a+LEoa1mBBkfeZaPLFDYVC/o5mc ptpQ== X-Received: by 10.49.63.39 with SMTP id d7mr3584646qes.78.1380220867734; Thu, 26 Sep 2013 11:41:07 -0700 (PDT) Received: from bhalevy-lt.il.tonian.com.com (nat-pool-bos-u.redhat.com. [66.187.233.207]) by mx.google.com with ESMTPSA id w20sm10232753qax.11.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 26 Sep 2013 11:41:07 -0700 (PDT) From: Benny Halevy To: " J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v0 18/49] pnfsd: nfs4_assert_state_locked Date: Thu, 26 Sep 2013 14:41:05 -0400 Message-Id: <1380220865-13506-1-git-send-email-bhalevy@primarydata.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <52447EA0.7070004@primarydata.com> References: <52447EA0.7070004@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=-9.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Make sure the state lock state is taken. Signed-off-by: Benny Halevy --- fs/nfsd/nfs4state.c | 15 +++++++++++++++ fs/nfsd/state.h | 1 + 2 files changed, 16 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 68b6f7a..f6022a6 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -135,6 +135,12 @@ static bool is_client_expired(struct nfs4_client *clp) return clp->cl_time == 0; } +void +nfs4_assert_state_locked(void) +{ + BUG_ON(!mutex_is_locked(&client_mutex)); +} + static __be32 mark_client_expired_locked(struct nfs4_client *clp) { if (atomic_read(&clp->cl_refcount)) @@ -331,6 +337,7 @@ static struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct struct nfs4_stid *stid; int new_id; + nfs4_assert_state_locked(); stid = kmem_cache_alloc(slab, GFP_KERNEL); if (!stid) return NULL; @@ -400,6 +407,7 @@ static void remove_stid(struct nfs4_stid *s) { struct idr *stateids = &s->sc_client->cl_stateids; + nfs4_assert_state_locked(); idr_remove(stateids, s->sc_stateid.si_opaque.so_id); } @@ -1306,6 +1314,7 @@ static struct nfs4_stid *find_stateid(struct nfs4_client *cl, stateid_t *t) { struct nfs4_stid *ret; + nfs4_assert_state_locked(); ret = idr_find(&cl->cl_stateids, t->si_opaque.so_id); if (!ret || !ret->sc_type) return NULL; @@ -1394,6 +1403,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name, struct rb_node *node = root->rb_node; struct nfs4_client *clp; + nfs4_assert_state_locked(); while (node) { clp = rb_entry(node, struct nfs4_client, cl_namenode); cmp = compare_blob(&clp->cl_name, name); @@ -1440,6 +1450,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name, struct nfs4_client *clp; unsigned int idhashval = clientid_hashval(clid->cl_id); + nfs4_assert_state_locked(); list_for_each_entry(clp, &tbl[idhashval], cl_idhash) { if (same_clid(&clp->cl_clientid, clid)) { if ((bool)clp->cl_minorversion != sessions) @@ -2589,6 +2600,7 @@ static void hash_openowner(struct nfs4_openowner *oo, struct nfs4_client *clp, u { struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); + nfs4_assert_state_locked(); list_add(&oo->oo_owner.so_strhash, &nn->ownerstr_hashtbl[strhashval]); list_add(&oo->oo_perclient, &clp->cl_openowners); } @@ -2655,6 +2667,7 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp, struct nfs4_openowner *oo; struct nfs4_client *clp; + nfs4_assert_state_locked(); list_for_each_entry(so, &nn->ownerstr_hashtbl[hashval], so_strhash) { if (!so->so_is_open_owner) continue; @@ -4166,6 +4179,7 @@ static bool same_lockowner_ino(struct nfs4_lockowner *lo, struct inode *inode, c unsigned int hashval = lockowner_ino_hashval(inode, clid->cl_id, owner); struct nfs4_lockowner *lo; + nfs4_assert_state_locked(); list_for_each_entry(lo, &nn->lockowner_ino_hashtbl[hashval], lo_owner_ino_hash) { if (same_lockowner_ino(lo, inode, clid, owner)) return lo; @@ -4180,6 +4194,7 @@ static void hash_lockowner(struct nfs4_lockowner *lo, unsigned int strhashval, s clp->cl_clientid.cl_id, &lo->lo_owner.so_owner); struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); + nfs4_assert_state_locked(); list_add(&lo->lo_owner.so_strhash, &nn->ownerstr_hashtbl[strhashval]); list_add(&lo->lo_owner_ino_hash, &nn->lockowner_ino_hashtbl[inohash]); list_add(&lo->lo_perstateid, &open_stp->st_lockowners); diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 424d8f5..2e601a2 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -459,6 +459,7 @@ extern __be32 nfs4_preprocess_stateid_op(struct net *net, stateid_t *stateid, int flags, struct file **filp); extern void nfs4_lock_state(void); extern void nfs4_unlock_state(void); +extern void nfs4_assert_state_locked(void); void nfs4_remove_reclaim_record(struct nfs4_client_reclaim *, struct nfsd_net *); extern void nfs4_release_reclaim(struct nfsd_net *); extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(const char *recdir,