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"
25 #if defined(AFS_LINUX24_ENV)
26 #include "h/smp_lock.h"
29 #define __NO_VERSION__ /* don't define kernel_verion in module.h */
30 #include <linux/module.h>
33 struct vcache *afs_globalVp = 0;
34 struct vfs *afs_globalVFS = 0;
35 struct nameidata afs_cacheNd;
36 int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */
38 extern struct super_operations afs_sops;
39 extern afs_rwlock_t afs_xvcache;
40 extern struct afs_q VLRU;
42 extern struct dentry_operations afs_dentry_operations;
44 /* Forward declarations */
45 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
46 static void update_inode_cache(struct inode *ip, struct vattr *vp);
47 static int afs_root(struct super_block *afsp);
48 struct super_block *afs_read_super(struct super_block *sb, void *data,
50 void put_inode_on_dummy_list(struct inode *ip);
53 * VFS entry for Linux - installed in init_module
54 * Linux mounts file systems by:
55 * 1) register_filesystem(&afs_file_system) - done in init_module
56 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
57 * We are expected to setup the super_block. See afs_read_super.
59 #if defined(AFS_LINUX24_ENV)
60 DECLARE_FSTYPE(afs_file_system, "afs", afs_read_super, 0);
62 struct file_system_type afs_file_system = {
63 "afs", /* name - used by mount operation. */
64 0, /* requires_dev - no for network filesystems. mount() will
65 * pass us an "unnamed" device. */
66 afs_read_super, /* wrapper to afs_mount */
67 NULL /* pointer to next file_system_type once registered. */
72 * read the "super block" for AFS - roughly eguivalent to struct vfs.
73 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
76 afs_read_super(struct super_block *sb, void *data, int silent)
81 if (afs_was_mounted) {
83 ("You must reload the AFS kernel extensions before remounting AFS.\n");
89 /* Set basics of super_block */
90 #if !defined(AFS_LINUX24_ENV)
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 sb->s_maxbytes = MAX_NON_LFS;
107 #if !defined(AFS_LINUX24_ENV)
112 return code ? NULL : sb;
116 /* afs_root - stat the root of the file system. AFS global held on entry. */
118 afs_root(struct super_block *afsp)
120 register afs_int32 code = 0;
121 struct vrequest treq;
122 register struct vcache *tvp = 0;
124 AFS_STATCNT(afs_root);
125 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
128 cred_t *credp = crref();
131 afs_PutVCache(afs_globalVp);
135 if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
136 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
138 extern struct inode_operations afs_dir_iops;
139 #if defined(AFS_LINUX24_ENV)
140 extern struct file_operations afs_dir_fops;
143 /* "/afs" is a directory, reset inode ops accordingly. */
144 AFSTOV(tvp)->v_op = &afs_dir_iops;
145 #if defined(AFS_LINUX24_ENV)
146 AFSTOV(tvp)->v_fop = &afs_dir_fops;
149 /* setup super_block and mount point inode. */
151 #if defined(AFS_LINUX24_ENV)
152 afsp->s_root = d_alloc_root(AFSTOI(tvp));
154 afsp->s_root = d_alloc_root(AFSTOI(tvp), NULL);
156 afsp->s_root->d_op = &afs_dentry_operations;
163 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
164 ICL_TYPE_INT32, code);
168 /* super_operations */
171 * called via iget to read in the inode. The passed in inode has i_ino, i_dev
172 * and i_sb setup on input. Linux file systems use this to get super block
173 * inode information, so we don't really care what happens here.
174 * For Linux 2.2, we'll be called if we participate in the inode pool.
177 afs_read_inode(struct inode *ip)
179 /* I don't think we ever get called with this. So print if we do. */
180 printf("afs_read_inode: Called for inode %d\n", ip->i_ino);
185 * Linux version of setattr call. What to change is in the iattr struct.
186 * We need to set bits in both the Linux inode as well as the vcache.
189 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
193 cred_t *credp = crref();
194 struct inode *ip = dp->d_inode;
198 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
199 update_inode_cache(ip, &vattr);
200 code = afs_setattr(ITOAFS(ip), &vattr, credp);
201 afs_CopyOutAttrs(ITOAFS(ip), &vattr);
202 /* Note that the inode may still not have all the correct info. But at
203 * least we've got the newest version of what was supposed to be set.
212 /* This list is simply used to initialize the i_list member of the
213 * linux inode. This stops linux inode syncing code from choking on our
216 static LIST_HEAD(dummy_inode_list);
219 /* This is included for documentation only. */
221 * Used to flush in core inode to disk. We don't need to do this. Top level
222 * write_inode() routine will clear i_dirt. If this routine is in the table,
223 * it's expected to do the cleaning and clear i_dirt.
225 * 9/24/99: This is what we thought until we discovered msync() does end up calling
226 * this function to sync a single inode to disk. msync() only flushes selective
227 * pages to disk. So it needs an inode syncing function to update metadata when it
228 * has synced some pages of a file to disk.
230 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
232 afs_write_inode(struct inode *ip, int unused)
235 afs_write_inode(struct inode *ip)
238 /* and put it back on our dummy list. */
239 list_del(&ip->i_list);
240 list_add(&ip->i_list, &dummy_inode_list);
242 /* for now we don't actually update the metadata during msync. This
243 * is just to keep linux happy. */
248 * called from iput when count goes to zero. Linux version of inactive.
249 * For Linux 2.2, this funcionality has moved to the delete inode super op.
250 * If we use the common inode pool, we'll need to set i_nlink to 0 here.
251 * That will trigger the call to delete routine.
255 afs_delete_inode(struct inode *ip)
257 struct vcache *vc = ITOAFS(ip);
266 * Called from unmount to release super_block. */
268 afs_put_super(struct super_block *sbp)
270 extern int afs_afs_cold_shutdown;
275 AFS_STATCNT(afs_unmount);
285 path_release(&afs_cacheNd);
287 osi_linux_verify_alloced_memory();
299 * Not required since we don't write out a super block. */
301 afs_write_super(struct super_block *sbp)
306 * Used to remount filesystems with different flags. Not relevant for AFS.
309 afs_remount_fs(struct super_block *sbp, int *, char *)
316 * statp is in user space, so we need to cobble together a statfs, then
319 #if defined(AFS_LINUX24_ENV)
321 afs_statfs(struct super_block *sbp, struct statfs *statp)
324 afs_statfs(struct super_block *sbp, struct statfs *statp, int size)
329 AFS_STATCNT(afs_statfs);
331 #if !defined(AFS_LINUX24_ENV)
332 if (size < sizeof(struct statfs))
335 memset(&stat, 0, size);
337 stat.f_type = 0; /* Can we get a real type sometime? */
338 stat.f_bsize = sbp->s_blocksize;
339 stat.f_blocks = stat.f_bfree = stat.f_bavail = stat.f_files =
340 stat.f_ffree = 9000000;
341 stat.f_fsid.val[0] = AFS_VFSMAGIC;
342 stat.f_fsid.val[1] = AFS_VFSFSID;
343 stat.f_namelen = 256;
345 #if defined(AFS_LINUX24_ENV)
348 memcpy_tofs(statp, &stat, size);
355 afs_umount_begin(struct super_block *sbp)
357 afs_shuttingdown = 1;
360 #if defined(AFS_LINUX24_ENV)
361 struct super_operations afs_sops = {
362 read_inode:afs_read_inode,
363 write_inode:afs_write_inode,
364 delete_inode:afs_delete_inode,
365 put_super:afs_put_super,
367 umount_begin:afs_umount_begin
370 struct super_operations afs_sops = {
372 afs_write_inode, /* afs_write_inode - see doc above. */
373 NULL, /* afs_put_inode */
377 NULL, /* afs_write_super - see doc above */
379 NULL, /* afs_remount_fs - see doc above */
380 NULL, /* afs_clear_inode */
385 /************** Support routines ************************/
388 * Set iattr data into vattr. Assume vattr cleared before call.
391 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
393 vattrp->va_mask = iattrp->ia_valid;
394 if (iattrp->ia_valid & ATTR_MODE)
395 vattrp->va_mode = iattrp->ia_mode;
396 if (iattrp->ia_valid & ATTR_UID)
397 vattrp->va_uid = iattrp->ia_uid;
398 if (iattrp->ia_valid & ATTR_GID)
399 vattrp->va_gid = iattrp->ia_gid;
400 if (iattrp->ia_valid & ATTR_SIZE)
401 vattrp->va_size = iattrp->ia_size;
402 if (iattrp->ia_valid & ATTR_ATIME) {
403 vattrp->va_atime.tv_sec = iattrp->ia_atime;
404 vattrp->va_atime.tv_usec = 0;
406 if (iattrp->ia_valid & ATTR_MTIME) {
407 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
408 vattrp->va_mtime.tv_usec = 0;
410 if (iattrp->ia_valid & ATTR_CTIME) {
411 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
412 vattrp->va_ctime.tv_usec = 0;
416 /* update_inode_cache
417 * Update inode with info from vattr struct. Use va_mask to determine what
421 update_inode_cache(struct inode *ip, struct vattr *vp)
423 if (vp->va_mask & ATTR_MODE)
424 ip->i_mode = vp->va_mode;
425 if (vp->va_mask & ATTR_UID)
426 ip->i_uid = vp->va_uid;
427 if (vp->va_mask & ATTR_GID)
428 ip->i_gid = vp->va_gid;
429 if (vp->va_mask & ATTR_SIZE)
430 ip->i_size = vp->va_size;
431 if (vp->va_mask & ATTR_ATIME)
432 ip->i_atime = vp->va_atime.tv_sec;
433 if (vp->va_mask & ATTR_MTIME)
434 ip->i_mtime = vp->va_mtime.tv_sec;
435 if (vp->va_mask & ATTR_CTIME)
436 ip->i_ctime = vp->va_ctime.tv_sec;
440 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
443 vattr2inode(struct inode *ip, struct vattr *vp)
445 ip->i_ino = vp->va_nodeid;
446 ip->i_nlink = vp->va_nlink;
447 ip->i_blocks = vp->va_blocks;
448 ip->i_blksize = vp->va_blocksize;
449 ip->i_rdev = vp->va_rdev;
450 ip->i_mode = vp->va_mode;
451 ip->i_uid = vp->va_uid;
452 ip->i_gid = vp->va_gid;
453 ip->i_size = vp->va_size;
454 ip->i_atime = vp->va_atime.tv_sec;
455 ip->i_mtime = vp->va_mtime.tv_sec;
456 ip->i_ctime = vp->va_ctime.tv_sec;
458 /* we should put our inodes on a dummy inode list to keep linux happy. */
459 if (!ip->i_list.prev && !ip->i_list.next) {
460 /* this might be bad as we are reaching under the covers of the
461 * list structure but we want to avoid putting the inode
462 * on the list more than once. */
463 put_inode_on_dummy_list(ip);
467 /* Put this afs inode on our own dummy list. Linux expects to see inodes
468 * nicely strung up in lists. Linux inode syncing code chokes on our inodes if
469 * they're not on any lists.
472 put_inode_on_dummy_list(struct inode *ip)
474 /* Initialize list. See explanation above. */
475 list_add(&ip->i_list, &dummy_inode_list);
478 /* And yet another routine to update the inode cache - called from ProcessFS */
480 vcache2inode(struct vcache *avc)
485 afs_CopyOutAttrs(avc, &vattr); /* calls vattr2inode */
488 /* Yet another one for fakestat'ed mountpoints */
490 vcache2fakeinode(struct vcache *rootvp, struct vcache *mpvp)
495 afs_CopyOutAttrs(rootvp, &vattr);
496 vattr2inode(AFSTOI(mpvp), &vattr);