]> Git Repo - linux.git/blame - fs/nfsd/nfsfh.c
exportfs: Add a function to return the raw output from fh_to_dentry()
[linux.git] / fs / nfsd / nfsfh.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
1da177e4
LT
3 * NFS server file handle treatment.
4 *
5 * Copyright (C) 1995, 1996 Olaf Kirch <[email protected]>
6 * Portions Copyright (C) 1999 G. Allen Morris III <[email protected]>
7 * Extensive rewrite by Neil Brown <[email protected]> Southern-Spring 1999
8 * ... and again Southern-Winter 2001 to support export_operations
9 */
10
a5694255 11#include <linux/exportfs.h>
1da177e4 12
32c1eb0c 13#include <linux/sunrpc/svcauth_gss.h>
9a74af21 14#include "nfsd.h"
0a3adade 15#include "vfs.h"
2e8138a2 16#include "auth.h"
f01274a9 17#include "trace.h"
1da177e4
LT
18
19#define NFSDDBG_FACILITY NFSDDBG_FH
1da177e4
LT
20
21
1da177e4
LT
22/*
23 * our acceptability function.
24 * if NOSUBTREECHECK, accept anything
25 * if not, require that we can walk up to exp->ex_dentry
26 * doing some checks on the 'x' bits
27 */
28static int nfsd_acceptable(void *expv, struct dentry *dentry)
29{
30 struct svc_export *exp = expv;
31 int rv;
32 struct dentry *tdentry;
33 struct dentry *parent;
34
35 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
36 return 1;
37
38 tdentry = dget(dentry);
54775491 39 while (tdentry != exp->ex_path.dentry && !IS_ROOT(tdentry)) {
1da177e4
LT
40 /* make sure parents give x permission to user */
41 int err;
42 parent = dget_parent(tdentry);
2b0143b5 43 err = inode_permission(d_inode(parent), MAY_EXEC);
1da177e4
LT
44 if (err < 0) {
45 dput(parent);
46 break;
47 }
48 dput(tdentry);
49 tdentry = parent;
50 }
54775491 51 if (tdentry != exp->ex_path.dentry)
97e47fa1 52 dprintk("nfsd_acceptable failed at %p %pd\n", tdentry, tdentry);
54775491 53 rv = (tdentry == exp->ex_path.dentry);
1da177e4
LT
54 dput(tdentry);
55 return rv;
56}
57
58/* Type check. The correct error return for type mismatches does not seem to be
59 * generally agreed upon. SunOS seems to use EISDIR if file isn't S_IFREG; a
60 * comment in the NFSv3 spec says this is incorrect (implementation notes for
61 * the write call).
62 */
83b11340 63static inline __be32
e75b23f9
BF
64nfsd_mode_check(struct svc_rqst *rqstp, struct dentry *dentry,
65 umode_t requested)
1da177e4 66{
e75b23f9 67 umode_t mode = d_inode(dentry)->i_mode & S_IFMT;
e10f9e14
BF
68
69 if (requested == 0) /* the caller doesn't care */
70 return nfs_ok;
e75b23f9
BF
71 if (mode == requested) {
72 if (mode == S_IFDIR && !d_can_lookup(dentry)) {
73 WARN_ON_ONCE(1);
74 return nfserr_notdir;
75 }
e10f9e14 76 return nfs_ok;
e75b23f9 77 }
e10f9e14
BF
78 /*
79 * v4 has an error more specific than err_notdir which we should
80 * return in preference to err_notdir:
81 */
82 if (rqstp->rq_vers == 4 && mode == S_IFLNK)
83 return nfserr_symlink;
84 if (requested == S_IFDIR)
85 return nfserr_notdir;
86 if (mode == S_IFDIR)
87 return nfserr_isdir;
88 return nfserr_inval;
1da177e4
LT
89}
90
9d7ed135
BF
91static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)
92{
93 if (flags & NFSEXP_INSECURE_PORT)
94 return true;
95 /* We don't require gss requests to use low ports: */
96 if (rqstp->rq_cred.cr_flavor >= RPC_AUTH_GSS)
97 return true;
98 return test_bit(RQ_SECURE, &rqstp->rq_flags);
99}
100
6fa02839
BF
101static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
102 struct svc_export *exp)
103{
12045a6e
BF
104 int flags = nfsexp_flags(rqstp, exp);
105
6fa02839 106 /* Check if the request originated from a secure port. */
9d7ed135 107 if (!nfsd_originating_port_ok(rqstp, flags)) {
5216a8e7 108 RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
a48fd0f9
KM
109 dprintk("nfsd: request from insecure port %s!\n",
110 svc_print_addr(rqstp, buf, sizeof(buf)));
6fa02839
BF
111 return nfserr_perm;
112 }
113
114 /* Set user creds for this exportpoint */
115 return nfserrno(nfsd_setuser(rqstp, exp));
116}
117
03a816b4
SD
118static inline __be32 check_pseudo_root(struct svc_rqst *rqstp,
119 struct dentry *dentry, struct svc_export *exp)
120{
121 if (!(exp->ex_flags & NFSEXP_V4ROOT))
122 return nfs_ok;
123 /*
124 * v2/v3 clients have no need for the V4ROOT export--they use
125 * the mount protocl instead; also, further V4ROOT checks may be
126 * in v4-specific code, in which case v2/v3 clients could bypass
127 * them.
128 */
129 if (!nfsd_v4client(rqstp))
130 return nfserr_stale;
131 /*
132 * We're exposing only the directories and symlinks that have to be
133 * traversed on the way to real exports:
134 */
e36cb0b8
DH
135 if (unlikely(!d_is_dir(dentry) &&
136 !d_is_symlink(dentry)))
03a816b4
SD
137 return nfserr_stale;
138 /*
139 * A pseudoroot export gives permission to access only one
140 * single directory; the kernel has to make another upcall
141 * before granting access to anything else under it:
142 */
143 if (unlikely(dentry != exp->ex_path.dentry))
144 return nfserr_stale;
145 return nfs_ok;
146}
147
03550fac
BF
148/*
149 * Use the given filehandle to look up the corresponding export and
150 * dentry. On success, the results are used to set fh_export and
151 * fh_dentry.
152 */
153static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
154{
155 struct knfsd_fh *fh = &fhp->fh_handle;
156 struct fid *fid = NULL, sfid;
157 struct svc_export *exp;
158 struct dentry *dentry;
159 int fileid_type;
160 int data_left = fh->fh_size/4;
161 __be32 error;
162
163 error = nfserr_stale;
164 if (rqstp->rq_vers > 2)
165 error = nfserr_badhandle;
166 if (rqstp->rq_vers == 4 && fh->fh_size == 0)
167 return nfserr_nofilehandle;
168
169 if (fh->fh_version == 1) {
170 int len;
171
172 if (--data_left < 0)
173 return error;
174 if (fh->fh_auth_type != 0)
175 return error;
176 len = key_len(fh->fh_fsid_type) / 4;
177 if (len == 0)
178 return error;
179 if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
180 /* deprecated, convert to type 3 */
181 len = key_len(FSID_ENCODE_DEV)/4;
182 fh->fh_fsid_type = FSID_ENCODE_DEV;
94ec938b
JL
183 /*
184 * struct knfsd_fh uses host-endian fields, which are
185 * sometimes used to hold net-endian values. This
186 * confuses sparse, so we must use __force here to
187 * keep it from complaining.
188 */
189 fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl((__force __be32)fh->fh_fsid[0]),
190 ntohl((__force __be32)fh->fh_fsid[1])));
03550fac
BF
191 fh->fh_fsid[1] = fh->fh_fsid[2];
192 }
193 data_left -= len;
194 if (data_left < 0)
195 return error;
5409e46f
CH
196 exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_fsid);
197 fid = (struct fid *)(fh->fh_fsid + len);
03550fac
BF
198 } else {
199 __u32 tfh[2];
200 dev_t xdev;
201 ino_t xino;
202
203 if (fh->fh_size != NFS_FHSIZE)
204 return error;
205 /* assume old filehandle format */
206 xdev = old_decode_dev(fh->ofh_xdev);
207 xino = u32_to_ino_t(fh->ofh_xino);
208 mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
209 exp = rqst_exp_find(rqstp, FSID_DEV, tfh);
210 }
211
212 error = nfserr_stale;
f01274a9
TM
213 if (IS_ERR(exp)) {
214 trace_nfsd_set_fh_dentry_badexport(rqstp, fhp, PTR_ERR(exp));
215
216 if (PTR_ERR(exp) == -ENOENT)
217 return error;
03550fac 218
03550fac 219 return nfserrno(PTR_ERR(exp));
f01274a9 220 }
03550fac 221
496d6c32
NB
222 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) {
223 /* Elevate privileges so that the lack of 'r' or 'x'
224 * permission on some parent directory will
225 * not stop exportfs_decode_fh from being able
226 * to reconnect a directory into the dentry cache.
227 * The same problem can affect "SUBTREECHECK" exports,
228 * but as nfsd_acceptable depends on correct
229 * access control settings being in effect, we cannot
230 * fix that case easily.
231 */
d84f4f99 232 struct cred *new = prepare_creds();
027bc41a
KM
233 if (!new) {
234 error = nfserrno(-ENOMEM);
235 goto out;
236 }
d84f4f99
DH
237 new->cap_effective =
238 cap_raise_nfsd_set(new->cap_effective,
239 new->cap_permitted);
240 put_cred(override_creds(new));
241 put_cred(new);
496d6c32
NB
242 } else {
243 error = nfsd_setuser_and_check_port(rqstp, exp);
244 if (error)
245 goto out;
246 }
03550fac
BF
247
248 /*
249 * Look up the dentry using the NFS file handle.
250 */
251 error = nfserr_stale;
252 if (rqstp->rq_vers > 2)
253 error = nfserr_badhandle;
254
255 if (fh->fh_version != 1) {
256 sfid.i32.ino = fh->ofh_ino;
257 sfid.i32.gen = fh->ofh_generation;
258 sfid.i32.parent_ino = fh->ofh_dirino;
259 fid = &sfid;
260 data_left = 3;
261 if (fh->ofh_dirino == 0)
262 fileid_type = FILEID_INO32_GEN;
263 else
264 fileid_type = FILEID_INO32_GEN_PARENT;
265 } else
266 fileid_type = fh->fh_fileid_type;
267
268 if (fileid_type == FILEID_ROOT)
269 dentry = dget(exp->ex_path.dentry);
270 else {
271 dentry = exportfs_decode_fh(exp->ex_path.mnt, fid,
272 data_left, fileid_type,
273 nfsd_acceptable, exp);
f01274a9
TM
274 if (IS_ERR_OR_NULL(dentry))
275 trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,
276 dentry ? PTR_ERR(dentry) : -ESTALE);
03550fac
BF
277 }
278 if (dentry == NULL)
279 goto out;
280 if (IS_ERR(dentry)) {
281 if (PTR_ERR(dentry) != -EINVAL)
282 error = nfserrno(PTR_ERR(dentry));
283 goto out;
284 }
285
e36cb0b8 286 if (d_is_dir(dentry) &&
03550fac 287 (dentry->d_flags & DCACHE_DISCONNECTED)) {
97e47fa1
AV
288 printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %pd2\n",
289 dentry);
03550fac
BF
290 }
291
292 fhp->fh_dentry = dentry;
293 fhp->fh_export = exp;
daab110e
JL
294
295 switch (rqstp->rq_vers) {
296 case 3:
297 if (dentry->d_sb->s_export_op->flags & EXPORT_OP_NOWCC)
298 fhp->fh_no_wcc = true;
299 break;
300 case 2:
301 fhp->fh_no_wcc = true;
302 }
303
03550fac
BF
304 return 0;
305out:
306 exp_put(exp);
307 return error;
308}
309
b3d47676
BF
310/**
311 * fh_verify - filehandle lookup and access checking
312 * @rqstp: pointer to current rpc request
313 * @fhp: filehandle to be verified
314 * @type: expected type of object pointed to by filehandle
315 * @access: type of access needed to object
316 *
317 * Look up a dentry from the on-the-wire filehandle, check the client's
318 * access to the export, and set the current task's credentials.
319 *
320 * Regardless of success or failure of fh_verify(), fh_put() should be
321 * called on @fhp when the caller is finished with the filehandle.
322 *
323 * fh_verify() may be called multiple times on a given filehandle, for
324 * example, when processing an NFSv4 compound. The first call will look
325 * up a dentry using the on-the-wire filehandle. Subsequent calls will
326 * skip the lookup and just perform the other checks and possibly change
327 * the current task's credentials.
1da177e4 328 *
b3d47676
BF
329 * @type specifies the type of object expected using one of the S_IF*
330 * constants defined in include/linux/stat.h. The caller may use zero
331 * to indicate that it doesn't care, or a negative integer to indicate
332 * that it expects something not of the given type.
1da177e4 333 *
b3d47676 334 * @access is formed from the NFSD_MAY_* constants defined in
93f580a9 335 * fs/nfsd/vfs.h.
1da177e4 336 */
83b11340 337__be32
175a4eb7 338fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
1da177e4 339{
03550fac 340 struct svc_export *exp;
1da177e4 341 struct dentry *dentry;
03550fac 342 __be32 error;
1da177e4
LT
343
344 dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
345
1da177e4 346 if (!fhp->fh_dentry) {
03550fac 347 error = nfsd_set_fh_dentry(rqstp, fhp);
d1bbf14f
N
348 if (error)
349 goto out;
1da177e4 350 }
864f0f61
BF
351 dentry = fhp->fh_dentry;
352 exp = fhp->fh_export;
353 /*
354 * We still have to do all these permission checks, even when
355 * fh_dentry is already set:
356 * - fh_verify may be called multiple times with different
357 * "access" arguments (e.g. nfsd_proc_create calls
358 * fh_verify(...,NFSD_MAY_EXEC) first, then later (in
359 * nfsd_create) calls fh_verify(...,NFSD_MAY_CREATE).
360 * - in the NFSv4 case, the filehandle may have been filled
361 * in by fh_compose, and given a dentry, but further
362 * compound operations performed with that filehandle
363 * still need permissions checks. In the worst case, a
364 * mountpoint crossing may have changed the export
365 * options, and we may now need to use a different uid
366 * (for example, if different id-squashing options are in
367 * effect on the new filesystem).
368 */
03a816b4
SD
369 error = check_pseudo_root(rqstp, dentry, exp);
370 if (error)
371 goto out;
372
864f0f61
BF
373 error = nfsd_setuser_and_check_port(rqstp, exp);
374 if (error)
375 goto out;
7fc90ec9 376
e75b23f9 377 error = nfsd_mode_check(rqstp, dentry, type);
1da177e4
LT
378 if (error)
379 goto out;
380
04716e66
BF
381 /*
382 * pseudoflavor restrictions are not enforced on NLM,
383 * which clients virtually always use auth_sys for,
384 * even while using RPCSEC_GSS for NFS.
385 */
204f4ce7 386 if (access & NFSD_MAY_LOCK || access & NFSD_MAY_BYPASS_GSS)
04716e66
BF
387 goto skip_pseudoflavor_check;
388 /*
389 * Clients may expect to be able to use auth_sys during mount,
390 * even if they use gss for everything else; see section 2.3.2
391 * of rfc 2623.
392 */
393 if (access & NFSD_MAY_BYPASS_GSS_ON_ROOT
394 && exp->ex_path.dentry == dentry)
395 goto skip_pseudoflavor_check;
396
397 error = check_nfsd_access(exp, rqstp);
398 if (error)
399 goto out;
32c1eb0c 400
04716e66 401skip_pseudoflavor_check:
1da177e4 402 /* Finally, check access permissions. */
0ec757df 403 error = nfsd_permission(rqstp, exp, dentry, access);
1da177e4 404
1da177e4 405 if (error) {
97e47fa1 406 dprintk("fh_verify: %pd2 permission failure, "
34e9a63b 407 "acc=%x, error=%d\n",
97e47fa1 408 dentry,
fc2dd2e5 409 access, ntohl(error));
1da177e4 410 }
1da177e4 411out:
1da177e4
LT
412 if (error == nfserr_stale)
413 nfsdstats.fh_stale++;
414 return error;
415}
416
417
418/*
419 * Compose a file handle for an NFS reply.
420 *
421 * Note that when first composed, the dentry may not yet have
422 * an inode. In this case a call to fh_update should be made
423 * before the fh goes out on the wire ...
424 */
6e91ea2b
CH
425static void _fh_update(struct svc_fh *fhp, struct svc_export *exp,
426 struct dentry *dentry)
1da177e4 427{
54775491 428 if (dentry != exp->ex_path.dentry) {
6e91ea2b 429 struct fid *fid = (struct fid *)
5409e46f 430 (fhp->fh_handle.fh_fsid + fhp->fh_handle.fh_size/4 - 1);
6e91ea2b
CH
431 int maxsize = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
432 int subtreecheck = !(exp->ex_flags & NFSEXP_NOSUBTREECHECK);
1da177e4 433
6e91ea2b
CH
434 fhp->fh_handle.fh_fileid_type =
435 exportfs_encode_fh(dentry, fid, &maxsize, subtreecheck);
436 fhp->fh_handle.fh_size += maxsize * 4;
437 } else {
438 fhp->fh_handle.fh_fileid_type = FILEID_ROOT;
439 }
1da177e4
LT
440}
441
442/*
443 * for composing old style file handles
444 */
445static inline void _fh_update_old(struct dentry *dentry,
446 struct svc_export *exp,
447 struct knfsd_fh *fh)
448{
2b0143b5
DH
449 fh->ofh_ino = ino_t_to_u32(d_inode(dentry)->i_ino);
450 fh->ofh_generation = d_inode(dentry)->i_generation;
e36cb0b8 451 if (d_is_dir(dentry) ||
1da177e4
LT
452 (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
453 fh->ofh_dirino = 0;
454}
455
8e498751
BF
456static bool is_root_export(struct svc_export *exp)
457{
458 return exp->ex_path.dentry == exp->ex_path.dentry->d_sb->s_root;
459}
460
461static struct super_block *exp_sb(struct svc_export *exp)
462{
fc64005c 463 return exp->ex_path.dentry->d_sb;
8e498751
BF
464}
465
466static bool fsid_type_ok_for_exp(u8 fsid_type, struct svc_export *exp)
467{
468 switch (fsid_type) {
469 case FSID_DEV:
470 if (!old_valid_dev(exp_sb(exp)->s_dev))
a677a783 471 return false;
df561f66 472 fallthrough;
8e498751
BF
473 case FSID_MAJOR_MINOR:
474 case FSID_ENCODE_DEV:
475 return exp_sb(exp)->s_type->fs_flags & FS_REQUIRES_DEV;
476 case FSID_NUM:
477 return exp->ex_flags & NFSEXP_FSID;
478 case FSID_UUID8:
479 case FSID_UUID16:
480 if (!is_root_export(exp))
a677a783 481 return false;
df561f66 482 fallthrough;
8e498751
BF
483 case FSID_UUID4_INUM:
484 case FSID_UUID16_INUM:
485 return exp->ex_uuid != NULL;
486 }
a677a783 487 return true;
8e498751
BF
488}
489
1da177e4 490
bc6c53d5
BF
491static void set_version_and_fsid_type(struct svc_fh *fhp, struct svc_export *exp, struct svc_fh *ref_fh)
492{
b41eeef1 493 u8 version;
bc6c53d5
BF
494 u8 fsid_type;
495retry:
b41eeef1 496 version = 1;
7e405364 497 if (ref_fh && ref_fh->fh_export == exp) {
982aedfd 498 version = ref_fh->fh_handle.fh_version;
b41eeef1
N
499 fsid_type = ref_fh->fh_handle.fh_fsid_type;
500
b41eeef1
N
501 ref_fh = NULL;
502
503 switch (version) {
504 case 0xca:
af6a4e28 505 fsid_type = FSID_DEV;
b41eeef1
N
506 break;
507 case 1:
508 break;
509 default:
510 goto retry;
511 }
512
8e498751
BF
513 /*
514 * As the fsid -> filesystem mapping was guided by
515 * user-space, there is no guarantee that the filesystem
516 * actually supports that fsid type. If it doesn't we
517 * loop around again without ref_fh set.
982aedfd 518 */
8e498751
BF
519 if (!fsid_type_ok_for_exp(fsid_type, exp))
520 goto retry;
30fa8c01
SD
521 } else if (exp->ex_flags & NFSEXP_FSID) {
522 fsid_type = FSID_NUM;
af6a4e28
N
523 } else if (exp->ex_uuid) {
524 if (fhp->fh_maxsize >= 64) {
8e498751 525 if (is_root_export(exp))
af6a4e28
N
526 fsid_type = FSID_UUID16;
527 else
528 fsid_type = FSID_UUID16_INUM;
529 } else {
8e498751 530 if (is_root_export(exp))
af6a4e28
N
531 fsid_type = FSID_UUID8;
532 else
533 fsid_type = FSID_UUID4_INUM;
534 }
bc6c53d5 535 } else if (!old_valid_dev(exp_sb(exp)->s_dev))
1da177e4 536 /* for newer device numbers, we must use a newer fsid format */
af6a4e28 537 fsid_type = FSID_ENCODE_DEV;
982aedfd 538 else
af6a4e28 539 fsid_type = FSID_DEV;
bc6c53d5
BF
540 fhp->fh_handle.fh_version = version;
541 if (version)
542 fhp->fh_handle.fh_fsid_type = fsid_type;
543}
544
545__be32
546fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
547 struct svc_fh *ref_fh)
548{
549 /* ref_fh is a reference file handle.
550 * if it is non-null and for the same filesystem, then we should compose
551 * a filehandle which is of the same version, where possible.
552 * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
553 * Then create a 32byte filehandle using nfs_fhbase_old
554 *
555 */
556
2b0143b5 557 struct inode * inode = d_inode(dentry);
bc6c53d5
BF
558 dev_t ex_dev = exp_sb(exp)->s_dev;
559
97e47fa1 560 dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %pd2, ino=%ld)\n",
bc6c53d5 561 MAJOR(ex_dev), MINOR(ex_dev),
2b0143b5 562 (long) d_inode(exp->ex_path.dentry)->i_ino,
97e47fa1 563 dentry,
bc6c53d5
BF
564 (inode ? inode->i_ino : 0));
565
566 /* Choose filehandle version and fsid type based on
567 * the reference filehandle (if it is in the same export)
568 * or the export options.
569 */
d28c442f 570 set_version_and_fsid_type(fhp, exp, ref_fh);
1da177e4 571
daab110e
JL
572 /* If we have a ref_fh, then copy the fh_no_wcc setting from it. */
573 fhp->fh_no_wcc = ref_fh ? ref_fh->fh_no_wcc : false;
574
1da177e4
LT
575 if (ref_fh == fhp)
576 fh_put(ref_fh);
577
578 if (fhp->fh_locked || fhp->fh_dentry) {
97e47fa1
AV
579 printk(KERN_ERR "fh_compose: fh %pd2 not initialized!\n",
580 dentry);
1da177e4
LT
581 }
582 if (fhp->fh_maxsize < NFS_FHSIZE)
97e47fa1 583 printk(KERN_ERR "fh_compose: called with maxsize %d! %pd2\n",
982aedfd 584 fhp->fh_maxsize,
97e47fa1 585 dentry);
1da177e4
LT
586
587 fhp->fh_dentry = dget(dentry); /* our internal copy */
bf18f163 588 fhp->fh_export = exp_get(exp);
1da177e4 589
bc6c53d5 590 if (fhp->fh_handle.fh_version == 0xca) {
1da177e4
LT
591 /* old style filehandle please */
592 memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
593 fhp->fh_handle.fh_size = NFS_FHSIZE;
594 fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
595 fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
596 fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
982aedfd 597 fhp->fh_handle.ofh_xino =
2b0143b5 598 ino_t_to_u32(d_inode(exp->ex_path.dentry)->i_ino);
1da177e4
LT
599 fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
600 if (inode)
601 _fh_update_old(dentry, exp, &fhp->fh_handle);
602 } else {
5409e46f
CH
603 fhp->fh_handle.fh_size =
604 key_len(fhp->fh_handle.fh_fsid_type) + 4;
1da177e4 605 fhp->fh_handle.fh_auth_type = 0;
5409e46f
CH
606
607 mk_fsid(fhp->fh_handle.fh_fsid_type,
608 fhp->fh_handle.fh_fsid,
609 ex_dev,
2b0143b5 610 d_inode(exp->ex_path.dentry)->i_ino,
af6a4e28
N
611 exp->ex_fsid, exp->ex_uuid);
612
6e91ea2b
CH
613 if (inode)
614 _fh_update(fhp, exp, dentry);
216b6cbd 615 if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID) {
1be10a88 616 fh_put(fhp);
1da177e4 617 return nfserr_opnotsupp;
1be10a88 618 }
1da177e4
LT
619 }
620
1da177e4
LT
621 return 0;
622}
623
624/*
625 * Update file handle information after changing a dentry.
626 * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
627 */
83b11340 628__be32
1da177e4
LT
629fh_update(struct svc_fh *fhp)
630{
631 struct dentry *dentry;
982aedfd 632
1da177e4
LT
633 if (!fhp->fh_dentry)
634 goto out_bad;
635
636 dentry = fhp->fh_dentry;
2b0143b5 637 if (d_really_is_negative(dentry))
1da177e4
LT
638 goto out_negative;
639 if (fhp->fh_handle.fh_version != 1) {
640 _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
641 } else {
6e91ea2b 642 if (fhp->fh_handle.fh_fileid_type != FILEID_ROOT)
49e73720 643 return 0;
6e91ea2b
CH
644
645 _fh_update(fhp, fhp->fh_export, dentry);
216b6cbd 646 if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID)
1da177e4
LT
647 return nfserr_opnotsupp;
648 }
1da177e4 649 return 0;
1da177e4
LT
650out_bad:
651 printk(KERN_ERR "fh_update: fh not verified!\n");
49e73720 652 return nfserr_serverfault;
1da177e4 653out_negative:
97e47fa1
AV
654 printk(KERN_ERR "fh_update: %pd2 still negative!\n",
655 dentry);
49e73720 656 return nfserr_serverfault;
1da177e4
LT
657}
658
659/*
660 * Release a file handle.
661 */
662void
663fh_put(struct svc_fh *fhp)
664{
665 struct dentry * dentry = fhp->fh_dentry;
666 struct svc_export * exp = fhp->fh_export;
667 if (dentry) {
668 fh_unlock(fhp);
669 fhp->fh_dentry = NULL;
670 dput(dentry);
aaf91ec1 671 fh_clear_wcc(fhp);
1da177e4 672 }
4a55c101 673 fh_drop_write(fhp);
1da177e4 674 if (exp) {
a09581f2 675 exp_put(exp);
1da177e4
LT
676 fhp->fh_export = NULL;
677 }
daab110e 678 fhp->fh_no_wcc = false;
1da177e4
LT
679 return;
680}
681
682/*
683 * Shorthand for dprintk()'s
684 */
685char * SVCFH_fmt(struct svc_fh *fhp)
686{
687 struct knfsd_fh *fh = &fhp->fh_handle;
688
689 static char buf[80];
690 sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
691 fh->fh_size,
692 fh->fh_base.fh_pad[0],
693 fh->fh_base.fh_pad[1],
694 fh->fh_base.fh_pad[2],
695 fh->fh_base.fh_pad[3],
696 fh->fh_base.fh_pad[4],
697 fh->fh_base.fh_pad[5]);
698 return buf;
699}
af6a4e28
N
700
701enum fsid_source fsid_source(struct svc_fh *fhp)
702{
703 if (fhp->fh_handle.fh_version != 1)
704 return FSIDSOURCE_DEV;
705 switch(fhp->fh_handle.fh_fsid_type) {
706 case FSID_DEV:
707 case FSID_ENCODE_DEV:
708 case FSID_MAJOR_MINOR:
8e498751 709 if (exp_sb(fhp->fh_export)->s_type->fs_flags & FS_REQUIRES_DEV)
b8da0d1c
NB
710 return FSIDSOURCE_DEV;
711 break;
af6a4e28 712 case FSID_NUM:
af6a4e28
N
713 if (fhp->fh_export->ex_flags & NFSEXP_FSID)
714 return FSIDSOURCE_FSID;
b8da0d1c
NB
715 break;
716 default:
717 break;
af6a4e28 718 }
b8da0d1c
NB
719 /* either a UUID type filehandle, or the filehandle doesn't
720 * match the export.
721 */
722 if (fhp->fh_export->ex_flags & NFSEXP_FSID)
723 return FSIDSOURCE_FSID;
724 if (fhp->fh_export->ex_uuid)
725 return FSIDSOURCE_UUID;
726 return FSIDSOURCE_DEV;
af6a4e28 727}
This page took 1.129451 seconds and 4 git commands to generate.