ext4: Fix return value of ext4_split_unwritten_extents() to fix direct I/O
[safe/jmp/linux-2.6] / fs / freevxfs / vxfs_inode.c
index 9672d2f..03a6ea5 100644 (file)
 #include "vxfs_extern.h"
 
 
-extern struct address_space_operations vxfs_aops;
-extern struct address_space_operations vxfs_immed_aops;
-
-extern struct inode_operations vxfs_immed_symlink_iops;
-
-static struct file_operations vxfs_file_operations = {
-       .open =                 generic_file_open,
-       .llseek =               generic_file_llseek,
-       .read =                 generic_file_read,
-       .mmap =                 generic_file_mmap,
-       .sendfile =             generic_file_sendfile,
-};
-
-
-kmem_cache_t           *vxfs_inode_cachep;
+struct kmem_cache              *vxfs_inode_cachep;
 
 
 #ifdef DIAGNOSTIC
@@ -108,11 +94,11 @@ vxfs_blkiget(struct super_block *sbp, u_long extent, ino_t ino)
        offset = ((ino % (sbp->s_blocksize / VXFS_ISIZE)) * VXFS_ISIZE);
        bp = sb_bread(sbp, block);
 
-       if (buffer_mapped(bp)) {
+       if (bp && buffer_mapped(bp)) {
                struct vxfs_inode_info  *vip;
                struct vxfs_dinode      *dip;
 
-               if (!(vip = kmem_cache_alloc(vxfs_inode_cachep, SLAB_KERNEL)))
+               if (!(vip = kmem_cache_alloc(vxfs_inode_cachep, GFP_KERNEL)))
                        goto fail;
                dip = (struct vxfs_dinode *)(bp->b_data + offset);
                memcpy(vip, dip, sizeof(*vip));
@@ -138,7 +124,7 @@ fail:
  * Description:
  *  Search the for inode number @ino in the filesystem
  *  described by @sbp.  Use the specified inode table (@ilistp).
- *  Returns the matching VxFS inode on success, else a NULL pointer.
+ *  Returns the matching VxFS inode on success, else an error code.
  */
 static struct vxfs_inode_info *
 __vxfs_iget(ino_t ino, struct inode *ilistp)
@@ -154,7 +140,7 @@ __vxfs_iget(ino_t ino, struct inode *ilistp)
                struct vxfs_dinode      *dip;
                caddr_t                 kaddr = (char *)page_address(pp);
 
-               if (!(vip = kmem_cache_alloc(vxfs_inode_cachep, SLAB_KERNEL)))
+               if (!(vip = kmem_cache_alloc(vxfs_inode_cachep, GFP_KERNEL)))
                        goto fail;
                dip = (struct vxfs_dinode *)(kaddr + offset);
                memcpy(vip, dip, sizeof(*vip));
@@ -166,12 +152,12 @@ __vxfs_iget(ino_t ino, struct inode *ilistp)
        }
 
        printk(KERN_WARNING "vxfs: error on page %p\n", pp);
-       return NULL;
+       return ERR_CAST(pp);
 
 fail:
        printk(KERN_WARNING "vxfs: unable to read inode %ld\n", (unsigned long)ino);
        vxfs_put_page(pp);
-       return NULL;
+       return ERR_PTR(-ENOMEM);
 }
 
 /**
@@ -187,7 +173,10 @@ fail:
 struct vxfs_inode_info *
 vxfs_stiget(struct super_block *sbp, ino_t ino)
 {
-        return __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_stilist);
+       struct vxfs_inode_info *vip;
+
+       vip = __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_stilist);
+       return IS_ERR(vip) ? NULL : vip;
 }
 
 /**
@@ -248,11 +237,10 @@ vxfs_iinit(struct inode *ip, struct vxfs_inode_info *vip)
        ip->i_ctime.tv_nsec = 0;
        ip->i_mtime.tv_nsec = 0;
 
-       ip->i_blksize = PAGE_SIZE;
        ip->i_blocks = vip->vii_blocks;
        ip->i_generation = vip->vii_gen;
 
-       ip->u.generic_ip = (void *)vip;
+       ip->i_private = vip;
        
 }
 
@@ -292,23 +280,32 @@ vxfs_put_fake_inode(struct inode *ip)
 }
 
 /**
- * vxfs_read_inode - fill in inode information
- * @ip:                inode pointer to fill
+ * vxfs_iget - get an inode
+ * @sbp:       the superblock to get the inode for
+ * @ino:       the number of the inode to get
  *
  * Description:
- *  vxfs_read_inode reads the disk inode for @ip and fills
- *  in all relevant fields in @ip.
+ *  vxfs_read_inode creates an inode, reads the disk inode for @ino and fills
+ *  in all relevant fields in the new inode.
  */
-void
-vxfs_read_inode(struct inode *ip)
+struct inode *
+vxfs_iget(struct super_block *sbp, ino_t ino)
 {
-       struct super_block              *sbp = ip->i_sb;
        struct vxfs_inode_info          *vip;
-       struct address_space_operations *aops;
-       ino_t                           ino = ip->i_ino;
-
-       if (!(vip = __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_ilist)))
-               return;
+       const struct address_space_operations   *aops;
+       struct inode *ip;
+
+       ip = iget_locked(sbp, ino);
+       if (!ip)
+               return ERR_PTR(-ENOMEM);
+       if (!(ip->i_state & I_NEW))
+               return ip;
+
+       vip = __vxfs_iget(ino, VXFS_SBI(sbp)->vsi_ilist);
+       if (IS_ERR(vip)) {
+               iget_failed(ip);
+               return ERR_CAST(vip);
+       }
 
        vxfs_iinit(ip, vip);
 
@@ -318,7 +315,7 @@ vxfs_read_inode(struct inode *ip)
                aops = &vxfs_aops;
 
        if (S_ISREG(ip->i_mode)) {
-               ip->i_fop = &vxfs_file_operations;
+               ip->i_fop = &generic_ro_fops;
                ip->i_mapping->a_ops = aops;
        } else if (S_ISDIR(ip->i_mode)) {
                ip->i_op = &vxfs_dir_inode_ops;
@@ -328,12 +325,15 @@ vxfs_read_inode(struct inode *ip)
                if (!VXFS_ISIMMED(vip)) {
                        ip->i_op = &page_symlink_inode_operations;
                        ip->i_mapping->a_ops = &vxfs_aops;
-               } else
+               } else {
                        ip->i_op = &vxfs_immed_symlink_iops;
+                       vip->vii_immed.vi_immed[ip->i_size] = '\0';
+               }
        } else
                init_special_inode(ip, ip->i_mode, old_decode_dev(vip->vii_rdev));
 
-       return;
+       unlock_new_inode(ip);
+       return ip;
 }
 
 /**
@@ -347,5 +347,5 @@ vxfs_read_inode(struct inode *ip)
 void
 vxfs_clear_inode(struct inode *ip)
 {
-       kmem_cache_free(vxfs_inode_cachep, ip->u.generic_ip);
+       kmem_cache_free(vxfs_inode_cachep, ip->i_private);
 }