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"
19 #define __NO_VERSION__ /* don't define kernel_version in module.h */
20 #include <linux/module.h> /* early to avoid printf->printk mapping */
21 #include "afs/sysincludes.h"
22 #include "afsincludes.h"
23 #include "afs/afs_stats.h"
25 #if defined(AFS_LINUX24_ENV)
26 #include "h/smp_lock.h"
30 struct vcache *afs_globalVp = 0;
31 struct vfs *afs_globalVFS = 0;
32 #if defined(AFS_LINUX24_ENV)
33 struct vfsmount *afs_cacheMnt;
35 int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */
37 extern struct super_operations afs_sops;
38 extern afs_rwlock_t afs_xvcache;
39 extern struct afs_q VLRU;
41 extern struct dentry_operations afs_dentry_operations;
43 /* Forward declarations */
44 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
45 static int afs_root(struct super_block *afsp);
46 struct super_block *afs_read_super(struct super_block *sb, void *data, int silent);
47 int afs_fill_super(struct super_block *sb, void *data, int silent);
50 * VFS entry for Linux - installed in init_module
51 * Linux mounts file systems by:
52 * 1) register_filesystem(&afs_file_system) - done in init_module
53 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
54 * We are expected to setup the super_block. See afs_read_super.
59 * read the "super block" for AFS - roughly eguivalent to struct vfs.
60 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
62 #if defined(AFS_LINUX24_ENV)
63 DECLARE_FSTYPE(afs_fs_type, "afs", afs_read_super, 0);
65 struct file_system_type afs_fs_type = {
66 "afs", /* name - used by mount operation. */
67 0, /* requires_dev - no for network filesystems. mount() will
68 * pass us an "unnamed" device. */
69 afs_read_super, /* wrapper to afs_mount */
70 NULL /* pointer to next file_system_type once registered. */
75 afs_read_super(struct super_block *sb, void *data, int silent)
80 if (afs_was_mounted) {
82 ("You must reload the AFS kernel extensions before remounting AFS.\n");
88 /* Set basics of super_block */
89 #if !defined(AFS_LINUX24_ENV)
95 sb->s_blocksize = 1024;
96 sb->s_blocksize_bits = 10;
97 sb->s_magic = AFS_VFSMAGIC;
98 sb->s_op = &afs_sops; /* Super block (vfs) ops */
99 #if defined(HAVE_BDI_INIT)
100 bdi_init(&afs_backing_dev_info);
102 #if defined(MAX_NON_LFS)
103 #ifdef AFS_64BIT_CLIENT
104 #if !defined(MAX_LFS_FILESIZE)
105 #if BITS_PER_LONG==32
106 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
107 #elif BITS_PER_LONG==64
108 #define MAX_LFS_FILESIZE 0x7fffffffffffffff
111 sb->s_maxbytes = MAX_LFS_FILESIZE;
113 sb->s_maxbytes = MAX_NON_LFS;
118 afs_globalVFS = NULL;
122 #if !defined(AFS_LINUX24_ENV)
127 return code ? NULL : sb;
131 /* afs_root - stat the root of the file system. AFS global held on entry. */
133 afs_root(struct super_block *afsp)
135 register afs_int32 code = 0;
136 struct vrequest treq;
137 register struct vcache *tvp = 0;
139 AFS_STATCNT(afs_root);
140 if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
143 cred_t *credp = crref();
146 afs_PutVCache(afs_globalVp);
150 if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
151 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
153 struct inode *ip = AFSTOV(tvp);
156 afs_getattr(tvp, &vattr, credp);
157 afs_fill_inode(ip, &vattr);
159 /* setup super_block and mount point inode. */
161 #if defined(AFS_LINUX24_ENV)
162 afsp->s_root = d_alloc_root(ip);
164 afsp->s_root = d_alloc_root(ip, NULL);
166 afsp->s_root->d_op = &afs_dentry_operations;
173 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
174 ICL_TYPE_INT32, code);
178 /* super_operations */
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.
185 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. */
196 code = afs_setattr(VTOAFS(ip), &vattr, credp);
198 afs_getattr(VTOAFS(ip), &vattr, credp);
199 vattr2inode(ip, &vattr);
207 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
208 #if defined(HAVE_KMEM_CACHE_T)
209 static kmem_cache_t *afs_inode_cachep;
211 struct kmem_cache *afs_inode_cachep;
214 static struct inode *
215 afs_alloc_inode(struct super_block *sb)
219 #if defined(SLAB_KERNEL)
220 vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, SLAB_KERNEL);
222 vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL);
231 afs_destroy_inode(struct inode *inode)
233 kmem_cache_free(afs_inode_cachep, inode);
237 #if defined(HAVE_KMEM_CACHE_T)
238 init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
240 #if defined(KMEM_CACHE_INIT)
241 init_once(struct kmem_cache * cachep, void * foo)
243 init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
247 struct vcache *vcp = (struct vcache *) foo;
249 #if defined(SLAB_CTOR_VERIFY)
250 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
251 SLAB_CTOR_CONSTRUCTOR)
253 inode_init_once(AFSTOV(vcp));
257 afs_init_inodecache(void)
259 #ifndef SLAB_RECLAIM_ACCOUNT
260 #define SLAB_RECLAIM_ACCOUNT 0
263 #if defined(KMEM_CACHE_TAKES_DTOR)
264 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
265 sizeof(struct vcache),
266 0, SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT,
269 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
270 sizeof(struct vcache),
271 0, SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT,
274 if (afs_inode_cachep == NULL)
280 afs_destroy_inodecache(void)
282 if (afs_inode_cachep)
283 (void) kmem_cache_destroy(afs_inode_cachep);
287 afs_init_inodecache(void)
293 afs_destroy_inodecache(void)
300 afs_clear_inode(struct inode *ip)
302 struct vcache *vcp = VTOAFS(ip);
304 if (vcp->vlruq.prev || vcp->vlruq.next)
305 osi_Panic("inode freed while on LRU");
307 osi_Panic("inode freed while still hashed");
309 #if !defined(STRUCT_SUPER_HAS_ALLOC_INODE)
310 afs_osi_Free(ip->u.generic_ip, sizeof(struct vcache));
315 * Called from unmount to release super_block. */
317 afs_put_super(struct super_block *sbp)
320 AFS_STATCNT(afs_unmount);
330 osi_linux_free_inode_pages(); /* invalidate and release remaining AFS inodes. */
332 #if defined(AFS_LINUX24_ENV)
333 mntput(afs_cacheMnt);
336 osi_linux_verify_alloced_memory();
337 #if defined(HAVE_BDI_INIT)
338 bdi_destroy(&afs_backing_dev_info);
348 * statp is in user space, so we need to cobble together a statfs, then
351 #if defined(AFS_LINUX24_ENV)
353 afs_statfs(struct super_block *sbp, struct statfs *statp)
356 afs_statfs(struct super_block *sbp, struct statfs *__statp, int size)
359 #if !defined(AFS_LINUX24_ENV)
360 struct statfs stat, *statp;
362 if (size < sizeof(struct statfs))
365 memset(&stat, 0, size);
368 memset(statp, 0, sizeof(*statp));
371 AFS_STATCNT(afs_statfs);
373 /* hardcode in case that which is giveth is taken away */
374 statp->f_type = 0x5346414F;
375 #if defined(STATFS_TAKES_DENTRY)
376 statp->f_bsize = dentry->d_sb->s_blocksize;
378 statp->f_bsize = sbp->s_blocksize;
380 statp->f_blocks = statp->f_bfree = statp->f_bavail = statp->f_files =
381 statp->f_ffree = 9000000;
382 statp->f_fsid.val[0] = AFS_VFSMAGIC;
383 statp->f_fsid.val[1] = AFS_VFSFSID;
384 statp->f_namelen = 256;
386 #if !defined(AFS_LINUX24_ENV)
387 memcpy_tofs(__statp, &stat, size);
392 struct super_operations afs_sops = {
393 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
394 .alloc_inode = afs_alloc_inode,
395 .destroy_inode = afs_destroy_inode,
397 .clear_inode = afs_clear_inode,
398 .put_super = afs_put_super,
399 .statfs = afs_statfs,
400 #if !defined(AFS_LINUX24_ENV)
401 .notify_change = afs_notify_change,
405 /************** Support routines ************************/
408 * Set iattr data into vattr. Assume vattr cleared before call.
411 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
413 vattrp->va_mask = iattrp->ia_valid;
414 if (iattrp->ia_valid & ATTR_MODE)
415 vattrp->va_mode = iattrp->ia_mode;
416 if (iattrp->ia_valid & ATTR_UID)
417 vattrp->va_uid = iattrp->ia_uid;
418 if (iattrp->ia_valid & ATTR_GID)
419 vattrp->va_gid = iattrp->ia_gid;
420 if (iattrp->ia_valid & ATTR_SIZE)
421 vattrp->va_size = iattrp->ia_size;
422 if (iattrp->ia_valid & ATTR_ATIME) {
423 vattrp->va_atime.tv_sec = iattrp->ia_atime;
424 vattrp->va_atime.tv_usec = 0;
426 if (iattrp->ia_valid & ATTR_MTIME) {
427 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
428 vattrp->va_mtime.tv_usec = 0;
430 if (iattrp->ia_valid & ATTR_CTIME) {
431 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
432 vattrp->va_ctime.tv_usec = 0;
437 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
440 vattr2inode(struct inode *ip, struct vattr *vp)
442 ip->i_ino = vp->va_nodeid;
443 ip->i_nlink = vp->va_nlink;
444 ip->i_blocks = vp->va_blocks;
445 #ifdef STRUCT_INODE_HAS_I_BLKBITS
446 ip->i_blkbits = AFS_BLKBITS;
448 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
449 ip->i_blksize = vp->va_blocksize;
451 ip->i_rdev = vp->va_rdev;
452 ip->i_mode = vp->va_mode;
453 ip->i_uid = vp->va_uid;
454 ip->i_gid = vp->va_gid;
455 i_size_write(ip, vp->va_size);
456 ip->i_atime = vp->va_atime.tv_sec;
457 ip->i_mtime = vp->va_mtime.tv_sec;
458 ip->i_ctime = vp->va_ctime.tv_sec;
461 /* osi_linux_free_inode_pages
463 * Free all vnodes remaining in the afs hash. Must be done before
464 * shutting down afs and freeing all memory.
467 osi_linux_free_inode_pages(void)
470 struct vcache *tvc, *nvc;
471 extern struct vcache *afs_vhashT[VCSIZE];
473 for (i = 0; i < VCSIZE; i++) {
474 for (tvc = afs_vhashT[i]; tvc; ) {
478 if (afs_FlushVCache(tvc, &slept)) /* slept always 0 for linux? */
479 printf("Failed to invalidate all pages on inode 0x%p\n", tvc);