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"
24 #include <linux/smp_lock.h>
26 #include "osi_compat.h"
28 struct vcache *afs_globalVp = 0;
29 struct vfs *afs_globalVFS = 0;
30 struct vfsmount *afs_cacheMnt;
31 int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */
33 extern struct super_operations afs_sops;
34 #if !defined(AFS_NONFSTRANS)
35 extern struct export_operations afs_export_ops;
37 extern afs_rwlock_t afs_xvcache;
38 extern struct afs_q VLRU;
40 extern struct dentry_operations afs_dentry_operations;
42 /* Forward declarations */
43 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
44 static int afs_root(struct super_block *afsp);
45 struct super_block *afs_read_super(struct super_block *sb, void *data, int silent);
46 int afs_fill_super(struct super_block *sb, void *data, int silent);
49 * VFS entry for Linux - installed in init_module
50 * Linux mounts file systems by:
51 * 1) register_filesystem(&afs_file_system) - done in init_module
52 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
53 * We are expected to setup the super_block. See afs_read_super.
58 * read the "super block" for AFS - roughly eguivalent to struct vfs.
59 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
61 #ifdef GET_SB_HAS_STRUCT_VFSMOUNT
63 afs_get_sb(struct file_system_type *fs_type, int flags,
64 const char *dev_name, void *data, struct vfsmount *mnt) {
65 return get_sb_nodev(fs_type, flags, data, afs_fill_super, mnt);
68 static struct superblock *
69 afs_get_sb(struct file_system_type *fs_type, int flags,
70 const char *dev_name, void *data) {
71 return get_sb_nodev(fs_type, flags, data, afs_fill_super);
75 struct file_system_type afs_fs_type = {
79 .kill_sb = kill_anon_super,
80 .fs_flags = FS_BINARY_MOUNTDATA,
83 struct backing_dev_info *afs_backing_dev_info;
86 afs_fill_super(struct super_block *sb, void *data, int silent)
91 if (afs_was_mounted) {
93 ("You must reload the AFS kernel extensions before remounting AFS.\n");
99 /* Set basics of super_block */
100 __module_get(THIS_MODULE);
103 sb->s_flags |= MS_NOATIME;
104 sb->s_blocksize = 1024;
105 sb->s_blocksize_bits = 10;
106 sb->s_magic = AFS_VFSMAGIC;
107 sb->s_op = &afs_sops; /* Super block (vfs) ops */
108 /* used for inodes backing_dev_info field, also */
109 afs_backing_dev_info = osi_Alloc(sizeof(struct backing_dev_info));
110 #if defined(HAVE_BDI_INIT)
111 bdi_init(afs_backing_dev_info);
113 afs_backing_dev_info->name = "openafs";
114 afs_backing_dev_info->ra_pages = 32;
115 #if defined (STRUCT_SUPER_BLOCK_HAS_S_BDI)
116 sb->s_bdi = afs_backing_dev_info;
117 /* The name specified here will appear in the flushing thread name - flush-afs */
118 bdi_register(afs_backing_dev_info, NULL, "afs");
120 #if !defined(AFS_NONFSTRANS)
121 sb->s_export_op = &afs_export_ops;
123 #if defined(MAX_NON_LFS)
124 #ifdef AFS_64BIT_CLIENT
125 #if !defined(MAX_LFS_FILESIZE)
126 #if BITS_PER_LONG==32
127 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
128 #elif BITS_PER_LONG==64
129 #define MAX_LFS_FILESIZE 0x7fffffffffffffff
132 sb->s_maxbytes = MAX_LFS_FILESIZE;
134 sb->s_maxbytes = MAX_NON_LFS;
139 afs_globalVFS = NULL;
140 osi_linux_free_inode_pages();
141 module_put(THIS_MODULE);
145 return code ? -EINVAL : 0;
149 /* afs_root - stat the root of the file system. AFS global held on entry. */
151 afs_root(struct super_block *afsp)
153 register afs_int32 code = 0;
154 struct vrequest treq;
155 register struct vcache *tvp = 0;
157 AFS_STATCNT(afs_root);
158 if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
161 cred_t *credp = crref();
164 afs_PutVCache(afs_globalVp);
168 if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
169 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
171 struct inode *ip = AFSTOV(tvp);
174 afs_getattr(tvp, &vattr, credp);
175 afs_fill_inode(ip, &vattr);
177 /* setup super_block and mount point inode. */
179 afsp->s_root = d_alloc_root(ip);
180 afsp->s_root->d_op = &afs_dentry_operations;
187 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
188 ICL_TYPE_INT32, code);
192 /* super_operations */
195 * Linux version of setattr call. What to change is in the iattr struct.
196 * We need to set bits in both the Linux inode as well as the vcache.
199 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
202 cred_t *credp = crref();
203 struct inode *ip = dp->d_inode;
207 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
211 code = afs_setattr(VTOAFS(ip), &vattr, credp);
213 afs_getattr(VTOAFS(ip), &vattr, credp);
214 vattr2inode(ip, &vattr);
223 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
224 static afs_kmem_cache_t *afs_inode_cachep;
226 static struct inode *
227 afs_alloc_inode(struct super_block *sb)
231 vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, KALLOC_TYPE);
239 afs_destroy_inode(struct inode *inode)
241 kmem_cache_free(afs_inode_cachep, inode);
245 init_once(void * foo)
247 struct vcache *vcp = (struct vcache *) foo;
249 inode_init_once(AFSTOV(vcp));
253 afs_init_inodecache(void)
255 #if defined(KMEM_CACHE_TAKES_DTOR)
256 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
257 sizeof(struct vcache), 0,
258 SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT, init_once_func, NULL);
260 afs_inode_cachep = kmem_cache_create("afs_inode_cache",
261 sizeof(struct vcache), 0,
262 SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT, init_once_func);
264 if (afs_inode_cachep == NULL)
270 afs_destroy_inodecache(void)
272 if (afs_inode_cachep)
273 (void) kmem_cache_destroy(afs_inode_cachep);
277 afs_init_inodecache(void)
283 afs_destroy_inodecache(void)
290 afs_clear_inode(struct inode *ip)
292 struct vcache *vcp = VTOAFS(ip);
294 if (vcp->vlruq.prev || vcp->vlruq.next)
295 osi_Panic("inode freed while on LRU");
297 osi_Panic("inode freed while still hashed");
299 #if !defined(STRUCT_SUPER_HAS_ALLOC_INODE)
300 afs_osi_Free(ip->u.generic_ip, sizeof(struct vcache));
305 * Called from unmount to release super_block. */
307 afs_put_super(struct super_block *sbp)
310 AFS_STATCNT(afs_unmount);
315 osi_linux_free_inode_pages(); /* invalidate and release remaining AFS inodes. */
317 mntput(afs_cacheMnt);
319 osi_linux_verify_alloced_memory();
320 #if defined(HAVE_BDI_INIT)
321 bdi_destroy(afs_backing_dev_info);
323 osi_Free(afs_backing_dev_info, sizeof(struct backing_dev_info));
327 module_put(THIS_MODULE);
332 * statp is in user space, so we need to cobble together a statfs, then
336 #if defined(STATFS_TAKES_DENTRY)
337 afs_statfs(struct dentry *dentry, struct kstatfs *statp)
339 afs_statfs(struct super_block *sbp, struct kstatfs *statp)
342 memset(statp, 0, sizeof(*statp));
344 AFS_STATCNT(afs_statfs);
346 /* hardcode in case that which is giveth is taken away */
347 statp->f_type = 0x5346414F;
348 #if defined(STATFS_TAKES_DENTRY)
349 statp->f_bsize = dentry->d_sb->s_blocksize;
351 statp->f_bsize = sbp->s_blocksize;
353 statp->f_blocks = statp->f_bfree = statp->f_bavail = statp->f_files =
354 statp->f_ffree = 9000000;
355 statp->f_fsid.val[0] = AFS_VFSMAGIC;
356 statp->f_fsid.val[1] = AFS_VFSFSID;
357 statp->f_namelen = 256;
362 struct super_operations afs_sops = {
363 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
364 .alloc_inode = afs_alloc_inode,
365 .destroy_inode = afs_destroy_inode,
367 .clear_inode = afs_clear_inode,
368 .put_super = afs_put_super,
369 .statfs = afs_statfs,
372 /************** Support routines ************************/
375 * Set iattr data into vattr. Assume vattr cleared before call.
378 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
380 vattrp->va_mask = iattrp->ia_valid;
381 if (iattrp->ia_valid & ATTR_MODE)
382 vattrp->va_mode = iattrp->ia_mode;
383 if (iattrp->ia_valid & ATTR_UID)
384 vattrp->va_uid = iattrp->ia_uid;
385 if (iattrp->ia_valid & ATTR_GID)
386 vattrp->va_gid = iattrp->ia_gid;
387 if (iattrp->ia_valid & ATTR_SIZE)
388 vattrp->va_size = iattrp->ia_size;
389 if (iattrp->ia_valid & ATTR_ATIME) {
390 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
391 vattrp->va_atime.tv_usec = 0;
393 if (iattrp->ia_valid & ATTR_MTIME) {
394 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
395 vattrp->va_mtime.tv_usec = 0;
397 if (iattrp->ia_valid & ATTR_CTIME) {
398 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
399 vattrp->va_ctime.tv_usec = 0;
404 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
407 vattr2inode(struct inode *ip, struct vattr *vp)
409 ip->i_ino = vp->va_nodeid;
410 ip->i_nlink = vp->va_nlink;
411 ip->i_blocks = vp->va_blocks;
412 #ifdef STRUCT_INODE_HAS_I_BLKBITS
413 ip->i_blkbits = AFS_BLKBITS;
415 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
416 ip->i_blksize = vp->va_blocksize;
418 ip->i_rdev = vp->va_rdev;
419 ip->i_mode = vp->va_mode;
420 ip->i_uid = vp->va_uid;
421 ip->i_gid = vp->va_gid;
422 i_size_write(ip, vp->va_size);
423 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
424 ip->i_atime.tv_nsec = 0;
425 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
426 /* Set the mtime nanoseconds to the sysname generation number.
427 * This convinces NFS clients that all directories have changed
428 * any time the sysname list changes.
430 ip->i_mtime.tv_nsec = afs_sysnamegen;
431 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
432 ip->i_ctime.tv_nsec = 0;
435 /* osi_linux_free_inode_pages
437 * Free all vnodes remaining in the afs hash. Must be done before
438 * shutting down afs and freeing all memory.
441 osi_linux_free_inode_pages(void)
444 struct vcache *tvc, *nvc;
445 extern struct vcache *afs_vhashT[VCSIZE];
447 for (i = 0; i < VCSIZE; i++) {
448 for (tvc = afs_vhashT[i]; tvc; ) {
452 if (afs_FlushVCache(tvc, &slept)) /* slept always 0 for linux? */
453 printf("Failed to invalidate all pages on inode 0x%p\n", tvc);