2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * VFS operations for Linux
13 * super_block operations should return negated errno to Linux.
15 #include "../afs/param.h"
16 #include "../afs/sysincludes.h"
17 #include "../afs/afsincludes.h"
18 #include "../afs/afs_stats.h"
19 #include "../h/locks.h"
20 #if defined(AFS_LINUX24_ENV)
21 #include "../h/smp_lock.h"
24 #define __NO_VERSION__ /* don't define kernel_verion in module.h */
25 #include <linux/module.h>
28 struct vcache *afs_globalVp = 0;
29 struct vfs *afs_globalVFS = 0;
30 int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */
32 extern struct super_operations afs_sops;
33 extern afs_rwlock_t afs_xvcache;
34 extern struct afs_q VLRU;
36 extern struct dentry_operations afs_dentry_operations;
38 /* Forward declarations */
39 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
40 static void update_inode_cache(struct inode *ip, struct vattr *vp);
41 static int afs_root(struct super_block *afsp);
42 struct super_block *afs_read_super(struct super_block *sb, void *data,
44 void put_inode_on_dummy_list(struct inode *ip);
47 * VFS entry for Linux - installed in init_module
48 * Linux mounts file systems by:
49 * 1) register_filesystem(&afs_file_system) - done in init_module
50 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
51 * We are expected to setup the super_block. See afs_read_super.
53 #if defined(AFS_LINUX24_ENV)
54 DECLARE_FSTYPE(afs_file_system, "afs", afs_read_super, 0);
56 struct file_system_type afs_file_system = {
57 "afs", /* name - used by mount operation. */
58 0, /* requires_dev - no for network filesystems. mount() will
59 * pass us an "unnamed" device. */
60 afs_read_super, /* wrapper to afs_mount */
61 NULL /* pointer to next file_system_type once registered. */
66 * read the "super block" for AFS - roughly eguivalent to struct vfs.
67 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
69 struct super_block *afs_read_super(struct super_block *sb, void *data,
75 if (afs_was_mounted) {
76 printf("You must reload the AFS kernel extensions before remounting AFS.\n");
81 /* Set basics of super_block */
82 #if !defined(AFS_LINUX24_ENV)
88 sb->s_blocksize = 1024;
89 sb->s_blocksize_bits = 10;
90 sb->s_magic = AFS_VFSMAGIC;
91 sb->s_op = &afs_sops; /* Super block (vfs) ops */
96 #if !defined(AFS_LINUX24_ENV)
101 return code ? NULL : sb;
105 /* afs_root - stat the root of the file system. AFS global held on entry. */
106 static int afs_root(struct super_block *afsp)
108 register afs_int32 code = 0;
109 struct vrequest treq;
110 register struct vcache *tvp=0;
112 AFS_STATCNT(afs_root);
113 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
116 cred_t *credp = crref();
118 if (!(code = afs_InitReq(&treq, credp)) &&
119 !(code = afs_CheckInit())) {
120 tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0,
121 (struct vcache*)0, WRITE_LOCK);
123 extern struct inode_operations afs_dir_iops;
124 #if defined(AFS_LINUX24_ENV)
125 extern struct file_operations afs_dir_fops;
128 /* "/afs" is a directory, reset inode ops accordingly. */
129 tvp->v.v_op = &afs_dir_iops;
130 #if defined(AFS_LINUX24_ENV)
131 tvp->v.v_fop = &afs_dir_fops;
134 /* setup super_block and mount point inode. */
136 #if defined(AFS_LINUX24_ENV)
137 afsp->s_root = d_alloc_root((struct inode*)tvp);
139 afsp->s_root = d_alloc_root((struct inode*)tvp, NULL);
141 afsp->s_root->d_op = &afs_dentry_operations;
148 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
149 ICL_TYPE_INT32, code);
153 /* super_operations */
156 * called via iget to read in the inode. The passed in inode has i_ino, i_dev
157 * and i_sb setup on input. Linux file systems use this to get super block
158 * inode information, so we don't really care what happens here.
159 * For Linux 2.2, we'll be called if we participate in the inode pool.
161 void afs_read_inode(struct inode *ip)
163 /* I don't think we ever get called with this. So print if we do. */
164 printf("afs_read_inode: Called for inode %d\n", ip->i_ino);
169 * Linux version of setattr call. What to change is in the iattr struct.
170 * We need to set bits in both the Linux inode as well as the vcache.
172 int afs_notify_change(struct dentry *dp, struct iattr* iattrp)
176 cred_t *credp = crref();
177 struct inode *ip = dp->d_inode;
181 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
182 update_inode_cache(ip, &vattr);
183 code = afs_setattr((struct vcache*)ip, &vattr, credp);
184 afs_CopyOutAttrs((struct vcache*)ip, &vattr);
185 /* Note that the inode may still not have all the correct info. But at
186 * least we've got the newest version of what was supposed to be set.
195 /* This list is simply used to initialize the i_list member of the
196 * linux inode. This stops linux inode syncing code from choking on our
199 static LIST_HEAD(dummy_inode_list);
202 /* This is included for documentation only. */
204 * Used to flush in core inode to disk. We don't need to do this. Top level
205 * write_inode() routine will clear i_dirt. If this routine is in the table,
206 * it's expected to do the cleaning and clear i_dirt.
208 * 9/24/99: This is what we thought until we discovered msync() does end up calling
209 * this function to sync a single inode to disk. msync() only flushes selective
210 * pages to disk. So it needs an inode syncing function to update metadata when it
211 * has synced some pages of a file to disk.
213 void afs_write_inode(struct inode *ip)
215 /* and put it back on our dummy list. */
216 list_del(&ip->i_list);
217 list_add(&ip->i_list, &dummy_inode_list);
219 /* for now we don't actually update the metadata during msync. This
220 * is just to keep linux happy. */
225 * called from iput when count goes to zero. Linux version of inactive.
226 * For Linux 2.2, this funcionality has moved to the delete inode super op.
227 * If we use the common inode pool, we'll need to set i_nlink to 0 here.
228 * That will trigger the call to delete routine.
230 void afs_delete_inode(struct inode *ip)
232 cred_t *credp = crref();
233 struct vcache *vc = (struct vcache*)ip;
236 #if defined(AFS_LINUX24_ENV)
238 if (atomic_read(&ip->i_count) > 1)
242 printf("afs_put_inode: ino %d (0x%x) has count %d\n", ip->i_ino, ip);
244 ObtainWriteLock(&vc->lock, 504);
245 afs_InactiveVCache(vc, credp);
246 #if defined(AFS_LINUX24_ENV)
247 atomic_set(&ip->i_count, 0);
251 ip->i_nlink = 0; /* iput checks this after calling this routine. */
252 ReleaseWriteLock(&vc->lock);
254 #ifdef AFS_LINUX24_ENV
262 * Called from unmount to release super_block. */
263 void afs_put_super(struct super_block *sbp)
265 extern int afs_afs_cold_shutdown;
270 AFS_STATCNT(afs_unmount);
279 osi_linux_verify_alloced_memory();
291 * Not required since we don't write out a super block. */
292 void afs_write_super(struct super_block *sbp)
297 * Used to remount filesystems with different flags. Not relevant for AFS.
299 int afs_remount_fs(struct super_block *sbp, int *, char *)
306 * statp is in user space, so we need to cobble together a statfs, then
309 #if defined(AFS_LINUX24_ENV)
310 int afs_statfs(struct super_block *sbp, struct statfs *statp)
312 int afs_statfs(struct super_block *sbp, struct statfs *statp, int size)
317 AFS_STATCNT(afs_statfs);
319 #if !defined(AFS_LINUX24_ENV)
320 if (size < sizeof(struct statfs))
323 memset(&stat, 0, size);
325 stat.f_type = 0; /* Can we get a real type sometime? */
326 stat.f_bsize = sbp->s_blocksize;
327 stat.f_blocks = stat.f_bfree = stat.f_bavail = stat.f_files =
328 stat.f_ffree = 9000000;
329 stat.f_fsid.val[0] = AFS_VFSMAGIC;
330 stat.f_fsid.val[1] = AFS_VFSFSID;
331 stat.f_namelen = 256;
333 #if defined(AFS_LINUX24_ENV)
336 memcpy_tofs(statp, &stat, size);
342 #if defined(AFS_LINUX24_ENV)
343 struct super_operations afs_sops = {
344 read_inode: afs_read_inode,
345 write_inode: afs_write_inode,
346 delete_inode: afs_delete_inode,
347 put_super: afs_put_super,
351 struct super_operations afs_sops = {
353 afs_write_inode, /* afs_write_inode - see doc above. */
354 NULL, /* afs_put_inode */
358 NULL, /* afs_write_super - see doc above */
360 NULL, /* afs_remount_fs - see doc above */
361 NULL, /* afs_clear_inode */
362 NULL, /* afs_umount_begin */
366 /************** Support routines ************************/
369 * Set iattr data into vattr. Assume vattr cleared before call.
371 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
373 vattrp->va_mask = iattrp->ia_valid;
374 if (iattrp->ia_valid & ATTR_MODE)
375 vattrp->va_mode = iattrp->ia_mode;
376 if (iattrp->ia_valid & ATTR_UID)
377 vattrp->va_uid = iattrp->ia_uid;
378 if (iattrp->ia_valid & ATTR_GID)
379 vattrp->va_gid = iattrp->ia_gid;
380 if (iattrp->ia_valid & ATTR_SIZE)
381 vattrp->va_size = iattrp->ia_size;
382 if (iattrp->ia_valid & ATTR_ATIME) {
383 vattrp->va_atime.tv_sec = iattrp->ia_atime;
384 vattrp->va_atime.tv_usec = 0;
386 if (iattrp->ia_valid & ATTR_MTIME) {
387 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
388 vattrp->va_mtime.tv_usec = 0;
390 if (iattrp->ia_valid & ATTR_CTIME) {
391 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
392 vattrp->va_ctime.tv_usec = 0;
396 /* update_inode_cache
397 * Update inode with info from vattr struct. Use va_mask to determine what
400 static void update_inode_cache(struct inode *ip, struct vattr *vp)
402 if (vp->va_mask & ATTR_MODE)
403 ip->i_mode = vp->va_mode;
404 if (vp->va_mask & ATTR_UID)
405 ip->i_uid = vp->va_uid;
406 if (vp->va_mask & ATTR_GID)
407 ip->i_gid = vp->va_gid;
408 if (vp->va_mask & ATTR_SIZE)
409 ip->i_size = vp->va_size;
410 if (vp->va_mask & ATTR_ATIME)
411 ip->i_atime = vp->va_atime.tv_sec;
412 if (vp->va_mask & ATTR_MTIME)
413 ip->i_mtime = vp->va_mtime.tv_sec;
414 if (vp->va_mask & ATTR_CTIME)
415 ip->i_ctime = vp->va_ctime.tv_sec;
419 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
421 void vattr2inode(struct inode *ip, struct vattr *vp)
423 ip->i_ino = vp->va_nodeid;
424 ip->i_nlink = vp->va_nlink;
425 ip->i_blocks = vp->va_blocks;
426 ip->i_blksize = vp->va_blocksize;
427 ip->i_rdev = vp->va_rdev;
428 ip->i_mode = vp->va_mode;
429 ip->i_uid = vp->va_uid;
430 ip->i_gid = vp->va_gid;
431 ip->i_size = vp->va_size;
432 ip->i_atime = vp->va_atime.tv_sec;
433 ip->i_mtime = vp->va_mtime.tv_sec;
434 ip->i_ctime = vp->va_ctime.tv_sec;
436 /* we should put our inodes on a dummy inode list to keep linux happy.*/
437 if (!ip->i_list.prev && !ip->i_list.next) {
438 /* this might be bad as we are reaching under the covers of the
439 * list structure but we want to avoid putting the inode
440 * on the list more than once. */
441 put_inode_on_dummy_list(ip);
445 /* Put this afs inode on our own dummy list. Linux expects to see inodes
446 * nicely strung up in lists. Linux inode syncing code chokes on our inodes if
447 * they're not on any lists.
449 void put_inode_on_dummy_list(struct inode *ip)
451 /* Initialize list. See explanation above. */
452 list_add(&ip->i_list, &dummy_inode_list);
455 /* And yet another routine to update the inode cache - called from ProcessFS */
456 void vcache2inode(struct vcache *avc)
461 afs_CopyOutAttrs(avc, &vattr); /* calls vattr2inode */