From: Xiubo Li <xiubli@xxxxxxxxxx> Get the parent inode for the snap directory ".snap", if the inode is not a snap directory just return it with the reference increased. Signed-off-by: Xiubo Li <xiubli@xxxxxxxxxx> --- fs/ceph/snap.c | 24 ++++++++++++++++++++++++ fs/ceph/super.h | 1 + 2 files changed, 25 insertions(+) diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c index 322ee5add942..b62c1ace2ee9 100644 --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -1268,3 +1268,27 @@ void ceph_cleanup_snapid_map(struct ceph_mds_client *mdsc) kfree(sm); } } + +/* + * Get the parent inode for the snap directory ".snap", + * if the inode is not a snap directory just return it + * with the reference increased. + */ +struct inode *ceph_get_snap_parent_inode(struct inode *inode) +{ + struct inode *pinode; + + if (ceph_snap(inode) == CEPH_SNAPDIR) { + struct ceph_vino vino = { + .ino = ceph_ino(inode), + .snap = CEPH_NOSNAP, + }; + pinode = ceph_find_inode(inode->i_sb, vino); + BUG_ON(!pinode); + } else { + ihold(inode); + pinode = inode; + } + + return pinode; +} diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 6d41a69f5d86..f0268a571621 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -969,6 +969,7 @@ extern void ceph_put_snapid_map(struct ceph_mds_client* mdsc, struct ceph_snapid_map *sm); extern void ceph_trim_snapid_map(struct ceph_mds_client *mdsc); extern void ceph_cleanup_snapid_map(struct ceph_mds_client *mdsc); +extern struct inode *ceph_get_snap_parent_inode(struct inode *inode); void ceph_umount_begin(struct super_block *sb); -- 2.27.0