From patchwork Tue Nov 17 11:52:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 7636271 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 EE2A29F1D3 for ; Tue, 17 Nov 2015 11:54:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 18DE9204EC for ; Tue, 17 Nov 2015 11:54:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 27A6020501 for ; Tue, 17 Nov 2015 11:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753600AbbKQLyP (ORCPT ); Tue, 17 Nov 2015 06:54:15 -0500 Received: from mail-qg0-f47.google.com ([209.85.192.47]:34835 "EHLO mail-qg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753592AbbKQLxw (ORCPT ); Tue, 17 Nov 2015 06:53:52 -0500 Received: by qgec40 with SMTP id c40so3396332qge.2 for ; Tue, 17 Nov 2015 03:53:51 -0800 (PST) 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=4x+50XVxj5G1tSlciUd/Ev2fLHZKQtpSPgpIcNaSem0=; b=Y2Nv7JOkhTo3pITUzMxazxwubL5o5RzHDxg41645wk3I49Ky+4gMX1rtSm3BuG3URa Hk+BotFJqAdiekw0EA9/NIfppP9D0OJmPUK/CcV+9WughWe+z+RlF7CL+LvGRIB1NJsy qkkgNOZl+o2BcOsWoS29f/DrDH4HXu1+tv8e65pTMKx3GYg0A60VhghA7c/fiDOXd/p8 gNCtbkqNxC3BxpuiZQJO0EWeQO1sMNQvSYNI8ue4EZvxrNGQJ9aYGKD5Q0WFGWm/AFZw v5K2gY47TtMWm99nVqHti/+JTIN+m1Jq8zpSqix5tMLH5lqzZ/MBPBXObM00t+wb+3jL GAFw== 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=4x+50XVxj5G1tSlciUd/Ev2fLHZKQtpSPgpIcNaSem0=; b=CBlHRaZw6b2isiqSZlrGcCmImXoPH7Iaf67K3xjnUfZSZmau3Il/kJJ5XRQL5ICN1l LWHB1ELCkQ89rtjck2tOSmo9LOpGlHwGAe45BBuXceoRBvX/l8Dx1Mcc7GiynpuK3T7X gCGmauIeWl9UXJvUvb0/lccQuopxzKleRk90s+4cM6qFxmHqT7C/wbXtgBdDx4ntK4or h5X4MpFQ3DPxMKmB9wyTMlnATELBHiXrWwvCz1mwLoVPMVmyt3yPzA6nJU/jHX/PYXky Jc29tay3eIBvxJ3L+eHNkVH/AnQhrZju6Tt6MOZMknB9C8aGEoM5uDokvyx+fv5mc5tQ gaow== X-Gm-Message-State: ALoCoQknBZNBGh+pQuB1hj168d8V/bTwDqsUcDiiwv2stDXAao/cjLJCsenxn76N3Vw2bGvNzjGW X-Received: by 10.140.217.138 with SMTP id n132mr40857139qhb.26.1447761231365; Tue, 17 Nov 2015 03:53:51 -0800 (PST) Received: from tlielax.poochiereds.net ([2606:a000:1125:4075::d5a]) by smtp.googlemail.com with ESMTPSA id w10sm1583910qhc.16.2015.11.17.03.53.50 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Nov 2015 03:53:50 -0800 (PST) From: Jeff Layton X-Google-Original-From: Jeff Layton To: bfields@fieldses.org, trond.myklebust@primarydata.com Cc: linux-nfs@vger.kernel.org, Eric Paris , Alexander Viro , linux-fsdevel@vger.kernel.org Subject: [PATCH v1 33/38] nfs: add fh_to_dentry export op Date: Tue, 17 Nov 2015 06:52:55 -0500 Message-Id: <1447761180-4250-34-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1447761180-4250-1-git-send-email-jeff.layton@primarydata.com> References: <1447761180-4250-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.4 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 From: Peng Tao Signed-off-by: Peng Tao --- fs/nfs/export.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/fs/nfs/export.c b/fs/nfs/export.c index d446f77b26b3..374dcc2590a0 100644 --- a/fs/nfs/export.c +++ b/fs/nfs/export.c @@ -6,10 +6,12 @@ * Tao Peng */ +#include #include #include #include +#include "internal.h" #include "nfstrace.h" #define NFSDBG_FACILITY NFSDBG_VFS @@ -40,7 +42,54 @@ nfs_encode_fh(struct inode *inode, __u32 *p, int *max_len, struct inode *parent) return *max_len; } +static struct dentry * +nfs_fh_to_dentry(struct super_block *sb, struct fid *fid, + int fh_len, int fh_type) +{ + struct nfs4_label *label = NULL; + struct nfs_fattr *fattr = NULL; + struct nfs_fh *server_fh = (struct nfs_fh *)fid->raw; + const struct nfs_rpc_ops *rpc_ops; + struct dentry *dentry = NULL; + struct inode *inode; + int len = server_fh->size / 4 + 1; + int ret; + + /* NULL translates to ESTALE */ + if (fh_len < len || fh_type != len) + return NULL; + + fattr = nfs_alloc_fattr(); + if (fattr == NULL) { + ret = -ENOMEM; + goto out; + } + + label = nfs4_label_alloc(NFS_SB(sb), GFP_KERNEL); + if (IS_ERR(label)) { + ret = PTR_ERR(label); + goto out; + } + + rpc_ops = NFS_SB(sb)->nfs_client->rpc_ops; + ret = rpc_ops->getattr(NFS_SB(sb), server_fh, fattr, label); + if (ret) { + dprintk("%s: getattr failed %d\n", __func__, ret); + goto out; + } + + inode = nfs_fhget(sb, server_fh, fattr, label); + dentry = d_obtain_alias(inode); + +out: + nfs4_label_free(label); + nfs_free_fattr(fattr); + + return ret ? ERR_PTR(ret) : dentry; +} + const struct export_operations nfs_export_ops = { .encode_fh = nfs_encode_fh, + .fh_to_dentry = nfs_fh_to_dentry, .flags = EXPORT_OP_NOWCC|EXPORT_OP_NOSUBTREECHK|EXPORT_OP_CLOSE_BEFORE_UNLINK, };