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);
57 * VFS entry for Linux - installed in init_module
58 * Linux mounts file systems by:
59 * 1) register_filesystem(&afs_file_system) - done in init_module
60 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
61 * We are expected to setup the super_block. See afs_read_super.
63 #if defined(AFS_LINUX26_ENV)
64 struct backing_dev_info afs_backing_dev_info = {
65 .ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE,
71 * read the "super block" for AFS - roughly eguivalent to struct vfs.
72 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
74 #if defined(AFS_LINUX26_ENV)
75 static struct super_block *
76 #ifdef GET_SB_HAS_STRUCT_VFSMOUNT
77 afs_get_sb(struct file_system_type *fs_type, int flags,
78 const char *dev_name, void *data, struct vfsmount *mnt)
80 afs_get_sb(struct file_system_type *fs_type, int flags,
81 const char *dev_name, void *data)
84 #ifdef GET_SB_HAS_STRUCT_VFSMOUNT
85 return get_sb_nodev(fs_type, flags, data, afs_fill_super, mnt);
87 return get_sb_nodev(fs_type, flags, data, afs_fill_super);
92 struct file_system_type afs_fs_type = {
96 .kill_sb = kill_anon_super,
97 .fs_flags = FS_BINARY_MOUNTDATA,
99 #elif defined(AFS_LINUX24_ENV)
100 DECLARE_FSTYPE(afs_fs_type, "afs", afs_read_super, 0);
102 struct file_system_type afs_fs_type = {
103 "afs", /* name - used by mount operation. */
104 0, /* requires_dev - no for network filesystems. mount() will
105 * pass us an "unnamed" device. */
106 afs_read_super, /* wrapper to afs_mount */
107 NULL /* pointer to next file_system_type once registered. */
113 afs_fill_super(struct super_block *sb, void *data, int silent)
116 afs_read_super(struct super_block *sb, void *data, int silent)
122 if (afs_was_mounted) {
124 ("You must reload the AFS kernel extensions before remounting AFS.\n");
126 #if defined(AFS_LINUX26_ENV)
134 /* Set basics of super_block */
135 #if !defined(AFS_LINUX24_ENV)
138 #if defined(AFS_LINUX26_ENV)
139 __module_get(THIS_MODULE);
145 sb->s_blocksize = 1024;
146 sb->s_blocksize_bits = 10;
147 sb->s_magic = AFS_VFSMAGIC;
148 sb->s_op = &afs_sops; /* Super block (vfs) ops */
149 #if defined(AFS_LINUX26_ENV)
150 sb->s_export_op = &afs_export_ops;
152 #if defined(MAX_NON_LFS)
153 #ifdef AFS_64BIT_CLIENT
154 #if !defined(MAX_LFS_FILESIZE)
155 #if BITS_PER_LONG==32
156 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
157 #elif BITS_PER_LONG==64
158 #define MAX_LFS_FILESIZE 0x7fffffffffffffff
161 sb->s_maxbytes = MAX_LFS_FILESIZE;
163 sb->s_maxbytes = MAX_NON_LFS;
168 afs_globalVFS = NULL;
169 #if defined(AFS_LINUX26_ENV)
170 module_put(THIS_MODULE);
176 #if !defined(AFS_LINUX24_ENV)
181 #if defined(AFS_LINUX26_ENV)
182 return code ? -EINVAL : 0;
184 return code ? NULL : sb;
189 /* afs_root - stat the root of the file system. AFS global held on entry. */
191 afs_root(struct super_block *afsp)
193 register afs_int32 code = 0;
194 struct vrequest treq;
195 register struct vcache *tvp = 0;
197 AFS_STATCNT(afs_root);
198 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
201 cred_t *credp = crref();
204 afs_PutVCache(afs_globalVp);
208 if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
209 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
211 struct inode *ip = AFSTOV(tvp);
214 afs_getattr(tvp, &vattr, credp);
215 afs_fill_inode(ip, &vattr);
217 /* setup super_block and mount point inode. */
219 #if defined(AFS_LINUX24_ENV)
220 afsp->s_root = d_alloc_root(ip);
222 afsp->s_root = d_alloc_root(ip, NULL);
224 afsp->s_root->d_op = &afs_dentry_operations;
231 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
232 ICL_TYPE_INT32, code);
236 /* super_operations */
239 * Linux version of setattr call. What to change is in the iattr struct.
240 * We need to set bits in both the Linux inode as well as the vcache.
243 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
246 cred_t *credp = crref();
247 struct inode *ip = dp->d_inode;
251 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
253 #if defined(AFS_LINUX26_ENV)
257 code = afs_setattr(VTOAFS(ip), &vattr, credp);
259 afs_getattr(VTOAFS(ip), &vattr, credp);
260 vattr2inode(ip, &vattr);
263 #if defined(AFS_LINUX26_ENV)
271 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
272 static kmem_cache_t *afs_inode_cachep;
274 static struct inode *
275 afs_alloc_inode(struct super_block *sb)
279 vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, SLAB_KERNEL);
287 afs_destroy_inode(struct inode *inode)
289 kmem_cache_free(afs_inode_cachep, inode);
293 init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
295 struct vcache *vcp = (struct vcache *) foo;
297 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
298 SLAB_CTOR_CONSTRUCTOR)
299 inode_init_once(AFSTOV(vcp));
303 afs_init_inodecache(void)
305 #ifndef SLAB_RECLAIM_ACCOUNT
306 #define SLAB_RECLAIM_ACCOUNT 0
309 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
310 sizeof(struct vcache),
311 0, SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT,
313 if (afs_inode_cachep == NULL)
319 afs_destroy_inodecache(void)
321 if (kmem_cache_destroy(afs_inode_cachep))
322 printk(KERN_INFO "afs_inode_cache: not all structures were freed\n");
326 afs_init_inodecache(void)
332 afs_destroy_inodecache(void)
339 afs_clear_inode(struct inode *ip)
341 struct vcache *vcp = VTOAFS(ip);
343 if (vcp->vlruq.prev || vcp->vlruq.next)
344 osi_Panic("inode freed while on LRU");
346 osi_Panic("inode freed while still hashed");
348 #if !defined(STRUCT_SUPER_HAS_ALLOC_INODE)
349 afs_osi_Free(ip->u.generic_ip, sizeof(struct vcache));
354 * Called from unmount to release super_block. */
356 afs_put_super(struct super_block *sbp)
359 AFS_STATCNT(afs_unmount);
361 #if !defined(AFS_LINUX26_ENV)
371 osi_linux_free_inode_pages(); /* invalidate and release remaining AFS inodes. */
373 #if defined(AFS_LINUX24_ENV)
374 mntput(afs_cacheMnt);
377 osi_linux_verify_alloced_memory();
381 #if defined(AFS_LINUX26_ENV)
382 module_put(THIS_MODULE);
390 * statp is in user space, so we need to cobble together a statfs, then
393 #if defined(AFS_LINUX26_ENV)
395 afs_statfs(struct super_block *sbp, struct kstatfs *statp)
396 #elif defined(AFS_LINUX24_ENV)
398 afs_statfs(struct super_block *sbp, struct statfs *statp)
401 afs_statfs(struct super_block *sbp, struct statfs *__statp, int size)
404 #if !defined(AFS_LINUX24_ENV)
405 struct statfs stat, *statp;
407 if (size < sizeof(struct statfs))
410 memset(&stat, 0, size);
413 memset(statp, 0, sizeof(*statp));
416 AFS_STATCNT(afs_statfs);
418 statp->f_type = 0; /* Can we get a real type sometime? */
419 statp->f_bsize = sbp->s_blocksize;
420 statp->f_blocks = statp->f_bfree = statp->f_bavail = statp->f_files =
421 statp->f_ffree = 9000000;
422 statp->f_fsid.val[0] = AFS_VFSMAGIC;
423 statp->f_fsid.val[1] = AFS_VFSFSID;
424 statp->f_namelen = 256;
426 #if !defined(AFS_LINUX24_ENV)
427 memcpy_tofs(__statp, &stat, size);
432 struct super_operations afs_sops = {
433 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
434 .alloc_inode = afs_alloc_inode,
435 .destroy_inode = afs_destroy_inode,
437 .clear_inode = afs_clear_inode,
438 .put_super = afs_put_super,
439 .statfs = afs_statfs,
440 #if !defined(AFS_LINUX24_ENV)
441 .notify_change = afs_notify_change,
445 /************** Support routines ************************/
448 * Set iattr data into vattr. Assume vattr cleared before call.
451 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
453 vattrp->va_mask = iattrp->ia_valid;
454 if (iattrp->ia_valid & ATTR_MODE)
455 vattrp->va_mode = iattrp->ia_mode;
456 if (iattrp->ia_valid & ATTR_UID)
457 vattrp->va_uid = iattrp->ia_uid;
458 if (iattrp->ia_valid & ATTR_GID)
459 vattrp->va_gid = iattrp->ia_gid;
460 if (iattrp->ia_valid & ATTR_SIZE)
461 vattrp->va_size = iattrp->ia_size;
462 if (iattrp->ia_valid & ATTR_ATIME) {
463 #if defined(AFS_LINUX26_ENV)
464 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
466 vattrp->va_atime.tv_sec = iattrp->ia_atime;
468 vattrp->va_atime.tv_usec = 0;
470 if (iattrp->ia_valid & ATTR_MTIME) {
471 #if defined(AFS_LINUX26_ENV)
472 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
474 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
476 vattrp->va_mtime.tv_usec = 0;
478 if (iattrp->ia_valid & ATTR_CTIME) {
479 #if defined(AFS_LINUX26_ENV)
480 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
482 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
484 vattrp->va_ctime.tv_usec = 0;
489 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
492 vattr2inode(struct inode *ip, struct vattr *vp)
494 ip->i_ino = vp->va_nodeid;
495 ip->i_nlink = vp->va_nlink;
496 ip->i_blocks = vp->va_blocks;
497 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
498 ip->i_blksize = vp->va_blocksize;
500 ip->i_rdev = vp->va_rdev;
501 ip->i_mode = vp->va_mode;
502 ip->i_uid = vp->va_uid;
503 ip->i_gid = vp->va_gid;
504 ip->i_size = vp->va_size;
505 #if defined(AFS_LINUX26_ENV)
506 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
507 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
508 /* Set the mtime nanoseconds to the sysname generation number.
509 * This convinces NFS clients that all directories have changed
510 * any time the sysname list changes.
512 ip->i_mtime.tv_nsec = afs_sysnamegen;
513 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
515 ip->i_atime = vp->va_atime.tv_sec;
516 ip->i_mtime = vp->va_mtime.tv_sec;
517 ip->i_ctime = vp->va_ctime.tv_sec;
521 /* osi_linux_free_inode_pages
523 * Free all vnodes remaining in the afs hash. Must be done before
524 * shutting down afs and freeing all memory.
527 osi_linux_free_inode_pages(void)
530 struct vcache *tvc, *nvc;
531 extern struct vcache *afs_vhashT[VCSIZE];
533 for (i = 0; i < VCSIZE; i++) {
534 for (tvc = afs_vhashT[i]; tvc; ) {
538 if (afs_FlushVCache(tvc, &slept)) /* slept always 0 for linux? */
539 printf("Failed to invalidate all pages on inode 0x%p\n", tvc);