Linux-2.4.0-test2
[davej-history.git] / fs / nfsd / vfs.c
blob40f1ab85aa2ccdf3920ddca1c25f920f4671c0f1
1 /*
2 * linux/fs/nfsd/vfs.c
4 * File operations used by nfsd. Some of these have been ripped from
5 * other parts of the kernel because they weren't in ksyms.c, others
6 * are partial duplicates with added or changed functionality.
8 * Note that several functions dget() the dentry upon which they want
9 * to act, most notably those that create directory entries. Response
10 * dentry's are dput()'d if necessary in the release callback.
11 * So if you notice code paths that apparently fail to dput() the
12 * dentry, don't worry--they have been taken care of.
14 * Copyright (C) 1995-1999 Olaf Kirch <okir@monad.swb.de>
17 #include <linux/config.h>
18 #include <linux/version.h>
19 #include <linux/string.h>
20 #include <linux/sched.h>
21 #include <linux/errno.h>
22 #include <linux/locks.h>
23 #include <linux/fs.h>
24 #include <linux/major.h>
25 #include <linux/ext2_fs.h>
26 #include <linux/proc_fs.h>
27 #include <linux/stat.h>
28 #include <linux/fcntl.h>
29 #include <linux/net.h>
30 #include <linux/unistd.h>
31 #include <linux/malloc.h>
32 #include <linux/in.h>
33 #define __NO_VERSION__
34 #include <linux/module.h>
36 #include <linux/sunrpc/svc.h>
37 #include <linux/nfsd/nfsd.h>
38 #ifdef CONFIG_NFSD_V3
39 #include <linux/nfs3.h>
40 #include <linux/nfsd/xdr3.h>
41 #endif /* CONFIG_NFSD_V3 */
42 #include <linux/nfsd/nfsfh.h>
43 #include <linux/quotaops.h>
45 #include <asm/uaccess.h>
47 #define NFSDDBG_FACILITY NFSDDBG_FILEOP
48 #define NFSD_PARANOIA
51 /* We must ignore files (but only files) which might have mandatory
52 * locks on them because there is no way to know if the accesser has
53 * the lock.
55 #define IS_ISMNDLK(i) (S_ISREG((i)->i_mode) && MANDATORY_LOCK(i))
58 * This is a cache of readahead params that help us choose the proper
59 * readahead strategy. Initially, we set all readahead parameters to 0
60 * and let the VFS handle things.
61 * If you increase the number of cached files very much, you'll need to
62 * add a hash table here.
64 struct raparms {
65 struct raparms *p_next;
66 unsigned int p_count;
67 ino_t p_ino;
68 dev_t p_dev;
69 unsigned long p_reada,
70 p_ramax,
71 p_raend,
72 p_ralen,
73 p_rawin;
76 static struct raparms * raparml = NULL;
77 static struct raparms * raparm_cache = NULL;
80 * Look up one component of a pathname.
81 * N.B. After this call _both_ fhp and resfh need an fh_put
83 * If the lookup would cross a mountpoint, and the mounted filesystem
84 * is exported to the client with NFSEXP_CROSSMNT, then the lookup is
85 * accepted as it stands and the mounted directory is
86 * returned. Otherwise the covered directory is returned.
87 * NOTE: this mountpoint crossing is not supported properly by all
88 * clients and is explicitly disallowed for NFSv3
89 * NeilBrown <neilb@cse.unsw.edu.au>
91 int
92 nfsd_lookup(struct svc_rqst *rqstp, struct svc_fh *fhp, const char *name,
93 int len, struct svc_fh *resfh)
95 struct svc_export *exp;
96 struct dentry *dparent;
97 struct dentry *dentry;
98 int err;
100 dprintk("nfsd: nfsd_lookup(fh %s, %s)\n", SVCFH_fmt(fhp), name);
102 /* Obtain dentry and export. */
103 err = fh_verify(rqstp, fhp, S_IFDIR, MAY_EXEC);
104 if (err)
105 goto out;
107 dparent = fhp->fh_dentry;
108 exp = fhp->fh_export;
110 err = nfserr_acces;
112 /* Lookup the name, but don't follow links */
113 if (strcmp(name, ".")==0) {
114 dentry = dget(dparent);
115 } else if (strcmp(name, "..")==0) {
116 /* checking mountpoint crossing is very different when stepping up */
117 if (dparent == exp->ex_dentry) {
118 if (!EX_CROSSMNT(exp))
119 dentry = dget(dparent); /* .. == . just like at / */
120 else
122 struct svc_export *exp2 = NULL;
123 struct dentry *dp;
124 struct vfsmount *mnt = mntget(exp->ex_mnt);
125 dentry = dget(dparent);
126 while(follow_up(&mnt, &dentry))
128 dp = dget(dentry->d_parent);
129 dput(dentry);
130 dentry = dp;
131 for ( ; exp2 == NULL && dp->d_parent != dp;
132 dp=dp->d_parent)
133 exp2 = exp_get(exp->ex_client, dp->d_inode->i_dev, dp->d_inode->i_ino);
134 if (exp2==NULL) {
135 dput(dentry);
136 dentry = dget(dparent);
137 } else {
138 exp = exp2;
140 mntput(mnt);
142 } else
143 dentry = dget(dparent->d_parent);
144 } else {
145 dentry = lookup_one(name, dparent);
146 err = PTR_ERR(dentry);
147 if (IS_ERR(dentry))
148 goto out_nfserr;
150 * check if we have crossed a mount point ...
152 if (d_mountpoint(dentry)) {
153 struct svc_export *exp2 = NULL;
154 struct vfsmount *mnt = mntget(exp->ex_mnt);
155 struct dentry *mounts = dget(dentry);
156 while (follow_down(&mnt,&mounts)&&d_mountpoint(mounts))
158 exp2 = exp_get(rqstp->rq_client,
159 mounts->d_inode->i_dev,
160 mounts->d_inode->i_ino);
161 if (exp2 && EX_CROSSMNT(exp2)) {
162 /* successfully crossed mount point */
163 exp = exp2;
164 dput(dentry);
165 dentry = mounts;
166 } else
167 dput(mounts);
171 * Note: we compose the file handle now, but as the
172 * dentry may be negative, it may need to be updated.
174 err = fh_compose(resfh, exp, dentry);
175 if (!err && !dentry->d_inode)
176 err = nfserr_noent;
177 out:
178 return err;
180 out_nfserr:
181 err = nfserrno(err);
182 goto out;
186 * Set various file attributes.
187 * N.B. After this call fhp needs an fh_put
190 nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap)
192 struct dentry *dentry;
193 struct inode *inode;
194 int accmode = MAY_SATTR;
195 int ftype = 0;
196 int imode;
197 int err;
198 kernel_cap_t saved_cap = 0;
199 int size_change = 0;
201 if (iap->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_SIZE))
202 accmode |= MAY_WRITE|MAY_OWNER_OVERRIDE;
203 if (iap->ia_valid & ATTR_SIZE)
204 ftype = S_IFREG;
206 /* Get inode */
207 err = fh_verify(rqstp, fhp, ftype, accmode);
208 if (err || !iap->ia_valid)
209 goto out;
211 dentry = fhp->fh_dentry;
212 inode = dentry->d_inode;
214 err = inode_change_ok(inode, iap);
215 /* could be a "touch" (utimes) request where the user is not the owner but does
216 * have write permission. In this case the user should be allowed to set
217 * both times to the current time. We could just assume any such SETATTR
218 * is intended to set the times to "now", but we do a couple of simple tests
219 * to increase our confidence.
221 #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
222 #define MAX_TOUCH_TIME_ERROR (30*60)
223 if (err
224 && (iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET
225 && iap->ia_mtime == iap->ia_ctime
227 /* looks good. now just make sure time is in the right ballpark.
228 * solaris, at least, doesn't seem to care what the time request is
230 time_t delta = iap->ia_atime - CURRENT_TIME;
231 if (delta<0) delta = -delta;
232 if (delta < MAX_TOUCH_TIME_ERROR) {
233 /* turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME
234 * this will cause notify_change to set these times to "now"
236 iap->ia_valid &= ~BOTH_TIME_SET;
237 err = inode_change_ok(inode, iap);
241 if (err)
242 goto out_nfserr;
244 /* The size case is special. It changes the file as well as the attributes. */
245 if (iap->ia_valid & ATTR_SIZE) {
246 if (iap->ia_size < inode->i_size) {
247 err = nfsd_permission(fhp->fh_export, dentry, MAY_TRUNC|MAY_OWNER_OVERRIDE);
248 if (err)
249 goto out;
251 err = get_write_access(inode);
252 if (err)
253 goto out_nfserr;
255 err = locks_verify_truncate(inode, NULL, iap->ia_size);
256 if (err)
257 goto out_nfserr;
258 DQUOT_INIT(inode);
261 imode = inode->i_mode;
262 if (iap->ia_valid & ATTR_MODE) {
263 iap->ia_mode &= S_IALLUGO;
264 imode = iap->ia_mode |= (imode & ~S_IALLUGO);
267 /* Revoke setuid/setgid bit on chown/chgrp */
268 if ((iap->ia_valid & ATTR_UID) && (imode & S_ISUID)
269 && iap->ia_uid != inode->i_uid) {
270 iap->ia_valid |= ATTR_MODE;
271 iap->ia_mode = imode &= ~S_ISUID;
273 if ((iap->ia_valid & ATTR_GID) && (imode & S_ISGID)
274 && iap->ia_gid != inode->i_gid) {
275 iap->ia_valid |= ATTR_MODE;
276 iap->ia_mode = imode &= ~S_ISGID;
279 /* Change the attributes. */
282 iap->ia_valid |= ATTR_CTIME;
283 if (current->fsuid != 0) {
284 saved_cap = current->cap_effective;
285 cap_clear(current->cap_effective);
287 #ifdef CONFIG_QUOTA
288 /* DQUOT_TRANSFER needs both ia_uid and ia_gid defined */
289 if (iap->ia_valid & (ATTR_UID|ATTR_GID)) {
290 if (! (iap->ia_valid & ATTR_UID))
291 iap->ia_uid = inode->i_uid;
292 if (! (iap->ia_valid & ATTR_GID))
293 iap->ia_gid = inode->i_gid;
294 iap->ia_valid |= ATTR_UID|ATTR_GID;
296 #endif /* CONFIG_QUOTA */
298 if (iap->ia_valid & ATTR_SIZE) {
299 fh_lock(fhp);
300 size_change = 1;
302 #ifdef CONFIG_QUOTA
303 if (iap->ia_valid & (ATTR_UID|ATTR_GID))
304 err = DQUOT_TRANSFER(dentry, iap);
305 else
306 #endif
307 err = notify_change(dentry, iap);
308 if (size_change) {
309 fh_unlock(fhp);
310 put_write_access(inode);
312 if (current->fsuid != 0)
313 current->cap_effective = saved_cap;
314 if (err)
315 goto out_nfserr;
316 if (EX_ISSYNC(fhp->fh_export))
317 write_inode_now(inode);
318 err = 0;
320 /* Don't unlock inode; the nfssvc_release functions are supposed
321 * to do this. */
322 out:
323 return err;
325 out_nfserr:
326 err = nfserrno(err);
327 goto out;
330 #ifdef CONFIG_NFSD_V3
332 * Check server access rights to a file system object
334 struct accessmap {
335 u32 access;
336 int how;
338 static struct accessmap nfs3_regaccess[] = {
339 { NFS3_ACCESS_READ, MAY_READ },
340 { NFS3_ACCESS_EXECUTE, MAY_EXEC },
341 { NFS3_ACCESS_MODIFY, MAY_WRITE|MAY_TRUNC },
342 { NFS3_ACCESS_EXTEND, MAY_WRITE },
344 { 0, 0 }
347 static struct accessmap nfs3_diraccess[] = {
348 { NFS3_ACCESS_READ, MAY_READ },
349 { NFS3_ACCESS_LOOKUP, MAY_EXEC },
350 { NFS3_ACCESS_MODIFY, MAY_EXEC|MAY_WRITE|MAY_TRUNC },
351 { NFS3_ACCESS_EXTEND, MAY_EXEC|MAY_WRITE },
352 { NFS3_ACCESS_DELETE, MAY_REMOVE },
354 { 0, 0 }
357 static struct accessmap nfs3_anyaccess[] = {
358 /* XXX: should we try to cover read/write here for clients that
359 * rely on us to do their access checking for special files? */
361 { 0, 0 }
365 nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access)
367 struct accessmap *map;
368 struct svc_export *export;
369 struct dentry *dentry;
370 u32 query, result = 0;
371 unsigned int error;
373 error = fh_verify(rqstp, fhp, 0, MAY_NOP);
374 if (error)
375 goto out;
377 export = fhp->fh_export;
378 dentry = fhp->fh_dentry;
380 if (S_ISREG(dentry->d_inode->i_mode))
381 map = nfs3_regaccess;
382 else if (S_ISDIR(dentry->d_inode->i_mode))
383 map = nfs3_diraccess;
384 else
385 map = nfs3_anyaccess;
388 query = *access;
389 for (; map->access; map++) {
390 if (map->access & query) {
391 unsigned int err2;
392 err2 = nfsd_permission(export, dentry, map->how);
393 switch (err2) {
394 case nfs_ok:
395 result |= map->access;
396 break;
398 /* the following error codes just mean the access was not allowed,
399 * rather than an error occurred */
400 case nfserr_rofs:
401 case nfserr_acces:
402 case nfserr_perm:
403 /* simply don't "or" in the access bit. */
404 break;
405 default:
406 error = err2;
407 goto out;
411 *access = result;
413 out:
414 return error;
416 #endif
421 * Open an existing file or directory.
422 * The access argument indicates the type of open (read/write/lock)
423 * N.B. After this call fhp needs an fh_put
426 nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
427 int access, struct file *filp)
429 struct dentry *dentry;
430 struct inode *inode;
431 int err;
433 /* If we get here, then the client has already done an "open", and (hopefully)
434 * checked permission - so allow OWNER_OVERRIDE in case a chmod has now revoked
435 * permission */
436 err = fh_verify(rqstp, fhp, type, access | MAY_OWNER_OVERRIDE);
437 if (err)
438 goto out;
440 dentry = fhp->fh_dentry;
441 inode = dentry->d_inode;
443 /* Disallow access to files with the append-only bit set or
444 * with mandatory locking enabled
446 err = nfserr_perm;
447 if (IS_APPEND(inode) || IS_ISMNDLK(inode))
448 goto out;
449 if (!inode->i_fop)
450 goto out;
452 if ((access & MAY_WRITE) && (err = get_write_access(inode)) != 0)
453 goto out_nfserr;
455 memset(filp, 0, sizeof(*filp));
456 filp->f_op = fops_get(inode->i_fop);
457 atomic_set(&filp->f_count, 1);
458 filp->f_dentry = dentry;
459 if (access & MAY_WRITE) {
460 filp->f_flags = O_WRONLY;
461 filp->f_mode = FMODE_WRITE;
462 DQUOT_INIT(inode);
463 } else {
464 filp->f_flags = O_RDONLY;
465 filp->f_mode = FMODE_READ;
468 err = 0;
469 if (filp->f_op && filp->f_op->open) {
470 err = filp->f_op->open(inode, filp);
471 if (err) {
472 fops_put(filp->f_op);
473 if (access & MAY_WRITE)
474 put_write_access(inode);
476 /* I nearly added put_filp() call here, but this filp
477 * is really on callers stack frame. -DaveM
479 atomic_dec(&filp->f_count);
482 out_nfserr:
483 if (err)
484 err = nfserrno(err);
485 out:
486 return err;
490 * Close a file.
492 void
493 nfsd_close(struct file *filp)
495 struct dentry *dentry = filp->f_dentry;
496 struct inode *inode = dentry->d_inode;
498 if (filp->f_op && filp->f_op->release)
499 filp->f_op->release(inode, filp);
500 fops_put(filp->f_op);
501 if (filp->f_mode & FMODE_WRITE)
502 put_write_access(inode);
506 * Sync a file
507 * As this calls fsync (not fdatasync) there is no need for a write_inode
508 * after it.
510 void
511 nfsd_sync(struct file *filp)
513 dprintk("nfsd: sync file %s\n", filp->f_dentry->d_name.name);
514 down(&filp->f_dentry->d_inode->i_sem);
515 filp->f_op->fsync(filp, filp->f_dentry);
516 up(&filp->f_dentry->d_inode->i_sem);
519 void
520 nfsd_sync_dir(struct dentry *dp)
522 struct inode *inode = dp->d_inode;
523 int (*fsync) (struct file *, struct dentry *);
525 if (inode->i_fop && (fsync = inode->i_fop->fsync)) {
526 fsync(NULL, dp);
531 * Obtain the readahead parameters for the file
532 * specified by (dev, ino).
534 static inline struct raparms *
535 nfsd_get_raparms(dev_t dev, ino_t ino)
537 struct raparms *ra, **rap, **frap = NULL;
538 int depth = 0;
540 for (rap = &raparm_cache; (ra = *rap); rap = &ra->p_next) {
541 if (ra->p_ino == ino && ra->p_dev == dev)
542 goto found;
543 depth++;
544 if (ra->p_count == 0)
545 frap = rap;
547 depth = nfsdstats.ra_size*11/10;
548 if (!frap)
549 return NULL;
550 rap = frap;
551 ra = *frap;
552 memset(ra, 0, sizeof(*ra));
553 ra->p_dev = dev;
554 ra->p_ino = ino;
555 found:
556 if (rap != &raparm_cache) {
557 *rap = ra->p_next;
558 ra->p_next = raparm_cache;
559 raparm_cache = ra;
561 ra->p_count++;
562 nfsdstats.ra_depth[depth*10/nfsdstats.ra_size]++;
563 return ra;
567 * Read data from a file. count must contain the requested read count
568 * on entry. On return, *count contains the number of bytes actually read.
569 * N.B. After this call fhp needs an fh_put
572 nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
573 char *buf, unsigned long *count)
575 struct raparms *ra;
576 mm_segment_t oldfs;
577 int err;
578 struct file file;
580 err = nfsd_open(rqstp, fhp, S_IFREG, MAY_READ, &file);
581 if (err)
582 goto out;
583 err = nfserr_perm;
584 if (!file.f_op->read)
585 goto out_close;
587 /* Get readahead parameters */
588 ra = nfsd_get_raparms(fhp->fh_export->ex_dev, fhp->fh_dentry->d_inode->i_ino);
589 if (ra) {
590 file.f_reada = ra->p_reada;
591 file.f_ramax = ra->p_ramax;
592 file.f_raend = ra->p_raend;
593 file.f_ralen = ra->p_ralen;
594 file.f_rawin = ra->p_rawin;
596 file.f_pos = offset;
598 oldfs = get_fs(); set_fs(KERNEL_DS);
599 err = file.f_op->read(&file, buf, *count, &file.f_pos);
600 set_fs(oldfs);
601 nfsdstats.io_read += *count;
603 /* Write back readahead params */
604 if (ra != NULL) {
605 dprintk("nfsd: raparms %ld %ld %ld %ld %ld\n",
606 file.f_reada, file.f_ramax, file.f_raend,
607 file.f_ralen, file.f_rawin);
608 ra->p_reada = file.f_reada;
609 ra->p_ramax = file.f_ramax;
610 ra->p_raend = file.f_raend;
611 ra->p_ralen = file.f_ralen;
612 ra->p_rawin = file.f_rawin;
613 ra->p_count -= 1;
616 if (err >= 0) {
617 *count = err;
618 err = 0;
619 } else
620 err = nfserrno(err);
621 out_close:
622 nfsd_close(&file);
623 out:
624 return err;
628 * Write data to a file.
629 * The stable flag requests synchronous writes.
630 * N.B. After this call fhp needs an fh_put
633 nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
634 char *buf, unsigned long cnt, int *stablep)
636 struct svc_export *exp;
637 struct file file;
638 struct dentry *dentry;
639 struct inode *inode;
640 mm_segment_t oldfs;
641 int err = 0;
642 int stable = *stablep;
643 #ifdef CONFIG_QUOTA
644 uid_t saved_euid;
645 #endif
647 err = nfsd_open(rqstp, fhp, S_IFREG, MAY_WRITE, &file);
648 if (err)
649 goto out;
650 if (!cnt)
651 goto out_close;
652 err = nfserr_perm;
653 if (!file.f_op->write)
654 goto out_close;
656 dentry = file.f_dentry;
657 inode = dentry->d_inode;
658 exp = fhp->fh_export;
661 * Request sync writes if
662 * - the sync export option has been set, or
663 * - the client requested O_SYNC behavior (NFSv3 feature).
664 * - The file system doesn't support fsync().
665 * When gathered writes have been configured for this volume,
666 * flushing the data to disk is handled separately below.
668 #ifdef CONFIG_NFSD_V3
669 if (file.f_op->fsync == 0) {/* COMMIT3 cannot work */
670 stable = 2;
671 *stablep = 2; /* FILE_SYNC */
673 if (!EX_ISSYNC(exp))
674 stable = 0;
675 if (stable && !EX_WGATHER(exp))
676 file.f_flags |= O_SYNC;
677 #else
678 if ((stable || (stable = EX_ISSYNC(exp))) && !EX_WGATHER(exp))
679 file.f_flags |= O_SYNC;
680 #endif /* CONFIG_NFSD_V3 */
682 file.f_pos = offset; /* set write offset */
684 /* Write the data. */
685 oldfs = get_fs(); set_fs(KERNEL_DS);
686 #ifdef CONFIG_QUOTA
687 /* This is for disk quota. */
688 saved_euid = current->euid;
689 current->euid = current->fsuid;
690 err = file.f_op->write(&file, buf, cnt, &file.f_pos);
691 current->euid = saved_euid;
692 #else
693 err = file.f_op->write(&file, buf, cnt, &file.f_pos);
694 #endif
695 nfsdstats.io_write += cnt;
696 set_fs(oldfs);
698 /* clear setuid/setgid flag after write */
699 if (err >= 0 && (inode->i_mode & (S_ISUID | S_ISGID))) {
700 struct iattr ia;
701 kernel_cap_t saved_cap = 0;
703 ia.ia_valid = ATTR_MODE;
704 ia.ia_mode = inode->i_mode & ~(S_ISUID | S_ISGID);
705 if (current->fsuid != 0) {
706 saved_cap = current->cap_effective;
707 cap_clear(current->cap_effective);
709 notify_change(dentry, &ia);
710 if (current->fsuid != 0)
711 current->cap_effective = saved_cap;
714 if (err >= 0 && stable) {
715 static unsigned long last_ino = 0;
716 static kdev_t last_dev = NODEV;
719 * Gathered writes: If another process is currently
720 * writing to the file, there's a high chance
721 * this is another nfsd (triggered by a bulk write
722 * from a client's biod). Rather than syncing the
723 * file with each write request, we sleep for 10 msec.
725 * I don't know if this roughly approximates
726 * C. Juszak's idea of gathered writes, but it's a
727 * nice and simple solution (IMHO), and it seems to
728 * work:-)
730 if (EX_WGATHER(exp) && (atomic_read(&inode->i_writecount) > 1
731 || (last_ino == inode->i_ino && last_dev == inode->i_dev))) {
732 #if 0
733 interruptible_sleep_on_timeout(&inode->i_wait, 10 * HZ / 1000);
734 #else
735 dprintk("nfsd: write defer %d\n", current->pid);
736 /* FIXME: Olaf commented this out [gam3] */
737 schedule_timeout((HZ+99)/100);
738 dprintk("nfsd: write resume %d\n", current->pid);
739 #endif
742 if (inode->i_state & I_DIRTY) {
743 dprintk("nfsd: write sync %d\n", current->pid);
744 nfsd_sync(&file);
746 wake_up(&inode->i_wait);
747 last_ino = inode->i_ino;
748 last_dev = inode->i_dev;
751 dprintk("nfsd: write complete err=%d\n", err);
752 if (err >= 0)
753 err = 0;
754 else
755 err = nfserrno(err);
756 out_close:
757 nfsd_close(&file);
758 out:
759 return err;
763 #ifdef CONFIG_NFSD_V3
765 * Commit all pendig writes to stable storage.
766 * Strictly speaking, we could sync just indicated the file region here,
767 * but there's currently no way we can ask the VFS to do so.
769 * We lock the file to make sure we return full WCC data to the client.
772 nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
773 off_t offset, unsigned long count)
775 struct file file;
776 int err;
778 if ((err = nfsd_open(rqstp, fhp, S_IFREG, MAY_WRITE, &file)) != 0)
779 return err;
780 if (EX_ISSYNC(fhp->fh_export)) {
781 if (file.f_op && file.f_op->fsync) {
782 nfsd_sync(&file);
783 } else {
784 err = nfserr_notsupp;
788 nfsd_close(&file);
789 return err;
791 #endif /* CONFIG_NFSD_V3 */
794 * Create a file (regular, directory, device, fifo); UNIX sockets
795 * not yet implemented.
796 * If the response fh has been verified, the parent directory should
797 * already be locked. Note that the parent directory is left locked.
799 * N.B. Every call to nfsd_create needs an fh_put for _both_ fhp and resfhp
802 nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
803 char *fname, int flen, struct iattr *iap,
804 int type, dev_t rdev, struct svc_fh *resfhp)
806 struct dentry *dentry, *dchild;
807 struct inode *dirp;
808 int err;
810 err = nfserr_perm;
811 if (!flen)
812 goto out;
813 err = nfserr_exist;
814 if (isdotent(fname, flen))
815 goto out;
817 err = fh_verify(rqstp, fhp, S_IFDIR, MAY_CREATE);
818 if (err)
819 goto out;
821 dentry = fhp->fh_dentry;
822 dirp = dentry->d_inode;
824 err = nfserr_notdir;
825 if(!dirp->i_op || !dirp->i_op->lookup)
826 goto out;
828 * Check whether the response file handle has been verified yet.
829 * If it has, the parent directory should already be locked.
831 if (!resfhp->fh_dverified) {
832 /* called from nfsd_proc_mkdir, or possibly nfsd3_proc_create */
833 fh_lock(fhp);
834 dchild = lookup_one(fname, dentry);
835 err = PTR_ERR(dchild);
836 if (IS_ERR(dchild))
837 goto out_nfserr;
838 err = fh_compose(resfhp, fhp->fh_export, dchild);
839 if (err)
840 goto out;
841 } else {
842 /* called from nfsd_proc_create */
843 dchild = resfhp->fh_dentry;
844 if (!fhp->fh_locked) {
845 /* not actually possible */
846 printk(KERN_ERR
847 "nfsd_create: parent %s/%s not locked!\n",
848 dentry->d_parent->d_name.name,
849 dentry->d_name.name);
850 err = -EIO;
851 goto out;
855 * Make sure the child dentry is still negative ...
857 err = nfserr_exist;
858 if (dchild->d_inode) {
859 dprintk("nfsd_create: dentry %s/%s not negative!\n",
860 dentry->d_name.name, dchild->d_name.name);
861 goto out;
864 if (!(iap->ia_valid & ATTR_MODE))
865 iap->ia_mode = 0;
866 iap->ia_mode = (iap->ia_mode & S_IALLUGO) | type;
869 * Get the dir op function pointer.
871 err = nfserr_perm;
872 switch (type) {
873 case S_IFREG:
874 err = vfs_create(dirp, dchild, iap->ia_mode);
875 break;
876 case S_IFDIR:
877 err = vfs_mkdir(dirp, dchild, iap->ia_mode);
878 break;
879 case S_IFCHR:
880 case S_IFBLK:
881 case S_IFIFO:
882 case S_IFSOCK:
883 err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
884 break;
885 default:
886 printk("nfsd: bad file type %o in nfsd_create\n", type);
887 err = -EINVAL;
889 if (err < 0)
890 goto out_nfserr;
892 if (EX_ISSYNC(fhp->fh_export)) {
893 nfsd_sync_dir(dentry);
894 write_inode_now(dchild->d_inode);
898 /* Set file attributes. Mode has already been set and
899 * setting uid/gid works only for root. Irix appears to
900 * send along the gid when it tries to implement setgid
901 * directories via NFS.
903 err = 0;
904 if ((iap->ia_valid &= ~(ATTR_UID|ATTR_GID|ATTR_MODE)) != 0)
905 err = nfsd_setattr(rqstp, resfhp, iap);
907 * Update the file handle to get the new inode info.
909 if (!err)
910 err = fh_update(resfhp);
911 out:
912 return err;
914 out_nfserr:
915 err = nfserrno(err);
916 goto out;
919 #ifdef CONFIG_NFSD_V3
921 * NFSv3 version of nfsd_create
924 nfsd_create_v3(struct svc_rqst *rqstp, struct svc_fh *fhp,
925 char *fname, int flen, struct iattr *iap,
926 struct svc_fh *resfhp, int createmode, u32 *verifier)
928 struct dentry *dentry, *dchild;
929 struct inode *dirp;
930 int err;
932 err = nfserr_perm;
933 if (!flen)
934 goto out;
935 err = nfserr_exist;
936 if (isdotent(fname, flen))
937 goto out;
938 if (!(iap->ia_valid & ATTR_MODE))
939 iap->ia_mode = 0;
940 err = fh_verify(rqstp, fhp, S_IFDIR, MAY_CREATE);
941 if (err)
942 goto out;
944 dentry = fhp->fh_dentry;
945 dirp = dentry->d_inode;
947 /* Get all the sanity checks out of the way before
948 * we lock the parent. */
949 err = nfserr_notdir;
950 if(!dirp->i_op || !dirp->i_op->lookup)
951 goto out;
952 fh_lock(fhp);
955 * Compose the response file handle.
957 dchild = lookup_one(fname, dentry);
958 err = PTR_ERR(dchild);
959 if (IS_ERR(dchild))
960 goto out_nfserr;
962 err = fh_compose(resfhp, fhp->fh_export, dchild);
963 if (err)
964 goto out;
966 if (dchild->d_inode) {
967 err = 0;
969 switch (createmode) {
970 case NFS3_CREATE_UNCHECKED:
971 if (! S_ISREG(dchild->d_inode->i_mode))
972 err = nfserr_exist;
973 else {
974 iap->ia_valid &= ATTR_SIZE;
975 goto set_attr;
977 break;
978 case NFS3_CREATE_EXCLUSIVE:
979 if ( dchild->d_inode->i_mtime == verifier[0]
980 && dchild->d_inode->i_atime == verifier[1]
981 && dchild->d_inode->i_mode == S_IFREG
982 && dchild->d_inode->i_size == 0 )
983 break;
984 /* fallthru */
985 case NFS3_CREATE_GUARDED:
986 err = nfserr_exist;
988 goto out;
991 err = vfs_create(dirp, dchild, iap->ia_mode);
992 if (err < 0)
993 goto out_nfserr;
995 if (EX_ISSYNC(fhp->fh_export)) {
996 nfsd_sync_dir(dentry);
997 /* setattr will sync the child (or not) */
1001 * Update the filehandle to get the new inode info.
1003 err = fh_update(resfhp);
1004 if (err)
1005 goto out;
1007 if (createmode == NFS3_CREATE_EXCLUSIVE) {
1008 /* Cram the verifier into atime/mtime */
1009 iap->ia_valid = ATTR_MTIME|ATTR_ATIME|ATTR_MTIME_SET|ATTR_ATIME_SET;
1010 iap->ia_mtime = verifier[0];
1011 iap->ia_atime = verifier[1];
1014 /* Set file attributes. Mode has already been set and
1015 * setting uid/gid works only for root. Irix appears to
1016 * send along the gid when it tries to implement setgid
1017 * directories via NFS. Clear out all that cruft.
1019 set_attr:
1020 if ((iap->ia_valid &= ~(ATTR_UID|ATTR_GID|ATTR_MODE)) != 0)
1021 err = nfsd_setattr(rqstp, resfhp, iap);
1023 out:
1024 fh_unlock(fhp);
1025 return err;
1027 out_nfserr:
1028 err = nfserrno(err);
1029 goto out;
1031 #endif /* CONFIG_NFSD_V3 */
1034 * Read a symlink. On entry, *lenp must contain the maximum path length that
1035 * fits into the buffer. On return, it contains the true length.
1036 * N.B. After this call fhp needs an fh_put
1039 nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
1041 struct dentry *dentry;
1042 struct inode *inode;
1043 mm_segment_t oldfs;
1044 int err;
1046 err = fh_verify(rqstp, fhp, S_IFLNK, MAY_NOP);
1047 if (err)
1048 goto out;
1050 dentry = fhp->fh_dentry;
1051 inode = dentry->d_inode;
1053 err = nfserr_inval;
1054 if (!inode->i_op || !inode->i_op->readlink)
1055 goto out;
1057 UPDATE_ATIME(inode);
1058 /* N.B. Why does this call need a get_fs()??
1059 * Remove the set_fs and watch the fireworks:-) --okir
1062 oldfs = get_fs(); set_fs(KERNEL_DS);
1063 err = inode->i_op->readlink(dentry, buf, *lenp);
1064 set_fs(oldfs);
1066 if (err < 0)
1067 goto out_nfserr;
1068 *lenp = err;
1069 err = 0;
1070 out:
1071 return err;
1073 out_nfserr:
1074 err = nfserrno(err);
1075 goto out;
1079 * Create a symlink and look up its inode
1080 * N.B. After this call _both_ fhp and resfhp need an fh_put
1083 nfsd_symlink(struct svc_rqst *rqstp, struct svc_fh *fhp,
1084 char *fname, int flen,
1085 char *path, int plen,
1086 struct svc_fh *resfhp,
1087 struct iattr *iap)
1089 struct dentry *dentry, *dnew;
1090 int err, cerr;
1092 err = nfserr_noent;
1093 if (!flen || !plen)
1094 goto out;
1095 err = nfserr_exist;
1096 if (isdotent(fname, flen))
1097 goto out;
1099 err = fh_verify(rqstp, fhp, S_IFDIR, MAY_CREATE);
1100 if (err)
1101 goto out;
1102 fh_lock(fhp);
1103 dentry = fhp->fh_dentry;
1104 dnew = lookup_one(fname, dentry);
1105 err = PTR_ERR(dnew);
1106 if (IS_ERR(dnew))
1107 goto out_nfserr;
1109 err = vfs_symlink(dentry->d_inode, dnew, path);
1110 if (!err) {
1111 if (EX_ISSYNC(fhp->fh_export))
1112 nfsd_sync_dir(dentry);
1113 if (iap) {
1114 iap->ia_valid &= ATTR_MODE /* ~(ATTR_MODE|ATTR_UID|ATTR_GID)*/;
1115 if (iap->ia_valid) {
1116 iap->ia_valid |= ATTR_CTIME;
1117 iap->ia_mode = (iap->ia_mode&S_IALLUGO)
1118 | S_IFLNK;
1119 err = notify_change(dnew, iap);
1120 if (!err && EX_ISSYNC(fhp->fh_export))
1121 write_inode_now(dentry->d_inode);
1124 } else
1125 err = nfserrno(err);
1126 fh_unlock(fhp);
1128 /* Compose the fh so the dentry will be freed ... */
1129 cerr = fh_compose(resfhp, fhp->fh_export, dnew);
1130 if (err==0) err = cerr;
1131 out:
1132 return err;
1134 out_nfserr:
1135 err = nfserrno(err);
1136 goto out;
1140 * Create a hardlink
1141 * N.B. After this call _both_ ffhp and tfhp need an fh_put
1144 nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
1145 char *fname, int len, struct svc_fh *tfhp)
1147 struct dentry *ddir, *dnew, *dold;
1148 struct inode *dirp, *dest;
1149 int err;
1151 err = fh_verify(rqstp, ffhp, S_IFDIR, MAY_CREATE);
1152 if (err)
1153 goto out;
1154 err = fh_verify(rqstp, tfhp, -S_IFDIR, MAY_NOP);
1155 if (err)
1156 goto out;
1158 err = nfserr_perm;
1159 if (!len)
1160 goto out;
1161 err = nfserr_exist;
1162 if (isdotent(fname, len))
1163 goto out;
1165 fh_lock(ffhp);
1166 ddir = ffhp->fh_dentry;
1167 dirp = ddir->d_inode;
1169 dnew = lookup_one(fname, ddir);
1170 err = PTR_ERR(dnew);
1171 if (IS_ERR(dnew))
1172 goto out_nfserr;
1174 dold = tfhp->fh_dentry;
1175 dest = dold->d_inode;
1177 err = vfs_link(dold, dirp, dnew);
1178 if (!err) {
1179 if (EX_ISSYNC(ffhp->fh_export)) {
1180 nfsd_sync_dir(ddir);
1181 write_inode_now(dest);
1183 } else {
1184 if (err == -EXDEV && rqstp->rq_vers == 2)
1185 err = nfserr_acces;
1186 else
1187 err = nfserrno(err);
1190 fh_unlock(ffhp);
1191 dput(dnew);
1192 out:
1193 return err;
1195 out_nfserr:
1196 err = nfserrno(err);
1197 goto out;
1201 * Rename a file
1202 * N.B. After this call _both_ ffhp and tfhp need an fh_put
1205 nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
1206 struct svc_fh *tfhp, char *tname, int tlen)
1208 struct dentry *fdentry, *tdentry, *odentry, *ndentry;
1209 struct inode *fdir, *tdir;
1210 int err;
1212 err = fh_verify(rqstp, ffhp, S_IFDIR, MAY_REMOVE);
1213 if (err)
1214 goto out;
1215 err = fh_verify(rqstp, tfhp, S_IFDIR, MAY_CREATE);
1216 if (err)
1217 goto out;
1219 fdentry = ffhp->fh_dentry;
1220 fdir = fdentry->d_inode;
1222 tdentry = tfhp->fh_dentry;
1223 tdir = tdentry->d_inode;
1225 err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev;
1226 if (fdir->i_dev != tdir->i_dev)
1227 goto out;
1229 err = nfserr_perm;
1230 if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen))
1231 goto out;
1233 double_down(&tdir->i_sem, &fdir->i_sem);
1234 odentry = lookup_one(fname, fdentry);
1235 err = PTR_ERR(odentry);
1236 if (IS_ERR(odentry))
1237 goto out_nfserr;
1239 err = -ENOENT;
1240 if (!odentry->d_inode)
1241 goto out_dput_old;
1243 ndentry = lookup_one(tname, tdentry);
1244 err = PTR_ERR(ndentry);
1245 if (IS_ERR(ndentry))
1246 goto out_dput_old;
1248 #ifdef CONFIG_NFSD_V3
1249 /* Fill in the pre-op attr for the wcc data for both
1250 * tdir and fdir
1252 fill_pre_wcc(ffhp);
1253 fill_pre_wcc(tfhp);
1254 #endif /* CONFIG_NFSD_V3 */
1256 err = vfs_rename(fdir, odentry, tdir, ndentry);
1257 if (!err && EX_ISSYNC(tfhp->fh_export)) {
1258 nfsd_sync_dir(tdentry);
1259 nfsd_sync_dir(fdentry);
1261 #ifdef CONFIG_NFSD_V3
1262 /* Fill in the post-op attr for the wcc data for both
1263 * tdir and fdir
1265 fill_post_wcc(ffhp);
1266 fill_post_wcc(tfhp);
1267 #endif /* CONFIG_NFSD_V3 */
1268 double_up(&tdir->i_sem, &fdir->i_sem);
1269 dput(ndentry);
1271 out_dput_old:
1272 dput(odentry);
1273 if (err)
1274 goto out_nfserr;
1275 out:
1276 return err;
1278 out_nfserr:
1279 err = nfserrno(err);
1280 goto out;
1284 * Unlink a file or directory
1285 * N.B. After this call fhp needs an fh_put
1288 nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
1289 char *fname, int flen)
1291 struct dentry *dentry, *rdentry;
1292 struct inode *dirp;
1293 int err;
1295 err = nfserr_acces;
1296 if (!flen || isdotent(fname, flen))
1297 goto out;
1298 err = fh_verify(rqstp, fhp, S_IFDIR, MAY_REMOVE);
1299 if (err)
1300 goto out;
1302 fh_lock(fhp);
1303 dentry = fhp->fh_dentry;
1304 dirp = dentry->d_inode;
1306 rdentry = lookup_one(fname, dentry);
1307 err = PTR_ERR(rdentry);
1308 if (IS_ERR(rdentry))
1309 goto out_nfserr;
1311 if (!rdentry->d_inode) {
1312 dput(rdentry);
1313 err = nfserr_noent;
1314 goto out;
1317 if (type != S_IFDIR) { /* It's UNLINK */
1318 err = vfs_unlink(dirp, rdentry);
1319 } else { /* It's RMDIR */
1320 err = vfs_rmdir(dirp, rdentry);
1323 fh_unlock(fhp);
1325 dput(rdentry);
1327 if (err)
1328 goto out_nfserr;
1329 if (EX_ISSYNC(fhp->fh_export)) {
1330 down(&dentry->d_inode->i_sem);
1331 nfsd_sync_dir(dentry);
1332 up(&dentry->d_inode->i_sem);
1334 out:
1335 return err;
1337 out_nfserr:
1338 err = nfserrno(err);
1339 goto out;
1343 * Read entries from a directory.
1344 * The verifier is an NFSv3 thing we ignore for now.
1347 nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
1348 encode_dent_fn func, u32 *buffer, int *countp, u32 *verf)
1350 struct inode *inode;
1351 u32 *p;
1352 int oldlen, eof, err;
1353 struct file file;
1354 struct readdir_cd cd;
1356 err = 0;
1357 if (offset > ~(u32) 0)
1358 goto out;
1360 err = nfsd_open(rqstp, fhp, S_IFDIR, MAY_READ, &file);
1361 if (err)
1362 goto out;
1364 err = nfserr_notdir;
1365 if (!file.f_op->readdir)
1366 goto out_close;
1367 file.f_pos = offset;
1369 /* Set up the readdir context */
1370 memset(&cd, 0, sizeof(cd));
1371 cd.rqstp = rqstp;
1372 cd.buffer = buffer;
1373 cd.buflen = *countp; /* count of words */
1374 cd.dirfh = fhp;
1377 * Read the directory entries. This silly loop is necessary because
1378 * readdir() is not guaranteed to fill up the entire buffer, but
1379 * may choose to do less.
1381 inode = file.f_dentry->d_inode;
1382 down(&inode->i_sem);
1383 while (1) {
1384 oldlen = cd.buflen;
1387 dprintk("nfsd: f_op->readdir(%x/%ld @ %d) buflen = %d (%d)\n",
1388 file.f_inode->i_dev, file.f_inode->i_ino,
1389 (int) file.f_pos, (int) oldlen, (int) cd.buflen);
1391 err = file.f_op->readdir(&file, &cd, (filldir_t) func);
1392 if (err < 0)
1393 goto out_nfserr;
1394 if (oldlen == cd.buflen)
1395 break;
1396 if (cd.eob)
1397 break;
1399 up(&inode->i_sem);
1401 /* If we didn't fill the buffer completely, we're at EOF */
1402 eof = !cd.eob;
1404 if (cd.offset) {
1405 #ifdef CONFIG_NFSD_V3
1406 if (rqstp->rq_vers == 3)
1407 (void)xdr_encode_hyper(cd.offset, file.f_pos);
1408 else
1409 #endif /* CONFIG_NFSD_V3 */
1410 *cd.offset = htonl(file.f_pos);
1413 p = cd.buffer;
1414 *p++ = 0; /* no more entries */
1415 *p++ = htonl(eof); /* end of directory */
1416 *countp = (caddr_t) p - (caddr_t) buffer;
1418 dprintk("nfsd: readdir result %d bytes, eof %d offset %d\n",
1419 *countp, eof,
1420 cd.offset? ntohl(*cd.offset) : -1);
1421 err = 0;
1422 out_close:
1423 nfsd_close(&file);
1424 out:
1425 return err;
1427 out_nfserr:
1428 up(&inode->i_sem);
1429 err = nfserrno(err);
1430 goto out_close;
1434 * Get file system stats
1435 * N.B. After this call fhp needs an fh_put
1438 nfsd_statfs(struct svc_rqst *rqstp, struct svc_fh *fhp, struct statfs *stat)
1440 int err = fh_verify(rqstp, fhp, 0, MAY_NOP);
1441 if (!err && vfs_statfs(fhp->fh_dentry->d_inode->i_sb,stat))
1442 err = nfserr_io;
1443 return err;
1447 * Check for a user's access permissions to this inode.
1450 nfsd_permission(struct svc_export *exp, struct dentry *dentry, int acc)
1452 struct inode *inode = dentry->d_inode;
1453 int err;
1454 kernel_cap_t saved_cap = 0;
1456 if (acc == MAY_NOP)
1457 return 0;
1458 #if 0
1459 dprintk("nfsd: permission 0x%x%s%s%s%s%s%s%s mode 0%o%s%s%s\n",
1460 acc,
1461 (acc & MAY_READ)? " read" : "",
1462 (acc & MAY_WRITE)? " write" : "",
1463 (acc & MAY_EXEC)? " exec" : "",
1464 (acc & MAY_SATTR)? " sattr" : "",
1465 (acc & MAY_TRUNC)? " trunc" : "",
1466 (acc & MAY_LOCK)? " lock" : "",
1467 (acc & MAY_OWNER_OVERRIDE)? " owneroverride" : "",
1468 inode->i_mode,
1469 IS_IMMUTABLE(inode)? " immut" : "",
1470 IS_APPEND(inode)? " append" : "",
1471 IS_RDONLY(inode)? " ro" : "");
1472 dprintk(" owner %d/%d user %d/%d\n",
1473 inode->i_uid, inode->i_gid, current->fsuid, current->fsgid);
1474 #endif
1476 if (acc & (MAY_WRITE | MAY_SATTR | MAY_TRUNC)) {
1477 if (EX_RDONLY(exp) || IS_RDONLY(inode))
1478 return nfserr_rofs;
1479 if (/* (acc & MAY_WRITE) && */ IS_IMMUTABLE(inode))
1480 return nfserr_perm;
1482 if ((acc & MAY_TRUNC) && IS_APPEND(inode))
1483 return nfserr_perm;
1485 if (acc & MAY_LOCK) {
1486 /* If we cannot rely on authentication in NLM requests,
1487 * just allow locks, otherwise require read permission, or
1488 * ownership
1490 if (exp->ex_flags & NFSEXP_NOAUTHNLM)
1491 return 0;
1492 else
1493 acc = MAY_READ | MAY_OWNER_OVERRIDE;
1496 * The file owner always gets access permission for accesses that
1497 * would normally be checked at open time. This is to make
1498 * file access work even when the client has done a fchmod(fd, 0).
1500 * However, `cp foo bar' should fail nevertheless when bar is
1501 * readonly. A sensible way to do this might be to reject all
1502 * attempts to truncate a read-only file, because a creat() call
1503 * always implies file truncation.
1504 * ... but this isn't really fair. A process may reasonably call
1505 * ftruncate on an open file descriptor on a file with perm 000.
1506 * We must trust the client to do permission checking - using "ACCESS"
1507 * with NFSv3.
1509 if ((acc & MAY_OWNER_OVERRIDE) &&
1510 inode->i_uid == current->fsuid)
1511 return 0;
1513 if (current->fsuid != 0) {
1514 saved_cap = current->cap_effective;
1515 cap_clear(current->cap_effective);
1518 err = permission(inode, acc & (MAY_READ|MAY_WRITE|MAY_EXEC));
1520 /* Allow read access to binaries even when mode 111 */
1521 if (err == -EACCES && S_ISREG(inode->i_mode) && acc == MAY_READ)
1522 err = permission(inode, MAY_EXEC);
1524 if (current->fsuid != 0)
1525 current->cap_effective = saved_cap;
1527 return err? nfserrno(err) : 0;
1530 void
1531 nfsd_racache_shutdown(void)
1533 if (!raparm_cache)
1534 return;
1535 dprintk("nfsd: freeing readahead buffers.\n");
1536 kfree(raparml);
1537 raparm_cache = raparml = NULL;
1540 * Initialize readahead param cache
1543 nfsd_racache_init(int cache_size)
1545 int i;
1547 if (raparm_cache)
1548 return 0;
1549 raparml = kmalloc(sizeof(struct raparms) * cache_size, GFP_KERNEL);
1551 if (raparml != NULL) {
1552 dprintk("nfsd: allocating %d readahead buffers.\n",
1553 cache_size);
1554 memset(raparml, 0, sizeof(struct raparms) * cache_size);
1555 for (i = 0; i < cache_size - 1; i++) {
1556 raparml[i].p_next = raparml + i + 1;
1558 raparm_cache = raparml;
1559 } else {
1560 printk(KERN_WARNING
1561 "nfsd: Could not allocate memory read-ahead cache.\n");
1562 return -ENOMEM;
1564 nfsdstats.ra_size = cache_size;
1565 return 0;