1 /* Copyright Transarc Corporation 1998 - All Rights Reserved.
4 * VFS operations for Linux
6 * super_block operations should return negated errno to Linux.
8 #include "../afs/param.h"
9 #include "../afs/sysincludes.h"
10 #include "../afs/afsincludes.h"
11 #include "../afs/afs_stats.h"
12 #include "../h/locks.h"
14 #define __NO_VERSION__ /* don't define kernel_verion in module.h */
15 #include <linux/module.h>
18 struct vcache *afs_globalVp = 0;
19 struct vfs *afs_globalVFS = 0;
20 int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */
22 extern struct super_operations afs_sops;
23 extern afs_rwlock_t afs_xvcache;
24 extern struct afs_q VLRU;
26 extern struct dentry_operations afs_dentry_operations;
28 /* Forward declarations */
29 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
30 static void update_inode_cache(struct inode *ip, struct vattr *vp);
31 static int afs_root(struct super_block *afsp);
32 struct super_block *afs_read_super(struct super_block *sb, void *data,
34 void put_inode_on_dummy_list(struct inode *ip);
37 * VFS entry for Linux - installed in init_module
38 * Linux mounts file systems by:
39 * 1) register_filesystem(&afs_file_system) - done in init_module
40 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
41 * We are expected to setup the super_block. See afs_read_super.
43 struct file_system_type afs_file_system = {
44 "afs", /* name - used by mount operation. */
45 0, /* requires_dev - no for network filesystems. mount() will
46 * pass us an "unnamed" device. */
47 afs_read_super, /* wrapper to afs_mount */
48 NULL /* pointer to next file_system_type once registered. */
52 * read the "super block" for AFS - roughly eguivalent to struct vfs.
53 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
55 struct super_block *afs_read_super(struct super_block *sb, void *data,
61 if (afs_was_mounted) {
62 printf("You must reload the AFS kernel extensions before remounting AFS.\n");
67 /* Set basics of super_block */
72 sb->s_blocksize = 1024;
73 sb->s_blocksize_bits = 10;
74 sb->s_magic = AFS_VFSMAGIC;
75 sb->s_op = &afs_sops; /* Super block (vfs) ops */
83 return code ? NULL : sb;
87 /* afs_root - stat the root of the file system. AFS global held on entry. */
88 static int afs_root(struct super_block *afsp)
90 register afs_int32 code = 0;
92 register struct vcache *tvp=0;
94 AFS_STATCNT(afs_root);
95 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
98 cred_t *credp = crref();
100 if (!(code = afs_InitReq(&treq, credp)) &&
101 !(code = afs_CheckInit())) {
102 tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0,
103 (struct vcache*)0, WRITE_LOCK);
105 extern struct inode_operations afs_dir_iops;
107 /* "/afs" is a directory, reset inode ops accordingly. */
108 tvp->v.v_op = &afs_dir_iops;
110 /* setup super_block and mount point inode. */
112 afsp->s_root = d_alloc_root((struct inode*)tvp, NULL);
113 afsp->s_root->d_op = &afs_dentry_operations;
120 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
121 ICL_TYPE_INT32, code);
125 /* super_operations */
128 * called via iget to read in the inode. The passed in inode has i_ino, i_dev
129 * and i_sb setup on input. Linux file systems use this to get super block
130 * inode information, so we don't really care what happens here.
131 * For Linux 2.2, we'll be called if we participate in the inode pool.
133 void afs_read_inode(struct inode *ip)
135 /* I don't think we ever get called with this. So print if we do. */
136 printf("afs_read_inode: Called for inode %d\n", ip->i_ino);
141 * Linux version of setattr call. What to change is in the iattr struct.
142 * We need to set bits in both the Linux inode as well as the vcache.
144 int afs_notify_change(struct dentry *dp, struct iattr* iattrp)
148 cred_t *credp = crref();
149 struct inode *ip = dp->d_inode;
153 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
154 update_inode_cache(ip, &vattr);
155 code = afs_setattr((struct vcache*)ip, &vattr, credp);
156 afs_CopyOutAttrs((struct vcache*)ip, &vattr);
157 /* Note that the inode may still not have all the correct info. But at
158 * least we've got the newest version of what was supposed to be set.
167 /* This list is simply used to initialize the i_list member of the
168 * linux inode. This stops linux inode syncing code from choking on our
171 static LIST_HEAD(dummy_inode_list);
174 /* This is included for documentation only. */
176 * Used to flush in core inode to disk. We don't need to do this. Top level
177 * write_inode() routine will clear i_dirt. If this routine is in the table,
178 * it's expected to do the cleaning and clear i_dirt.
180 * 9/24/99: This is what we thought until we discovered msync() does end up calling
181 * this function to sync a single inode to disk. msync() only flushes selective
182 * pages to disk. So it needs an inode syncing function to update metadata when it
183 * has synced some pages of a file to disk.
185 void afs_write_inode(struct inode *ip)
187 /* and put it back on our dummy list. */
188 list_del(&ip->i_list);
189 list_add(&ip->i_list, &dummy_inode_list);
191 /* for now we don't actually update the metadata during msync. This
192 * is just to keep linux happy. */
197 * called from iput when count goes to zero. Linux version of inactive.
198 * For Linux 2.2, this funcionality has moved to the delete inode super op.
199 * If we use the common inode pool, we'll need to set i_nlink to 0 here.
200 * That will trigger the call to delete routine.
202 void afs_delete_inode(struct inode *ip)
204 cred_t *credp = crref();
205 struct vcache *vc = (struct vcache*)ip;
209 printf("afs_put_inode: ino %d (0x%x) has count %d\n", ip->i_ino, ip);
211 ObtainWriteLock(&vc->lock, 504);
212 afs_InactiveVCache(vc, credp);
214 ip->i_nlink = 0; /* iput checks this after calling this routine. */
215 ReleaseWriteLock(&vc->lock);
222 * Called from unmount to release super_block. */
223 void afs_put_super(struct super_block *sbp)
225 extern int afs_afs_cold_shutdown;
230 AFS_STATCNT(afs_unmount);
239 osi_linux_verify_alloced_memory();
251 * Not required since we don't write out a super block. */
252 void afs_write_super(struct super_block *sbp)
257 * Used to remount filesystems with different flags. Not relevant for AFS.
259 int afs_remount_fs(struct super_block *sbp, int *, char *)
266 * statp is in user space, so we need to cobble together a statfs, then
269 int afs_statfs(struct super_block *sbp, struct statfs *statp, int size)
273 AFS_STATCNT(afs_statfs);
275 if (size < sizeof(struct statfs))
278 memset(&stat, 0, size);
279 stat.f_type = 0; /* Can we get a real type sometime? */
280 stat.f_bsize = sbp->s_blocksize;
281 stat.f_blocks = stat.f_bfree = stat.f_bavail = stat.f_files =
282 stat.f_ffree = 9000000;
283 stat.f_fsid.val[0] = AFS_VFSMAGIC;
284 stat.f_fsid.val[1] = AFS_VFSFSID;
285 stat.f_namelen = 256;
287 memcpy_tofs(statp, &stat, size);
292 struct super_operations afs_sops = {
294 afs_write_inode, /* afs_write_inode - see doc above. */
295 NULL, /* afs_put_inode */
299 NULL, /* afs_write_super - see doc above */
301 NULL, /* afs_remount_fs - see doc above */
302 NULL, /* afs_clear_inode */
303 NULL, /* afs_umount_begin */
306 /************** Support routines ************************/
309 * Set iattr data into vattr. Assume vattr cleared before call.
311 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
313 vattrp->va_mask = iattrp->ia_valid;
314 if (iattrp->ia_valid & ATTR_MODE)
315 vattrp->va_mode = iattrp->ia_mode;
316 if (iattrp->ia_valid & ATTR_UID)
317 vattrp->va_uid = iattrp->ia_uid;
318 if (iattrp->ia_valid & ATTR_GID)
319 vattrp->va_gid = iattrp->ia_gid;
320 if (iattrp->ia_valid & ATTR_SIZE)
321 vattrp->va_size = iattrp->ia_size;
322 if (iattrp->ia_valid & ATTR_ATIME) {
323 vattrp->va_atime.tv_sec = iattrp->ia_atime;
324 vattrp->va_atime.tv_usec = 0;
326 if (iattrp->ia_valid & ATTR_MTIME) {
327 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
328 vattrp->va_mtime.tv_usec = 0;
330 if (iattrp->ia_valid & ATTR_CTIME) {
331 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
332 vattrp->va_ctime.tv_usec = 0;
336 /* update_inode_cache
337 * Update inode with info from vattr struct. Use va_mask to determine what
340 static void update_inode_cache(struct inode *ip, struct vattr *vp)
342 if (vp->va_mask & ATTR_MODE)
343 ip->i_mode = vp->va_mode;
344 if (vp->va_mask & ATTR_UID)
345 ip->i_uid = vp->va_uid;
346 if (vp->va_mask & ATTR_GID)
347 ip->i_gid = vp->va_gid;
348 if (vp->va_mask & ATTR_SIZE)
349 ip->i_size = vp->va_size;
350 if (vp->va_mask & ATTR_ATIME)
351 ip->i_atime = vp->va_atime.tv_sec;
352 if (vp->va_mask & ATTR_MTIME)
353 ip->i_mtime = vp->va_mtime.tv_sec;
354 if (vp->va_mask & ATTR_CTIME)
355 ip->i_ctime = vp->va_ctime.tv_sec;
359 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
361 void vattr2inode(struct inode *ip, struct vattr *vp)
363 ip->i_ino = vp->va_nodeid;
364 ip->i_nlink = vp->va_nlink;
365 ip->i_blocks = vp->va_blocks;
366 ip->i_blksize = vp->va_blocksize;
367 ip->i_rdev = vp->va_rdev;
368 ip->i_mode = vp->va_mode;
369 ip->i_uid = vp->va_uid;
370 ip->i_gid = vp->va_gid;
371 ip->i_size = vp->va_size;
372 ip->i_atime = vp->va_atime.tv_sec;
373 ip->i_mtime = vp->va_mtime.tv_sec;
374 ip->i_ctime = vp->va_ctime.tv_sec;
376 /* we should put our inodes on a dummy inode list to keep linux happy.*/
377 if (!ip->i_list.prev && !ip->i_list.next) {
378 /* this might be bad as we are reaching under the covers of the
379 * list structure but we want to avoid putting the inode
380 * on the list more than once. */
381 put_inode_on_dummy_list(ip);
385 /* Put this afs inode on our own dummy list. Linux expects to see inodes
386 * nicely strung up in lists. Linux inode syncing code chokes on our inodes if
387 * they're not on any lists.
389 void put_inode_on_dummy_list(struct inode *ip)
391 /* Initialize list. See explanation above. */
392 list_add(&ip->i_list, &dummy_inode_list);
395 /* And yet another routine to update the inode cache - called from ProcessFS */
396 void vcache2inode(struct vcache *avc)
401 afs_CopyOutAttrs(avc, &vattr); /* calls vattr2inode */