[PATCH] switch a bunch of LSM hooks from nameidata to path
[safe/jmp/linux-2.6] / fs / gfs2 / eattr.c
index a65a4cc..e3f76f4 100644 (file)
@@ -7,7 +7,6 @@
  * of the GNU General Public License version 2.
  */
 
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/completion.h>
@@ -112,7 +111,7 @@ 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);
@@ -129,7 +128,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 +223,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 +254,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 +277,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 +297,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 +318,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)
@@ -444,11 +444,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;
 
@@ -581,10 +581,11 @@ 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;
 
-       block = gfs2_alloc_meta(ip);
-
+       block = gfs2_alloc_block(ip, &n);
+       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 +597,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;
 }
@@ -629,7 +630,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 +641,15 @@ 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);
-
+                       block = gfs2_alloc_block(ip, &n);
+                       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 +683,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 +697,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 +710,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);
        }
 
@@ -846,12 +846,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,12 +931,12 @@ 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;
+               __be64 *end;
 
                error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT,
                                       &indbh);
@@ -948,7 +948,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 +963,19 @@ 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;
+               blk = gfs2_alloc_block(ip, &n);
+               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 = (__be64 *)(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++;
+               gfs2_add_inode_blocks(&ip->i_inode, 1);
 
                eablk++;
        }
@@ -1129,9 +1129,9 @@ 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);
        }
 
@@ -1202,11 +1202,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 +1284,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 +1299,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;
@@ -1319,7 +1318,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 +1343,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 +1362,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,9 +1383,7 @@ 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);
@@ -1396,7 +1393,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
        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,7 +1411,7 @@ 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;
@@ -1438,14 +1435,12 @@ static int ea_dealloc_block(struct gfs2_inode *ip)
        gfs2_free_meta(ip, ip->i_di.di_eattr, 1);
 
        ip->i_di.di_eattr = 0;
-       if (!ip->i_di.di_blocks)
-               gfs2_consist_inode(ip);
-       ip->i_di.di_blocks--;
+       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 +1464,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)