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>
31 #include <linux/smp_lock.h>
33 #include <asm/system.h>
34 #include <asm/uaccess.h>
36 #define CONFIG_NFS_SNAPSHOT 1
37 #define NFSDBG_FACILITY NFSDBG_VFS
38 #define NFS_PARANOIA 1
40 static struct inode
* __nfs_fhget(struct super_block
*, struct nfs_fattr
*);
41 void nfs_zap_caches(struct inode
*);
42 static void nfs_invalidate_inode(struct inode
*);
44 static void nfs_read_inode(struct inode
*);
45 static void nfs_put_inode(struct inode
*);
46 static void nfs_delete_inode(struct inode
*);
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 read_inode
: nfs_read_inode
,
53 put_inode
: nfs_put_inode
,
54 delete_inode
: nfs_delete_inode
,
55 put_super
: nfs_put_super
,
57 umount_begin
: nfs_umount_begin
,
60 struct rpc_stat nfs_rpcstat
= { &nfs_program
};
63 * The "read_inode" function doesn't actually do anything:
64 * the real data is filled in later in nfs_fhget. Here we
65 * just mark the cache times invalid, and zero out i_mode
66 * (the latter makes "nfs_refresh_inode" do the right thing
70 nfs_read_inode(struct inode
* inode
)
72 inode
->i_blksize
= inode
->i_sb
->s_blocksize
;
75 NFS_FILEID(inode
) = 0;
78 NFS_ATTRTIMEO(inode
) = NFS_MINATTRTIMEO(inode
);
82 nfs_put_inode(struct inode
* inode
)
84 dprintk("NFS: put_inode(%x/%ld)\n", inode
->i_dev
, inode
->i_ino
);
86 * We want to get rid of unused inodes ...
88 if (inode
->i_count
== 1)
93 nfs_delete_inode(struct inode
* inode
)
97 dprintk("NFS: delete_inode(%x/%ld)\n", inode
->i_dev
, inode
->i_ino
);
100 if (S_ISDIR(inode
->i_mode
)) {
101 nfs_free_dircache(inode
);
104 * Flush out any pending write requests ...
106 if (NFS_WRITEBACK(inode
) != NULL
) {
107 unsigned long timeout
= jiffies
+ 5*HZ
;
108 #ifdef NFS_DEBUG_VERBOSE
109 printk("nfs_delete_inode: inode %ld has pending RPC requests\n", inode
->i_ino
);
112 while (NFS_WRITEBACK(inode
) != NULL
&&
113 time_before(jiffies
, timeout
)) {
114 current
->state
= TASK_INTERRUPTIBLE
;
115 schedule_timeout(HZ
/10);
117 current
->state
= TASK_RUNNING
;
118 if (NFS_WRITEBACK(inode
) != NULL
)
119 printk("NFS: Arghhh, stuck RPC requests!\n");
123 failed
= nfs_check_failed_request(inode
);
125 printk("NFS: inode %ld had %d failed requests\n",
126 inode
->i_ino
, failed
);
133 nfs_put_super(struct super_block
*sb
)
135 struct nfs_server
*server
= &sb
->u
.nfs_sb
.s_server
;
136 struct rpc_clnt
*rpc
;
138 if ((rpc
= server
->client
) != NULL
)
139 rpc_shutdown_client(rpc
);
141 if (!(server
->flags
& NFS_MOUNT_NONLM
))
142 lockd_down(); /* release rpc.lockd */
143 rpciod_down(); /* release rpciod */
145 kfree(server
->hostname
);
151 nfs_umount_begin(struct super_block
*sb
)
153 struct nfs_server
*server
= &sb
->u
.nfs_sb
.s_server
;
154 struct rpc_clnt
*rpc
;
156 /* -EIO all pending I/O */
157 if ((rpc
= server
->client
) != NULL
)
158 rpc_killall_tasks(rpc
);
162 * Compute and set NFS server blocksize
165 nfs_block_size(unsigned int bsize
, unsigned char *nrbitsp
)
168 bsize
= NFS_DEF_FILE_IO_BUFFER_SIZE
;
169 else if (bsize
>= NFS_MAX_FILE_IO_BUFFER_SIZE
)
170 bsize
= NFS_MAX_FILE_IO_BUFFER_SIZE
;
172 /* make sure blocksize is a power of two */
173 if ((bsize
& (bsize
- 1)) || nrbitsp
) {
176 for (nrbits
= 31; nrbits
&& !(bsize
& (1 << nrbits
)); nrbits
--)
181 if (bsize
< NFS_DEF_FILE_IO_BUFFER_SIZE
)
182 bsize
= NFS_DEF_FILE_IO_BUFFER_SIZE
;
188 extern struct nfs_fh
*nfs_fh_alloc(void);
189 extern void nfs_fh_free(struct nfs_fh
*p
);
192 * The way this works is that the mount process passes a structure
193 * in the data argument which contains the server's IP address
194 * and the root file handle obtained from the server's mount
195 * daemon. We stash these away in the private superblock fields.
198 nfs_read_super(struct super_block
*sb
, void *raw_data
, int silent
)
200 struct nfs_mount_data
*data
= (struct nfs_mount_data
*) raw_data
;
201 struct nfs_server
*server
;
202 struct rpc_xprt
*xprt
;
203 struct rpc_clnt
*clnt
;
204 struct nfs_fh
*root_fh
;
205 struct inode
*root_inode
;
206 unsigned int authflavor
;
208 struct sockaddr_in srvaddr
;
209 struct rpc_timeout timeparms
;
210 struct nfs_fattr fattr
;
216 if (data
->version
!= NFS_MOUNT_VERSION
) {
217 printk("nfs warning: mount version %s than kernel\n",
218 data
->version
< NFS_MOUNT_VERSION
? "older" : "newer");
219 if (data
->version
< 2)
221 if (data
->version
< 3)
225 /* We now require that the mount process passes the remote address */
226 memcpy(&srvaddr
, &data
->addr
, sizeof(srvaddr
));
227 if (srvaddr
.sin_addr
.s_addr
== INADDR_ANY
)
232 sb
->s_flags
|= MS_ODD_RENAME
; /* This should go away */
234 sb
->s_magic
= NFS_SUPER_MAGIC
;
235 sb
->s_op
= &nfs_sops
;
236 sb
->s_blocksize
= nfs_block_size(data
->bsize
, &sb
->s_blocksize_bits
);
237 sb
->u
.nfs_sb
.s_root
= data
->root
;
238 server
= &sb
->u
.nfs_sb
.s_server
;
239 server
->rsize
= nfs_block_size(data
->rsize
, NULL
);
240 server
->wsize
= nfs_block_size(data
->wsize
, NULL
);
241 server
->flags
= data
->flags
;
243 if (data
->flags
& NFS_MOUNT_NOAC
) {
244 data
->acregmin
= data
->acregmax
= 0;
245 data
->acdirmin
= data
->acdirmax
= 0;
247 server
->acregmin
= data
->acregmin
*HZ
;
248 server
->acregmax
= data
->acregmax
*HZ
;
249 server
->acdirmin
= data
->acdirmin
*HZ
;
250 server
->acdirmax
= data
->acdirmax
*HZ
;
252 server
->hostname
= kmalloc(strlen(data
->hostname
) + 1, GFP_KERNEL
);
253 if (!server
->hostname
)
255 strcpy(server
->hostname
, data
->hostname
);
257 /* Which protocol do we use? */
258 tcp
= (data
->flags
& NFS_MOUNT_TCP
);
260 /* Initialize timeout values */
261 timeparms
.to_initval
= data
->timeo
* HZ
/ 10;
262 timeparms
.to_retries
= data
->retrans
;
263 timeparms
.to_maxval
= tcp
? RPC_MAX_TCP_TIMEOUT
: RPC_MAX_UDP_TIMEOUT
;
264 timeparms
.to_exponential
= 1;
266 /* Now create transport and client */
267 xprt
= xprt_create_proto(tcp
? IPPROTO_TCP
: IPPROTO_UDP
,
268 &srvaddr
, &timeparms
);
272 /* Choose authentication flavor */
273 authflavor
= RPC_AUTH_UNIX
;
274 if (data
->flags
& NFS_MOUNT_SECURE
)
275 authflavor
= RPC_AUTH_DES
;
276 else if (data
->flags
& NFS_MOUNT_KERBEROS
)
277 authflavor
= RPC_AUTH_KRB
;
279 clnt
= rpc_create_client(xprt
, server
->hostname
, &nfs_program
,
280 NFS_VERSION
, authflavor
);
284 clnt
->cl_intr
= (data
->flags
& NFS_MOUNT_INTR
)? 1 : 0;
285 clnt
->cl_softrtry
= (data
->flags
& NFS_MOUNT_SOFT
)? 1 : 0;
287 server
->client
= clnt
;
289 /* Fire up rpciod if not yet running */
290 if (rpciod_up() != 0)
294 * Keep the super block locked while we try to get
295 * the root fh attributes.
297 root_fh
= nfs_fh_alloc();
300 *root_fh
= data
->root
;
302 if (nfs_proc_getattr(server
, root_fh
, &fattr
) != 0)
305 root_inode
= __nfs_fhget(sb
, &fattr
);
308 sb
->s_root
= d_alloc_root(root_inode
);
311 sb
->s_root
->d_op
= &nfs_dentry_operations
;
312 sb
->s_root
->d_fsdata
= root_fh
;
317 /* Check whether to start the lockd process */
318 if (!(server
->flags
& NFS_MOUNT_NONLM
))
322 /* Yargs. It didn't work out. */
324 printk("nfs_read_super: get root inode failed\n");
329 printk("nfs_read_super: get root fattr failed\n");
331 nfs_fh_free(root_fh
);
337 printk(KERN_WARNING
"NFS: couldn't start rpciod!\n");
339 rpc_shutdown_client(server
->client
);
343 printk(KERN_WARNING
"NFS: cannot create RPC client.\n");
348 printk(KERN_WARNING
"NFS: cannot create RPC transport.\n");
351 kfree(server
->hostname
);
357 printk("NFS: mount program didn't pass remote address!\n");
361 printk("nfs_read_super: missing data argument\n");
370 nfs_statfs(struct super_block
*sb
, struct statfs
*buf
, int bufsiz
)
373 struct nfs_fsinfo res
;
376 error
= nfs_proc_statfs(&sb
->u
.nfs_sb
.s_server
, &sb
->u
.nfs_sb
.s_root
,
379 printk("nfs_statfs: statfs error = %d\n", -error
);
380 res
.bsize
= res
.blocks
= res
.bfree
= res
.bavail
= 0;
382 tmp
.f_type
= NFS_SUPER_MAGIC
;
383 tmp
.f_bsize
= res
.bsize
;
384 tmp
.f_blocks
= res
.blocks
;
385 tmp
.f_bfree
= res
.bfree
;
386 tmp
.f_bavail
= res
.bavail
;
389 tmp
.f_namelen
= NAME_MAX
;
390 return copy_to_user(buf
, &tmp
, bufsiz
) ? -EFAULT
: 0;
394 * Free all unused dentries in an inode's alias list.
396 * Subtle note: we have to be very careful not to cause
397 * any IO operations with the stale dentries, as this
398 * could cause file corruption. But since the dentry
399 * count is 0 and all pending IO for a dentry has been
400 * flushed when the count went to 0, we're safe here.
401 * Also returns the number of unhashed dentries
404 nfs_free_dentries(struct inode
*inode
)
406 struct list_head
*tmp
, *head
= &inode
->i_dentry
;
412 while ((tmp
= tmp
->next
) != head
) {
413 struct dentry
*dentry
= list_entry(tmp
, struct dentry
, d_alias
);
414 dprintk("nfs_free_dentries: found %s/%s, d_count=%d, hashed=%d\n",
415 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
416 dentry
->d_count
, !list_empty(&dentry
->d_hash
));
417 if (!list_empty(&dentry
->d_subdirs
))
418 shrink_dcache_parent(dentry
);
419 if (!dentry
->d_count
) {
425 if (list_empty(&dentry
->d_hash
))
432 * Invalidate the local caches
435 nfs_zap_caches(struct inode
*inode
)
437 NFS_ATTRTIMEO(inode
) = NFS_MINATTRTIMEO(inode
);
440 invalidate_inode_pages(inode
);
441 if (S_ISDIR(inode
->i_mode
))
442 nfs_flush_dircache(inode
);
446 * Invalidate, but do not unhash, the inode
449 nfs_invalidate_inode(struct inode
*inode
)
451 umode_t save_mode
= inode
->i_mode
;
453 make_bad_inode(inode
);
454 inode
->i_mode
= save_mode
;
456 nfs_zap_caches(inode
);
460 * Fill in inode information from the fattr.
463 nfs_fill_inode(struct inode
*inode
, struct nfs_fattr
*fattr
)
466 * Check whether the mode has been set, as we only want to
467 * do this once. (We don't allow inodes to change types.)
469 if (inode
->i_mode
== 0) {
470 NFS_FILEID(inode
) = fattr
->fileid
;
471 NFS_FSID(inode
) = fattr
->fsid
;
472 inode
->i_mode
= fattr
->mode
;
473 /* Why so? Because we want revalidate for devices/FIFOs, and
474 * that's precisely what we have in nfs_file_inode_operations.
476 inode
->i_op
= &nfs_file_inode_operations
;
477 if (S_ISREG(inode
->i_mode
)) {
478 inode
->i_fop
= &nfs_file_operations
;
479 inode
->i_data
.a_ops
= &nfs_file_aops
;
480 } else if (S_ISDIR(inode
->i_mode
)) {
481 inode
->i_op
= &nfs_dir_inode_operations
;
482 inode
->i_fop
= &nfs_dir_operations
;
483 } else if (S_ISLNK(inode
->i_mode
))
484 inode
->i_op
= &nfs_symlink_inode_operations
;
486 init_special_inode(inode
, inode
->i_mode
, fattr
->rdev
);
488 * Preset the size and mtime, as there's no need
489 * to invalidate the caches.
491 inode
->i_size
= fattr
->size
;
492 inode
->i_mtime
= fattr
->mtime
.seconds
;
493 NFS_OLDMTIME(inode
) = fattr
->mtime
.seconds
;
495 nfs_refresh_inode(inode
, fattr
);
499 * In NFSv3 we can have 64bit inode numbers. In order to support
500 * this, and re-exported directories (also seen in NFSv2)
501 * we are forced to allow 2 different inodes to have the same
505 nfs_find_actor(struct inode
*inode
, unsigned long ino
, void *opaque
)
507 struct nfs_fattr
*fattr
= (struct nfs_fattr
*)opaque
;
508 if (NFS_FSID(inode
) != fattr
->fsid
)
510 if (NFS_FILEID(inode
) != fattr
->fileid
)
516 nfs_inode_is_stale(struct inode
*inode
, struct nfs_fattr
*fattr
)
522 (fattr
->mode
& S_IFMT
) != (inode
->i_mode
& S_IFMT
))
525 if (is_bad_inode(inode
))
529 * If the inode seems stale, free up cached dentries.
531 unhashed
= nfs_free_dentries(inode
);
533 /* Assume we're holding an i_count
535 * NB: sockets sometimes have volatile file handles
536 * don't invalidate their inodes even if all dentries are
539 if (unhashed
&& inode
->i_count
== unhashed
+ 1
540 && !S_ISSOCK(inode
->i_mode
) && !S_ISFIFO(inode
->i_mode
))
547 * This is our own version of iget that looks up inodes by file handle
548 * instead of inode number. We use this technique instead of using
549 * the vfs read_inode function because there is no way to pass the
550 * file handle or current attributes into the read_inode function.
552 * We provide a special check for NetApp .snapshot directories to avoid
553 * inode aliasing problems. All snapshot inodes are anonymous (unhashed).
556 nfs_fhget(struct dentry
*dentry
, struct nfs_fh
*fhandle
,
557 struct nfs_fattr
*fattr
)
559 struct super_block
*sb
= dentry
->d_sb
;
561 dprintk("NFS: nfs_fhget(%s/%s fileid=%d)\n",
562 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
565 /* Install the file handle in the dentry */
566 *((struct nfs_fh
*) dentry
->d_fsdata
) = *fhandle
;
568 #ifdef CONFIG_NFS_SNAPSHOT
570 * Check for NetApp snapshot dentries, and get an
571 * unhashed inode to avoid aliasing problems.
573 if ((dentry
->d_parent
->d_inode
->u
.nfs_i
.flags
& NFS_IS_SNAPSHOT
) ||
574 (dentry
->d_name
.len
== 9 &&
575 memcmp(dentry
->d_name
.name
, ".snapshot", 9) == 0)) {
576 struct inode
*inode
= get_empty_inode();
580 inode
->i_dev
= sb
->s_dev
;
582 inode
->i_ino
= fattr
->fileid
;
583 nfs_read_inode(inode
);
584 nfs_fill_inode(inode
, fattr
);
585 inode
->u
.nfs_i
.flags
|= NFS_IS_SNAPSHOT
;
586 dprintk("NFS: nfs_fhget(snapshot ino=%ld)\n", inode
->i_ino
);
591 return __nfs_fhget(sb
, fattr
);
595 * Look up the inode by super block and fattr->fileid.
597 * Note carefully the special handling of busy inodes (i_count > 1).
598 * With the kernel 2.1.xx dcache all inodes except hard links must
599 * have i_count == 1 after iget(). Otherwise, it indicates that the
600 * server has reused a fileid (i_ino) and we have a stale inode.
602 static struct inode
*
603 __nfs_fhget(struct super_block
*sb
, struct nfs_fattr
*fattr
)
605 struct inode
*inode
= NULL
;
609 printk("NFS: Buggy server - nlink == 0!\n");
615 while((inode
= iget4(sb
, ino
, nfs_find_actor
, fattr
)) != NULL
) {
618 * Check for busy inodes, and attempt to get rid of any
619 * unused local references. If successful, we release the
620 * inode and try again.
622 * Note that the busy test uses the values in the fattr,
623 * as the inode may have become a different object.
624 * (We can probably handle modes changes here, too.)
626 if (!nfs_inode_is_stale(inode
,fattr
))
629 dprintk("__nfs_fhget: inode %ld still busy, i_count=%d\n",
630 inode
->i_ino
, inode
->i_count
);
631 nfs_zap_caches(inode
);
632 remove_inode_hash(inode
);
639 nfs_fill_inode(inode
, fattr
);
640 dprintk("NFS: __nfs_fhget(%x/%ld ct=%d)\n",
641 inode
->i_dev
, inode
->i_ino
, inode
->i_count
);
647 printk("__nfs_fhget: iget failed\n");
652 nfs_notify_change(struct dentry
*dentry
, struct iattr
*attr
)
654 struct inode
*inode
= dentry
->d_inode
;
655 struct nfs_fattr fattr
;
659 * Make sure the inode is up-to-date.
661 error
= nfs_revalidate(dentry
);
664 printk("nfs_notify_change: revalidate failed, error=%d\n", error
);
669 if (!S_ISREG(inode
->i_mode
))
670 attr
->ia_valid
&= ~ATTR_SIZE
;
672 error
= nfs_wb_all(inode
);
676 error
= nfs_proc_setattr(NFS_DSERVER(dentry
), NFS_FH(dentry
),
681 * If we changed the size or mtime, update the inode
682 * now to avoid invalidating the page cache.
684 if (attr
->ia_valid
& ATTR_SIZE
) {
685 if (attr
->ia_size
!= fattr
.size
)
686 printk("nfs_notify_change: attr=%Ld, fattr=%d??\n",
687 (long long) attr
->ia_size
, fattr
.size
);
688 inode
->i_mtime
= fattr
.mtime
.seconds
;
689 vmtruncate(inode
, attr
->ia_size
);
691 if (attr
->ia_valid
& ATTR_MTIME
)
692 inode
->i_mtime
= fattr
.mtime
.seconds
;
693 error
= nfs_refresh_inode(inode
, &fattr
);
699 * Wait for the inode to get unlocked.
700 * (Used for NFS_INO_LOCKED and NFS_INO_REVALIDATING).
703 nfs_wait_on_inode(struct inode
*inode
, int flag
)
705 struct task_struct
*tsk
= current
;
706 DECLARE_WAITQUEUE(wait
, tsk
);
709 intr
= NFS_SERVER(inode
)->flags
& NFS_MOUNT_INTR
;
710 add_wait_queue(&inode
->i_wait
, &wait
);
712 set_task_state(tsk
, (intr
? TASK_INTERRUPTIBLE
: TASK_UNINTERRUPTIBLE
));
714 if (!(NFS_FLAGS(inode
) & flag
))
716 error
= -ERESTARTSYS
;
717 if (intr
&& signalled())
721 set_task_state(tsk
, TASK_RUNNING
);
722 remove_wait_queue(&inode
->i_wait
, &wait
);
727 * Externally visible revalidation function
730 nfs_revalidate(struct dentry
*dentry
)
732 return nfs_revalidate_inode(NFS_DSERVER(dentry
), dentry
);
736 * These are probably going to contain hooks for
737 * allocating and releasing RPC credentials for
738 * the file. I'll have to think about Tronds patch
741 int nfs_open(struct inode
*inode
, struct file
*filp
)
746 int nfs_release(struct inode
*inode
, struct file
*filp
)
752 * This function is called whenever some part of NFS notices that
753 * the cached attributes have to be refreshed.
756 __nfs_revalidate_inode(struct nfs_server
*server
, struct dentry
*dentry
)
758 struct inode
*inode
= dentry
->d_inode
;
760 struct nfs_fattr fattr
;
762 dfprintk(PAGECACHE
, "NFS: revalidating %s/%s, ino=%ld\n",
763 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
766 if (!inode
|| is_bad_inode(inode
))
769 while (NFS_REVALIDATING(inode
)) {
770 status
= nfs_wait_on_inode(inode
, NFS_INO_REVALIDATING
);
773 if (time_before(jiffies
,NFS_READTIME(inode
)+NFS_ATTRTIMEO(inode
)))
776 NFS_FLAGS(inode
) |= NFS_INO_REVALIDATING
;
778 status
= nfs_proc_getattr(server
, NFS_FH(dentry
), &fattr
);
782 struct nfs_fh fhandle
;
783 dfprintk(PAGECACHE
, "nfs_revalidate_inode: %s/%s getattr failed, ino=%ld, error=%d\n",
784 dentry
->d_parent
->d_name
.name
,
785 dentry
->d_name
.name
, inode
->i_ino
, status
);
786 if (status
!= -ESTALE
)
789 * A "stale filehandle" error ... show the current fh
790 * and find out what the filehandle should be.
792 fh
= (u32
*) NFS_FH(dentry
);
793 dfprintk(PAGECACHE
, "NFS: bad fh %08x%08x%08x%08x%08x%08x%08x%08x\n",
794 fh
[0],fh
[1],fh
[2],fh
[3],fh
[4],fh
[5],fh
[6],fh
[7]);
795 error
= nfs_proc_lookup(server
, NFS_FH(dentry
->d_parent
),
796 dentry
->d_name
.name
, &fhandle
, &fattr
);
798 dfprintk(PAGECACHE
, "NFS: lookup failed, error=%d\n", error
);
801 fh
= (u32
*) &fhandle
;
802 dfprintk(PAGECACHE
, " %08x%08x%08x%08x%08x%08x%08x%08x\n",
803 fh
[0],fh
[1],fh
[2],fh
[3],fh
[4],fh
[5],fh
[6],fh
[7]);
807 status
= nfs_refresh_inode(inode
, &fattr
);
809 dfprintk(PAGECACHE
, "nfs_revalidate_inode: %s/%s refresh failed, ino=%ld, error=%d\n",
810 dentry
->d_parent
->d_name
.name
,
811 dentry
->d_name
.name
, inode
->i_ino
, status
);
814 dfprintk(PAGECACHE
, "NFS: %s/%s revalidation complete\n",
815 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
);
817 NFS_FLAGS(inode
) &= ~NFS_INO_REVALIDATING
;
818 wake_up(&inode
->i_wait
);
823 * Many nfs protocol calls return the new file attributes after
824 * an operation. Here we update the inode to reflect the state
825 * of the server's inode.
827 * This is a bit tricky because we have to make sure all dirty pages
828 * have been sent off to the server before calling invalidate_inode_pages.
829 * To make sure no other process adds more write requests while we try
830 * our best to flush them, we make them sleep during the attribute refresh.
832 * A very similar scenario holds for the dir cache.
835 nfs_refresh_inode(struct inode
*inode
, struct nfs_fattr
*fattr
)
840 dfprintk(VFS
, "NFS: refresh_inode(%x/%ld ct=%d)\n",
841 inode
->i_dev
, inode
->i_ino
, inode
->i_count
);
843 if (!inode
|| !fattr
) {
844 printk("nfs_refresh_inode: inode or fattr is NULL\n");
847 if (inode
->i_ino
!= fattr
->fileid
) {
848 printk("nfs_refresh_inode: mismatch, ino=%ld, fattr=%d\n",
849 inode
->i_ino
, fattr
->fileid
);
854 * Make sure the inode's type hasn't changed.
856 if ((inode
->i_mode
& S_IFMT
) != (fattr
->mode
& S_IFMT
))
859 inode
->i_mode
= fattr
->mode
;
860 inode
->i_nlink
= fattr
->nlink
;
861 inode
->i_uid
= fattr
->uid
;
862 inode
->i_gid
= fattr
->gid
;
864 inode
->i_blocks
= fattr
->blocks
;
865 inode
->i_atime
= fattr
->atime
.seconds
;
866 inode
->i_ctime
= fattr
->ctime
.seconds
;
869 * Update the read time so we don't revalidate too often.
871 NFS_READTIME(inode
) = jiffies
;
875 * If we have pending write-back entries, we don't want
876 * to look at the size or the mtime the server sends us
877 * too closely, as we're in the middle of modifying them.
879 if (NFS_WRITEBACK(inode
))
882 if (inode
->i_size
!= fattr
->size
) {
883 #ifdef NFS_DEBUG_VERBOSE
884 printk("NFS: size change on %x/%ld\n", inode
->i_dev
, inode
->i_ino
);
886 inode
->i_size
= fattr
->size
;
890 if (inode
->i_mtime
!= fattr
->mtime
.seconds
) {
891 #ifdef NFS_DEBUG_VERBOSE
892 printk("NFS: mtime change on %x/%ld\n", inode
->i_dev
, inode
->i_ino
);
894 inode
->i_mtime
= fattr
->mtime
.seconds
;
901 /* Update attrtimeo value */
902 if (fattr
->mtime
.seconds
== NFS_OLDMTIME(inode
)) {
903 if ((NFS_ATTRTIMEO(inode
) <<= 1) > NFS_MAXATTRTIMEO(inode
))
904 NFS_ATTRTIMEO(inode
) = NFS_MAXATTRTIMEO(inode
);
906 NFS_OLDMTIME(inode
) = fattr
->mtime
.seconds
;
913 * Big trouble! The inode has become a different object.
916 printk("nfs_refresh_inode: inode %ld mode changed, %07o to %07o\n",
917 inode
->i_ino
, inode
->i_mode
, fattr
->mode
);
920 * No need to worry about unhashing the dentry, as the
921 * lookup validation will know that the inode is bad.
923 nfs_invalidate_inode(inode
);
927 #ifdef NFS_DEBUG_VERBOSE
928 printk("nfs_refresh_inode: invalidating %ld pages\n", inode
->i_nrpages
);
930 nfs_zap_caches(inode
);
935 * File system information
937 static struct file_system_type nfs_fs_type
= {
939 0 /* FS_NO_DCACHE - this doesn't work right now*/,
944 extern int nfs_init_fhcache(void);
945 extern int nfs_init_wreqcache(void);
955 err
= nfs_init_fhcache();
959 err
= nfs_init_wreqcache();
963 #ifdef CONFIG_PROC_FS
964 rpc_proc_register(&nfs_rpcstat
);
966 return register_filesystem(&nfs_fs_type
);
970 * Every kernel module contains stuff like this.
975 /* Not quite true; I just maintain it */
976 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
981 return init_nfs_fs();
987 #ifdef CONFIG_PROC_FS
988 rpc_proc_unregister("nfs");
990 unregister_filesystem(&nfs_fs_type
);