Blame view
fs/ceph/export.c
6.16 KB
3d14c5d2b ceph: factor out ... |
1 |
#include <linux/ceph/ceph_debug.h> |
a8e63b7d5 ceph: nfs re-expo... |
2 3 |
#include <linux/exportfs.h> |
5a0e3ad6a include cleanup: ... |
4 |
#include <linux/slab.h> |
a8e63b7d5 ceph: nfs re-expo... |
5 6 7 |
#include <asm/unaligned.h> #include "super.h" |
3d14c5d2b ceph: factor out ... |
8 |
#include "mds_client.h" |
a8e63b7d5 ceph: nfs re-expo... |
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
/* * NFS export support * * NFS re-export of a ceph mount is, at present, only semireliable. * The basic issue is that the Ceph architectures doesn't lend itself * well to generating filehandles that will remain valid forever. * * So, we do our best. If you're lucky, your inode will be in the * client's cache. If it's not, and you have a connectable fh, then * the MDS server may be able to find it for you. Otherwise, you get * ESTALE. * * There are ways to this more reliable, but in the non-connectable fh * case, we won't every work perfectly, and in the connectable case, * some changes are needed on the MDS side to work better. */ /* * Basic fh */ struct ceph_nfs_fh { u64 ino; } __attribute__ ((packed)); /* * Larger 'connectable' fh that includes parent ino and name hash. * Use this whenever possible, as it works more reliably. */ struct ceph_nfs_confh { u64 ino, parent_ino; u32 parent_name_hash; } __attribute__ ((packed)); static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len, int connectable) { |
92923dcbf ceph: Fix return ... |
46 |
int type; |
a8e63b7d5 ceph: nfs re-expo... |
47 48 |
struct ceph_nfs_fh *fh = (void *)rawfh; struct ceph_nfs_confh *cfh = (void *)rawfh; |
e5f86dc37 ceph: avoid d_par... |
49 |
struct dentry *parent; |
a8e63b7d5 ceph: nfs re-expo... |
50 |
struct inode *inode = dentry->d_inode; |
92923dcbf ceph: Fix return ... |
51 52 |
int connected_handle_length = sizeof(*cfh)/4; int handle_length = sizeof(*fh)/4; |
a8e63b7d5 ceph: nfs re-expo... |
53 54 55 56 |
/* don't re-export snaps */ if (ceph_snap(inode) != CEPH_NOSNAP) return -EINVAL; |
e5f86dc37 ceph: avoid d_par... |
57 |
spin_lock(&dentry->d_lock); |
ee6b1baf6 ceph: avoid usele... |
58 |
parent = dentry->d_parent; |
92923dcbf ceph: Fix return ... |
59 |
if (*max_len >= connected_handle_length) { |
a8e63b7d5 ceph: nfs re-expo... |
60 61 62 63 |
dout("encode_fh %p connectable ", dentry); cfh->ino = ceph_ino(dentry->d_inode); cfh->parent_ino = ceph_ino(parent->d_inode); |
e5f86dc37 ceph: avoid d_par... |
64 65 |
cfh->parent_name_hash = ceph_dentry_hash(parent->d_inode, dentry); |
92923dcbf ceph: Fix return ... |
66 |
*max_len = connected_handle_length; |
a8e63b7d5 ceph: nfs re-expo... |
67 |
type = 2; |
92923dcbf ceph: Fix return ... |
68 |
} else if (*max_len >= handle_length) { |
bba0cd0e3 ceph: Update max_... |
69 70 |
if (connectable) { *max_len = connected_handle_length; |
e5f86dc37 ceph: avoid d_par... |
71 72 73 74 75 76 77 |
type = 255; } else { dout("encode_fh %p ", dentry); fh->ino = ceph_ino(dentry->d_inode); *max_len = handle_length; type = 1; |
bba0cd0e3 ceph: Update max_... |
78 |
} |
a8e63b7d5 ceph: nfs re-expo... |
79 |
} else { |
bba0cd0e3 ceph: Update max_... |
80 |
*max_len = handle_length; |
e5f86dc37 ceph: avoid d_par... |
81 |
type = 255; |
a8e63b7d5 ceph: nfs re-expo... |
82 |
} |
ee6b1baf6 ceph: avoid usele... |
83 |
spin_unlock(&dentry->d_lock); |
a8e63b7d5 ceph: nfs re-expo... |
84 85 86 87 88 89 90 91 92 93 94 |
return type; } /* * convert regular fh to dentry * * FIXME: we should try harder by querying the mds for the ino. */ static struct dentry *__fh_to_dentry(struct super_block *sb, struct ceph_nfs_fh *fh) { |
3c454cf21 ceph: use LOOKUPI... |
95 |
struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc; |
a8e63b7d5 ceph: nfs re-expo... |
96 97 98 99 100 101 102 103 104 105 |
struct inode *inode; struct dentry *dentry; struct ceph_vino vino; int err; dout("__fh_to_dentry %llx ", fh->ino); vino.ino = fh->ino; vino.snap = CEPH_NOSNAP; inode = ceph_find_inode(sb, vino); |
3c454cf21 ceph: use LOOKUPI... |
106 107 108 109 110 111 112 113 114 115 116 |
if (!inode) { struct ceph_mds_request *req; req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPINO, USE_ANY_MDS); if (IS_ERR(req)) return ERR_CAST(req); req->r_ino1 = vino; req->r_num_caps = 1; err = ceph_mdsc_do_request(mdsc, NULL, req); |
45e3d3eeb ceph: avoid inode... |
117 118 |
inode = req->r_target_inode; if (inode) |
70b666c3b ceph: use ihold w... |
119 |
ihold(inode); |
3c454cf21 ceph: use LOOKUPI... |
120 |
ceph_mdsc_put_request(req); |
3c454cf21 ceph: use LOOKUPI... |
121 122 123 |
if (!inode) return ERR_PTR(-ESTALE); } |
a8e63b7d5 ceph: nfs re-expo... |
124 125 |
dentry = d_obtain_alias(inode); |
0d509c949 ceph: d_obtain_al... |
126 |
if (IS_ERR(dentry)) { |
a8e63b7d5 ceph: nfs re-expo... |
127 128 129 130 |
pr_err("fh_to_dentry %llx -- inode %p but ENOMEM ", fh->ino, inode); iput(inode); |
0d509c949 ceph: d_obtain_al... |
131 |
return dentry; |
a8e63b7d5 ceph: nfs re-expo... |
132 133 |
} err = ceph_init_dentry(dentry); |
a8e63b7d5 ceph: nfs re-expo... |
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
if (err < 0) { iput(inode); return ERR_PTR(err); } dout("__fh_to_dentry %llx %p dentry %p ", fh->ino, inode, dentry); return dentry; } /* * convert connectable fh to dentry */ static struct dentry *__cfh_to_dentry(struct super_block *sb, struct ceph_nfs_confh *cfh) { |
3d14c5d2b ceph: factor out ... |
149 |
struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc; |
a8e63b7d5 ceph: nfs re-expo... |
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
struct inode *inode; struct dentry *dentry; struct ceph_vino vino; int err; dout("__cfh_to_dentry %llx (%llx/%x) ", cfh->ino, cfh->parent_ino, cfh->parent_name_hash); vino.ino = cfh->ino; vino.snap = CEPH_NOSNAP; inode = ceph_find_inode(sb, vino); if (!inode) { struct ceph_mds_request *req; req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPHASH, USE_ANY_MDS); if (IS_ERR(req)) |
7e34bc524 fs/ceph: Use ERR_... |
168 |
return ERR_CAST(req); |
a8e63b7d5 ceph: nfs re-expo... |
169 170 171 172 173 174 175 176 |
req->r_ino1 = vino; req->r_ino2.ino = cfh->parent_ino; req->r_ino2.snap = CEPH_NOSNAP; req->r_path2 = kmalloc(16, GFP_NOFS); snprintf(req->r_path2, 16, "%d", cfh->parent_name_hash); req->r_num_caps = 1; err = ceph_mdsc_do_request(mdsc, NULL, req); |
45e3d3eeb ceph: avoid inode... |
177 178 |
inode = req->r_target_inode; if (inode) |
70b666c3b ceph: use ihold w... |
179 |
ihold(inode); |
a8e63b7d5 ceph: nfs re-expo... |
180 |
ceph_mdsc_put_request(req); |
a8e63b7d5 ceph: nfs re-expo... |
181 182 183 184 185 |
if (!inode) return ERR_PTR(err ? err : -ESTALE); } dentry = d_obtain_alias(inode); |
0d509c949 ceph: d_obtain_al... |
186 |
if (IS_ERR(dentry)) { |
a8e63b7d5 ceph: nfs re-expo... |
187 188 189 190 |
pr_err("cfh_to_dentry %llx -- inode %p but ENOMEM ", cfh->ino, inode); iput(inode); |
0d509c949 ceph: d_obtain_al... |
191 |
return dentry; |
a8e63b7d5 ceph: nfs re-expo... |
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
} err = ceph_init_dentry(dentry); if (err < 0) { iput(inode); return ERR_PTR(err); } dout("__cfh_to_dentry %llx %p dentry %p ", cfh->ino, inode, dentry); return dentry; } static struct dentry *ceph_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { if (fh_type == 1) return __fh_to_dentry(sb, (struct ceph_nfs_fh *)fid->raw); else return __cfh_to_dentry(sb, (struct ceph_nfs_confh *)fid->raw); } /* * get parent, if possible. * * FIXME: we could do better by querying the mds to discover the * parent. */ static struct dentry *ceph_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { struct ceph_nfs_confh *cfh = (void *)fid->raw; struct ceph_vino vino; struct inode *inode; struct dentry *dentry; int err; if (fh_type == 1) return ERR_PTR(-ESTALE); pr_debug("fh_to_parent %llx/%d ", cfh->parent_ino, cfh->parent_name_hash); vino.ino = cfh->ino; vino.snap = CEPH_NOSNAP; inode = ceph_find_inode(sb, vino); if (!inode) return ERR_PTR(-ESTALE); dentry = d_obtain_alias(inode); |
0d509c949 ceph: d_obtain_al... |
242 |
if (IS_ERR(dentry)) { |
a8e63b7d5 ceph: nfs re-expo... |
243 244 245 246 |
pr_err("fh_to_parent %llx -- inode %p but ENOMEM ", cfh->ino, inode); iput(inode); |
0d509c949 ceph: d_obtain_al... |
247 |
return dentry; |
a8e63b7d5 ceph: nfs re-expo... |
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
} err = ceph_init_dentry(dentry); if (err < 0) { iput(inode); return ERR_PTR(err); } dout("fh_to_parent %llx %p dentry %p ", cfh->ino, inode, dentry); return dentry; } const struct export_operations ceph_export_ops = { .encode_fh = ceph_encode_fh, .fh_to_dentry = ceph_fh_to_dentry, .fh_to_parent = ceph_fh_to_parent, }; |