Skip to content

Commit 9017c2e

Browse files
author
Yan, Zheng
committed
ceph: add get_parent() NFS export callback
The callback uses LOOKUPPARENT MDS request to find parent. Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com> Reviewed-by: Sage Weil <sage@inktank.com>
1 parent 4f32b42 commit 9017c2e

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

‎fs/ceph/export.c‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,65 @@ static struct dentry *ceph_fh_to_dentry(struct super_block *sb,
121121
return __fh_to_dentry(sb, fh->ino);
122122
}
123123

124+
static struct dentry *__get_parent(struct super_block *sb,
125+
struct dentry *child, u64 ino)
126+
{
127+
struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc;
128+
struct ceph_mds_request *req;
129+
struct inode *inode;
130+
struct dentry *dentry;
131+
int err;
132+
133+
req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPPARENT,
134+
USE_ANY_MDS);
135+
if (IS_ERR(req))
136+
return ERR_CAST(req);
137+
138+
if (child) {
139+
req->r_inode = child->d_inode;
140+
ihold(child->d_inode);
141+
} else {
142+
req->r_ino1 = (struct ceph_vino) {
143+
.ino = ino,
144+
.snap = CEPH_NOSNAP,
145+
};
146+
}
147+
req->r_num_caps = 1;
148+
err = ceph_mdsc_do_request(mdsc, NULL, req);
149+
inode = req->r_target_inode;
150+
if (inode)
151+
ihold(inode);
152+
ceph_mdsc_put_request(req);
153+
if (!inode)
154+
return ERR_PTR(-ENOENT);
155+
156+
dentry = d_obtain_alias(inode);
157+
if (IS_ERR(dentry)) {
158+
iput(inode);
159+
return dentry;
160+
}
161+
err = ceph_init_dentry(dentry);
162+
if (err < 0) {
163+
dput(dentry);
164+
return ERR_PTR(err);
165+
}
166+
dout("__get_parent ino %llx parent %p ino %llx.%llx\n",
167+
child ? ceph_ino(child->d_inode) : ino,
168+
dentry, ceph_vinop(inode));
169+
return dentry;
170+
}
171+
172+
struct dentry *ceph_get_parent(struct dentry *child)
173+
{
174+
/* don't re-export snaps */
175+
if (ceph_snap(child->d_inode) != CEPH_NOSNAP)
176+
return ERR_PTR(-EINVAL);
177+
178+
dout("get_parent %p ino %llx.%llx\n",
179+
child, ceph_vinop(child->d_inode));
180+
return __get_parent(child->d_sb, child, 0);
181+
}
182+
124183
/*
125184
* get parent, if possible.
126185
*
@@ -171,4 +230,5 @@ const struct export_operations ceph_export_ops = {
171230
.encode_fh = ceph_encode_fh,
172231
.fh_to_dentry = ceph_fh_to_dentry,
173232
.fh_to_parent = ceph_fh_to_parent,
233+
.get_parent = ceph_get_parent,
174234
};

0 commit comments

Comments
 (0)