|
Packit Service |
360c39 |
#include "clusterautoconfig.h"
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
#include <stdio.h>
|
|
Packit Service |
360c39 |
#include <stdlib.h>
|
|
Packit Service |
360c39 |
#include <string.h>
|
|
Packit Service |
360c39 |
#include <stdint.h>
|
|
Packit Service |
360c39 |
#include <inttypes.h>
|
|
Packit Service |
360c39 |
#include <sys/types.h>
|
|
Packit Service |
360c39 |
#include <sys/stat.h>
|
|
Packit Service |
360c39 |
#include <fcntl.h>
|
|
Packit Service |
360c39 |
#include <unistd.h>
|
|
Packit Service |
360c39 |
#include <errno.h>
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
#include <linux/types.h>
|
|
Packit Service |
360c39 |
#include "libgfs2.h"
|
|
Packit Service |
360c39 |
#include "config.h"
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
/**
|
|
Packit Service |
360c39 |
* Given a number of blocks in a resource group, return the number of blocks
|
|
Packit Service |
360c39 |
* needed for bitmaps. Also calculate the adjusted number of free data blocks
|
|
Packit Service |
360c39 |
* in the resource group and store it in *ri_data.
|
|
Packit Service |
360c39 |
*/
|
|
Packit Service |
360c39 |
uint32_t rgblocks2bitblocks(const unsigned int bsize, const uint32_t rgblocks, uint32_t *ri_data)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
uint32_t mappable = 0;
|
|
Packit Service |
360c39 |
uint32_t bitblocks = 0;
|
|
Packit Service |
360c39 |
/* Number of blocks mappable by bitmap blocks with these header types */
|
|
Packit Service |
360c39 |
const uint32_t blks_rgrp = GFS2_NBBY * (bsize - sizeof(struct gfs2_rgrp));
|
|
Packit Service |
360c39 |
const uint32_t blks_meta = GFS2_NBBY * (bsize - sizeof(struct gfs2_meta_header));
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
while (blks_rgrp + (blks_meta * bitblocks) < ((rgblocks - bitblocks) & ~(uint32_t)3))
|
|
Packit Service |
360c39 |
bitblocks++;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
if (bitblocks > 0)
|
|
Packit Service |
360c39 |
mappable = blks_rgrp + (blks_meta * (bitblocks - 1));
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
*ri_data = (rgblocks - (bitblocks + 1)) & ~(uint32_t)3;
|
|
Packit Service |
360c39 |
if (mappable < *ri_data)
|
|
Packit Service |
360c39 |
bitblocks++;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
return bitblocks;
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
/**
|
|
Packit Service |
360c39 |
* build_rgrps - write a bunch of resource groups to disk.
|
|
Packit Service |
360c39 |
* If fd > 0, write the data to the given file handle.
|
|
Packit Service |
360c39 |
* Otherwise, use gfs2 buffering in buf.c.
|
|
Packit Service |
360c39 |
*/
|
|
Packit Service |
360c39 |
int build_rgrps(struct gfs2_sbd *sdp, int do_write)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
struct osi_node *n, *next = NULL;
|
|
Packit Service |
360c39 |
struct rgrp_tree *rl;
|
|
Packit Service |
360c39 |
uint32_t rgblocks, bitblocks;
|
|
Packit Service |
360c39 |
struct gfs2_rindex *ri;
|
|
Packit Service |
360c39 |
struct gfs2_meta_header mh;
|
|
Packit Service |
360c39 |
unsigned int x;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
mh.mh_magic = GFS2_MAGIC;
|
|
Packit Service |
360c39 |
mh.mh_type = GFS2_METATYPE_RB;
|
|
Packit Service |
360c39 |
mh.mh_format = GFS2_FORMAT_RB;
|
|
Packit Service |
360c39 |
if (do_write)
|
|
Packit Service |
360c39 |
n = osi_first(&sdp->rgtree);
|
|
Packit Service |
360c39 |
else
|
|
Packit Service |
360c39 |
n = osi_first(&sdp->rgcalc);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
for (; n; n = next) {
|
|
Packit Service |
360c39 |
next = osi_next(n);
|
|
Packit Service |
360c39 |
rl = (struct rgrp_tree *)n;
|
|
Packit Service |
360c39 |
ri = &rl->ri;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
bitblocks = rgblocks2bitblocks(sdp->bsize, rl->length, &rgblocks);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
ri->ri_addr = rl->start;
|
|
Packit Service |
360c39 |
ri->ri_length = bitblocks;
|
|
Packit Service |
360c39 |
ri->ri_data0 = rl->start + bitblocks;
|
|
Packit Service |
360c39 |
ri->ri_data = rgblocks;
|
|
Packit Service |
360c39 |
ri->ri_bitbytes = rgblocks / GFS2_NBBY;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
memset(&rl->rg, 0, sizeof(rl->rg));
|
|
Packit Service |
360c39 |
rl->rg.rg_header.mh_magic = GFS2_MAGIC;
|
|
Packit Service |
360c39 |
rl->rg.rg_header.mh_type = GFS2_METATYPE_RG;
|
|
Packit Service |
360c39 |
rl->rg.rg_header.mh_format = GFS2_FORMAT_RG;
|
|
Packit Service |
360c39 |
rl->rg.rg_free = rgblocks;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
if (gfs2_compute_bitstructs(sdp->sd_sb.sb_bsize, rl))
|
|
Packit Service |
360c39 |
return -1;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
if (do_write) {
|
|
Packit Service |
360c39 |
for (x = 0; x < bitblocks; x++) {
|
|
Packit Service |
360c39 |
rl->bits[x].bi_bh = bget(sdp, rl->start + x);
|
|
Packit Service |
360c39 |
if (x)
|
|
Packit Service |
360c39 |
gfs2_meta_header_out(&mh, rl->bits[x].bi_bh->b_data);
|
|
Packit Service |
360c39 |
else
|
|
Packit Service |
360c39 |
gfs2_rgrp_out(&rl->rg, rl->bits[x].bi_bh->b_data);
|
|
Packit Service |
360c39 |
bmodified(rl->bits[x].bi_bh);
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
if (cfg_debug) {
|
|
Packit Service |
360c39 |
printf("\n");
|
|
Packit Service |
360c39 |
gfs2_rindex_print(ri);
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
sdp->blks_total += rgblocks;
|
|
Packit Service |
360c39 |
sdp->fssize = ri->ri_data0 + ri->ri_data;
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
return 0;
|
|
Packit Service |
360c39 |
}
|