From patchwork Mon Sep 8 14:46:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4863011 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 23EF19F32F for ; Mon, 8 Sep 2014 14:47:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 622E92012F for ; Mon, 8 Sep 2014 14:47:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 144E220125 for ; Mon, 8 Sep 2014 14:47:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753222AbaIHOrL (ORCPT ); Mon, 8 Sep 2014 10:47:11 -0400 Received: from mail-qc0-f171.google.com ([209.85.216.171]:42466 "EHLO mail-qc0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751781AbaIHOrI (ORCPT ); Mon, 8 Sep 2014 10:47:08 -0400 Received: by mail-qc0-f171.google.com with SMTP id x3so15967050qcv.30 for ; Mon, 08 Sep 2014 07:47:07 -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=ZXik87kISS6ZwStP13u6gfnID6GoIDSbzsdSJaL5IIA=; b=FMA2itrkFpJFJh9cSG1yBM5+oddH2olb/KC2+FgQzNCGC1tfhtKf34d9qA0SzWO4v7 Fs4v+F5SMeKG08dAPCj5fomZSpdjVDLN74TswNnp5CZdcmaKoqo4ORhghZ2M9GFlBQgP MEY855OfS7gpoN01X5+nXtvZlpcKJL+9+8c3En/BGzRK8S7YiTlMuHWzC2YZhR0WU+ZE Z8i9tdDZ/BIq1qAPrF48HVN0DmvbJLIT1veB1hb/N8aZkFfPRUekbC09qKp3oK8epRvy vx/+N9+9Y1q9ffA1caFtuaUqk3ItXSF/wQgtl2Nrhnxx6HxmjpNwQ+Jciq6+Obi7JKXZ h4Sw== X-Gm-Message-State: ALoCoQnMU3quk4gXvUO6P/haJ+KJzlesSypwyNXXQZ/5pNr3yz7nHQsV+gCnkwsRzCXHYvWMKRD3 X-Received: by 10.229.232.1 with SMTP id js1mr41818216qcb.20.1410187627037; Mon, 08 Sep 2014 07:47:07 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id u95sm7407526qgu.35.2014.09.08.07.47.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Sep 2014 07:47:06 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, steved@redhat.com Subject: [PATCH v3 6/8] nfsd: serialize nfsdcltrack upcalls for a particular client Date: Mon, 8 Sep 2014 10:46:47 -0400 Message-Id: <1410187609-10319-7-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1410187609-10319-1-git-send-email-jlayton@primarydata.com> References: <1410187609-10319-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=-9.4 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 In a later patch, we want to add a flag that will allow us to reduce the need for upcalls. In order to handle that correctly, we'll need to ensure that racing upcalls for the same client can't occur. In practice it should be rare for this to occur with a well-behaved client, but it is possible. Convert one of the bits in the cl_flags field to be an upcall bitlock, and use it to ensure that upcalls for the same client are serialized. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4recover.c | 29 +++++++++++++++++++++++++++++ fs/nfsd/state.h | 1 + 2 files changed, 30 insertions(+) diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c index 5b69f0684060..ae313861a6f5 100644 --- a/fs/nfsd/nfs4recover.c +++ b/fs/nfsd/nfs4recover.c @@ -1260,6 +1260,22 @@ nfsd4_umh_cltrack_init(struct net *net) } static void +nfsd4_cltrack_upcall_lock(struct nfs4_client *clp) +{ + wait_on_bit_lock(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK, + TASK_UNINTERRUPTIBLE); +} + +static void +nfsd4_cltrack_upcall_unlock(struct nfs4_client *clp) +{ + smp_mb__before_atomic(); + clear_bit(NFSD4_CLIENT_UPCALL_LOCK, &clp->cl_flags); + smp_mb__after_atomic(); + wake_up_bit(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK); +} + +static void nfsd4_umh_cltrack_create(struct nfs4_client *clp) { char *hexid, *reclaim_complete, *grace_start; @@ -1270,9 +1286,14 @@ nfsd4_umh_cltrack_create(struct nfs4_client *clp) dprintk("%s: can't allocate memory for upcall!\n", __func__); return; } + reclaim_complete = nfsd4_cltrack_reclaim_complete(clp); grace_start = nfsd4_cltrack_grace_start(nn->boot_time); + + nfsd4_cltrack_upcall_lock(clp); nfsd4_umh_cltrack_upcall("create", hexid, reclaim_complete, grace_start); + nfsd4_cltrack_upcall_unlock(clp); + kfree(reclaim_complete); kfree(grace_start); kfree(hexid); @@ -1288,7 +1309,11 @@ nfsd4_umh_cltrack_remove(struct nfs4_client *clp) dprintk("%s: can't allocate memory for upcall!\n", __func__); return; } + + nfsd4_cltrack_upcall_lock(clp); nfsd4_umh_cltrack_upcall("remove", hexid, NULL, NULL); + nfsd4_cltrack_upcall_unlock(clp); + kfree(hexid); } @@ -1304,7 +1329,11 @@ nfsd4_umh_cltrack_check(struct nfs4_client *clp) return -ENOMEM; } legacy = nfsd4_cltrack_legacy_recdir(&clp->cl_name); + + nfsd4_cltrack_upcall_lock(clp); ret = nfsd4_umh_cltrack_upcall("check", hexid, legacy, NULL); + nfsd4_cltrack_upcall_unlock(clp); + kfree(legacy); kfree(hexid); return ret; diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 10bfda710f71..a0ed18f00dcb 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -306,6 +306,7 @@ struct nfs4_client { #define NFSD4_CLIENT_STABLE (2) /* client on stable storage */ #define NFSD4_CLIENT_RECLAIM_COMPLETE (3) /* reclaim_complete done */ #define NFSD4_CLIENT_CONFIRMED (4) /* client is confirmed */ +#define NFSD4_CLIENT_UPCALL_LOCK (5) /* upcall serialization */ #define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \ 1 << NFSD4_CLIENT_CB_KILL) unsigned long cl_flags;