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_version in module.h */
30 #include <linux/module.h>
33 struct vcache *afs_globalVp = 0;
34 struct vfs *afs_globalVFS = 0;
35 #if defined(AFS_LINUX24_ENV)
36 struct nameidata afs_cacheNd;
38 int afs_was_mounted = 0; /* Used to force reload if mount/unmount/mount */
40 extern struct super_operations afs_sops;
41 extern afs_rwlock_t afs_xvcache;
42 extern struct afs_q VLRU;
44 extern struct dentry_operations afs_dentry_operations;
46 /* Forward declarations */
47 static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
48 static void update_inode_cache(struct inode *ip, struct vattr *vp);
49 static int afs_root(struct super_block *afsp);
50 struct super_block *afs_read_super(struct super_block *sb, void *data,
52 void put_inode_on_dummy_list(struct inode *ip);
55 * VFS entry for Linux - installed in init_module
56 * Linux mounts file systems by:
57 * 1) register_filesystem(&afs_file_system) - done in init_module
58 * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
59 * We are expected to setup the super_block. See afs_read_super.
61 #if defined(AFS_LINUX24_ENV)
62 DECLARE_FSTYPE(afs_file_system, "afs", afs_read_super, 0);
64 struct file_system_type afs_file_system = {
65 "afs", /* name - used by mount operation. */
66 0, /* requires_dev - no for network filesystems. mount() will
67 * pass us an "unnamed" device. */
68 afs_read_super, /* wrapper to afs_mount */
69 NULL /* pointer to next file_system_type once registered. */
74 * read the "super block" for AFS - roughly eguivalent to struct vfs.
75 * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
78 afs_read_super(struct super_block *sb, void *data, int silent)
83 if (afs_was_mounted) {
85 ("You must reload the AFS kernel extensions before remounting AFS.\n");
91 /* Set basics of super_block */
92 #if !defined(AFS_LINUX24_ENV)
98 sb->s_blocksize = 1024;
99 sb->s_blocksize_bits = 10;
100 sb->s_magic = AFS_VFSMAGIC;
101 sb->s_op = &afs_sops; /* Super block (vfs) ops */
102 #if defined(MAX_NON_LFS)
103 sb->s_maxbytes = MAX_NON_LFS;
109 #if !defined(AFS_LINUX24_ENV)
114 return code ? NULL : sb;
118 /* afs_root - stat the root of the file system. AFS global held on entry. */
120 afs_root(struct super_block *afsp)
122 register afs_int32 code = 0;
123 struct vrequest treq;
124 register struct vcache *tvp = 0;
126 AFS_STATCNT(afs_root);
127 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
130 cred_t *credp = crref();
133 afs_PutVCache(afs_globalVp);
137 if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
138 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
140 extern struct inode_operations afs_dir_iops;
141 #if defined(AFS_LINUX24_ENV)
142 extern struct file_operations afs_dir_fops;
145 /* "/afs" is a directory, reset inode ops accordingly. */
146 AFSTOV(tvp)->v_op = &afs_dir_iops;
147 #if defined(AFS_LINUX24_ENV)
148 AFSTOV(tvp)->v_fop = &afs_dir_fops;
151 /* setup super_block and mount point inode. */
153 #if defined(AFS_LINUX24_ENV)
154 afsp->s_root = d_alloc_root(AFSTOI(tvp));
156 afsp->s_root = d_alloc_root(AFSTOI(tvp), NULL);
158 afsp->s_root->d_op = &afs_dentry_operations;
165 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
166 ICL_TYPE_INT32, code);
170 /* super_operations */
173 * Linux version of setattr call. What to change is in the iattr struct.
174 * We need to set bits in both the Linux inode as well as the vcache.
177 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
181 cred_t *credp = crref();
182 struct inode *ip = dp->d_inode;
186 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
187 update_inode_cache(ip, &vattr);
188 code = afs_setattr(ITOAFS(ip), &vattr, credp);
189 afs_CopyOutAttrs(ITOAFS(ip), &vattr);
190 /* Note that the inode may still not have all the correct info. But at
191 * least we've got the newest version of what was supposed to be set.
200 /* This list is simply used to initialize the i_list member of the
201 * linux inode. This stops linux inode syncing code from choking on our
204 static LIST_HEAD(dummy_inode_list);
207 /* This is included for documentation only. */
209 * Used to flush in core inode to disk. We don't need to do this. Top level
210 * write_inode() routine will clear i_dirt. If this routine is in the table,
211 * it's expected to do the cleaning and clear i_dirt.
213 * 9/24/99: This is what we thought until we discovered msync() does end up calling
214 * this function to sync a single inode to disk. msync() only flushes selective
215 * pages to disk. So it needs an inode syncing function to update metadata when it
216 * has synced some pages of a file to disk.
218 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
220 afs_write_inode(struct inode *ip, int unused)
223 afs_write_inode(struct inode *ip)
226 /* and put it back on our dummy list. */
227 list_del(&ip->i_list);
228 list_add(&ip->i_list, &dummy_inode_list);
230 /* for now we don't actually update the metadata during msync. This
231 * is just to keep linux happy. */
236 * called from iput when count goes to zero. Linux version of inactive.
237 * For Linux 2.2, this funcionality has moved to the delete inode super op.
238 * If we use the common inode pool, we'll need to set i_nlink to 0 here.
239 * That will trigger the call to delete routine.
243 afs_delete_inode(struct inode *ip)
245 struct vcache *vc = ITOAFS(ip);
254 * Called from unmount to release super_block. */
256 afs_put_super(struct super_block *sbp)
258 extern int afs_afs_cold_shutdown;
263 AFS_STATCNT(afs_unmount);
273 #if defined(AFS_LINUX24_ENV)
274 path_release(&afs_cacheNd);
277 osi_linux_verify_alloced_memory();
289 * statp is in user space, so we need to cobble together a statfs, then
292 #if defined(AFS_LINUX24_ENV)
294 afs_statfs(struct super_block *sbp, struct statfs *statp)
297 afs_statfs(struct super_block *sbp, struct statfs *statp, int size)
302 AFS_STATCNT(afs_statfs);
304 #if !defined(AFS_LINUX24_ENV)
305 if (size < sizeof(struct statfs))
308 memset(&stat, 0, size);
310 stat.f_type = 0; /* Can we get a real type sometime? */
311 stat.f_bsize = sbp->s_blocksize;
312 stat.f_blocks = stat.f_bfree = stat.f_bavail = stat.f_files =
313 stat.f_ffree = 9000000;
314 stat.f_fsid.val[0] = AFS_VFSMAGIC;
315 stat.f_fsid.val[1] = AFS_VFSFSID;
316 stat.f_namelen = 256;
318 #if defined(AFS_LINUX24_ENV)
321 memcpy_tofs(statp, &stat, size);
328 afs_umount_begin(struct super_block *sbp)
330 afs_shuttingdown = 1;
333 struct super_operations afs_sops = {
334 .write_inode = afs_write_inode,
335 .delete_inode = afs_delete_inode,
336 .put_super = afs_put_super,
337 .statfs = afs_statfs,
338 .umount_begin = afs_umount_begin
339 #if !defined(AFS_LINUX24_ENV)
340 .notifY_change = afs_notify_change,
344 /************** Support routines ************************/
347 * Set iattr data into vattr. Assume vattr cleared before call.
350 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
352 vattrp->va_mask = iattrp->ia_valid;
353 if (iattrp->ia_valid & ATTR_MODE)
354 vattrp->va_mode = iattrp->ia_mode;
355 if (iattrp->ia_valid & ATTR_UID)
356 vattrp->va_uid = iattrp->ia_uid;
357 if (iattrp->ia_valid & ATTR_GID)
358 vattrp->va_gid = iattrp->ia_gid;
359 if (iattrp->ia_valid & ATTR_SIZE)
360 vattrp->va_size = iattrp->ia_size;
361 if (iattrp->ia_valid & ATTR_ATIME) {
362 vattrp->va_atime.tv_sec = iattrp->ia_atime;
363 vattrp->va_atime.tv_usec = 0;
365 if (iattrp->ia_valid & ATTR_MTIME) {
366 vattrp->va_mtime.tv_sec = iattrp->ia_mtime;
367 vattrp->va_mtime.tv_usec = 0;
369 if (iattrp->ia_valid & ATTR_CTIME) {
370 vattrp->va_ctime.tv_sec = iattrp->ia_ctime;
371 vattrp->va_ctime.tv_usec = 0;
375 /* update_inode_cache
376 * Update inode with info from vattr struct. Use va_mask to determine what
380 update_inode_cache(struct inode *ip, struct vattr *vp)
382 if (vp->va_mask & ATTR_MODE)
383 ip->i_mode = vp->va_mode;
384 if (vp->va_mask & ATTR_UID)
385 ip->i_uid = vp->va_uid;
386 if (vp->va_mask & ATTR_GID)
387 ip->i_gid = vp->va_gid;
388 if (vp->va_mask & ATTR_SIZE)
389 ip->i_size = vp->va_size;
390 if (vp->va_mask & ATTR_ATIME)
391 ip->i_atime = vp->va_atime.tv_sec;
392 if (vp->va_mask & ATTR_MTIME)
393 ip->i_mtime = vp->va_mtime.tv_sec;
394 if (vp->va_mask & ATTR_CTIME)
395 ip->i_ctime = vp->va_ctime.tv_sec;
399 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
402 vattr2inode(struct inode *ip, struct vattr *vp)
404 ip->i_ino = vp->va_nodeid;
405 ip->i_nlink = vp->va_nlink;
406 ip->i_blocks = vp->va_blocks;
407 ip->i_blksize = vp->va_blocksize;
408 ip->i_rdev = vp->va_rdev;
409 ip->i_mode = vp->va_mode;
410 ip->i_uid = vp->va_uid;
411 ip->i_gid = vp->va_gid;
412 ip->i_size = vp->va_size;
413 ip->i_atime = vp->va_atime.tv_sec;
414 ip->i_mtime = vp->va_mtime.tv_sec;
415 ip->i_ctime = vp->va_ctime.tv_sec;
417 /* we should put our inodes on a dummy inode list to keep linux happy. */
418 if (!ip->i_list.prev && !ip->i_list.next) {
419 /* this might be bad as we are reaching under the covers of the
420 * list structure but we want to avoid putting the inode
421 * on the list more than once. */
422 put_inode_on_dummy_list(ip);
426 /* Put this afs inode on our own dummy list. Linux expects to see inodes
427 * nicely strung up in lists. Linux inode syncing code chokes on our inodes if
428 * they're not on any lists.
431 put_inode_on_dummy_list(struct inode *ip)
433 /* Initialize list. See explanation above. */
434 list_add(&ip->i_list, &dummy_inode_list);
437 /* And yet another routine to update the inode cache - called from ProcessFS */
439 vcache2inode(struct vcache *avc)
444 afs_CopyOutAttrs(avc, &vattr); /* calls vattr2inode */
447 /* Yet another one for fakestat'ed mountpoints */
449 vcache2fakeinode(struct vcache *rootvp, struct vcache *mpvp)
454 afs_CopyOutAttrs(rootvp, &vattr);
455 vattr2inode(AFSTOI(mpvp), &vattr);