@@ -65,8 +65,8 @@ static const char valid_change[16] = {
6565};
6666
6767static u32 rgblk_search (struct gfs2_rgrpd * rgd , u32 goal ,
68- unsigned char old_state , unsigned char new_state ,
69- unsigned int * n );
68+ unsigned char old_state , bool dinode ,
69+ unsigned int * ndata );
7070
7171/**
7272 * 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
921921 while (goal < rgd -> rd_data ) {
922922 down_write (& sdp -> sd_log_flush_lock );
923923 n = 1 ;
924- block = rgblk_search (rgd , goal , GFS2_BLKST_UNLINKED ,
925- GFS2_BLKST_UNLINKED , & n );
924+ block = rgblk_search (rgd , goal , GFS2_BLKST_UNLINKED , 0 , & n );
926925 up_write (& sdp -> sd_log_flush_lock );
927926 if (block == BFITNOENT )
928927 break ;
@@ -1115,7 +1114,7 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
11151114 * @rgd: the resource group descriptor
11161115 * @goal: the goal block within the RG (start here to search for avail block)
11171116 * @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
11191118 * @n: The extent length
11201119 *
11211120 * 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)
11321131 */
11331132
11341133static u32 rgblk_search (struct gfs2_rgrpd * rgd , u32 goal ,
1135- unsigned char old_state , unsigned char new_state ,
1136- unsigned int * n )
1134+ unsigned char old_state , bool dinode , unsigned int * n )
11371135{
11381136 struct gfs2_bitmap * bi = NULL ;
11391137 const u32 length = rgd -> rd_length ;
@@ -1192,13 +1190,14 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
11921190 if (blk == BFITNOENT )
11931191 return blk ;
11941192
1195- * n = 1 ;
1196- if (old_state == new_state )
1193+ if (old_state == GFS2_BLKST_UNLINKED )
11971194 goto out ;
11981195
11991196 gfs2_trans_add_bh (rgd -> rd_gl , bi -> bi_bh , 1 );
12001197 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 )++ ;
12021201 goal = blk ;
12031202 while (* n < elen ) {
12041203 goal ++ ;
@@ -1208,7 +1207,7 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
12081207 GFS2_BLKST_FREE )
12091208 break ;
12101209 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 );
12121211 (* n )++ ;
12131212 }
12141213out :
@@ -1300,45 +1299,41 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)
13001299}
13011300
13021301/**
1303- * gfs2_alloc_block - Allocate one or more blocks
1302+ * gfs2_alloc_blocks - Allocate one or more blocks of data and/or a dinode
13041303 * @ip: the inode to allocate the block for
13051304 * @bn: Used to return the starting block number
1306- * @n : requested number of blocks/extent length (value/result)
1307- * dinode: 1 if we're allocating a dinode, 0 if it's a data block
1305+ * @ndata : requested number of data blocks/extent length (value/result)
1306+ * @ dinode: 1 if we're allocating a dinode block, else 0
13081307 * @generation: the generation number of the inode
13091308 *
13101309 * Returns: 0 or error
13111310 */
13121311
1313- int gfs2_alloc_block (struct gfs2_inode * ip , u64 * bn , unsigned int * n ,
1314- int dinode , u64 * generation )
1312+ int gfs2_alloc_blocks (struct gfs2_inode * ip , u64 * bn , unsigned int * ndata ,
1313+ bool dinode , u64 * generation )
13151314{
13161315 struct gfs2_sbd * sdp = GFS2_SB (& ip -> i_inode );
13171316 struct buffer_head * dibh ;
13181317 struct gfs2_alloc * al = ip -> i_alloc ;
13191318 struct gfs2_rgrpd * rgd ;
1320- u32 goal , blk ; /* block, within the rgrp scope */
1319+ u32 goal , extlen , blk ; /* block, within the rgrp scope */
13211320 u64 block ; /* block, within the file system scope */
1322- unsigned int extn = 1 ;
13231321 int error ;
1324- unsigned char blk_type = dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED ;
13251322
13261323 /* Only happens if there is a bug in gfs2, return something distinctive
13271324 * to ensure that it is noticed.
13281325 */
13291326 if (al == NULL )
13301327 return - ECANCELED ;
13311328
1332- if (n == NULL )
1333- n = & extn ;
13341329 rgd = ip -> i_rgd ;
13351330
13361331 if (!dinode && rgrp_contains_block (rgd , ip -> i_goal ))
13371332 goal = ip -> i_goal - rgd -> rd_data0 ;
13381333 else
13391334 goal = rgd -> rd_last_alloc ;
13401335
1341- blk = rgblk_search (rgd , goal , GFS2_BLKST_FREE , blk_type , n );
1336+ blk = rgblk_search (rgd , goal , GFS2_BLKST_FREE , dinode , ndata );
13421337
13431338 /* Since all blocks are reserved in advance, this shouldn't happen */
13441339 if (blk == BFITNOENT )
@@ -1347,7 +1342,7 @@ int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
13471342 rgd -> rd_last_alloc = blk ;
13481343 block = rgd -> rd_data0 + blk ;
13491344 if (!dinode ) {
1350- ip -> i_goal = block + * n - 1 ;
1345+ ip -> i_goal = block + * ndata - 1 ;
13511346 error = gfs2_meta_inode_buffer (ip , & dibh );
13521347 if (error == 0 ) {
13531348 struct gfs2_dinode * di =
@@ -1358,10 +1353,13 @@ int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
13581353 brelse (dibh );
13591354 }
13601355 }
1361- if (rgd -> rd_free < * n )
1356+ extlen = * ndata ;
1357+ if (dinode )
1358+ extlen ++ ;
1359+ if (rgd -> rd_free < extlen )
13621360 goto rgrp_error ;
13631361
1364- rgd -> rd_free -= * n ;
1362+ rgd -> rd_free -= extlen ;
13651363 if (dinode ) {
13661364 rgd -> rd_dinodes ++ ;
13671365 * generation = rgd -> rd_igeneration ++ ;
@@ -1372,15 +1370,16 @@ int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
13721370 gfs2_trans_add_bh (rgd -> rd_gl , rgd -> rd_bits [0 ].bi_bh , 1 );
13731371 gfs2_rgrp_out (rgd , rgd -> rd_bits [0 ].bi_bh -> b_data );
13741372
1375- gfs2_statfs_change (sdp , 0 , - (s64 )* n , dinode ? 1 : 0 );
1373+ gfs2_statfs_change (sdp , 0 , - (s64 )extlen , dinode ? 1 : 0 );
13761374 if (dinode )
13771375 gfs2_trans_add_unrevoke (sdp , block , 1 );
1378- else
1379- gfs2_quota_change (ip , * n , ip -> i_inode .i_uid ,
1376+ if ( * ndata )
1377+ gfs2_quota_change (ip , * ndata , ip -> i_inode .i_uid ,
13801378 ip -> i_inode .i_gid );
13811379
1382- rgd -> rd_free_clone -= * n ;
1383- trace_gfs2_block_alloc (ip , block , * n , blk_type );
1380+ rgd -> rd_free_clone -= extlen ;
1381+ trace_gfs2_block_alloc (ip , block , * ndata ,
1382+ dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED );
13841383 * bn = block ;
13851384 return 0 ;
13861385
0 commit comments