From 285ea3a807d6158b7d3381ad97205e8e43a5c5f4 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 15 Feb 2020 22:46:24 +0100 Subject: Move block block accounting to the other end of the block pipeline This commit moves all of the fragment/block accounting in the block processor over to the writing end of the pipeline. In order to do this, the sparse blocks are allowed to bubble through the pipeline. Signed-off-by: David Oberhollenzer --- lib/sqfs/block_processor/common.c | 19 +++++++++++++++++-- lib/sqfs/block_processor/fileapi.c | 23 +++-------------------- lib/sqfs/block_processor/internal.h | 1 - 3 files changed, 20 insertions(+), 23 deletions(-) (limited to 'lib/sqfs') diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c index c8dbbc2..002dad4 100644 --- a/lib/sqfs/block_processor/common.c +++ b/lib/sqfs/block_processor/common.c @@ -13,6 +13,16 @@ int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk) sqfs_u32 size; int err; + if (blk->flags & SQFS_BLK_IS_SPARSE) { + sqfs_inode_make_extended(blk->inode); + blk->inode->data.file_ext.sparse += blk->size; + blk->inode->extra[blk->inode->num_file_blocks] = 0; + blk->inode->num_file_blocks += 1; + + proc->stats.sparse_block_count += 1; + return 0; + } + size = blk->size; if (!(blk->flags & SQFS_BLK_IS_COMPRESSED)) size |= 1 << 24; @@ -29,7 +39,10 @@ int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk) if (err) return err; } else { - blk->inode->extra[blk->index] = size; + blk->inode->extra[blk->inode->num_file_blocks] = size; + blk->inode->num_file_blocks += 1; + + proc->stats.data_block_count += 1; } } @@ -44,7 +57,7 @@ int block_processor_do_block(sqfs_block_t *block, sqfs_compressor_t *cmp, { ssize_t ret; - if (block->size == 0) { + if (block->size == 0 || (block->flags & SQFS_BLK_IS_SPARSE)) { block->checksum = 0; return 0; } @@ -77,6 +90,8 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag, size_t size; int err; + proc->stats.total_frag_count += 1; + err = sqfs_frag_table_find_tail_end(proc->frag_tbl, frag->checksum, frag->size, &index, &offset); diff --git a/lib/sqfs/block_processor/fileapi.c b/lib/sqfs/block_processor/fileapi.c index dbe3cf2..7ca189e 100644 --- a/lib/sqfs/block_processor/fileapi.c +++ b/lib/sqfs/block_processor/fileapi.c @@ -49,38 +49,22 @@ int sqfs_block_processor_begin_file(sqfs_block_processor_t *proc, proc->inode = inode; proc->blk_flags = flags | SQFS_BLK_FIRST_BLOCK; - proc->blk_index = 0; proc->blk_current = NULL; return 0; } static int flush_block(sqfs_block_processor_t *proc, sqfs_block_t *block) { - block->index = proc->blk_index++; block->flags = proc->blk_flags; block->inode = proc->inode; if (is_zero_block(block->data, block->size)) { - sqfs_inode_make_extended(proc->inode); - proc->inode->data.file_ext.sparse += block->size; - proc->inode->num_file_blocks += 1; - proc->inode->extra[block->index] = 0; - free(block); - - proc->stats.sparse_block_count += 1; - return 0; - } - - if (block->size < proc->max_block_size && - !(block->flags & SQFS_BLK_DONT_FRAGMENT)) { + block->flags |= SQFS_BLK_IS_SPARSE; + } else if (block->size < proc->max_block_size && + !(block->flags & SQFS_BLK_DONT_FRAGMENT)) { block->flags |= SQFS_BLK_IS_FRAGMENT; - - proc->stats.total_frag_count += 1; } else { - proc->inode->num_file_blocks += 1; proc->blk_flags &= ~SQFS_BLK_FIRST_BLOCK; - - proc->stats.data_block_count += 1; } return enqueue_block(proc, block); @@ -162,6 +146,5 @@ int sqfs_block_processor_end_file(sqfs_block_processor_t *proc) proc->inode = NULL; proc->blk_flags = 0; - proc->blk_index = 0; return 0; } diff --git a/lib/sqfs/block_processor/internal.h b/lib/sqfs/block_processor/internal.h index 45db014..cea820f 100644 --- a/lib/sqfs/block_processor/internal.h +++ b/lib/sqfs/block_processor/internal.h @@ -90,7 +90,6 @@ struct sqfs_block_processor_t { sqfs_inode_generic_t *inode; sqfs_block_t *blk_current; sqfs_u32 blk_flags; - size_t blk_index; /* used only by workers */ size_t max_block_size; -- cgit v1.2.3