From 5aaa26fe34ca2cbdf6f934a3a29c412db39a2441 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 19 Jan 2016 15:50:15 +0000 Subject: [PATCH] [thin_ls] only run pass1 if needed --- thin-provisioning/thin_ls.cc | 57 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/thin-provisioning/thin_ls.cc b/thin-provisioning/thin_ls.cc index adc58d1..be34fca 100644 --- a/thin-provisioning/thin_ls.cc +++ b/thin-provisioning/thin_ls.cc @@ -341,6 +341,21 @@ namespace { //------------------------------------------------ + bool pass1_needed(vector const &fields) { + vector::const_iterator it; + for (it = fields.begin(); it != fields.end(); ++it) { + if (*it == EXCLUSIVE_BLOCKS || + *it == SHARED_BLOCKS || + *it == EXCLUSIVE_SECTORS || + *it == SHARED_SECTORS || + *it == EXCLUSIVE || + *it == SHARED) + return true; + } + + return false; + } + void ls_(string const &path, ostream &out, struct flags &flags) { grid_layout grid; @@ -359,11 +374,14 @@ namespace { walk_device_tree(*md->details_, de, *dd_policy); mapping_set mappings(md->data_sm_->get_nr_blocks()); - - dd_map const &map = de.get_details(); dd_map::const_iterator it; - for (it = map.begin(); it != map.end(); ++it) - pass1(md, mappings, it->first); + dd_map const &map = de.get_details(); + + bool some_exclusive_fields = pass1_needed(flags.fields); + if (some_exclusive_fields) { + for (it = map.begin(); it != map.end(); ++it) + pass1(md, mappings, it->first); + } if (flags.headers) print_headers(grid, flags.fields); @@ -371,7 +389,10 @@ namespace { for (it = map.begin(); it != map.end(); ++it) { vector::const_iterator f; - optional exclusive; + block_address exclusive = 0; + + if (some_exclusive_fields) + exclusive = count_exclusives(md, mappings, it->first); for (f = flags.fields.begin(); f != flags.fields.end(); ++f) { switch (*f) { @@ -384,15 +405,11 @@ namespace { break; case EXCLUSIVE_BLOCKS: - if (!exclusive) - exclusive = count_exclusives(md, mappings, it->first); - grid.field(*exclusive); + grid.field(exclusive); break; case SHARED_BLOCKS: - if (!exclusive) - exclusive = count_exclusives(md, mappings, it->first); - grid.field(it->second.mapped_blocks_ - *exclusive); + grid.field(it->second.mapped_blocks_ - exclusive); break; case MAPPED_SECTORS: @@ -400,15 +417,11 @@ namespace { break; case EXCLUSIVE_SECTORS: - if (!exclusive) - exclusive = count_exclusives(md, mappings, it->first); - grid.field(*exclusive * block_size); + grid.field(exclusive * block_size); break; case SHARED_SECTORS: - if (!exclusive) - exclusive = count_exclusives(md, mappings, it->first); - grid.field((it->second.mapped_blocks_ - *exclusive) * block_size); + grid.field((it->second.mapped_blocks_ - exclusive) * block_size); break; @@ -419,20 +432,14 @@ namespace { break; case EXCLUSIVE: - if (!exclusive) - exclusive = count_exclusives(md, mappings, it->first); - grid.field( - format_disk_unit(*exclusive * block_size, + format_disk_unit(exclusive * block_size, UNIT_SECTOR)); break; case SHARED: - if (!exclusive) - exclusive = count_exclusives(md, mappings, it->first); - grid.field( - format_disk_unit((it->second.mapped_blocks_ - *exclusive) * + format_disk_unit((it->second.mapped_blocks_ - exclusive) * block_size, UNIT_SECTOR)); break;