GFS2: Fix incorrent statfs consistency check
[safe/jmp/linux-2.6] / fs / gfs2 / eattr.c
index bd5ca60..07ea952 100644 (file)
@@ -7,14 +7,12 @@
  * of the GNU General Public License version 2.
  */
 
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/completion.h>
 #include <linux/buffer_head.h>
 #include <linux/xattr.h>
 #include <linux/gfs2_ondisk.h>
-#include <linux/lm_interface.h>
 #include <asm/uaccess.h>
 
 #include "gfs2.h"
@@ -112,14 +110,14 @@ fail:
 static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data)
 {
        struct buffer_head *bh, *eabh;
-       u64 *eablk, *end;
+       __be64 *eablk, *end;
        int error;
 
-       error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT, &bh);
+       error = gfs2_meta_read(ip->i_gl, ip->i_eattr, DIO_WAIT, &bh);
        if (error)
                return error;
 
-       if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT)) {
+       if (!(ip->i_diskflags & GFS2_DIF_EA_INDIRECT)) {
                error = ea_foreach_i(ip, bh, ea_call, data);
                goto out;
        }
@@ -129,7 +127,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data)
                goto out;
        }
 
-       eablk = (u64 *)(bh->b_data + sizeof(struct gfs2_meta_header));
+       eablk = (__be64 *)(bh->b_data + sizeof(struct gfs2_meta_header));
        end = eablk + GFS2_SB(&ip->i_inode)->sd_inptrs;
 
        for (; eablk < end; eablk++) {
@@ -224,7 +222,8 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
        struct gfs2_rgrpd *rgd;
        struct gfs2_holder rg_gh;
        struct buffer_head *dibh;
-       u64 *dataptrs, bn = 0;
+       __be64 *dataptrs;
+       u64 bn = 0;
        u64 bstart = 0;
        unsigned int blen = 0;
        unsigned int blks = 0;
@@ -254,7 +253,7 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
        if (error)
                return error;
 
-       error = gfs2_trans_begin(sdp, rgd->rd_ri.ri_length + RES_DINODE +
+       error = gfs2_trans_begin(sdp, rgd->rd_length + RES_DINODE +
                                 RES_EATTR + RES_STATFS + RES_QUOTA, blks);
        if (error)
                goto out_gunlock;
@@ -277,9 +276,7 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
                }
 
                *dataptrs = 0;
-               if (!ip->i_di.di_blocks)
-                       gfs2_consist_inode(ip);
-               ip->i_di.di_blocks--;
+               gfs2_add_inode_blocks(&ip->i_inode, -1);
        }
        if (bstart)
                gfs2_free_meta(ip, bstart, blen);
@@ -299,9 +296,9 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
 
        error = gfs2_meta_inode_buffer(ip, &dibh);
        if (!error) {
-               ip->i_di.di_ctime = get_seconds();
+               ip->i_inode.i_ctime = CURRENT_TIME;
                gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-               gfs2_dinode_out(&ip->i_di, dibh->b_data);
+               gfs2_dinode_out(ip, dibh->b_data);
                brelse(dibh);
        }
 
@@ -320,6 +317,8 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
        int error;
 
        al = gfs2_alloc_get(ip);
+       if (!al)
+               return -ENOMEM;
 
        error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
        if (error)
@@ -414,7 +413,7 @@ int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er)
        if (error)
                return error;
 
-       if (ip->i_di.di_eattr) {
+       if (ip->i_eattr) {
                struct ea_list ei = { .ei_er = er, .ei_size = 0 };
 
                error = ea_foreach(ip, ea_list_i, &ei);
@@ -444,11 +443,11 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
        struct buffer_head **bh;
        unsigned int amount = GFS2_EA_DATA_LEN(ea);
        unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize);
-       u64 *dataptrs = GFS2_EA2DATAPTRS(ea);
+       __be64 *dataptrs = GFS2_EA2DATAPTRS(ea);
        unsigned int x;
        int error = 0;
 
-       bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_KERNEL);
+       bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS);
        if (!bh)
                return -ENOMEM;
 
@@ -514,7 +513,7 @@ int gfs2_ea_get_i(struct gfs2_inode *ip, struct gfs2_ea_request *er)
        struct gfs2_ea_location el;
        int error;
 
-       if (!ip->i_di.di_eattr)
+       if (!ip->i_eattr)
                return -ENODATA;
 
        error = gfs2_ea_find(ip, er, &el);
@@ -581,10 +580,14 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
        struct gfs2_ea_header *ea;
+       unsigned int n = 1;
        u64 block;
+       int error;
 
-       block = gfs2_alloc_meta(ip);
-
+       error = gfs2_alloc_block(ip, &block, &n);
+       if (error)
+               return error;
+       gfs2_trans_add_unrevoke(sdp, block, 1);
        *bhp = gfs2_meta_new(ip->i_gl, block);
        gfs2_trans_add_bh(ip->i_gl, *bhp, 1);
        gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA);
@@ -596,7 +599,7 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp)
        ea->ea_flags = GFS2_EAFLAG_LAST;
        ea->ea_num_ptrs = 0;
 
-       ip->i_di.di_blocks++;
+       gfs2_add_inode_blocks(&ip->i_inode, 1);
 
        return 0;
 }
@@ -617,6 +620,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
                    struct gfs2_ea_request *er)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
+       int error;
 
        ea->ea_data_len = cpu_to_be32(er->er_data_len);
        ea->ea_name_len = er->er_name_len;
@@ -629,7 +633,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
                ea->ea_num_ptrs = 0;
                memcpy(GFS2_EA2DATA(ea), er->er_data, er->er_data_len);
        } else {
-               u64 *dataptr = GFS2_EA2DATAPTRS(ea);
+               __be64 *dataptr = GFS2_EA2DATAPTRS(ea);
                const char *data = er->er_data;
                unsigned int data_len = er->er_data_len;
                unsigned int copy;
@@ -640,14 +644,17 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
                        struct buffer_head *bh;
                        u64 block;
                        int mh_size = sizeof(struct gfs2_meta_header);
+                       unsigned int n = 1;
 
-                       block = gfs2_alloc_meta(ip);
-
+                       error = gfs2_alloc_block(ip, &block, &n);
+                       if (error)
+                               return error;
+                       gfs2_trans_add_unrevoke(sdp, block, 1);
                        bh = gfs2_meta_new(ip->i_gl, block);
                        gfs2_trans_add_bh(ip->i_gl, bh, 1);
                        gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED);
 
-                       ip->i_di.di_blocks++;
+                       gfs2_add_inode_blocks(&ip->i_inode, 1);
 
                        copy = data_len > sdp->sd_jbsize ? sdp->sd_jbsize :
                                                           data_len;
@@ -681,15 +688,13 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
        int error;
 
        al = gfs2_alloc_get(ip);
+       if (!al)
+               return -ENOMEM;
 
-       error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
+       error = gfs2_quota_lock_check(ip);
        if (error)
                goto out;
 
-       error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid);
-       if (error)
-               goto out_gunlock_q;
-
        al->al_requested = blks;
 
        error = gfs2_inplace_reserve(ip);
@@ -697,7 +702,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
                goto out_gunlock_q;
 
        error = gfs2_trans_begin(GFS2_SB(&ip->i_inode),
-                                blks + al->al_rgd->rd_ri.ri_length +
+                                blks + al->al_rgd->rd_length +
                                 RES_DINODE + RES_STATFS + RES_QUOTA, 0);
        if (error)
                goto out_ipres;
@@ -710,13 +715,13 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
        if (!error) {
                if (er->er_flags & GFS2_ERF_MODE) {
                        gfs2_assert_withdraw(GFS2_SB(&ip->i_inode),
-                                           (ip->i_di.di_mode & S_IFMT) ==
+                                           (ip->i_inode.i_mode & S_IFMT) ==
                                            (er->er_mode & S_IFMT));
-                       ip->i_di.di_mode = er->er_mode;
+                       ip->i_inode.i_mode = er->er_mode;
                }
-               ip->i_di.di_ctime = get_seconds();
+               ip->i_inode.i_ctime = CURRENT_TIME;
                gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-               gfs2_dinode_out(&ip->i_di, dibh->b_data);
+               gfs2_dinode_out(ip, dibh->b_data);
                brelse(dibh);
        }
 
@@ -741,7 +746,7 @@ static int ea_init_i(struct gfs2_inode *ip, struct gfs2_ea_request *er,
        if (error)
                return error;
 
-       ip->i_di.di_eattr = bh->b_blocknr;
+       ip->i_eattr = bh->b_blocknr;
        error = ea_write(ip, GFS2_EA_BH2FIRST(bh), er);
 
        brelse(bh);
@@ -846,12 +851,12 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh,
 
        if (er->er_flags & GFS2_ERF_MODE) {
                gfs2_assert_withdraw(GFS2_SB(&ip->i_inode),
-                       (ip->i_di.di_mode & S_IFMT) == (er->er_mode & S_IFMT));
-               ip->i_di.di_mode = er->er_mode;
+                       (ip->i_inode.i_mode & S_IFMT) == (er->er_mode & S_IFMT));
+               ip->i_inode.i_mode = er->er_mode;
        }
-       ip->i_di.di_ctime = get_seconds();
+       ip->i_inode.i_ctime = CURRENT_TIME;
        gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-       gfs2_dinode_out(&ip->i_di, dibh->b_data);
+       gfs2_dinode_out(ip, dibh->b_data);
        brelse(dibh);
 out:
        gfs2_trans_end(GFS2_SB(&ip->i_inode));
@@ -931,14 +936,14 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
        struct buffer_head *indbh, *newbh;
-       u64 *eablk;
+       __be64 *eablk;
        int error;
        int mh_size = sizeof(struct gfs2_meta_header);
 
-       if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) {
-               u64 *end;
+       if (ip->i_diskflags & GFS2_DIF_EA_INDIRECT) {
+               __be64 *end;
 
-               error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT,
+               error = gfs2_meta_read(ip->i_gl, ip->i_eattr, DIO_WAIT,
                                       &indbh);
                if (error)
                        return error;
@@ -948,7 +953,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
                        goto out;
                }
 
-               eablk = (u64 *)(indbh->b_data + mh_size);
+               eablk = (__be64 *)(indbh->b_data + mh_size);
                end = eablk + sdp->sd_inptrs;
 
                for (; eablk < end; eablk++)
@@ -963,19 +968,21 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
                gfs2_trans_add_bh(ip->i_gl, indbh, 1);
        } else {
                u64 blk;
-
-               blk = gfs2_alloc_meta(ip);
-
+               unsigned int n = 1;
+               error = gfs2_alloc_block(ip, &blk, &n);
+               if (error)
+                       return error;
+               gfs2_trans_add_unrevoke(sdp, blk, 1);
                indbh = gfs2_meta_new(ip->i_gl, blk);
                gfs2_trans_add_bh(ip->i_gl, indbh, 1);
                gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN);
                gfs2_buffer_clear_tail(indbh, mh_size);
 
-               eablk = (u64 *)(indbh->b_data + mh_size);
-               *eablk = cpu_to_be64(ip->i_di.di_eattr);
-               ip->i_di.di_eattr = blk;
-               ip->i_di.di_flags |= GFS2_DIF_EA_INDIRECT;
-               ip->i_di.di_blocks++;
+               eablk = (__be64 *)(indbh->b_data + mh_size);
+               *eablk = cpu_to_be64(ip->i_eattr);
+               ip->i_eattr = blk;
+               ip->i_diskflags |= GFS2_DIF_EA_INDIRECT;
+               gfs2_add_inode_blocks(&ip->i_inode, 1);
 
                eablk++;
        }
@@ -1015,7 +1022,7 @@ static int ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er,
        if (error)
                return error;
 
-       if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT))
+       if (!(ip->i_diskflags & GFS2_DIF_EA_INDIRECT))
                blks++;
        if (GFS2_EAREQ_SIZE_STUFFED(er) > GFS2_SB(&ip->i_inode)->sd_jbsize)
                blks += DIV_ROUND_UP(er->er_data_len, GFS2_SB(&ip->i_inode)->sd_jbsize);
@@ -1040,7 +1047,7 @@ int gfs2_ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er)
        struct gfs2_ea_location el;
        int error;
 
-       if (!ip->i_di.di_eattr) {
+       if (!ip->i_eattr) {
                if (er->er_flags & XATTR_REPLACE)
                        return -ENODATA;
                return ea_init(ip, er);
@@ -1051,7 +1058,7 @@ int gfs2_ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er)
                return error;
 
        if (el.el_ea) {
-               if (ip->i_di.di_flags & GFS2_DIF_APPENDONLY) {
+               if (ip->i_diskflags & GFS2_DIF_APPENDONLY) {
                        brelse(el.el_bh);
                        return -EPERM;
                }
@@ -1129,11 +1136,11 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el)
 
        error = gfs2_meta_inode_buffer(ip, &dibh);
        if (!error) {
-               ip->i_di.di_ctime = get_seconds();
+               ip->i_inode.i_ctime = CURRENT_TIME;
                gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-               gfs2_dinode_out(&ip->i_di, dibh->b_data);
+               gfs2_dinode_out(ip, dibh->b_data);
                brelse(dibh);
-       }       
+       }
 
        gfs2_trans_end(GFS2_SB(&ip->i_inode));
 
@@ -1145,7 +1152,7 @@ int gfs2_ea_remove_i(struct gfs2_inode *ip, struct gfs2_ea_request *er)
        struct gfs2_ea_location el;
        int error;
 
-       if (!ip->i_di.di_eattr)
+       if (!ip->i_eattr)
                return -ENODATA;
 
        error = gfs2_ea_find(ip, er, &el);
@@ -1202,11 +1209,11 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip,
        struct buffer_head **bh;
        unsigned int amount = GFS2_EA_DATA_LEN(ea);
        unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize);
-       u64 *dataptrs = GFS2_EA2DATAPTRS(ea);
+       __be64 *dataptrs = GFS2_EA2DATAPTRS(ea);
        unsigned int x;
        int error;
 
-       bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_KERNEL);
+       bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS);
        if (!bh)
                return -ENOMEM;
 
@@ -1284,9 +1291,8 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el,
        if (!error) {
                error = inode_setattr(&ip->i_inode, attr);
                gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error);
-               gfs2_inode_attr_out(ip);
                gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-               gfs2_dinode_out(&ip->i_di, dibh->b_data);
+               gfs2_dinode_out(ip, dibh->b_data);
                brelse(dibh);
        }
 
@@ -1300,7 +1306,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
        struct gfs2_rgrp_list rlist;
        struct buffer_head *indbh, *dibh;
-       u64 *eablk, *end;
+       __be64 *eablk, *end;
        unsigned int rg_blocks = 0;
        u64 bstart = 0;
        unsigned int blen = 0;
@@ -1310,7 +1316,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
 
        memset(&rlist, 0, sizeof(struct gfs2_rgrp_list));
 
-       error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT, &indbh);
+       error = gfs2_meta_read(ip->i_gl, ip->i_eattr, DIO_WAIT, &indbh);
        if (error)
                return error;
 
@@ -1319,7 +1325,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
                goto out;
        }
 
-       eablk = (u64 *)(indbh->b_data + sizeof(struct gfs2_meta_header));
+       eablk = (__be64 *)(indbh->b_data + sizeof(struct gfs2_meta_header));
        end = eablk + sdp->sd_inptrs;
 
        for (; eablk < end; eablk++) {
@@ -1344,12 +1350,12 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
        else
                goto out;
 
-       gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE, 0);
+       gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE);
 
        for (x = 0; x < rlist.rl_rgrps; x++) {
                struct gfs2_rgrpd *rgd;
                rgd = rlist.rl_ghs[x].gh_gl->gl_object;
-               rg_blocks += rgd->rd_ri.ri_length;
+               rg_blocks += rgd->rd_length;
        }
 
        error = gfs2_glock_nq_m(rlist.rl_rgrps, rlist.rl_ghs);
@@ -1363,7 +1369,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
 
        gfs2_trans_add_bh(ip->i_gl, indbh, 1);
 
-       eablk = (u64 *)(indbh->b_data + sizeof(struct gfs2_meta_header));
+       eablk = (__be64 *)(indbh->b_data + sizeof(struct gfs2_meta_header));
        bstart = 0;
        blen = 0;
 
@@ -1384,19 +1390,17 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
                }
 
                *eablk = 0;
-               if (!ip->i_di.di_blocks)
-                       gfs2_consist_inode(ip);
-               ip->i_di.di_blocks--;
+               gfs2_add_inode_blocks(&ip->i_inode, -1);
        }
        if (bstart)
                gfs2_free_meta(ip, bstart, blen);
 
-       ip->i_di.di_flags &= ~GFS2_DIF_EA_INDIRECT;
+       ip->i_diskflags &= ~GFS2_DIF_EA_INDIRECT;
 
        error = gfs2_meta_inode_buffer(ip, &dibh);
        if (!error) {
                gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-               gfs2_dinode_out(&ip->i_di, dibh->b_data);
+               gfs2_dinode_out(ip, dibh->b_data);
                brelse(dibh);
        }
 
@@ -1414,12 +1418,12 @@ out:
 static int ea_dealloc_block(struct gfs2_inode *ip)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_rgrpd *rgd;
        struct buffer_head *dibh;
        int error;
 
-       rgd = gfs2_blk2rgrpd(sdp, ip->i_di.di_eattr);
+       rgd = gfs2_blk2rgrpd(sdp, ip->i_eattr);
        if (!rgd) {
                gfs2_consist_inode(ip);
                return -EIO;
@@ -1435,17 +1439,15 @@ static int ea_dealloc_block(struct gfs2_inode *ip)
        if (error)
                goto out_gunlock;
 
-       gfs2_free_meta(ip, ip->i_di.di_eattr, 1);
+       gfs2_free_meta(ip, ip->i_eattr, 1);
 
-       ip->i_di.di_eattr = 0;
-       if (!ip->i_di.di_blocks)
-               gfs2_consist_inode(ip);
-       ip->i_di.di_blocks--;
+       ip->i_eattr = 0;
+       gfs2_add_inode_blocks(&ip->i_inode, -1);
 
        error = gfs2_meta_inode_buffer(ip, &dibh);
        if (!error) {
                gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-               gfs2_dinode_out(&ip->i_di, dibh->b_data);
+               gfs2_dinode_out(ip, dibh->b_data);
                brelse(dibh);
        }
 
@@ -1469,6 +1471,8 @@ int gfs2_ea_dealloc(struct gfs2_inode *ip)
        int error;
 
        al = gfs2_alloc_get(ip);
+       if (!al)
+               return -ENOMEM;
 
        error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
        if (error)
@@ -1482,7 +1486,7 @@ int gfs2_ea_dealloc(struct gfs2_inode *ip)
        if (error)
                goto out_rindex;
 
-       if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) {
+       if (ip->i_diskflags & GFS2_DIF_EA_INDIRECT) {
                error = ea_dealloc_indirect(ip);
                if (error)
                        goto out_rindex;