From patchwork Thu Apr 14 12:37:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 8835871 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C1AEB9F3D1 for ; Thu, 14 Apr 2016 12:37:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD546201BB for ; Thu, 14 Apr 2016 12:37:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C9A72025A for ; Thu, 14 Apr 2016 12:37:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932122AbcDNMhS (ORCPT ); Thu, 14 Apr 2016 08:37:18 -0400 Received: from mail-qg0-f42.google.com ([209.85.192.42]:33843 "EHLO mail-qg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755395AbcDNMhQ (ORCPT ); Thu, 14 Apr 2016 08:37:16 -0400 Received: by mail-qg0-f42.google.com with SMTP id c6so61699161qga.1 for ; Thu, 14 Apr 2016 05:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poochiereds-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4/cWQZSSWr8nADK1qgsVIeZhVgJk04Imlb3nd+ohtTU=; b=R8zcxLMxyYtdmG0Yu2H5UCggSIr7XcXqp95ttF6neUCo2zraJclzbwXauOAK/o3zj8 PFZtyfd2xIDqL1jzvcwLQ8Vc2pxJW0zDEtY6ElFnyBLk1D35IIo8xXILlupL2JXBsaOc iKafjZBjJ6YBaEmUFA9l+7kaJtQHnIi5gCfluPtmcdhTVr+YMAvE7uWZZWCyH7LWSKcN RMcLvB/ppTOQV2xmiCns+pbQZ+pjNOdsvYwaAHKjPilkugkLf0ClQcLXdAF1Kz6lBteR gpn5zhQwACGR953jD2BpZ30YGoGfm/h3A565s37e9W/lJYYChq/D1Wykm0YeXJDqvmXU 5luw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4/cWQZSSWr8nADK1qgsVIeZhVgJk04Imlb3nd+ohtTU=; b=ecwygB4WAHiGrfVuc3TtFis5Dc6fT1gYeBrl/ksw3vdziJk4MKV39JvPFufPvcmNfy GoRQ3Nj5BUf30uYdLz0S7OS1tSAopRZn7SJKN27bLd7vovekyfqusddfkP8XNzErES32 xYIO6adUPH/jjCP8dtD/uxTndEBE6GwjMpi1nnSQ7pnbGGwFhJDzEMfXJD7zGEU3O6p7 no+AoMbZozTkr7vOEwRdBnC/gQq+agFtC0qnIuFjVhdQRxVfe4b0wJlB5JRyYjLJgrkG bTFgg2w5PgUECdq1G9PUJImc+r9vLY7vVIgScv+6HcNXGSC5EBUlNlQbDLteU/XR7/b1 hFdg== X-Gm-Message-State: AOPr4FXaTCvdApJOqnuAiJk+Z0EbbZAoTRNW8iYSGCVViEb+yrIlSLuuYxLEeav/wQDLSg== X-Received: by 10.140.89.178 with SMTP id v47mr17495753qgd.11.1460637434967; Thu, 14 Apr 2016 05:37:14 -0700 (PDT) Received: from tlielax.poochiereds.net ([2606:a000:1125:4074:3a60:77ff:fe93:a95d]) by smtp.googlemail.com with ESMTPSA id e11sm18022238qkb.39.2016.04.14.05.37.14 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Apr 2016 05:37:14 -0700 (PDT) From: Jeff Layton X-Google-Original-From: Jeff Layton To: trond.myklebust@primarydata.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 4/8] sunrpc: add a get_rpccred_rcu inline Date: Thu, 14 Apr 2016 08:37:01 -0400 Message-Id: <1460637425-1580-5-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460637425-1580-1-git-send-email-jeff.layton@primarydata.com> References: <1460637425-1580-1-git-send-email-jeff.layton@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.8 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 Sometimes we might have a RCU managed credential pointer and don't want to use locking to handle it. Add a function that will take a reference to the cred iff the refcount is not already zero. Callers can dereference the pointer under the rcu_read_lock and use that function to take a reference only if the cred is not on its way to destruction. Signed-off-by: Jeff Layton --- include/linux/sunrpc/auth.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h index 16bd8f8fef8c..6f36b2bf3e05 100644 --- a/include/linux/sunrpc/auth.h +++ b/include/linux/sunrpc/auth.h @@ -206,5 +206,23 @@ struct rpc_cred * get_rpccred(struct rpc_cred *cred) return cred; } +/** + * get_rpccred_rcu - get a reference to a cred using rcu-protected pointer + * @cred: cred of which to take a reference + * + * In some cases, we may have a pointer to a credential to which we + * want to take a reference, but don't already have one. Because these + * objects are freed using RCU, we can access the cr_count while its + * on its way to destruction and only take a reference if it's not already + * zero. + */ +static inline struct rpc_cred * +get_rpccred_rcu(struct rpc_cred *cred) +{ + if (atomic_inc_not_zero(&cred->cr_count)) + return cred; + return NULL; +} + #endif /* __KERNEL__ */ #endif /* _LINUX_SUNRPC_AUTH_H */