Gitweb:
http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=f2d9e5d0...
Commit: f2d9e5d0830609bc0e89e6c7e6d201d5f2265c71
Parent: f2efdb703a9b6f4ec9c5382df16d47e058fc63c7
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed Sep 17 16:19:07 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
libgfs2: Move old rgrp layout functions into fsck.gfs2
fsck.gfs2 is now the only user of compute_rgrp_layout and how_many_rgrps
and it requires them for discovery of resource groups when the rindex is
unreliable. Move them out of libgfs2 and into fsck.gfs2. New code should
use lgfs2_rgrps_plan() instead.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/fsck/rgrepair.c | 118 +++++++++++++++++++++++++++++++++++++++++
gfs2/libgfs2/fs_geometry.c | 126 --------------------------------------------
gfs2/libgfs2/libgfs2.h | 4 --
3 files changed, 118 insertions(+), 130 deletions(-)
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index dd197d6..12e474b 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -590,6 +590,124 @@ static int gfs2_rindex_rebuild(struct gfs2_sbd *sdp, int *num_rgs,
return 0;
}
+#define DIV_RU(x, y) (((x) + (y) - 1) / (y))
+
+/**
+ * how_many_rgrps - figure out how many RG to put in a subdevice
+ * @w: the command line
+ * @dev: the device
+ *
+ * Returns: the number of RGs
+ */
+static uint64_t how_many_rgrps(struct gfs2_sbd *sdp, struct device *dev, int
rgsize_specified)
+{
+ uint64_t nrgrp;
+ uint32_t rgblocks1, rgblocksn, bitblocks1, bitblocksn;
+ int bitmap_overflow = 0;
+
+ while (1) {
+ nrgrp = DIV_RU(dev->length, (sdp->rgsize << 20) / sdp->bsize);
+
+ /* check to see if the rg length overflows max # bitblks */
+ bitblocksn = rgblocks2bitblocks(sdp->bsize, dev->length / nrgrp,
&rgblocksn);
+ /* calculate size of the first rgrp */
+ bitblocks1 = rgblocks2bitblocks(sdp->bsize, dev->length - (nrgrp - 1) *
(dev->length / nrgrp),
+ &rgblocks1);
+ if (bitblocks1 > 2149 || bitblocksn > 2149) {
+ bitmap_overflow = 1;
+ if (sdp->rgsize <= GFS2_DEFAULT_RGSIZE) {
+ fprintf(stderr, "error: It is not possible "
+ "to use the entire device with "
+ "block size %u bytes.\n",
+ sdp->bsize);
+ exit(-1);
+ }
+ sdp->rgsize -= GFS2_DEFAULT_RGSIZE; /* smaller rgs */
+ continue;
+ }
+ if (bitmap_overflow ||
+ rgsize_specified || /* If user specified an rg size or */
+ nrgrp <= GFS2_EXCESSIVE_RGS || /* not an excessive # or */
+ sdp->rgsize >= 2048) /* we reached the max rg size */
+ break;
+
+ sdp->rgsize += GFS2_DEFAULT_RGSIZE; /* bigger rgs */
+ }
+
+ log_debug(" rg sz = %"PRIu32"\n nrgrp = %"PRIu64"\n",
sdp->rgsize, nrgrp);
+
+ return nrgrp;
+}
+
+/**
+ * compute_rgrp_layout - figure out where the RG in a FS are
+ */
+static void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree, int
rgsize_specified)
+{
+ struct device *dev;
+ struct rgrp_tree *rl, *rlast = NULL;
+ struct osi_node *n, *next = NULL;
+ unsigned int rgrp = 0, nrgrp, rglength;
+ uint64_t rgaddr;
+
+ sdp->new_rgrps = 0;
+ dev = &sdp->device;
+
+ /* If this is a new file system, compute the length and number */
+ /* of rgs based on the size of the device. */
+ /* If we have existing RGs (i.e. gfs2_grow) find the last one. */
+ if (!rgtree->osi_node) {
+ dev->length -= sdp->sb_addr + 1;
+ nrgrp = how_many_rgrps(sdp, dev, rgsize_specified);
+ rglength = dev->length / nrgrp;
+ sdp->new_rgrps = nrgrp;
+ } else {
+ uint64_t old_length, new_chunk;
+
+ printf("Existing resource groups:\n");
+ for (rgrp = 0, n = osi_first(rgtree); n; n = next, rgrp++) {
+ next = osi_next(n);
+ rl = (struct rgrp_tree *)n;
+
+ printf("%d: start: %" PRIu64 " (0x%"
+ PRIx64 "), length = %"PRIu64" (0x%"
+ PRIx64 ")\n", rgrp + 1, rl->start, rl->start,
+ rl->length, rl->length);
+ rlast = rl;
+ }
+ rlast->start = rlast->ri.ri_addr;
+ rglength = rgrp_size(rlast);
+ rlast->length = rglength;
+ old_length = rlast->ri.ri_addr + rglength;
+ new_chunk = dev->length - old_length;
+ sdp->new_rgrps = new_chunk / rglength;
+ nrgrp = rgrp + sdp->new_rgrps;
+ }
+
+ if (rgrp < nrgrp)
+ printf("\nNew resource groups:\n");
+ for (; rgrp < nrgrp; rgrp++) {
+ if (rgrp) {
+ rgaddr = rlast->start + rlast->length;
+ rl = rgrp_insert(rgtree, rgaddr);
+ rl->length = rglength;
+ } else {
+ rgaddr = sdp->sb_addr + 1;
+ rl = rgrp_insert(rgtree, rgaddr);
+ rl->length = dev->length -
+ (nrgrp - 1) * (dev->length / nrgrp);
+ }
+ rl->start = rgaddr;
+ printf("%d: start: %" PRIu64 " (0x%"
+ PRIx64 "), length = %"PRIu64" (0x%"
+ PRIx64 ")\n", rgrp + 1, rl->start, rl->start,
+ rl->length, rl->length);
+ rlast = rl;
+ }
+
+ sdp->rgrps = nrgrp;
+}
+
/*
* gfs2_rindex_calculate - calculate what the rindex should look like
* in a perfect world (trust_lvl == open_minded)
diff --git a/gfs2/libgfs2/fs_geometry.c b/gfs2/libgfs2/fs_geometry.c
index c378dba..59b5ef7 100644
--- a/gfs2/libgfs2/fs_geometry.c
+++ b/gfs2/libgfs2/fs_geometry.c
@@ -15,132 +15,6 @@
#include "libgfs2.h"
#include "config.h"
-#define DIV_RU(x, y) (((x) + (y) - 1) / (y))
-
-/**
- * how_many_rgrps - figure out how many RG to put in a subdevice
- * @w: the command line
- * @dev: the device
- *
- * Returns: the number of RGs
- */
-
-uint64_t how_many_rgrps(struct gfs2_sbd *sdp, struct device *dev, int rgsize_specified)
-{
- uint64_t nrgrp;
- uint32_t rgblocks1, rgblocksn, bitblocks1, bitblocksn;
- int bitmap_overflow = 0;
-
- while (TRUE) {
- nrgrp = DIV_RU(dev->length, (sdp->rgsize << 20) / sdp->bsize);
-
- /* check to see if the rg length overflows max # bitblks */
- bitblocksn = rgblocks2bitblocks(sdp->bsize, dev->length / nrgrp,
&rgblocksn);
- /* calculate size of the first rgrp */
- bitblocks1 = rgblocks2bitblocks(sdp->bsize, dev->length - (nrgrp - 1) *
(dev->length / nrgrp),
- &rgblocks1);
- if (bitblocks1 > 2149 || bitblocksn > 2149) {
- bitmap_overflow = 1;
- if (sdp->rgsize <= GFS2_DEFAULT_RGSIZE) {
- fprintf(stderr, "error: It is not possible "
- "to use the entire device with "
- "block size %u bytes.\n",
- sdp->bsize);
- exit(-1);
- }
- sdp->rgsize -= GFS2_DEFAULT_RGSIZE; /* smaller rgs */
- continue;
- }
- if (bitmap_overflow ||
- rgsize_specified || /* If user specified an rg size or */
- nrgrp <= GFS2_EXCESSIVE_RGS || /* not an excessive # or */
- sdp->rgsize >= 2048) /* we reached the max rg size */
- break;
-
- sdp->rgsize += GFS2_DEFAULT_RGSIZE; /* bigger rgs */
- }
-
- if (cfg_debug)
- printf(" rg sz = %"PRIu32"\n nrgrp = %"PRIu64"\n",
- sdp->rgsize, nrgrp);
-
- return nrgrp;
-}
-
-/**
- * compute_rgrp_layout - figure out where the RG in a FS are
- * @w: the command line
- *
- * Returns: a list of rgrp_list_t structures
- */
-
-void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
- int rgsize_specified)
-{
- struct device *dev;
- struct rgrp_tree *rl, *rlast = NULL;
- struct osi_node *n, *next = NULL;
- unsigned int rgrp = 0, nrgrp, rglength;
- uint64_t rgaddr;
-
- sdp->new_rgrps = 0;
- dev = &sdp->device;
-
- /* If this is a new file system, compute the length and number */
- /* of rgs based on the size of the device. */
- /* If we have existing RGs (i.e. gfs2_grow) find the last one. */
- if (!rgtree->osi_node) {
- dev->length -= sdp->sb_addr + 1;
- nrgrp = how_many_rgrps(sdp, dev, rgsize_specified);
- rglength = dev->length / nrgrp;
- sdp->new_rgrps = nrgrp;
- } else {
- uint64_t old_length, new_chunk;
-
- printf("Existing resource groups:\n");
- for (rgrp = 0, n = osi_first(rgtree); n; n = next, rgrp++) {
- next = osi_next(n);
- rl = (struct rgrp_tree *)n;
-
- printf("%d: start: %" PRIu64 " (0x%"
- PRIx64 "), length = %"PRIu64" (0x%"
- PRIx64 ")\n", rgrp + 1, rl->start, rl->start,
- rl->length, rl->length);
- rlast = rl;
- }
- rlast->start = rlast->ri.ri_addr;
- rglength = rgrp_size(rlast);
- rlast->length = rglength;
- old_length = rlast->ri.ri_addr + rglength;
- new_chunk = dev->length - old_length;
- sdp->new_rgrps = new_chunk / rglength;
- nrgrp = rgrp + sdp->new_rgrps;
- }
-
- if (rgrp < nrgrp)
- printf("\nNew resource groups:\n");
- for (; rgrp < nrgrp; rgrp++) {
- if (rgrp) {
- rgaddr = rlast->start + rlast->length;
- rl = rgrp_insert(rgtree, rgaddr);
- rl->length = rglength;
- } else {
- rgaddr = sdp->sb_addr + 1;
- rl = rgrp_insert(rgtree, rgaddr);
- rl->length = dev->length -
- (nrgrp - 1) * (dev->length / nrgrp);
- }
- rl->start = rgaddr;
- printf("%d: start: %" PRIu64 " (0x%"
- PRIx64 "), length = %"PRIu64" (0x%"
- PRIx64 ")\n", rgrp + 1, rl->start, rl->start,
- rl->length, rl->length);
- rlast = rl;
- }
-
- sdp->rgrps = nrgrp;
-}
-
/**
* Given a number of blocks in a resource group, return the number of blocks
* needed for bitmaps. Also calculate the adjusted number of free data blocks
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index d024e56..23ab210 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -425,10 +425,6 @@ extern int gfs2_set_bitmap(lgfs2_rgrp_t rg, uint64_t blkno, int
state);
/* fs_geometry.c */
extern uint32_t rgblocks2bitblocks(const unsigned int bsize, const uint32_t rgblocks,
uint32_t *ri_data) __attribute__((nonnull(3)));
-extern uint64_t how_many_rgrps(struct gfs2_sbd *sdp, struct device *dev,
- int rgsize_specified);
-extern void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
- int rgsize_specified);
extern int build_rgrps(struct gfs2_sbd *sdp, int write);
/* fs_ops.c */