From patchwork Tue Nov 17 11:52:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 7636251 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 7947A9F1D3 for ; Tue, 17 Nov 2015 11:54:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A6BD7204EA for ; Tue, 17 Nov 2015 11:54:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD7B5204E2 for ; Tue, 17 Nov 2015 11:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753664AbbKQLyA (ORCPT ); Tue, 17 Nov 2015 06:54:00 -0500 Received: from mail-qg0-f48.google.com ([209.85.192.48]:33319 "EHLO mail-qg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753626AbbKQLxz (ORCPT ); Tue, 17 Nov 2015 06:53:55 -0500 Received: by qgea14 with SMTP id a14so3422570qge.0 for ; Tue, 17 Nov 2015 03:53:54 -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=ELIEsVtPKEG/veaZnhplTNavvZfmK1lmjH5kNGjdkrk=; b=Fv68DbKGgTBG7l/8wr8u8XP60mCSBFz4vV0PPOR48ulGJkYkBUxyDWdLsNfe5QD5Jj stvuRHvKmo4LfsSfZdjbYkS6FKihr+7f6fsNNd93M0YUEX7FIaWVWnddOBJ0DVaUU55N R0d3X+1ngI3SQFbbwUNqk2QCJkJeG3n8tQCAL0RNS/x2Qc23ZJWIzm8k5vo8D1SsS0NO ip2WAjxKma7lsjkQh31SiheJknAF0B+hLhvZ99RT9EbvUdLPixZsjwMg8EQABQNjhbCG fkk0i4he/iL/oELluJn5q/KCwvDuBylz/ZNCLbEAMeSNHfgRogTAEAv7jiYm6umHBH0a z/PA== 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=ELIEsVtPKEG/veaZnhplTNavvZfmK1lmjH5kNGjdkrk=; b=WmdOiiZwguOYOBZFh1qvN5PN3k/UqrAJWIxfVgQWdMNYUzshtzWeNEygqX2fS6EK9v TI7AyBY36CKrUviHu9aCu5iCT+65LFp55gHIzmua69sSnpy7zKiFi+pOsbFxTohljJCv CEv5FkQbkDGe7r3sA7QOMG8sZxh2J+8oZF8Dh1YFyxHlmS5yQ2VgjRPaU9OpZ4W/pPxR kDwkqdja12kNBCqhjnCl06uXPym/sQoU2YCJxl+YRLtMqy4qzeb4l4WSrPqcI5WnoZyl AznclPwwXCmX/B148M8V97V+5DCiwDBFaljetf0e70BYwzxERDJ+C3+xdL26LEjYXePU M7vw== X-Gm-Message-State: ALoCoQkxWMRCta969umdPTFl23JPMwIdM0fos1OU5WxQldp0S87JnVbF9y/r55emT75o3R3WTME6 X-Received: by 10.140.242.141 with SMTP id n135mr42865167qhc.59.1447761234324; Tue, 17 Nov 2015 03:53:54 -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.53 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Nov 2015 03:53:53 -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 36/38] nfs: add a get_parent export operation for NFS Date: Tue, 17 Nov 2015 06:52:58 -0500 Message-Id: <1447761180-4250-37-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 In order to connect disconnected dentries into the tree, we must be able to determine their parent. Add a get_parent routine for NFS which does a LOOKUPP operation (in the case of NFSv4), finds the parent inode and then obtains the dentry for it. Signed-off-by: Jeff Layton --- fs/nfs/export.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/fs/nfs/export.c b/fs/nfs/export.c index a40a9fc31d13..e1c8165652c5 100644 --- a/fs/nfs/export.c +++ b/fs/nfs/export.c @@ -119,8 +119,51 @@ out: return ret ? ERR_PTR(ret) : dentry; } +static struct dentry * +nfs_get_parent(struct dentry *dentry) +{ + int ret; + struct inode *inode = d_inode(dentry), *pinode; + struct super_block *sb = inode->i_sb; + struct nfs_server *server = NFS_SB(sb); + struct nfs_fattr *fattr = NULL; + struct nfs4_label *label = NULL; + struct dentry *parent; + struct nfs_rpc_ops const *ops = server->nfs_client->rpc_ops; + struct nfs_fh fh; + + if (!ops->lookupp) + return ERR_PTR(-EACCES); + + fattr = nfs_alloc_fattr(); + if (fattr == NULL) { + parent = ERR_PTR(-ENOMEM); + goto out; + } + + label = nfs4_label_alloc(server, GFP_KERNEL); + if (IS_ERR(label)) { + parent = ERR_CAST(label); + goto out; + } + + ret = ops->lookupp(inode, &fh, fattr, label); + if (ret) { + parent = ERR_PTR(ret); + goto out; + } + + pinode = nfs_fhget(sb, &fh, fattr, label); + parent = d_obtain_alias(pinode); +out: + nfs4_label_free(label); + nfs_free_fattr(fattr); + return parent; +} + const struct export_operations nfs_export_ops = { .encode_fh = nfs_encode_fh, .fh_to_dentry = nfs_fh_to_dentry, + .get_parent = nfs_get_parent, .flags = EXPORT_OP_NOWCC|EXPORT_OP_NOSUBTREECHK|EXPORT_OP_CLOSE_BEFORE_UNLINK, };