From patchwork Tue Oct 29 09:39:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benny Halevy X-Patchwork-Id: 3107011 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 1D2149F2B7 for ; Tue, 29 Oct 2013 09:39:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6F8A520253 for ; Tue, 29 Oct 2013 09:39:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 546DB202C8 for ; Tue, 29 Oct 2013 09:39:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753750Ab3J2JjW (ORCPT ); Tue, 29 Oct 2013 05:39:22 -0400 Received: from mail-wg0-f46.google.com ([74.125.82.46]:52507 "EHLO mail-wg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753728Ab3J2JjV (ORCPT ); Tue, 29 Oct 2013 05:39:21 -0400 Received: by mail-wg0-f46.google.com with SMTP id m15so7931660wgh.25 for ; Tue, 29 Oct 2013 02:39:20 -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=pG9d7PgEHdbgQYugfXY0myzmFp6wlKW3beeWKe1Z9P0=; b=Kuh6RNk3MfL14H3L6uGFnHjo+iIj3lM/dpNfkpkiDaRtyMwkJ5t+l2Iqi70FghT+kx Zbygpb8VuP9Fgu/t8v+n5xdjJvuDe6JY5/6rtb20iiEGPniklFLh9xTrBd7Fns4ivgN7 Z0WGhlMcSTIXzoVR4ktob0ak8IdRFFXGi9a2reSZgnFu9DZeYIQos2oft3j2N6mMMCPd JeQSh66nh5EmGC2aH/2YYieukKJethyIXSPK7vULv41wlJkfPdk21MOJkxTlhpTdZeAV +uXtrFy2XZA6eAeEWd286YaYklVmLsqSg2KUbfSgL8Mgi/HZKKepNiVx3oc6EXi3zavH WueQ== X-Received: by 10.194.20.230 with SMTP id q6mr5638751wje.49.1383039560416; Tue, 29 Oct 2013 02:39:20 -0700 (PDT) Received: from bhalevy-lt.il.tonian.com (bzq-80-49-130.static.bezeqint.net. [82.80.49.130]) by mx.google.com with ESMTPSA id d11sm3017035wic.4.2013.10.29.02.39.18 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2013 02:39:19 -0700 (PDT) From: Benny Halevy To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org, Benny Halevy Subject: [PATCH 3/7] nfsd4: properly hash delegation in nfs4_setlease Date: Tue, 29 Oct 2013 11:39:16 +0200 Message-Id: <1383039556-27257-1-git-send-email-bhalevy@primarydata.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <526F81DE.6060704@primarydata.com> References: <526F81DE.6060704@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.3 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 keep all accesses via dl_perclnt under the recall_lock. Signed-off-by: Benny Halevy --- fs/nfsd/nfs4state.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index a66b0ad..405649f 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -432,6 +432,13 @@ static void unhash_stid(struct nfs4_stid *s) s->sc_type = 0; } +static void +hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp) +{ + list_add(&dp->dl_perfile, &fp->fi_delegations); + list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations); +} + /* Called under the state lock. */ static void unhash_delegation(struct nfs4_delegation *dp) @@ -3035,17 +3042,17 @@ static int nfs4_setlease(struct nfs4_delegation *dp) if (!fl) return -ENOMEM; fl->fl_file = find_readable_file(fp); - list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations); status = vfs_setlease(fl->fl_file, fl->fl_type, &fl); if (status) { - list_del_init(&dp->dl_perclnt); locks_free_lock(fl); return status; } fp->fi_lease = fl; fp->fi_deleg_file = get_file(fl->fl_file); atomic_set(&fp->fi_delegees, 1); - list_add(&dp->dl_perfile, &fp->fi_delegations); + spin_lock(&recall_lock); + hash_delegation_locked(dp, fp); + spin_unlock(&recall_lock); return 0; } @@ -3070,9 +3077,8 @@ static int nfs4_set_delegation(struct nfs4_delegation *dp, struct nfs4_file *fp) goto out_free; } atomic_inc(&fp->fi_delegees); - list_add(&dp->dl_perfile, &fp->fi_delegations); + hash_delegation_locked(dp, fp); spin_unlock(&recall_lock); - list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations); return 0; out_free: put_nfs4_file(fp); @@ -4871,6 +4877,7 @@ static u64 nfsd_find_all_delegations(struct nfs4_client *clp, u64 max, struct nfs4_delegation *dp, *next; u64 count = 0; + lockdep_assert_held(&recall_lock); list_for_each_entry_safe(dp, next, &clp->cl_delegations, dl_perclnt) { if (victims) list_move(&dp->dl_recall_lru, victims);