GFS2: Remove gfs2_dinode_print() function
[pandora-kernel.git] / fs / gfs2 / inode.c
index 97d54a2..7c2121f 100644 (file)
@@ -40,37 +40,61 @@ struct gfs2_inum_range_host {
        u64 ir_length;
 };
 
+struct gfs2_skip_data {
+       u64 no_addr;
+       int skipped;
+       int non_block;
+};
+
 static int iget_test(struct inode *inode, void *opaque)
 {
        struct gfs2_inode *ip = GFS2_I(inode);
-       u64 *no_addr = opaque;
+       struct gfs2_skip_data *data = opaque;
 
-       if (ip->i_no_addr == *no_addr)
+       if (ip->i_no_addr == data->no_addr) {
+               if (data->non_block &&
+                   inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) {
+                       data->skipped = 1;
+                       return 0;
+               }
                return 1;
-
+       }
        return 0;
 }
 
 static int iget_set(struct inode *inode, void *opaque)
 {
        struct gfs2_inode *ip = GFS2_I(inode);
-       u64 *no_addr = opaque;
+       struct gfs2_skip_data *data = opaque;
 
-       inode->i_ino = (unsigned long)*no_addr;
-       ip->i_no_addr = *no_addr;
+       if (data->skipped)
+               return -ENOENT;
+       inode->i_ino = (unsigned long)(data->no_addr);
+       ip->i_no_addr = data->no_addr;
        return 0;
 }
 
-struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr)
+struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr, int non_block)
 {
        unsigned long hash = (unsigned long)no_addr;
-       return ilookup5(sb, hash, iget_test, &no_addr);
+       struct gfs2_skip_data data;
+
+       data.no_addr = no_addr;
+       data.skipped = 0;
+       data.non_block = non_block;
+       return ilookup5(sb, hash, iget_test, &data);
 }
 
-static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr)
+static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr,
+                              int non_block)
 {
+       struct gfs2_skip_data data;
        unsigned long hash = (unsigned long)no_addr;
-       return iget5_locked(sb, hash, iget_test, iget_set, &no_addr);
+
+       data.no_addr = no_addr;
+       data.skipped = 0;
+       data.non_block = non_block;
+       return iget5_locked(sb, hash, iget_test, iget_set, &data);
 }
 
 /**
@@ -111,19 +135,20 @@ static void gfs2_set_iop(struct inode *inode)
  * @sb: The super block
  * @no_addr: The inode number
  * @type: The type of the inode
+ * non_block: Can we block on inodes that are being freed?
  *
  * Returns: A VFS inode, or an error
  */
 
 struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
-                               u64 no_addr, u64 no_formal_ino)
+                               u64 no_addr, u64 no_formal_ino, int non_block)
 {
        struct inode *inode;
        struct gfs2_inode *ip;
        struct gfs2_glock *io_gl = NULL;
        int error;
 
-       inode = gfs2_iget(sb, no_addr);
+       inode = gfs2_iget(sb, no_addr, non_block);
        ip = GFS2_I(inode);
 
        if (!inode)
@@ -185,11 +210,12 @@ struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
 {
        struct super_block *sb = sdp->sd_vfs;
        struct gfs2_holder i_gh;
-       struct inode *inode;
+       struct inode *inode = NULL;
        int error;
 
+       /* Must not read in block until block type is verified */
        error = gfs2_glock_nq_num(sdp, no_addr, &gfs2_inode_glops,
-                                 LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
+                                 LM_ST_EXCLUSIVE, GL_SKIP, &i_gh);
        if (error)
                return ERR_PTR(error);
 
@@ -197,7 +223,7 @@ struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
        if (error)
                goto fail;
 
-       inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0);
+       inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0, 1);
        if (IS_ERR(inode))
                goto fail;
 
@@ -222,6 +248,32 @@ fail_iput:
        goto fail;
 }
 
+/**
+ * gfs2_set_nlink - Set the inode's link count based on on-disk info
+ * @inode: The inode in question
+ * @nlink: The link count
+ *
+ * If the link count has hit zero, it must never be raised, whatever the
+ * on-disk inode might say. When new struct inodes are created the link
+ * count is set to 1, so that we can safely use this test even when reading
+ * in on disk information for the first time.
+ */
+
+static void gfs2_set_nlink(struct inode *inode, u32 nlink)
+{
+       /*
+        * We will need to review setting the nlink count here in the
+        * light of the forthcoming ro bind mount work. This is a reminder
+        * to do that.
+        */
+       if ((inode->i_nlink != nlink) && (inode->i_nlink != 0)) {
+               if (nlink == 0)
+                       clear_nlink(inode);
+               else
+                       inode->i_nlink = nlink;
+       }
+}
+
 static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
 {
        const struct gfs2_dinode *str = buf;
@@ -243,12 +295,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
 
        ip->i_inode.i_uid = be32_to_cpu(str->di_uid);
        ip->i_inode.i_gid = be32_to_cpu(str->di_gid);
-       /*
-        * We will need to review setting the nlink count here in the
-        * light of the forthcoming ro bind mount work. This is a reminder
-        * to do that.
-        */
-       ip->i_inode.i_nlink = be32_to_cpu(str->di_nlink);
+       gfs2_set_nlink(&ip->i_inode, be32_to_cpu(str->di_nlink));
        i_size_write(&ip->i_inode, be64_to_cpu(str->di_size));
        gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks));
        atime.tv_sec = be64_to_cpu(str->di_atime);
@@ -282,8 +329,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
 
        return 0;
 corrupt:
-       if (gfs2_consist_inode(ip))
-               gfs2_dinode_print(ip);
+       gfs2_consist_inode(ip);
        return -EIO;
 }
 
@@ -315,111 +361,6 @@ int gfs2_inode_refresh(struct gfs2_inode *ip)
        return error;
 }
 
-int gfs2_dinode_dealloc(struct gfs2_inode *ip)
-{
-       struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al;
-       struct gfs2_rgrpd *rgd;
-       int error;
-
-       if (gfs2_get_inode_blocks(&ip->i_inode) != 1) {
-               if (gfs2_consist_inode(ip))
-                       gfs2_dinode_print(ip);
-               return -EIO;
-       }
-
-       al = gfs2_alloc_get(ip);
-       if (!al)
-               return -ENOMEM;
-
-       error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
-       if (error)
-               goto out;
-
-       error = gfs2_rindex_hold(sdp, &al->al_ri_gh);
-       if (error)
-               goto out_qs;
-
-       rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
-       if (!rgd) {
-               gfs2_consist_inode(ip);
-               error = -EIO;
-               goto out_rindex_relse;
-       }
-
-       error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0,
-                                  &al->al_rgd_gh);
-       if (error)
-               goto out_rindex_relse;
-
-       error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1);
-       if (error)
-               goto out_rg_gunlock;
-
-       set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
-       set_bit(GLF_LFLUSH, &ip->i_gl->gl_flags);
-
-       gfs2_free_di(rgd, ip);
-
-       gfs2_trans_end(sdp);
-
-out_rg_gunlock:
-       gfs2_glock_dq_uninit(&al->al_rgd_gh);
-out_rindex_relse:
-       gfs2_glock_dq_uninit(&al->al_ri_gh);
-out_qs:
-       gfs2_quota_unhold(ip);
-out:
-       gfs2_alloc_put(ip);
-       return error;
-}
-
-/**
- * gfs2_change_nlink - Change nlink count on inode
- * @ip: The GFS2 inode
- * @diff: The change in the nlink count required
- *
- * Returns: errno
- */
-int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
-{
-       struct buffer_head *dibh;
-       u32 nlink;
-       int error;
-
-       BUG_ON(diff != 1 && diff != -1);
-       nlink = ip->i_inode.i_nlink + diff;
-
-       /* If we are reducing the nlink count, but the new value ends up being
-          bigger than the old one, we must have underflowed. */
-       if (diff < 0 && nlink > ip->i_inode.i_nlink) {
-               if (gfs2_consist_inode(ip))
-                       gfs2_dinode_print(ip);
-               return -EIO;
-       }
-
-       error = gfs2_meta_inode_buffer(ip, &dibh);
-       if (error)
-               return error;
-
-       if (diff > 0)
-               inc_nlink(&ip->i_inode);
-       else
-               drop_nlink(&ip->i_inode);
-
-       ip->i_inode.i_ctime = CURRENT_TIME;
-
-       gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-       gfs2_dinode_out(ip, dibh->b_data);
-       brelse(dibh);
-       mark_inode_dirty(&ip->i_inode);
-
-       if (ip->i_inode.i_nlink == 0)
-               gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */
-
-       return error;
-}
-
 struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
 {
        struct qstr qstr;
@@ -517,7 +458,7 @@ static int create_ok(struct gfs2_inode *dip, const struct qstr *name,
 
        /*  Don't create entries in an unlinked directory  */
        if (!dip->i_inode.i_nlink)
-               return -EPERM;
+               return -ENOENT;
 
        error = gfs2_dir_check(&dip->i_inode, name, NULL);
        switch (error) {
@@ -735,7 +676,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
                        goto fail_quota_locks;
        }
 
-       error = gfs2_dir_add(&dip->i_inode, name, ip, IF2DT(ip->i_inode.i_mode));
+       error = gfs2_dir_add(&dip->i_inode, name, ip);
        if (error)
                goto fail_end_trans;
 
@@ -843,7 +784,7 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
                goto fail_gunlock2;
 
        inode = gfs2_inode_lookup(dir->i_sb, IF2DT(mode), inum.no_addr,
-                                 inum.no_formal_ino);
+                                 inum.no_formal_ino, 0);
        if (IS_ERR(inode))
                goto fail_gunlock2;
 
@@ -959,24 +900,3 @@ void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf)
        str->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec);
        str->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec);
 }
-
-void gfs2_dinode_print(const struct gfs2_inode *ip)
-{
-       printk(KERN_INFO "  no_formal_ino = %llu\n",
-              (unsigned long long)ip->i_no_formal_ino);
-       printk(KERN_INFO "  no_addr = %llu\n",
-              (unsigned long long)ip->i_no_addr);
-       printk(KERN_INFO "  i_size = %llu\n",
-              (unsigned long long)i_size_read(&ip->i_inode));
-       printk(KERN_INFO "  blocks = %llu\n",
-              (unsigned long long)gfs2_get_inode_blocks(&ip->i_inode));
-       printk(KERN_INFO "  i_goal = %llu\n",
-              (unsigned long long)ip->i_goal);
-       printk(KERN_INFO "  i_diskflags = 0x%.8X\n", ip->i_diskflags);
-       printk(KERN_INFO "  i_height = %u\n", ip->i_height);
-       printk(KERN_INFO "  i_depth = %u\n", ip->i_depth);
-       printk(KERN_INFO "  i_entries = %u\n", ip->i_entries);
-       printk(KERN_INFO "  i_eattr = %llu\n",
-              (unsigned long long)ip->i_eattr);
-}
-