Staging: hv: Fix null pointer error after vmbus loading
[safe/jmp/linux-2.6] / fs / gfs2 / dir.c
index 94070ad..297d7e5 100644 (file)
@@ -36,7 +36,7 @@
  * the block.  In leaves, they begin at offset sizeof(struct gfs2_leaf) from the
  * beginning of the leaf block. The dirents reside in leaves when
  *
- * dip->i_di.di_flags & GFS2_DIF_EXHASH is true
+ * dip->i_diskflags & GFS2_DIF_EXHASH is true
  *
  * Otherwise, the dirents are "linear", within a single stuffed dinode block.
  *
@@ -60,7 +60,6 @@
 #include <linux/gfs2_ondisk.h>
 #include <linux/crc32.h>
 #include <linux/vmalloc.h>
-#include <linux/lm_interface.h>
 
 #include "gfs2.h"
 #include "incore.h"
@@ -128,8 +127,8 @@ static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf,
 
        gfs2_trans_add_bh(ip->i_gl, dibh, 1);
        memcpy(dibh->b_data + offset + sizeof(struct gfs2_dinode), buf, size);
-       if (ip->i_di.di_size < offset + size)
-               ip->i_di.di_size = offset + size;
+       if (ip->i_disksize < offset + size)
+               ip->i_disksize = offset + size;
        ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
        gfs2_dinode_out(ip, dibh->b_data);
 
@@ -226,8 +225,8 @@ out:
        if (error)
                return error;
 
-       if (ip->i_di.di_size < offset + copied)
-               ip->i_di.di_size = offset + copied;
+       if (ip->i_disksize < offset + copied)
+               ip->i_disksize = offset + copied;
        ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
 
        gfs2_trans_add_bh(ip->i_gl, dibh, 1);
@@ -277,11 +276,11 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset,
        int copied = 0;
        int error = 0;
 
-       if (offset >= ip->i_di.di_size)
+       if (offset >= ip->i_disksize)
                return 0;
 
-       if (offset + size > ip->i_di.di_size)
-               size = ip->i_di.di_size - offset;
+       if (offset + size > ip->i_disksize)
+               size = ip->i_disksize - offset;
 
        if (!size)
                return 0;
@@ -755,12 +754,12 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode,
        struct gfs2_inode *ip = GFS2_I(inode);
        int error;
 
-       if (ip->i_di.di_flags & GFS2_DIF_EXHASH) {
+       if (ip->i_diskflags & GFS2_DIF_EXHASH) {
                struct gfs2_leaf *leaf;
                unsigned hsize = 1 << ip->i_depth;
                unsigned index;
                u64 ln;
-               if (hsize * sizeof(u64) != ip->i_di.di_size) {
+               if (hsize * sizeof(u64) != ip->i_disksize) {
                        gfs2_consist_inode(ip);
                        return ERR_PTR(-EIO);
                }
@@ -804,13 +803,20 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
 {
        struct gfs2_inode *ip = GFS2_I(inode);
        unsigned int n = 1;
-       u64 bn = gfs2_alloc_block(ip, &n);
-       struct buffer_head *bh = gfs2_meta_new(ip->i_gl, bn);
+       u64 bn;
+       int error;
+       struct buffer_head *bh;
        struct gfs2_leaf *leaf;
        struct gfs2_dirent *dent;
        struct qstr name = { .name = "", .len = 0, .hash = 0 };
+
+       error = gfs2_alloc_block(ip, &bn, &n);
+       if (error)
+               return NULL;
+       bh = gfs2_meta_new(ip->i_gl, bn);
        if (!bh)
                return NULL;
+
        gfs2_trans_add_unrevoke(GFS2_SB(inode), bn, 1);
        gfs2_trans_add_bh(ip->i_gl, bh, 1);
        gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF);
@@ -858,8 +864,8 @@ static int dir_make_exhash(struct inode *inode)
                return -ENOSPC;
        bn = bh->b_blocknr;
 
-       gfs2_assert(sdp, dip->i_di.di_entries < (1 << 16));
-       leaf->lf_entries = cpu_to_be16(dip->i_di.di_entries);
+       gfs2_assert(sdp, dip->i_entries < (1 << 16));
+       leaf->lf_entries = cpu_to_be16(dip->i_entries);
 
        /*  Copy dirents  */
 
@@ -905,9 +911,9 @@ static int dir_make_exhash(struct inode *inode)
        for (x = sdp->sd_hash_ptrs; x--; lp++)
                *lp = cpu_to_be64(bn);
 
-       dip->i_di.di_size = sdp->sd_sb.sb_bsize / 2;
+       dip->i_disksize = sdp->sd_sb.sb_bsize / 2;
        gfs2_add_inode_blocks(&dip->i_inode, 1);
-       dip->i_di.di_flags |= GFS2_DIF_EXHASH;
+       dip->i_diskflags |= GFS2_DIF_EXHASH;
 
        for (x = sdp->sd_hash_ptrs, y = -1; x; x >>= 1, y++) ;
        dip->i_depth = y;
@@ -1082,16 +1088,16 @@ static int dir_double_exhash(struct gfs2_inode *dip)
        int error = 0;
 
        hsize = 1 << dip->i_depth;
-       if (hsize * sizeof(u64) != dip->i_di.di_size) {
+       if (hsize * sizeof(u64) != dip->i_disksize) {
                gfs2_consist_inode(dip);
                return -EIO;
        }
 
        /*  Allocate both the "from" and "to" buffers in one big chunk  */
 
-       buf = kcalloc(3, sdp->sd_hash_bsize, GFP_KERNEL | __GFP_NOFAIL);
+       buf = kcalloc(3, sdp->sd_hash_bsize, GFP_NOFS | __GFP_NOFAIL);
 
-       for (block = dip->i_di.di_size >> sdp->sd_hash_bsize_shift; block--;) {
+       for (block = dip->i_disksize >> sdp->sd_hash_bsize_shift; block--;) {
                error = gfs2_dir_read_data(dip, (char *)buf,
                                            block * sdp->sd_hash_bsize,
                                            sdp->sd_hash_bsize, 1);
@@ -1370,7 +1376,7 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
        unsigned depth = 0;
 
        hsize = 1 << dip->i_depth;
-       if (hsize * sizeof(u64) != dip->i_di.di_size) {
+       if (hsize * sizeof(u64) != dip->i_disksize) {
                gfs2_consist_inode(dip);
                return -EIO;
        }
@@ -1378,7 +1384,7 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
        hash = gfs2_dir_offset2hash(*offset);
        index = hash >> (32 - dip->i_depth);
 
-       lp = kmalloc(sdp->sd_hash_bsize, GFP_KERNEL);
+       lp = kmalloc(sdp->sd_hash_bsize, GFP_NOFS);
        if (!lp)
                return -ENOMEM;
 
@@ -1426,10 +1432,10 @@ int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
        int copied = 0;
        int error;
 
-       if (!dip->i_di.di_entries)
+       if (!dip->i_entries)
                return 0;
 
-       if (dip->i_di.di_flags & GFS2_DIF_EXHASH)
+       if (dip->i_diskflags & GFS2_DIF_EXHASH)
                return dir_e_read(inode, offset, opaque, filldir);
 
        if (!gfs2_is_stuffed(dip)) {
@@ -1443,7 +1449,7 @@ int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
 
        error = -ENOMEM;
        /* 96 is max number of dirents which can be stuffed into an inode */
-       darr = kmalloc(96 * sizeof(struct gfs2_dirent *), GFP_KERNEL);
+       darr = kmalloc(96 * sizeof(struct gfs2_dirent *), GFP_NOFS);
        if (darr) {
                g.pdent = darr;
                g.offset = 0;
@@ -1453,17 +1459,17 @@ int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
                        error = PTR_ERR(dent);
                        goto out;
                }
-               if (dip->i_di.di_entries != g.offset) {
+               if (dip->i_entries != g.offset) {
                        fs_warn(sdp, "Number of entries corrupt in dir %llu, "
-                               "ip->i_di.di_entries (%u) != g.offset (%u)\n",
+                               "ip->i_entries (%u) != g.offset (%u)\n",
                                (unsigned long long)dip->i_no_addr,
-                               dip->i_di.di_entries,
+                               dip->i_entries,
                                g.offset);
                        error = -EIO;
                        goto out;
                }
                error = do_filldir_main(dip, offset, opaque, filldir, darr,
-                                       dip->i_di.di_entries, &copied);
+                                       dip->i_entries, &copied);
 out:
                kfree(darr);
        }
@@ -1612,7 +1618,7 @@ int gfs2_dir_add(struct inode *inode, const struct qstr *name,
                        dent = gfs2_init_dirent(inode, dent, name, bh);
                        gfs2_inum_out(nip, dent);
                        dent->de_type = cpu_to_be16(type);
-                       if (ip->i_di.di_flags & GFS2_DIF_EXHASH) {
+                       if (ip->i_diskflags & GFS2_DIF_EXHASH) {
                                leaf = (struct gfs2_leaf *)bh->b_data;
                                be16_add_cpu(&leaf->lf_entries, 1);
                        }
@@ -1621,14 +1627,14 @@ int gfs2_dir_add(struct inode *inode, const struct qstr *name,
                        if (error)
                                break;
                        gfs2_trans_add_bh(ip->i_gl, bh, 1);
-                       ip->i_di.di_entries++;
+                       ip->i_entries++;
                        ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
                        gfs2_dinode_out(ip, bh->b_data);
                        brelse(bh);
                        error = 0;
                        break;
                }
-               if (!(ip->i_di.di_flags & GFS2_DIF_EXHASH)) {
+               if (!(ip->i_diskflags & GFS2_DIF_EXHASH)) {
                        error = dir_make_exhash(inode);
                        if (error)
                                break;
@@ -1691,7 +1697,7 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name)
        }
 
        dirent_del(dip, bh, prev, dent);
-       if (dip->i_di.di_flags & GFS2_DIF_EXHASH) {
+       if (dip->i_diskflags & GFS2_DIF_EXHASH) {
                struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data;
                u16 entries = be16_to_cpu(leaf->lf_entries);
                if (!entries)
@@ -1704,10 +1710,10 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name)
        if (error)
                return error;
 
-       if (!dip->i_di.di_entries)
+       if (!dip->i_entries)
                gfs2_consist_inode(dip);
        gfs2_trans_add_bh(dip->i_gl, bh, 1);
-       dip->i_di.di_entries--;
+       dip->i_entries--;
        dip->i_inode.i_mtime = dip->i_inode.i_ctime = CURRENT_TIME;
        gfs2_dinode_out(dip, bh->b_data);
        brelse(bh);
@@ -1748,7 +1754,7 @@ int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
        gfs2_inum_out(nip, dent);
        dent->de_type = cpu_to_be16(new_type);
 
-       if (dip->i_di.di_flags & GFS2_DIF_EXHASH) {
+       if (dip->i_diskflags & GFS2_DIF_EXHASH) {
                brelse(bh);
                error = gfs2_meta_inode_buffer(dip, &bh);
                if (error)
@@ -1784,12 +1790,12 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data)
        int error = 0;
 
        hsize = 1 << dip->i_depth;
-       if (hsize * sizeof(u64) != dip->i_di.di_size) {
+       if (hsize * sizeof(u64) != dip->i_disksize) {
                gfs2_consist_inode(dip);
                return -EIO;
        }
 
-       lp = kmalloc(sdp->sd_hash_bsize, GFP_KERNEL);
+       lp = kmalloc(sdp->sd_hash_bsize, GFP_NOFS);
        if (!lp)
                return -ENOMEM;
 
@@ -1864,7 +1870,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len,
 
        memset(&rlist, 0, sizeof(struct gfs2_rgrp_list));
 
-       ht = kzalloc(size, GFP_KERNEL);
+       ht = kzalloc(size, GFP_NOFS);
        if (!ht)
                return -ENOMEM;