diff options
Diffstat (limited to 'fs/gfs2/rgrp.c')
-rw-r--r-- | fs/gfs2/rgrp.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index ce48c4594ec8..708c287e1d0e 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "inode.h" | 31 | #include "inode.h" |
32 | 32 | ||
33 | #define BFITNOENT ((u32)~0) | 33 | #define BFITNOENT ((u32)~0) |
34 | #define NO_BLOCK ((u64)~0) | ||
34 | 35 | ||
35 | /* | 36 | /* |
36 | * These routines are used by the resource group routines (rgrp.c) | 37 | * These routines are used by the resource group routines (rgrp.c) |
@@ -116,8 +117,7 @@ static unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, | |||
116 | * @buffer: the buffer that holds the bitmaps | 117 | * @buffer: the buffer that holds the bitmaps |
117 | * @buflen: the length (in bytes) of the buffer | 118 | * @buflen: the length (in bytes) of the buffer |
118 | * @goal: start search at this block's bit-pair (within @buffer) | 119 | * @goal: start search at this block's bit-pair (within @buffer) |
119 | * @old_state: GFS2_BLKST_XXX the state of the block we're looking for; | 120 | * @old_state: GFS2_BLKST_XXX the state of the block we're looking for. |
120 | * bit 0 = alloc(1)/free(0), bit 1 = meta(1)/data(0) | ||
121 | * | 121 | * |
122 | * Scope of @goal and returned block number is only within this bitmap buffer, | 122 | * Scope of @goal and returned block number is only within this bitmap buffer, |
123 | * not entire rgrp or filesystem. @buffer will be offset from the actual | 123 | * not entire rgrp or filesystem. @buffer will be offset from the actual |
@@ -137,9 +137,13 @@ static u32 gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, | |||
137 | byte = buffer + (goal / GFS2_NBBY); | 137 | byte = buffer + (goal / GFS2_NBBY); |
138 | bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE; | 138 | bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE; |
139 | end = buffer + buflen; | 139 | end = buffer + buflen; |
140 | alloc = (old_state & 1) ? 0 : 0x55; | 140 | alloc = (old_state == GFS2_BLKST_FREE) ? 0x55 : 0; |
141 | 141 | ||
142 | while (byte < end) { | 142 | while (byte < end) { |
143 | /* If we're looking for a free block we can eliminate all | ||
144 | bitmap settings with 0x55, which represents four data | ||
145 | blocks in a row. If we're looking for a data block, we can | ||
146 | eliminate 0x00 which corresponds to four free blocks. */ | ||
143 | if ((*byte & 0x55) == alloc) { | 147 | if ((*byte & 0x55) == alloc) { |
144 | blk += (8 - bit) >> 1; | 148 | blk += (8 - bit) >> 1; |
145 | 149 | ||
@@ -859,23 +863,28 @@ static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_alloc *al) | |||
859 | static struct inode *try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked) | 863 | static struct inode *try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked) |
860 | { | 864 | { |
861 | struct inode *inode; | 865 | struct inode *inode; |
862 | u32 goal = 0; | 866 | u32 goal = 0, block; |
863 | u64 no_addr; | 867 | u64 no_addr; |
868 | struct gfs2_sbd *sdp = rgd->rd_sbd; | ||
864 | 869 | ||
865 | for(;;) { | 870 | for(;;) { |
866 | if (goal >= rgd->rd_data) | 871 | if (goal >= rgd->rd_data) |
867 | break; | 872 | break; |
868 | goal = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, | 873 | down_write(&sdp->sd_log_flush_lock); |
869 | GFS2_BLKST_UNLINKED); | 874 | block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, |
870 | if (goal == BFITNOENT) | 875 | GFS2_BLKST_UNLINKED); |
876 | up_write(&sdp->sd_log_flush_lock); | ||
877 | if (block == BFITNOENT) | ||
871 | break; | 878 | break; |
872 | no_addr = goal + rgd->rd_data0; | 879 | /* rgblk_search can return a block < goal, so we need to |
880 | keep it marching forward. */ | ||
881 | no_addr = block + rgd->rd_data0; | ||
873 | goal++; | 882 | goal++; |
874 | if (no_addr < *last_unlinked) | 883 | if (*last_unlinked != NO_BLOCK && no_addr <= *last_unlinked) |
875 | continue; | 884 | continue; |
876 | *last_unlinked = no_addr; | 885 | *last_unlinked = no_addr; |
877 | inode = gfs2_inode_lookup(rgd->rd_sbd->sd_vfs, DT_UNKNOWN, | 886 | inode = gfs2_inode_lookup(rgd->rd_sbd->sd_vfs, DT_UNKNOWN, |
878 | no_addr, -1); | 887 | no_addr, -1, 1); |
879 | if (!IS_ERR(inode)) | 888 | if (!IS_ERR(inode)) |
880 | return inode; | 889 | return inode; |
881 | } | 890 | } |
@@ -1152,7 +1161,7 @@ int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line) | |||
1152 | struct gfs2_alloc *al = &ip->i_alloc; | 1161 | struct gfs2_alloc *al = &ip->i_alloc; |
1153 | struct inode *inode; | 1162 | struct inode *inode; |
1154 | int error = 0; | 1163 | int error = 0; |
1155 | u64 last_unlinked = 0; | 1164 | u64 last_unlinked = NO_BLOCK; |
1156 | 1165 | ||
1157 | if (gfs2_assert_warn(sdp, al->al_requested)) | 1166 | if (gfs2_assert_warn(sdp, al->al_requested)) |
1158 | return -EINVAL; | 1167 | return -EINVAL; |
@@ -1289,7 +1298,9 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, | |||
1289 | allocatable block anywhere else, we want to be able wrap around and | 1298 | allocatable block anywhere else, we want to be able wrap around and |
1290 | search in the first part of our first-searched bit block. */ | 1299 | search in the first part of our first-searched bit block. */ |
1291 | for (x = 0; x <= length; x++) { | 1300 | for (x = 0; x <= length; x++) { |
1292 | if (bi->bi_clone) | 1301 | /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone |
1302 | bitmaps, so we must search the originals for that. */ | ||
1303 | if (old_state != GFS2_BLKST_UNLINKED && bi->bi_clone) | ||
1293 | blk = gfs2_bitfit(rgd, bi->bi_clone + bi->bi_offset, | 1304 | blk = gfs2_bitfit(rgd, bi->bi_clone + bi->bi_offset, |
1294 | bi->bi_len, goal, old_state); | 1305 | bi->bi_len, goal, old_state); |
1295 | else | 1306 | else |
@@ -1305,9 +1316,7 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, | |||
1305 | goal = 0; | 1316 | goal = 0; |
1306 | } | 1317 | } |
1307 | 1318 | ||
1308 | if (old_state != new_state) { | 1319 | if (blk != BFITNOENT && old_state != new_state) { |
1309 | gfs2_assert_withdraw(rgd->rd_sbd, blk != BFITNOENT); | ||
1310 | |||
1311 | gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); | 1320 | gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); |
1312 | gfs2_setbit(rgd, bi->bi_bh->b_data + bi->bi_offset, | 1321 | gfs2_setbit(rgd, bi->bi_bh->b_data + bi->bi_offset, |
1313 | bi->bi_len, blk, new_state); | 1322 | bi->bi_len, blk, new_state); |