blob: 8d2b49914843c91957b9c5b6cf1dad3b5ecb6b9e [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>
Andy Adamson32c1eb02007-07-17 04:04:48 -070023#include <linux/sunrpc/svcauth_gss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/nfsd/nfsd.h>
25
26#define NFSDDBG_FACILITY NFSDDBG_FH
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28
29static int nfsd_nr_verified;
30static int nfsd_nr_put;
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/*
33 * our acceptability function.
34 * if NOSUBTREECHECK, accept anything
35 * if not, require that we can walk up to exp->ex_dentry
36 * doing some checks on the 'x' bits
37 */
38static int nfsd_acceptable(void *expv, struct dentry *dentry)
39{
40 struct svc_export *exp = expv;
41 int rv;
42 struct dentry *tdentry;
43 struct dentry *parent;
44
45 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
46 return 1;
47
48 tdentry = dget(dentry);
49 while (tdentry != exp->ex_dentry && ! IS_ROOT(tdentry)) {
50 /* make sure parents give x permission to user */
51 int err;
52 parent = dget_parent(tdentry);
53 err = permission(parent->d_inode, MAY_EXEC, NULL);
54 if (err < 0) {
55 dput(parent);
56 break;
57 }
58 dput(tdentry);
59 tdentry = parent;
60 }
61 if (tdentry != exp->ex_dentry)
62 dprintk("nfsd_acceptable failed at %p %s\n", tdentry, tdentry->d_name.name);
63 rv = (tdentry == exp->ex_dentry);
64 dput(tdentry);
65 return rv;
66}
67
68/* Type check. The correct error return for type mismatches does not seem to be
69 * generally agreed upon. SunOS seems to use EISDIR if file isn't S_IFREG; a
70 * comment in the NFSv3 spec says this is incorrect (implementation notes for
71 * the write call).
72 */
Al Viro83b11342006-10-19 23:28:55 -070073static inline __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -070074nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type)
75{
76 /* Type can be negative when creating hardlinks - not to a dir */
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_notdir;
82 else if ((mode & S_IFMT) == S_IFDIR)
83 return nfserr_isdir;
84 else
85 return nfserr_inval;
86 }
87 if (type < 0 && (mode & S_IFMT) == -type) {
88 if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
89 return nfserr_symlink;
90 else if (type == -S_IFDIR)
91 return nfserr_isdir;
92 else
93 return nfserr_notdir;
94 }
95 return 0;
96}
97
98/*
99 * Perform sanity checks on the dentry in a client's file handle.
100 *
101 * Note that the file handle dentry may need to be freed even after
102 * an error return.
103 *
104 * This is only called at the start of an nfsproc call, so fhp points to
105 * a svc_fh which is all 0 except for the over-the-wire file handle.
106 */
Al Viro83b11342006-10-19 23:28:55 -0700107__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
109{
110 struct knfsd_fh *fh = &fhp->fh_handle;
111 struct svc_export *exp = NULL;
112 struct dentry *dentry;
Al Viro83b11342006-10-19 23:28:55 -0700113 __be32 error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 if (!fhp->fh_dentry) {
118 __u32 *datap=NULL;
119 __u32 tfh[3]; /* filehandle fragment for oldstyle filehandles */
120 int fileid_type;
121 int data_left = fh->fh_size/4;
122
123 error = nfserr_stale;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 if (rqstp->rq_vers > 2)
125 error = nfserr_badhandle;
126 if (rqstp->rq_vers == 4 && fh->fh_size == 0)
127 return nfserr_nofilehandle;
128
129 if (fh->fh_version == 1) {
130 int len;
131 datap = fh->fh_auth;
132 if (--data_left<0) goto out;
133 switch (fh->fh_auth_type) {
134 case 0: break;
135 default: goto out;
136 }
137 len = key_len(fh->fh_fsid_type) / 4;
138 if (len == 0) goto out;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800139 if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /* deprecated, convert to type 3 */
NeilBrownaf6a4e22007-02-14 00:33:12 -0800141 len = key_len(FSID_ENCODE_DEV)/4;
142 fh->fh_fsid_type = FSID_ENCODE_DEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl(fh->fh_fsid[0]), ntohl(fh->fh_fsid[1])));
144 fh->fh_fsid[1] = fh->fh_fsid[2];
145 }
146 if ((data_left -= len)<0) goto out;
J. Bruce Fields0989a782007-07-17 04:04:44 -0700147 exp = rqst_exp_find(rqstp, fh->fh_fsid_type, datap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 datap += len;
149 } else {
150 dev_t xdev;
151 ino_t xino;
152 if (fh->fh_size != NFS_FHSIZE)
153 goto out;
154 /* assume old filehandle format */
155 xdev = old_decode_dev(fh->ofh_xdev);
156 xino = u32_to_ino_t(fh->ofh_xino);
NeilBrownaf6a4e22007-02-14 00:33:12 -0800157 mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
J. Bruce Fields0989a782007-07-17 04:04:44 -0700158 exp = rqst_exp_find(rqstp, FSID_DEV, tfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160
J. Bruce Fields2d3bb252007-07-17 04:04:40 -0700161 error = nfserr_stale;
162 if (PTR_ERR(exp) == -ENOENT)
163 goto out;
164
165 if (IS_ERR(exp)) {
J.Bruce Fieldse0bb89e2006-12-13 00:35:25 -0800166 error = nfserrno(PTR_ERR(exp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 goto out;
J.Bruce Fieldse0bb89e2006-12-13 00:35:25 -0800168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 /* Check if the request originated from a secure port. */
171 error = nfserr_perm;
172 if (!rqstp->rq_secure && EX_SECURE(exp)) {
Chuck Leverad06e4b2007-02-12 00:53:32 -0800173 char buf[RPC_MAX_ADDRBUFLEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 printk(KERN_WARNING
Chuck Leverad06e4b2007-02-12 00:53:32 -0800175 "nfsd: request from insecure port %s!\n",
176 svc_print_addr(rqstp, buf, sizeof(buf)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 goto out;
178 }
179
NeilBrownd1bbf142006-07-30 03:03:16 -0700180 /* Set user creds for this exportpoint */
181 error = nfserrno(nfsd_setuser(rqstp, exp));
182 if (error)
183 goto out;
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 /*
186 * Look up the dentry using the NFS file handle.
187 */
188 error = nfserr_stale;
189 if (rqstp->rq_vers > 2)
190 error = nfserr_badhandle;
191
192 if (fh->fh_version != 1) {
193 tfh[0] = fh->ofh_ino;
194 tfh[1] = fh->ofh_generation;
195 tfh[2] = fh->ofh_dirino;
196 datap = tfh;
197 data_left = 3;
198 if (fh->ofh_dirino == 0)
199 fileid_type = 1;
200 else
201 fileid_type = 2;
202 } else
203 fileid_type = fh->fh_fileid_type;
NeilBrown982aedf2007-02-14 00:33:11 -0800204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 if (fileid_type == 0)
206 dentry = dget(exp->ex_dentry);
207 else {
Christoph Hellwigd37065c2007-07-17 04:04:30 -0700208 dentry = exportfs_decode_fh(exp->ex_mnt, datap,
209 data_left, fileid_type,
210 nfsd_acceptable, exp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212 if (dentry == NULL)
213 goto out;
214 if (IS_ERR(dentry)) {
215 if (PTR_ERR(dentry) != -EINVAL)
216 error = nfserrno(PTR_ERR(dentry));
217 goto out;
218 }
NeilBrown34e9a632007-01-29 13:19:52 -0800219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 if (S_ISDIR(dentry->d_inode->i_mode) &&
221 (dentry->d_flags & DCACHE_DISCONNECTED)) {
222 printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n",
223 dentry->d_parent->d_name.name, dentry->d_name.name);
224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 fhp->fh_dentry = dentry;
227 fhp->fh_export = exp;
228 nfsd_nr_verified++;
229 } else {
230 /* just rechecking permissions
231 * (e.g. nfsproc_create calls fh_verify, then nfsd_create does as well)
232 */
233 dprintk("nfsd: fh_verify - just checking\n");
234 dentry = fhp->fh_dentry;
235 exp = fhp->fh_export;
NeilBrownd1bbf142006-07-30 03:03:16 -0700236 /* Set user creds for this exportpoint; necessary even
237 * in the "just checking" case because this may be a
238 * filehandle that was created by fh_compose, and that
239 * is about to be used in another nfsv4 compound
240 * operation */
241 error = nfserrno(nfsd_setuser(rqstp, exp));
242 if (error)
243 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245 cache_get(&exp->h);
246
J. Bruce Fields7fc90ec2006-06-30 01:56:14 -0700247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type);
249 if (error)
250 goto out;
251
Andy Adamson32c1eb02007-07-17 04:04:48 -0700252 /* Check security flavor */
253 error = check_nfsd_access(exp, rqstp);
254 if (error)
255 goto out;
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 /* Finally, check access permissions. */
J. Bruce Fields0ec757d2007-07-17 04:04:48 -0700258 error = nfsd_permission(rqstp, exp, dentry, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (error) {
NeilBrown34e9a632007-01-29 13:19:52 -0800261 dprintk("fh_verify: %s/%s permission failure, "
262 "acc=%x, error=%d\n",
263 dentry->d_parent->d_name.name,
264 dentry->d_name.name,
Al Virofc2dd2e2007-02-01 13:52:43 +0000265 access, ntohl(error));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267out:
268 if (exp && !IS_ERR(exp))
269 exp_put(exp);
270 if (error == nfserr_stale)
271 nfsdstats.fh_stale++;
272 return error;
273}
274
275
276/*
277 * Compose a file handle for an NFS reply.
278 *
279 * Note that when first composed, the dentry may not yet have
280 * an inode. In this case a call to fh_update should be made
281 * before the fh goes out on the wire ...
282 */
283static inline int _fh_update(struct dentry *dentry, struct svc_export *exp,
284 __u32 *datap, int *maxsize)
285{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 if (dentry == exp->ex_dentry) {
287 *maxsize = 0;
288 return 0;
289 }
290
Christoph Hellwigd37065c2007-07-17 04:04:30 -0700291 return exportfs_encode_fh(dentry, datap, maxsize,
292 !(exp->ex_flags & NFSEXP_NOSUBTREECHECK));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
294
295/*
296 * for composing old style file handles
297 */
298static inline void _fh_update_old(struct dentry *dentry,
299 struct svc_export *exp,
300 struct knfsd_fh *fh)
301{
302 fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino);
303 fh->ofh_generation = dentry->d_inode->i_generation;
304 if (S_ISDIR(dentry->d_inode->i_mode) ||
305 (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
306 fh->ofh_dirino = 0;
307}
308
Al Viro83b11342006-10-19 23:28:55 -0700309__be32
NeilBrown982aedf2007-02-14 00:33:11 -0800310fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
311 struct svc_fh *ref_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
313 /* ref_fh is a reference file handle.
NeilBrown7e405362006-06-30 01:56:12 -0700314 * if it is non-null and for the same filesystem, then we should compose
315 * a filehandle which is of the same version, where possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
317 * Then create a 32byte filehandle using nfs_fhbase_old
318 *
319 */
320
NeilBrownb41eeef2007-05-09 02:34:57 -0700321 u8 version;
NeilBrown982aedf2007-02-14 00:33:11 -0800322 u8 fsid_type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 struct inode * inode = dentry->d_inode;
324 struct dentry *parent = dentry->d_parent;
325 __u32 *datap;
326 dev_t ex_dev = exp->ex_dentry->d_inode->i_sb->s_dev;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800327 int root_export = (exp->ex_dentry == exp->ex_dentry->d_sb->s_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %s/%s, ino=%ld)\n",
330 MAJOR(ex_dev), MINOR(ex_dev),
331 (long) exp->ex_dentry->d_inode->i_ino,
332 parent->d_name.name, dentry->d_name.name,
333 (inode ? inode->i_ino : 0));
334
NeilBrown982aedf2007-02-14 00:33:11 -0800335 /* Choose filehandle version and fsid type based on
336 * the reference filehandle (if it is in the same export)
337 * or the export options.
338 */
NeilBrownb41eeef2007-05-09 02:34:57 -0700339 retry:
340 version = 1;
NeilBrown7e405362006-06-30 01:56:12 -0700341 if (ref_fh && ref_fh->fh_export == exp) {
NeilBrown982aedf2007-02-14 00:33:11 -0800342 version = ref_fh->fh_handle.fh_version;
NeilBrownb41eeef2007-05-09 02:34:57 -0700343 fsid_type = ref_fh->fh_handle.fh_fsid_type;
344
345 if (ref_fh == fhp)
346 fh_put(ref_fh);
347 ref_fh = NULL;
348
349 switch (version) {
350 case 0xca:
NeilBrownaf6a4e22007-02-14 00:33:12 -0800351 fsid_type = FSID_DEV;
NeilBrownb41eeef2007-05-09 02:34:57 -0700352 break;
353 case 1:
354 break;
355 default:
356 goto retry;
357 }
358
359 /* Need to check that this type works for this
360 * export point. As the fsid -> filesystem mapping
361 * was guided by user-space, there is no guarantee
362 * that the filesystem actually supports that fsid
363 * type. If it doesn't we loop around again without
364 * ref_fh set.
NeilBrown982aedf2007-02-14 00:33:11 -0800365 */
NeilBrownb41eeef2007-05-09 02:34:57 -0700366 switch(fsid_type) {
367 case FSID_DEV:
368 if (!old_valid_dev(ex_dev))
369 goto retry;
370 /* FALL THROUGH */
371 case FSID_MAJOR_MINOR:
372 case FSID_ENCODE_DEV:
373 if (!(exp->ex_dentry->d_inode->i_sb->s_type->fs_flags
374 & FS_REQUIRES_DEV))
375 goto retry;
376 break;
377 case FSID_NUM:
378 if (! (exp->ex_flags & NFSEXP_FSID))
379 goto retry;
380 break;
381 case FSID_UUID8:
382 case FSID_UUID16:
383 if (!root_export)
384 goto retry;
385 /* fall through */
386 case FSID_UUID4_INUM:
387 case FSID_UUID16_INUM:
388 if (exp->ex_uuid == NULL)
389 goto retry;
390 break;
391 }
NeilBrownaf6a4e22007-02-14 00:33:12 -0800392 } else if (exp->ex_uuid) {
393 if (fhp->fh_maxsize >= 64) {
394 if (root_export)
395 fsid_type = FSID_UUID16;
396 else
397 fsid_type = FSID_UUID16_INUM;
398 } else {
399 if (root_export)
400 fsid_type = FSID_UUID8;
401 else
402 fsid_type = FSID_UUID4_INUM;
403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 } else if (exp->ex_flags & NFSEXP_FSID)
NeilBrownaf6a4e22007-02-14 00:33:12 -0800405 fsid_type = FSID_NUM;
NeilBrown982aedf2007-02-14 00:33:11 -0800406 else if (!old_valid_dev(ex_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 /* for newer device numbers, we must use a newer fsid format */
NeilBrownaf6a4e22007-02-14 00:33:12 -0800408 fsid_type = FSID_ENCODE_DEV;
NeilBrown982aedf2007-02-14 00:33:11 -0800409 else
NeilBrownaf6a4e22007-02-14 00:33:12 -0800410 fsid_type = FSID_DEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 if (ref_fh == fhp)
413 fh_put(ref_fh);
414
415 if (fhp->fh_locked || fhp->fh_dentry) {
416 printk(KERN_ERR "fh_compose: fh %s/%s not initialized!\n",
NeilBrown982aedf2007-02-14 00:33:11 -0800417 parent->d_name.name, dentry->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419 if (fhp->fh_maxsize < NFS_FHSIZE)
420 printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n",
NeilBrown982aedf2007-02-14 00:33:11 -0800421 fhp->fh_maxsize,
422 parent->d_name.name, dentry->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424 fhp->fh_dentry = dget(dentry); /* our internal copy */
425 fhp->fh_export = exp;
426 cache_get(&exp->h);
427
NeilBrown982aedf2007-02-14 00:33:11 -0800428 if (version == 0xca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* old style filehandle please */
430 memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
431 fhp->fh_handle.fh_size = NFS_FHSIZE;
432 fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
433 fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
434 fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
NeilBrown982aedf2007-02-14 00:33:11 -0800435 fhp->fh_handle.ofh_xino =
436 ino_t_to_u32(exp->ex_dentry->d_inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
438 if (inode)
439 _fh_update_old(dentry, exp, &fhp->fh_handle);
440 } else {
441 int len;
442 fhp->fh_handle.fh_version = 1;
443 fhp->fh_handle.fh_auth_type = 0;
444 datap = fhp->fh_handle.fh_auth+0;
NeilBrown982aedf2007-02-14 00:33:11 -0800445 fhp->fh_handle.fh_fsid_type = fsid_type;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800446 mk_fsid(fsid_type, datap, ex_dev,
447 exp->ex_dentry->d_inode->i_ino,
448 exp->ex_fsid, exp->ex_uuid);
449
NeilBrown982aedf2007-02-14 00:33:11 -0800450 len = key_len(fsid_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 datap += len/4;
452 fhp->fh_handle.fh_size = 4 + len;
453
454 if (inode) {
455 int size = (fhp->fh_maxsize-len-4)/4;
456 fhp->fh_handle.fh_fileid_type =
457 _fh_update(dentry, exp, datap, &size);
458 fhp->fh_handle.fh_size += size*4;
459 }
460 if (fhp->fh_handle.fh_fileid_type == 255)
461 return nfserr_opnotsupp;
462 }
463
464 nfsd_nr_verified++;
465 return 0;
466}
467
468/*
469 * Update file handle information after changing a dentry.
470 * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
471 */
Al Viro83b11342006-10-19 23:28:55 -0700472__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473fh_update(struct svc_fh *fhp)
474{
475 struct dentry *dentry;
476 __u32 *datap;
NeilBrown982aedf2007-02-14 00:33:11 -0800477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 if (!fhp->fh_dentry)
479 goto out_bad;
480
481 dentry = fhp->fh_dentry;
482 if (!dentry->d_inode)
483 goto out_negative;
484 if (fhp->fh_handle.fh_version != 1) {
485 _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
486 } else {
487 int size;
488 if (fhp->fh_handle.fh_fileid_type != 0)
NeilBrown4c9608b2006-06-30 01:56:11 -0700489 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 datap = fhp->fh_handle.fh_auth+
491 fhp->fh_handle.fh_size/4 -1;
492 size = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
493 fhp->fh_handle.fh_fileid_type =
494 _fh_update(dentry, fhp->fh_export, datap, &size);
495 fhp->fh_handle.fh_size += size*4;
496 if (fhp->fh_handle.fh_fileid_type == 255)
497 return nfserr_opnotsupp;
498 }
499out:
500 return 0;
501
502out_bad:
503 printk(KERN_ERR "fh_update: fh not verified!\n");
504 goto out;
505out_negative:
506 printk(KERN_ERR "fh_update: %s/%s still negative!\n",
507 dentry->d_parent->d_name.name, dentry->d_name.name);
508 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}
510
511/*
512 * Release a file handle.
513 */
514void
515fh_put(struct svc_fh *fhp)
516{
517 struct dentry * dentry = fhp->fh_dentry;
518 struct svc_export * exp = fhp->fh_export;
519 if (dentry) {
520 fh_unlock(fhp);
521 fhp->fh_dentry = NULL;
522 dput(dentry);
523#ifdef CONFIG_NFSD_V3
524 fhp->fh_pre_saved = 0;
525 fhp->fh_post_saved = 0;
526#endif
527 nfsd_nr_put++;
528 }
529 if (exp) {
NeilBrownbaab9352006-03-27 01:15:09 -0800530 cache_put(&exp->h, &svc_export_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 fhp->fh_export = NULL;
532 }
533 return;
534}
535
536/*
537 * Shorthand for dprintk()'s
538 */
539char * SVCFH_fmt(struct svc_fh *fhp)
540{
541 struct knfsd_fh *fh = &fhp->fh_handle;
542
543 static char buf[80];
544 sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
545 fh->fh_size,
546 fh->fh_base.fh_pad[0],
547 fh->fh_base.fh_pad[1],
548 fh->fh_base.fh_pad[2],
549 fh->fh_base.fh_pad[3],
550 fh->fh_base.fh_pad[4],
551 fh->fh_base.fh_pad[5]);
552 return buf;
553}
NeilBrownaf6a4e22007-02-14 00:33:12 -0800554
555enum fsid_source fsid_source(struct svc_fh *fhp)
556{
557 if (fhp->fh_handle.fh_version != 1)
558 return FSIDSOURCE_DEV;
559 switch(fhp->fh_handle.fh_fsid_type) {
560 case FSID_DEV:
561 case FSID_ENCODE_DEV:
562 case FSID_MAJOR_MINOR:
563 return FSIDSOURCE_DEV;
564 case FSID_NUM:
565 return FSIDSOURCE_FSID;
566 default:
567 if (fhp->fh_export->ex_flags & NFSEXP_FSID)
568 return FSIDSOURCE_FSID;
569 else
570 return FSIDSOURCE_UUID;
571 }
572}