diff --git a/utils/src/format.h b/utils/src/format.h index 4e9eeaad..2a3605c4 100644 --- a/utils/src/format.h +++ b/utils/src/format.h @@ -104,28 +104,26 @@ struct scoutfs_key { #define SCOUTFS_MAX_ITEM_LEN 512 -struct scoutfs_treap_root { - __le16 off; -} __packed; - -struct scoutfs_treap_node { - __le16 parent; - __le16 left; - __le16 right; - __le32 prio; -} __packed; - struct scoutfs_btree_root { u8 height; struct scoutfs_block_ref ref; } __packed; +/* + * @free_end: records the byte offset of the first byte after the free + * space in the block between the header and the first item. New items + * are allocated by subtracting the space they need. + * + * @free_reclaim: records the number of bytes of free space amongst the + * items after free_end. If a block is compacted then this much new + * free space would be reclaimed. + */ struct scoutfs_btree_block { struct scoutfs_block_header hdr; - struct scoutfs_treap_root treap; - __le16 total_free; - __le16 tail_free; - __le16 nr_items; + __le16 free_end; + __le16 free_reclaim; + __u8 nr_items; + __le16 item_offs[0]; } __packed; /* @@ -134,7 +132,6 @@ struct scoutfs_btree_block { */ struct scoutfs_btree_item { struct scoutfs_key key; - struct scoutfs_treap_node tnode; __le64 seq; __le16 val_len; char val[0]; diff --git a/utils/src/mkfs.c b/utils/src/mkfs.c index 83ad7ef3..202e77a4 100644 --- a/utils/src/mkfs.c +++ b/utils/src/mkfs.c @@ -190,15 +190,15 @@ 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 = cpu_to_le16(1); + bt->nr_items = 1; + bt->free_end = cpu_to_le16(SCOUTFS_BLOCK_SIZE - sizeof(*item) - + sizeof(*inode)); + bt->free_reclaim = 0; + bt->item_offs[0] = bt->free_end; - item = (void *)(bt + 1); + item = (void *)bt + le16_to_cpu(bt->free_end); item->seq = cpu_to_le64(1); item->key = root_key; - item->tnode.parent = 0; - item->tnode.left = 0; - item->tnode.right = 0; - pseudo_random_bytes(&item->tnode.prio, sizeof(item->tnode.prio)); item->val_len = cpu_to_le16(sizeof(struct scoutfs_inode)); inode = (void *)(item + 1); @@ -211,11 +211,6 @@ static int write_new_fs(char *path, int fd) inode->mtime.sec = inode->atime.sec; inode->mtime.nsec = inode->atime.nsec; - bt->treap.off = cpu_to_le16((char *)&item->tnode - (char *)&bt->treap); - bt->total_free = cpu_to_le16(SCOUTFS_BLOCK_SIZE - - ((char *)(inode + 1) - (char *)bt)); - bt->tail_free = bt->total_free; - ret = write_block(fd, blkno, super, &bt->hdr); if (ret) goto out; diff --git a/utils/src/print.c b/utils/src/print.c index 8b99bb27..1530d3e1 100644 --- a/utils/src/print.c +++ b/utils/src/print.c @@ -58,11 +58,11 @@ static void print_block_header(struct scoutfs_block_header *hdr) static void print_inode(struct scoutfs_inode *inode) { - printf(" inode: size: %llu blocks: %llu nlink: %u\n" - " uid: %u gid: %u mode: 0%o rdev: 0x%x\n" - " salt: 0x%x\n" - " atime: %llu.%08u ctime: %llu.%08u\n" - " mtime: %llu.%08u\n", + printf(" inode: size: %llu blocks: %llu nlink: %u\n" + " uid: %u gid: %u mode: 0%o rdev: 0x%x\n" + " salt: 0x%x\n" + " atime: %llu.%08u ctime: %llu.%08u\n" + " mtime: %llu.%08u\n", le64_to_cpu(inode->size), le64_to_cpu(inode->blocks), le32_to_cpu(inode->nlink), le32_to_cpu(inode->uid), le32_to_cpu(inode->gid), le32_to_cpu(inode->mode), @@ -95,17 +95,8 @@ static void print_block_ref(struct scoutfs_block_ref *ref) le64_to_cpu(ref->blkno), le64_to_cpu(ref->seq)); } -static void print_btree_item(unsigned int off, struct scoutfs_btree_item *item, - u8 level) +static void print_btree_val(struct scoutfs_btree_item *item, u8 level) { - printf(" item: key "SKF" seq %llu val_len %u off %u tnode: parent %u left %u right %u " - "prio %x\n", - SKA(&item->key), le64_to_cpu(item->seq), - le16_to_cpu(item->val_len), off, - le16_to_cpu(item->tnode.parent), - le16_to_cpu(item->tnode.left), - le16_to_cpu(item->tnode.right), - le32_to_cpu(item->tnode.prio)); if (level) { print_block_ref((void *)item->val); @@ -127,7 +118,6 @@ 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 off; int ret = 0; int err; int i; @@ -138,38 +128,29 @@ static int print_btree_block(int fd, __le64 blkno, u8 level) printf("btree blkno %llu\n", le64_to_cpu(blkno)); print_block_header(&bt->hdr); - printf(" treap.off %u total_free %u tail_free %u nr_items %u\n", - le16_to_cpu(bt->treap.off), - le16_to_cpu(bt->total_free), - le16_to_cpu(bt->tail_free), - le16_to_cpu(bt->nr_items)); + 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); - /* XXX just print in offset order */ - item = (void *)(bt + 1); - for (i = 0; i < le16_to_cpu(bt->nr_items); i++) { - if (item->tnode.parent == cpu_to_le16(1)) { - i--; - } else { - off = (char *)&item->tnode - (char *)&bt->treap; - print_btree_item(off, item, level); - } + for (i = 0; i < bt->nr_items; i++) { + item = (void *)bt + le16_to_cpu(bt->item_offs[i]); - item = (void *)&item->val[le16_to_cpu(item->val_len)]; + printf(" [%u] off %u: key "SKF" seq %llu val_len %u\n", + i, le16_to_cpu(bt->item_offs[i]), + SKA(&item->key), le64_to_cpu(item->seq), + le16_to_cpu(item->val_len)); + + print_btree_val(item, level); } - item = (void *)(bt + 1); - for (i = 0; level && i < le16_to_cpu(bt->nr_items); i++) { - if (item->tnode.parent == cpu_to_le16(1)) { - i--; - } else { - ref = (void *)item->val; + for (i = 0; level && i < bt->nr_items; i++) { + item = (void *)bt + le16_to_cpu(bt->item_offs[i]); - err = print_btree_block(fd, ref->blkno, level - 1); - if (err && !ret) - ret = err; - } - - item = (void *)&item->val[le16_to_cpu(item->val_len)]; + ref = (void *)item->val; + err = print_btree_block(fd, ref->blkno, level - 1); + if (err && !ret) + ret = err; } free(bt);