Import 2.2.6pre1
[davej-history.git] / fs / nfs / inode.c
blob0a08b299961bc6f86fef8d59c246609fddeb513d
1 /*
2 * linux/fs/nfs/inode.c
4 * Copyright (C) 1992 Rick Sladkey
6 * nfs inode and superblock handling functions
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
16 #include <linux/config.h>
17 #include <linux/module.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
21 #include <linux/mm.h>
22 #include <linux/string.h>
23 #include <linux/stat.h>
24 #include <linux/errno.h>
25 #include <linux/locks.h>
26 #include <linux/unistd.h>
27 #include <linux/sunrpc/clnt.h>
28 #include <linux/sunrpc/stats.h>
29 #include <linux/nfs_fs.h>
30 #include <linux/lockd/bind.h>
32 #include <asm/system.h>
33 #include <asm/uaccess.h>
35 #define CONFIG_NFS_SNAPSHOT 1
36 #define NFSDBG_FACILITY NFSDBG_VFS
37 #define NFS_PARANOIA 1
39 static struct inode * __nfs_fhget(struct super_block *, struct nfs_fattr *);
41 static void nfs_read_inode(struct inode *);
42 static void nfs_put_inode(struct inode *);
43 static void nfs_delete_inode(struct inode *);
44 static int nfs_notify_change(struct dentry *, struct iattr *);
45 static void nfs_put_super(struct super_block *);
46 static void nfs_umount_begin(struct super_block *);
47 static int nfs_statfs(struct super_block *, struct statfs *, int);
49 static struct super_operations nfs_sops = {
50 nfs_read_inode, /* read inode */
51 NULL, /* write inode */
52 nfs_put_inode, /* put inode */
53 nfs_delete_inode, /* delete inode */
54 nfs_notify_change, /* notify change */
55 nfs_put_super, /* put superblock */
56 NULL, /* write superblock */
57 nfs_statfs, /* stat filesystem */
58 NULL, /* no remount */
59 NULL, /* no clear inode */
60 nfs_umount_begin /* umount attempt begin */
63 struct rpc_stat nfs_rpcstat = { &nfs_program };
66 * The "read_inode" function doesn't actually do anything:
67 * the real data is filled in later in nfs_fhget. Here we
68 * just mark the cache times invalid, and zero out i_mode
69 * (the latter makes "nfs_refresh_inode" do the right thing
70 * wrt pipe inodes)
72 static void
73 nfs_read_inode(struct inode * inode)
75 inode->i_blksize = inode->i_sb->s_blocksize;
76 inode->i_mode = 0;
77 inode->i_rdev = 0;
78 inode->i_op = NULL;
79 NFS_CACHEINV(inode);
80 NFS_ATTRTIMEO(inode) = NFS_MINATTRTIMEO(inode);
83 static void
84 nfs_put_inode(struct inode * inode)
86 dprintk("NFS: put_inode(%x/%ld)\n", inode->i_dev, inode->i_ino);
88 * We want to get rid of unused inodes ...
90 if (inode->i_count == 1)
91 inode->i_nlink = 0;
94 static void
95 nfs_delete_inode(struct inode * inode)
97 int failed;
99 dprintk("NFS: delete_inode(%x/%ld)\n", inode->i_dev, inode->i_ino);
101 * Flush out any pending write requests ...
103 if (NFS_WRITEBACK(inode) != NULL) {
104 unsigned long timeout = jiffies + 5*HZ;
105 #ifdef NFS_DEBUG_VERBOSE
106 printk("nfs_delete_inode: inode %ld has pending RPC requests\n", inode->i_ino);
107 #endif
108 nfs_inval(inode);
109 while (NFS_WRITEBACK(inode) != NULL &&
110 time_before(jiffies, timeout)) {
111 current->state = TASK_INTERRUPTIBLE;
112 schedule_timeout(HZ/10);
114 current->state = TASK_RUNNING;
115 if (NFS_WRITEBACK(inode) != NULL)
116 printk("NFS: Arghhh, stuck RPC requests!\n");
119 failed = nfs_check_failed_request(inode);
120 if (failed)
121 printk("NFS: inode %ld had %d failed requests\n",
122 inode->i_ino, failed);
123 clear_inode(inode);
126 void
127 nfs_put_super(struct super_block *sb)
129 struct nfs_server *server = &sb->u.nfs_sb.s_server;
130 struct rpc_clnt *rpc;
132 if ((rpc = server->client) != NULL)
133 rpc_shutdown_client(rpc);
135 if (!(server->flags & NFS_MOUNT_NONLM))
136 lockd_down(); /* release rpc.lockd */
137 rpciod_down(); /* release rpciod */
139 * Invalidate the dircache for this superblock.
141 nfs_invalidate_dircache_sb(sb);
143 kfree(server->hostname);
145 MOD_DEC_USE_COUNT;
148 void
149 nfs_umount_begin(struct super_block *sb)
151 struct nfs_server *server = &sb->u.nfs_sb.s_server;
152 struct rpc_clnt *rpc;
154 /* -EIO all pending I/O */
155 if ((rpc = server->client) != NULL)
156 rpc_killall_tasks(rpc);
160 * Compute and set NFS server blocksize
162 static unsigned int
163 nfs_block_size(unsigned int bsize, unsigned char *nrbitsp)
165 if (bsize < 1024)
166 bsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
167 else if (bsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
168 bsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
170 /* make sure blocksize is a power of two */
171 if ((bsize & (bsize - 1)) || nrbitsp) {
172 unsigned int nrbits;
174 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
176 bsize = 1 << nrbits;
177 if (nrbitsp)
178 *nrbitsp = nrbits;
179 if (bsize < NFS_DEF_FILE_IO_BUFFER_SIZE)
180 bsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
183 return bsize;
187 * The way this works is that the mount process passes a structure
188 * in the data argument which contains the server's IP address
189 * and the root file handle obtained from the server's mount
190 * daemon. We stash these away in the private superblock fields.
192 struct super_block *
193 nfs_read_super(struct super_block *sb, void *raw_data, int silent)
195 struct nfs_mount_data *data = (struct nfs_mount_data *) raw_data;
196 struct nfs_server *server;
197 struct rpc_xprt *xprt;
198 struct rpc_clnt *clnt;
199 struct nfs_fh *root_fh;
200 struct inode *root_inode;
201 unsigned int authflavor;
202 int tcp;
203 struct sockaddr_in srvaddr;
204 struct rpc_timeout timeparms;
205 struct nfs_fattr fattr;
207 MOD_INC_USE_COUNT;
208 if (!data)
209 goto out_miss_args;
211 if (data->version != NFS_MOUNT_VERSION) {
212 printk("nfs warning: mount version %s than kernel\n",
213 data->version < NFS_MOUNT_VERSION ? "older" : "newer");
214 if (data->version < 2)
215 data->namlen = 0;
216 if (data->version < 3)
217 data->bsize = 0;
220 /* We now require that the mount process passes the remote address */
221 memcpy(&srvaddr, &data->addr, sizeof(srvaddr));
222 if (srvaddr.sin_addr.s_addr == INADDR_ANY)
223 goto out_no_remote;
225 lock_super(sb);
227 sb->s_flags |= MS_ODD_RENAME; /* This should go away */
229 sb->s_magic = NFS_SUPER_MAGIC;
230 sb->s_op = &nfs_sops;
231 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
232 sb->u.nfs_sb.s_root = data->root;
233 server = &sb->u.nfs_sb.s_server;
234 server->rsize = nfs_block_size(data->rsize, NULL);
235 server->wsize = nfs_block_size(data->wsize, NULL);
236 server->flags = data->flags;
237 server->acregmin = data->acregmin*HZ;
238 server->acregmax = data->acregmax*HZ;
239 server->acdirmin = data->acdirmin*HZ;
240 server->acdirmax = data->acdirmax*HZ;
242 server->hostname = kmalloc(strlen(data->hostname) + 1, GFP_KERNEL);
243 if (!server->hostname)
244 goto out_unlock;
245 strcpy(server->hostname, data->hostname);
247 /* Which protocol do we use? */
248 tcp = (data->flags & NFS_MOUNT_TCP);
250 /* Initialize timeout values */
251 timeparms.to_initval = data->timeo * HZ / 10;
252 timeparms.to_retries = data->retrans;
253 timeparms.to_maxval = tcp? RPC_MAX_TCP_TIMEOUT : RPC_MAX_UDP_TIMEOUT;
254 timeparms.to_exponential = 1;
256 /* Now create transport and client */
257 xprt = xprt_create_proto(tcp? IPPROTO_TCP : IPPROTO_UDP,
258 &srvaddr, &timeparms);
259 if (xprt == NULL)
260 goto out_no_xprt;
262 /* Choose authentication flavor */
263 authflavor = RPC_AUTH_UNIX;
264 if (data->flags & NFS_MOUNT_SECURE)
265 authflavor = RPC_AUTH_DES;
266 else if (data->flags & NFS_MOUNT_KERBEROS)
267 authflavor = RPC_AUTH_KRB;
269 clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
270 NFS_VERSION, authflavor);
271 if (clnt == NULL)
272 goto out_no_client;
274 clnt->cl_intr = (data->flags & NFS_MOUNT_INTR)? 1 : 0;
275 clnt->cl_softrtry = (data->flags & NFS_MOUNT_SOFT)? 1 : 0;
276 clnt->cl_chatty = 1;
277 server->client = clnt;
279 /* Fire up rpciod if not yet running */
280 if (rpciod_up() != 0)
281 goto out_no_iod;
284 * Keep the super block locked while we try to get
285 * the root fh attributes.
287 root_fh = kmalloc(sizeof(struct nfs_fh), GFP_KERNEL);
288 if (!root_fh)
289 goto out_no_fh;
290 *root_fh = data->root;
292 if (nfs_proc_getattr(server, root_fh, &fattr) != 0)
293 goto out_no_fattr;
295 root_inode = __nfs_fhget(sb, &fattr);
296 if (!root_inode)
297 goto out_no_root;
298 sb->s_root = d_alloc_root(root_inode, NULL);
299 if (!sb->s_root)
300 goto out_no_root;
301 sb->s_root->d_op = &nfs_dentry_operations;
302 sb->s_root->d_fsdata = root_fh;
304 /* We're airborne */
305 unlock_super(sb);
307 /* Check whether to start the lockd process */
308 if (!(server->flags & NFS_MOUNT_NONLM))
309 lockd_up();
310 return sb;
312 /* Yargs. It didn't work out. */
313 out_no_root:
314 printk("nfs_read_super: get root inode failed\n");
315 iput(root_inode);
316 goto out_free_fh;
318 out_no_fattr:
319 printk("nfs_read_super: get root fattr failed\n");
320 out_free_fh:
321 kfree(root_fh);
322 out_no_fh:
323 rpciod_down();
324 goto out_shutdown;
326 out_no_iod:
327 printk(KERN_WARNING "NFS: couldn't start rpciod!\n");
328 out_shutdown:
329 rpc_shutdown_client(server->client);
330 goto out_free_host;
332 out_no_client:
333 printk(KERN_WARNING "NFS: cannot create RPC client.\n");
334 xprt_destroy(xprt);
335 goto out_free_host;
337 out_no_xprt:
338 printk(KERN_WARNING "NFS: cannot create RPC transport.\n");
340 out_free_host:
341 kfree(server->hostname);
342 out_unlock:
343 unlock_super(sb);
344 goto out_fail;
346 out_no_remote:
347 printk("NFS: mount program didn't pass remote address!\n");
348 goto out_fail;
350 out_miss_args:
351 printk("nfs_read_super: missing data argument\n");
353 out_fail:
354 sb->s_dev = 0;
355 MOD_DEC_USE_COUNT;
356 return NULL;
359 static int
360 nfs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
362 int error;
363 struct nfs_fsinfo res;
364 struct statfs tmp;
366 error = nfs_proc_statfs(&sb->u.nfs_sb.s_server, &sb->u.nfs_sb.s_root,
367 &res);
368 if (error) {
369 printk("nfs_statfs: statfs error = %d\n", -error);
370 res.bsize = res.blocks = res.bfree = res.bavail = 0;
372 tmp.f_type = NFS_SUPER_MAGIC;
373 tmp.f_bsize = res.bsize;
374 tmp.f_blocks = res.blocks;
375 tmp.f_bfree = res.bfree;
376 tmp.f_bavail = res.bavail;
377 tmp.f_files = 0;
378 tmp.f_ffree = 0;
379 tmp.f_namelen = NAME_MAX;
380 return copy_to_user(buf, &tmp, bufsiz) ? -EFAULT : 0;
384 * Free all unused dentries in an inode's alias list.
386 * Subtle note: we have to be very careful not to cause
387 * any IO operations with the stale dentries, as this
388 * could cause file corruption. But since the dentry
389 * count is 0 and all pending IO for a dentry has been
390 * flushed when the count went to 0, we're safe here.
392 void nfs_free_dentries(struct inode *inode)
394 struct list_head *tmp, *head = &inode->i_dentry;
396 restart:
397 tmp = head;
398 while ((tmp = tmp->next) != head) {
399 struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
400 printk("nfs_free_dentries: found %s/%s, d_count=%d, hashed=%d\n",
401 dentry->d_parent->d_name.name, dentry->d_name.name,
402 dentry->d_count, !list_empty(&dentry->d_hash));
403 if (!dentry->d_count) {
404 dget(dentry);
405 d_drop(dentry);
406 dput(dentry);
407 goto restart;
413 * Fill in inode information from the fattr.
415 static void
416 nfs_fill_inode(struct inode *inode, struct nfs_fattr *fattr)
419 * Check whether the mode has been set, as we only want to
420 * do this once. (We don't allow inodes to change types.)
422 if (inode->i_mode == 0) {
423 inode->i_mode = fattr->mode;
424 if (S_ISREG(inode->i_mode))
425 inode->i_op = &nfs_file_inode_operations;
426 else if (S_ISDIR(inode->i_mode))
427 inode->i_op = &nfs_dir_inode_operations;
428 else if (S_ISLNK(inode->i_mode))
429 inode->i_op = &nfs_symlink_inode_operations;
430 else if (S_ISCHR(inode->i_mode)) {
431 inode->i_op = &chrdev_inode_operations;
432 inode->i_rdev = to_kdev_t(fattr->rdev);
433 } else if (S_ISBLK(inode->i_mode)) {
434 inode->i_op = &blkdev_inode_operations;
435 inode->i_rdev = to_kdev_t(fattr->rdev);
436 } else if (S_ISFIFO(inode->i_mode))
437 init_fifo(inode);
438 else
439 inode->i_op = NULL;
441 * Preset the size and mtime, as there's no need
442 * to invalidate the caches.
444 inode->i_size = fattr->size;
445 inode->i_mtime = fattr->mtime.seconds;
446 NFS_OLDMTIME(inode) = fattr->mtime.seconds;
448 nfs_refresh_inode(inode, fattr);
452 * This is our own version of iget that looks up inodes by file handle
453 * instead of inode number. We use this technique instead of using
454 * the vfs read_inode function because there is no way to pass the
455 * file handle or current attributes into the read_inode function.
457 * We provide a special check for NetApp .snapshot directories to avoid
458 * inode aliasing problems. All snapshot inodes are anonymous (unhashed).
460 struct inode *
461 nfs_fhget(struct dentry *dentry, struct nfs_fh *fhandle,
462 struct nfs_fattr *fattr)
464 struct super_block *sb = dentry->d_sb;
466 dprintk("NFS: nfs_fhget(%s/%s fileid=%d)\n",
467 dentry->d_parent->d_name.name, dentry->d_name.name,
468 fattr->fileid);
470 /* Install the file handle in the dentry */
471 *((struct nfs_fh *) dentry->d_fsdata) = *fhandle;
473 #ifdef CONFIG_NFS_SNAPSHOT
475 * Check for NetApp snapshot dentries, and get an
476 * unhashed inode to avoid aliasing problems.
478 if ((dentry->d_parent->d_inode->u.nfs_i.flags & NFS_IS_SNAPSHOT) ||
479 (dentry->d_name.len == 9 &&
480 memcmp(dentry->d_name.name, ".snapshot", 9) == 0)) {
481 struct inode *inode = get_empty_inode();
482 if (!inode)
483 goto out;
484 inode->i_sb = sb;
485 inode->i_dev = sb->s_dev;
486 inode->i_flags = 0;
487 inode->i_ino = fattr->fileid;
488 nfs_read_inode(inode);
489 nfs_fill_inode(inode, fattr);
490 inode->u.nfs_i.flags |= NFS_IS_SNAPSHOT;
491 dprintk("NFS: nfs_fhget(snapshot ino=%ld)\n", inode->i_ino);
492 out:
493 return inode;
495 #endif
496 return __nfs_fhget(sb, fattr);
500 * Look up the inode by super block and fattr->fileid.
502 * Note carefully the special handling of busy inodes (i_count > 1).
503 * With the kernel 2.1.xx dcache all inodes except hard links must
504 * have i_count == 1 after iget(). Otherwise, it indicates that the
505 * server has reused a fileid (i_ino) and we have a stale inode.
507 static struct inode *
508 __nfs_fhget(struct super_block *sb, struct nfs_fattr *fattr)
510 struct inode *inode;
511 int max_count;
513 retry:
514 inode = iget(sb, fattr->fileid);
515 if (!inode)
516 goto out_no_inode;
517 /* N.B. This should be impossible ... */
518 if (inode->i_ino != fattr->fileid)
519 goto out_bad_id;
522 * Check for busy inodes, and attempt to get rid of any
523 * unused local references. If successful, we release the
524 * inode and try again.
526 * Note that the busy test uses the values in the fattr,
527 * as the inode may have become a different object.
528 * (We can probably handle modes changes here, too.)
530 max_count = S_ISDIR(fattr->mode) ? 1 : fattr->nlink;
531 if (inode->i_count > max_count) {
532 printk("__nfs_fhget: inode %ld busy, i_count=%d, i_nlink=%d\n",
533 inode->i_ino, inode->i_count, inode->i_nlink);
534 nfs_free_dentries(inode);
535 if (inode->i_count > max_count) {
536 printk("__nfs_fhget: inode %ld still busy, i_count=%d\n",
537 inode->i_ino, inode->i_count);
538 if (!list_empty(&inode->i_dentry)) {
539 struct dentry *dentry;
540 dentry = list_entry(inode->i_dentry.next,
541 struct dentry, d_alias);
542 printk("__nfs_fhget: killing %s/%s filehandle\n",
543 dentry->d_parent->d_name.name, dentry->d_name.name);
544 memset(dentry->d_fsdata, 0,
545 sizeof(struct nfs_fh));
546 } else
547 printk("NFS: inode %ld busy, no aliases?\n",
548 inode->i_ino);
549 make_bad_inode(inode);
550 remove_inode_hash(inode);
552 iput(inode);
553 goto retry;
555 nfs_fill_inode(inode, fattr);
556 dprintk("NFS: __nfs_fhget(%x/%ld ct=%d)\n",
557 inode->i_dev, inode->i_ino, inode->i_count);
559 out:
560 return inode;
562 out_no_inode:
563 printk("__nfs_fhget: iget failed\n");
564 goto out;
565 out_bad_id:
566 printk("__nfs_fhget: unexpected inode from iget\n");
567 goto out;
571 nfs_notify_change(struct dentry *dentry, struct iattr *attr)
573 struct inode *inode = dentry->d_inode;
574 int error;
575 struct nfs_sattr sattr;
576 struct nfs_fattr fattr;
579 * Make sure the inode is up-to-date.
581 error = nfs_revalidate(dentry);
582 if (error) {
583 #ifdef NFS_PARANOIA
584 printk("nfs_notify_change: revalidate failed, error=%d\n", error);
585 #endif
586 goto out;
589 sattr.mode = (u32) -1;
590 if (attr->ia_valid & ATTR_MODE)
591 sattr.mode = attr->ia_mode;
593 sattr.uid = (u32) -1;
594 if (attr->ia_valid & ATTR_UID)
595 sattr.uid = attr->ia_uid;
597 sattr.gid = (u32) -1;
598 if (attr->ia_valid & ATTR_GID)
599 sattr.gid = attr->ia_gid;
601 sattr.size = (u32) -1;
602 if ((attr->ia_valid & ATTR_SIZE) && S_ISREG(inode->i_mode))
603 sattr.size = attr->ia_size;
605 sattr.mtime.seconds = sattr.mtime.useconds = (u32) -1;
606 if (attr->ia_valid & ATTR_MTIME) {
607 sattr.mtime.seconds = attr->ia_mtime;
608 sattr.mtime.useconds = 0;
611 sattr.atime.seconds = sattr.atime.useconds = (u32) -1;
612 if (attr->ia_valid & ATTR_ATIME) {
613 sattr.atime.seconds = attr->ia_atime;
614 sattr.atime.useconds = 0;
617 error = nfs_wb_all(inode);
618 if (error)
619 goto out;
621 error = nfs_proc_setattr(NFS_DSERVER(dentry), NFS_FH(dentry),
622 &sattr, &fattr);
623 if (error)
624 goto out;
626 * If we changed the size or mtime, update the inode
627 * now to avoid invalidating the page cache.
629 if (sattr.size != (u32) -1) {
630 if (sattr.size != fattr.size)
631 printk("nfs_notify_change: sattr=%d, fattr=%d??\n",
632 sattr.size, fattr.size);
633 inode->i_size = sattr.size;
634 inode->i_mtime = fattr.mtime.seconds;
636 if (sattr.mtime.seconds != (u32) -1)
637 inode->i_mtime = fattr.mtime.seconds;
638 error = nfs_refresh_inode(inode, &fattr);
639 out:
640 return error;
644 * Externally visible revalidation function
647 nfs_revalidate(struct dentry *dentry)
649 return nfs_revalidate_inode(NFS_DSERVER(dentry), dentry);
653 * This function is called whenever some part of NFS notices that
654 * the cached attributes have to be refreshed.
657 _nfs_revalidate_inode(struct nfs_server *server, struct dentry *dentry)
659 struct inode *inode = dentry->d_inode;
660 int status = 0;
661 struct nfs_fattr fattr;
663 /* Don't bother revalidating if we've done it recently */
664 if (jiffies - NFS_READTIME(inode) < NFS_ATTRTIMEO(inode))
665 goto out;
667 dfprintk(PAGECACHE, "NFS: revalidating %s/%s, ino=%ld\n",
668 dentry->d_parent->d_name.name, dentry->d_name.name,
669 inode->i_ino);
670 status = nfs_proc_getattr(server, NFS_FH(dentry), &fattr);
671 if (status) {
672 int error;
673 u32 *fh;
674 struct nfs_fh fhandle;
675 #ifdef NFS_PARANOIA
676 printk("nfs_revalidate_inode: %s/%s getattr failed, ino=%ld, error=%d\n",
677 dentry->d_parent->d_name.name, dentry->d_name.name, inode->i_ino, status);
678 #endif
679 if (status != -ESTALE)
680 goto out;
682 * A "stale filehandle" error ... show the current fh
683 * and find out what the filehandle should be.
685 fh = (u32 *) NFS_FH(dentry);
686 printk("NFS: bad fh %08x%08x%08x%08x%08x%08x%08x%08x\n",
687 fh[0],fh[1],fh[2],fh[3],fh[4],fh[5],fh[6],fh[7]);
688 error = nfs_proc_lookup(server, NFS_FH(dentry->d_parent),
689 dentry->d_name.name, &fhandle, &fattr);
690 if (error) {
691 printk("NFS: lookup failed, error=%d\n", error);
692 goto out;
694 fh = (u32 *) &fhandle;
695 printk(" %08x%08x%08x%08x%08x%08x%08x%08x\n",
696 fh[0],fh[1],fh[2],fh[3],fh[4],fh[5],fh[6],fh[7]);
697 goto out;
700 status = nfs_refresh_inode(inode, &fattr);
701 if (status) {
702 #ifdef NFS_PARANOIA
703 printk("nfs_revalidate_inode: %s/%s refresh failed, ino=%ld, error=%d\n",
704 dentry->d_parent->d_name.name, dentry->d_name.name, inode->i_ino, status);
705 #endif
706 goto out;
708 dfprintk(PAGECACHE, "NFS: %s/%s revalidation complete\n",
709 dentry->d_parent->d_name.name, dentry->d_name.name);
710 out:
711 return status;
715 * Many nfs protocol calls return the new file attributes after
716 * an operation. Here we update the inode to reflect the state
717 * of the server's inode.
719 * This is a bit tricky because we have to make sure all dirty pages
720 * have been sent off to the server before calling invalidate_inode_pages.
721 * To make sure no other process adds more write requests while we try
722 * our best to flush them, we make them sleep during the attribute refresh.
724 * A very similar scenario holds for the dir cache.
727 nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
729 int invalid = 0;
730 int error = -EIO;
732 dfprintk(VFS, "NFS: refresh_inode(%x/%ld ct=%d)\n",
733 inode->i_dev, inode->i_ino, inode->i_count);
735 if (!inode || !fattr) {
736 printk("nfs_refresh_inode: inode or fattr is NULL\n");
737 goto out;
739 if (inode->i_ino != fattr->fileid) {
740 printk("nfs_refresh_inode: mismatch, ino=%ld, fattr=%d\n",
741 inode->i_ino, fattr->fileid);
742 goto out;
746 * Make sure the inode's type hasn't changed.
748 if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
749 goto out_changed;
751 inode->i_mode = fattr->mode;
752 inode->i_nlink = fattr->nlink;
753 inode->i_uid = fattr->uid;
754 inode->i_gid = fattr->gid;
756 inode->i_blocks = fattr->blocks;
757 inode->i_atime = fattr->atime.seconds;
758 inode->i_ctime = fattr->ctime.seconds;
761 * Update the read time so we don't revalidate too often.
763 NFS_READTIME(inode) = jiffies;
764 error = 0;
767 * If we have pending write-back entries, we don't want
768 * to look at the size or the mtime the server sends us
769 * too closely, as we're in the middle of modifying them.
771 if (NFS_WRITEBACK(inode))
772 goto out;
774 if (inode->i_size != fattr->size) {
775 #ifdef NFS_DEBUG_VERBOSE
776 printk("NFS: size change on %x/%ld\n", inode->i_dev, inode->i_ino);
777 #endif
778 inode->i_size = fattr->size;
779 invalid = 1;
782 if (inode->i_mtime != fattr->mtime.seconds) {
783 #ifdef NFS_DEBUG_VERBOSE
784 printk("NFS: mtime change on %x/%ld\n", inode->i_dev, inode->i_ino);
785 #endif
786 inode->i_mtime = fattr->mtime.seconds;
787 invalid = 1;
790 if (invalid)
791 goto out_invalid;
793 /* Update attrtimeo value */
794 if (fattr->mtime.seconds == NFS_OLDMTIME(inode)) {
795 if ((NFS_ATTRTIMEO(inode) <<= 1) > NFS_MAXATTRTIMEO(inode))
796 NFS_ATTRTIMEO(inode) = NFS_MAXATTRTIMEO(inode);
798 NFS_OLDMTIME(inode) = fattr->mtime.seconds;
800 out:
801 return error;
803 out_changed:
805 * Big trouble! The inode has become a different object.
807 #ifdef NFS_PARANOIA
808 printk("nfs_refresh_inode: inode %ld mode changed, %07o to %07o\n",
809 inode->i_ino, inode->i_mode, fattr->mode);
810 #endif
811 fattr->mode = inode->i_mode; /* save mode */
812 make_bad_inode(inode);
813 nfs_inval(inode);
814 inode->i_mode = fattr->mode; /* restore mode */
816 * No need to worry about unhashing the dentry, as the
817 * lookup validation will know that the inode is bad.
818 * (But we fall through to invalidate the caches.)
821 out_invalid:
823 * Invalidate the local caches
825 #ifdef NFS_DEBUG_VERBOSE
826 printk("nfs_refresh_inode: invalidating %ld pages\n", inode->i_nrpages);
827 #endif
828 if (!S_ISDIR(inode->i_mode))
829 invalidate_inode_pages(inode);
830 else
831 nfs_invalidate_dircache(inode);
832 NFS_CACHEINV(inode);
833 NFS_ATTRTIMEO(inode) = NFS_MINATTRTIMEO(inode);
834 goto out;
838 * File system information
840 static struct file_system_type nfs_fs_type = {
841 "nfs",
842 0 /* FS_NO_DCACHE - this doesn't work right now*/,
843 nfs_read_super,
844 NULL
848 * Initialize NFS
851 init_nfs_fs(void)
853 #ifdef CONFIG_PROC_FS
854 rpc_register_sysctl();
855 rpc_proc_init();
856 rpc_proc_register(&nfs_rpcstat);
857 #endif
858 return register_filesystem(&nfs_fs_type);
862 * Every kernel module contains stuff like this.
864 #ifdef MODULE
866 EXPORT_NO_SYMBOLS;
867 /* Not quite true; I just maintain it */
868 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
871 init_module(void)
873 return init_nfs_fs();
876 void
877 cleanup_module(void)
879 #ifdef CONFIG_PROC_FS
880 rpc_proc_unregister("nfs");
881 #endif
882 unregister_filesystem(&nfs_fs_type);
883 nfs_free_dircache();
885 #endif