3 * Directory operations for Coda filesystem
4 * Original version: (C) 1996 P. Braam and M. Callahan
5 * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University
7 * Carnegie Mellon encourages users to contribute improvements to
8 * the Coda project. Contact Peter Braam (coda@cs.cmu.edu).
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
15 #include <linux/stat.h>
16 #include <linux/errno.h>
17 #include <linux/locks.h>
18 #include <asm/segment.h>
19 #include <asm/uaccess.h>
20 #include <linux/string.h>
22 #include <linux/coda.h>
23 #include <linux/coda_linux.h>
24 #include <linux/coda_psdev.h>
25 #include <linux/coda_fs_i.h>
26 #include <linux/coda_cache.h>
27 #include <linux/coda_proc.h>
30 static int coda_create(struct inode
*dir
, struct dentry
*new, int mode
);
31 static int coda_mknod(struct inode
*dir
, struct dentry
*new, int mode
, int rdev
);
32 static struct dentry
*coda_lookup(struct inode
*dir
, struct dentry
*target
);
33 static int coda_link(struct dentry
*old_dentry
, struct inode
*dir_inode
,
34 struct dentry
*entry
);
35 static int coda_unlink(struct inode
*dir_inode
, struct dentry
*entry
);
36 static int coda_symlink(struct inode
*dir_inode
, struct dentry
*entry
,
38 static int coda_mkdir(struct inode
*dir_inode
, struct dentry
*entry
, int mode
);
39 static int coda_rmdir(struct inode
*dir_inode
, struct dentry
*entry
);
40 static int coda_rename(struct inode
*old_inode
, struct dentry
*old_dentry
,
41 struct inode
*new_inode
, struct dentry
*new_dentry
);
44 static int coda_readdir(struct file
*file
, void *dirent
, filldir_t filldir
);
47 static int coda_dentry_revalidate(struct dentry
*de
, int);
48 static int coda_dentry_delete(struct dentry
*);
50 /* support routines */
51 static void coda_prepare_fakefile(struct inode
*coda_inode
,
52 struct file
*coda_file
,
53 struct inode
*open_inode
,
54 struct file
*open_file
,
55 struct dentry
*open_dentry
);
56 static int coda_venus_readdir(struct file
*filp
, void *dirent
,
58 int coda_fsync(struct file
*, struct dentry
*dentry
, int);
60 int coda_hasmknod
= 0;
62 struct dentry_operations coda_dentry_operations
=
64 d_revalidate
: coda_dentry_revalidate
,
65 d_delete
: coda_dentry_delete
,
68 struct inode_operations coda_dir_inode_operations
=
74 symlink
: coda_symlink
,
79 permission
: coda_permission
,
80 revalidate
: coda_revalidate_inode
,
81 setattr
: coda_notify_change
,
84 struct file_operations coda_dir_operations
= {
85 read
: generic_read_dir
,
86 readdir
: coda_readdir
,
88 release
: coda_release
,
93 /* inode operations for directories */
94 /* acces routines: lookup, readlink, permission */
95 static struct dentry
*coda_lookup(struct inode
*dir
, struct dentry
*entry
)
97 struct inode
*res_inode
= NULL
;
98 struct ViceFid resfid
= {0,0,0};
99 int dropme
= 0; /* to indicate entry should not be cached */
102 const char *name
= entry
->d_name
.name
;
103 size_t length
= entry
->d_name
.len
;
107 if ( length
> CODA_MAXNAMLEN
) {
108 printk("name too long: lookup, %s (%*s)\n",
109 coda_i2s(dir
), (int)length
, name
);
110 return ERR_PTR(-ENAMETOOLONG
);
113 CDEBUG(D_INODE
, "name %s, len %ld in ino %ld, fid %s\n",
114 name
, (long)length
, dir
->i_ino
, coda_i2s(dir
));
116 /* control object, create inode on the fly */
117 if (coda_isroot(dir
) && coda_iscontrol(name
, length
)) {
118 error
= coda_cnode_makectl(&res_inode
, dir
->i_sb
);
120 "Lookup on CTL object; dir ino %ld, count %d\n",
121 dir
->i_ino
, atomic_read(&dir
->i_count
));
126 error
= venus_lookup(dir
->i_sb
, coda_i2f(dir
),
127 (const char *)name
, length
, &type
, &resfid
);
131 if (type
& CODA_NOCACHE
) {
132 type
&= (~CODA_NOCACHE
);
133 CDEBUG(D_INODE
, "dropme set for %s\n",
138 error
= coda_cnode_make(&res_inode
, &resfid
, dir
->i_sb
);
139 if (error
) return ERR_PTR(error
);
141 /* make sure we drop unexpected weird fid's */
142 if (coda_f2i(&resfid
) != res_inode
->i_ino
&&
143 !coda_fid_is_weird(&resfid
))
145 } else if (error
!= -ENOENT
) {
146 CDEBUG(D_INODE
, "error for %s(%*s)%d\n",
147 coda_i2s(dir
), (int)length
, name
, error
);
148 return ERR_PTR(error
);
150 CDEBUG(D_INODE
, "lookup: %s is (%s), type %d result %d, dropme %d\n",
151 name
, coda_f2s(&resfid
), type
, error
, dropme
);
155 entry
->d_op
= &coda_dentry_operations
;
156 d_add(entry
, res_inode
);
159 coda_flag_inode(res_inode
, C_VATTR
);
166 int coda_permission(struct inode
*inode
, int mask
)
171 coda_vfs_stat
.permission
++;
172 coda_permission_stat
.count
++;
177 if ( coda_access_cache
== 1 ) {
178 if ( coda_cache_check(inode
, mask
) ) {
179 coda_permission_stat
.hit_count
++;
184 CDEBUG(D_INODE
, "mask is %o\n", mask
);
185 error
= venus_access(inode
->i_sb
, coda_i2f(inode
), mask
);
187 CDEBUG(D_INODE
, "fid: %s, ino: %ld (mask: %o) error: %d\n",
188 coda_i2s(inode
), inode
->i_ino
, mask
, error
);
191 coda_cache_enter(inode
, mask
);
197 static inline void coda_dir_changed(struct inode
*dir
, int link
)
199 #ifdef REQUERY_VENUS_FOR_MTIME
200 /* invalidate the directory cnode's attributes so we refetch the
201 * attributes from venus next time the inode is referenced */
202 coda_flag_inode(dir
, C_VATTR
);
204 /* optimistically we can also act as if our nose bleeds. The
205 * granularity of the mtime is coarse anyways so we might actually be
206 * right most of the time. Note: we only do this for directories. */
207 dir
->i_mtime
= CURRENT_TIME
;
210 dir
->i_nlink
+= link
;
213 /* creation routines: create, mknod, mkdir, link, symlink */
214 static int coda_create(struct inode
*dir
, struct dentry
*de
, int mode
)
217 const char *name
=de
->d_name
.name
;
218 int length
=de
->d_name
.len
;
219 struct inode
*result
= NULL
;
220 struct ViceFid newfid
;
221 struct coda_vattr attrs
;
224 coda_vfs_stat
.create
++;
226 CDEBUG(D_INODE
, "name: %s, length %d, mode %o\n", name
, length
, mode
);
228 if (coda_isroot(dir
) && coda_iscontrol(name
, length
))
231 error
= venus_create(dir
->i_sb
, coda_i2f(dir
), name
, length
,
232 0, mode
, 0, &newfid
, &attrs
);
235 CDEBUG(D_INODE
, "create: %s, result %d\n",
236 coda_f2s(&newfid
), error
);
241 error
= coda_cnode_make(&result
, &newfid
, dir
->i_sb
);
248 /* invalidate the directory cnode's attributes */
249 coda_dir_changed(dir
, 0);
250 d_instantiate(de
, result
);
254 static int coda_mknod(struct inode
*dir
, struct dentry
*de
, int mode
, int rdev
)
257 const char *name
=de
->d_name
.name
;
258 int length
=de
->d_name
.len
;
259 struct inode
*result
= NULL
;
260 struct ViceFid newfid
;
261 struct coda_vattr attrs
;
263 if ( coda_hasmknod
== 0 )
266 coda_vfs_stat
.create
++;
268 CDEBUG(D_INODE
, "name: %s, length %d, mode %o, rdev %x\n",
269 name
, length
, mode
, rdev
);
271 if (coda_isroot(dir
) && coda_iscontrol(name
, length
))
274 error
= venus_create(dir
->i_sb
, coda_i2f(dir
), name
, length
,
275 0, mode
, rdev
, &newfid
, &attrs
);
278 CDEBUG(D_INODE
, "mknod: %s, result %d\n",
279 coda_f2s(&newfid
), error
);
284 error
= coda_cnode_make(&result
, &newfid
, dir
->i_sb
);
291 /* invalidate the directory cnode's attributes */
292 coda_dir_changed(dir
, 0);
293 d_instantiate(de
, result
);
297 static int coda_mkdir(struct inode
*dir
, struct dentry
*de
, int mode
)
300 struct coda_vattr attr
;
301 const char *name
= de
->d_name
.name
;
302 int len
= de
->d_name
.len
;
304 struct ViceFid newfid
;
307 coda_vfs_stat
.mkdir
++;
309 if (coda_isroot(dir
) && coda_iscontrol(name
, len
))
312 CDEBUG(D_INODE
, "mkdir %s (len %d) in %s, mode %o.\n",
313 name
, len
, coda_i2s(dir
), mode
);
316 error
= venus_mkdir(dir
->i_sb
, coda_i2f(dir
),
317 name
, len
, &newfid
, &attr
);
320 CDEBUG(D_INODE
, "mkdir error: %s result %d\n",
321 coda_f2s(&newfid
), error
);
326 CDEBUG(D_INODE
, "mkdir: new dir has fid %s.\n",
329 error
= coda_cnode_make(&inode
, &newfid
, dir
->i_sb
);
335 /* invalidate the directory cnode's attributes */
336 coda_dir_changed(dir
, 1);
337 d_instantiate(de
, inode
);
341 /* try to make de an entry in dir_inodde linked to source_de */
342 static int coda_link(struct dentry
*source_de
, struct inode
*dir_inode
,
345 struct inode
*inode
= source_de
->d_inode
;
346 const char * name
= de
->d_name
.name
;
347 int len
= de
->d_name
.len
;
351 coda_vfs_stat
.link
++;
353 if (coda_isroot(dir_inode
) && coda_iscontrol(name
, len
))
356 CDEBUG(D_INODE
, "old: fid: %s\n", coda_i2s(inode
));
357 CDEBUG(D_INODE
, "directory: %s\n", coda_i2s(dir_inode
));
359 error
= venus_link(dir_inode
->i_sb
, coda_i2f(inode
),
360 coda_i2f(dir_inode
), (const char *)name
, len
);
367 coda_dir_changed(dir_inode
, 0);
368 atomic_inc(&inode
->i_count
);
369 d_instantiate(de
, inode
);
373 CDEBUG(D_INODE
, "link result %d\n",error
);
379 static int coda_symlink(struct inode
*dir_inode
, struct dentry
*de
,
382 const char *name
= de
->d_name
.name
;
383 int len
= de
->d_name
.len
;
388 coda_vfs_stat
.symlink
++;
390 if (coda_isroot(dir_inode
) && coda_iscontrol(name
, len
))
393 symlen
= strlen(symname
);
394 if ( symlen
> CODA_MAXPATHLEN
)
395 return -ENAMETOOLONG
;
397 CDEBUG(D_INODE
, "symname: %s, length: %d\n", symname
, symlen
);
400 * This entry is now negative. Since we do not create
401 * an inode for the entry we have to drop it.
404 error
= venus_symlink(dir_inode
->i_sb
, coda_i2f(dir_inode
), name
, len
,
407 /* mtime is no good anymore */
409 coda_dir_changed(dir_inode
, 0);
411 CDEBUG(D_INODE
, "in symlink result %d\n",error
);
416 /* destruction routines: unlink, rmdir */
417 int coda_unlink(struct inode
*dir
, struct dentry
*de
)
420 const char *name
= de
->d_name
.name
;
421 int len
= de
->d_name
.len
;
424 coda_vfs_stat
.unlink
++;
426 CDEBUG(D_INODE
, " %s in %s, dirino %ld\n", name
,
427 coda_i2s(dir
), dir
->i_ino
);
429 error
= venus_remove(dir
->i_sb
, coda_i2f(dir
), name
, len
);
431 CDEBUG(D_INODE
, "upc returned error %d\n", error
);
435 coda_dir_changed(dir
, 0);
436 de
->d_inode
->i_nlink
--;
441 int coda_rmdir(struct inode
*dir
, struct dentry
*de
)
443 const char *name
= de
->d_name
.name
;
444 int len
= de
->d_name
.len
;
448 coda_vfs_stat
.rmdir
++;
452 error
= venus_rmdir(dir
->i_sb
, coda_i2f(dir
), name
, len
);
455 CDEBUG(D_INODE
, "upc returned error %d\n", error
);
459 coda_dir_changed(dir
, -1);
460 de
->d_inode
->i_nlink
--;
467 static int coda_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
468 struct inode
*new_dir
, struct dentry
*new_dentry
)
470 const char *old_name
= old_dentry
->d_name
.name
;
471 const char *new_name
= new_dentry
->d_name
.name
;
472 int old_length
= old_dentry
->d_name
.len
;
473 int new_length
= new_dentry
->d_name
.len
;
477 coda_vfs_stat
.rename
++;
479 CDEBUG(D_INODE
, "old: %s, (%d length), new: %s"
480 "(%d length). old:d_count: %d, new:d_count: %d\n",
481 old_name
, old_length
, new_name
, new_length
,
482 old_dentry
->d_count
, new_dentry
->d_count
);
484 error
= venus_rename(old_dir
->i_sb
, coda_i2f(old_dir
),
485 coda_i2f(new_dir
), old_length
, new_length
,
486 (const char *) old_name
, (const char *)new_name
);
489 if ( new_dentry
->d_inode
) {
490 if ( S_ISDIR(new_dentry
->d_inode
->i_mode
) ) {
494 coda_flag_inode(new_dentry
->d_inode
, C_VATTR
);
497 /* coda_flag_inode(old_dir, C_VATTR); */
498 /* coda_flag_inode(new_dir, C_VATTR); */
499 old_dir
->i_mtime
= new_dir
->i_mtime
= CURRENT_TIME
;
502 CDEBUG(D_INODE
, "result %d\n", error
);
509 /* file operations for directories */
510 int coda_readdir(struct file
*file
, void *dirent
, filldir_t filldir
)
513 struct file open_file
;
514 struct dentry open_dentry
;
515 struct inode
*inode
=file
->f_dentry
->d_inode
, *container
;
518 coda_vfs_stat
.readdir
++;
520 if ( inode
->i_mapping
== &inode
->i_data
) {
521 CDEBUG(D_FILE
, "no container inode.\n");
525 container
= (struct inode
*)inode
->i_mapping
->host
;
527 coda_prepare_fakefile(inode
, file
, container
, &open_file
, &open_dentry
);
529 if ( S_ISREG(container
->i_mode
) ) {
530 /* Venus: we must read Venus dirents from the file */
531 result
= coda_venus_readdir(&open_file
, dirent
, filldir
);
533 /* potemkin case: we are handed a directory inode */
534 result
= vfs_readdir(&open_file
, filldir
, dirent
);
537 /* we only have to restore the file position (and f_version?) */
538 file
->f_pos
= open_file
.f_pos
;
539 file
->f_version
= open_file
.f_version
;
545 /* grab the ext2 inode of the container file */
546 static int coda_inode_grab(dev_t dev
, ino_t ino
, struct inode
**ind
)
548 struct super_block
*sbptr
;
550 sbptr
= get_super(dev
);
553 printk("coda_inode_grab: coda_find_super returns NULL.\n");
558 *ind
= iget(sbptr
, ino
);
560 if ( *ind
== NULL
) {
561 printk("coda_inode_grab: iget(dev: %d, ino: %ld) "
562 "returns NULL.\n", dev
, (long)ino
);
565 CDEBUG(D_FILE
, "ino: %ld, ops at %p\n", (long)ino
, (*ind
)->i_op
);
569 /* ask venus to cache the file and return the inode of the container file,
570 put this inode pointer in the cnode for future read/writes */
571 int coda_open(struct inode
*i
, struct file
*f
)
576 struct inode
*cont_inode
= NULL
, *old_container
;
577 unsigned short flags
= f
->f_flags
& (~O_EXCL
);
578 unsigned short coda_flags
= coda_flags_to_cflags(flags
);
579 struct coda_cred
*cred
;
582 coda_vfs_stat
.open
++;
584 CDEBUG(D_SPECIAL
, "OPEN inode number: %ld, count %d, flags %o.\n",
585 f
->f_dentry
->d_inode
->i_ino
, f
->f_dentry
->d_count
, flags
);
587 error
= venus_open(i
->i_sb
, coda_i2f(i
), coda_flags
, &ino
, &dev
);
589 CDEBUG(D_FILE
, "venus: dev %d, inode %ld, out->result %d\n",
590 dev
, (long)ino
, error
);
594 /* coda_upcall returns ino number of cached object, get inode */
595 CDEBUG(D_FILE
, "cache file dev %d, ino %ld\n", dev
, (long)ino
);
596 error
= coda_inode_grab(dev
, ino
, &cont_inode
);
598 if ( error
|| !cont_inode
){
599 printk("coda_open: coda_inode_grab error %d.", error
);
605 CODA_ALLOC(cred
, struct coda_cred
*, sizeof(*cred
));
606 coda_load_creds(cred
);
607 f
->private_data
= cred
;
609 if ( i
->i_mapping
!= &i
->i_data
) {
610 old_container
= (struct inode
*)i
->i_mapping
->host
;
611 i
->i_mapping
= &i
->i_data
;
614 i
->i_mapping
= cont_inode
->i_mapping
;
616 CDEBUG(D_FILE
, "result %d, coda i->i_count is %d for ino %ld\n",
617 error
, atomic_read(&i
->i_count
), i
->i_ino
);
618 CDEBUG(D_FILE
, "cache ino: %ld, count %d, ops %p\n",
619 cont_inode
->i_ino
, atomic_read(&cont_inode
->i_count
),
625 int coda_release(struct inode
*i
, struct file
*f
)
627 struct inode
*container
= NULL
;
629 unsigned short flags
= (f
->f_flags
) & (~O_EXCL
);
630 unsigned short cflags
= coda_flags_to_cflags(flags
);
631 struct coda_cred
*cred
;
634 coda_vfs_stat
.release
++;
636 cred
= (struct coda_cred
*)f
->private_data
;
638 if (i
->i_mapping
!= &i
->i_data
)
639 container
= (struct inode
*)i
->i_mapping
->host
;
641 CDEBUG(D_FILE
, "RELEASE coda (ino %ld, ct %d) cache (ino %ld, ct %d)\n",
642 i
->i_ino
, atomic_read(&i
->i_count
),
643 (container
? container
->i_ino
: 0),
644 (container
? atomic_read(&container
->i_count
) : -99));
646 error
= venus_release(i
->i_sb
, coda_i2f(i
), cflags
, cred
);
648 f
->private_data
= NULL
;
650 CODA_FREE(cred
, sizeof(*cred
));
652 CDEBUG(D_FILE
, "coda_release: result: %d\n", error
);
656 /* support routines */
658 /* instantiate a fake file and dentry to pass to coda_venus_readdir */
659 static void coda_prepare_fakefile(struct inode
*i
, struct file
*coda_file
,
660 struct inode
*cont_inode
,
661 struct file
*cont_file
,
662 struct dentry
*cont_dentry
)
664 cont_file
->f_dentry
= cont_dentry
;
665 cont_file
->f_dentry
->d_inode
= cont_inode
;
666 cont_file
->f_pos
= coda_file
->f_pos
;
667 cont_file
->f_version
= coda_file
->f_version
;
668 cont_file
->f_op
= cont_inode
->i_fop
;
673 * this structure is manipulated by filldir in vfs layer.
674 * the count holds the remaining amount of space in the getdents buffer,
675 * beyond the current_dir pointer.
677 * What structure is this comment referring to?? -JH
680 /* should be big enough to hold any single directory entry */
681 #define DIR_BUFSIZE 2048
683 static int coda_venus_readdir(struct file
*filp
, void *getdent
,
687 int offset
= filp
->f_pos
; /* offset in the directory file */
689 int pos
= 0; /* offset in the block we read */
690 int result
= 0; /* either an error or # of entries returned */
693 struct venus_dirent
*vdirent
;
694 int string_offset
= (int) (&((struct venus_dirent
*)(0))->d_name
);
699 CODA_ALLOC(buff
, char *, DIR_BUFSIZE
);
701 printk("coda_venus_readdir: out of memory.\n");
705 /* we use this routine to read the file into our buffer */
706 bufsize
= kernel_read(filp
, filp
->f_pos
, buff
, DIR_BUFSIZE
);
708 printk("coda_venus_readdir: cannot read directory %d.\n",
718 /* Parse and write into user space. Filldir tells us when done! */
719 CDEBUG(D_FILE
, "buffsize: %d offset %d, count %d.\n",
720 bufsize
, offset
, count
);
724 while ( pos
+ string_offset
< bufsize
&& i
< 1024) {
725 vdirent
= (struct venus_dirent
*) (buff
+ pos
);
727 /* test if the name is fully in the buffer */
728 if ( pos
+ string_offset
+ (int) vdirent
->d_namlen
>= bufsize
){
730 printk("CODA: Invalid directory cfino: %ld\n",
731 filp
->f_dentry
->d_inode
->i_ino
);
734 /* now we are certain that we can read the entry from buff */
736 /* if we don't have a null entry, copy it */
737 if ( vdirent
->d_fileno
&& vdirent
->d_reclen
) {
738 int namlen
= vdirent
->d_namlen
;
739 off_t offs
= filp
->f_pos
;
740 ino_t ino
= vdirent
->d_fileno
;
741 char *name
= vdirent
->d_name
;
743 errfill
= filldir(getdent
, name
, namlen
,
745 CDEBUG(D_FILE
, "entry %d: ino %ld, namlen %d, reclen %d, type %d, pos %d, string_offs %d, name %*s, offset %d, result: %d, errfill: %d.\n", i
,vdirent
->d_fileno
, vdirent
->d_namlen
, vdirent
->d_reclen
, vdirent
->d_type
, pos
, string_offset
, vdirent
->d_namlen
, vdirent
->d_name
, (u_int
) offs
, result
, errfill
);
746 /* errfill means no space for filling in this round */
755 filp
->f_pos
+= vdirent
->d_reclen
;
756 if ( filp
->f_pos
> filp
->f_dentry
->d_inode
->i_size
)
758 if ( !vdirent
->d_reclen
) {
759 printk("CODA: Invalid directory, cfino: %ld\n",
760 filp
->f_dentry
->d_inode
->i_ino
);
764 pos
+= (unsigned int) vdirent
->d_reclen
;
769 printk("Repeating too much in readdir %ld\n",
770 filp
->f_dentry
->d_inode
->i_ino
);
775 CODA_FREE(buff
, DIR_BUFSIZE
);
779 /* called when a cache lookup succeeds */
780 static int coda_dentry_revalidate(struct dentry
*de
, int flags
)
783 struct inode
*inode
= de
->d_inode
;
784 struct coda_inode_info
*cii
;
789 if (coda_isroot(inode
))
791 if (is_bad_inode(inode
))
794 cii
= ITOC(de
->d_inode
);
795 if (! (cii
->c_flags
& (C_PURGE
| C_FLUSH
)) )
798 shrink_dcache_parent(de
);
800 /* propagate for a flush */
801 if (cii
->c_flags
& C_FLUSH
)
802 coda_flag_inode_children(inode
, C_FLUSH
);
804 if (de
->d_count
> 1) {
805 /* pretend it's valid, but don't change the flags */
806 CDEBUG(D_DOWNCALL
, "BOOM for: ino %ld, %s\n",
807 de
->d_inode
->i_ino
, coda_f2s(&cii
->c_fid
));
811 /* clear the flags. */
812 cii
->c_flags
&= ~(C_VATTR
| C_PURGE
| C_FLUSH
);
818 * This is the callback from dput() when d_count is going to 0.
819 * We use this to unhash dentries with bad inodes.
821 static int coda_dentry_delete(struct dentry
* dentry
)
825 if (!dentry
->d_inode
)
828 flags
= (ITOC(dentry
->d_inode
)->c_flags
) & C_PURGE
;
829 if (is_bad_inode(dentry
->d_inode
) || flags
) {
830 CDEBUG(D_DOWNCALL
, "bad inode, unhashing %s/%s, %ld\n",
831 dentry
->d_parent
->d_name
.name
, dentry
->d_name
.name
,
832 dentry
->d_inode
->i_ino
);
841 * This is called when we want to check if the inode has
842 * changed on the server. Coda makes this easy since the
843 * cache manager Venus issues a downcall to the kernel when this
846 int coda_revalidate_inode(struct dentry
*dentry
)
848 struct coda_vattr attr
;
852 struct inode
*inode
= dentry
->d_inode
, *container
;
853 struct coda_inode_info
*cii
= ITOC(inode
);
856 CDEBUG(D_INODE
, "revalidating: %*s/%*s\n",
857 dentry
->d_name
.len
, dentry
->d_name
.name
,
858 dentry
->d_parent
->d_name
.len
, dentry
->d_parent
->d_name
.name
);
860 if ( cii
->c_flags
== 0 )
863 if (cii
->c_flags
& (C_VATTR
| C_PURGE
| C_FLUSH
)) {
864 error
= venus_getattr(inode
->i_sb
, &(cii
->c_fid
), &attr
);
866 goto return_bad_inode
;
868 /* this inode may be lost if:
870 - type changes must be permitted for repair and
871 missing mount points.
873 old_mode
= inode
->i_mode
;
874 old_ino
= inode
->i_ino
;
875 coda_vattr_to_iattr(inode
, &attr
);
877 if ((old_mode
& S_IFMT
) != (inode
->i_mode
& S_IFMT
)) {
878 printk("Coda: inode %ld, fid %s changed type!\n",
879 inode
->i_ino
, coda_f2s(&(cii
->c_fid
)));
882 /* the following can happen when a local fid is replaced
883 with a global one, here we lose and declare the inode bad */
884 if (inode
->i_ino
!= old_ino
)
885 goto return_bad_inode
;
888 coda_flag_inode_children(inode
, C_FLUSH
);
890 cii
->c_flags
&= ~(C_VATTR
| C_PURGE
| C_FLUSH
);
896 if ( inode
->i_mapping
!= &inode
->i_data
) {
897 container
= (struct inode
*)inode
->i_mapping
->host
;
898 inode
->i_mapping
= &inode
->i_data
;
901 make_bad_inode(inode
);