~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/nfs/export.c

Version: ~ [ linux-6.0-rc1 ] ~ [ linux-5.19.1 ] ~ [ linux-5.18.17 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.60 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.136 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.210 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.255 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.290 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.325 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Copyright (c) 2015, Primary Data, Inc. All rights reserved.
  4  *
  5  * Tao Peng <bergwolf@primarydata.com>
  6  */
  7 #include <linux/dcache.h>
  8 #include <linux/exportfs.h>
  9 #include <linux/nfs.h>
 10 #include <linux/nfs_fs.h>
 11 
 12 #include "internal.h"
 13 #include "nfstrace.h"
 14 
 15 #define NFSDBG_FACILITY         NFSDBG_VFS
 16 
 17 enum {
 18         FILEID_HIGH_OFF = 0,    /* inode fileid high */
 19         FILEID_LOW_OFF,         /* inode fileid low */
 20         FILE_I_TYPE_OFF,        /* inode type */
 21         EMBED_FH_OFF            /* embeded server fh */
 22 };
 23 
 24 
 25 static struct nfs_fh *nfs_exp_embedfh(__u32 *p)
 26 {
 27         return (struct nfs_fh *)(p + EMBED_FH_OFF);
 28 }
 29 
 30 /*
 31  * Let's break subtree checking for now... otherwise we'll have to embed parent fh
 32  * but there might not be enough space.
 33  */
 34 static int
 35 nfs_encode_fh(struct inode *inode, __u32 *p, int *max_len, struct inode *parent)
 36 {
 37         struct nfs_fh *server_fh = NFS_FH(inode);
 38         struct nfs_fh *clnt_fh = nfs_exp_embedfh(p);
 39         size_t fh_size = offsetof(struct nfs_fh, data) + server_fh->size;
 40         int len = EMBED_FH_OFF + XDR_QUADLEN(fh_size);
 41 
 42         dprintk("%s: max fh len %d inode %p parent %p",
 43                 __func__, *max_len, inode, parent);
 44 
 45         if (*max_len < len || IS_AUTOMOUNT(inode)) {
 46                 dprintk("%s: fh len %d too small, required %d\n",
 47                         __func__, *max_len, len);
 48                 *max_len = len;
 49                 return FILEID_INVALID;
 50         }
 51         if (IS_AUTOMOUNT(inode)) {
 52                 *max_len = FILEID_INVALID;
 53                 goto out;
 54         }
 55 
 56         p[FILEID_HIGH_OFF] = NFS_FILEID(inode) >> 32;
 57         p[FILEID_LOW_OFF] = NFS_FILEID(inode);
 58         p[FILE_I_TYPE_OFF] = inode->i_mode & S_IFMT;
 59         p[len - 1] = 0; /* Padding */
 60         nfs_copy_fh(clnt_fh, server_fh);
 61         *max_len = len;
 62 out:
 63         dprintk("%s: result fh fileid %llu mode %u size %d\n",
 64                 __func__, NFS_FILEID(inode), inode->i_mode, *max_len);
 65         return *max_len;
 66 }
 67 
 68 static struct dentry *
 69 nfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
 70                  int fh_len, int fh_type)
 71 {
 72         struct nfs4_label *label = NULL;
 73         struct nfs_fattr *fattr = NULL;
 74         struct nfs_fh *server_fh = nfs_exp_embedfh(fid->raw);
 75         size_t fh_size = offsetof(struct nfs_fh, data) + server_fh->size;
 76         const struct nfs_rpc_ops *rpc_ops;
 77         struct dentry *dentry;
 78         struct inode *inode;
 79         int len = EMBED_FH_OFF + XDR_QUADLEN(fh_size);
 80         u32 *p = fid->raw;
 81         int ret;
 82 
 83         /* NULL translates to ESTALE */
 84         if (fh_len < len || fh_type != len)
 85                 return NULL;
 86 
 87         fattr = nfs_alloc_fattr();
 88         if (fattr == NULL) {
 89                 dentry = ERR_PTR(-ENOMEM);
 90                 goto out;
 91         }
 92 
 93         fattr->fileid = ((u64)p[FILEID_HIGH_OFF] << 32) + p[FILEID_LOW_OFF];
 94         fattr->mode = p[FILE_I_TYPE_OFF];
 95         fattr->valid |= NFS_ATTR_FATTR_FILEID | NFS_ATTR_FATTR_TYPE;
 96 
 97         dprintk("%s: fileid %llu mode %d\n", __func__, fattr->fileid, fattr->mode);
 98 
 99         inode = nfs_ilookup(sb, fattr, server_fh);
100         if (inode)
101                 goto out_found;
102 
103         label = nfs4_label_alloc(NFS_SB(sb), GFP_KERNEL);
104         if (IS_ERR(label)) {
105                 dentry = ERR_CAST(label);
106                 goto out_free_fattr;
107         }
108 
109         rpc_ops = NFS_SB(sb)->nfs_client->rpc_ops;
110         ret = rpc_ops->getattr(NFS_SB(sb), server_fh, fattr, label);
111         if (ret) {
112                 dprintk("%s: getattr failed %d\n", __func__, ret);
113                 dentry = ERR_PTR(ret);
114                 goto out_free_label;
115         }
116 
117         inode = nfs_fhget(sb, server_fh, fattr, label);
118 
119 out_found:
120         dentry = d_obtain_alias(inode);
121 
122 out_free_label:
123         nfs4_label_free(label);
124 out_free_fattr:
125         nfs_free_fattr(fattr);
126 out:
127         return dentry;
128 }
129 
130 static struct dentry *
131 nfs_get_parent(struct dentry *dentry)
132 {
133         int ret;
134         struct inode *inode = d_inode(dentry), *pinode;
135         struct super_block *sb = inode->i_sb;
136         struct nfs_server *server = NFS_SB(sb);
137         struct nfs_fattr *fattr = NULL;
138         struct nfs4_label *label = NULL;
139         struct dentry *parent;
140         struct nfs_rpc_ops const *ops = server->nfs_client->rpc_ops;
141         struct nfs_fh fh;
142 
143         if (!ops->lookupp)
144                 return ERR_PTR(-EACCES);
145 
146         fattr = nfs_alloc_fattr();
147         if (fattr == NULL) {
148                 parent = ERR_PTR(-ENOMEM);
149                 goto out;
150         }
151 
152         label = nfs4_label_alloc(server, GFP_KERNEL);
153         if (IS_ERR(label)) {
154                 parent = ERR_CAST(label);
155                 goto out_free_fattr;
156         }
157 
158         ret = ops->lookupp(inode, &fh, fattr, label);
159         if (ret) {
160                 parent = ERR_PTR(ret);
161                 goto out_free_label;
162         }
163 
164         pinode = nfs_fhget(sb, &fh, fattr, label);
165         parent = d_obtain_alias(pinode);
166 out_free_label:
167         nfs4_label_free(label);
168 out_free_fattr:
169         nfs_free_fattr(fattr);
170 out:
171         return parent;
172 }
173 
174 const struct export_operations nfs_export_ops = {
175         .encode_fh = nfs_encode_fh,
176         .fh_to_dentry = nfs_fh_to_dentry,
177         .get_parent = nfs_get_parent,
178 };
179 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp