1 /* cnode related routines for the coda kernel code
5 #include <linux/types.h>
6 #include <linux/string.h>
7 #include <linux/time.h>
9 #include <linux/coda.h>
10 #include <linux/coda_linux.h>
11 #include <linux/coda_fs_i.h>
12 #include <linux/coda_psdev.h>
14 extern int coda_debug
;
15 extern int coda_print_entry
;
17 inline int coda_fideq(ViceFid
*fid1
, ViceFid
*fid2
)
19 if (fid1
->Vnode
!= fid2
->Vnode
)
21 if (fid1
->Volume
!= fid2
->Volume
)
23 if (fid1
->Unique
!= fid2
->Unique
)
28 static struct inode_operations coda_symlink_inode_operations
= {
29 readlink
: page_readlink
,
30 follow_link
: page_follow_link
,
31 setattr
: coda_notify_change
,
35 static void coda_fill_inode(struct inode
*inode
, struct coda_vattr
*attr
)
37 CDEBUG(D_SUPER
, "ino: %ld\n", inode
->i_ino
);
39 if (coda_debug
& D_SUPER
)
42 coda_vattr_to_iattr(inode
, attr
);
44 if (S_ISREG(inode
->i_mode
)) {
45 inode
->i_op
= &coda_file_inode_operations
;
46 inode
->i_fop
= &coda_file_operations
;
47 } else if (S_ISDIR(inode
->i_mode
)) {
48 inode
->i_op
= &coda_dir_inode_operations
;
49 inode
->i_fop
= &coda_dir_operations
;
50 } else if (S_ISLNK(inode
->i_mode
)) {
51 inode
->i_op
= &coda_symlink_inode_operations
;
52 inode
->i_data
.a_ops
= &coda_symlink_aops
;
54 init_special_inode(inode
, inode
->i_mode
, attr
->va_rdev
);
57 struct inode
* coda_iget(struct super_block
* sb
, ViceFid
* fid
,
58 struct coda_vattr
* attr
)
61 struct coda_sb_info
*sbi
= coda_sbp(sb
);
62 struct coda_inode_info
*cii
;
63 ino_t ino
= attr
->va_fileid
;
65 inode
= iget(sb
, ino
);
67 CDEBUG(D_CNODE
, "coda_iget: no inode\n");
71 /* check if the inode is already initialized */
73 if (cii
->c_magic
== CODA_CNODE_MAGIC
)
76 /* Initialize the Coda inode info structure */
77 memset(cii
, 0, (int) sizeof(struct coda_inode_info
));
78 cii
->c_magic
= CODA_CNODE_MAGIC
;
82 INIT_LIST_HEAD(&(cii
->c_cnhead
));
83 INIT_LIST_HEAD(&(cii
->c_volrootlist
));
85 coda_fill_inode(inode
, attr
);
87 /* check if it is a weird fid (hashed fid != ino), f.i mountpoints
88 repair object, expanded local-global conflict trees, etc.
90 if ( coda_f2i(fid
) == ino
)
93 /* check if we expect this weird fid */
94 if ( !coda_fid_is_weird(fid
) )
95 printk("Coda: unknown weird fid: ino %ld, fid %s."
96 "Tell Peter.\n", (long)ino
, coda_f2s(&cii
->c_fid
));
98 /* add the inode to a global list so we can find it back later */
99 list_add(&cii
->c_volrootlist
, &sbi
->sbi_volroothead
);
100 CDEBUG(D_CNODE
, "Added %ld, %s to volroothead\n",
101 (long)ino
, coda_f2s(&cii
->c_fid
));
106 /* this is effectively coda_iget:
107 - get attributes (might be cached)
108 - get the inode for the fid using vfs iget
109 - link the two up if this is needed
110 - fill in the attributes
112 int coda_cnode_make(struct inode
**inode
, ViceFid
*fid
, struct super_block
*sb
)
114 struct coda_inode_info
*cnp
;
115 struct coda_vattr attr
;
120 /* We get inode numbers from Venus -- see venus source */
122 error
= venus_getattr(sb
, fid
, &attr
);
125 "coda_cnode_make: coda_getvattr returned %d for %s.\n",
126 error
, coda_f2s(fid
));
131 *inode
= coda_iget(sb
, fid
, &attr
);
133 printk("coda_cnode_make: coda_iget failed\n");
138 /* see if it is the right one (we might have an inode collision) */
139 if ( coda_fideq(fid
, &cnp
->c_fid
) ) {
141 "Done making inode: ino %ld, count %d with %s\n",
142 (*inode
)->i_ino
, atomic_read(&(*inode
)->i_count
),
143 coda_f2s(&cnp
->c_fid
));
149 printk("coda_cnode_make on initialized inode %ld, old %s new %s!\n",
150 (*inode
)->i_ino
, coda_f2s(&cnp
->c_fid
), coda_f2s2(fid
));
157 void coda_replace_fid(struct inode
*inode
, struct ViceFid
*oldfid
,
158 struct ViceFid
*newfid
)
160 struct coda_inode_info
*cnp
;
161 struct coda_sb_info
*sbi
= coda_sbp(inode
->i_sb
);
165 if ( ! coda_fideq(&cnp
->c_fid
, oldfid
) )
166 printk("What? oldfid != cnp->c_fid. Call 911.\n");
168 cnp
->c_fid
= *newfid
;
170 list_del(&cnp
->c_volrootlist
);
171 if ( !coda_fid_is_weird(newfid
) )
172 list_add(&cnp
->c_volrootlist
, &sbi
->sbi_volroothead
);
180 /* convert a fid to an inode. Mostly we can compute
181 the inode number from the FID, but not for volume
182 mount points: those are in a list */
183 struct inode
*coda_fid_to_inode(ViceFid
*fid
, struct super_block
*sb
)
187 struct coda_inode_info
*cnp
;
192 printk("coda_fid_to_inode: no sb!\n");
197 printk("coda_fid_to_inode: no fid!\n");
200 CDEBUG(D_INODE
, "%s\n", coda_f2s(fid
));
203 if ( coda_fid_is_weird(fid
) ) {
204 struct coda_inode_info
*cii
;
205 struct list_head
*lh
, *le
;
206 struct coda_sb_info
*sbi
= coda_sbp(sb
);
207 le
= lh
= &sbi
->sbi_volroothead
;
209 while ( (le
= le
->next
) != lh
) {
210 cii
= list_entry(le
, struct coda_inode_info
,
212 CDEBUG(D_DOWNCALL
, "iterating, now doing %s, ino %ld\n",
213 coda_f2s(&cii
->c_fid
), cii
->c_vnode
->i_ino
);
214 if ( coda_fideq(&cii
->c_fid
, fid
) ) {
215 inode
= cii
->c_vnode
;
216 CDEBUG(D_INODE
, "volume root, found %ld\n", inode
->i_ino
);
217 if ( cii
->c_magic
!= CODA_CNODE_MAGIC
)
218 printk("%s: Bad magic in inode, tell Peter.\n",
221 iget(sb
, inode
->i_ino
);
229 /* fid is not weird: ino should be computable */
231 inode
= iget(sb
, nr
);
233 printk("coda_fid_to_inode: null from iget, sb %p, nr %ld.\n",
238 /* check if this inode is linked to a cnode */
240 if ( cnp
->c_magic
!= CODA_CNODE_MAGIC
) {
241 CDEBUG(D_INODE
, "uninitialized inode. Return.\n");
246 /* make sure fid is the one we want;
247 unfortunately Venus will shamelessly send us mount-symlinks.
248 These have the same inode as the root of the volume they
249 mount, but the fid will be wrong.
251 if ( !coda_fideq(fid
, &(cnp
->c_fid
)) ) {
252 /* printk("coda_fid2inode: bad cnode (ino %ld, fid %s)"
253 "Tell Peter.\n", nr, coda_f2s(fid)); */
258 CDEBUG(D_INODE
, "found %ld\n", inode
->i_ino
);
262 /* the CONTROL inode is made without asking attributes from Venus */
263 int coda_cnode_makectl(struct inode
**inode
, struct super_block
*sb
)
267 *inode
= iget(sb
, CTL_INO
);
269 (*inode
)->i_op
= &coda_ioctl_inode_operations
;
270 (*inode
)->i_fop
= &coda_ioctl_operations
;
271 (*inode
)->i_mode
= 00444;