LINUX: Minor osi_vfsop.c cleanup
[openafs.git] / src / afs / LINUX / osi_vfsops.c
index 36a0048..0adfc38 100644 (file)
@@ -21,7 +21,6 @@
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
 #include "afs/afs_stats.h"
-#include <linux/smp_lock.h>
 
 #include "osi_compat.h"
 
@@ -40,34 +39,35 @@ extern struct afs_q VLRU;
 extern struct dentry_operations afs_dentry_operations;
 
 /* Forward declarations */
-static void iattr2vattr(struct vattr *vattrp, struct iattr *iattrp);
 static int afs_root(struct super_block *afsp);
-struct super_block *afs_read_super(struct super_block *sb, void *data, int silent);
-int afs_fill_super(struct super_block *sb, void *data, int silent);
-
-/* afs_file_system
- * VFS entry for Linux - installed in init_module
- * Linux mounts file systems by:
- * 1) register_filesystem(&afs_file_system) - done in init_module
- * 2) Mount call comes to us via do_mount -> read_super -> afs_read_super.
- *    We are expected to setup the super_block. See afs_read_super.
- */
+static int afs_fill_super(struct super_block *sb, void *data, int silent);
 
 
-/* afs_read_super
- * read the "super block" for AFS - roughly eguivalent to struct vfs.
- * dev, covered, s_rd_only, s_dirt, and s_type will be set by read_super.
+/*
+ * afs_mount (2.6.37+) and afs_get_sb (2.6.36-) are the entry
+ * points from the vfs when mounting afs.  The super block
+ * structure is setup in the afs_fill_super callback function.
  */
-#ifdef GET_SB_HAS_STRUCT_VFSMOUNT
+
+#if defined(STRUCT_FILE_SYSTEM_TYPE_HAS_MOUNT)
+static struct dentry *
+afs_mount(struct file_system_type *fs_type, int flags,
+         const char *dev_name, void *data)
+{
+    return mount_nodev(fs_type, flags, data, afs_fill_super);
+}
+#elif defined(GET_SB_HAS_STRUCT_VFSMOUNT)
 static int
 afs_get_sb(struct file_system_type *fs_type, int flags,
-          const char *dev_name, void *data, struct vfsmount *mnt) {
+          const char *dev_name, void *data, struct vfsmount *mnt)
+{
     return get_sb_nodev(fs_type, flags, data, afs_fill_super, mnt);
 }
 #else
-static struct superblock *
+static struct super_block *
 afs_get_sb(struct file_system_type *fs_type, int flags,
-          const char *dev_name, void *data) {
+          const char *dev_name, void *data)
+{
     return get_sb_nodev(fs_type, flags, data, afs_fill_super);
 }
 #endif
@@ -75,17 +75,24 @@ afs_get_sb(struct file_system_type *fs_type, int flags,
 struct file_system_type afs_fs_type = {
     .owner = THIS_MODULE,
     .name = "afs",
+#if defined(STRUCT_FILE_SYSTEM_TYPE_HAS_MOUNT)
+    .mount = afs_mount,
+#else
     .get_sb = afs_get_sb,
+#endif
     .kill_sb = kill_anon_super,
     .fs_flags = FS_BINARY_MOUNTDATA,
 };
 
 struct backing_dev_info *afs_backing_dev_info;
 
-int
+static int
 afs_fill_super(struct super_block *sb, void *data, int silent)
 {
     int code = 0;
+#if defined(HAVE_LINUX_BDI_INIT)
+    int bdi_init_done = 0;
+#endif
 
     AFS_GLOCK();
     if (afs_was_mounted) {
@@ -100,15 +107,33 @@ afs_fill_super(struct super_block *sb, void *data, int silent)
    __module_get(THIS_MODULE);
 
     afs_globalVFS = sb;
+#if defined(SB_NOATIME)
+    sb->s_flags |= SB_NOATIME;
+#else
     sb->s_flags |= MS_NOATIME;
+#endif
     sb->s_blocksize = 1024;
     sb->s_blocksize_bits = 10;
     sb->s_magic = AFS_VFSMAGIC;
     sb->s_op = &afs_sops;      /* Super block (vfs) ops */
+
+#if defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
+    sb->s_d_op = &afs_dentry_operations;
+#endif
+#if defined(HAVE_LINUX_SUPER_SETUP_BDI)
+    code = super_setup_bdi(sb);
+    if (code)
+        goto out;
+    sb->s_bdi->name = "openafs";
+    sb->s_bdi->ra_pages = 32;
+#else
     /* used for inodes backing_dev_info field, also */
-    afs_backing_dev_info = osi_Alloc(sizeof(struct backing_dev_info));
+    afs_backing_dev_info = kzalloc(sizeof(struct backing_dev_info), GFP_NOFS);
 #if defined(HAVE_LINUX_BDI_INIT)
-    bdi_init(afs_backing_dev_info);
+    code = bdi_init(afs_backing_dev_info);
+    if (code)
+       goto out;
+    bdi_init_done = 1;
 #endif
 #if defined(STRUCT_BACKING_DEV_INFO_HAS_NAME)
     afs_backing_dev_info->name = "openafs";
@@ -119,6 +144,7 @@ afs_fill_super(struct super_block *sb, void *data, int silent)
     /* The name specified here will appear in the flushing thread name - flush-afs */
     bdi_register(afs_backing_dev_info, NULL, "afs");
 #endif
+#endif /* HAVE_LINUX_SUPER_SETUP_BDI */
 #if !defined(AFS_NONFSTRANS)
     sb->s_export_op = &afs_export_ops;
 #endif
@@ -137,9 +163,17 @@ afs_fill_super(struct super_block *sb, void *data, int silent)
 #endif
 #endif
     code = afs_root(sb);
+out:
     if (code) {
        afs_globalVFS = NULL;
-       osi_linux_free_inode_pages();
+       afs_FlushAllVCaches();
+#if defined(HAVE_LINUX_BDI_INIT)
+       if (bdi_init_done)
+           bdi_destroy(afs_backing_dev_info);
+#endif
+#if !defined(HAVE_LINUX_SUPER_SETUP_BDI)
+       kfree(afs_backing_dev_info);
+#endif
         module_put(THIS_MODULE);
     }
 
@@ -152,14 +186,14 @@ afs_fill_super(struct super_block *sb, void *data, int silent)
 static int
 afs_root(struct super_block *afsp)
 {
-    register afs_int32 code = 0;
-    struct vrequest treq;
-    register struct vcache *tvp = 0;
+    afs_int32 code = 0;
+    struct vcache *tvp = 0;
 
     AFS_STATCNT(afs_root);
     if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
        tvp = afs_globalVp;
     } else {
+       struct vrequest *treq = NULL;
        cred_t *credp = crref();
 
        if (afs_globalVp) {
@@ -167,23 +201,34 @@ afs_root(struct super_block *afsp)
            afs_globalVp = NULL;
        }
 
-       if (!(code = afs_InitReq(&treq, credp)) && !(code = afs_CheckInit())) {
-           tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
+       if (!(code = afs_CreateReq(&treq, credp)) && !(code = afs_CheckInit())) {
+           tvp = afs_GetVCache(&afs_rootFid, treq, NULL, NULL);
            if (tvp) {
                struct inode *ip = AFSTOV(tvp);
-               struct vattr vattr;
+               struct vattr *vattr = NULL;
 
-               afs_getattr(tvp, &vattr, credp);
-               afs_fill_inode(ip, &vattr);
+               code = afs_CreateAttr(&vattr);
+               if (!code) {
+                   afs_getattr(tvp, vattr, credp);
+                   afs_fill_inode(ip, vattr);
 
-               /* setup super_block and mount point inode. */
-               afs_globalVp = tvp;
-               afsp->s_root = d_alloc_root(ip);
-               afsp->s_root->d_op = &afs_dentry_operations;
+                   /* setup super_block and mount point inode. */
+                   afs_globalVp = tvp;
+#if defined(HAVE_LINUX_D_MAKE_ROOT)
+                   afsp->s_root = d_make_root(ip);
+#else
+                   afsp->s_root = d_alloc_root(ip);
+#endif
+#if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
+                   afsp->s_root->d_op = &afs_dentry_operations;
+#endif
+                   afs_DestroyAttr(vattr);
+               }
            } else
-               code = ENOENT;
+               code = EIO;
        }
        crfree(credp);
+       afs_DestroyReq(treq);
     }
 
     afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, afs_globalVp,
@@ -193,33 +238,6 @@ afs_root(struct super_block *afsp)
 
 /* super_operations */
 
-/* afs_notify_change
- * Linux version of setattr call. What to change is in the iattr struct.
- * We need to set bits in both the Linux inode as well as the vcache.
- */
-int
-afs_notify_change(struct dentry *dp, struct iattr *iattrp)
-{
-    struct vattr vattr;
-    cred_t *credp = crref();
-    struct inode *ip = dp->d_inode;
-    int code;
-
-    VATTR_NULL(&vattr);
-    iattr2vattr(&vattr, iattrp);       /* Convert for AFS vnodeops call. */
-
-    AFS_GLOCK();
-    code = afs_setattr(VTOAFS(ip), &vattr, credp);
-    if (!code) {
-       afs_getattr(VTOAFS(ip), &vattr, credp);
-       vattr2inode(ip, &vattr);
-    }
-    AFS_GUNLOCK();
-    crfree(credp);
-    return -code;
-}
-
-
 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
 static afs_kmem_cache_t *afs_inode_cachep;
 
@@ -298,7 +316,11 @@ afs_evict_inode(struct inode *ip)
        osi_Panic("inode freed while still hashed");
 
     truncate_inode_pages(&ip->i_data, 0);
+#if defined(HAVE_LINUX_CLEAR_INODE)
+    clear_inode(ip);
+#else
     end_writeback(ip);
+#endif
 
 #if !defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
     afs_osi_Free(ip->u.generic_ip, sizeof(struct vcache));
@@ -332,7 +354,6 @@ afs_put_super(struct super_block *sbp)
     afs_globalVFS = 0;
     afs_globalVp = 0;
 
-    osi_linux_free_inode_pages();      /* invalidate and release remaining AFS inodes. */
     afs_shutdown();
     mntput(afs_cacheMnt);
 
@@ -340,7 +361,7 @@ afs_put_super(struct super_block *sbp)
 #if defined(HAVE_LINUX_BDI_INIT)
     bdi_destroy(afs_backing_dev_info);
 #endif
-    osi_Free(afs_backing_dev_info, sizeof(struct backing_dev_info));
+    kfree(afs_backing_dev_info);
     AFS_GUNLOCK();
 
     sbp->s_dev = 0;
@@ -352,7 +373,7 @@ afs_put_super(struct super_block *sbp)
  * statp is in user space, so we need to cobble together a statfs, then
  * copy it.
  */
-int
+static int
 #if defined(STATFS_TAKES_DENTRY)
 afs_statfs(struct dentry *dentry, struct kstatfs *statp)
 #else
@@ -371,7 +392,7 @@ afs_statfs(struct super_block *sbp, struct kstatfs *statp)
     statp->f_bsize = sbp->s_blocksize;
 #endif
     statp->f_blocks = statp->f_bfree = statp->f_bavail = statp->f_files =
-       statp->f_ffree = 9000000;
+       statp->f_ffree = AFS_VFS_FAKEFREE;
     statp->f_fsid.val[0] = AFS_VFSMAGIC;
     statp->f_fsid.val[1] = AFS_VFSFSID;
     statp->f_namelen = 256;
@@ -392,90 +413,3 @@ struct super_operations afs_sops = {
   .put_super =         afs_put_super,
   .statfs =            afs_statfs,
 };
-
-/************** Support routines ************************/
-
-/* vattr_setattr
- * Set iattr data into vattr. Assume vattr cleared before call.
- */
-static void
-iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
-{
-    vattrp->va_mask = iattrp->ia_valid;
-    if (iattrp->ia_valid & ATTR_MODE)
-       vattrp->va_mode = iattrp->ia_mode;
-    if (iattrp->ia_valid & ATTR_UID)
-       vattrp->va_uid = iattrp->ia_uid;
-    if (iattrp->ia_valid & ATTR_GID)
-       vattrp->va_gid = iattrp->ia_gid;
-    if (iattrp->ia_valid & ATTR_SIZE)
-       vattrp->va_size = iattrp->ia_size;
-    if (iattrp->ia_valid & ATTR_ATIME) {
-       vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
-       vattrp->va_atime.tv_usec = 0;
-    }
-    if (iattrp->ia_valid & ATTR_MTIME) {
-       vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
-       vattrp->va_mtime.tv_usec = 0;
-    }
-    if (iattrp->ia_valid & ATTR_CTIME) {
-       vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
-       vattrp->va_ctime.tv_usec = 0;
-    }
-}
-
-/* vattr2inode
- * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
- */
-void
-vattr2inode(struct inode *ip, struct vattr *vp)
-{
-    ip->i_ino = vp->va_nodeid;
-    ip->i_nlink = vp->va_nlink;
-    ip->i_blocks = vp->va_blocks;
-#ifdef STRUCT_INODE_HAS_I_BLKBITS
-    ip->i_blkbits = AFS_BLKBITS;
-#endif
-#ifdef STRUCT_INODE_HAS_I_BLKSIZE
-    ip->i_blksize = vp->va_blocksize;
-#endif
-    ip->i_rdev = vp->va_rdev;
-    ip->i_mode = vp->va_mode;
-    ip->i_uid = vp->va_uid;
-    ip->i_gid = vp->va_gid;
-    i_size_write(ip, vp->va_size);
-    ip->i_atime.tv_sec = vp->va_atime.tv_sec;
-    ip->i_atime.tv_nsec = 0;
-    ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
-    /* Set the mtime nanoseconds to the sysname generation number.
-     * This convinces NFS clients that all directories have changed
-     * any time the sysname list changes.
-     */
-    ip->i_mtime.tv_nsec = afs_sysnamegen;
-    ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
-    ip->i_ctime.tv_nsec = 0;
-}
-
-/* osi_linux_free_inode_pages
- *
- * Free all vnodes remaining in the afs hash.  Must be done before
- * shutting down afs and freeing all memory.
- */
-void
-osi_linux_free_inode_pages(void)
-{
-    int i;
-    struct vcache *tvc, *nvc;
-    extern struct vcache *afs_vhashT[VCSIZE];
-
-    for (i = 0; i < VCSIZE; i++) {
-       for (tvc = afs_vhashT[i]; tvc; ) {
-           int slept;
-       
-           nvc = tvc->hnext;
-           if (afs_FlushVCache(tvc, &slept))           /* slept always 0 for linux? */
-               printf("Failed to invalidate all pages on inode 0x%p\n", tvc);
-           tvc = nvc;
-       }
-    }
-}