aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/bmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/gfs2/bmap.c')
-rw-r--r--fs/gfs2/bmap.c59
1 files changed, 12 insertions, 47 deletions
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index bd194f645c52..4efcd8a39e98 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -18,12 +18,12 @@
18#include "bmap.h" 18#include "bmap.h"
19#include "glock.h" 19#include "glock.h"
20#include "inode.h" 20#include "inode.h"
21#include "jdata.h"
22#include "meta_io.h" 21#include "meta_io.h"
23#include "page.h" 22#include "page.h"
24#include "quota.h" 23#include "quota.h"
25#include "rgrp.h" 24#include "rgrp.h"
26#include "trans.h" 25#include "trans.h"
26#include "dir.h"
27 27
28/* This doesn't need to be that large as max 64 bit pointers in a 4k 28/* This doesn't need to be that large as max 64 bit pointers in a 4k
29 * block is 512, so __u16 is fine for that. It saves stack space to 29 * block is 512, so __u16 is fine for that. It saves stack space to
@@ -90,7 +90,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer,
90{ 90{
91 struct buffer_head *bh, *dibh; 91 struct buffer_head *bh, *dibh;
92 uint64_t block = 0; 92 uint64_t block = 0;
93 int journaled = gfs2_is_jdata(ip); 93 int isdir = gfs2_is_dir(ip);
94 int error; 94 int error;
95 95
96 down_write(&ip->i_rw_mutex); 96 down_write(&ip->i_rw_mutex);
@@ -103,10 +103,10 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer,
103 /* Get a free block, fill it with the stuffed data, 103 /* Get a free block, fill it with the stuffed data,
104 and write it out to disk */ 104 and write it out to disk */
105 105
106 if (journaled) { 106 if (isdir) {
107 block = gfs2_alloc_meta(ip); 107 block = gfs2_alloc_meta(ip);
108 108
109 error = gfs2_jdata_get_buffer(ip, block, 1, &bh); 109 error = gfs2_dir_get_buffer(ip, block, 1, &bh);
110 if (error) 110 if (error)
111 goto out_brelse; 111 goto out_brelse;
112 gfs2_buffer_copy_tail(bh, 112 gfs2_buffer_copy_tail(bh,
@@ -168,7 +168,7 @@ static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size)
168 if (ip->i_di.di_size > size) 168 if (ip->i_di.di_size > size)
169 size = ip->i_di.di_size; 169 size = ip->i_di.di_size;
170 170
171 if (gfs2_is_jdata(ip)) { 171 if (gfs2_is_dir(ip)) {
172 arr = sdp->sd_jheightsize; 172 arr = sdp->sd_jheightsize;
173 max = sdp->sd_max_jheight; 173 max = sdp->sd_max_jheight;
174 } else { 174 } else {
@@ -377,7 +377,7 @@ static void lookup_block(struct gfs2_inode *ip, struct buffer_head *bh,
377 return; 377 return;
378 378
379 if (height == ip->i_di.di_height - 1 && 379 if (height == ip->i_di.di_height - 1 &&
380 !gfs2_is_jdata(ip)) 380 !gfs2_is_dir(ip))
381 *block = gfs2_alloc_data(ip); 381 *block = gfs2_alloc_data(ip);
382 else 382 else
383 *block = gfs2_alloc_meta(ip); 383 *block = gfs2_alloc_meta(ip);
@@ -430,7 +430,7 @@ int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
430 if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) 430 if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip)))
431 goto out; 431 goto out;
432 432
433 bsize = (gfs2_is_jdata(ip)) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize; 433 bsize = (gfs2_is_dir(ip)) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize;
434 434
435 height = calc_tree_height(ip, (lblock + 1) * bsize); 435 height = calc_tree_height(ip, (lblock + 1) * bsize);
436 if (ip->i_di.di_height < height) { 436 if (ip->i_di.di_height < height) {
@@ -618,7 +618,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
618 sm->sm_first = 0; 618 sm->sm_first = 0;
619 } 619 }
620 620
621 metadata = (height != ip->i_di.di_height - 1) || gfs2_is_jdata(ip); 621 metadata = (height != ip->i_di.di_height - 1);
622 if (metadata) 622 if (metadata)
623 revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs; 623 revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs;
624 624
@@ -814,33 +814,6 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size)
814 return error; 814 return error;
815} 815}
816 816
817static int truncator_journaled(struct gfs2_inode *ip, uint64_t size)
818{
819 uint64_t lbn, dbn;
820 uint32_t off;
821 struct buffer_head *bh;
822 int new = 0;
823 int error;
824
825 lbn = size;
826 off = do_div(lbn, ip->i_sbd->sd_jbsize);
827
828 error = gfs2_block_map(ip, lbn, &new, &dbn, NULL);
829 if (error || !dbn)
830 return error;
831
832 error = gfs2_jdata_get_buffer(ip, dbn, 0, &bh);
833 if (error)
834 return error;
835
836 gfs2_trans_add_bh(ip->i_gl, bh, 1);
837 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header) + off);
838
839 brelse(bh);
840
841 return 0;
842}
843
844static int trunc_start(struct gfs2_inode *ip, uint64_t size) 817static int trunc_start(struct gfs2_inode *ip, uint64_t size)
845{ 818{
846 struct gfs2_sbd *sdp = ip->i_sbd; 819 struct gfs2_sbd *sdp = ip->i_sbd;
@@ -866,12 +839,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size)
866 error = 1; 839 error = 1;
867 840
868 } else { 841 } else {
869 if (journaled) { 842 if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1))
870 uint64_t junk = size;
871 /* we're just interested in the modulus */
872 if (do_div(junk, sdp->sd_jbsize))
873 error = truncator_journaled(ip, size);
874 } else if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1))
875 error = gfs2_block_truncate_page(ip->i_vnode->i_mapping); 843 error = gfs2_block_truncate_page(ip->i_vnode->i_mapping);
876 844
877 if (!error) { 845 if (!error) {
@@ -900,10 +868,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size)
900 868
901 if (!size) 869 if (!size)
902 lblock = 0; 870 lblock = 0;
903 else if (gfs2_is_jdata(ip)) { 871 else
904 lblock = size - 1;
905 do_div(lblock, ip->i_sbd->sd_jbsize);
906 } else
907 lblock = (size - 1) >> ip->i_sbd->sd_sb.sb_bsize_shift; 872 lblock = (size - 1) >> ip->i_sbd->sd_sb.sb_bsize_shift;
908 873
909 find_metapath(ip, lblock, &mp); 874 find_metapath(ip, lblock, &mp);
@@ -1051,7 +1016,7 @@ void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len,
1051 struct gfs2_sbd *sdp = ip->i_sbd; 1016 struct gfs2_sbd *sdp = ip->i_sbd;
1052 unsigned int tmp; 1017 unsigned int tmp;
1053 1018
1054 if (gfs2_is_jdata(ip)) { 1019 if (gfs2_is_dir(ip)) {
1055 *data_blocks = DIV_RU(len, sdp->sd_jbsize) + 2; 1020 *data_blocks = DIV_RU(len, sdp->sd_jbsize) + 2;
1056 *ind_blocks = 3 * (sdp->sd_max_jheight - 1); 1021 *ind_blocks = 3 * (sdp->sd_max_jheight - 1);
1057 } else { 1022 } else {
@@ -1096,7 +1061,7 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset,
1096 return 0; 1061 return 0;
1097 } 1062 }
1098 1063
1099 if (gfs2_is_jdata(ip)) { 1064 if (gfs2_is_dir(ip)) {
1100 unsigned int bsize = sdp->sd_jbsize; 1065 unsigned int bsize = sdp->sd_jbsize;
1101 lblock = offset; 1066 lblock = offset;
1102 do_div(lblock, bsize); 1067 do_div(lblock, bsize);