^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/ceph/ceph_debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/exportfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "super.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "mds_client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Basic fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct ceph_nfs_fh {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) u64 ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Larger fh that includes parent ino.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct ceph_nfs_confh {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) u64 ino, parent_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * fh for snapped inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct ceph_nfs_snapfh {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) u64 ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u64 snapid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u64 parent_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u32 hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int ceph_encode_snapfh(struct inode *inode, u32 *rawfh, int *max_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct inode *parent_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static const int snap_handle_length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) sizeof(struct ceph_nfs_snapfh) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct ceph_nfs_snapfh *sfh = (void *)rawfh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u64 snapid = ceph_snap(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) bool no_parent = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (*max_len < snap_handle_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *max_len = snap_handle_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ret = FILEID_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (snapid != CEPH_SNAPDIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct inode *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct dentry *dentry = d_find_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) dir = d_inode_rcu(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (ceph_snap(dir) != CEPH_SNAPDIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) sfh->parent_ino = ceph_ino(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) sfh->hash = ceph_dentry_hash(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) no_parent = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (no_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) sfh->parent_ino = sfh->ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) sfh->hash = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) sfh->ino = ceph_ino(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) sfh->snapid = snapid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) *max_len = snap_handle_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ret = FILEID_BTRFS_WITH_PARENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) dout("encode_snapfh %llx.%llx ret=%d\n", ceph_vinop(inode), ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static int ceph_encode_fh(struct inode *inode, u32 *rawfh, int *max_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct inode *parent_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static const int handle_length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) sizeof(struct ceph_nfs_fh) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static const int connected_handle_length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) sizeof(struct ceph_nfs_confh) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (ceph_snap(inode) != CEPH_NOSNAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return ceph_encode_snapfh(inode, rawfh, max_len, parent_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (parent_inode && (*max_len < connected_handle_length)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) *max_len = connected_handle_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return FILEID_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) } else if (*max_len < handle_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *max_len = handle_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return FILEID_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (parent_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct ceph_nfs_confh *cfh = (void *)rawfh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) dout("encode_fh %llx with parent %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ceph_ino(inode), ceph_ino(parent_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) cfh->ino = ceph_ino(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) cfh->parent_ino = ceph_ino(parent_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) *max_len = connected_handle_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) type = FILEID_INO32_GEN_PARENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct ceph_nfs_fh *fh = (void *)rawfh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) dout("encode_fh %llx\n", ceph_ino(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) fh->ino = ceph_ino(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *max_len = handle_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) type = FILEID_INO32_GEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static struct inode *__lookup_inode(struct super_block *sb, u64 ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct ceph_vino vino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) vino.ino = ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) vino.snap = CEPH_NOSNAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (ceph_vino_is_reserved(vino))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) inode = ceph_find_inode(sb, vino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct ceph_mds_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPINO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) USE_ANY_MDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (IS_ERR(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return ERR_CAST(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) mask = CEPH_STAT_CAP_INODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (ceph_security_xattr_wanted(d_inode(sb->s_root)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) mask |= CEPH_CAP_XATTR_SHARED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) req->r_args.lookupino.mask = cpu_to_le32(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) req->r_ino1 = vino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) req->r_num_caps = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) err = ceph_mdsc_do_request(mdsc, NULL, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) inode = req->r_target_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ihold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ceph_mdsc_put_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return err < 0 ? ERR_PTR(err) : ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct inode *ceph_lookup_inode(struct super_block *sb, u64 ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct inode *inode = __lookup_inode(sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (inode->i_nlink == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct inode *inode = __lookup_inode(sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return ERR_CAST(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* We need LINK caps to reliably check i_nlink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) err = ceph_do_getattr(inode, CEPH_CAP_LINK_SHARED, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* -ESTALE if inode as been unlinked and no file is open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if ((inode->i_nlink == 0) && (atomic_read(&inode->i_count) == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return d_obtain_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static struct dentry *__snapfh_to_dentry(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct ceph_nfs_snapfh *sfh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) bool want_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct ceph_mds_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct ceph_vino vino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) bool unlinked = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (want_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) vino.ino = sfh->parent_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (sfh->snapid == CEPH_SNAPDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) vino.snap = CEPH_NOSNAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) else if (sfh->ino == sfh->parent_ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) vino.snap = CEPH_SNAPDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) vino.snap = sfh->snapid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) vino.ino = sfh->ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) vino.snap = sfh->snapid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (ceph_vino_is_reserved(vino))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) inode = ceph_find_inode(sb, vino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return d_obtain_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPINO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) USE_ANY_MDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (IS_ERR(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return ERR_CAST(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) mask = CEPH_STAT_CAP_INODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (ceph_security_xattr_wanted(d_inode(sb->s_root)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) mask |= CEPH_CAP_XATTR_SHARED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) req->r_args.lookupino.mask = cpu_to_le32(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (vino.snap < CEPH_NOSNAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) req->r_args.lookupino.snapid = cpu_to_le64(vino.snap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (!want_parent && sfh->ino != sfh->parent_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) req->r_args.lookupino.parent =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) cpu_to_le64(sfh->parent_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) req->r_args.lookupino.hash =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) cpu_to_le32(sfh->hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) req->r_ino1 = vino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) req->r_num_caps = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) err = ceph_mdsc_do_request(mdsc, NULL, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) inode = req->r_target_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (vino.snap == CEPH_SNAPDIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (inode->i_nlink == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) unlinked = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) inode = ceph_get_snapdir(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) } else if (ceph_snap(inode) == vino.snap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ihold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* mds does not support lookup snapped inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ceph_mdsc_put_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (want_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) dout("snapfh_to_parent %llx.%llx\n err=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) vino.ino, vino.snap, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) dout("snapfh_to_dentry %llx.%llx parent %llx hash %x err=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) vino.ino, vino.snap, sfh->parent_ino, sfh->hash, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* see comments in ceph_get_parent() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return unlinked ? d_obtain_root(inode) : d_obtain_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * convert regular fh to dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static struct dentry *ceph_fh_to_dentry(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct ceph_nfs_fh *fh = (void *)fid->raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (fh_type == FILEID_BTRFS_WITH_PARENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct ceph_nfs_snapfh *sfh = (void *)fid->raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return __snapfh_to_dentry(sb, sfh, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (fh_type != FILEID_INO32_GEN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) fh_type != FILEID_INO32_GEN_PARENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (fh_len < sizeof(*fh) / 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) dout("fh_to_dentry %llx\n", fh->ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return __fh_to_dentry(sb, fh->ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static struct dentry *__get_parent(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct dentry *child, u64 ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct ceph_mds_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPPARENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) USE_ANY_MDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (IS_ERR(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return ERR_CAST(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) req->r_inode = d_inode(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ihold(d_inode(child));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) req->r_ino1 = (struct ceph_vino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .ino = ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .snap = CEPH_NOSNAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) mask = CEPH_STAT_CAP_INODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (ceph_security_xattr_wanted(d_inode(sb->s_root)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) mask |= CEPH_CAP_XATTR_SHARED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) req->r_args.getattr.mask = cpu_to_le32(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) req->r_num_caps = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) err = ceph_mdsc_do_request(mdsc, NULL, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) ceph_mdsc_put_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) inode = req->r_target_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) ihold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ceph_mdsc_put_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return d_obtain_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static struct dentry *ceph_get_parent(struct dentry *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct inode *inode = d_inode(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) struct dentry *dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (ceph_snap(inode) != CEPH_NOSNAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct inode* dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) bool unlinked = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* do not support non-directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (!d_is_dir(child)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) dn = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) dir = __lookup_inode(inode->i_sb, ceph_ino(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (IS_ERR(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) dn = ERR_CAST(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /* There can be multiple paths to access snapped inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * For simplicity, treat snapdir of head inode as parent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (ceph_snap(inode) != CEPH_SNAPDIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct inode *snapdir = ceph_get_snapdir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (dir->i_nlink == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) unlinked = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) iput(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (IS_ERR(snapdir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) dn = ERR_CAST(snapdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) dir = snapdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /* If directory has already been deleted, futher get_parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * will fail. Do not mark snapdir dentry as disconnected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * this prevent exportfs from doing futher get_parent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (unlinked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) dn = d_obtain_root(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) dn = d_obtain_alias(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) dn = __get_parent(child->d_sb, child, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) dout("get_parent %p ino %llx.%llx err=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) child, ceph_vinop(inode), (long)PTR_ERR_OR_ZERO(dn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * convert regular fh to parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static struct dentry *ceph_fh_to_parent(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct ceph_nfs_confh *cfh = (void *)fid->raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (fh_type == FILEID_BTRFS_WITH_PARENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct ceph_nfs_snapfh *sfh = (void *)fid->raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return __snapfh_to_dentry(sb, sfh, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (fh_type != FILEID_INO32_GEN_PARENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (fh_len < sizeof(*cfh) / 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) dout("fh_to_parent %llx\n", cfh->parent_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) dentry = __get_parent(sb, NULL, cfh->ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (unlikely(dentry == ERR_PTR(-ENOENT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) dentry = __fh_to_dentry(sb, cfh->parent_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static int __get_snap_name(struct dentry *parent, char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct dentry *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct inode *inode = d_inode(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct inode *dir = d_inode(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) struct ceph_mds_request *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) char *last_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) unsigned next_offset = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (ceph_ino(inode) != ceph_ino(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (ceph_snap(inode) == CEPH_SNAPDIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (ceph_snap(dir) == CEPH_NOSNAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) strcpy(name, fsc->mount_options->snapdir_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (ceph_snap(dir) != CEPH_SNAPDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct ceph_mds_reply_info_parsed *rinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct ceph_mds_reply_dir_entry *rde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) req = ceph_mdsc_create_request(fsc->mdsc, CEPH_MDS_OP_LSSNAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) USE_AUTH_MDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (IS_ERR(req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) err = PTR_ERR(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) err = ceph_alloc_readdir_reply_buffer(req, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) req->r_direct_mode = USE_AUTH_MDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) req->r_readdir_offset = next_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) req->r_args.readdir.flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) cpu_to_le16(CEPH_READDIR_REPLY_BITFLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (last_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) req->r_path2 = last_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) last_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) req->r_inode = dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) ihold(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) req->r_dentry = dget(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) inode_lock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) err = ceph_mdsc_do_request(fsc->mdsc, NULL, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) inode_unlock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) rinfo = &req->r_reply_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) for (i = 0; i < rinfo->dir_nr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) rde = rinfo->dir_entries + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) BUG_ON(!rde->inode.in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (ceph_snap(inode) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) le64_to_cpu(rde->inode.in->snapid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) memcpy(name, rde->name, rde->name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) name[rde->name_len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (rinfo->dir_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) BUG_ON(rinfo->dir_nr <= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) rde = rinfo->dir_entries + (rinfo->dir_nr - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) next_offset += rinfo->dir_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) last_name = kstrndup(rde->name, rde->name_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (!last_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) ceph_mdsc_put_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) ceph_mdsc_put_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) kfree(last_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) dout("get_snap_name %p ino %llx.%llx err=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) child, ceph_vinop(inode), err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static int ceph_get_name(struct dentry *parent, char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct dentry *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct ceph_mds_client *mdsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct ceph_mds_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct inode *inode = d_inode(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (ceph_snap(inode) != CEPH_NOSNAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return __get_snap_name(parent, name, child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) mdsc = ceph_inode_to_client(inode)->mdsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) USE_ANY_MDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (IS_ERR(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return PTR_ERR(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) inode_lock(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) req->r_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) ihold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) req->r_ino2 = ceph_vino(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) req->r_parent = d_inode(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) req->r_num_caps = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) err = ceph_mdsc_do_request(mdsc, NULL, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) inode_unlock(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) memcpy(name, rinfo->dname, rinfo->dname_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) name[rinfo->dname_len] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) dout("get_name %p ino %llx.%llx name %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) child, ceph_vinop(inode), name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) dout("get_name %p ino %llx.%llx err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) child, ceph_vinop(inode), err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) ceph_mdsc_put_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) const struct export_operations ceph_export_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) .encode_fh = ceph_encode_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) .fh_to_dentry = ceph_fh_to_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) .fh_to_parent = ceph_fh_to_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) .get_parent = ceph_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) .get_name = ceph_get_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) };