blob: ecf9c361b3f5f5eb93f0af370f6609d6837b6806 [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>
Christoph Hellwiga5694252007-07-17 04:04:28 -070018#include <linux/exportfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Chuck Leverad06e4b2007-02-12 00:53:32 -080021#include <linux/sunrpc/clnt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/sunrpc/svc.h>
23#include <linux/nfsd/nfsd.h>
24
25#define NFSDDBG_FACILITY NFSDDBG_FH
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27
28static int nfsd_nr_verified;
29static int nfsd_nr_put;
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031/*
32 * our acceptability function.
33 * if NOSUBTREECHECK, accept anything
34 * if not, require that we can walk up to exp->ex_dentry
35 * doing some checks on the 'x' bits
36 */
37static int nfsd_acceptable(void *expv, struct dentry *dentry)
38{
39 struct svc_export *exp = expv;
40 int rv;
41 struct dentry *tdentry;
42 struct dentry *parent;
43
44 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
45 return 1;
46
47 tdentry = dget(dentry);
48 while (tdentry != exp->ex_dentry && ! IS_ROOT(tdentry)) {
49 /* make sure parents give x permission to user */
50 int err;
51 parent = dget_parent(tdentry);
52 err = permission(parent->d_inode, MAY_EXEC, NULL);
53 if (err < 0) {
54 dput(parent);
55 break;
56 }
57 dput(tdentry);
58 tdentry = parent;
59 }
60 if (tdentry != exp->ex_dentry)
61 dprintk("nfsd_acceptable failed at %p %s\n", tdentry, tdentry->d_name.name);
62 rv = (tdentry == exp->ex_dentry);
63 dput(tdentry);
64 return rv;
65}
66
67/* Type check. The correct error return for type mismatches does not seem to be
68 * generally agreed upon. SunOS seems to use EISDIR if file isn't S_IFREG; a
69 * comment in the NFSv3 spec says this is incorrect (implementation notes for
70 * the write call).
71 */
Al Viro83b11342006-10-19 23:28:55 -070072static inline __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -070073nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type)
74{
75 /* Type can be negative when creating hardlinks - not to a dir */
76 if (type > 0 && (mode & S_IFMT) != type) {
77 if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
78 return nfserr_symlink;
79 else if (type == S_IFDIR)
80 return nfserr_notdir;
81 else if ((mode & S_IFMT) == S_IFDIR)
82 return nfserr_isdir;
83 else
84 return nfserr_inval;
85 }
86 if (type < 0 && (mode & S_IFMT) == -type) {
87 if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
88 return nfserr_symlink;
89 else if (type == -S_IFDIR)
90 return nfserr_isdir;
91 else
92 return nfserr_notdir;
93 }
94 return 0;
95}
96
97/*
98 * Perform sanity checks on the dentry in a client's file handle.
99 *
100 * Note that the file handle dentry may need to be freed even after
101 * an error return.
102 *
103 * This is only called at the start of an nfsproc call, so fhp points to
104 * a svc_fh which is all 0 except for the over-the-wire file handle.
105 */
Al Viro83b11342006-10-19 23:28:55 -0700106__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
108{
109 struct knfsd_fh *fh = &fhp->fh_handle;
110 struct svc_export *exp = NULL;
111 struct dentry *dentry;
Al Viro83b11342006-10-19 23:28:55 -0700112 __be32 error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (!fhp->fh_dentry) {
117 __u32 *datap=NULL;
118 __u32 tfh[3]; /* filehandle fragment for oldstyle filehandles */
119 int fileid_type;
120 int data_left = fh->fh_size/4;
121
122 error = nfserr_stale;
123 if (rqstp->rq_client == NULL)
124 goto out;
125 if (rqstp->rq_vers > 2)
126 error = nfserr_badhandle;
127 if (rqstp->rq_vers == 4 && fh->fh_size == 0)
128 return nfserr_nofilehandle;
129
130 if (fh->fh_version == 1) {
131 int len;
132 datap = fh->fh_auth;
133 if (--data_left<0) goto out;
134 switch (fh->fh_auth_type) {
135 case 0: break;
136 default: goto out;
137 }
138 len = key_len(fh->fh_fsid_type) / 4;
139 if (len == 0) goto out;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800140 if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 /* deprecated, convert to type 3 */
NeilBrownaf6a4e22007-02-14 00:33:12 -0800142 len = key_len(FSID_ENCODE_DEV)/4;
143 fh->fh_fsid_type = FSID_ENCODE_DEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl(fh->fh_fsid[0]), ntohl(fh->fh_fsid[1])));
145 fh->fh_fsid[1] = fh->fh_fsid[2];
146 }
147 if ((data_left -= len)<0) goto out;
148 exp = exp_find(rqstp->rq_client, fh->fh_fsid_type, datap, &rqstp->rq_chandle);
149 datap += len;
150 } else {
151 dev_t xdev;
152 ino_t xino;
153 if (fh->fh_size != NFS_FHSIZE)
154 goto out;
155 /* assume old filehandle format */
156 xdev = old_decode_dev(fh->ofh_xdev);
157 xino = u32_to_ino_t(fh->ofh_xino);
NeilBrownaf6a4e22007-02-14 00:33:12 -0800158 mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
159 exp = exp_find(rqstp->rq_client, FSID_DEV, tfh,
160 &rqstp->rq_chandle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162
J.Bruce Fieldse0bb89e2006-12-13 00:35:25 -0800163 if (IS_ERR(exp) && (PTR_ERR(exp) == -EAGAIN
164 || PTR_ERR(exp) == -ETIMEDOUT)) {
165 error = nfserrno(PTR_ERR(exp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 goto out;
J.Bruce Fieldse0bb89e2006-12-13 00:35:25 -0800167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 error = nfserr_stale;
170 if (!exp || IS_ERR(exp))
171 goto out;
172
173 /* Check if the request originated from a secure port. */
174 error = nfserr_perm;
175 if (!rqstp->rq_secure && EX_SECURE(exp)) {
Chuck Leverad06e4b2007-02-12 00:53:32 -0800176 char buf[RPC_MAX_ADDRBUFLEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 printk(KERN_WARNING
Chuck Leverad06e4b2007-02-12 00:53:32 -0800178 "nfsd: request from insecure port %s!\n",
179 svc_print_addr(rqstp, buf, sizeof(buf)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 goto out;
181 }
182
NeilBrownd1bbf142006-07-30 03:03:16 -0700183 /* Set user creds for this exportpoint */
184 error = nfserrno(nfsd_setuser(rqstp, exp));
185 if (error)
186 goto out;
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 /*
189 * Look up the dentry using the NFS file handle.
190 */
191 error = nfserr_stale;
192 if (rqstp->rq_vers > 2)
193 error = nfserr_badhandle;
194
195 if (fh->fh_version != 1) {
196 tfh[0] = fh->ofh_ino;
197 tfh[1] = fh->ofh_generation;
198 tfh[2] = fh->ofh_dirino;
199 datap = tfh;
200 data_left = 3;
201 if (fh->ofh_dirino == 0)
202 fileid_type = 1;
203 else
204 fileid_type = 2;
205 } else
206 fileid_type = fh->fh_fileid_type;
NeilBrown982aedf2007-02-14 00:33:11 -0800207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 if (fileid_type == 0)
209 dentry = dget(exp->ex_dentry);
210 else {
Christoph Hellwigd37065c2007-07-17 04:04:30 -0700211 dentry = exportfs_decode_fh(exp->ex_mnt, datap,
212 data_left, fileid_type,
213 nfsd_acceptable, exp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215 if (dentry == NULL)
216 goto out;
217 if (IS_ERR(dentry)) {
218 if (PTR_ERR(dentry) != -EINVAL)
219 error = nfserrno(PTR_ERR(dentry));
220 goto out;
221 }
NeilBrown34e9a632007-01-29 13:19:52 -0800222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 if (S_ISDIR(dentry->d_inode->i_mode) &&
224 (dentry->d_flags & DCACHE_DISCONNECTED)) {
225 printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n",
226 dentry->d_parent->d_name.name, dentry->d_name.name);
227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 fhp->fh_dentry = dentry;
230 fhp->fh_export = exp;
231 nfsd_nr_verified++;
232 } else {
233 /* just rechecking permissions
234 * (e.g. nfsproc_create calls fh_verify, then nfsd_create does as well)
235 */
236 dprintk("nfsd: fh_verify - just checking\n");
237 dentry = fhp->fh_dentry;
238 exp = fhp->fh_export;
NeilBrownd1bbf142006-07-30 03:03:16 -0700239 /* Set user creds for this exportpoint; necessary even
240 * in the "just checking" case because this may be a
241 * filehandle that was created by fh_compose, and that
242 * is about to be used in another nfsv4 compound
243 * operation */
244 error = nfserrno(nfsd_setuser(rqstp, exp));
245 if (error)
246 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248 cache_get(&exp->h);
249
J. Bruce Fields7fc90ec2006-06-30 01:56:14 -0700250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type);
252 if (error)
253 goto out;
254
255 /* Finally, check access permissions. */
256 error = nfsd_permission(exp, dentry, access);
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (error) {
NeilBrown34e9a632007-01-29 13:19:52 -0800259 dprintk("fh_verify: %s/%s permission failure, "
260 "acc=%x, error=%d\n",
261 dentry->d_parent->d_name.name,
262 dentry->d_name.name,
Al Virofc2dd2e2007-02-01 13:52:43 +0000263 access, ntohl(error));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265out:
266 if (exp && !IS_ERR(exp))
267 exp_put(exp);
268 if (error == nfserr_stale)
269 nfsdstats.fh_stale++;
270 return error;
271}
272
273
274/*
275 * Compose a file handle for an NFS reply.
276 *
277 * Note that when first composed, the dentry may not yet have
278 * an inode. In this case a call to fh_update should be made
279 * before the fh goes out on the wire ...
280 */
281static inline int _fh_update(struct dentry *dentry, struct svc_export *exp,
282 __u32 *datap, int *maxsize)
283{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 if (dentry == exp->ex_dentry) {
285 *maxsize = 0;
286 return 0;
287 }
288
Christoph Hellwigd37065c2007-07-17 04:04:30 -0700289 return exportfs_encode_fh(dentry, datap, maxsize,
290 !(exp->ex_flags & NFSEXP_NOSUBTREECHECK));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
293/*
294 * for composing old style file handles
295 */
296static inline void _fh_update_old(struct dentry *dentry,
297 struct svc_export *exp,
298 struct knfsd_fh *fh)
299{
300 fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino);
301 fh->ofh_generation = dentry->d_inode->i_generation;
302 if (S_ISDIR(dentry->d_inode->i_mode) ||
303 (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
304 fh->ofh_dirino = 0;
305}
306
Al Viro83b11342006-10-19 23:28:55 -0700307__be32
NeilBrown982aedf2007-02-14 00:33:11 -0800308fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
309 struct svc_fh *ref_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
311 /* ref_fh is a reference file handle.
NeilBrown7e405362006-06-30 01:56:12 -0700312 * if it is non-null and for the same filesystem, then we should compose
313 * a filehandle which is of the same version, where possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
315 * Then create a 32byte filehandle using nfs_fhbase_old
316 *
317 */
318
NeilBrownb41eeef2007-05-09 02:34:57 -0700319 u8 version;
NeilBrown982aedf2007-02-14 00:33:11 -0800320 u8 fsid_type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 struct inode * inode = dentry->d_inode;
322 struct dentry *parent = dentry->d_parent;
323 __u32 *datap;
324 dev_t ex_dev = exp->ex_dentry->d_inode->i_sb->s_dev;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800325 int root_export = (exp->ex_dentry == exp->ex_dentry->d_sb->s_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %s/%s, ino=%ld)\n",
328 MAJOR(ex_dev), MINOR(ex_dev),
329 (long) exp->ex_dentry->d_inode->i_ino,
330 parent->d_name.name, dentry->d_name.name,
331 (inode ? inode->i_ino : 0));
332
NeilBrown982aedf2007-02-14 00:33:11 -0800333 /* Choose filehandle version and fsid type based on
334 * the reference filehandle (if it is in the same export)
335 * or the export options.
336 */
NeilBrownb41eeef2007-05-09 02:34:57 -0700337 retry:
338 version = 1;
NeilBrown7e405362006-06-30 01:56:12 -0700339 if (ref_fh && ref_fh->fh_export == exp) {
NeilBrown982aedf2007-02-14 00:33:11 -0800340 version = ref_fh->fh_handle.fh_version;
NeilBrownb41eeef2007-05-09 02:34:57 -0700341 fsid_type = ref_fh->fh_handle.fh_fsid_type;
342
343 if (ref_fh == fhp)
344 fh_put(ref_fh);
345 ref_fh = NULL;
346
347 switch (version) {
348 case 0xca:
NeilBrownaf6a4e22007-02-14 00:33:12 -0800349 fsid_type = FSID_DEV;
NeilBrownb41eeef2007-05-09 02:34:57 -0700350 break;
351 case 1:
352 break;
353 default:
354 goto retry;
355 }
356
357 /* Need to check that this type works for this
358 * export point. As the fsid -> filesystem mapping
359 * was guided by user-space, there is no guarantee
360 * that the filesystem actually supports that fsid
361 * type. If it doesn't we loop around again without
362 * ref_fh set.
NeilBrown982aedf2007-02-14 00:33:11 -0800363 */
NeilBrownb41eeef2007-05-09 02:34:57 -0700364 switch(fsid_type) {
365 case FSID_DEV:
366 if (!old_valid_dev(ex_dev))
367 goto retry;
368 /* FALL THROUGH */
369 case FSID_MAJOR_MINOR:
370 case FSID_ENCODE_DEV:
371 if (!(exp->ex_dentry->d_inode->i_sb->s_type->fs_flags
372 & FS_REQUIRES_DEV))
373 goto retry;
374 break;
375 case FSID_NUM:
376 if (! (exp->ex_flags & NFSEXP_FSID))
377 goto retry;
378 break;
379 case FSID_UUID8:
380 case FSID_UUID16:
381 if (!root_export)
382 goto retry;
383 /* fall through */
384 case FSID_UUID4_INUM:
385 case FSID_UUID16_INUM:
386 if (exp->ex_uuid == NULL)
387 goto retry;
388 break;
389 }
NeilBrownaf6a4e22007-02-14 00:33:12 -0800390 } else if (exp->ex_uuid) {
391 if (fhp->fh_maxsize >= 64) {
392 if (root_export)
393 fsid_type = FSID_UUID16;
394 else
395 fsid_type = FSID_UUID16_INUM;
396 } else {
397 if (root_export)
398 fsid_type = FSID_UUID8;
399 else
400 fsid_type = FSID_UUID4_INUM;
401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 } else if (exp->ex_flags & NFSEXP_FSID)
NeilBrownaf6a4e22007-02-14 00:33:12 -0800403 fsid_type = FSID_NUM;
NeilBrown982aedf2007-02-14 00:33:11 -0800404 else if (!old_valid_dev(ex_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 /* for newer device numbers, we must use a newer fsid format */
NeilBrownaf6a4e22007-02-14 00:33:12 -0800406 fsid_type = FSID_ENCODE_DEV;
NeilBrown982aedf2007-02-14 00:33:11 -0800407 else
NeilBrownaf6a4e22007-02-14 00:33:12 -0800408 fsid_type = FSID_DEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 if (ref_fh == fhp)
411 fh_put(ref_fh);
412
413 if (fhp->fh_locked || fhp->fh_dentry) {
414 printk(KERN_ERR "fh_compose: fh %s/%s not initialized!\n",
NeilBrown982aedf2007-02-14 00:33:11 -0800415 parent->d_name.name, dentry->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417 if (fhp->fh_maxsize < NFS_FHSIZE)
418 printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n",
NeilBrown982aedf2007-02-14 00:33:11 -0800419 fhp->fh_maxsize,
420 parent->d_name.name, dentry->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 fhp->fh_dentry = dget(dentry); /* our internal copy */
423 fhp->fh_export = exp;
424 cache_get(&exp->h);
425
NeilBrown982aedf2007-02-14 00:33:11 -0800426 if (version == 0xca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 /* old style filehandle please */
428 memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
429 fhp->fh_handle.fh_size = NFS_FHSIZE;
430 fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
431 fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
432 fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
NeilBrown982aedf2007-02-14 00:33:11 -0800433 fhp->fh_handle.ofh_xino =
434 ino_t_to_u32(exp->ex_dentry->d_inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
436 if (inode)
437 _fh_update_old(dentry, exp, &fhp->fh_handle);
438 } else {
439 int len;
440 fhp->fh_handle.fh_version = 1;
441 fhp->fh_handle.fh_auth_type = 0;
442 datap = fhp->fh_handle.fh_auth+0;
NeilBrown982aedf2007-02-14 00:33:11 -0800443 fhp->fh_handle.fh_fsid_type = fsid_type;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800444 mk_fsid(fsid_type, datap, ex_dev,
445 exp->ex_dentry->d_inode->i_ino,
446 exp->ex_fsid, exp->ex_uuid);
447
NeilBrown982aedf2007-02-14 00:33:11 -0800448 len = key_len(fsid_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 datap += len/4;
450 fhp->fh_handle.fh_size = 4 + len;
451
452 if (inode) {
453 int size = (fhp->fh_maxsize-len-4)/4;
454 fhp->fh_handle.fh_fileid_type =
455 _fh_update(dentry, exp, datap, &size);
456 fhp->fh_handle.fh_size += size*4;
457 }
458 if (fhp->fh_handle.fh_fileid_type == 255)
459 return nfserr_opnotsupp;
460 }
461
462 nfsd_nr_verified++;
463 return 0;
464}
465
466/*
467 * Update file handle information after changing a dentry.
468 * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
469 */
Al Viro83b11342006-10-19 23:28:55 -0700470__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471fh_update(struct svc_fh *fhp)
472{
473 struct dentry *dentry;
474 __u32 *datap;
NeilBrown982aedf2007-02-14 00:33:11 -0800475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 if (!fhp->fh_dentry)
477 goto out_bad;
478
479 dentry = fhp->fh_dentry;
480 if (!dentry->d_inode)
481 goto out_negative;
482 if (fhp->fh_handle.fh_version != 1) {
483 _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
484 } else {
485 int size;
486 if (fhp->fh_handle.fh_fileid_type != 0)
NeilBrown4c9608b2006-06-30 01:56:11 -0700487 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 datap = fhp->fh_handle.fh_auth+
489 fhp->fh_handle.fh_size/4 -1;
490 size = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
491 fhp->fh_handle.fh_fileid_type =
492 _fh_update(dentry, fhp->fh_export, datap, &size);
493 fhp->fh_handle.fh_size += size*4;
494 if (fhp->fh_handle.fh_fileid_type == 255)
495 return nfserr_opnotsupp;
496 }
497out:
498 return 0;
499
500out_bad:
501 printk(KERN_ERR "fh_update: fh not verified!\n");
502 goto out;
503out_negative:
504 printk(KERN_ERR "fh_update: %s/%s still negative!\n",
505 dentry->d_parent->d_name.name, dentry->d_name.name);
506 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507}
508
509/*
510 * Release a file handle.
511 */
512void
513fh_put(struct svc_fh *fhp)
514{
515 struct dentry * dentry = fhp->fh_dentry;
516 struct svc_export * exp = fhp->fh_export;
517 if (dentry) {
518 fh_unlock(fhp);
519 fhp->fh_dentry = NULL;
520 dput(dentry);
521#ifdef CONFIG_NFSD_V3
522 fhp->fh_pre_saved = 0;
523 fhp->fh_post_saved = 0;
524#endif
525 nfsd_nr_put++;
526 }
527 if (exp) {
NeilBrownbaab9352006-03-27 01:15:09 -0800528 cache_put(&exp->h, &svc_export_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 fhp->fh_export = NULL;
530 }
531 return;
532}
533
534/*
535 * Shorthand for dprintk()'s
536 */
537char * SVCFH_fmt(struct svc_fh *fhp)
538{
539 struct knfsd_fh *fh = &fhp->fh_handle;
540
541 static char buf[80];
542 sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
543 fh->fh_size,
544 fh->fh_base.fh_pad[0],
545 fh->fh_base.fh_pad[1],
546 fh->fh_base.fh_pad[2],
547 fh->fh_base.fh_pad[3],
548 fh->fh_base.fh_pad[4],
549 fh->fh_base.fh_pad[5]);
550 return buf;
551}
NeilBrownaf6a4e22007-02-14 00:33:12 -0800552
553enum fsid_source fsid_source(struct svc_fh *fhp)
554{
555 if (fhp->fh_handle.fh_version != 1)
556 return FSIDSOURCE_DEV;
557 switch(fhp->fh_handle.fh_fsid_type) {
558 case FSID_DEV:
559 case FSID_ENCODE_DEV:
560 case FSID_MAJOR_MINOR:
561 return FSIDSOURCE_DEV;
562 case FSID_NUM:
563 return FSIDSOURCE_FSID;
564 default:
565 if (fhp->fh_export->ex_flags & NFSEXP_FSID)
566 return FSIDSOURCE_FSID;
567 else
568 return FSIDSOURCE_UUID;
569 }
570}