From patchwork Fri Apr 22 00:51:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 8905071 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 700679F457 for ; Fri, 22 Apr 2016 00:52:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FE6920225 for ; Fri, 22 Apr 2016 00:52:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD24420221 for ; Fri, 22 Apr 2016 00:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751840AbcDVAwN (ORCPT ); Thu, 21 Apr 2016 20:52:13 -0400 Received: from mail-qk0-f178.google.com ([209.85.220.178]:36600 "EHLO mail-qk0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751731AbcDVAwM (ORCPT ); Thu, 21 Apr 2016 20:52:12 -0400 Received: by mail-qk0-f178.google.com with SMTP id x7so33030600qkd.3 for ; Thu, 21 Apr 2016 17:52:12 -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=KXBV9i6ljOJVfkiLtAApwYW4gSXd+smgD2+ODUqvGBle93g0RRKlXaxOQlCuEvYNjX n4DsjU4A5nEMQrLc3Xr7warMuLltcnjTNyeiVjxCqyv4QkXMLtRJx3ucuZ5U8uu5tEp5 Gc+QGKLM3qpcww37GrEkrB2scGhMjnFv76W38CiJauhTnvLbdkESRpAzPPQr7kjArkMc fF9k+L3IlOq3NKMM1dTHaBZP4COjS0l47uQixca+VwiZJM2Ir/aYGfXoFkKgEFG0SaI5 sTuBswnUB4ujeg9R/dJ8RLpqHMX2FYcBr8ARCTuMN9mycckLm/pjp0wrWFo1XOR4owMw hhyw== 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=YKm5A0qUSVpbM14lvH/G3WnqUv7HVAPWqa/chMVkyxQ8H8OPyIZOYQUDpWnWRYsilh UtOK2eW+7UfdQejHLFBu/lKvQZKfrbgKO1hySpL+IT8UwFb99++s7wvMPXcfs22LlOMU 7gpEtRNxSRlSOHDSn3891I8lGfSw0fF1QD9BL1ChOlRjbJTWIqIBlJUeJHRaW0zd8wYP PU6/xsfGR8qlkEWfhcEtwYj8H9iAwkaOfODwGFSu87pAcf5uV1NS9ED7X0QB+9KWujYT n2x6mK0HtCPZTgrdidhAkYXx5Lim7PgrICO/ObOiSG6BGbn+E+RJBCoRCEzUrUmgIH84 jh1w== X-Gm-Message-State: AOPr4FWQf8MdlcR+AqfCWrtYm0K6ZOwKrPG0rIBACDpMBM3hgLRE6faFIPArndWWlhbBLQ== X-Received: by 10.55.165.22 with SMTP id o22mr13687235qke.0.1461286331571; Thu, 21 Apr 2016 17:52:11 -0700 (PDT) Received: from tlielax.poochiereds.net ([2606:a000:1125:4074:3a60:77ff:fe93:a95d]) by smtp.googlemail.com with ESMTPSA id 13sm1573335qgt.8.2016.04.21.17.52.10 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 21 Apr 2016 17:52:10 -0700 (PDT) From: Jeff Layton X-Google-Original-From: Jeff Layton To: trond.myklebust@primarydata.com Cc: Anna Schumaker , linux-nfs@vger.kernel.org Subject: [PATCH v2 3/7] sunrpc: add a get_rpccred_rcu inline Date: Thu, 21 Apr 2016 20:51:56 -0400 Message-Id: <1461286320-24601-4-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1461286320-24601-1-git-send-email-jeff.layton@primarydata.com> References: <1461286320-24601-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 */