Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 41adf63ed2763528207b0b4267b955a47a30e12e
Parent: 6df7df354ab5282061fa11367a1f6e42209f43c5
Author: Ken Preslan <kpreslan(a)redhat.com>
AuthorDate: Thu Apr 14 19:27:34 2005 +0000
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Feb 8 17:31:37 2010 -0600
Fix bug #154902:
Replace the function that gets confused on certain device sizes with a
different function -- a new and improved one, that always knows what it's
doing.
---
gfs/gfs_mkfs/structures.c | 80 +++++++++++++++++++++++---------------------
1 files changed, 42 insertions(+), 38 deletions(-)
diff --git a/gfs/gfs_mkfs/structures.c b/gfs/gfs_mkfs/structures.c
index 62e69c7..273dfee 100644
--- a/gfs/gfs_mkfs/structures.c
+++ b/gfs/gfs_mkfs/structures.c
@@ -61,43 +61,43 @@
/**
- * rgrplength2bitblocks - blerg
- * @comline: the command line
- * @length: the number of blocks in a RG
+ * rgblocks2bitblocks - blerg
+ * @bsize: the FS block size
+ * @rgblocks: The total number of the blocks in the RG
+ * Also, returns the number of allocateable blocks
+ * @bitblocks: Returns the number of bitmap blocks
*
* Give a number of blocks in a RG, figure out the number of blocks
* needed for bitmaps.
*
- * Returns: the number of bitmap blocks
*/
-uint32 rgrplength2bitblocks(commandline_t *comline, uint32 length)
+static void
+rgblocks2bitblocks(unsigned int bsize,
+ uint32_t *rgblocks,
+ uint32_t *bitblocks)
{
- uint32 bitbytes;
- uint32 old_blocks = 0, blocks;
- int tries = 0;
-
- for (;;)
- {
- bitbytes = (length - old_blocks) / GFS_NBBY;
- blocks = 1;
+ unsigned int bitbytes_provided, last = 0;
+ unsigned int bitbytes_needed;
- if (bitbytes > comline->bsize - sizeof(struct gfs_rgrp))
- {
- bitbytes -= comline->bsize - sizeof(struct gfs_rgrp);
- blocks += DIV_RU(bitbytes, (comline->bsize - sizeof(struct gfs_meta_header)));
- }
+ *bitblocks = 1;
+ bitbytes_provided = bsize - sizeof(struct gfs_rgrp);
- if (blocks == old_blocks)
- break;
+ for (;;) {
+ bitbytes_needed = (*rgblocks - *bitblocks) / GFS_NBBY;
- old_blocks = blocks;
+ if (bitbytes_provided >= bitbytes_needed) {
+ if (last >= bitbytes_needed)
+ (*bitblocks)--;
+ break;
+ }
- if (tries++ > 10)
- die("confused computing bitblock length\n");
- }
+ last = bitbytes_provided;
+ (*bitblocks)++;
+ bitbytes_provided += bsize - sizeof(struct gfs_meta_header);
+ }
- return blocks;
+ *rgblocks = bitbytes_needed * GFS_NBBY;
}
@@ -111,7 +111,6 @@ uint32 rgrplength2bitblocks(commandline_t *comline, uint32 length)
void write_sb(commandline_t *comline, osi_list_t *rlist)
{
struct gfs_sb *sb;
- rgrp_list_t *rl;
uint64 jindex_dinode;
char buf[comline->bsize];
int x;
@@ -128,9 +127,15 @@ void write_sb(commandline_t *comline, osi_list_t *rlist)
/* Figure out the location of the journal index inode */
- rl = osi_list_entry(rlist->next, rgrp_list_t, list);
+ {
+ rgrp_list_t *rl = osi_list_entry(rlist->next, rgrp_list_t, list);
+ uint32_t rgblocks, bitblocks;
- jindex_dinode = rl->rg_offset + rgrplength2bitblocks(comline, rl->rg_length);
+ rgblocks = rl->rg_length;
+ rgblocks2bitblocks(comline->bsize, &rgblocks, &bitblocks);
+
+ jindex_dinode = rl->rg_offset + bitblocks;
+ }
/* Now, fill in the superblock */
@@ -493,7 +498,7 @@ static char *fill_rindex(commandline_t *comline, osi_list_t *rlist)
osi_list_t *tmp;
char *buf;
unsigned int r = 0;
- uint32 length, blocks;
+ uint32 rgblocks, bitblocks;
type_alloc(buf, char, comline->rgrps * sizeof(struct gfs_rindex));
@@ -503,25 +508,24 @@ static char *fill_rindex(commandline_t *comline, osi_list_t *rlist)
{
rl = osi_list_entry(tmp, rgrp_list_t, list);
- length = rgrplength2bitblocks(comline, rl->rg_length);
-
- blocks = rl->rg_length - length;
- blocks -= blocks % GFS_NBBY;
- comline->fssize += blocks;
+ rgblocks = rl->rg_length;
+ rgblocks2bitblocks(comline->bsize, &rgblocks, &bitblocks);
type_zalloc(ri, struct gfs_rindex, 1);
rl->ri = ri;
ri->ri_addr = rl->rg_offset;
- ri->ri_length = length;
+ ri->ri_length = bitblocks;
- ri->ri_data1 = rl->rg_offset + length;
- ri->ri_data = blocks;
+ ri->ri_data1 = rl->rg_offset + bitblocks;
+ ri->ri_data = rgblocks;
- ri->ri_bitbytes = blocks / GFS_NBBY;
+ ri->ri_bitbytes = rgblocks / GFS_NBBY;
gfs_rindex_out(ri, buf + r * sizeof(struct gfs_rindex));
+ comline->fssize += rgblocks;
+
r++;
}