From patchwork Wed Aug 28 19:40:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 2850968 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 C4FC2BF546 for ; Wed, 28 Aug 2013 19:41:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0072A20430 for ; Wed, 28 Aug 2013 19:41:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 03AC6203F4 for ; Wed, 28 Aug 2013 19:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754543Ab3H1Tk4 (ORCPT ); Wed, 28 Aug 2013 15:40:56 -0400 Received: from mx12.netapp.com ([216.240.18.77]:1449 "EHLO mx12.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754332Ab3H1Tkz (ORCPT ); Wed, 28 Aug 2013 15:40:55 -0400 X-IronPort-AV: E=Sophos;i="4.89,977,1367996400"; d="scan'208";a="84744484" Received: from vmwexceht05-prd.hq.netapp.com ([10.106.77.35]) by mx12-out.netapp.com with ESMTP; 28 Aug 2013 12:40:34 -0700 Received: from smtp2.corp.netapp.com (10.57.159.114) by VMWEXCEHT05-PRD.hq.netapp.com (10.106.77.35) with Microsoft SMTP Server id 14.3.123.3; Wed, 28 Aug 2013 12:40:33 -0700 Received: from leira.trondhjem.org.com (leira.trondhjem.org.vpn.netapp.com [10.55.74.77]) by smtp2.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id r7SJeOrf013790; Wed, 28 Aug 2013 12:40:33 -0700 (PDT) From: Trond Myklebust To: CC: Subject: [PATCH v2 14/16] SUNRPC: Add a helper to allow sharing of rpc_pipefs directory objects Date: Wed, 28 Aug 2013 15:40:19 -0400 Message-ID: <1377718821-28159-14-git-send-email-Trond.Myklebust@netapp.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1377718821-28159-13-git-send-email-Trond.Myklebust@netapp.com> References: <1377718821-28159-1-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-2-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-3-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-4-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-5-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-6-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-7-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-8-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-9-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-10-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-11-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-12-git-send-email-Trond.Myklebust@netapp.com> <1377718821-28159-13-git-send-email-Trond.Myklebust@netapp.com> MIME-Version: 1.0 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=unavailable 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 Add support for looking up existing objects and creating new ones if there is no match. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/rpc_pipe_fs.h | 6 ++++++ net/sunrpc/rpc_pipe.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/linux/sunrpc/rpc_pipe_fs.h b/include/linux/sunrpc/rpc_pipe_fs.h index b0cf181..a353e03 100644 --- a/include/linux/sunrpc/rpc_pipe_fs.h +++ b/include/linux/sunrpc/rpc_pipe_fs.h @@ -106,6 +106,12 @@ extern int rpc_add_pipe_dir_object(struct net *net, extern void rpc_remove_pipe_dir_object(struct net *net, struct rpc_pipe_dir_head *pdh, struct rpc_pipe_dir_object *pdo); +extern struct rpc_pipe_dir_object *rpc_find_or_alloc_pipe_dir_object( + struct net *net, + struct rpc_pipe_dir_head *pdh, + int (*match)(struct rpc_pipe_dir_object *, void *), + struct rpc_pipe_dir_object *(*alloc)(void *), + void *data); struct cache_detail; extern struct dentry *rpc_create_cache_dir(struct dentry *, diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c index a35b2f4..f94567b 100644 --- a/net/sunrpc/rpc_pipe.c +++ b/net/sunrpc/rpc_pipe.c @@ -982,6 +982,41 @@ rpc_remove_pipe_dir_object(struct net *net, } EXPORT_SYMBOL_GPL(rpc_remove_pipe_dir_object); +/** + * rpc_find_or_alloc_pipe_dir_object + * @net: pointer to struct net + * @pdh: pointer to struct rpc_pipe_dir_head + * @match: match struct rpc_pipe_dir_object to data + * @alloc: allocate a new struct rpc_pipe_dir_object + * @data: user defined data for match() and alloc() + * + */ +struct rpc_pipe_dir_object * +rpc_find_or_alloc_pipe_dir_object(struct net *net, + struct rpc_pipe_dir_head *pdh, + int (*match)(struct rpc_pipe_dir_object *, void *), + struct rpc_pipe_dir_object *(*alloc)(void *), + void *data) +{ + struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); + struct rpc_pipe_dir_object *pdo; + + mutex_lock(&sn->pipefs_sb_lock); + list_for_each_entry(pdo, &pdh->pdh_entries, pdo_head) { + if (!match(pdo, data)) + continue; + goto out; + } + pdo = alloc(data); + if (!pdo) + goto out; + rpc_add_pipe_dir_object_locked(net, pdh, pdo); +out: + mutex_unlock(&sn->pipefs_sb_lock); + return pdo; +} +EXPORT_SYMBOL_GPL(rpc_find_or_alloc_pipe_dir_object); + static void rpc_create_pipe_dir_objects(struct rpc_pipe_dir_head *pdh) {