blob: 89f9041a77825bfcd7c2195101d2d9bee46cc0f4 [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 Fields2d3bb252007-07-17 04:04:40 -0700163 error = nfserr_stale;
164 if (PTR_ERR(exp) == -ENOENT)
165 goto out;
166
167 if (IS_ERR(exp)) {
J.Bruce Fieldse0bb89e2006-12-13 00:35:25 -0800168 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /* Check if the request originated from a secure port. */
173 error = nfserr_perm;
174 if (!rqstp->rq_secure && EX_SECURE(exp)) {
Chuck Leverad06e4b2007-02-12 00:53:32 -0800175 char buf[RPC_MAX_ADDRBUFLEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 printk(KERN_WARNING
Chuck Leverad06e4b2007-02-12 00:53:32 -0800177 "nfsd: request from insecure port %s!\n",
178 svc_print_addr(rqstp, buf, sizeof(buf)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 goto out;
180 }
181
NeilBrownd1bbf142006-07-30 03:03:16 -0700182 /* Set user creds for this exportpoint */
183 error = nfserrno(nfsd_setuser(rqstp, exp));
184 if (error)
185 goto out;
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 /*
188 * Look up the dentry using the NFS file handle.
189 */
190 error = nfserr_stale;
191 if (rqstp->rq_vers > 2)
192 error = nfserr_badhandle;
193
194 if (fh->fh_version != 1) {
195 tfh[0] = fh->ofh_ino;
196 tfh[1] = fh->ofh_generation;
197 tfh[2] = fh->ofh_dirino;
198 datap = tfh;
199 data_left = 3;
200 if (fh->ofh_dirino == 0)
201 fileid_type = 1;
202 else
203 fileid_type = 2;
204 } else
205 fileid_type = fh->fh_fileid_type;
NeilBrown982aedf2007-02-14 00:33:11 -0800206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 if (fileid_type == 0)
208 dentry = dget(exp->ex_dentry);
209 else {
Christoph Hellwigd37065c2007-07-17 04:04:30 -0700210 dentry = exportfs_decode_fh(exp->ex_mnt, datap,
211 data_left, fileid_type,
212 nfsd_acceptable, exp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214 if (dentry == NULL)
215 goto out;
216 if (IS_ERR(dentry)) {
217 if (PTR_ERR(dentry) != -EINVAL)
218 error = nfserrno(PTR_ERR(dentry));
219 goto out;
220 }
NeilBrown34e9a632007-01-29 13:19:52 -0800221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 if (S_ISDIR(dentry->d_inode->i_mode) &&
223 (dentry->d_flags & DCACHE_DISCONNECTED)) {
224 printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n",
225 dentry->d_parent->d_name.name, dentry->d_name.name);
226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 fhp->fh_dentry = dentry;
229 fhp->fh_export = exp;
230 nfsd_nr_verified++;
231 } else {
232 /* just rechecking permissions
233 * (e.g. nfsproc_create calls fh_verify, then nfsd_create does as well)
234 */
235 dprintk("nfsd: fh_verify - just checking\n");
236 dentry = fhp->fh_dentry;
237 exp = fhp->fh_export;
NeilBrownd1bbf142006-07-30 03:03:16 -0700238 /* Set user creds for this exportpoint; necessary even
239 * in the "just checking" case because this may be a
240 * filehandle that was created by fh_compose, and that
241 * is about to be used in another nfsv4 compound
242 * operation */
243 error = nfserrno(nfsd_setuser(rqstp, exp));
244 if (error)
245 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247 cache_get(&exp->h);
248
J. Bruce Fields7fc90ec2006-06-30 01:56:14 -0700249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type);
251 if (error)
252 goto out;
253
254 /* Finally, check access permissions. */
255 error = nfsd_permission(exp, dentry, access);
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 if (error) {
NeilBrown34e9a632007-01-29 13:19:52 -0800258 dprintk("fh_verify: %s/%s permission failure, "
259 "acc=%x, error=%d\n",
260 dentry->d_parent->d_name.name,
261 dentry->d_name.name,
Al Virofc2dd2e2007-02-01 13:52:43 +0000262 access, ntohl(error));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264out:
265 if (exp && !IS_ERR(exp))
266 exp_put(exp);
267 if (error == nfserr_stale)
268 nfsdstats.fh_stale++;
269 return error;
270}
271
272
273/*
274 * Compose a file handle for an NFS reply.
275 *
276 * Note that when first composed, the dentry may not yet have
277 * an inode. In this case a call to fh_update should be made
278 * before the fh goes out on the wire ...
279 */
280static inline int _fh_update(struct dentry *dentry, struct svc_export *exp,
281 __u32 *datap, int *maxsize)
282{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (dentry == exp->ex_dentry) {
284 *maxsize = 0;
285 return 0;
286 }
287
Christoph Hellwigd37065c2007-07-17 04:04:30 -0700288 return exportfs_encode_fh(dentry, datap, maxsize,
289 !(exp->ex_flags & NFSEXP_NOSUBTREECHECK));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
292/*
293 * for composing old style file handles
294 */
295static inline void _fh_update_old(struct dentry *dentry,
296 struct svc_export *exp,
297 struct knfsd_fh *fh)
298{
299 fh->ofh_ino = ino_t_to_u32(dentry->d_inode->i_ino);
300 fh->ofh_generation = dentry->d_inode->i_generation;
301 if (S_ISDIR(dentry->d_inode->i_mode) ||
302 (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
303 fh->ofh_dirino = 0;
304}
305
Al Viro83b11342006-10-19 23:28:55 -0700306__be32
NeilBrown982aedf2007-02-14 00:33:11 -0800307fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
308 struct svc_fh *ref_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 /* ref_fh is a reference file handle.
NeilBrown7e405362006-06-30 01:56:12 -0700311 * if it is non-null and for the same filesystem, then we should compose
312 * a filehandle which is of the same version, where possible.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
314 * Then create a 32byte filehandle using nfs_fhbase_old
315 *
316 */
317
NeilBrownb41eeef2007-05-09 02:34:57 -0700318 u8 version;
NeilBrown982aedf2007-02-14 00:33:11 -0800319 u8 fsid_type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 struct inode * inode = dentry->d_inode;
321 struct dentry *parent = dentry->d_parent;
322 __u32 *datap;
323 dev_t ex_dev = exp->ex_dentry->d_inode->i_sb->s_dev;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800324 int root_export = (exp->ex_dentry == exp->ex_dentry->d_sb->s_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %s/%s, ino=%ld)\n",
327 MAJOR(ex_dev), MINOR(ex_dev),
328 (long) exp->ex_dentry->d_inode->i_ino,
329 parent->d_name.name, dentry->d_name.name,
330 (inode ? inode->i_ino : 0));
331
NeilBrown982aedf2007-02-14 00:33:11 -0800332 /* Choose filehandle version and fsid type based on
333 * the reference filehandle (if it is in the same export)
334 * or the export options.
335 */
NeilBrownb41eeef2007-05-09 02:34:57 -0700336 retry:
337 version = 1;
NeilBrown7e405362006-06-30 01:56:12 -0700338 if (ref_fh && ref_fh->fh_export == exp) {
NeilBrown982aedf2007-02-14 00:33:11 -0800339 version = ref_fh->fh_handle.fh_version;
NeilBrownb41eeef2007-05-09 02:34:57 -0700340 fsid_type = ref_fh->fh_handle.fh_fsid_type;
341
342 if (ref_fh == fhp)
343 fh_put(ref_fh);
344 ref_fh = NULL;
345
346 switch (version) {
347 case 0xca:
NeilBrownaf6a4e22007-02-14 00:33:12 -0800348 fsid_type = FSID_DEV;
NeilBrownb41eeef2007-05-09 02:34:57 -0700349 break;
350 case 1:
351 break;
352 default:
353 goto retry;
354 }
355
356 /* Need to check that this type works for this
357 * export point. As the fsid -> filesystem mapping
358 * was guided by user-space, there is no guarantee
359 * that the filesystem actually supports that fsid
360 * type. If it doesn't we loop around again without
361 * ref_fh set.
NeilBrown982aedf2007-02-14 00:33:11 -0800362 */
NeilBrownb41eeef2007-05-09 02:34:57 -0700363 switch(fsid_type) {
364 case FSID_DEV:
365 if (!old_valid_dev(ex_dev))
366 goto retry;
367 /* FALL THROUGH */
368 case FSID_MAJOR_MINOR:
369 case FSID_ENCODE_DEV:
370 if (!(exp->ex_dentry->d_inode->i_sb->s_type->fs_flags
371 & FS_REQUIRES_DEV))
372 goto retry;
373 break;
374 case FSID_NUM:
375 if (! (exp->ex_flags & NFSEXP_FSID))
376 goto retry;
377 break;
378 case FSID_UUID8:
379 case FSID_UUID16:
380 if (!root_export)
381 goto retry;
382 /* fall through */
383 case FSID_UUID4_INUM:
384 case FSID_UUID16_INUM:
385 if (exp->ex_uuid == NULL)
386 goto retry;
387 break;
388 }
NeilBrownaf6a4e22007-02-14 00:33:12 -0800389 } else if (exp->ex_uuid) {
390 if (fhp->fh_maxsize >= 64) {
391 if (root_export)
392 fsid_type = FSID_UUID16;
393 else
394 fsid_type = FSID_UUID16_INUM;
395 } else {
396 if (root_export)
397 fsid_type = FSID_UUID8;
398 else
399 fsid_type = FSID_UUID4_INUM;
400 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 } else if (exp->ex_flags & NFSEXP_FSID)
NeilBrownaf6a4e22007-02-14 00:33:12 -0800402 fsid_type = FSID_NUM;
NeilBrown982aedf2007-02-14 00:33:11 -0800403 else if (!old_valid_dev(ex_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 /* for newer device numbers, we must use a newer fsid format */
NeilBrownaf6a4e22007-02-14 00:33:12 -0800405 fsid_type = FSID_ENCODE_DEV;
NeilBrown982aedf2007-02-14 00:33:11 -0800406 else
NeilBrownaf6a4e22007-02-14 00:33:12 -0800407 fsid_type = FSID_DEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 if (ref_fh == fhp)
410 fh_put(ref_fh);
411
412 if (fhp->fh_locked || fhp->fh_dentry) {
413 printk(KERN_ERR "fh_compose: fh %s/%s not initialized!\n",
NeilBrown982aedf2007-02-14 00:33:11 -0800414 parent->d_name.name, dentry->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416 if (fhp->fh_maxsize < NFS_FHSIZE)
417 printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n",
NeilBrown982aedf2007-02-14 00:33:11 -0800418 fhp->fh_maxsize,
419 parent->d_name.name, dentry->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 fhp->fh_dentry = dget(dentry); /* our internal copy */
422 fhp->fh_export = exp;
423 cache_get(&exp->h);
424
NeilBrown982aedf2007-02-14 00:33:11 -0800425 if (version == 0xca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /* old style filehandle please */
427 memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
428 fhp->fh_handle.fh_size = NFS_FHSIZE;
429 fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
430 fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
431 fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
NeilBrown982aedf2007-02-14 00:33:11 -0800432 fhp->fh_handle.ofh_xino =
433 ino_t_to_u32(exp->ex_dentry->d_inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
435 if (inode)
436 _fh_update_old(dentry, exp, &fhp->fh_handle);
437 } else {
438 int len;
439 fhp->fh_handle.fh_version = 1;
440 fhp->fh_handle.fh_auth_type = 0;
441 datap = fhp->fh_handle.fh_auth+0;
NeilBrown982aedf2007-02-14 00:33:11 -0800442 fhp->fh_handle.fh_fsid_type = fsid_type;
NeilBrownaf6a4e22007-02-14 00:33:12 -0800443 mk_fsid(fsid_type, datap, ex_dev,
444 exp->ex_dentry->d_inode->i_ino,
445 exp->ex_fsid, exp->ex_uuid);
446
NeilBrown982aedf2007-02-14 00:33:11 -0800447 len = key_len(fsid_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 datap += len/4;
449 fhp->fh_handle.fh_size = 4 + len;
450
451 if (inode) {
452 int size = (fhp->fh_maxsize-len-4)/4;
453 fhp->fh_handle.fh_fileid_type =
454 _fh_update(dentry, exp, datap, &size);
455 fhp->fh_handle.fh_size += size*4;
456 }
457 if (fhp->fh_handle.fh_fileid_type == 255)
458 return nfserr_opnotsupp;
459 }
460
461 nfsd_nr_verified++;
462 return 0;
463}
464
465/*
466 * Update file handle information after changing a dentry.
467 * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
468 */
Al Viro83b11342006-10-19 23:28:55 -0700469__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470fh_update(struct svc_fh *fhp)
471{
472 struct dentry *dentry;
473 __u32 *datap;
NeilBrown982aedf2007-02-14 00:33:11 -0800474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 if (!fhp->fh_dentry)
476 goto out_bad;
477
478 dentry = fhp->fh_dentry;
479 if (!dentry->d_inode)
480 goto out_negative;
481 if (fhp->fh_handle.fh_version != 1) {
482 _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
483 } else {
484 int size;
485 if (fhp->fh_handle.fh_fileid_type != 0)
NeilBrown4c9608b2006-06-30 01:56:11 -0700486 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 datap = fhp->fh_handle.fh_auth+
488 fhp->fh_handle.fh_size/4 -1;
489 size = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
490 fhp->fh_handle.fh_fileid_type =
491 _fh_update(dentry, fhp->fh_export, datap, &size);
492 fhp->fh_handle.fh_size += size*4;
493 if (fhp->fh_handle.fh_fileid_type == 255)
494 return nfserr_opnotsupp;
495 }
496out:
497 return 0;
498
499out_bad:
500 printk(KERN_ERR "fh_update: fh not verified!\n");
501 goto out;
502out_negative:
503 printk(KERN_ERR "fh_update: %s/%s still negative!\n",
504 dentry->d_parent->d_name.name, dentry->d_name.name);
505 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506}
507
508/*
509 * Release a file handle.
510 */
511void
512fh_put(struct svc_fh *fhp)
513{
514 struct dentry * dentry = fhp->fh_dentry;
515 struct svc_export * exp = fhp->fh_export;
516 if (dentry) {
517 fh_unlock(fhp);
518 fhp->fh_dentry = NULL;
519 dput(dentry);
520#ifdef CONFIG_NFSD_V3
521 fhp->fh_pre_saved = 0;
522 fhp->fh_post_saved = 0;
523#endif
524 nfsd_nr_put++;
525 }
526 if (exp) {
NeilBrownbaab9352006-03-27 01:15:09 -0800527 cache_put(&exp->h, &svc_export_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 fhp->fh_export = NULL;
529 }
530 return;
531}
532
533/*
534 * Shorthand for dprintk()'s
535 */
536char * SVCFH_fmt(struct svc_fh *fhp)
537{
538 struct knfsd_fh *fh = &fhp->fh_handle;
539
540 static char buf[80];
541 sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
542 fh->fh_size,
543 fh->fh_base.fh_pad[0],
544 fh->fh_base.fh_pad[1],
545 fh->fh_base.fh_pad[2],
546 fh->fh_base.fh_pad[3],
547 fh->fh_base.fh_pad[4],
548 fh->fh_base.fh_pad[5]);
549 return buf;
550}
NeilBrownaf6a4e22007-02-14 00:33:12 -0800551
552enum fsid_source fsid_source(struct svc_fh *fhp)
553{
554 if (fhp->fh_handle.fh_version != 1)
555 return FSIDSOURCE_DEV;
556 switch(fhp->fh_handle.fh_fsid_type) {
557 case FSID_DEV:
558 case FSID_ENCODE_DEV:
559 case FSID_MAJOR_MINOR:
560 return FSIDSOURCE_DEV;
561 case FSID_NUM:
562 return FSIDSOURCE_FSID;
563 default:
564 if (fhp->fh_export->ex_flags & NFSEXP_FSID)
565 return FSIDSOURCE_FSID;
566 else
567 return FSIDSOURCE_UUID;
568 }
569}