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"
21 #define __NO_VERSION__ /* don't define kernel_version in module.h */
22 #include <linux/module.h> /* early to avoid printf->printk mapping */
23 #include "afs/sysincludes.h"
24 #include "afsincludes.h"
25 #include "afs/afs_stats.h"
26 #if !defined(AFS_LINUX26_ENV)
29 #if defined(AFS_LINUX24_ENV)
30 #include "h/smp_lock.h"
34 struct vcache *afs_globalVp = 0;
35 struct vfs *afs_globalVFS = 0;
36 #if defined(AFS_LINUX24_ENV)
37 struct vfsmount *afs_cacheMnt;
39 int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */
41 extern struct super_operations afs_sops;
42 #if defined(AFS_LINUX26_ENV)
43 extern struct export_operations afs_export_ops;
45 extern afs_rwlock_t afs_xvcache;
46 extern struct afs_q VLRU;
48 extern struct dentry_operations afs_dentry_operations;
50 /* Forward declarations */
51 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
52 static int afs_root(struct super_block *afsp);
53 struct super_block *afs_read_super(struct super_block *sb, void *data, int silent);
54 int afs_fill_super(struct super_block *sb, void *data, int silent);
55 static struct super_block *afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data);
58 * VFS entry for Linux - installed in init_module
59 * Linux mounts file systems by:
60 * 1) register_filesystem(&afs_file_system) - done in init_module
61 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
62 * We are expected to setup the super_block. See afs_read_super.
64 #if defined(AFS_LINUX26_ENV)
65 struct backing_dev_info afs_backing_dev_info = {
66 .ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE,
70 struct file_system_type afs_fs_type = {
74 .kill_sb = kill_anon_super,
75 .fs_flags = FS_BINARY_MOUNTDATA,
77 #elif defined(AFS_LINUX24_ENV)
78 DECLARE_FSTYPE(afs_fs_type, "afs", afs_read_super, 0);
80 struct file_system_type afs_fs_type = {
81 "afs", /* name - used by mount operation. */
82 0, /* requires_dev - no for network filesystems. mount() will
83 * pass us an "unnamed" device. */
84 afs_read_super, /* wrapper to afs_mount */
85 NULL /* pointer to next file_system_type once registered. */
90 * read the "super block" for AFS - roughly eguivalent to struct vfs.
91 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
93 #if defined(AFS_LINUX26_ENV)
94 static struct super_block *
95 afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
97 return get_sb_nodev(fs_type, flags, data, afs_fill_super);
101 afs_fill_super(struct super_block *sb, void *data, int silent)
104 afs_read_super(struct super_block *sb, void *data, int silent)
110 if (afs_was_mounted) {
112 ("You must reload the AFS kernel extensions before remounting AFS.\n");
114 #if defined(AFS_LINUX26_ENV)
122 /* Set basics of super_block */
123 #if !defined(AFS_LINUX24_ENV)
126 #if defined(AFS_LINUX26_ENV)
127 __module_get(THIS_MODULE);
133 sb->s_blocksize = 1024;
134 sb->s_blocksize_bits = 10;
135 sb->s_magic = AFS_VFSMAGIC;
136 sb->s_op = &afs_sops; /* Super block (vfs) ops */
137 #if defined(AFS_LINUX26_ENV)
138 sb->s_export_op = &afs_export_ops;
140 #if defined(MAX_NON_LFS)
141 #ifdef AFS_64BIT_CLIENT
142 #if !defined(MAX_LFS_FILESIZE)
143 #if BITS_PER_LONG==32
144 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
145 #elif BITS_PER_LONG==64
146 #define MAX_LFS_FILESIZE 0x7fffffffffffffff
149 sb->s_maxbytes = MAX_LFS_FILESIZE;
151 sb->s_maxbytes = MAX_NON_LFS;
156 afs_globalVFS = NULL;
157 #if defined(AFS_LINUX26_ENV)
158 module_put(THIS_MODULE);
164 #if !defined(AFS_LINUX24_ENV)
169 #if defined(AFS_LINUX26_ENV)
170 return code ? -EINVAL : 0;
172 return code ? NULL : sb;
177 /* afs_root - stat the root of the file system. AFS global held on entry. */
179 afs_root(struct super_block *afsp)
181 register afs_int32 code = 0;
182 struct vrequest treq;
183 register struct vcache *tvp = 0;
185 AFS_STATCNT(afs_root);
186 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
189 cred_t *credp = crref();
192 afs_PutVCache(afs_globalVp);
196 if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
197 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
199 struct inode *ip = AFSTOV(tvp);
202 afs_getattr(tvp, &vattr, credp);
203 afs_fill_inode(ip, &vattr);
205 /* setup super_block and mount point inode. */
207 #if defined(AFS_LINUX24_ENV)
208 afsp->s_root = d_alloc_root(ip);
210 afsp->s_root = d_alloc_root(ip, NULL);
212 afsp->s_root->d_op = &afs_dentry_operations;
219 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
220 ICL_TYPE_INT32, code);
224 /* super_operations */
227 * Linux version of setattr call. What to change is in the iattr struct.
228 * We need to set bits in both the Linux inode as well as the vcache.
231 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
234 cred_t *credp = crref();
235 struct inode *ip = dp->d_inode;
239 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
241 #if defined(AFS_LINUX26_ENV)
245 code = afs_setattr(VTOAFS(ip), &vattr, credp);
247 afs_getattr(VTOAFS(ip), &vattr, credp);
248 vattr2inode(ip, &vattr);
251 #if defined(AFS_LINUX26_ENV)
259 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
260 static kmem_cache_t *afs_inode_cachep;
262 static struct inode *
263 afs_alloc_inode(struct super_block *sb)
267 vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, SLAB_KERNEL);
275 afs_destroy_inode(struct inode *inode)
277 kmem_cache_free(afs_inode_cachep, inode);
281 init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
283 struct vcache *vcp = (struct vcache *) foo;
285 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
286 SLAB_CTOR_CONSTRUCTOR)
287 inode_init_once(AFSTOV(vcp));
291 afs_init_inodecache(void)
293 #ifndef SLAB_RECLAIM_ACCOUNT
294 #define SLAB_RECLAIM_ACCOUNT 0
297 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
298 sizeof(struct vcache),
299 0, SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT,
301 if (afs_inode_cachep == NULL)
307 afs_destroy_inodecache(void)
309 if (kmem_cache_destroy(afs_inode_cachep))
310 printk(KERN_INFO "afs_inode_cache: not all structures were freed\n");
314 afs_init_inodecache(void)
320 afs_destroy_inodecache(void)
327 afs_clear_inode(struct inode *ip)
329 struct vcache *vcp = VTOAFS(ip);
331 if (vcp->vlruq.prev || vcp->vlruq.next)
332 osi_Panic("inode freed while on LRU");
334 osi_Panic("inode freed while still hashed");
336 #if !defined(STRUCT_SUPER_HAS_ALLOC_INODE)
337 afs_osi_Free(ip->u.generic_ip, sizeof(struct vcache));
342 * Linux version of inactive. When refcount == 2, we are about to
343 * decrement to 1 and the only reference remaining should be for
348 afs_put_inode(struct inode *ip)
350 struct vcache *vcp = VTOAFS(ip);
353 if (VREFCOUNT(vcp) == 2)
354 afs_InactiveVCache(vcp, NULL);
359 * Called from unmount to release super_block. */
361 afs_put_super(struct super_block *sbp)
364 AFS_STATCNT(afs_unmount);
366 #if !defined(AFS_LINUX26_ENV)
376 osi_linux_free_inode_pages(); /* invalidate and release remaining AFS inodes. */
378 #if defined(AFS_LINUX24_ENV)
379 mntput(afs_cacheMnt);
382 osi_linux_verify_alloced_memory();
386 #if defined(AFS_LINUX26_ENV)
387 module_put(THIS_MODULE);
395 * statp is in user space, so we need to cobble together a statfs, then
398 #if defined(AFS_LINUX26_ENV)
400 afs_statfs(struct super_block *sbp, struct kstatfs *statp)
401 #elif defined(AFS_LINUX24_ENV)
403 afs_statfs(struct super_block *sbp, struct statfs *statp)
406 afs_statfs(struct super_block *sbp, struct statfs *__statp, int size)
409 #if !defined(AFS_LINUX24_ENV)
410 struct statfs stat, *statp;
412 if (size < sizeof(struct statfs))
415 memset(&stat, 0, size);
418 memset(statp, 0, sizeof(*statp));
421 AFS_STATCNT(afs_statfs);
423 statp->f_type = 0; /* Can we get a real type sometime? */
424 statp->f_bsize = sbp->s_blocksize;
425 statp->f_blocks = statp->f_bfree = statp->f_bavail = statp->f_files =
426 statp->f_ffree = 9000000;
427 statp->f_fsid.val[0] = AFS_VFSMAGIC;
428 statp->f_fsid.val[1] = AFS_VFSFSID;
429 statp->f_namelen = 256;
431 #if !defined(AFS_LINUX24_ENV)
432 memcpy_tofs(__statp, &stat, size);
437 struct super_operations afs_sops = {
438 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
439 .alloc_inode = afs_alloc_inode,
440 .destroy_inode = afs_destroy_inode,
442 .clear_inode = afs_clear_inode,
443 .put_inode = afs_put_inode,
444 .put_super = afs_put_super,
445 .statfs = afs_statfs,
446 #if !defined(AFS_LINUX24_ENV)
447 .notify_change = afs_notify_change,
451 /************** Support routines ************************/
454 * Set iattr data into vattr. Assume vattr cleared before call.
457 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
459 vattrp->va_mask = iattrp->ia_valid;
460 if (iattrp->ia_valid & ATTR_MODE)
461 vattrp->va_mode = iattrp->ia_mode;
462 if (iattrp->ia_valid & ATTR_UID)
463 vattrp->va_uid = iattrp->ia_uid;
464 if (iattrp->ia_valid & ATTR_GID)
465 vattrp->va_gid = iattrp->ia_gid;
466 if (iattrp->ia_valid & ATTR_SIZE)
467 vattrp->va_size = iattrp->ia_size;
468 if (iattrp->ia_valid & ATTR_ATIME) {
469 #if defined(AFS_LINUX26_ENV)
470 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
472 vattrp->va_atime.tv_sec = iattrp->ia_atime;
474 vattrp->va_atime.tv_usec = 0;
476 if (iattrp->ia_valid & ATTR_MTIME) {
477 #if defined(AFS_LINUX26_ENV)
478 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
480 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
482 vattrp->va_mtime.tv_usec = 0;
484 if (iattrp->ia_valid & ATTR_CTIME) {
485 #if defined(AFS_LINUX26_ENV)
486 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
488 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
490 vattrp->va_ctime.tv_usec = 0;
495 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
498 vattr2inode(struct inode *ip, struct vattr *vp)
500 ip->i_ino = vp->va_nodeid;
501 ip->i_nlink = vp->va_nlink;
502 ip->i_blocks = vp->va_blocks;
503 ip->i_blksize = vp->va_blocksize;
504 ip->i_rdev = vp->va_rdev;
505 ip->i_mode = vp->va_mode;
506 ip->i_uid = vp->va_uid;
507 ip->i_gid = vp->va_gid;
508 ip->i_size = vp->va_size;
509 #if defined(AFS_LINUX26_ENV)
510 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
511 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
512 /* Set the mtime nanoseconds to the sysname generation number.
513 * This convinces NFS clients that all directories have changed
514 * any time the sysname list changes.
516 ip->i_mtime.tv_nsec = afs_sysnamegen;
517 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
519 ip->i_atime = vp->va_atime.tv_sec;
520 ip->i_mtime = vp->va_mtime.tv_sec;
521 ip->i_ctime = vp->va_ctime.tv_sec;
525 /* osi_linux_free_inode_pages
527 * Free all vnodes remaining in the afs hash. Must be done before
528 * shutting down afs and freeing all memory.
531 osi_linux_free_inode_pages(void)
534 struct vcache *tvc, *nvc;
535 extern struct vcache *afs_vhashT[VCSIZE];
537 for (i = 0; i < VCSIZE; i++) {
538 for (tvc = afs_vhashT[i]; tvc; ) {
542 if (afs_FlushVCache(tvc, &slept)) /* slept always 0 for linux? */
543 printf("Failed to invalidate all pages on inode 0x%p\n", tvc);