aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/rgrp.c
diff options
context:
space:
mode:
authorBob Peterson <rpeterso@redhat.com>2011-11-18 10:58:32 -0500
committerSteven Whitehouse <swhiteho@redhat.com>2011-11-21 05:04:09 -0500
commit6e87ed0fc93ffbe2aec296e6912b1dcb19034d6c (patch)
tree4f4ac522d34f35de3e3671996ddc35977aaa49ad /fs/gfs2/rgrp.c
parent4442f2e03ed9646664c94e197e637b03324a6664 (diff)
GFS2: move toward a generic multi-block allocator
This patch is a revision of the one I previously posted. I tried to integrate all the suggestions Steve gave. The purpose of the patch is to change function gfs2_alloc_block (allocate either a dinode block or an extent of data blocks) to a more generic gfs2_alloc_blocks function that can allocate both a dinode _and_ an extent of data blocks in the same call. This will ultimately help us create a multi-block reservation scheme to reduce file fragmentation. This patch moves more toward a generic multi-block allocator that takes a pointer to the number of data blocks to allocate, plus whether or not to allocate a dinode. In theory, it could be called to allocate (1) a single dinode block, (2) a group of one or more data blocks, or (3) a dinode plus several data blocks. Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/rgrp.c')
-rw-r--r--fs/gfs2/rgrp.c59
1 files changed, 29 insertions, 30 deletions
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 855597abc5e7..b8935afab20b 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -65,8 +65,8 @@ static const char valid_change[16] = {
65}; 65};
66 66
67static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, 67static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
68 unsigned char old_state, unsigned char new_state, 68 unsigned char old_state, bool dinode,
69 unsigned int *n); 69 unsigned int *ndata);
70 70
71/** 71/**
72 * gfs2_setbit - Set a bit in the bitmaps 72 * gfs2_setbit - Set a bit in the bitmaps
@@ -921,8 +921,7 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
921 while (goal < rgd->rd_data) { 921 while (goal < rgd->rd_data) {
922 down_write(&sdp->sd_log_flush_lock); 922 down_write(&sdp->sd_log_flush_lock);
923 n = 1; 923 n = 1;
924 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, 924 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, 0, &n);
925 GFS2_BLKST_UNLINKED, &n);
926 up_write(&sdp->sd_log_flush_lock); 925 up_write(&sdp->sd_log_flush_lock);
927 if (block == BFITNOENT) 926 if (block == BFITNOENT)
928 break; 927 break;
@@ -1115,7 +1114,7 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
1115 * @rgd: the resource group descriptor 1114 * @rgd: the resource group descriptor
1116 * @goal: the goal block within the RG (start here to search for avail block) 1115 * @goal: the goal block within the RG (start here to search for avail block)
1117 * @old_state: GFS2_BLKST_XXX the before-allocation state to find 1116 * @old_state: GFS2_BLKST_XXX the before-allocation state to find
1118 * @new_state: GFS2_BLKST_XXX the after-allocation block state 1117 * @dinode: TRUE if the first block we allocate is for a dinode
1119 * @n: The extent length 1118 * @n: The extent length
1120 * 1119 *
1121 * Walk rgrp's bitmap to find bits that represent a block in @old_state. 1120 * Walk rgrp's bitmap to find bits that represent a block in @old_state.
@@ -1132,8 +1131,7 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
1132 */ 1131 */
1133 1132
1134static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, 1133static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
1135 unsigned char old_state, unsigned char new_state, 1134 unsigned char old_state, bool dinode, unsigned int *n)
1136 unsigned int *n)
1137{ 1135{
1138 struct gfs2_bitmap *bi = NULL; 1136 struct gfs2_bitmap *bi = NULL;
1139 const u32 length = rgd->rd_length; 1137 const u32 length = rgd->rd_length;
@@ -1192,13 +1190,14 @@ skip:
1192 if (blk == BFITNOENT) 1190 if (blk == BFITNOENT)
1193 return blk; 1191 return blk;
1194 1192
1195 *n = 1; 1193 if (old_state == GFS2_BLKST_UNLINKED)
1196 if (old_state == new_state)
1197 goto out; 1194 goto out;
1198 1195
1199 gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); 1196 gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1);
1200 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset, 1197 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
1201 bi, blk, new_state); 1198 bi, blk, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
1199 if (!dinode)
1200 (*n)++;
1202 goal = blk; 1201 goal = blk;
1203 while (*n < elen) { 1202 while (*n < elen) {
1204 goal++; 1203 goal++;
@@ -1208,7 +1207,7 @@ skip:
1208 GFS2_BLKST_FREE) 1207 GFS2_BLKST_FREE)
1209 break; 1208 break;
1210 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset, 1209 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
1211 bi, goal, new_state); 1210 bi, goal, GFS2_BLKST_USED);
1212 (*n)++; 1211 (*n)++;
1213 } 1212 }
1214out: 1213out:
@@ -1300,28 +1299,26 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)
1300} 1299}
1301 1300
1302/** 1301/**
1303 * gfs2_alloc_block - Allocate one or more blocks 1302 * gfs2_alloc_blocks - Allocate one or more blocks of data and/or a dinode
1304 * @ip: the inode to allocate the block for 1303 * @ip: the inode to allocate the block for
1305 * @bn: Used to return the starting block number 1304 * @bn: Used to return the starting block number
1306 * @n: requested number of blocks/extent length (value/result) 1305 * @ndata: requested number of data blocks/extent length (value/result)
1307 * dinode: 1 if we're allocating a dinode, 0 if it's a data block 1306 * @dinode: 1 if we're allocating a dinode block, else 0
1308 * @generation: the generation number of the inode 1307 * @generation: the generation number of the inode
1309 * 1308 *
1310 * Returns: 0 or error 1309 * Returns: 0 or error
1311 */ 1310 */
1312 1311
1313int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n, 1312int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *ndata,
1314 int dinode, u64 *generation) 1313 bool dinode, u64 *generation)
1315{ 1314{
1316 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1315 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1317 struct buffer_head *dibh; 1316 struct buffer_head *dibh;
1318 struct gfs2_alloc *al = ip->i_alloc; 1317 struct gfs2_alloc *al = ip->i_alloc;
1319 struct gfs2_rgrpd *rgd; 1318 struct gfs2_rgrpd *rgd;
1320 u32 goal, blk; /* block, within the rgrp scope */ 1319 u32 goal, extlen, blk; /* block, within the rgrp scope */
1321 u64 block; /* block, within the file system scope */ 1320 u64 block; /* block, within the file system scope */
1322 unsigned int extn = 1;
1323 int error; 1321 int error;
1324 unsigned char blk_type = dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED;
1325 1322
1326 /* Only happens if there is a bug in gfs2, return something distinctive 1323 /* Only happens if there is a bug in gfs2, return something distinctive
1327 * to ensure that it is noticed. 1324 * to ensure that it is noticed.
@@ -1329,8 +1326,6 @@ int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
1329 if (al == NULL) 1326 if (al == NULL)
1330 return -ECANCELED; 1327 return -ECANCELED;
1331 1328
1332 if (n == NULL)
1333 n = &extn;
1334 rgd = ip->i_rgd; 1329 rgd = ip->i_rgd;
1335 1330
1336 if (!dinode && rgrp_contains_block(rgd, ip->i_goal)) 1331 if (!dinode && rgrp_contains_block(rgd, ip->i_goal))
@@ -1338,7 +1333,7 @@ int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
1338 else 1333 else
1339 goal = rgd->rd_last_alloc; 1334 goal = rgd->rd_last_alloc;
1340 1335
1341 blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, blk_type, n); 1336 blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, dinode, ndata);
1342 1337
1343 /* Since all blocks are reserved in advance, this shouldn't happen */ 1338 /* Since all blocks are reserved in advance, this shouldn't happen */
1344 if (blk == BFITNOENT) 1339 if (blk == BFITNOENT)
@@ -1347,7 +1342,7 @@ int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
1347 rgd->rd_last_alloc = blk; 1342 rgd->rd_last_alloc = blk;
1348 block = rgd->rd_data0 + blk; 1343 block = rgd->rd_data0 + blk;
1349 if (!dinode) { 1344 if (!dinode) {
1350 ip->i_goal = block + *n - 1; 1345 ip->i_goal = block + *ndata - 1;
1351 error = gfs2_meta_inode_buffer(ip, &dibh); 1346 error = gfs2_meta_inode_buffer(ip, &dibh);
1352 if (error == 0) { 1347 if (error == 0) {
1353 struct gfs2_dinode *di = 1348 struct gfs2_dinode *di =
@@ -1358,10 +1353,13 @@ int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
1358 brelse(dibh); 1353 brelse(dibh);
1359 } 1354 }
1360 } 1355 }
1361 if (rgd->rd_free < *n) 1356 extlen = *ndata;
1357 if (dinode)
1358 extlen++;
1359 if (rgd->rd_free < extlen)
1362 goto rgrp_error; 1360 goto rgrp_error;
1363 1361
1364 rgd->rd_free -= *n; 1362 rgd->rd_free -= extlen;
1365 if (dinode) { 1363 if (dinode) {
1366 rgd->rd_dinodes++; 1364 rgd->rd_dinodes++;
1367 *generation = rgd->rd_igeneration++; 1365 *generation = rgd->rd_igeneration++;
@@ -1372,15 +1370,16 @@ int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
1372 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); 1370 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
1373 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); 1371 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
1374 1372
1375 gfs2_statfs_change(sdp, 0, -(s64)*n, dinode ? 1 : 0); 1373 gfs2_statfs_change(sdp, 0, -(s64)extlen, dinode ? 1 : 0);
1376 if (dinode) 1374 if (dinode)
1377 gfs2_trans_add_unrevoke(sdp, block, 1); 1375 gfs2_trans_add_unrevoke(sdp, block, 1);
1378 else 1376 if (*ndata)
1379 gfs2_quota_change(ip, *n, ip->i_inode.i_uid, 1377 gfs2_quota_change(ip, *ndata, ip->i_inode.i_uid,
1380 ip->i_inode.i_gid); 1378 ip->i_inode.i_gid);
1381 1379
1382 rgd->rd_free_clone -= *n; 1380 rgd->rd_free_clone -= extlen;
1383 trace_gfs2_block_alloc(ip, block, *n, blk_type); 1381 trace_gfs2_block_alloc(ip, block, *ndata,
1382 dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
1384 *bn = block; 1383 *bn = block;
1385 return 0; 1384 return 0;
1386 1385