blob: 6ca2d24fc216d6cf5ccf6f293955b0ad27accb73 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/fs.h>
14#include <linux/unistd.h>
15#include <linux/string.h>
16#include <linux/stat.h>
17#include <linux/dcache.h>
18#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Chuck Leverad06e4b2007-02-12 00:53:32 -080020#include <linux/sunrpc/clnt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/sunrpc/svc.h>
22#include <linux/nfsd/nfsd.h>
23
24#define NFSDDBG_FACILITY NFSDDBG_FH
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26
27static int nfsd_nr_verified;
28static int nfsd_nr_put;
29
30extern struct export_operations export_op_default;
31
32#define CALL(ops,fun) ((ops->fun)?(ops->fun):export_op_default.fun)
33
34/*
35 * our acceptability function.
36 * if NOSUBTREECHECK, accept anything
37 * if not, require that we can walk up to exp->ex_dentry
38 * doing some checks on the 'x' bits
39 */
40static int nfsd_acceptable(void *expv, struct dentry *dentry)
41{
42 struct svc_export *exp = expv;
43 int rv;
44 struct dentry *tdentry;
45 struct dentry *parent;
46
47 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
48 return 1;
49
50 tdentry = dget(dentry);
51 while (tdentry != exp->ex_dentry && ! IS_ROOT(tdentry)) {
52 /* make sure parents give x permission to user */
53 int err;
54 parent = dget_parent(tdentry);
55 err = permission(parent->d_inode, MAY_EXEC, NULL);
56 if (err < 0) {
57 dput(parent);
58 break;
59 }
60 dput(tdentry);
61 tdentry = parent;
62 }
63 if (tdentry != exp->ex_dentry)
64 dprintk("nfsd_acceptable failed at %p %s\n", tdentry, tdentry->d_name.name);
65 rv = (tdentry == exp->ex_dentry);
66 dput(tdentry);
67 return rv;
68}
69
70/* Type check. The correct error return for type mismatches does not seem to be
71 * generally agreed upon. SunOS seems to use EISDIR if file isn't S_IFREG; a
72 * comment in the NFSv3 spec says this is incorrect (implementation notes for
73 * the write call).
74 */
Al Viro83b11342006-10-19 23:28:55 -070075static inline __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -070076nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type)
77{
78 /* Type can be negative when creating hardlinks - not to a dir */
79 if (type > 0 && (mode & S_IFMT) != type) {
80 if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
81 return nfserr_symlink;
82 else if (type == S_IFDIR)
83 return nfserr_notdir;
84 else if ((mode & S_IFMT) == S_IFDIR)
85 return nfserr_isdir;
86 else
87 return nfserr_inval;
88 }
89 if (type < 0 && (mode & S_IFMT) == -type) {
90 if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
91 return nfserr_symlink;
92 else if (type == -S_IFDIR)
93 return nfserr_isdir;
94 else
95 return nfserr_notdir;
96 }
97 return 0;
98}
99
100/*
101 * Perform sanity checks on the dentry in a client's file handle.
102 *
103 * Note that the file handle dentry may need to be freed even after
104 * an error return.
105 *
106 * This is only called at the start of an nfsproc call, so fhp points to
107 * a svc_fh which is all 0 except for the over-the-wire file handle.
108 */
Al Viro83b11342006-10-19 23:28:55 -0700109__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
111{
112 struct knfsd_fh *fh = &fhp->fh_handle;
113 struct svc_export *exp = NULL;
114 struct dentry *dentry;
Al Viro83b11342006-10-19 23:28:55 -0700115 __be32 error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (!fhp->fh_dentry) {
120 __u32 *datap=NULL;
121 __u32 tfh[3]; /* filehandle fragment for oldstyle filehandles */
122 int fileid_type;
123 int data_left = fh->fh_size/4;
124
125 error = nfserr_stale;
126 if (rqstp->rq_client == NULL)
127 goto out;
128 if (rqstp->rq_vers > 2)
129 error = nfserr_badhandle;
130 if (rqstp->rq_vers == 4 && fh->fh_size == 0)
131 return nfserr_nofilehandle;
132
133 if (fh->fh_version == 1) {
134 int len;
135 datap = fh->fh_auth;
136 if (--data_left<0) goto out;
137 switch (fh->fh_auth_type) {
138 case 0: break;
139 default: goto out;
140 }
141 len = key_len(fh->fh_fsid_type) / 4;
142 if (len == 0) goto out;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800143 if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* deprecated, convert to type 3 */
NeilBrownaf6a4e22007-02-14 00:33:12 -0800145 len = key_len(FSID_ENCODE_DEV)/4;
146 fh->fh_fsid_type = FSID_ENCODE_DEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl(fh->fh_fsid[0]), ntohl(fh->fh_fsid[1])));
148 fh->fh_fsid[1] = fh->fh_fsid[2];
149 }
150 if ((data_left -= len)<0) goto out;
151 exp = exp_find(rqstp->rq_client, fh->fh_fsid_type, datap, &rqstp->rq_chandle);
152 datap += len;
153 } else {
154 dev_t xdev;
155 ino_t xino;
156 if (fh->fh_size != NFS_FHSIZE)
157 goto out;
158 /* assume old filehandle format */
159 xdev = old_decode_dev(fh->ofh_xdev);
160 xino = u32_to_ino_t(fh->ofh_xino);
NeilBrownaf6a4e22007-02-14 00:33:12 -0800161 mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
162 exp = exp_find(rqstp->rq_client, FSID_DEV, tfh,
163 &rqstp->rq_chandle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
165
J.Bruce Fieldse0bb89e2006-12-13 00:35:25 -0800166 if (IS_ERR(exp) && (PTR_ERR(exp) == -EAGAIN
167 || PTR_ERR(exp) == -ETIMEDOUT)) {
168 error = nfserrno(PTR_ERR(exp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 goto out;
J.Bruce Fieldse0bb89e2006-12-13 00:35:25 -0800170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 error = nfserr_stale;
173 if (!exp || IS_ERR(exp))
174 goto out;
175
176 /* Check if the request originated from a secure port. */
177 error = nfserr_perm;
178 if (!rqstp->rq_secure && EX_SECURE(exp)) {
Chuck Leverad06e4b2007-02-12 00:53:32 -0800179 char buf[RPC_MAX_ADDRBUFLEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 printk(KERN_WARNING
Chuck Leverad06e4b2007-02-12 00:53:32 -0800181 "nfsd: request from insecure port %s!\n",
182 svc_print_addr(rqstp, buf, sizeof(buf)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 goto out;
184 }
185
NeilBrownd1bbf142006-07-30 03:03:16 -0700186 /* Set user creds for this exportpoint */
187 error = nfserrno(nfsd_setuser(rqstp, exp));
188 if (error)
189 goto out;
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 /*
192 * Look up the dentry using the NFS file handle.
193 */
194 error = nfserr_stale;
195 if (rqstp->rq_vers > 2)
196 error = nfserr_badhandle;
197
198 if (fh->fh_version != 1) {
199 tfh[0] = fh->ofh_ino;
200 tfh[1] = fh->ofh_generation;
201 tfh[2] = fh->ofh_dirino;
202 datap = tfh;
203 data_left = 3;
204 if (fh->ofh_dirino == 0)
205 fileid_type = 1;
206 else
207 fileid_type = 2;
208 } else
209 fileid_type = fh->fh_fileid_type;
NeilBrown982aedf2007-02-14 00:33:11 -0800210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 if (fileid_type == 0)
212 dentry = dget(exp->ex_dentry);
213 else {
214 struct export_operations *nop = exp->ex_mnt->mnt_sb->s_export_op;
215 dentry = CALL(nop,decode_fh)(exp->ex_mnt->mnt_sb,
216 datap, data_left,
217 fileid_type,
218 nfsd_acceptable, exp);
219 }
220 if (dentry == NULL)
221 goto out;
222 if (IS_ERR(dentry)) {
223 if (PTR_ERR(dentry) != -EINVAL)
224 error = nfserrno(PTR_ERR(dentry));
225 goto out;
226 }
NeilBrown34e9a632007-01-29 13:19:52 -0800227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (S_ISDIR(dentry->d_inode->i_mode) &&
229 (dentry->d_flags & DCACHE_DISCONNECTED)) {
230 printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n",
231 dentry->d_parent->d_name.name, dentry->d_name.name);
232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 fhp->fh_dentry = dentry;
235 fhp->fh_export = exp;
236 nfsd_nr_verified++;
237 } else {
238 /* just rechecking permissions
239 * (e.g. nfsproc_create calls fh_verify, then nfsd_create does as well)
240 */
241 dprintk("nfsd: fh_verify - just checking\n");
242 dentry = fhp->fh_dentry;
243 exp = fhp->fh_export;
NeilBrownd1bbf142006-07-30 03:03:16 -0700244 /* Set user creds for this exportpoint; necessary even
245 * in the "just checking" case because this may be a
246 * filehandle that was created by fh_compose, and that
247 * is about to be used in another nfsv4 compound
248 * operation */
249 error = nfserrno(nfsd_setuser(rqstp, exp));
250 if (error)
251 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253 cache_get(&exp->h);
254
J. Bruce Fields7fc90ec2006-06-30 01:56:14 -0700255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type);
257 if (error)
258 goto out;
259
260 /* Finally, check access permissions. */
261 error = nfsd_permission(exp, dentry, access);
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 if (error) {
NeilBrown34e9a632007-01-29 13:19:52 -0800264 dprintk("fh_verify: %s/%s permission failure, "
265 "acc=%x, error=%d\n",
266 dentry->d_parent->d_name.name,
267 dentry->d_name.name,
Al Virofc2dd2e2007-02-01 13:52:43 +0000268 access, ntohl(error));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270out:
271 if (exp && !IS_ERR(exp))
272 exp_put(exp);
273 if (error == nfserr_stale)
274 nfsdstats.fh_stale++;
275 return error;
276}
277
278
279/*
280 * Compose a file handle for an NFS reply.
281 *
282 * Note that when first composed, the dentry may not yet have
283 * an inode. In this case a call to fh_update should be made
284 * before the fh goes out on the wire ...
285 */
286static inline int _fh_update(struct dentry *dentry, struct svc_export *exp,
287 __u32 *datap, int *maxsize)
288{
289 struct export_operations *nop = exp->ex_mnt->mnt_sb->s_export_op;
NeilBrown982aedf2007-02-14 00:33:11 -0800290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 if (dentry == exp->ex_dentry) {
292 *maxsize = 0;
293 return 0;
294 }
295
296 return CALL(nop,encode_fh)(dentry, datap, maxsize,
297 !(exp->ex_flags&NFSEXP_NOSUBTREECHECK));
298}
299
300/*
301 * for composing old style file handles
302 */
303static inline void _fh_update_old(struct dentry *dentry,
304 struct svc_export *exp,
305 struct knfsd_fh *fh)
306{
307 fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino);
308 fh->ofh_generation = dentry->d_inode->i_generation;
309 if (S_ISDIR(dentry->d_inode->i_mode) ||
310 (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
311 fh->ofh_dirino = 0;
312}
313
Al Viro83b11342006-10-19 23:28:55 -0700314__be32
NeilBrown982aedf2007-02-14 00:33:11 -0800315fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
316 struct svc_fh *ref_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 /* ref_fh is a reference file handle.
NeilBrown7e405362006-06-30 01:56:12 -0700319 * if it is non-null and for the same filesystem, then we should compose
320 * a filehandle which is of the same version, where possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
322 * Then create a 32byte filehandle using nfs_fhbase_old
323 *
324 */
325
NeilBrownb41eeef2007-05-09 02:34:57 -0700326 u8 version;
NeilBrown982aedf2007-02-14 00:33:11 -0800327 u8 fsid_type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 struct inode * inode = dentry->d_inode;
329 struct dentry *parent = dentry->d_parent;
330 __u32 *datap;
331 dev_t ex_dev = exp->ex_dentry->d_inode->i_sb->s_dev;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800332 int root_export = (exp->ex_dentry == exp->ex_dentry->d_sb->s_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %s/%s, ino=%ld)\n",
335 MAJOR(ex_dev), MINOR(ex_dev),
336 (long) exp->ex_dentry->d_inode->i_ino,
337 parent->d_name.name, dentry->d_name.name,
338 (inode ? inode->i_ino : 0));
339
NeilBrown982aedf2007-02-14 00:33:11 -0800340 /* Choose filehandle version and fsid type based on
341 * the reference filehandle (if it is in the same export)
342 * or the export options.
343 */
NeilBrownb41eeef2007-05-09 02:34:57 -0700344 retry:
345 version = 1;
NeilBrown7e405362006-06-30 01:56:12 -0700346 if (ref_fh && ref_fh->fh_export == exp) {
NeilBrown982aedf2007-02-14 00:33:11 -0800347 version = ref_fh->fh_handle.fh_version;
NeilBrownb41eeef2007-05-09 02:34:57 -0700348 fsid_type = ref_fh->fh_handle.fh_fsid_type;
349
350 if (ref_fh == fhp)
351 fh_put(ref_fh);
352 ref_fh = NULL;
353
354 switch (version) {
355 case 0xca:
NeilBrownaf6a4e22007-02-14 00:33:12 -0800356 fsid_type = FSID_DEV;
NeilBrownb41eeef2007-05-09 02:34:57 -0700357 break;
358 case 1:
359 break;
360 default:
361 goto retry;
362 }
363
364 /* Need to check that this type works for this
365 * export point. As the fsid -> filesystem mapping
366 * was guided by user-space, there is no guarantee
367 * that the filesystem actually supports that fsid
368 * type. If it doesn't we loop around again without
369 * ref_fh set.
NeilBrown982aedf2007-02-14 00:33:11 -0800370 */
NeilBrownb41eeef2007-05-09 02:34:57 -0700371 switch(fsid_type) {
372 case FSID_DEV:
373 if (!old_valid_dev(ex_dev))
374 goto retry;
375 /* FALL THROUGH */
376 case FSID_MAJOR_MINOR:
377 case FSID_ENCODE_DEV:
378 if (!(exp->ex_dentry->d_inode->i_sb->s_type->fs_flags
379 & FS_REQUIRES_DEV))
380 goto retry;
381 break;
382 case FSID_NUM:
383 if (! (exp->ex_flags & NFSEXP_FSID))
384 goto retry;
385 break;
386 case FSID_UUID8:
387 case FSID_UUID16:
388 if (!root_export)
389 goto retry;
390 /* fall through */
391 case FSID_UUID4_INUM:
392 case FSID_UUID16_INUM:
393 if (exp->ex_uuid == NULL)
394 goto retry;
395 break;
396 }
NeilBrownaf6a4e22007-02-14 00:33:12 -0800397 } else if (exp->ex_uuid) {
398 if (fhp->fh_maxsize >= 64) {
399 if (root_export)
400 fsid_type = FSID_UUID16;
401 else
402 fsid_type = FSID_UUID16_INUM;
403 } else {
404 if (root_export)
405 fsid_type = FSID_UUID8;
406 else
407 fsid_type = FSID_UUID4_INUM;
408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 } else if (exp->ex_flags & NFSEXP_FSID)
NeilBrownaf6a4e22007-02-14 00:33:12 -0800410 fsid_type = FSID_NUM;
NeilBrown982aedf2007-02-14 00:33:11 -0800411 else if (!old_valid_dev(ex_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /* for newer device numbers, we must use a newer fsid format */
NeilBrownaf6a4e22007-02-14 00:33:12 -0800413 fsid_type = FSID_ENCODE_DEV;
NeilBrown982aedf2007-02-14 00:33:11 -0800414 else
NeilBrownaf6a4e22007-02-14 00:33:12 -0800415 fsid_type = FSID_DEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 if (ref_fh == fhp)
418 fh_put(ref_fh);
419
420 if (fhp->fh_locked || fhp->fh_dentry) {
421 printk(KERN_ERR "fh_compose: fh %s/%s not initialized!\n",
NeilBrown982aedf2007-02-14 00:33:11 -0800422 parent->d_name.name, dentry->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424 if (fhp->fh_maxsize < NFS_FHSIZE)
425 printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n",
NeilBrown982aedf2007-02-14 00:33:11 -0800426 fhp->fh_maxsize,
427 parent->d_name.name, dentry->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 fhp->fh_dentry = dget(dentry); /* our internal copy */
430 fhp->fh_export = exp;
431 cache_get(&exp->h);
432
NeilBrown982aedf2007-02-14 00:33:11 -0800433 if (version == 0xca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 /* old style filehandle please */
435 memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
436 fhp->fh_handle.fh_size = NFS_FHSIZE;
437 fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
438 fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
439 fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
NeilBrown982aedf2007-02-14 00:33:11 -0800440 fhp->fh_handle.ofh_xino =
441 ino_t_to_u32(exp->ex_dentry->d_inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
443 if (inode)
444 _fh_update_old(dentry, exp, &fhp->fh_handle);
445 } else {
446 int len;
447 fhp->fh_handle.fh_version = 1;
448 fhp->fh_handle.fh_auth_type = 0;
449 datap = fhp->fh_handle.fh_auth+0;
NeilBrown982aedf2007-02-14 00:33:11 -0800450 fhp->fh_handle.fh_fsid_type = fsid_type;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800451 mk_fsid(fsid_type, datap, ex_dev,
452 exp->ex_dentry->d_inode->i_ino,
453 exp->ex_fsid, exp->ex_uuid);
454
NeilBrown982aedf2007-02-14 00:33:11 -0800455 len = key_len(fsid_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 datap += len/4;
457 fhp->fh_handle.fh_size = 4 + len;
458
459 if (inode) {
460 int size = (fhp->fh_maxsize-len-4)/4;
461 fhp->fh_handle.fh_fileid_type =
462 _fh_update(dentry, exp, datap, &size);
463 fhp->fh_handle.fh_size += size*4;
464 }
465 if (fhp->fh_handle.fh_fileid_type == 255)
466 return nfserr_opnotsupp;
467 }
468
469 nfsd_nr_verified++;
470 return 0;
471}
472
473/*
474 * Update file handle information after changing a dentry.
475 * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
476 */
Al Viro83b11342006-10-19 23:28:55 -0700477__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478fh_update(struct svc_fh *fhp)
479{
480 struct dentry *dentry;
481 __u32 *datap;
NeilBrown982aedf2007-02-14 00:33:11 -0800482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 if (!fhp->fh_dentry)
484 goto out_bad;
485
486 dentry = fhp->fh_dentry;
487 if (!dentry->d_inode)
488 goto out_negative;
489 if (fhp->fh_handle.fh_version != 1) {
490 _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
491 } else {
492 int size;
493 if (fhp->fh_handle.fh_fileid_type != 0)
NeilBrown4c9608b2006-06-30 01:56:11 -0700494 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 datap = fhp->fh_handle.fh_auth+
496 fhp->fh_handle.fh_size/4 -1;
497 size = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
498 fhp->fh_handle.fh_fileid_type =
499 _fh_update(dentry, fhp->fh_export, datap, &size);
500 fhp->fh_handle.fh_size += size*4;
501 if (fhp->fh_handle.fh_fileid_type == 255)
502 return nfserr_opnotsupp;
503 }
504out:
505 return 0;
506
507out_bad:
508 printk(KERN_ERR "fh_update: fh not verified!\n");
509 goto out;
510out_negative:
511 printk(KERN_ERR "fh_update: %s/%s still negative!\n",
512 dentry->d_parent->d_name.name, dentry->d_name.name);
513 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
515
516/*
517 * Release a file handle.
518 */
519void
520fh_put(struct svc_fh *fhp)
521{
522 struct dentry * dentry = fhp->fh_dentry;
523 struct svc_export * exp = fhp->fh_export;
524 if (dentry) {
525 fh_unlock(fhp);
526 fhp->fh_dentry = NULL;
527 dput(dentry);
528#ifdef CONFIG_NFSD_V3
529 fhp->fh_pre_saved = 0;
530 fhp->fh_post_saved = 0;
531#endif
532 nfsd_nr_put++;
533 }
534 if (exp) {
NeilBrownbaab9352006-03-27 01:15:09 -0800535 cache_put(&exp->h, &svc_export_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 fhp->fh_export = NULL;
537 }
538 return;
539}
540
541/*
542 * Shorthand for dprintk()'s
543 */
544char * SVCFH_fmt(struct svc_fh *fhp)
545{
546 struct knfsd_fh *fh = &fhp->fh_handle;
547
548 static char buf[80];
549 sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
550 fh->fh_size,
551 fh->fh_base.fh_pad[0],
552 fh->fh_base.fh_pad[1],
553 fh->fh_base.fh_pad[2],
554 fh->fh_base.fh_pad[3],
555 fh->fh_base.fh_pad[4],
556 fh->fh_base.fh_pad[5]);
557 return buf;
558}
NeilBrownaf6a4e22007-02-14 00:33:12 -0800559
560enum fsid_source fsid_source(struct svc_fh *fhp)
561{
562 if (fhp->fh_handle.fh_version != 1)
563 return FSIDSOURCE_DEV;
564 switch(fhp->fh_handle.fh_fsid_type) {
565 case FSID_DEV:
566 case FSID_ENCODE_DEV:
567 case FSID_MAJOR_MINOR:
568 return FSIDSOURCE_DEV;
569 case FSID_NUM:
570 return FSIDSOURCE_FSID;
571 default:
572 if (fhp->fh_export->ex_flags & NFSEXP_FSID)
573 return FSIDSOURCE_FSID;
574 else
575 return FSIDSOURCE_UUID;
576 }
577}