mirror of
https://github.com/versity/scoutfs.git
synced 2026-01-05 03:44:05 +00:00
Add buddy indirect order totals
The total counts of all the set order bits in all the child buddy blocks is needed for statfs. Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
@@ -72,6 +72,7 @@ struct scoutfs_buddy_block {
|
||||
|
||||
struct scoutfs_buddy_indirect {
|
||||
struct scoutfs_block_header hdr;
|
||||
__le64 order_totals[SCOUTFS_BUDDY_ORDERS];
|
||||
struct scoutfs_buddy_slot {
|
||||
__u8 free_orders;
|
||||
struct scoutfs_block_ref ref;
|
||||
@@ -79,7 +80,7 @@ struct scoutfs_buddy_indirect {
|
||||
} __packed;
|
||||
|
||||
#define SCOUTFS_BUDDY_SLOTS \
|
||||
((SCOUTFS_BLOCK_SIZE - sizeof(struct scoutfs_buddy_block)) / \
|
||||
((SCOUTFS_BLOCK_SIZE - sizeof(struct scoutfs_buddy_indirect)) / \
|
||||
sizeof(struct scoutfs_buddy_slot))
|
||||
|
||||
/*
|
||||
|
||||
@@ -140,15 +140,15 @@ static int write_new_fs(char *path, int fd)
|
||||
u64 blkno;
|
||||
u64 total_blocks;
|
||||
u64 buddy_blocks;
|
||||
u8 free_orders;
|
||||
void *buf;
|
||||
int ret;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
buf = malloc(SCOUTFS_BLOCK_SIZE);
|
||||
bud = malloc(SCOUTFS_BLOCK_SIZE);
|
||||
super = malloc(SCOUTFS_BLOCK_SIZE);
|
||||
if (!buf || !super) {
|
||||
if (!buf || !bud || !super) {
|
||||
ret = -errno;
|
||||
fprintf(stderr, "failed to allocate a block: %s (%d)\n",
|
||||
strerror(errno), errno);
|
||||
@@ -221,12 +221,10 @@ static int write_new_fs(char *path, int fd)
|
||||
super->btree_root.ref.seq = bt->hdr.seq;
|
||||
|
||||
/* free all the blocks in the first buddy block after btree block */
|
||||
memset(buf, 0, SCOUTFS_BLOCK_SIZE);
|
||||
bud = buf;
|
||||
memset(bud, 0, SCOUTFS_BLOCK_SIZE);
|
||||
for (i = 1; i < min(total_blocks - first_blkno(super),
|
||||
SCOUTFS_BUDDY_ORDER0_BITS); i++)
|
||||
free_order_bit(bud, 0, i);
|
||||
free_orders = calc_free_orders(bud);
|
||||
|
||||
blkno = SCOUTFS_BUDDY_BM_BLKNO + SCOUTFS_BUDDY_BM_NR;
|
||||
ret = write_block(fd, blkno, super, &bud->hdr);
|
||||
@@ -236,11 +234,14 @@ static int write_new_fs(char *path, int fd)
|
||||
/* an indirect buddy block references the buddy bitmap block */
|
||||
memset(buf, 0, SCOUTFS_BLOCK_SIZE);
|
||||
ind = buf;
|
||||
for (i = 0; i < SCOUTFS_BUDDY_ORDERS; i++)
|
||||
ind->order_totals[i] = cpu_to_le64(le32_to_cpu(
|
||||
bud->order_counts[i]));
|
||||
for (i = 0; i < SCOUTFS_BUDDY_SLOTS; i++) {
|
||||
ind->slots[i].free_orders = 0;
|
||||
ind->slots[i].ref = (struct scoutfs_block_ref){0,};
|
||||
}
|
||||
ind->slots[0].free_orders = free_orders;
|
||||
ind->slots[0].free_orders = calc_free_orders(bud);
|
||||
ind->slots[0].ref.seq = super->hdr.seq;
|
||||
ind->slots[0].ref.blkno = cpu_to_le64(blkno);
|
||||
|
||||
@@ -298,6 +299,8 @@ static int write_new_fs(char *path, int fd)
|
||||
out:
|
||||
if (super)
|
||||
free(super);
|
||||
if (bud)
|
||||
free(bud);
|
||||
if (buf)
|
||||
free(buf);
|
||||
return ret;
|
||||
|
||||
@@ -245,6 +245,10 @@ static int print_buddy_blocks(int fd, struct scoutfs_super_block *super)
|
||||
|
||||
printf("buddy indirect blkno %llu\n", blkno);
|
||||
print_block_header(&ind->hdr);
|
||||
printf(" total_counts:");
|
||||
for (i = 0; i < SCOUTFS_BUDDY_ORDERS; i++)
|
||||
printf(" %llu", le64_to_cpu(ind->order_totals[i]));
|
||||
printf("\n");
|
||||
|
||||
for (i = 0; i < SCOUTFS_BUDDY_SLOTS; i++) {
|
||||
slot = &ind->slots[i];
|
||||
|
||||
Reference in New Issue
Block a user