From patchwork Mon Sep 2 18:16:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 2852934 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 0B182C0AD3 for ; Mon, 2 Sep 2013 18:17:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 340A1202EB for ; Mon, 2 Sep 2013 18:17:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F3CA202C6 for ; Mon, 2 Sep 2013 18:17:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932067Ab3IBSRT (ORCPT ); Mon, 2 Sep 2013 14:17:19 -0400 Received: from mx12.netapp.com ([216.240.18.77]:61092 "EHLO mx12.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932111Ab3IBSRQ (ORCPT ); Mon, 2 Sep 2013 14:17:16 -0400 X-IronPort-AV: E=Sophos;i="4.89,1008,1367996400"; d="scan'208";a="86036609" Received: from vmwexceht01-prd.hq.netapp.com ([10.106.76.239]) by mx12-out.netapp.com with ESMTP; 02 Sep 2013 11:17:16 -0700 Received: from smtp1.corp.netapp.com (10.57.156.124) by VMWEXCEHT01-PRD.hq.netapp.com (10.106.76.239) with Microsoft SMTP Server id 14.3.123.3; Mon, 2 Sep 2013 11:17:16 -0700 Received: from leira.trondhjem.org.com (leira.trondhjem.org.vpn.netapp.com [10.55.73.213]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id r82IH4NH006298; Mon, 2 Sep 2013 11:17:15 -0700 (PDT) From: Trond Myklebust To: CC: Subject: [PATCH v3 14/17] SUNRPC: Add a helper to allow sharing of rpc_pipefs directory objects Date: Mon, 2 Sep 2013 14:16:57 -0400 Message-ID: <1378145820-29990-14-git-send-email-Trond.Myklebust@netapp.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1378145820-29990-13-git-send-email-Trond.Myklebust@netapp.com> References: <1378145820-29990-1-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-2-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-3-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-4-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-5-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-6-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-7-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-8-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-9-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-10-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-11-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-12-git-send-email-Trond.Myklebust@netapp.com> <1378145820-29990-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.3 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) {