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 extern afs_rwlock_t afs_xvcache;
43 extern struct afs_q VLRU;
45 extern struct dentry_operations afs_dentry_operations;
47 /* Forward declarations */
48 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
49 static int afs_root(struct super_block *afsp);
50 struct super_block *afs_read_super(struct super_block *sb, void *data, int silent);
51 int afs_fill_super(struct super_block *sb, void *data, int silent);
52 static struct super_block *afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data);
55 * VFS entry for Linux - installed in init_module
56 * Linux mounts file systems by:
57 * 1) register_filesystem(&afs_file_system) - done in init_module
58 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
59 * We are expected to setup the super_block. See afs_read_super.
61 #if defined(AFS_LINUX26_ENV)
62 struct backing_dev_info afs_backing_dev_info = {
63 .ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE,
67 struct file_system_type afs_fs_type = {
71 .kill_sb = kill_anon_super,
72 .fs_flags = FS_BINARY_MOUNTDATA,
74 #elif defined(AFS_LINUX24_ENV)
75 DECLARE_FSTYPE(afs_fs_type, "afs", afs_read_super, 0);
77 struct file_system_type afs_fs_type = {
78 "afs", /* name - used by mount operation. */
79 0, /* requires_dev - no for network filesystems. mount() will
80 * pass us an "unnamed" device. */
81 afs_read_super, /* wrapper to afs_mount */
82 NULL /* pointer to next file_system_type once registered. */
87 * read the "super block" for AFS - roughly eguivalent to struct vfs.
88 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
90 #if defined(AFS_LINUX26_ENV)
91 static struct super_block *
92 afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
94 return get_sb_nodev(fs_type, flags, data, afs_fill_super);
98 afs_fill_super(struct super_block *sb, void *data, int silent)
101 afs_read_super(struct super_block *sb, void *data, int silent)
107 if (afs_was_mounted) {
109 ("You must reload the AFS kernel extensions before remounting AFS.\n");
111 #if defined(AFS_LINUX26_ENV)
119 /* Set basics of super_block */
120 #if !defined(AFS_LINUX24_ENV)
123 #if defined(AFS_LINUX26_ENV)
124 __module_get(THIS_MODULE);
130 sb->s_blocksize = 1024;
131 sb->s_blocksize_bits = 10;
132 sb->s_magic = AFS_VFSMAGIC;
133 sb->s_op = &afs_sops; /* Super block (vfs) ops */
134 #if defined(MAX_NON_LFS)
135 #ifdef AFS_64BIT_CLIENT
136 #if !defined(MAX_LFS_FILESIZE)
137 #if BITS_PER_LONG==32
138 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
139 #elif BITS_PER_LONG==64
140 #define MAX_LFS_FILESIZE 0x7fffffffffffffff
143 sb->s_maxbytes = MAX_LFS_FILESIZE;
145 sb->s_maxbytes = MAX_NON_LFS;
150 afs_globalVFS = NULL;
151 #if defined(AFS_LINUX26_ENV)
152 module_put(THIS_MODULE);
158 #if !defined(AFS_LINUX24_ENV)
163 #if defined(AFS_LINUX26_ENV)
164 return code ? -EINVAL : 0;
166 return code ? NULL : sb;
171 /* afs_root - stat the root of the file system. AFS global held on entry. */
173 afs_root(struct super_block *afsp)
175 register afs_int32 code = 0;
176 struct vrequest treq;
177 register struct vcache *tvp = 0;
179 AFS_STATCNT(afs_root);
180 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
183 cred_t *credp = crref();
186 afs_PutVCache(afs_globalVp);
190 if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
191 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
193 struct inode *ip = AFSTOV(tvp);
196 afs_getattr(tvp, &vattr, credp);
197 afs_fill_inode(ip, &vattr);
199 /* setup super_block and mount point inode. */
201 #if defined(AFS_LINUX24_ENV)
202 afsp->s_root = d_alloc_root(ip);
204 afsp->s_root = d_alloc_root(ip, NULL);
206 afsp->s_root->d_op = &afs_dentry_operations;
213 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
214 ICL_TYPE_INT32, code);
218 /* super_operations */
221 * Linux version of setattr call. What to change is in the iattr struct.
222 * We need to set bits in both the Linux inode as well as the vcache.
225 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
228 cred_t *credp = crref();
229 struct inode *ip = dp->d_inode;
233 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
235 #if defined(AFS_LINUX26_ENV)
239 code = afs_setattr(VTOAFS(ip), &vattr, credp);
241 afs_getattr(VTOAFS(ip), &vattr, credp);
242 vattr2inode(ip, &vattr);
245 #if defined(AFS_LINUX26_ENV)
253 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
254 static kmem_cache_t *afs_inode_cachep;
256 static struct inode *
257 afs_alloc_inode(struct super_block *sb)
261 vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, SLAB_KERNEL);
269 afs_destroy_inode(struct inode *inode)
271 kmem_cache_free(afs_inode_cachep, inode);
275 init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
277 struct vcache *vcp = (struct vcache *) foo;
279 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
280 SLAB_CTOR_CONSTRUCTOR)
281 inode_init_once(AFSTOV(vcp));
285 afs_init_inodecache(void)
287 #ifndef SLAB_RECLAIM_ACCOUNT
288 #define SLAB_RECLAIM_ACCOUNT 0
291 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
292 sizeof(struct vcache),
293 0, SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT,
295 if (afs_inode_cachep == NULL)
301 afs_destroy_inodecache(void)
303 if (kmem_cache_destroy(afs_inode_cachep))
304 printk(KERN_INFO "afs_inode_cache: not all structures were freed\n");
308 afs_init_inodecache(void)
314 afs_destroy_inodecache(void)
321 afs_clear_inode(struct inode *ip)
323 struct vcache *vcp = VTOAFS(ip);
325 if (vcp->vlruq.prev || vcp->vlruq.next)
326 osi_Panic("inode freed while on LRU");
327 if (vcp->hnext || vcp->vhnext)
328 osi_Panic("inode freed while still hashed");
330 #if !defined(STRUCT_SUPER_HAS_ALLOC_INODE)
331 afs_osi_Free(ip->u.generic_ip, sizeof(struct vcache));
336 * Linux version of inactive. When refcount == 2, we are about to
337 * decrement to 1 and the only reference remaining should be for
342 afs_put_inode(struct inode *ip)
344 cred_t *credp = crref();
345 struct vcache *vcp = VTOAFS(ip);
348 ObtainReadLock(&vcp->lock);
349 if (VREFCOUNT(vcp) == 2)
350 afs_InactiveVCache(vcp, credp);
351 ReleaseReadLock(&vcp->lock);
357 * Called from unmount to release super_block. */
359 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();
387 #if defined(AFS_LINUX26_ENV)
388 module_put(THIS_MODULE);
397 * statp is in user space, so we need to cobble together a statfs, then
400 #if defined(AFS_LINUX26_ENV)
402 afs_statfs(struct super_block *sbp, struct kstatfs *statp)
403 #elif defined(AFS_LINUX24_ENV)
405 afs_statfs(struct super_block *sbp, struct statfs *statp)
408 afs_statfs(struct super_block *sbp, struct statfs *__statp, int size)
411 #if !defined(AFS_LINUX24_ENV)
412 struct statfs stat, *statp;
414 if (size < sizeof(struct statfs))
417 memset(&stat, 0, size);
420 memset(statp, 0, sizeof(*statp));
423 AFS_STATCNT(afs_statfs);
425 statp->f_type = 0; /* Can we get a real type sometime? */
426 statp->f_bsize = sbp->s_blocksize;
427 statp->f_blocks = statp->f_bfree = statp->f_bavail = statp->f_files =
428 statp->f_ffree = 9000000;
429 statp->f_fsid.val[0] = AFS_VFSMAGIC;
430 statp->f_fsid.val[1] = AFS_VFSFSID;
431 statp->f_namelen = 256;
433 #if !defined(AFS_LINUX24_ENV)
434 memcpy_tofs(__statp, &stat, size);
440 afs_umount_begin(struct super_block *sbp)
442 afs_shuttingdown = 1;
445 struct super_operations afs_sops = {
446 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
447 .alloc_inode = afs_alloc_inode,
448 .destroy_inode = afs_destroy_inode,
450 .clear_inode = afs_clear_inode,
451 .put_inode = afs_put_inode,
452 .put_super = afs_put_super,
453 .statfs = afs_statfs,
454 .umount_begin = afs_umount_begin
455 #if !defined(AFS_LINUX24_ENV)
456 .notify_change = afs_notify_change,
460 /************** Support routines ************************/
463 * Set iattr data into vattr. Assume vattr cleared before call.
466 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
468 vattrp->va_mask = iattrp->ia_valid;
469 if (iattrp->ia_valid & ATTR_MODE)
470 vattrp->va_mode = iattrp->ia_mode;
471 if (iattrp->ia_valid & ATTR_UID)
472 vattrp->va_uid = iattrp->ia_uid;
473 if (iattrp->ia_valid & ATTR_GID)
474 vattrp->va_gid = iattrp->ia_gid;
475 if (iattrp->ia_valid & ATTR_SIZE)
476 vattrp->va_size = iattrp->ia_size;
477 if (iattrp->ia_valid & ATTR_ATIME) {
478 #if defined(AFS_LINUX26_ENV)
479 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
481 vattrp->va_atime.tv_sec = iattrp->ia_atime;
483 vattrp->va_atime.tv_usec = 0;
485 if (iattrp->ia_valid & ATTR_MTIME) {
486 #if defined(AFS_LINUX26_ENV)
487 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
489 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
491 vattrp->va_mtime.tv_usec = 0;
493 if (iattrp->ia_valid & ATTR_CTIME) {
494 #if defined(AFS_LINUX26_ENV)
495 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
497 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
499 vattrp->va_ctime.tv_usec = 0;
504 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
507 vattr2inode(struct inode *ip, struct vattr *vp)
509 ip->i_ino = vp->va_nodeid;
510 ip->i_nlink = vp->va_nlink;
511 ip->i_blocks = vp->va_blocks;
512 ip->i_blksize = vp->va_blocksize;
513 ip->i_rdev = vp->va_rdev;
514 ip->i_mode = vp->va_mode;
515 ip->i_uid = vp->va_uid;
516 ip->i_gid = vp->va_gid;
517 ip->i_size = vp->va_size;
518 #if defined(AFS_LINUX26_ENV)
519 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
520 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
521 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
523 ip->i_atime = vp->va_atime.tv_sec;
524 ip->i_mtime = vp->va_mtime.tv_sec;
525 ip->i_ctime = vp->va_ctime.tv_sec;