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 <afsconfig.h>
16 #include "afs/param.h"
20 #include "afs/sysincludes.h"
21 #include "afsincludes.h"
22 #include "afs/afs_stats.h"
24 #if defined(AFS_LINUX24_ENV)
25 #include "h/smp_lock.h"
28 #define __NO_VERSION__ /* don't define kernel_verion in module.h */
29 #include <linux/module.h>
32 struct vcache *afs_globalVp = 0;
33 struct vfs *afs_globalVFS = 0;
34 int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */
36 extern struct super_operations afs_sops;
37 extern afs_rwlock_t afs_xvcache;
38 extern struct afs_q VLRU;
40 extern struct dentry_operations afs_dentry_operations;
42 /* Forward declarations */
43 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
44 static void update_inode_cache(struct inode *ip, struct vattr *vp);
45 static int afs_root(struct super_block *afsp);
46 struct super_block *afs_read_super(struct super_block *sb, void *data,
48 void put_inode_on_dummy_list(struct inode *ip);
51 * VFS entry for Linux - installed in init_module
52 * Linux mounts file systems by:
53 * 1) register_filesystem(&afs_file_system) - done in init_module
54 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
55 * We are expected to setup the super_block. See afs_read_super.
57 #if defined(AFS_LINUX24_ENV)
58 DECLARE_FSTYPE(afs_file_system, "afs", afs_read_super, 0);
60 struct file_system_type afs_file_system = {
61 "afs", /* name - used by mount operation. */
62 0, /* requires_dev - no for network filesystems. mount() will
63 * pass us an "unnamed" device. */
64 afs_read_super, /* wrapper to afs_mount */
65 NULL /* pointer to next file_system_type once registered. */
70 * read the "super block" for AFS - roughly eguivalent to struct vfs.
71 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
73 struct super_block *afs_read_super(struct super_block *sb, void *data,
79 if (afs_was_mounted) {
80 printf("You must reload the AFS kernel extensions before remounting AFS.\n");
86 /* Set basics of super_block */
87 #if !defined(AFS_LINUX24_ENV)
93 sb->s_blocksize = 1024;
94 sb->s_blocksize_bits = 10;
95 sb->s_magic = AFS_VFSMAGIC;
96 sb->s_op = &afs_sops; /* Super block (vfs) ops */
97 #if defined(MAX_NON_LFS)
98 sb->s_maxbytes = MAX_NON_LFS;
104 #if !defined(AFS_LINUX24_ENV)
109 return code ? NULL : sb;
113 /* afs_root - stat the root of the file system. AFS global held on entry. */
114 static int afs_root(struct super_block *afsp)
116 register afs_int32 code = 0;
117 struct vrequest treq;
118 register struct vcache *tvp=0;
120 AFS_STATCNT(afs_root);
121 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
124 cred_t *credp = crref();
127 afs_PutVCache(afs_globalVp);
131 if (!(code = afs_InitReq(&treq, credp)) &&
132 !(code = afs_CheckInit())) {
133 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
135 extern struct inode_operations afs_dir_iops;
136 #if defined(AFS_LINUX24_ENV)
137 extern struct file_operations afs_dir_fops;
140 /* "/afs" is a directory, reset inode ops accordingly. */
141 AFSTOV(tvp)->v_op = &afs_dir_iops;
142 #if defined(AFS_LINUX24_ENV)
143 AFSTOV(tvp)->v_fop = &afs_dir_fops;
146 /* setup super_block and mount point inode. */
148 #if defined(AFS_LINUX24_ENV)
149 afsp->s_root = d_alloc_root(AFSTOI(tvp));
151 afsp->s_root = d_alloc_root(AFSTOI(tvp), NULL);
153 afsp->s_root->d_op = &afs_dentry_operations;
160 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
161 ICL_TYPE_INT32, code);
165 /* super_operations */
168 * called via iget to read in the inode. The passed in inode has i_ino, i_dev
169 * and i_sb setup on input. Linux file systems use this to get super block
170 * inode information, so we don't really care what happens here.
171 * For Linux 2.2, we'll be called if we participate in the inode pool.
173 void afs_read_inode(struct inode *ip)
175 /* I don't think we ever get called with this. So print if we do. */
176 printf("afs_read_inode: Called for inode %d\n", ip->i_ino);
181 * Linux version of setattr call. What to change is in the iattr struct.
182 * We need to set bits in both the Linux inode as well as the vcache.
184 int afs_notify_change(struct dentry *dp, struct iattr* iattrp)
188 cred_t *credp = crref();
189 struct inode *ip = dp->d_inode;
193 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
194 update_inode_cache(ip, &vattr);
195 code = afs_setattr(ITOAFS(ip), &vattr, credp);
196 afs_CopyOutAttrs(ITOAFS(ip), &vattr);
197 /* Note that the inode may still not have all the correct info. But at
198 * least we've got the newest version of what was supposed to be set.
207 /* This list is simply used to initialize the i_list member of the
208 * linux inode. This stops linux inode syncing code from choking on our
211 static LIST_HEAD(dummy_inode_list);
214 /* This is included for documentation only. */
216 * Used to flush in core inode to disk. We don't need to do this. Top level
217 * write_inode() routine will clear i_dirt. If this routine is in the table,
218 * it's expected to do the cleaning and clear i_dirt.
220 * 9/24/99: This is what we thought until we discovered msync() does end up calling
221 * this function to sync a single inode to disk. msync() only flushes selective
222 * pages to disk. So it needs an inode syncing function to update metadata when it
223 * has synced some pages of a file to disk.
225 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
226 void afs_write_inode(struct inode *ip, int unused)
228 void afs_write_inode(struct inode *ip)
231 /* and put it back on our dummy list. */
232 list_del(&ip->i_list);
233 list_add(&ip->i_list, &dummy_inode_list);
235 /* for now we don't actually update the metadata during msync. This
236 * is just to keep linux happy. */
241 * called from iput when count goes to zero. Linux version of inactive.
242 * For Linux 2.2, this funcionality has moved to the delete inode super op.
243 * If we use the common inode pool, we'll need to set i_nlink to 0 here.
244 * That will trigger the call to delete routine.
247 void afs_delete_inode(struct inode *ip)
249 struct vcache *vc = ITOAFS(ip);
258 * Called from unmount to release super_block. */
259 void afs_put_super(struct super_block *sbp)
261 extern int afs_afs_cold_shutdown;
266 AFS_STATCNT(afs_unmount);
277 osi_linux_verify_alloced_memory();
289 * Not required since we don't write out a super block. */
290 void afs_write_super(struct super_block *sbp)
295 * Used to remount filesystems with different flags. Not relevant for AFS.
297 int afs_remount_fs(struct super_block *sbp, int *, char *)
304 * statp is in user space, so we need to cobble together a statfs, then
307 #if defined(AFS_LINUX24_ENV)
308 int afs_statfs(struct super_block *sbp, struct statfs *statp)
310 int afs_statfs(struct super_block *sbp, struct statfs *statp, int size)
315 AFS_STATCNT(afs_statfs);
317 #if !defined(AFS_LINUX24_ENV)
318 if (size < sizeof(struct statfs))
321 memset(&stat, 0, size);
323 stat.f_type = 0; /* Can we get a real type sometime? */
324 stat.f_bsize = sbp->s_blocksize;
325 stat.f_blocks = stat.f_bfree = stat.f_bavail = stat.f_files =
326 stat.f_ffree = 9000000;
327 stat.f_fsid.val[0] = AFS_VFSMAGIC;
328 stat.f_fsid.val[1] = AFS_VFSFSID;
329 stat.f_namelen = 256;
331 #if defined(AFS_LINUX24_ENV)
334 memcpy_tofs(statp, &stat, size);
341 afs_umount_begin(struct super_block *sbp)
348 #if defined(AFS_LINUX24_ENV)
349 struct super_operations afs_sops = {
350 read_inode: afs_read_inode,
351 write_inode: afs_write_inode,
352 delete_inode: afs_delete_inode,
353 put_super: afs_put_super,
355 umount_begin: NULL /* afs_umount_begin */
358 struct super_operations afs_sops = {
360 afs_write_inode, /* afs_write_inode - see doc above. */
361 NULL, /* afs_put_inode */
365 NULL, /* afs_write_super - see doc above */
367 NULL, /* afs_remount_fs - see doc above */
368 NULL, /* afs_clear_inode */
369 NULL /* afs_umount_begin */
373 /************** Support routines ************************/
376 * Set iattr data into vattr. Assume vattr cleared before call.
378 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
380 vattrp->va_mask = iattrp->ia_valid;
381 if (iattrp->ia_valid & ATTR_MODE)
382 vattrp->va_mode = iattrp->ia_mode;
383 if (iattrp->ia_valid & ATTR_UID)
384 vattrp->va_uid = iattrp->ia_uid;
385 if (iattrp->ia_valid & ATTR_GID)
386 vattrp->va_gid = iattrp->ia_gid;
387 if (iattrp->ia_valid & ATTR_SIZE)
388 vattrp->va_size = iattrp->ia_size;
389 if (iattrp->ia_valid & ATTR_ATIME) {
390 vattrp->va_atime.tv_sec = iattrp->ia_atime;
391 vattrp->va_atime.tv_usec = 0;
393 if (iattrp->ia_valid & ATTR_MTIME) {
394 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
395 vattrp->va_mtime.tv_usec = 0;
397 if (iattrp->ia_valid & ATTR_CTIME) {
398 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
399 vattrp->va_ctime.tv_usec = 0;
403 /* update_inode_cache
404 * Update inode with info from vattr struct. Use va_mask to determine what
407 static void update_inode_cache(struct inode *ip, struct vattr *vp)
409 if (vp->va_mask & ATTR_MODE)
410 ip->i_mode = vp->va_mode;
411 if (vp->va_mask & ATTR_UID)
412 ip->i_uid = vp->va_uid;
413 if (vp->va_mask & ATTR_GID)
414 ip->i_gid = vp->va_gid;
415 if (vp->va_mask & ATTR_SIZE)
416 ip->i_size = vp->va_size;
417 if (vp->va_mask & ATTR_ATIME)
418 ip->i_atime = vp->va_atime.tv_sec;
419 if (vp->va_mask & ATTR_MTIME)
420 ip->i_mtime = vp->va_mtime.tv_sec;
421 if (vp->va_mask & ATTR_CTIME)
422 ip->i_ctime = vp->va_ctime.tv_sec;
426 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
428 void vattr2inode(struct inode *ip, struct vattr *vp)
430 ip->i_ino = vp->va_nodeid;
431 ip->i_nlink = vp->va_nlink;
432 ip->i_blocks = vp->va_blocks;
433 ip->i_blksize = vp->va_blocksize;
434 ip->i_rdev = vp->va_rdev;
435 ip->i_mode = vp->va_mode;
436 ip->i_uid = vp->va_uid;
437 ip->i_gid = vp->va_gid;
438 ip->i_size = vp->va_size;
439 ip->i_atime = vp->va_atime.tv_sec;
440 ip->i_mtime = vp->va_mtime.tv_sec;
441 ip->i_ctime = vp->va_ctime.tv_sec;
443 /* we should put our inodes on a dummy inode list to keep linux happy.*/
444 if (!ip->i_list.prev && !ip->i_list.next) {
445 /* this might be bad as we are reaching under the covers of the
446 * list structure but we want to avoid putting the inode
447 * on the list more than once. */
448 put_inode_on_dummy_list(ip);
452 /* Put this afs inode on our own dummy list. Linux expects to see inodes
453 * nicely strung up in lists. Linux inode syncing code chokes on our inodes if
454 * they're not on any lists.
456 void put_inode_on_dummy_list(struct inode *ip)
458 /* Initialize list. See explanation above. */
459 list_add(&ip->i_list, &dummy_inode_list);
462 /* And yet another routine to update the inode cache - called from ProcessFS */
463 void vcache2inode(struct vcache *avc)
468 afs_CopyOutAttrs(avc, &vattr); /* calls vattr2inode */
471 /* Yet another one for fakestat'ed mountpoints */
472 void vcache2fakeinode(struct vcache *rootvp, struct vcache *mpvp)
477 afs_CopyOutAttrs(rootvp, &vattr);
478 vattr2inode(AFSTOV(mpvp), &vattr);