linux-truncate-race-20090109
[openafs.git] / src / afs / LINUX / osi_vfsops.c
index 8d6ce9b..4b609e0 100644 (file)
@@ -39,6 +39,9 @@ struct vfsmount *afs_cacheMnt;
 int afs_was_mounted = 0;       /* Used to force reload if mount/unmount/mount */
 
 extern struct super_operations afs_sops;
+#if defined(AFS_LINUX26_ENV) && !defined(AFS_NONFSTRANS)
+extern struct export_operations afs_export_ops;
+#endif
 extern afs_rwlock_t afs_xvcache;
 extern struct afs_q VLRU;
 
@@ -49,7 +52,6 @@ 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);
-static struct super_block *afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data);
 
 /* afs_file_system
  * VFS entry for Linux - installed in init_module
@@ -58,11 +60,30 @@ static struct super_block *afs_get_sb(struct file_system_type *fs_type, int flag
  * 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.
  */
+
+
+/* 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.
+ */
 #if defined(AFS_LINUX26_ENV)
-struct backing_dev_info afs_backing_dev_info = {
-       .ra_pages       = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE,
-       .state          = 0,
-};
+#ifdef GET_SB_HAS_STRUCT_VFSMOUNT
+int
+afs_get_sb(struct file_system_type *fs_type, int flags,
+          const char *dev_name, void *data, struct vfsmount *mnt)
+#else
+static struct superblock *
+afs_get_sb(struct file_system_type *fs_type, int flags,
+          const char *dev_name, void *data)
+#endif
+{
+#ifdef GET_SB_HAS_STRUCT_VFSMOUNT
+    return get_sb_nodev(fs_type, flags, data, afs_fill_super, mnt);
+#else
+    return get_sb_nodev(fs_type, flags, data, afs_fill_super);
+#endif
+}
+
 
 struct file_system_type afs_fs_type = {
     .owner = THIS_MODULE,
@@ -83,16 +104,10 @@ struct file_system_type afs_fs_type = {
 };
 #endif
 
-/* 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.
- */
 #if defined(AFS_LINUX26_ENV)
-static struct super_block *
-afs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
-{
-    return get_sb_nodev(fs_type, flags, data, afs_fill_super);
-}
+struct backing_dev_info afs_backing_dev_info = {
+    .ra_pages          = 0, /* disable readahead, afs does prefetch */
+};
 
 int
 afs_fill_super(struct super_block *sb, void *data, int silent)
@@ -131,6 +146,12 @@ afs_read_super(struct super_block *sb, void *data, int silent)
     sb->s_blocksize_bits = 10;
     sb->s_magic = AFS_VFSMAGIC;
     sb->s_op = &afs_sops;      /* Super block (vfs) ops */
+#if defined(HAVE_BDI_INIT)
+    bdi_init(&afs_backing_dev_info);
+#endif
+#if defined(AFS_LINUX26_ENV) && !defined(AFS_NONFSTRANS)
+    sb->s_export_op = &afs_export_ops;
+#endif
 #if defined(MAX_NON_LFS)
 #ifdef AFS_64BIT_CLIENT
 #if !defined(MAX_LFS_FILESIZE)
@@ -251,14 +272,22 @@ afs_notify_change(struct dentry *dp, struct iattr *iattrp)
 
 
 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
+#if defined(HAVE_KMEM_CACHE_T)
 static kmem_cache_t *afs_inode_cachep;
+#else
+struct kmem_cache *afs_inode_cachep;
+#endif
 
 static struct inode *
 afs_alloc_inode(struct super_block *sb)
 {
     struct vcache *vcp;
 
+#if defined(SLAB_KERNEL)
     vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, SLAB_KERNEL);
+#else
+    vcp = (struct vcache *) kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL);
+#endif
     if (!vcp)
        return NULL;
 
@@ -272,12 +301,22 @@ afs_destroy_inode(struct inode *inode)
 }
 
 static void
+#if defined(HAVE_KMEM_CACHE_T)
 init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+#else
+#if defined(KMEM_CACHE_INIT)
+init_once(struct kmem_cache * cachep, void * foo)
+#else
+init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
+#endif
+#endif
 {
     struct vcache *vcp = (struct vcache *) foo;
 
+#if defined(SLAB_CTOR_VERIFY)
     if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
        SLAB_CTOR_CONSTRUCTOR)
+#endif
        inode_init_once(AFSTOV(vcp));
 }
 
@@ -288,10 +327,17 @@ afs_init_inodecache(void)
 #define SLAB_RECLAIM_ACCOUNT 0
 #endif
 
+#if defined(KMEM_CACHE_TAKES_DTOR)
     afs_inode_cachep = kmem_cache_create("afs_inode_cache",
                                         sizeof(struct vcache),
                                         0, SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT,
                                         init_once, NULL);
+#else
+    afs_inode_cachep = kmem_cache_create("afs_inode_cache",
+                                        sizeof(struct vcache),
+                                        0, SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT,
+                                        init_once);
+#endif
     if (afs_inode_cachep == NULL)
        return -ENOMEM;
     return 0;
@@ -300,8 +346,8 @@ afs_init_inodecache(void)
 void
 afs_destroy_inodecache(void)
 {
-    if (kmem_cache_destroy(afs_inode_cachep))
-       printk(KERN_INFO "afs_inode_cache: not all structures were freed\n");
+    if (afs_inode_cachep)
+       (void) kmem_cache_destroy(afs_inode_cachep);
 }
 #else
 int
@@ -332,25 +378,6 @@ afs_clear_inode(struct inode *ip)
 #endif
 }
 
-/* afs_put_inode
- * Linux version of inactive.  When refcount == 2, we are about to
- * decrement to 1 and the only reference remaining should be for
- * the VLRU
- */
-
-static void
-afs_put_inode(struct inode *ip)
-{
-    struct vcache *vcp = VTOAFS(ip);
-
-    if (VREFCOUNT(vcp) == 2) {
-       AFS_GLOCK();
-       if (VREFCOUNT(vcp) == 2)
-           afs_InactiveVCache(vcp, NULL);
-       AFS_GUNLOCK();
-    }
-}
-
 /* afs_put_super
  * Called from unmount to release super_block. */
 static void
@@ -376,6 +403,9 @@ afs_put_super(struct super_block *sbp)
 #endif
 
     osi_linux_verify_alloced_memory();
+#if defined(HAVE_BDI_INIT)
+    bdi_destroy(&afs_backing_dev_info);
+#endif
     AFS_GUNLOCK();
 
     sbp->s_dev = 0;
@@ -393,7 +423,11 @@ afs_put_super(struct super_block *sbp)
  */
 #if defined(AFS_LINUX26_ENV)
 int
+#if defined(STATFS_TAKES_DENTRY)
+afs_statfs(struct dentry *dentry, struct kstatfs *statp)
+#else
 afs_statfs(struct super_block *sbp, struct kstatfs *statp)
+#endif
 #elif defined(AFS_LINUX24_ENV)
 int
 afs_statfs(struct super_block *sbp, struct statfs *statp)
@@ -416,8 +450,13 @@ afs_statfs(struct super_block *sbp, struct statfs *__statp, int size)
 
     AFS_STATCNT(afs_statfs);
 
-    statp->f_type = 0;         /* Can we get a real type sometime? */
+    /* hardcode in case that which is giveth is taken away */
+    statp->f_type = 0x5346414F;
+#if defined(STATFS_TAKES_DENTRY)
+    statp->f_bsize = dentry->d_sb->s_blocksize;
+#else
     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_fsid.val[0] = AFS_VFSMAGIC;
@@ -436,7 +475,6 @@ struct super_operations afs_sops = {
   .destroy_inode =     afs_destroy_inode,
 #endif
   .clear_inode =       afs_clear_inode,
-  .put_inode =         afs_put_inode,
   .put_super =         afs_put_super,
   .statfs =            afs_statfs,
 #if !defined(AFS_LINUX24_ENV)
@@ -496,19 +534,55 @@ 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;
-    ip->i_size = vp->va_size;
+    i_size_write(ip, vp->va_size);
 #if defined(AFS_LINUX26_ENV)
     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;
 #else
     ip->i_atime = vp->va_atime.tv_sec;
     ip->i_mtime = vp->va_mtime.tv_sec;
     ip->i_ctime = vp->va_ctime.tv_sec;
 #endif
 }
+
+/* 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;
+       }
+    }
+}