nfsd: new interface to advertise export features
[linux-2.6-block.git] / fs / nfsd / nfsfh.c
CommitLineData
1da177e4
LT
1/*
2 * linux/fs/nfsd/nfsfh.c
3 *
4 * NFS server file handle treatment.
5 *
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7 * Portions Copyright (C) 1999 G. Allen Morris III <gam3@acm.org>
8 * Extensive rewrite by Neil Brown <neilb@cse.unsw.edu.au> Southern-Spring 1999
9 * ... and again Southern-Winter 2001 to support export_operations
10 */
11
a5694255 12#include <linux/exportfs.h>
1da177e4 13
32c1eb0c 14#include <linux/sunrpc/svcauth_gss.h>
9a74af21 15#include "nfsd.h"
0a3adade 16#include "vfs.h"
2e8138a2 17#include "auth.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);
f419a2e3 43 err = inode_permission(parent->d_inode, 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)
1da177e4 52 dprintk("nfsd_acceptable failed at %p %s\n", tdentry, tdentry->d_name.name);
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
1da177e4
LT
64nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type)
65{
66 /* Type can be negative when creating hardlinks - not to a dir */
67 if (type > 0 && (mode & S_IFMT) != type) {
68 if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
69 return nfserr_symlink;
70 else if (type == S_IFDIR)
71 return nfserr_notdir;
72 else if ((mode & S_IFMT) == S_IFDIR)
73 return nfserr_isdir;
74 else
75 return nfserr_inval;
76 }
77 if (type < 0 && (mode & S_IFMT) == -type) {
78 if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
79 return nfserr_symlink;
80 else if (type == -S_IFDIR)
81 return nfserr_isdir;
82 else
83 return nfserr_notdir;
84 }
85 return 0;
86}
87
6fa02839
BF
88static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
89 struct svc_export *exp)
90{
91 /* Check if the request originated from a secure port. */
92 if (!rqstp->rq_secure && EX_SECURE(exp)) {
5216a8e7 93 RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
6fa02839
BF
94 dprintk(KERN_WARNING
95 "nfsd: request from insecure port %s!\n",
96 svc_print_addr(rqstp, buf, sizeof(buf)));
97 return nfserr_perm;
98 }
99
100 /* Set user creds for this exportpoint */
101 return nfserrno(nfsd_setuser(rqstp, exp));
102}
103
03550fac
BF
104/*
105 * Use the given filehandle to look up the corresponding export and
106 * dentry. On success, the results are used to set fh_export and
107 * fh_dentry.
108 */
109static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
110{
111 struct knfsd_fh *fh = &fhp->fh_handle;
112 struct fid *fid = NULL, sfid;
113 struct svc_export *exp;
114 struct dentry *dentry;
115 int fileid_type;
116 int data_left = fh->fh_size/4;
117 __be32 error;
118
119 error = nfserr_stale;
120 if (rqstp->rq_vers > 2)
121 error = nfserr_badhandle;
122 if (rqstp->rq_vers == 4 && fh->fh_size == 0)
123 return nfserr_nofilehandle;
124
125 if (fh->fh_version == 1) {
126 int len;
127
128 if (--data_left < 0)
129 return error;
130 if (fh->fh_auth_type != 0)
131 return error;
132 len = key_len(fh->fh_fsid_type) / 4;
133 if (len == 0)
134 return error;
135 if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
136 /* deprecated, convert to type 3 */
137 len = key_len(FSID_ENCODE_DEV)/4;
138 fh->fh_fsid_type = FSID_ENCODE_DEV;
139 fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl(fh->fh_fsid[0]), ntohl(fh->fh_fsid[1])));
140 fh->fh_fsid[1] = fh->fh_fsid[2];
141 }
142 data_left -= len;
143 if (data_left < 0)
144 return error;
145 exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_auth);
146 fid = (struct fid *)(fh->fh_auth + len);
147 } else {
148 __u32 tfh[2];
149 dev_t xdev;
150 ino_t xino;
151
152 if (fh->fh_size != NFS_FHSIZE)
153 return error;
154 /* assume old filehandle format */
155 xdev = old_decode_dev(fh->ofh_xdev);
156 xino = u32_to_ino_t(fh->ofh_xino);
157 mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
158 exp = rqst_exp_find(rqstp, FSID_DEV, tfh);
159 }
160
161 error = nfserr_stale;
162 if (PTR_ERR(exp) == -ENOENT)
163 return error;
164
165 if (IS_ERR(exp))
166 return nfserrno(PTR_ERR(exp));
167
496d6c32
NB
168 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) {
169 /* Elevate privileges so that the lack of 'r' or 'x'
170 * permission on some parent directory will
171 * not stop exportfs_decode_fh from being able
172 * to reconnect a directory into the dentry cache.
173 * The same problem can affect "SUBTREECHECK" exports,
174 * but as nfsd_acceptable depends on correct
175 * access control settings being in effect, we cannot
176 * fix that case easily.
177 */
d84f4f99
DH
178 struct cred *new = prepare_creds();
179 if (!new)
180 return nfserrno(-ENOMEM);
181 new->cap_effective =
182 cap_raise_nfsd_set(new->cap_effective,
183 new->cap_permitted);
184 put_cred(override_creds(new));
185 put_cred(new);
496d6c32
NB
186 } else {
187 error = nfsd_setuser_and_check_port(rqstp, exp);
188 if (error)
189 goto out;
190 }
03550fac
BF
191
192 /*
193 * Look up the dentry using the NFS file handle.
194 */
195 error = nfserr_stale;
196 if (rqstp->rq_vers > 2)
197 error = nfserr_badhandle;
198
199 if (fh->fh_version != 1) {
200 sfid.i32.ino = fh->ofh_ino;
201 sfid.i32.gen = fh->ofh_generation;
202 sfid.i32.parent_ino = fh->ofh_dirino;
203 fid = &sfid;
204 data_left = 3;
205 if (fh->ofh_dirino == 0)
206 fileid_type = FILEID_INO32_GEN;
207 else
208 fileid_type = FILEID_INO32_GEN_PARENT;
209 } else
210 fileid_type = fh->fh_fileid_type;
211
212 if (fileid_type == FILEID_ROOT)
213 dentry = dget(exp->ex_path.dentry);
214 else {
215 dentry = exportfs_decode_fh(exp->ex_path.mnt, fid,
216 data_left, fileid_type,
217 nfsd_acceptable, exp);
218 }
219 if (dentry == NULL)
220 goto out;
221 if (IS_ERR(dentry)) {
222 if (PTR_ERR(dentry) != -EINVAL)
223 error = nfserrno(PTR_ERR(dentry));
224 goto out;
225 }
226
227 if (S_ISDIR(dentry->d_inode->i_mode) &&
228 (dentry->d_flags & DCACHE_DISCONNECTED)) {
229 printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n",
230 dentry->d_parent->d_name.name, dentry->d_name.name);
231 }
232
233 fhp->fh_dentry = dentry;
234 fhp->fh_export = exp;
03550fac
BF
235 return 0;
236out:
237 exp_put(exp);
238 return error;
239}
240
b3d47676
BF
241/**
242 * fh_verify - filehandle lookup and access checking
243 * @rqstp: pointer to current rpc request
244 * @fhp: filehandle to be verified
245 * @type: expected type of object pointed to by filehandle
246 * @access: type of access needed to object
247 *
248 * Look up a dentry from the on-the-wire filehandle, check the client's
249 * access to the export, and set the current task's credentials.
250 *
251 * Regardless of success or failure of fh_verify(), fh_put() should be
252 * called on @fhp when the caller is finished with the filehandle.
253 *
254 * fh_verify() may be called multiple times on a given filehandle, for
255 * example, when processing an NFSv4 compound. The first call will look
256 * up a dentry using the on-the-wire filehandle. Subsequent calls will
257 * skip the lookup and just perform the other checks and possibly change
258 * the current task's credentials.
1da177e4 259 *
b3d47676
BF
260 * @type specifies the type of object expected using one of the S_IF*
261 * constants defined in include/linux/stat.h. The caller may use zero
262 * to indicate that it doesn't care, or a negative integer to indicate
263 * that it expects something not of the given type.
1da177e4 264 *
b3d47676
BF
265 * @access is formed from the NFSD_MAY_* constants defined in
266 * include/linux/nfsd/nfsd.h.
1da177e4 267 */
83b11340 268__be32
1da177e4
LT
269fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
270{
03550fac 271 struct svc_export *exp;
1da177e4 272 struct dentry *dentry;
03550fac 273 __be32 error;
1da177e4
LT
274
275 dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
276
1da177e4 277 if (!fhp->fh_dentry) {
03550fac 278 error = nfsd_set_fh_dentry(rqstp, fhp);
d1bbf14f
N
279 if (error)
280 goto out;
1da177e4 281 }
864f0f61
BF
282 dentry = fhp->fh_dentry;
283 exp = fhp->fh_export;
284 /*
285 * We still have to do all these permission checks, even when
286 * fh_dentry is already set:
287 * - fh_verify may be called multiple times with different
288 * "access" arguments (e.g. nfsd_proc_create calls
289 * fh_verify(...,NFSD_MAY_EXEC) first, then later (in
290 * nfsd_create) calls fh_verify(...,NFSD_MAY_CREATE).
291 * - in the NFSv4 case, the filehandle may have been filled
292 * in by fh_compose, and given a dentry, but further
293 * compound operations performed with that filehandle
294 * still need permissions checks. In the worst case, a
295 * mountpoint crossing may have changed the export
296 * options, and we may now need to use a different uid
297 * (for example, if different id-squashing options are in
298 * effect on the new filesystem).
299 */
300 error = nfsd_setuser_and_check_port(rqstp, exp);
301 if (error)
302 goto out;
7fc90ec9 303
1da177e4
LT
304 error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type);
305 if (error)
306 goto out;
307
04716e66
BF
308 /*
309 * pseudoflavor restrictions are not enforced on NLM,
310 * which clients virtually always use auth_sys for,
311 * even while using RPCSEC_GSS for NFS.
312 */
313 if (access & NFSD_MAY_LOCK)
314 goto skip_pseudoflavor_check;
315 /*
316 * Clients may expect to be able to use auth_sys during mount,
317 * even if they use gss for everything else; see section 2.3.2
318 * of rfc 2623.
319 */
320 if (access & NFSD_MAY_BYPASS_GSS_ON_ROOT
321 && exp->ex_path.dentry == dentry)
322 goto skip_pseudoflavor_check;
323
324 error = check_nfsd_access(exp, rqstp);
325 if (error)
326 goto out;
32c1eb0c 327
04716e66 328skip_pseudoflavor_check:
1da177e4 329 /* Finally, check access permissions. */
0ec757df 330 error = nfsd_permission(rqstp, exp, dentry, access);
1da177e4 331
1da177e4 332 if (error) {
34e9a63b
N
333 dprintk("fh_verify: %s/%s permission failure, "
334 "acc=%x, error=%d\n",
335 dentry->d_parent->d_name.name,
336 dentry->d_name.name,
fc2dd2e5 337 access, ntohl(error));
1da177e4 338 }
1da177e4 339out:
1da177e4
LT
340 if (error == nfserr_stale)
341 nfsdstats.fh_stale++;
342 return error;
343}
344
345
346/*
347 * Compose a file handle for an NFS reply.
348 *
349 * Note that when first composed, the dentry may not yet have
350 * an inode. In this case a call to fh_update should be made
351 * before the fh goes out on the wire ...
352 */
6e91ea2b
CH
353static void _fh_update(struct svc_fh *fhp, struct svc_export *exp,
354 struct dentry *dentry)
1da177e4 355{
54775491 356 if (dentry != exp->ex_path.dentry) {
6e91ea2b
CH
357 struct fid *fid = (struct fid *)
358 (fhp->fh_handle.fh_auth + fhp->fh_handle.fh_size/4 - 1);
359 int maxsize = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
360 int subtreecheck = !(exp->ex_flags & NFSEXP_NOSUBTREECHECK);
1da177e4 361
6e91ea2b
CH
362 fhp->fh_handle.fh_fileid_type =
363 exportfs_encode_fh(dentry, fid, &maxsize, subtreecheck);
364 fhp->fh_handle.fh_size += maxsize * 4;
365 } else {
366 fhp->fh_handle.fh_fileid_type = FILEID_ROOT;
367 }
1da177e4
LT
368}
369
370/*
371 * for composing old style file handles
372 */
373static inline void _fh_update_old(struct dentry *dentry,
374 struct svc_export *exp,
375 struct knfsd_fh *fh)
376{
377 fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino);
378 fh->ofh_generation = dentry->d_inode->i_generation;
379 if (S_ISDIR(dentry->d_inode->i_mode) ||
380 (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
381 fh->ofh_dirino = 0;
382}
383
8e498751
BF
384static bool is_root_export(struct svc_export *exp)
385{
386 return exp->ex_path.dentry == exp->ex_path.dentry->d_sb->s_root;
387}
388
389static struct super_block *exp_sb(struct svc_export *exp)
390{
391 return exp->ex_path.dentry->d_inode->i_sb;
392}
393
394static bool fsid_type_ok_for_exp(u8 fsid_type, struct svc_export *exp)
395{
396 switch (fsid_type) {
397 case FSID_DEV:
398 if (!old_valid_dev(exp_sb(exp)->s_dev))
399 return 0;
400 /* FALL THROUGH */
401 case FSID_MAJOR_MINOR:
402 case FSID_ENCODE_DEV:
403 return exp_sb(exp)->s_type->fs_flags & FS_REQUIRES_DEV;
404 case FSID_NUM:
405 return exp->ex_flags & NFSEXP_FSID;
406 case FSID_UUID8:
407 case FSID_UUID16:
408 if (!is_root_export(exp))
409 return 0;
410 /* fall through */
411 case FSID_UUID4_INUM:
412 case FSID_UUID16_INUM:
413 return exp->ex_uuid != NULL;
414 }
415 return 1;
416}
417
1da177e4 418
bc6c53d5
BF
419static void set_version_and_fsid_type(struct svc_fh *fhp, struct svc_export *exp, struct svc_fh *ref_fh)
420{
b41eeef1 421 u8 version;
bc6c53d5
BF
422 u8 fsid_type;
423retry:
b41eeef1 424 version = 1;
7e405364 425 if (ref_fh && ref_fh->fh_export == exp) {
982aedfd 426 version = ref_fh->fh_handle.fh_version;
b41eeef1
N
427 fsid_type = ref_fh->fh_handle.fh_fsid_type;
428
b41eeef1
N
429 ref_fh = NULL;
430
431 switch (version) {
432 case 0xca:
af6a4e28 433 fsid_type = FSID_DEV;
b41eeef1
N
434 break;
435 case 1:
436 break;
437 default:
438 goto retry;
439 }
440
8e498751
BF
441 /*
442 * As the fsid -> filesystem mapping was guided by
443 * user-space, there is no guarantee that the filesystem
444 * actually supports that fsid type. If it doesn't we
445 * loop around again without ref_fh set.
982aedfd 446 */
8e498751
BF
447 if (!fsid_type_ok_for_exp(fsid_type, exp))
448 goto retry;
30fa8c01
SD
449 } else if (exp->ex_flags & NFSEXP_FSID) {
450 fsid_type = FSID_NUM;
af6a4e28
N
451 } else if (exp->ex_uuid) {
452 if (fhp->fh_maxsize >= 64) {
8e498751 453 if (is_root_export(exp))
af6a4e28
N
454 fsid_type = FSID_UUID16;
455 else
456 fsid_type = FSID_UUID16_INUM;
457 } else {
8e498751 458 if (is_root_export(exp))
af6a4e28
N
459 fsid_type = FSID_UUID8;
460 else
461 fsid_type = FSID_UUID4_INUM;
462 }
bc6c53d5 463 } else if (!old_valid_dev(exp_sb(exp)->s_dev))
1da177e4 464 /* for newer device numbers, we must use a newer fsid format */
af6a4e28 465 fsid_type = FSID_ENCODE_DEV;
982aedfd 466 else
af6a4e28 467 fsid_type = FSID_DEV;
bc6c53d5
BF
468 fhp->fh_handle.fh_version = version;
469 if (version)
470 fhp->fh_handle.fh_fsid_type = fsid_type;
471}
472
473__be32
474fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
475 struct svc_fh *ref_fh)
476{
477 /* ref_fh is a reference file handle.
478 * if it is non-null and for the same filesystem, then we should compose
479 * a filehandle which is of the same version, where possible.
480 * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
481 * Then create a 32byte filehandle using nfs_fhbase_old
482 *
483 */
484
485 struct inode * inode = dentry->d_inode;
486 struct dentry *parent = dentry->d_parent;
487 __u32 *datap;
488 dev_t ex_dev = exp_sb(exp)->s_dev;
489
490 dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %s/%s, ino=%ld)\n",
491 MAJOR(ex_dev), MINOR(ex_dev),
492 (long) exp->ex_path.dentry->d_inode->i_ino,
493 parent->d_name.name, dentry->d_name.name,
494 (inode ? inode->i_ino : 0));
495
496 /* Choose filehandle version and fsid type based on
497 * the reference filehandle (if it is in the same export)
498 * or the export options.
499 */
500 set_version_and_fsid_type(fhp, exp, ref_fh);
1da177e4
LT
501
502 if (ref_fh == fhp)
503 fh_put(ref_fh);
504
505 if (fhp->fh_locked || fhp->fh_dentry) {
506 printk(KERN_ERR "fh_compose: fh %s/%s not initialized!\n",
982aedfd 507 parent->d_name.name, dentry->d_name.name);
1da177e4
LT
508 }
509 if (fhp->fh_maxsize < NFS_FHSIZE)
510 printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n",
982aedfd
N
511 fhp->fh_maxsize,
512 parent->d_name.name, dentry->d_name.name);
1da177e4
LT
513
514 fhp->fh_dentry = dget(dentry); /* our internal copy */
515 fhp->fh_export = exp;
516 cache_get(&exp->h);
517
bc6c53d5 518 if (fhp->fh_handle.fh_version == 0xca) {
1da177e4
LT
519 /* old style filehandle please */
520 memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
521 fhp->fh_handle.fh_size = NFS_FHSIZE;
522 fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
523 fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
524 fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
982aedfd 525 fhp->fh_handle.ofh_xino =
54775491 526 ino_t_to_u32(exp->ex_path.dentry->d_inode->i_ino);
1da177e4
LT
527 fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
528 if (inode)
529 _fh_update_old(dentry, exp, &fhp->fh_handle);
530 } else {
531 int len;
1da177e4
LT
532 fhp->fh_handle.fh_auth_type = 0;
533 datap = fhp->fh_handle.fh_auth+0;
bc6c53d5 534 mk_fsid(fhp->fh_handle.fh_fsid_type, datap, ex_dev,
54775491 535 exp->ex_path.dentry->d_inode->i_ino,
af6a4e28
N
536 exp->ex_fsid, exp->ex_uuid);
537
bc6c53d5 538 len = key_len(fhp->fh_handle.fh_fsid_type);
1da177e4
LT
539 datap += len/4;
540 fhp->fh_handle.fh_size = 4 + len;
541
6e91ea2b
CH
542 if (inode)
543 _fh_update(fhp, exp, dentry);
1be10a88
BF
544 if (fhp->fh_handle.fh_fileid_type == 255) {
545 fh_put(fhp);
1da177e4 546 return nfserr_opnotsupp;
1be10a88 547 }
1da177e4
LT
548 }
549
1da177e4
LT
550 return 0;
551}
552
553/*
554 * Update file handle information after changing a dentry.
555 * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
556 */
83b11340 557__be32
1da177e4
LT
558fh_update(struct svc_fh *fhp)
559{
560 struct dentry *dentry;
982aedfd 561
1da177e4
LT
562 if (!fhp->fh_dentry)
563 goto out_bad;
564
565 dentry = fhp->fh_dentry;
566 if (!dentry->d_inode)
567 goto out_negative;
568 if (fhp->fh_handle.fh_version != 1) {
569 _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
570 } else {
6e91ea2b 571 if (fhp->fh_handle.fh_fileid_type != FILEID_ROOT)
4c9608b2 572 goto out;
6e91ea2b
CH
573
574 _fh_update(fhp, fhp->fh_export, dentry);
1da177e4
LT
575 if (fhp->fh_handle.fh_fileid_type == 255)
576 return nfserr_opnotsupp;
577 }
578out:
579 return 0;
580
581out_bad:
582 printk(KERN_ERR "fh_update: fh not verified!\n");
583 goto out;
584out_negative:
585 printk(KERN_ERR "fh_update: %s/%s still negative!\n",
586 dentry->d_parent->d_name.name, dentry->d_name.name);
587 goto out;
1da177e4
LT
588}
589
590/*
591 * Release a file handle.
592 */
593void
594fh_put(struct svc_fh *fhp)
595{
596 struct dentry * dentry = fhp->fh_dentry;
597 struct svc_export * exp = fhp->fh_export;
598 if (dentry) {
599 fh_unlock(fhp);
600 fhp->fh_dentry = NULL;
601 dput(dentry);
602#ifdef CONFIG_NFSD_V3
603 fhp->fh_pre_saved = 0;
604 fhp->fh_post_saved = 0;
605#endif
1da177e4
LT
606 }
607 if (exp) {
baab935f 608 cache_put(&exp->h, &svc_export_cache);
1da177e4
LT
609 fhp->fh_export = NULL;
610 }
611 return;
612}
613
614/*
615 * Shorthand for dprintk()'s
616 */
617char * SVCFH_fmt(struct svc_fh *fhp)
618{
619 struct knfsd_fh *fh = &fhp->fh_handle;
620
621 static char buf[80];
622 sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
623 fh->fh_size,
624 fh->fh_base.fh_pad[0],
625 fh->fh_base.fh_pad[1],
626 fh->fh_base.fh_pad[2],
627 fh->fh_base.fh_pad[3],
628 fh->fh_base.fh_pad[4],
629 fh->fh_base.fh_pad[5]);
630 return buf;
631}
af6a4e28
N
632
633enum fsid_source fsid_source(struct svc_fh *fhp)
634{
635 if (fhp->fh_handle.fh_version != 1)
636 return FSIDSOURCE_DEV;
637 switch(fhp->fh_handle.fh_fsid_type) {
638 case FSID_DEV:
639 case FSID_ENCODE_DEV:
640 case FSID_MAJOR_MINOR:
8e498751 641 if (exp_sb(fhp->fh_export)->s_type->fs_flags & FS_REQUIRES_DEV)
b8da0d1c
NB
642 return FSIDSOURCE_DEV;
643 break;
af6a4e28 644 case FSID_NUM:
af6a4e28
N
645 if (fhp->fh_export->ex_flags & NFSEXP_FSID)
646 return FSIDSOURCE_FSID;
b8da0d1c
NB
647 break;
648 default:
649 break;
af6a4e28 650 }
b8da0d1c
NB
651 /* either a UUID type filehandle, or the filehandle doesn't
652 * match the export.
653 */
654 if (fhp->fh_export->ex_flags & NFSEXP_FSID)
655 return FSIDSOURCE_FSID;
656 if (fhp->fh_export->ex_uuid)
657 return FSIDSOURCE_UUID;
658 return FSIDSOURCE_DEV;
af6a4e28 659}