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 #include "afs/sysincludes.h"
22 #include "afsincludes.h"
23 #include "afs/afs_stats.h"
24 #if !defined(AFS_LINUX26_ENV)
27 #if defined(AFS_LINUX24_ENV)
28 #include "h/smp_lock.h"
31 #define __NO_VERSION__ /* don't define kernel_version in module.h */
32 #include <linux/module.h>
35 struct vcache *afs_globalVp = 0;
36 struct vfs *afs_globalVFS = 0;
37 #if defined(AFS_LINUX24_ENV)
38 struct nameidata afs_cacheNd;
40 int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */
42 extern struct super_operations afs_sops;
43 extern afs_rwlock_t afs_xvcache;
44 extern struct afs_q VLRU;
46 extern struct dentry_operations afs_dentry_operations;
48 /* Forward declarations */
49 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
50 static void update_inode_cache(struct inode *ip, struct vattr *vp);
51 static int afs_root(struct super_block *afsp);
52 struct super_block *afs_read_super(struct super_block *sb, void *data, int silent);
53 int afs_fill_super(struct super_block *sb, void *data, int silent);
54 static struct super_block *afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data);
55 void put_inode_on_dummy_list(struct inode *ip);
58 * VFS entry for Linux - installed in init_module
59 * Linux mounts file systems by:
60 * 1) register_filesystem(&afs_file_system) - done in init_module
61 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
62 * We are expected to setup the super_block. See afs_read_super.
64 #if defined(AFS_LINUX26_ENV)
65 struct backing_dev_info afs_backing_dev_info = {
66 .ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE,
70 struct file_system_type afs_fs_type = {
74 .kill_sb = kill_anon_super,
75 .fs_flags = FS_BINARY_MOUNTDATA,
77 #elif defined(AFS_LINUX24_ENV)
78 DECLARE_FSTYPE(afs_fs_type, "afs", afs_read_super, 0);
80 struct file_system_type afs_fs_type = {
81 "afs", /* name - used by mount operation. */
82 0, /* requires_dev - no for network filesystems. mount() will
83 * pass us an "unnamed" device. */
84 afs_read_super, /* wrapper to afs_mount */
85 NULL /* pointer to next file_system_type once registered. */
90 * read the "super block" for AFS - roughly eguivalent to struct vfs.
91 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
93 #if defined(AFS_LINUX26_ENV)
94 static struct super_block *
95 afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
97 return get_sb_nodev(fs_type, flags, data, afs_fill_super);
101 afs_fill_super(struct super_block *sb, void *data, int silent)
104 afs_read_super(struct super_block *sb, void *data, int silent)
110 if (afs_was_mounted) {
112 ("You must reload the AFS kernel extensions before remounting AFS.\n");
114 #if defined(AFS_LINUX26_ENV)
122 /* Set basics of super_block */
123 #if !defined(AFS_LINUX24_ENV)
126 #if defined(AFS_LINUX26_ENV)
127 __module_get(THIS_MODULE);
133 sb->s_blocksize = 1024;
134 sb->s_blocksize_bits = 10;
135 sb->s_magic = AFS_VFSMAGIC;
136 sb->s_op = &afs_sops; /* Super block (vfs) ops */
137 #if defined(MAX_NON_LFS)
138 sb->s_maxbytes = MAX_NON_LFS;
142 afs_globalVFS = NULL;
143 #if defined(AFS_LINUX26_ENV)
144 module_put(THIS_MODULE);
150 #if !defined(AFS_LINUX24_ENV)
155 #if defined(AFS_LINUX26_ENV)
156 return code ? -EINVAL : 0;
158 return code ? NULL : sb;
163 /* afs_root - stat the root of the file system. AFS global held on entry. */
165 afs_root(struct super_block *afsp)
167 register afs_int32 code = 0;
168 struct vrequest treq;
169 register struct vcache *tvp = 0;
171 AFS_STATCNT(afs_root);
172 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
175 cred_t *credp = crref();
178 afs_PutVCache(afs_globalVp);
182 if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
183 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
185 extern struct inode_operations afs_dir_iops;
186 #if defined(AFS_LINUX24_ENV)
187 extern struct file_operations afs_dir_fops;
190 /* "/afs" is a directory, reset inode ops accordingly. */
191 AFSTOV(tvp)->v_op = &afs_dir_iops;
192 #if defined(AFS_LINUX24_ENV)
193 AFSTOV(tvp)->v_fop = &afs_dir_fops;
196 /* setup super_block and mount point inode. */
198 #if defined(AFS_LINUX24_ENV)
199 afsp->s_root = d_alloc_root(AFSTOI(tvp));
201 afsp->s_root = d_alloc_root(AFSTOI(tvp), NULL);
203 afsp->s_root->d_op = &afs_dentry_operations;
210 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
211 ICL_TYPE_INT32, code);
215 /* super_operations */
218 * Linux version of setattr call. What to change is in the iattr struct.
219 * We need to set bits in both the Linux inode as well as the vcache.
222 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
226 cred_t *credp = crref();
227 struct inode *ip = dp->d_inode;
230 #if defined(AFS_LINUX26_ENV)
234 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
235 update_inode_cache(ip, &vattr);
236 code = afs_setattr(ITOAFS(ip), &vattr, credp);
237 afs_CopyOutAttrs(ITOAFS(ip), &vattr);
238 /* Note that the inode may still not have all the correct info. But at
239 * least we've got the newest version of what was supposed to be set.
242 #if defined(AFS_LINUX26_ENV)
251 /* This list is simply used to initialize the i_list member of the
252 * linux inode. This stops linux inode syncing code from choking on our
255 static LIST_HEAD(dummy_inode_list);
258 /* This is included for documentation only. */
260 * Used to flush in core inode to disk. We don't need to do this. Top level
261 * write_inode() routine will clear i_dirt. If this routine is in the table,
262 * it's expected to do the cleaning and clear i_dirt.
264 * 9/24/99: This is what we thought until we discovered msync() does end up calling
265 * this function to sync a single inode to disk. msync() only flushes selective
266 * pages to disk. So it needs an inode syncing function to update metadata when it
267 * has synced some pages of a file to disk.
269 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
271 afs_write_inode(struct inode *ip, int unused)
274 afs_write_inode(struct inode *ip)
277 list_del(&ip->i_list);
278 /* and put it back on our dummy list. */
279 put_inode_on_dummy_list(ip);
281 /* for now we don't actually update the metadata during msync. This
282 * is just to keep linux happy. */
287 afs_destroy_inode(struct inode *ip)
294 * called from iput when count goes to zero. Linux version of inactive.
295 * For Linux 2.2, this funcionality has moved to the delete inode super op.
296 * If we use the common inode pool, we'll need to set i_nlink to 0 here.
297 * That will trigger the call to delete routine.
301 afs_delete_inode(struct inode *ip)
303 struct vcache *vp = ITOAFS(ip);
305 #ifdef AFS_LINUX26_ENV
306 put_inode_on_dummy_list(ip);
316 * Called from unmount to release super_block. */
318 afs_put_super(struct super_block *sbp)
320 extern int afs_afs_cold_shutdown;
325 AFS_STATCNT(afs_unmount);
327 #if !defined(AFS_LINUX26_ENV)
337 #if defined(AFS_LINUX24_ENV)
338 path_release(&afs_cacheNd);
341 osi_linux_verify_alloced_memory();
347 #if defined(AFS_LINUX26_ENV)
348 module_put(THIS_MODULE);
357 * statp is in user space, so we need to cobble together a statfs, then
360 #if defined(AFS_LINUX26_ENV)
362 afs_statfs(struct super_block *sbp, struct kstatfs *statp)
363 #elif defined(AFS_LINUX24_ENV)
365 afs_statfs(struct super_block *sbp, struct statfs *statp)
368 afs_statfs(struct super_block *sbp, struct statfs *__statp, int size)
371 #if !defined(AFS_LINUX24_ENV)
374 if (size < sizeof(struct statfs))
377 memset(&stat, 0, size);
380 memset(statp, 0, sizeof(*statp));
383 AFS_STATCNT(afs_statfs);
385 statp->f_type = 0; /* Can we get a real type sometime? */
386 statp->f_bsize = sbp->s_blocksize;
387 statp->f_blocks = statp->f_bfree = statp->f_bavail = statp->f_files =
388 statp->f_ffree = 9000000;
389 statp->f_fsid.val[0] = AFS_VFSMAGIC;
390 statp->f_fsid.val[1] = AFS_VFSFSID;
391 statp->f_namelen = 256;
393 #if !defined(AFS_LINUX24_ENV)
394 memcpy_tofs(__statp, &stat, size);
400 afs_umount_begin(struct super_block *sbp)
402 afs_shuttingdown = 1;
405 struct super_operations afs_sops = {
406 #if defined(AFS_LINUX26_ENV)
407 .drop_inode = generic_delete_inode,
408 .destroy_inode = afs_destroy_inode,
410 .delete_inode = afs_delete_inode,
411 .write_inode = afs_write_inode,
412 .put_super = afs_put_super,
413 .statfs = afs_statfs,
414 .umount_begin = afs_umount_begin
415 #if !defined(AFS_LINUX24_ENV)
416 .notify_change = afs_notify_change,
420 /************** Support routines ************************/
423 * Set iattr data into vattr. Assume vattr cleared before call.
426 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
428 vattrp->va_mask = iattrp->ia_valid;
429 if (iattrp->ia_valid & ATTR_MODE)
430 vattrp->va_mode = iattrp->ia_mode;
431 if (iattrp->ia_valid & ATTR_UID)
432 vattrp->va_uid = iattrp->ia_uid;
433 if (iattrp->ia_valid & ATTR_GID)
434 vattrp->va_gid = iattrp->ia_gid;
435 if (iattrp->ia_valid & ATTR_SIZE)
436 vattrp->va_size = iattrp->ia_size;
437 if (iattrp->ia_valid & ATTR_ATIME) {
438 #if defined(AFS_LINUX26_ENV)
439 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
441 vattrp->va_atime.tv_sec = iattrp->ia_atime;
443 vattrp->va_atime.tv_usec = 0;
445 if (iattrp->ia_valid & ATTR_MTIME) {
446 #if defined(AFS_LINUX26_ENV)
447 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
449 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
451 vattrp->va_mtime.tv_usec = 0;
453 if (iattrp->ia_valid & ATTR_CTIME) {
454 #if defined(AFS_LINUX26_ENV)
455 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
457 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
459 vattrp->va_ctime.tv_usec = 0;
463 /* update_inode_cache
464 * Update inode with info from vattr struct. Use va_mask to determine what
468 update_inode_cache(struct inode *ip, struct vattr *vp)
470 if (vp->va_mask & ATTR_MODE)
471 ip->i_mode = vp->va_mode;
472 if (vp->va_mask & ATTR_UID)
473 ip->i_uid = vp->va_uid;
474 if (vp->va_mask & ATTR_GID)
475 ip->i_gid = vp->va_gid;
476 if (vp->va_mask & ATTR_SIZE)
477 ip->i_size = vp->va_size;
478 if (vp->va_mask & ATTR_ATIME)
479 #if defined(AFS_LINUX26_ENV)
480 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
482 ip->i_atime = vp->va_atime.tv_sec;
484 if (vp->va_mask & ATTR_MTIME)
485 #if defined(AFS_LINUX26_ENV)
486 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
488 ip->i_mtime = vp->va_mtime.tv_sec;
490 if (vp->va_mask & ATTR_CTIME)
491 #if defined(AFS_LINUX26_ENV)
492 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
494 ip->i_ctime = vp->va_ctime.tv_sec;
499 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
502 vattr2inode(struct inode *ip, struct vattr *vp)
504 ip->i_ino = vp->va_nodeid;
505 ip->i_nlink = vp->va_nlink;
506 ip->i_blocks = vp->va_blocks;
507 ip->i_blksize = vp->va_blocksize;
508 ip->i_rdev = vp->va_rdev;
509 ip->i_mode = vp->va_mode;
510 ip->i_uid = vp->va_uid;
511 ip->i_gid = vp->va_gid;
512 ip->i_size = vp->va_size;
513 #if defined(AFS_LINUX26_ENV)
514 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
515 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
516 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
518 ip->i_atime = vp->va_atime.tv_sec;
519 ip->i_mtime = vp->va_mtime.tv_sec;
520 ip->i_ctime = vp->va_ctime.tv_sec;
524 /* Put this afs inode on our own dummy list. Linux expects to see inodes
525 * nicely strung up in lists. Linux inode syncing code chokes on our inodes if
526 * they're not on any lists.
529 put_inode_on_dummy_list(struct inode *ip)
531 /* Initialize list. See explanation above. */
532 list_add(&ip->i_list, &dummy_inode_list);
535 /* And yet another routine to update the inode cache - called from ProcessFS */
537 vcache2inode(struct vcache *avc)
542 afs_CopyOutAttrs(avc, &vattr); /* calls vattr2inode */
545 /* Yet another one for fakestat'ed mountpoints */
547 vcache2fakeinode(struct vcache *rootvp, struct vcache *mpvp)
552 afs_CopyOutAttrs(rootvp, &vattr);
553 vattr2inode(AFSTOI(mpvp), &vattr);