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
*);
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
73 nfs_read_inode(struct inode
* inode
)
75 inode
->i_blksize
= inode
->i_sb
->s_blocksize
;
80 NFS_ATTRTIMEO(inode
) = NFS_MINATTRTIMEO(inode
);
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)
95 nfs_delete_inode(struct inode
* inode
)
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
);
108 nfs_invalidate_pages(inode
);
109 while (NFS_WRITEBACK(inode
) != NULL
&& jiffies
< timeout
) {
110 current
->state
= TASK_INTERRUPTIBLE
;
111 current
->timeout
= jiffies
+ 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
);
121 printk("NFS: inode %ld had %d failed requests\n",
122 inode
->i_ino
, failed
);
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
);
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
163 nfs_block_size(unsigned int bsize
, unsigned char *nrbitsp
)
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
) {
174 for (nrbits
= 31; nrbits
&& !(bsize
& (1 << nrbits
)); nrbits
--)
179 if (bsize
< NFS_DEF_FILE_IO_BUFFER_SIZE
)
180 bsize
= NFS_DEF_FILE_IO_BUFFER_SIZE
;
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.
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
;
203 struct sockaddr_in srvaddr
;
204 struct rpc_timeout timeparms
;
205 struct nfs_fattr fattr
;
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)
216 if (data
->version
< 3)
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
)
227 sb
->s_magic
= NFS_SUPER_MAGIC
;
228 sb
->s_op
= &nfs_sops
;
229 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
230 sb
->u
.nfs_sb
.s_root
= data
->root
;
231 server
= &sb
->u
.nfs_sb
.s_server
;
232 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
233 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
234 server
->flags
= data
->flags
;
235 server
->acregmin
= data
->acregmin
*HZ
;
236 server
->acregmax
= data
->acregmax
*HZ
;
237 server
->acdirmin
= data
->acdirmin
*HZ
;
238 server
->acdirmax
= data
->acdirmax
*HZ
;
240 server
->hostname
= kmalloc(strlen(data
->hostname
) + 1, GFP_KERNEL
);
241 if (!server
->hostname
)
243 strcpy(server
->hostname
, data
->hostname
);
245 /* Which protocol do we use? */
246 tcp
= (data
->flags
& NFS_MOUNT_TCP
);
248 /* Initialize timeout values */
249 timeparms
.to_initval
= data
->timeo
* HZ
/ 10;
250 timeparms
.to_retries
= data
->retrans
;
251 timeparms
.to_maxval
= tcp
? RPC_MAX_TCP_TIMEOUT
: RPC_MAX_UDP_TIMEOUT
;
252 timeparms
.to_exponential
= 1;
254 /* Now create transport and client */
255 xprt
= xprt_create_proto(tcp
? IPPROTO_TCP
: IPPROTO_UDP
,
256 &srvaddr
, &timeparms
);
260 /* Choose authentication flavor */
261 authflavor
= RPC_AUTH_UNIX
;
262 if (data
->flags
& NFS_MOUNT_SECURE
)
263 authflavor
= RPC_AUTH_DES
;
264 else if (data
->flags
& NFS_MOUNT_KERBEROS
)
265 authflavor
= RPC_AUTH_KRB
;
267 clnt
= rpc_create_client(xprt
, server
->hostname
, &nfs_program
,
268 NFS_VERSION
, authflavor
);
272 clnt
->cl_intr
= (data
->flags
& NFS_MOUNT_INTR
)? 1 : 0;
273 clnt
->cl_softrtry
= (data
->flags
& NFS_MOUNT_SOFT
)? 1 : 0;
275 server
->client
= clnt
;
277 /* Fire up rpciod if not yet running */
278 if (rpciod_up() != 0)
282 * Keep the super block locked while we try to get
283 * the root fh attributes.
285 root_fh
= kmalloc(sizeof(struct nfs_fh
), GFP_KERNEL
);
288 *root_fh
= data
->root
;
290 if (nfs_proc_getattr(server
, root_fh
, &fattr
) != 0)
293 root_inode
= __nfs_fhget(sb
, &fattr
);
296 sb
->s_root
= d_alloc_root(root_inode
, NULL
);
299 sb
->s_root
->d_op
= &nfs_dentry_operations
;
300 sb
->s_root
->d_fsdata
= root_fh
;
305 /* Check whether to start the lockd process */
306 if (!(server
->flags
& NFS_MOUNT_NONLM
))
310 /* Yargs. It didn't work out. */
312 printk("nfs_read_super: get root inode failed\n");
317 printk("nfs_read_super: get root fattr failed\n");
325 printk("NFS: couldn't start rpciod!\n");
327 rpc_shutdown_client(server
->client
);
331 printk("NFS: cannot create RPC client.\n");
336 printk("NFS: cannot create RPC transport.\n");
337 kfree(server
->hostname
);
343 printk("NFS: mount program didn't pass remote address!\n");
347 printk("nfs_read_super: missing data argument\n");
356 nfs_statfs(struct super_block
*sb
, struct statfs
*buf
, int bufsiz
)
359 struct nfs_fsinfo res
;
362 error
= nfs_proc_statfs(&sb
->u
.nfs_sb
.s_server
, &sb
->u
.nfs_sb
.s_root
,
365 printk("nfs_statfs: statfs error = %d\n", -error
);
366 res
.bsize
= res
.blocks
= res
.bfree
= res
.bavail
= 0;
368 tmp
.f_type
= NFS_SUPER_MAGIC
;
369 tmp
.f_bsize
= res
.bsize
;
370 tmp
.f_blocks
= res
.blocks
;
371 tmp
.f_bfree
= res
.bfree
;
372 tmp
.f_bavail
= res
.bavail
;
375 tmp
.f_namelen
= NAME_MAX
;
376 return copy_to_user(buf
, &tmp
, bufsiz
) ? -EFAULT
: 0;
380 * Free all unused dentries in an inode's alias list.
382 * Subtle note: we have to be very careful not to cause
383 * any IO operations with the stale dentries, as this
384 * could cause file corruption. But since the dentry
385 * count is 0 and all pending IO for a dentry has been
386 * flushed when the count went to 0, we're safe here.
388 void nfs_free_dentries(struct inode
*inode
)
390 struct list_head
*tmp
, *head
= &inode
->i_dentry
;
394 while ((tmp
= tmp
->next
) != head
) {
395 struct dentry
*dentry
= list_entry(tmp
, struct dentry
, d_alias
);
396 if (!dentry
->d_count
) {
397 printk("nfs_free_dentries: freeing %s/%s, i_count=%d\n",
398 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
, inode
->i_count
);
408 * Fill in inode information from the fattr.
411 nfs_fill_inode(struct inode
*inode
, struct nfs_fattr
*fattr
)
414 * Check whether the mode has been set, as we only want to
415 * do this once. (We don't allow inodes to change types.)
417 if (inode
->i_mode
== 0) {
418 inode
->i_mode
= fattr
->mode
;
419 if (S_ISREG(inode
->i_mode
))
420 inode
->i_op
= &nfs_file_inode_operations
;
421 else if (S_ISDIR(inode
->i_mode
))
422 inode
->i_op
= &nfs_dir_inode_operations
;
423 else if (S_ISLNK(inode
->i_mode
))
424 inode
->i_op
= &nfs_symlink_inode_operations
;
425 else if (S_ISCHR(inode
->i_mode
)) {
426 inode
->i_op
= &chrdev_inode_operations
;
427 inode
->i_rdev
= to_kdev_t(fattr
->rdev
);
428 } else if (S_ISBLK(inode
->i_mode
)) {
429 inode
->i_op
= &blkdev_inode_operations
;
430 inode
->i_rdev
= to_kdev_t(fattr
->rdev
);
431 } else if (S_ISFIFO(inode
->i_mode
))
436 * Preset the size and mtime, as there's no need
437 * to invalidate the caches.
439 inode
->i_size
= fattr
->size
;
440 inode
->i_mtime
= fattr
->mtime
.seconds
;
441 NFS_OLDMTIME(inode
) = fattr
->mtime
.seconds
;
443 nfs_refresh_inode(inode
, fattr
);
447 * This is our own version of iget that looks up inodes by file handle
448 * instead of inode number. We use this technique instead of using
449 * the vfs read_inode function because there is no way to pass the
450 * file handle or current attributes into the read_inode function.
452 * We provide a special check for NetApp .snapshot directories to avoid
453 * inode aliasing problems. All snapshot inodes are anonymous (unhashed).
456 nfs_fhget(struct dentry
*dentry
, struct nfs_fh
*fhandle
,
457 struct nfs_fattr
*fattr
)
459 struct super_block
*sb
= dentry
->d_sb
;
461 dprintk("NFS: nfs_fhget(%s/%s fileid=%d)\n",
462 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
465 /* Install the file handle in the dentry */
466 *((struct nfs_fh
*) dentry
->d_fsdata
) = *fhandle
;
468 #ifdef CONFIG_NFS_SNAPSHOT
470 * Check for NetApp snapshot dentries, and get an
471 * unhashed inode to avoid aliasing problems.
473 if ((dentry
->d_parent
->d_inode
->u
.nfs_i
.flags
& NFS_IS_SNAPSHOT
) ||
474 (IS_ROOT(dentry
->d_parent
) && dentry
->d_name
.len
== 9 &&
475 memcmp(dentry
->d_name
.name
, ".snapshot", 9) == 0)) {
476 struct inode
*inode
= get_empty_inode();
480 inode
->i_dev
= sb
->s_dev
;
481 inode
->i_flags
= sb
->s_flags
;
482 inode
->i_ino
= fattr
->fileid
;
483 nfs_read_inode(inode
);
484 nfs_fill_inode(inode
, fattr
);
485 inode
->u
.nfs_i
.flags
|= NFS_IS_SNAPSHOT
;
486 dprintk("NFS: nfs_fhget(snapshot ino=%ld)\n", inode
->i_ino
);
491 return __nfs_fhget(sb
, fattr
);
495 * Look up the inode by super block and fattr->fileid.
497 * Note carefully the special handling of busy inodes (i_count > 1).
498 * With the kernel 2.1.xx dcache all inodes except hard links must
499 * have i_count == 1 after iget(). Otherwise, it indicates that the
500 * server has reused a fileid (i_ino) and we have a stale inode.
502 static struct inode
*
503 __nfs_fhget(struct super_block
*sb
, struct nfs_fattr
*fattr
)
509 inode
= iget(sb
, fattr
->fileid
);
512 /* N.B. This should be impossible ... */
513 if (inode
->i_ino
!= fattr
->fileid
)
517 * Check for busy inodes, and attempt to get rid of any
518 * unused local references. If successful, we release the
519 * inode and try again.
521 * Note that the busy test uses the values in the fattr,
522 * as the inode may have become a different object.
523 * (We can probably handle modes changes here, too.)
525 max_count
= S_ISDIR(fattr
->mode
) ? 1 : fattr
->nlink
;
526 if (inode
->i_count
> max_count
) {
527 printk("__nfs_fhget: inode %ld busy, i_count=%d, i_nlink=%d\n",
528 inode
->i_ino
, inode
->i_count
, inode
->i_nlink
);
529 nfs_free_dentries(inode
);
530 if (inode
->i_count
> max_count
) {
531 printk("__nfs_fhget: inode %ld still busy, i_count=%d\n",
532 inode
->i_ino
, inode
->i_count
);
533 if (!list_empty(&inode
->i_dentry
)) {
534 struct dentry
*dentry
;
535 dentry
= list_entry(inode
->i_dentry
.next
,
536 struct dentry
, d_alias
);
537 printk("__nfs_fhget: killing %s/%s filehandle\n",
538 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
);
539 memset(dentry
->d_fsdata
, 0,
540 sizeof(struct nfs_fh
));
542 printk("NFS: inode %ld busy, no aliases?\n",
544 make_bad_inode(inode
);
545 remove_inode_hash(inode
);
550 nfs_fill_inode(inode
, fattr
);
551 dprintk("NFS: __nfs_fhget(%x/%ld ct=%d)\n",
552 inode
->i_dev
, inode
->i_ino
, inode
->i_count
);
558 printk("__nfs_fhget: iget failed\n");
561 printk("__nfs_fhget: unexpected inode from iget\n");
566 nfs_notify_change(struct dentry
*dentry
, struct iattr
*attr
)
568 struct inode
*inode
= dentry
->d_inode
;
570 struct nfs_sattr sattr
;
571 struct nfs_fattr fattr
;
574 * Make sure the inode is up-to-date.
576 error
= nfs_revalidate(dentry
);
579 printk("nfs_notify_change: revalidate failed, error=%d\n", error
);
584 sattr
.mode
= (u32
) -1;
585 if (attr
->ia_valid
& ATTR_MODE
)
586 sattr
.mode
= attr
->ia_mode
;
588 sattr
.uid
= (u32
) -1;
589 if (attr
->ia_valid
& ATTR_UID
)
590 sattr
.uid
= attr
->ia_uid
;
592 sattr
.gid
= (u32
) -1;
593 if (attr
->ia_valid
& ATTR_GID
)
594 sattr
.gid
= attr
->ia_gid
;
596 sattr
.size
= (u32
) -1;
597 if ((attr
->ia_valid
& ATTR_SIZE
) && S_ISREG(inode
->i_mode
))
598 sattr
.size
= attr
->ia_size
;
600 sattr
.mtime
.seconds
= sattr
.mtime
.useconds
= (u32
) -1;
601 if (attr
->ia_valid
& ATTR_MTIME
) {
602 sattr
.mtime
.seconds
= attr
->ia_mtime
;
603 sattr
.mtime
.useconds
= 0;
606 sattr
.atime
.seconds
= sattr
.atime
.useconds
= (u32
) -1;
607 if (attr
->ia_valid
& ATTR_ATIME
) {
608 sattr
.atime
.seconds
= attr
->ia_atime
;
609 sattr
.atime
.useconds
= 0;
612 error
= nfs_proc_setattr(NFS_DSERVER(dentry
), NFS_FH(dentry
),
617 * If we changed the size or mtime, update the inode
618 * now to avoid invalidating the page cache.
620 if (sattr
.size
!= (u32
) -1) {
621 if (sattr
.size
!= fattr
.size
)
622 printk("nfs_notify_change: sattr=%d, fattr=%d??\n",
623 sattr
.size
, fattr
.size
);
624 nfs_truncate_dirty_pages(inode
, sattr
.size
);
625 inode
->i_size
= sattr
.size
;
626 inode
->i_mtime
= fattr
.mtime
.seconds
;
628 if (sattr
.mtime
.seconds
!= (u32
) -1)
629 inode
->i_mtime
= fattr
.mtime
.seconds
;
630 error
= nfs_refresh_inode(inode
, &fattr
);
636 * Externally visible revalidation function
639 nfs_revalidate(struct dentry
*dentry
)
641 return nfs_revalidate_inode(NFS_DSERVER(dentry
), dentry
);
645 * This function is called whenever some part of NFS notices that
646 * the cached attributes have to be refreshed.
649 _nfs_revalidate_inode(struct nfs_server
*server
, struct dentry
*dentry
)
651 struct inode
*inode
= dentry
->d_inode
;
653 struct nfs_fattr fattr
;
655 /* Don't bother revalidating if we've done it recently */
656 if (jiffies
- NFS_READTIME(inode
) < NFS_ATTRTIMEO(inode
))
659 dfprintk(PAGECACHE
, "NFS: revalidating %s/%s, ino=%ld\n",
660 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
662 status
= nfs_proc_getattr(server
, NFS_FH(dentry
), &fattr
);
666 struct nfs_fh fhandle
;
668 printk("nfs_revalidate_inode: %s/%s getattr failed, ino=%ld, error=%d\n",
669 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
, inode
->i_ino
, status
);
671 if (status
!= -ESTALE
)
674 * A "stale filehandle" error ... show the current fh
675 * and find out what the filehandle should be.
677 fh
= (u32
*) NFS_FH(dentry
);
678 printk("NFS: bad fh %08x%08x%08x%08x%08x%08x%08x%08x\n",
679 fh
[0],fh
[1],fh
[2],fh
[3],fh
[4],fh
[5],fh
[6],fh
[7]);
680 error
= nfs_proc_lookup(server
, NFS_FH(dentry
->d_parent
),
681 dentry
->d_name
.name
, &fhandle
, &fattr
);
683 printk("NFS: lookup failed, error=%d\n", error
);
686 fh
= (u32
*) &fhandle
;
687 printk(" %08x%08x%08x%08x%08x%08x%08x%08x\n",
688 fh
[0],fh
[1],fh
[2],fh
[3],fh
[4],fh
[5],fh
[6],fh
[7]);
692 status
= nfs_refresh_inode(inode
, &fattr
);
695 printk("nfs_revalidate_inode: %s/%s refresh failed, ino=%ld, error=%d\n",
696 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
, inode
->i_ino
, status
);
700 if (fattr
.mtime
.seconds
== NFS_OLDMTIME(inode
)) {
701 /* Update attrtimeo value */
702 if ((NFS_ATTRTIMEO(inode
) <<= 1) > NFS_MAXATTRTIMEO(inode
))
703 NFS_ATTRTIMEO(inode
) = NFS_MAXATTRTIMEO(inode
);
705 NFS_OLDMTIME(inode
) = fattr
.mtime
.seconds
;
706 dfprintk(PAGECACHE
, "NFS: %s/%s revalidation complete\n",
707 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
);
713 * Many nfs protocol calls return the new file attributes after
714 * an operation. Here we update the inode to reflect the state
715 * of the server's inode.
717 * This is a bit tricky because we have to make sure all dirty pages
718 * have been sent off to the server before calling invalidate_inode_pages.
719 * To make sure no other process adds more write requests while we try
720 * our best to flush them, we make them sleep during the attribute refresh.
722 * A very similar scenario holds for the dir cache.
725 nfs_refresh_inode(struct inode
*inode
, struct nfs_fattr
*fattr
)
730 dfprintk(VFS
, "NFS: refresh_inode(%x/%ld ct=%d)\n",
731 inode
->i_dev
, inode
->i_ino
, inode
->i_count
);
733 if (!inode
|| !fattr
) {
734 printk("nfs_refresh_inode: inode or fattr is NULL\n");
737 if (inode
->i_ino
!= fattr
->fileid
) {
738 printk("nfs_refresh_inode: mismatch, ino=%ld, fattr=%d\n",
739 inode
->i_ino
, fattr
->fileid
);
744 * Make sure the inode's type hasn't changed.
746 if ((inode
->i_mode
& S_IFMT
) != (fattr
->mode
& S_IFMT
))
750 * If we have pending write-back entries, we don't want
751 * to look at the size the server sends us too closely..
752 * In particular, ignore the server if it tells us that
753 * the file is smaller or older than we locally think it
756 if (NFS_WRITEBACK(inode
)) {
757 if (inode
->i_size
> fattr
->size
)
758 fattr
->size
= inode
->i_size
;
759 if (inode
->i_mtime
> fattr
->mtime
.seconds
)
760 fattr
->mtime
.seconds
= inode
->i_mtime
;
764 * If the size or mtime changed from outside, we want
765 * to invalidate the local caches immediately.
767 if (inode
->i_size
!= fattr
->size
) {
768 #ifdef NFS_DEBUG_VERBOSE
769 printk("NFS: size change on %x/%ld\n", inode
->i_dev
, inode
->i_ino
);
773 if (inode
->i_mtime
!= fattr
->mtime
.seconds
) {
774 #ifdef NFS_DEBUG_VERBOSE
775 printk("NFS: mtime change on %x/%ld\n", inode
->i_dev
, inode
->i_ino
);
780 inode
->i_mode
= fattr
->mode
;
781 inode
->i_nlink
= fattr
->nlink
;
782 inode
->i_uid
= fattr
->uid
;
783 inode
->i_gid
= fattr
->gid
;
785 inode
->i_size
= fattr
->size
;
786 inode
->i_blocks
= fattr
->blocks
;
787 inode
->i_atime
= fattr
->atime
.seconds
;
788 inode
->i_mtime
= fattr
->mtime
.seconds
;
789 inode
->i_ctime
= fattr
->ctime
.seconds
;
791 * Update the read time so we don't revalidate too often.
793 NFS_READTIME(inode
) = jiffies
;
802 * Big trouble! The inode has become a different object.
805 printk("nfs_refresh_inode: inode %ld mode changed, %07o to %07o\n",
806 inode
->i_ino
, inode
->i_mode
, fattr
->mode
);
808 fattr
->mode
= inode
->i_mode
; /* save mode */
809 make_bad_inode(inode
);
810 inode
->i_mode
= fattr
->mode
; /* restore mode */
812 * No need to worry about unhashing the dentry, as the
813 * lookup validation will know that the inode is bad.
814 * (But we fall through to invalidate the caches.)
819 * Invalidate the local caches
821 #ifdef NFS_DEBUG_VERBOSE
822 printk("nfs_refresh_inode: invalidating %ld pages\n", inode
->i_nrpages
);
824 if (!S_ISDIR(inode
->i_mode
)) {
825 /* This sends off all dirty pages off to the server.
826 * Note that this function must not sleep. */
827 nfs_invalidate_pages(inode
);
828 invalidate_inode_pages(inode
);
830 nfs_invalidate_dircache(inode
);
832 NFS_ATTRTIMEO(inode
) = NFS_MINATTRTIMEO(inode
);
837 * File system information
839 static struct file_system_type nfs_fs_type
= {
841 0 /* FS_NO_DCACHE - this doesn't work right now*/,
852 #ifdef CONFIG_PROC_FS
853 rpc_register_sysctl();
855 rpc_proc_register(&nfs_rpcstat
);
857 return register_filesystem(&nfs_fs_type
);
861 * Every kernel module contains stuff like this.
866 /* Not quite true; I just maintain it */
867 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
872 return init_nfs_fs();
878 #ifdef CONFIG_PROC_FS
879 rpc_proc_unregister("nfs");
881 unregister_filesystem(&nfs_fs_type
);