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>
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
*);
40 static void nfs_zap_caches(struct inode
*);
41 static void nfs_invalidate_inode(struct inode
*);
43 static void nfs_read_inode(struct inode
*);
44 static void nfs_put_inode(struct inode
*);
45 static void nfs_delete_inode(struct inode
*);
46 static int nfs_notify_change(struct dentry
*, struct iattr
*);
47 static void nfs_put_super(struct super_block
*);
48 static void nfs_umount_begin(struct super_block
*);
49 static int nfs_statfs(struct super_block
*, struct statfs
*, int);
51 static struct super_operations nfs_sops
= {
52 nfs_read_inode
, /* read inode */
53 NULL
, /* write inode */
54 nfs_put_inode
, /* put inode */
55 nfs_delete_inode
, /* delete inode */
56 nfs_notify_change
, /* notify change */
57 nfs_put_super
, /* put superblock */
58 NULL
, /* write superblock */
59 nfs_statfs
, /* stat filesystem */
60 NULL
, /* no remount */
61 NULL
, /* no clear inode */
62 nfs_umount_begin
/* umount attempt begin */
65 struct rpc_stat nfs_rpcstat
= { &nfs_program
};
68 * The "read_inode" function doesn't actually do anything:
69 * the real data is filled in later in nfs_fhget. Here we
70 * just mark the cache times invalid, and zero out i_mode
71 * (the latter makes "nfs_refresh_inode" do the right thing
75 nfs_read_inode(struct inode
* inode
)
77 inode
->i_blksize
= inode
->i_sb
->s_blocksize
;
82 NFS_ATTRTIMEO(inode
) = NFS_MINATTRTIMEO(inode
);
86 nfs_put_inode(struct inode
* inode
)
88 dprintk("NFS: put_inode(%x/%ld)\n", inode
->i_dev
, inode
->i_ino
);
90 * We want to get rid of unused inodes ...
92 if (inode
->i_count
== 1)
97 nfs_delete_inode(struct inode
* inode
)
101 dprintk("NFS: delete_inode(%x/%ld)\n", inode
->i_dev
, inode
->i_ino
);
103 if (S_ISDIR(inode
->i_mode
)) {
104 nfs_free_dircache(inode
);
107 * Flush out any pending write requests ...
109 if (NFS_WRITEBACK(inode
) != NULL
) {
110 unsigned long timeout
= jiffies
+ 5*HZ
;
111 #ifdef NFS_DEBUG_VERBOSE
112 printk("nfs_delete_inode: inode %ld has pending RPC requests\n", inode
->i_ino
);
115 while (NFS_WRITEBACK(inode
) != NULL
&&
116 time_before(jiffies
, timeout
)) {
117 current
->state
= TASK_INTERRUPTIBLE
;
118 schedule_timeout(HZ
/10);
120 current
->state
= TASK_RUNNING
;
121 if (NFS_WRITEBACK(inode
) != NULL
)
122 printk("NFS: Arghhh, stuck RPC requests!\n");
126 failed
= nfs_check_failed_request(inode
);
128 printk("NFS: inode %ld had %d failed requests\n",
129 inode
->i_ino
, failed
);
134 nfs_put_super(struct super_block
*sb
)
136 struct nfs_server
*server
= &sb
->u
.nfs_sb
.s_server
;
137 struct rpc_clnt
*rpc
;
139 if ((rpc
= server
->client
) != NULL
)
140 rpc_shutdown_client(rpc
);
142 if (!(server
->flags
& NFS_MOUNT_NONLM
))
143 lockd_down(); /* release rpc.lockd */
144 rpciod_down(); /* release rpciod */
146 kfree(server
->hostname
);
152 nfs_umount_begin(struct super_block
*sb
)
154 struct nfs_server
*server
= &sb
->u
.nfs_sb
.s_server
;
155 struct rpc_clnt
*rpc
;
157 /* -EIO all pending I/O */
158 if ((rpc
= server
->client
) != NULL
)
159 rpc_killall_tasks(rpc
);
163 * Compute and set NFS server blocksize
166 nfs_block_size(unsigned int bsize
, unsigned char *nrbitsp
)
169 bsize
= NFS_DEF_FILE_IO_BUFFER_SIZE
;
170 else if (bsize
>= NFS_MAX_FILE_IO_BUFFER_SIZE
)
171 bsize
= NFS_MAX_FILE_IO_BUFFER_SIZE
;
173 /* make sure blocksize is a power of two */
174 if ((bsize
& (bsize
- 1)) || nrbitsp
) {
177 for (nrbits
= 31; nrbits
&& !(bsize
& (1 << nrbits
)); nrbits
--)
182 if (bsize
< NFS_DEF_FILE_IO_BUFFER_SIZE
)
183 bsize
= NFS_DEF_FILE_IO_BUFFER_SIZE
;
189 extern struct nfs_fh
*nfs_fh_alloc(void);
190 extern void nfs_fh_free(struct nfs_fh
*p
);
193 * The way this works is that the mount process passes a structure
194 * in the data argument which contains the server's IP address
195 * and the root file handle obtained from the server's mount
196 * daemon. We stash these away in the private superblock fields.
199 nfs_read_super(struct super_block
*sb
, void *raw_data
, int silent
)
201 struct nfs_mount_data
*data
= (struct nfs_mount_data
*) raw_data
;
202 struct nfs_server
*server
;
203 struct rpc_xprt
*xprt
;
204 struct rpc_clnt
*clnt
;
205 struct nfs_fh
*root_fh
;
206 struct inode
*root_inode
;
207 unsigned int authflavor
;
209 struct sockaddr_in srvaddr
;
210 struct rpc_timeout timeparms
;
211 struct nfs_fattr fattr
;
217 if (data
->version
!= NFS_MOUNT_VERSION
) {
218 printk("nfs warning: mount version %s than kernel\n",
219 data
->version
< NFS_MOUNT_VERSION
? "older" : "newer");
220 if (data
->version
< 2)
222 if (data
->version
< 3)
226 /* We now require that the mount process passes the remote address */
227 memcpy(&srvaddr
, &data
->addr
, sizeof(srvaddr
));
228 if (srvaddr
.sin_addr
.s_addr
== INADDR_ANY
)
233 sb
->s_flags
|= MS_ODD_RENAME
; /* This should go away */
235 sb
->s_magic
= NFS_SUPER_MAGIC
;
236 sb
->s_op
= &nfs_sops
;
237 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
238 sb
->u
.nfs_sb
.s_root
= data
->root
;
239 server
= &sb
->u
.nfs_sb
.s_server
;
240 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
241 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
242 server
->flags
= data
->flags
;
244 if (data
->flags
& NFS_MOUNT_NOAC
) {
245 data
->acregmin
= data
->acregmax
= 0;
246 data
->acdirmin
= data
->acdirmax
= 0;
248 server
->acregmin
= data
->acregmin
*HZ
;
249 server
->acregmax
= data
->acregmax
*HZ
;
250 server
->acdirmin
= data
->acdirmin
*HZ
;
251 server
->acdirmax
= data
->acdirmax
*HZ
;
253 server
->hostname
= kmalloc(strlen(data
->hostname
) + 1, GFP_KERNEL
);
254 if (!server
->hostname
)
256 strcpy(server
->hostname
, data
->hostname
);
258 /* Which protocol do we use? */
259 tcp
= (data
->flags
& NFS_MOUNT_TCP
);
261 /* Initialize timeout values */
262 timeparms
.to_initval
= data
->timeo
* HZ
/ 10;
263 timeparms
.to_retries
= data
->retrans
;
264 timeparms
.to_maxval
= tcp
? RPC_MAX_TCP_TIMEOUT
: RPC_MAX_UDP_TIMEOUT
;
265 timeparms
.to_exponential
= 1;
267 /* Now create transport and client */
268 xprt
= xprt_create_proto(tcp
? IPPROTO_TCP
: IPPROTO_UDP
,
269 &srvaddr
, &timeparms
);
273 /* Choose authentication flavor */
274 authflavor
= RPC_AUTH_UNIX
;
275 if (data
->flags
& NFS_MOUNT_SECURE
)
276 authflavor
= RPC_AUTH_DES
;
277 else if (data
->flags
& NFS_MOUNT_KERBEROS
)
278 authflavor
= RPC_AUTH_KRB
;
280 clnt
= rpc_create_client(xprt
, server
->hostname
, &nfs_program
,
281 NFS_VERSION
, authflavor
);
285 clnt
->cl_intr
= (data
->flags
& NFS_MOUNT_INTR
)? 1 : 0;
286 clnt
->cl_softrtry
= (data
->flags
& NFS_MOUNT_SOFT
)? 1 : 0;
288 server
->client
= clnt
;
290 /* Fire up rpciod if not yet running */
291 if (rpciod_up() != 0)
295 * Keep the super block locked while we try to get
296 * the root fh attributes.
298 root_fh
= nfs_fh_alloc();
301 *root_fh
= data
->root
;
303 if (nfs_proc_getattr(server
, root_fh
, &fattr
) != 0)
306 root_inode
= __nfs_fhget(sb
, &fattr
);
309 sb
->s_root
= d_alloc_root(root_inode
);
312 sb
->s_root
->d_op
= &nfs_dentry_operations
;
313 sb
->s_root
->d_fsdata
= root_fh
;
318 /* Check whether to start the lockd process */
319 if (!(server
->flags
& NFS_MOUNT_NONLM
))
323 /* Yargs. It didn't work out. */
325 printk("nfs_read_super: get root inode failed\n");
330 printk("nfs_read_super: get root fattr failed\n");
332 nfs_fh_free(root_fh
);
338 printk(KERN_WARNING
"NFS: couldn't start rpciod!\n");
340 rpc_shutdown_client(server
->client
);
344 printk(KERN_WARNING
"NFS: cannot create RPC client.\n");
349 printk(KERN_WARNING
"NFS: cannot create RPC transport.\n");
352 kfree(server
->hostname
);
358 printk("NFS: mount program didn't pass remote address!\n");
362 printk("nfs_read_super: missing data argument\n");
371 nfs_statfs(struct super_block
*sb
, struct statfs
*buf
, int bufsiz
)
374 struct nfs_fsinfo res
;
377 error
= nfs_proc_statfs(&sb
->u
.nfs_sb
.s_server
, &sb
->u
.nfs_sb
.s_root
,
380 printk("nfs_statfs: statfs error = %d\n", -error
);
381 res
.bsize
= res
.blocks
= res
.bfree
= res
.bavail
= 0;
383 tmp
.f_type
= NFS_SUPER_MAGIC
;
384 tmp
.f_bsize
= res
.bsize
;
385 tmp
.f_blocks
= res
.blocks
;
386 tmp
.f_bfree
= res
.bfree
;
387 tmp
.f_bavail
= res
.bavail
;
390 tmp
.f_namelen
= NAME_MAX
;
391 return copy_to_user(buf
, &tmp
, bufsiz
) ? -EFAULT
: 0;
395 * Free all unused dentries in an inode's alias list.
397 * Subtle note: we have to be very careful not to cause
398 * any IO operations with the stale dentries, as this
399 * could cause file corruption. But since the dentry
400 * count is 0 and all pending IO for a dentry has been
401 * flushed when the count went to 0, we're safe here.
402 * Also returns the number of unhashed dentries
405 nfs_free_dentries(struct inode
*inode
)
407 struct list_head
*tmp
, *head
= &inode
->i_dentry
;
413 while ((tmp
= tmp
->next
) != head
) {
414 struct dentry
*dentry
= list_entry(tmp
, struct dentry
, d_alias
);
415 dprintk("nfs_free_dentries: found %s/%s, d_count=%d, hashed=%d\n",
416 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
417 dentry
->d_count
, !list_empty(&dentry
->d_hash
));
418 if (!dentry
->d_count
) {
424 if (!list_empty(&dentry
->d_hash
))
431 * Invalidate the local caches
434 nfs_zap_caches(struct inode
*inode
)
436 NFS_ATTRTIMEO(inode
) = NFS_MINATTRTIMEO(inode
);
439 invalidate_inode_pages(inode
);
440 if (S_ISDIR(inode
->i_mode
))
441 nfs_flush_dircache(inode
);
445 * Invalidate, but do not unhash, the inode
448 nfs_invalidate_inode(struct inode
*inode
)
450 umode_t save_mode
= inode
->i_mode
;
452 make_bad_inode(inode
);
453 inode
->i_mode
= save_mode
;
455 nfs_zap_caches(inode
);
459 * Fill in inode information from the fattr.
462 nfs_fill_inode(struct inode
*inode
, struct nfs_fattr
*fattr
)
465 * Check whether the mode has been set, as we only want to
466 * do this once. (We don't allow inodes to change types.)
468 if (inode
->i_mode
== 0) {
469 inode
->i_mode
= fattr
->mode
;
470 if (S_ISREG(inode
->i_mode
))
471 inode
->i_op
= &nfs_file_inode_operations
;
472 else if (S_ISDIR(inode
->i_mode
))
473 inode
->i_op
= &nfs_dir_inode_operations
;
474 else if (S_ISLNK(inode
->i_mode
))
475 inode
->i_op
= &nfs_symlink_inode_operations
;
477 init_special_inode(inode
, inode
->i_mode
, fattr
->rdev
);
479 * Preset the size and mtime, as there's no need
480 * to invalidate the caches.
482 inode
->i_size
= fattr
->size
;
483 inode
->i_mtime
= fattr
->mtime
.seconds
;
484 NFS_OLDMTIME(inode
) = fattr
->mtime
.seconds
;
486 nfs_refresh_inode(inode
, fattr
);
490 * This is our own version of iget that looks up inodes by file handle
491 * instead of inode number. We use this technique instead of using
492 * the vfs read_inode function because there is no way to pass the
493 * file handle or current attributes into the read_inode function.
495 * We provide a special check for NetApp .snapshot directories to avoid
496 * inode aliasing problems. All snapshot inodes are anonymous (unhashed).
499 nfs_fhget(struct dentry
*dentry
, struct nfs_fh
*fhandle
,
500 struct nfs_fattr
*fattr
)
502 struct super_block
*sb
= dentry
->d_sb
;
504 dprintk("NFS: nfs_fhget(%s/%s fileid=%d)\n",
505 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
508 /* Install the file handle in the dentry */
509 *((struct nfs_fh
*) dentry
->d_fsdata
) = *fhandle
;
511 #ifdef CONFIG_NFS_SNAPSHOT
513 * Check for NetApp snapshot dentries, and get an
514 * unhashed inode to avoid aliasing problems.
516 if ((dentry
->d_parent
->d_inode
->u
.nfs_i
.flags
& NFS_IS_SNAPSHOT
) ||
517 (dentry
->d_name
.len
== 9 &&
518 memcmp(dentry
->d_name
.name
, ".snapshot", 9) == 0)) {
519 struct inode
*inode
= get_empty_inode();
523 inode
->i_dev
= sb
->s_dev
;
525 inode
->i_ino
= fattr
->fileid
;
526 nfs_read_inode(inode
);
527 nfs_fill_inode(inode
, fattr
);
528 inode
->u
.nfs_i
.flags
|= NFS_IS_SNAPSHOT
;
529 dprintk("NFS: nfs_fhget(snapshot ino=%ld)\n", inode
->i_ino
);
534 return __nfs_fhget(sb
, fattr
);
538 * Look up the inode by super block and fattr->fileid.
540 * Note carefully the special handling of busy inodes (i_count > 1).
541 * With the kernel 2.1.xx dcache all inodes except hard links must
542 * have i_count == 1 after iget(). Otherwise, it indicates that the
543 * server has reused a fileid (i_ino) and we have a stale inode.
545 static struct inode
*
546 __nfs_fhget(struct super_block
*sb
, struct nfs_fattr
*fattr
)
549 int max_count
, stale_inode
, unhashed
= 0;
552 inode
= iget(sb
, fattr
->fileid
);
555 /* N.B. This should be impossible ... */
556 if (inode
->i_ino
!= fattr
->fileid
)
560 * Check for busy inodes, and attempt to get rid of any
561 * unused local references. If successful, we release the
562 * inode and try again.
564 * Note that the busy test uses the values in the fattr,
565 * as the inode may have become a different object.
566 * (We can probably handle modes changes here, too.)
568 stale_inode
= inode
->i_mode
&&
569 ((fattr
->mode
^ inode
->i_mode
) & S_IFMT
);
570 stale_inode
|= inode
->i_count
&& inode
->i_count
== unhashed
;
571 max_count
= S_ISDIR(fattr
->mode
) ? 1 : fattr
->nlink
;
572 if (stale_inode
|| inode
->i_count
> max_count
+ unhashed
) {
573 dprintk("__nfs_fhget: inode %ld busy, i_count=%d, i_nlink=%d\n",
574 inode
->i_ino
, inode
->i_count
, inode
->i_nlink
);
575 unhashed
= nfs_free_dentries(inode
);
576 if (stale_inode
|| inode
->i_count
> max_count
+ unhashed
) {
577 printk("__nfs_fhget: inode %ld still busy, i_count=%d\n",
578 inode
->i_ino
, inode
->i_count
);
579 if (!list_empty(&inode
->i_dentry
)) {
580 struct dentry
*dentry
;
581 dentry
= list_entry(inode
->i_dentry
.next
,
582 struct dentry
, d_alias
);
583 printk("__nfs_fhget: killing %s/%s filehandle\n",
584 dentry
->d_parent
->d_name
.name
,
585 dentry
->d_name
.name
);
586 memset(dentry
->d_fsdata
, 0,
587 sizeof(struct nfs_fh
));
589 remove_inode_hash(inode
);
590 nfs_invalidate_inode(inode
);
596 nfs_fill_inode(inode
, fattr
);
597 dprintk("NFS: __nfs_fhget(%x/%ld ct=%d)\n",
598 inode
->i_dev
, inode
->i_ino
, inode
->i_count
);
604 printk("__nfs_fhget: iget failed\n");
607 printk("__nfs_fhget: unexpected inode from iget\n");
612 nfs_notify_change(struct dentry
*dentry
, struct iattr
*attr
)
614 struct inode
*inode
= dentry
->d_inode
;
616 struct nfs_sattr sattr
;
617 struct nfs_fattr fattr
;
620 * Make sure the inode is up-to-date.
622 error
= nfs_revalidate(dentry
);
625 printk("nfs_notify_change: revalidate failed, error=%d\n", error
);
630 sattr
.mode
= (u32
) -1;
631 if (attr
->ia_valid
& ATTR_MODE
)
632 sattr
.mode
= attr
->ia_mode
;
634 sattr
.uid
= (u32
) -1;
635 if (attr
->ia_valid
& ATTR_UID
)
636 sattr
.uid
= attr
->ia_uid
;
638 sattr
.gid
= (u32
) -1;
639 if (attr
->ia_valid
& ATTR_GID
)
640 sattr
.gid
= attr
->ia_gid
;
642 sattr
.size
= (u32
) -1;
643 if ((attr
->ia_valid
& ATTR_SIZE
) && S_ISREG(inode
->i_mode
))
644 sattr
.size
= attr
->ia_size
;
646 sattr
.mtime
.seconds
= sattr
.mtime
.useconds
= (u32
) -1;
647 if (attr
->ia_valid
& ATTR_MTIME
) {
648 sattr
.mtime
.seconds
= attr
->ia_mtime
;
649 sattr
.mtime
.useconds
= 0;
652 sattr
.atime
.seconds
= sattr
.atime
.useconds
= (u32
) -1;
653 if (attr
->ia_valid
& ATTR_ATIME
) {
654 sattr
.atime
.seconds
= attr
->ia_atime
;
655 sattr
.atime
.useconds
= 0;
658 error
= nfs_wb_all(inode
);
662 error
= nfs_proc_setattr(NFS_DSERVER(dentry
), NFS_FH(dentry
),
667 * If we changed the size or mtime, update the inode
668 * now to avoid invalidating the page cache.
670 if (sattr
.size
!= (u32
) -1) {
671 if (sattr
.size
!= fattr
.size
)
672 printk("nfs_notify_change: sattr=%d, fattr=%d??\n",
673 sattr
.size
, fattr
.size
);
674 inode
->i_size
= sattr
.size
;
675 inode
->i_mtime
= fattr
.mtime
.seconds
;
677 if (sattr
.mtime
.seconds
!= (u32
) -1)
678 inode
->i_mtime
= fattr
.mtime
.seconds
;
679 error
= nfs_refresh_inode(inode
, &fattr
);
685 * Externally visible revalidation function
688 nfs_revalidate(struct dentry
*dentry
)
690 return nfs_revalidate_inode(NFS_DSERVER(dentry
), dentry
);
694 * These are probably going to contain hooks for
695 * allocating and releasing RPC credentials for
696 * the file. I'll have to think about Tronds patch
699 int nfs_open(struct inode
*inode
, struct file
*filp
)
704 int nfs_release(struct inode
*inode
, struct file
*filp
)
710 * This function is called whenever some part of NFS notices that
711 * the cached attributes have to be refreshed.
714 _nfs_revalidate_inode(struct nfs_server
*server
, struct dentry
*dentry
)
716 struct inode
*inode
= dentry
->d_inode
;
718 struct nfs_fattr fattr
;
720 dfprintk(PAGECACHE
, "NFS: revalidating %s/%s, ino=%ld\n",
721 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
723 status
= nfs_proc_getattr(server
, NFS_FH(dentry
), &fattr
);
727 struct nfs_fh fhandle
;
728 dfprintk(PAGECACHE
, "nfs_revalidate_inode: %s/%s getattr failed, ino=%ld, error=%d\n",
729 dentry
->d_parent
->d_name
.name
,
730 dentry
->d_name
.name
, inode
->i_ino
, status
);
731 if (status
!= -ESTALE
)
734 * A "stale filehandle" error ... show the current fh
735 * and find out what the filehandle should be.
737 fh
= (u32
*) NFS_FH(dentry
);
738 dfprintk(PAGECACHE
, "NFS: bad fh %08x%08x%08x%08x%08x%08x%08x%08x\n",
739 fh
[0],fh
[1],fh
[2],fh
[3],fh
[4],fh
[5],fh
[6],fh
[7]);
740 error
= nfs_proc_lookup(server
, NFS_FH(dentry
->d_parent
),
741 dentry
->d_name
.name
, &fhandle
, &fattr
);
743 dfprintk(PAGECACHE
, "NFS: lookup failed, error=%d\n", error
);
746 fh
= (u32
*) &fhandle
;
747 dfprintk(PAGECACHE
, " %08x%08x%08x%08x%08x%08x%08x%08x\n",
748 fh
[0],fh
[1],fh
[2],fh
[3],fh
[4],fh
[5],fh
[6],fh
[7]);
752 status
= nfs_refresh_inode(inode
, &fattr
);
754 dfprintk(PAGECACHE
, "nfs_revalidate_inode: %s/%s refresh failed, ino=%ld, error=%d\n",
755 dentry
->d_parent
->d_name
.name
,
756 dentry
->d_name
.name
, inode
->i_ino
, status
);
759 dfprintk(PAGECACHE
, "NFS: %s/%s revalidation complete\n",
760 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
);
766 * Many nfs protocol calls return the new file attributes after
767 * an operation. Here we update the inode to reflect the state
768 * of the server's inode.
770 * This is a bit tricky because we have to make sure all dirty pages
771 * have been sent off to the server before calling invalidate_inode_pages.
772 * To make sure no other process adds more write requests while we try
773 * our best to flush them, we make them sleep during the attribute refresh.
775 * A very similar scenario holds for the dir cache.
778 nfs_refresh_inode(struct inode
*inode
, struct nfs_fattr
*fattr
)
783 dfprintk(VFS
, "NFS: refresh_inode(%x/%ld ct=%d)\n",
784 inode
->i_dev
, inode
->i_ino
, inode
->i_count
);
786 if (!inode
|| !fattr
) {
787 printk("nfs_refresh_inode: inode or fattr is NULL\n");
790 if (inode
->i_ino
!= fattr
->fileid
) {
791 printk("nfs_refresh_inode: mismatch, ino=%ld, fattr=%d\n",
792 inode
->i_ino
, fattr
->fileid
);
797 * Make sure the inode's type hasn't changed.
799 if ((inode
->i_mode
& S_IFMT
) != (fattr
->mode
& S_IFMT
))
802 inode
->i_mode
= fattr
->mode
;
803 inode
->i_nlink
= fattr
->nlink
;
804 inode
->i_uid
= fattr
->uid
;
805 inode
->i_gid
= fattr
->gid
;
807 inode
->i_blocks
= fattr
->blocks
;
808 inode
->i_atime
= fattr
->atime
.seconds
;
809 inode
->i_ctime
= fattr
->ctime
.seconds
;
812 * Update the read time so we don't revalidate too often.
814 NFS_READTIME(inode
) = jiffies
;
818 * If we have pending write-back entries, we don't want
819 * to look at the size or the mtime the server sends us
820 * too closely, as we're in the middle of modifying them.
822 if (NFS_WRITEBACK(inode
))
825 if (inode
->i_size
!= fattr
->size
) {
826 #ifdef NFS_DEBUG_VERBOSE
827 printk("NFS: size change on %x/%ld\n", inode
->i_dev
, inode
->i_ino
);
829 inode
->i_size
= fattr
->size
;
833 if (inode
->i_mtime
!= fattr
->mtime
.seconds
) {
834 #ifdef NFS_DEBUG_VERBOSE
835 printk("NFS: mtime change on %x/%ld\n", inode
->i_dev
, inode
->i_ino
);
837 inode
->i_mtime
= fattr
->mtime
.seconds
;
844 /* Update attrtimeo value */
845 if (fattr
->mtime
.seconds
== NFS_OLDMTIME(inode
)) {
846 if ((NFS_ATTRTIMEO(inode
) <<= 1) > NFS_MAXATTRTIMEO(inode
))
847 NFS_ATTRTIMEO(inode
) = NFS_MAXATTRTIMEO(inode
);
849 NFS_OLDMTIME(inode
) = fattr
->mtime
.seconds
;
856 * Big trouble! The inode has become a different object.
859 printk("nfs_refresh_inode: inode %ld mode changed, %07o to %07o\n",
860 inode
->i_ino
, inode
->i_mode
, fattr
->mode
);
863 * No need to worry about unhashing the dentry, as the
864 * lookup validation will know that the inode is bad.
866 nfs_invalidate_inode(inode
);
870 #ifdef NFS_DEBUG_VERBOSE
871 printk("nfs_refresh_inode: invalidating %ld pages\n", inode
->i_nrpages
);
873 nfs_zap_caches(inode
);
878 * File system information
880 static struct file_system_type nfs_fs_type
= {
882 0 /* FS_NO_DCACHE - this doesn't work right now*/,
887 extern int nfs_init_fhcache(void);
888 extern int nfs_init_wreqcache(void);
898 err
= nfs_init_fhcache();
902 err
= nfs_init_wreqcache();
906 #ifdef CONFIG_PROC_FS
907 rpc_register_sysctl();
909 rpc_proc_register(&nfs_rpcstat
);
911 return register_filesystem(&nfs_fs_type
);
915 * Every kernel module contains stuff like this.
920 /* Not quite true; I just maintain it */
921 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
926 return init_nfs_fs();
932 #ifdef CONFIG_PROC_FS
933 rpc_proc_unregister("nfs");
935 unregister_filesystem(&nfs_fs_type
);