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_flags |= MS_NOATIME;
96 sb->s_blocksize = 1024;
97 sb->s_blocksize_bits = 10;
98 sb->s_magic = AFS_VFSMAGIC;
99 sb->s_op = &afs_sops; /* Super block (vfs) ops */
100 #if defined(MAX_NON_LFS)
101 #ifdef AFS_64BIT_CLIENT
102 #if !defined(MAX_LFS_FILESIZE)
103 #if BITS_PER_LONG==32
104 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
105 #elif BITS_PER_LONG==64
106 #define MAX_LFS_FILESIZE 0x7fffffffffffffff
109 sb->s_maxbytes = MAX_LFS_FILESIZE;
111 sb->s_maxbytes = MAX_NON_LFS;
116 afs_globalVFS = NULL;
120 #if !defined(AFS_LINUX24_ENV)
125 return code ? NULL : sb;
129 /* afs_root - stat the root of the file system. AFS global held on entry. */
131 afs_root(struct super_block *afsp)
134 struct vrequest treq;
135 struct vcache *tvp = 0;
137 AFS_STATCNT(afs_root);
138 if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
141 cred_t *credp = crref();
144 afs_PutVCache(afs_globalVp);
148 if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
149 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
151 struct inode *ip = AFSTOV(tvp);
154 afs_getattr(tvp, &vattr, credp);
155 afs_fill_inode(ip, &vattr);
157 /* setup super_block and mount point inode. */
159 #if defined(AFS_LINUX24_ENV)
160 afsp->s_root = d_alloc_root(ip);
162 afsp->s_root = d_alloc_root(ip, NULL);
164 afsp->s_root->d_op = &afs_dentry_operations;
171 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
172 ICL_TYPE_INT32, code);
176 /* super_operations */
179 * Linux version of setattr call. What to change is in the iattr struct.
180 * We need to set bits in both the Linux inode as well as the vcache.
183 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
186 cred_t *credp = crref();
187 struct inode *ip = dp->d_inode;
191 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
194 code = afs_setattr(VTOAFS(ip), &vattr, credp);
196 afs_getattr(VTOAFS(ip), &vattr, credp);
197 vattr2inode(ip, &vattr);
205 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
206 #if defined(HAVE_KMEM_CACHE_T)
207 static kmem_cache_t *afs_inode_cachep;
209 struct kmem_cache *afs_inode_cachep;
212 static struct inode *
213 afs_alloc_inode(struct super_block *sb)
217 #if defined(SLAB_KERNEL)
218 vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, SLAB_KERNEL);
220 vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL);
229 afs_destroy_inode(struct inode *inode)
231 kmem_cache_free(afs_inode_cachep, inode);
235 #if defined(HAVE_KMEM_CACHE_T)
236 init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
238 #if defined(KMEM_CACHE_INIT)
239 init_once(struct kmem_cache * cachep, void * foo)
241 init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
245 struct vcache *vcp = (struct vcache *) foo;
247 #if defined(SLAB_CTOR_VERIFY)
248 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
249 SLAB_CTOR_CONSTRUCTOR)
251 inode_init_once(AFSTOV(vcp));
255 afs_init_inodecache(void)
257 #ifndef SLAB_RECLAIM_ACCOUNT
258 #define SLAB_RECLAIM_ACCOUNT 0
261 #if defined(KMEM_CACHE_TAKES_DTOR)
262 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
263 sizeof(struct vcache),
264 0, SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT,
267 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
268 sizeof(struct vcache),
269 0, SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT,
272 if (afs_inode_cachep == NULL)
278 afs_destroy_inodecache(void)
280 if (afs_inode_cachep)
281 (void) kmem_cache_destroy(afs_inode_cachep);
285 afs_init_inodecache(void)
291 afs_destroy_inodecache(void)
298 afs_clear_inode(struct inode *ip)
300 struct vcache *vcp = VTOAFS(ip);
302 if (vcp->vlruq.prev || vcp->vlruq.next)
303 osi_Panic("inode freed while on LRU");
305 osi_Panic("inode freed while still hashed");
307 #if !defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
308 afs_osi_Free(ip->u.generic_ip, sizeof(struct vcache));
313 * Called from unmount to release super_block. */
315 afs_put_super(struct super_block *sbp)
318 AFS_STATCNT(afs_unmount);
328 osi_linux_free_inode_pages(); /* invalidate and release remaining AFS inodes. */
330 #if defined(AFS_LINUX24_ENV)
331 mntput(afs_cacheMnt);
334 osi_linux_verify_alloced_memory();
343 * statp is in user space, so we need to cobble together a statfs, then
346 #if defined(AFS_LINUX24_ENV)
348 afs_statfs(struct super_block *sbp, struct statfs *statp)
351 afs_statfs(struct super_block *sbp, struct statfs *__statp, int size)
354 #if !defined(AFS_LINUX24_ENV)
355 struct statfs stat, *statp;
357 if (size < sizeof(struct statfs))
360 memset(&stat, 0, size);
363 memset(statp, 0, sizeof(*statp));
366 AFS_STATCNT(afs_statfs);
368 /* hardcode in case that which is giveth is taken away */
369 statp->f_type = 0x5346414F;
370 #if defined(STATFS_TAKES_DENTRY)
371 statp->f_bsize = dentry->d_sb->s_blocksize;
373 statp->f_bsize = sbp->s_blocksize;
375 statp->f_blocks = statp->f_bfree = statp->f_bavail = statp->f_files =
376 statp->f_ffree = 9000000;
377 statp->f_fsid.val[0] = AFS_VFSMAGIC;
378 statp->f_fsid.val[1] = AFS_VFSFSID;
379 statp->f_namelen = 256;
381 #if !defined(AFS_LINUX24_ENV)
382 memcpy_tofs(__statp, &stat, size);
387 struct super_operations afs_sops = {
388 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
389 .alloc_inode = afs_alloc_inode,
390 .destroy_inode = afs_destroy_inode,
392 .clear_inode = afs_clear_inode,
393 .put_super = afs_put_super,
394 .statfs = afs_statfs,
395 #if !defined(AFS_LINUX24_ENV)
396 .notify_change = afs_notify_change,
400 /************** Support routines ************************/
403 * Set iattr data into vattr. Assume vattr cleared before call.
406 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
408 vattrp->va_mask = iattrp->ia_valid;
409 if (iattrp->ia_valid & ATTR_MODE)
410 vattrp->va_mode = iattrp->ia_mode;
411 if (iattrp->ia_valid & ATTR_UID)
412 vattrp->va_uid = iattrp->ia_uid;
413 if (iattrp->ia_valid & ATTR_GID)
414 vattrp->va_gid = iattrp->ia_gid;
415 if (iattrp->ia_valid & ATTR_SIZE)
416 vattrp->va_size = iattrp->ia_size;
417 if (iattrp->ia_valid & ATTR_ATIME) {
418 vattrp->va_atime.tv_sec = iattrp->ia_atime;
419 vattrp->va_atime.tv_usec = 0;
421 if (iattrp->ia_valid & ATTR_MTIME) {
422 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
423 vattrp->va_mtime.tv_usec = 0;
425 if (iattrp->ia_valid & ATTR_CTIME) {
426 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
427 vattrp->va_ctime.tv_usec = 0;
432 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
435 vattr2inode(struct inode *ip, struct vattr *vp)
437 ip->i_ino = vp->va_nodeid;
438 ip->i_nlink = vp->va_nlink;
439 ip->i_blocks = vp->va_blocks;
440 #ifdef STRUCT_INODE_HAS_I_BLKBITS
441 ip->i_blkbits = AFS_BLKBITS;
443 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
444 ip->i_blksize = vp->va_blocksize;
446 ip->i_rdev = vp->va_rdev;
447 ip->i_mode = vp->va_mode;
448 ip->i_uid = vp->va_uid;
449 ip->i_gid = vp->va_gid;
450 i_size_write(ip, vp->va_size);
451 ip->i_atime = vp->va_atime.tv_sec;
452 ip->i_mtime = vp->va_mtime.tv_sec;
453 ip->i_ctime = vp->va_ctime.tv_sec;
456 /* osi_linux_free_inode_pages
458 * Free all vnodes remaining in the afs hash. Must be done before
459 * shutting down afs and freeing all memory.
462 osi_linux_free_inode_pages(void)
465 struct vcache *tvc, *nvc;
466 extern struct vcache *afs_vhashT[VCSIZE];
469 for (i = 0; i < VCSIZE; i++) {
470 for (tvc = afs_vhashT[i]; tvc; ) {
474 if (afs_FlushVCache(tvc, &slept))
475 printf("Failed to invalidate all pages on inode 0x%p\n", tvc);