blob: 15ff1b09cfa29673cc08e6a1bd04cb5ab6c33085 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002#include <linux/ceph/ceph_debug.h>
Sage Weila8e63b72009-10-06 11:31:13 -07003
4#include <linux/exportfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09005#include <linux/slab.h>
Sage Weila8e63b72009-10-06 11:31:13 -07006#include <asm/unaligned.h>
7
8#include "super.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07009#include "mds_client.h"
Sage Weila8e63b72009-10-06 11:31:13 -070010
11/*
Sage Weila8e63b72009-10-06 11:31:13 -070012 * Basic fh
13 */
14struct ceph_nfs_fh {
15 u64 ino;
16} __attribute__ ((packed));
17
18/*
Yan, Zheng4f32b422014-03-01 18:05:41 +080019 * Larger fh that includes parent ino.
Sage Weila8e63b72009-10-06 11:31:13 -070020 */
21struct ceph_nfs_confh {
22 u64 ino, parent_ino;
Sage Weila8e63b72009-10-06 11:31:13 -070023} __attribute__ ((packed));
24
Yan, Zheng570df4e2017-11-15 17:39:40 +080025/*
26 * fh for snapped inode
27 */
28struct ceph_nfs_snapfh {
29 u64 ino;
30 u64 snapid;
31 u64 parent_ino;
32 u32 hash;
33} __attribute__ ((packed));
34
35static int ceph_encode_snapfh(struct inode *inode, u32 *rawfh, int *max_len,
36 struct inode *parent_inode)
37{
38 const static int snap_handle_length =
39 sizeof(struct ceph_nfs_snapfh) >> 2;
40 struct ceph_nfs_snapfh *sfh = (void *)rawfh;
41 u64 snapid = ceph_snap(inode);
42 int ret;
43 bool no_parent = true;
44
45 if (*max_len < snap_handle_length) {
46 *max_len = snap_handle_length;
47 ret = FILEID_INVALID;
48 goto out;
49 }
50
51 ret = -EINVAL;
52 if (snapid != CEPH_SNAPDIR) {
53 struct inode *dir;
54 struct dentry *dentry = d_find_alias(inode);
55 if (!dentry)
56 goto out;
57
58 rcu_read_lock();
59 dir = d_inode_rcu(dentry->d_parent);
60 if (ceph_snap(dir) != CEPH_SNAPDIR) {
61 sfh->parent_ino = ceph_ino(dir);
62 sfh->hash = ceph_dentry_hash(dir, dentry);
63 no_parent = false;
64 }
65 rcu_read_unlock();
66 dput(dentry);
67 }
68
69 if (no_parent) {
70 if (!S_ISDIR(inode->i_mode))
71 goto out;
72 sfh->parent_ino = sfh->ino;
73 sfh->hash = 0;
74 }
75 sfh->ino = ceph_ino(inode);
76 sfh->snapid = snapid;
77
78 *max_len = snap_handle_length;
79 ret = FILEID_BTRFS_WITH_PARENT;
80out:
81 dout("encode_snapfh %llx.%llx ret=%d\n", ceph_vinop(inode), ret);
82 return ret;
83}
84
Sage Weilc8628682012-04-05 12:07:36 -070085static int ceph_encode_fh(struct inode *inode, u32 *rawfh, int *max_len,
86 struct inode *parent_inode)
Sage Weila8e63b72009-10-06 11:31:13 -070087{
Yan, Zheng570df4e2017-11-15 17:39:40 +080088 const static int handle_length =
89 sizeof(struct ceph_nfs_fh) >> 2;
90 const static int connected_handle_length =
91 sizeof(struct ceph_nfs_confh) >> 2;
Aneesh Kumar K.V92923dc2010-10-05 16:03:41 +053092 int type;
Sage Weila8e63b72009-10-06 11:31:13 -070093
Sage Weila8e63b72009-10-06 11:31:13 -070094 if (ceph_snap(inode) != CEPH_NOSNAP)
Yan, Zheng570df4e2017-11-15 17:39:40 +080095 return ceph_encode_snapfh(inode, rawfh, max_len, parent_inode);
Sage Weila8e63b72009-10-06 11:31:13 -070096
Yan, Zheng4f32b422014-03-01 18:05:41 +080097 if (parent_inode && (*max_len < connected_handle_length)) {
Aneesh Kumar K.V92923dc2010-10-05 16:03:41 +053098 *max_len = connected_handle_length;
Yan, Zheng4f32b422014-03-01 18:05:41 +080099 return FILEID_INVALID;
100 } else if (*max_len < handle_length) {
Aneesh Kumar K.Vbba0cd02010-10-05 16:03:42 +0530101 *max_len = handle_length;
Yan, Zheng4f32b422014-03-01 18:05:41 +0800102 return FILEID_INVALID;
Sage Weila8e63b72009-10-06 11:31:13 -0700103 }
Yan, Zheng4f32b422014-03-01 18:05:41 +0800104
105 if (parent_inode) {
Yan, Zheng570df4e2017-11-15 17:39:40 +0800106 struct ceph_nfs_confh *cfh = (void *)rawfh;
Yan, Zheng4f32b422014-03-01 18:05:41 +0800107 dout("encode_fh %llx with parent %llx\n",
108 ceph_ino(inode), ceph_ino(parent_inode));
109 cfh->ino = ceph_ino(inode);
110 cfh->parent_ino = ceph_ino(parent_inode);
111 *max_len = connected_handle_length;
112 type = FILEID_INO32_GEN_PARENT;
113 } else {
Yan, Zheng570df4e2017-11-15 17:39:40 +0800114 struct ceph_nfs_fh *fh = (void *)rawfh;
Yan, Zheng4f32b422014-03-01 18:05:41 +0800115 dout("encode_fh %llx\n", ceph_ino(inode));
116 fh->ino = ceph_ino(inode);
117 *max_len = handle_length;
118 type = FILEID_INO32_GEN;
119 }
Sage Weila8e63b72009-10-06 11:31:13 -0700120 return type;
121}
122
Yan, Zheng570df4e2017-11-15 17:39:40 +0800123static struct inode *__lookup_inode(struct super_block *sb, u64 ino)
Sage Weila8e63b72009-10-06 11:31:13 -0700124{
Sage Weil3c454cf2011-04-06 09:31:40 -0700125 struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc;
Sage Weila8e63b72009-10-06 11:31:13 -0700126 struct inode *inode;
Sage Weila8e63b72009-10-06 11:31:13 -0700127 struct ceph_vino vino;
128 int err;
129
Yan, Zheng4f32b422014-03-01 18:05:41 +0800130 vino.ino = ino;
Sage Weila8e63b72009-10-06 11:31:13 -0700131 vino.snap = CEPH_NOSNAP;
132 inode = ceph_find_inode(sb, vino);
Sage Weil3c454cf2011-04-06 09:31:40 -0700133 if (!inode) {
134 struct ceph_mds_request *req;
Yan, Zheng315f2402016-03-07 10:34:50 +0800135 int mask;
Sage Weil3c454cf2011-04-06 09:31:40 -0700136
137 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPINO,
138 USE_ANY_MDS);
139 if (IS_ERR(req))
140 return ERR_CAST(req);
141
Yan, Zheng315f2402016-03-07 10:34:50 +0800142 mask = CEPH_STAT_CAP_INODE;
143 if (ceph_security_xattr_wanted(d_inode(sb->s_root)))
144 mask |= CEPH_CAP_XATTR_SHARED;
Yan, Zheng570df4e2017-11-15 17:39:40 +0800145 req->r_args.lookupino.mask = cpu_to_le32(mask);
Yan, Zheng315f2402016-03-07 10:34:50 +0800146
Sage Weil3c454cf2011-04-06 09:31:40 -0700147 req->r_ino1 = vino;
148 req->r_num_caps = 1;
149 err = ceph_mdsc_do_request(mdsc, NULL, req);
Sage Weil45e3d3e2011-04-06 09:35:00 -0700150 inode = req->r_target_inode;
151 if (inode)
Sage Weil70b666c2011-05-27 09:24:26 -0700152 ihold(inode);
Sage Weil3c454cf2011-04-06 09:31:40 -0700153 ceph_mdsc_put_request(req);
Sage Weil3c454cf2011-04-06 09:31:40 -0700154 if (!inode)
Luis Henriques38862742019-03-21 10:20:09 +0000155 return err < 0 ? ERR_PTR(err) : ERR_PTR(-ESTALE);
Sage Weil3c454cf2011-04-06 09:31:40 -0700156 }
Yan, Zheng570df4e2017-11-15 17:39:40 +0800157 return inode;
158}
Sage Weila8e63b72009-10-06 11:31:13 -0700159
Yan, Zheng570df4e2017-11-15 17:39:40 +0800160struct inode *ceph_lookup_inode(struct super_block *sb, u64 ino)
161{
162 struct inode *inode = __lookup_inode(sb, ino);
163 if (IS_ERR(inode))
164 return inode;
165 if (inode->i_nlink == 0) {
166 iput(inode);
167 return ERR_PTR(-ESTALE);
168 }
Luis Henriques38862742019-03-21 10:20:09 +0000169 return inode;
170}
171
172static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
173{
Yan, Zheng570df4e2017-11-15 17:39:40 +0800174 struct inode *inode = __lookup_inode(sb, ino);
Luis Henriques38862742019-03-21 10:20:09 +0000175 if (IS_ERR(inode))
176 return ERR_CAST(inode);
Yan, Zheng570df4e2017-11-15 17:39:40 +0800177 if (inode->i_nlink == 0) {
178 iput(inode);
179 return ERR_PTR(-ESTALE);
180 }
Al Viroad5cb122016-10-28 22:05:13 -0400181 return d_obtain_alias(inode);
Sage Weila8e63b72009-10-06 11:31:13 -0700182}
183
Yan, Zheng570df4e2017-11-15 17:39:40 +0800184static struct dentry *__snapfh_to_dentry(struct super_block *sb,
185 struct ceph_nfs_snapfh *sfh,
186 bool want_parent)
187{
188 struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc;
189 struct ceph_mds_request *req;
190 struct inode *inode;
191 struct ceph_vino vino;
192 int mask;
193 int err;
194 bool unlinked = false;
195
196 if (want_parent) {
197 vino.ino = sfh->parent_ino;
198 if (sfh->snapid == CEPH_SNAPDIR)
199 vino.snap = CEPH_NOSNAP;
200 else if (sfh->ino == sfh->parent_ino)
201 vino.snap = CEPH_SNAPDIR;
202 else
203 vino.snap = sfh->snapid;
204 } else {
205 vino.ino = sfh->ino;
206 vino.snap = sfh->snapid;
207 }
208 inode = ceph_find_inode(sb, vino);
209 if (inode)
210 return d_obtain_alias(inode);
211
212 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPINO,
213 USE_ANY_MDS);
214 if (IS_ERR(req))
215 return ERR_CAST(req);
216
217 mask = CEPH_STAT_CAP_INODE;
218 if (ceph_security_xattr_wanted(d_inode(sb->s_root)))
219 mask |= CEPH_CAP_XATTR_SHARED;
220 req->r_args.lookupino.mask = cpu_to_le32(mask);
221 if (vino.snap < CEPH_NOSNAP) {
222 req->r_args.lookupino.snapid = cpu_to_le64(vino.snap);
223 if (!want_parent && sfh->ino != sfh->parent_ino) {
224 req->r_args.lookupino.parent =
225 cpu_to_le64(sfh->parent_ino);
226 req->r_args.lookupino.hash =
227 cpu_to_le32(sfh->hash);
228 }
229 }
230
231 req->r_ino1 = vino;
232 req->r_num_caps = 1;
233 err = ceph_mdsc_do_request(mdsc, NULL, req);
234 inode = req->r_target_inode;
235 if (inode) {
236 if (vino.snap == CEPH_SNAPDIR) {
237 if (inode->i_nlink == 0)
238 unlinked = true;
239 inode = ceph_get_snapdir(inode);
240 } else if (ceph_snap(inode) == vino.snap) {
241 ihold(inode);
242 } else {
243 /* mds does not support lookup snapped inode */
244 err = -EOPNOTSUPP;
245 inode = NULL;
246 }
247 }
248 ceph_mdsc_put_request(req);
249
250 if (want_parent) {
251 dout("snapfh_to_parent %llx.%llx\n err=%d\n",
252 vino.ino, vino.snap, err);
253 } else {
254 dout("snapfh_to_dentry %llx.%llx parent %llx hash %x err=%d",
255 vino.ino, vino.snap, sfh->parent_ino, sfh->hash, err);
256 }
257 if (!inode)
258 return ERR_PTR(-ESTALE);
259 /* see comments in ceph_get_parent() */
260 return unlinked ? d_obtain_root(inode) : d_obtain_alias(inode);
261}
262
Sage Weila8e63b72009-10-06 11:31:13 -0700263/*
Yan, Zheng4f32b422014-03-01 18:05:41 +0800264 * convert regular fh to dentry
Sage Weila8e63b72009-10-06 11:31:13 -0700265 */
Yan, Zheng4f32b422014-03-01 18:05:41 +0800266static struct dentry *ceph_fh_to_dentry(struct super_block *sb,
267 struct fid *fid,
Sage Weila8e63b72009-10-06 11:31:13 -0700268 int fh_len, int fh_type)
269{
Yan, Zheng4f32b422014-03-01 18:05:41 +0800270 struct ceph_nfs_fh *fh = (void *)fid->raw;
271
Yan, Zheng570df4e2017-11-15 17:39:40 +0800272 if (fh_type == FILEID_BTRFS_WITH_PARENT) {
273 struct ceph_nfs_snapfh *sfh = (void *)fid->raw;
274 return __snapfh_to_dentry(sb, sfh, false);
275 }
276
Yan, Zheng4f32b422014-03-01 18:05:41 +0800277 if (fh_type != FILEID_INO32_GEN &&
278 fh_type != FILEID_INO32_GEN_PARENT)
279 return NULL;
280 if (fh_len < sizeof(*fh) / 4)
281 return NULL;
282
283 dout("fh_to_dentry %llx\n", fh->ino);
284 return __fh_to_dentry(sb, fh->ino);
Sage Weila8e63b72009-10-06 11:31:13 -0700285}
286
Yan, Zheng9017c2e2014-03-01 22:11:45 +0800287static struct dentry *__get_parent(struct super_block *sb,
288 struct dentry *child, u64 ino)
289{
290 struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc;
291 struct ceph_mds_request *req;
292 struct inode *inode;
Yan, Zheng315f2402016-03-07 10:34:50 +0800293 int mask;
Yan, Zheng9017c2e2014-03-01 22:11:45 +0800294 int err;
295
296 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPPARENT,
297 USE_ANY_MDS);
298 if (IS_ERR(req))
299 return ERR_CAST(req);
300
301 if (child) {
David Howells2b0143b2015-03-17 22:25:59 +0000302 req->r_inode = d_inode(child);
303 ihold(d_inode(child));
Yan, Zheng9017c2e2014-03-01 22:11:45 +0800304 } else {
305 req->r_ino1 = (struct ceph_vino) {
306 .ino = ino,
307 .snap = CEPH_NOSNAP,
308 };
309 }
Yan, Zheng315f2402016-03-07 10:34:50 +0800310
311 mask = CEPH_STAT_CAP_INODE;
312 if (ceph_security_xattr_wanted(d_inode(sb->s_root)))
313 mask |= CEPH_CAP_XATTR_SHARED;
314 req->r_args.getattr.mask = cpu_to_le32(mask);
315
Yan, Zheng9017c2e2014-03-01 22:11:45 +0800316 req->r_num_caps = 1;
317 err = ceph_mdsc_do_request(mdsc, NULL, req);
318 inode = req->r_target_inode;
319 if (inode)
320 ihold(inode);
321 ceph_mdsc_put_request(req);
322 if (!inode)
323 return ERR_PTR(-ENOENT);
324
Al Viroad5cb122016-10-28 22:05:13 -0400325 return d_obtain_alias(inode);
Yan, Zheng9017c2e2014-03-01 22:11:45 +0800326}
327
Fengguang Wue84be112014-04-09 14:11:31 +0800328static struct dentry *ceph_get_parent(struct dentry *child)
Yan, Zheng9017c2e2014-03-01 22:11:45 +0800329{
Yan, Zheng570df4e2017-11-15 17:39:40 +0800330 struct inode *inode = d_inode(child);
331 struct dentry *dn;
Yan, Zheng9017c2e2014-03-01 22:11:45 +0800332
Yan, Zheng570df4e2017-11-15 17:39:40 +0800333 if (ceph_snap(inode) != CEPH_NOSNAP) {
334 struct inode* dir;
335 bool unlinked = false;
336 /* do not support non-directory */
337 if (!d_is_dir(child)) {
338 dn = ERR_PTR(-EINVAL);
339 goto out;
340 }
341 dir = __lookup_inode(inode->i_sb, ceph_ino(inode));
342 if (IS_ERR(dir)) {
343 dn = ERR_CAST(dir);
344 goto out;
345 }
346 /* There can be multiple paths to access snapped inode.
347 * For simplicity, treat snapdir of head inode as parent */
348 if (ceph_snap(inode) != CEPH_SNAPDIR) {
349 struct inode *snapdir = ceph_get_snapdir(dir);
350 if (dir->i_nlink == 0)
351 unlinked = true;
352 iput(dir);
353 if (IS_ERR(snapdir)) {
354 dn = ERR_CAST(snapdir);
355 goto out;
356 }
357 dir = snapdir;
358 }
359 /* If directory has already been deleted, futher get_parent
360 * will fail. Do not mark snapdir dentry as disconnected,
361 * this prevent exportfs from doing futher get_parent. */
362 if (unlinked)
363 dn = d_obtain_root(dir);
364 else
365 dn = d_obtain_alias(dir);
366 } else {
367 dn = __get_parent(child->d_sb, child, 0);
368 }
369out:
370 dout("get_parent %p ino %llx.%llx err=%ld\n",
Hariprasad Kelam03af4392019-05-25 14:45:59 +0530371 child, ceph_vinop(inode), (long)PTR_ERR_OR_ZERO(dn));
Yan, Zheng570df4e2017-11-15 17:39:40 +0800372 return dn;
Yan, Zheng9017c2e2014-03-01 22:11:45 +0800373}
374
Sage Weila8e63b72009-10-06 11:31:13 -0700375/*
Yan, Zheng8996f4f2014-03-01 23:09:05 +0800376 * convert regular fh to parent
Sage Weila8e63b72009-10-06 11:31:13 -0700377 */
378static struct dentry *ceph_fh_to_parent(struct super_block *sb,
Yan, Zheng8996f4f2014-03-01 23:09:05 +0800379 struct fid *fid,
Sage Weila8e63b72009-10-06 11:31:13 -0700380 int fh_len, int fh_type)
381{
382 struct ceph_nfs_confh *cfh = (void *)fid->raw;
Sage Weila8e63b72009-10-06 11:31:13 -0700383 struct dentry *dentry;
Sage Weila8e63b72009-10-06 11:31:13 -0700384
Yan, Zheng570df4e2017-11-15 17:39:40 +0800385 if (fh_type == FILEID_BTRFS_WITH_PARENT) {
386 struct ceph_nfs_snapfh *sfh = (void *)fid->raw;
387 return __snapfh_to_dentry(sb, sfh, true);
388 }
389
Yan, Zheng8996f4f2014-03-01 23:09:05 +0800390 if (fh_type != FILEID_INO32_GEN_PARENT)
391 return NULL;
Hugh Dickins35c2a7f2012-10-07 20:32:51 -0700392 if (fh_len < sizeof(*cfh) / 4)
Yan, Zheng8996f4f2014-03-01 23:09:05 +0800393 return NULL;
Sage Weila8e63b72009-10-06 11:31:13 -0700394
Yan, Zheng8996f4f2014-03-01 23:09:05 +0800395 dout("fh_to_parent %llx\n", cfh->parent_ino);
396 dentry = __get_parent(sb, NULL, cfh->ino);
Al Virob42b90d2016-06-24 23:49:03 -0400397 if (unlikely(dentry == ERR_PTR(-ENOENT)))
Yan, Zheng8996f4f2014-03-01 23:09:05 +0800398 dentry = __fh_to_dentry(sb, cfh->parent_ino);
Sage Weila8e63b72009-10-06 11:31:13 -0700399 return dentry;
400}
401
Yan, Zheng570df4e2017-11-15 17:39:40 +0800402static int __get_snap_name(struct dentry *parent, char *name,
403 struct dentry *child)
404{
405 struct inode *inode = d_inode(child);
406 struct inode *dir = d_inode(parent);
407 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
408 struct ceph_mds_request *req = NULL;
409 char *last_name = NULL;
410 unsigned next_offset = 2;
411 int err = -EINVAL;
412
413 if (ceph_ino(inode) != ceph_ino(dir))
414 goto out;
415 if (ceph_snap(inode) == CEPH_SNAPDIR) {
416 if (ceph_snap(dir) == CEPH_NOSNAP) {
417 strcpy(name, fsc->mount_options->snapdir_name);
418 err = 0;
419 }
420 goto out;
421 }
422 if (ceph_snap(dir) != CEPH_SNAPDIR)
423 goto out;
424
425 while (1) {
426 struct ceph_mds_reply_info_parsed *rinfo;
427 struct ceph_mds_reply_dir_entry *rde;
428 int i;
429
430 req = ceph_mdsc_create_request(fsc->mdsc, CEPH_MDS_OP_LSSNAP,
431 USE_AUTH_MDS);
432 if (IS_ERR(req)) {
433 err = PTR_ERR(req);
434 req = NULL;
435 goto out;
436 }
437 err = ceph_alloc_readdir_reply_buffer(req, inode);
438 if (err)
439 goto out;
440
441 req->r_direct_mode = USE_AUTH_MDS;
442 req->r_readdir_offset = next_offset;
443 req->r_args.readdir.flags =
444 cpu_to_le16(CEPH_READDIR_REPLY_BITFLAGS);
445 if (last_name) {
446 req->r_path2 = last_name;
447 last_name = NULL;
448 }
449
450 req->r_inode = dir;
451 ihold(dir);
452 req->r_dentry = dget(parent);
453
454 inode_lock(dir);
455 err = ceph_mdsc_do_request(fsc->mdsc, NULL, req);
456 inode_unlock(dir);
457
458 if (err < 0)
459 goto out;
460
461 rinfo = &req->r_reply_info;
462 for (i = 0; i < rinfo->dir_nr; i++) {
463 rde = rinfo->dir_entries + i;
464 BUG_ON(!rde->inode.in);
465 if (ceph_snap(inode) ==
466 le64_to_cpu(rde->inode.in->snapid)) {
467 memcpy(name, rde->name, rde->name_len);
468 name[rde->name_len] = '\0';
469 err = 0;
470 goto out;
471 }
472 }
473
474 if (rinfo->dir_end)
475 break;
476
477 BUG_ON(rinfo->dir_nr <= 0);
478 rde = rinfo->dir_entries + (rinfo->dir_nr - 1);
479 next_offset += rinfo->dir_nr;
480 last_name = kstrndup(rde->name, rde->name_len, GFP_KERNEL);
481 if (!last_name) {
482 err = -ENOMEM;
483 goto out;
484 }
485
486 ceph_mdsc_put_request(req);
487 req = NULL;
488 }
489 err = -ENOENT;
490out:
491 if (req)
492 ceph_mdsc_put_request(req);
493 kfree(last_name);
494 dout("get_snap_name %p ino %llx.%llx err=%d\n",
495 child, ceph_vinop(inode), err);
496 return err;
497}
498
Yan, Zheng19913b42014-03-06 16:40:32 +0800499static int ceph_get_name(struct dentry *parent, char *name,
500 struct dentry *child)
501{
502 struct ceph_mds_client *mdsc;
503 struct ceph_mds_request *req;
Yan, Zheng570df4e2017-11-15 17:39:40 +0800504 struct inode *inode = d_inode(child);
Yan, Zheng19913b42014-03-06 16:40:32 +0800505 int err;
506
Yan, Zheng570df4e2017-11-15 17:39:40 +0800507 if (ceph_snap(inode) != CEPH_NOSNAP)
508 return __get_snap_name(parent, name, child);
509
510 mdsc = ceph_inode_to_client(inode)->mdsc;
Yan, Zheng19913b42014-03-06 16:40:32 +0800511 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPNAME,
512 USE_ANY_MDS);
513 if (IS_ERR(req))
514 return PTR_ERR(req);
515
Al Viro59551022016-01-22 15:40:57 -0500516 inode_lock(d_inode(parent));
Yan, Zheng19913b42014-03-06 16:40:32 +0800517
Yan, Zheng570df4e2017-11-15 17:39:40 +0800518 req->r_inode = inode;
519 ihold(inode);
David Howells2b0143b2015-03-17 22:25:59 +0000520 req->r_ino2 = ceph_vino(d_inode(parent));
Jeff Layton3dd69aa2017-01-31 10:28:26 -0500521 req->r_parent = d_inode(parent);
522 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
Yan, Zheng19913b42014-03-06 16:40:32 +0800523 req->r_num_caps = 2;
524 err = ceph_mdsc_do_request(mdsc, NULL, req);
525
Al Viro59551022016-01-22 15:40:57 -0500526 inode_unlock(d_inode(parent));
Yan, Zheng19913b42014-03-06 16:40:32 +0800527
528 if (!err) {
529 struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info;
530 memcpy(name, rinfo->dname, rinfo->dname_len);
531 name[rinfo->dname_len] = 0;
532 dout("get_name %p ino %llx.%llx name %s\n",
Yan, Zheng570df4e2017-11-15 17:39:40 +0800533 child, ceph_vinop(inode), name);
Yan, Zheng19913b42014-03-06 16:40:32 +0800534 } else {
535 dout("get_name %p ino %llx.%llx err %d\n",
Yan, Zheng570df4e2017-11-15 17:39:40 +0800536 child, ceph_vinop(inode), err);
Yan, Zheng19913b42014-03-06 16:40:32 +0800537 }
538
539 ceph_mdsc_put_request(req);
540 return err;
541}
542
Sage Weila8e63b72009-10-06 11:31:13 -0700543const struct export_operations ceph_export_ops = {
544 .encode_fh = ceph_encode_fh,
Sage Weila8e63b72009-10-06 11:31:13 -0700545 .fh_to_dentry = ceph_fh_to_dentry,
546 .fh_to_parent = ceph_fh_to_parent,
Yan, Zheng9017c2e2014-03-01 22:11:45 +0800547 .get_parent = ceph_get_parent,
Yan, Zheng19913b42014-03-06 16:40:32 +0800548 .get_name = ceph_get_name,
Sage Weila8e63b72009-10-06 11:31:13 -0700549};