From patchwork Fri May 30 13:09: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: 4270581 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 7A977BEEA7 for ; Fri, 30 May 2014 13:09:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 781462038E for ; Fri, 30 May 2014 13:09:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9BC3E2038D for ; Fri, 30 May 2014 13:09:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932205AbaE3NJt (ORCPT ); Fri, 30 May 2014 09:09:49 -0400 Received: from mail-qg0-f49.google.com ([209.85.192.49]:51906 "EHLO mail-qg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752186AbaE3NJs (ORCPT ); Fri, 30 May 2014 09:09:48 -0400 Received: by mail-qg0-f49.google.com with SMTP id a108so5099728qge.36 for ; Fri, 30 May 2014 06:09:48 -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=IlvyOOVcAHKVkk/ckKhsUMLN7MLQjJUInj+EzDZvprU=; b=D/fNuIvkpwvPL+NhvBNcEyBRNp6Djhh30V/hPCUbhysMop54LT4QBsofAES5LYibkU QOcjZJsefwix5n8lbCieioYPyOiTiJK/NcvmLkAhuMeVN11d88B/RX6bsSRm2YgV1BSZ uLceWfmAVFiwqw5d+S2IOsPbfZ4LLzIECVInDdK6499rIpdG4zlvOcBSOgqg3F0L2OPp /ZK6HnmDu5CX/kQZiELDEJIs95YkuiCZE61Xc9wmdJEjTxo0YbT/gNbZlKG2nBwFD1my Tk5rmtn3uSW40e7Zl+pBcSj2cPKtpja6Bf98usTF8inQPEtmxS23Rdp7ytnAKmXG1BBS 5HgQ== X-Gm-Message-State: ALoCoQmo8rpmtz9byX4fY0rf+ak7LfBo2MIoVNuoXZ74AOtYMqn/4I2rT4am8J/oBC6ZHwZLhfsc X-Received: by 10.140.26.179 with SMTP id 48mr20057110qgv.51.1401455388183; Fri, 30 May 2014 06:09:48 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id j3sm6169861qaf.6.2014.05.30.06.09.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 May 2014 06:09:47 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: trond.myklebust@primarydata.com, bhalevy@primarydata.com, linux-nfs@vger.kernel.org Subject: [PATCH 3/9] nfsd4: use recall_lock for delegation hashing Date: Fri, 30 May 2014 09:09:27 -0400 Message-Id: <1401455373-18207-4-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1401455373-18207-1-git-send-email-jlayton@primarydata.com> References: <1401455373-18207-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.5 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 From: Benny Halevy This fixes a bug in the handling of the fi_delegations list. nfs4_setlease does not hold the recall_lock when adding to it. The client_mutex is held, which prevents against concurrent list changes, but nfsd_break_deleg_cb does not hold while walking it. New delegations could theoretically creep onto the list while we're walking it there. Signed-off-by: Benny Halevy Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index be6199cc8711..96bdd90b96b1 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -433,12 +433,21 @@ 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) +{ + lockdep_assert_held(&recall_lock); + + 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) { - list_del_init(&dp->dl_perclnt); spin_lock(&recall_lock); + list_del_init(&dp->dl_perclnt); list_del_init(&dp->dl_perfile); list_del_init(&dp->dl_recall_lru); spin_unlock(&recall_lock); @@ -3053,11 +3062,12 @@ static int nfs4_setlease(struct nfs4_delegation *dp) status = vfs_setlease(fl->fl_file, fl->fl_type, &fl); if (status) goto out_free; - list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations); 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; out_free: locks_free_lock(fl); @@ -3078,9 +3088,8 @@ static int nfs4_set_delegation(struct nfs4_delegation *dp, struct nfs4_file *fp) spin_unlock(&recall_lock); return -EAGAIN; } - 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; } @@ -4891,6 +4900,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);