btree nr_items is now a le16

The btree block now has a le16 nr_items field to make room for the
number of items that larger blocks can hold.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2016-11-07 14:42:36 -08:00
parent cd0d045c93
commit fb16af7b7d
3 changed files with 8 additions and 7 deletions

View File

@@ -136,7 +136,7 @@ struct scoutfs_btree_block {
struct scoutfs_block_header hdr;
__le16 free_end;
__le16 free_reclaim;
__u8 nr_items;
__le16 nr_items;
__le16 item_offs[0];
} __packed;

View File

@@ -360,7 +360,7 @@ static int write_new_fs(char *path, int fd)
/* write a btree leaf root inode item */
memset(buf, 0, SCOUTFS_BLOCK_SIZE);
bt = buf;
bt->nr_items = 1;
bt->nr_items = cpu_to_le16(1);
bt->free_end = cpu_to_le16(SCOUTFS_BLOCK_SIZE - sizeof(*item) -
sizeof(*inode));
bt->free_reclaim = 0;

View File

@@ -178,6 +178,7 @@ static int print_btree_block(int fd, __le64 blkno, u8 level)
struct scoutfs_btree_item *item;
struct scoutfs_btree_block *bt;
struct scoutfs_block_ref *ref;
unsigned int nr;
int ret = 0;
int err;
int i;
@@ -186,14 +187,14 @@ static int print_btree_block(int fd, __le64 blkno, u8 level)
if (!bt)
return -ENOMEM;
nr = le16_to_cpu(bt->nr_items);
printf("btree blkno %llu\n", le64_to_cpu(blkno));
print_block_header(&bt->hdr);
printf(" free_end %u free_reclaim %u nr_items %u\n",
le16_to_cpu(bt->free_end),
le16_to_cpu(bt->free_reclaim),
bt->nr_items);
le16_to_cpu(bt->free_end), le16_to_cpu(bt->free_reclaim), nr);
for (i = 0; i < bt->nr_items; i++) {
for (i = 0; i < nr; i++) {
item = (void *)bt + le16_to_cpu(bt->item_offs[i]);
printf(" [%u] off %u: key "SKF" seq %llu val_len %u\n",
@@ -204,7 +205,7 @@ static int print_btree_block(int fd, __le64 blkno, u8 level)
print_btree_val(item, level);
}
for (i = 0; level && i < bt->nr_items; i++) {
for (i = 0; level && i < nr; i++) {
item = (void *)bt + le16_to_cpu(bt->item_offs[i]);
ref = (void *)item->val;