From 283cc27cbdcfa96e5eff5243d861aba979e0c13f Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 14:03:27 +0200 Subject: [PATCH 01/27] create_xml_data: fix nr_data_blocks --- thin-provisioning/create_xml_data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 42942cb..0168b40 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -105,7 +105,7 @@ end def xml_metadata(opts, units) blocks, to = opts[:thinsize] / opts[:blocksize], 0 - puts begin_superblock(opts[:blocksize], blocks) + puts begin_superblock(opts[:blocksize], opts[:thins] * blocks) 0.step(opts[:thins] - 1) do |devid| puts begin_device(devid, opts[:thinsize]) if opts[:range] From 420c8ef868cfa74f20e506085ae2884675141d48 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 14:22:03 +0200 Subject: [PATCH 02/27] create_xml_data: fix device and range_mapping --- thin-provisioning/create_xml_data | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 0168b40..4fb5127 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -99,7 +99,7 @@ def single_mapping(from, to = 4711) end def range_mapping(from, to, length) - " \n" + " \n" end def xml_metadata(opts, units) @@ -107,7 +107,7 @@ def xml_metadata(opts, units) puts begin_superblock(opts[:blocksize], opts[:thins] * blocks) 0.step(opts[:thins] - 1) do |devid| - puts begin_device(devid, opts[:thinsize]) + puts begin_device(devid, blocks) if opts[:range] puts range_mapping(0, to, blocks) to += blocks From 0c715c652e6fa5c50ab962c77712773f06053f81 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 14:59:25 +0200 Subject: [PATCH 03/27] thin_metadata_size,create_xml_data: fix units --- thin-provisioning/create_xml_data | 4 ++-- thin-provisioning/thin_metadata_size | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 4fb5127..0b7438b 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -15,14 +15,14 @@ $prg = Pathname.new($0).basename def init_units units = {} units[:bytes_per_sector] = 512 - units[:chars] = "bsKkMmGgTtPpEeZzYy" + units[:chars] = "bskKmMgGtTpPeEzZyY" units[:strings] = [ 'bytes', 'sectors', 'kilobytes', 'kibibytes', 'megabytes', 'mebibytes', 'gigabytes', 'gibibytes', 'terabytes', 'tebibytes', 'petabytes', 'pebibytes', 'exabytes', 'ebibytes', 'zetabytes', 'zebibytes', 'yottabytes', 'yobibytes' ] units[:factors] = [ 1, units[:bytes_per_sector] ] - 1.step(8) { |e| units[:factors] += [ 1000**e, 1024**e ] } + 1.step(8) { |e| units[:factors] += [ 1024**e, 1000**e ] } units end diff --git a/thin-provisioning/thin_metadata_size b/thin-provisioning/thin_metadata_size index 0895af4..04e9eb7 100755 --- a/thin-provisioning/thin_metadata_size +++ b/thin-provisioning/thin_metadata_size @@ -20,14 +20,14 @@ $prg = Pathname.new($0).basename def init_units units = {} units[:bytes_per_sector] = 512 - units[:chars] = "bsKkMmGgTtPpEeZzYy" + units[:chars] = "bskKmMgGtTpPeEzZyY" units[:strings] = [ 'bytes', 'sectors', 'kilobytes', 'kibibytes', 'megabytes', 'mebibytes', 'gigabytes', 'gibibytes', 'terabytes', 'tebibytes', 'petabytes', 'pebibytes', 'exabytes', 'ebibytes', 'zetabytes', 'zebibytes', 'yottabytes', 'yobibytes' ] units[:factors] = [ 1, units[:bytes_per_sector] ] - 1.step(8) { |e| units[:factors] += [ 1000**e, 1024**e ] } + 1.step(8) { |e| units[:factors] += [ 1024**e, 1000**e ] } units end From 66d8dd4e282103c0a8276d59ba48ae743f6f1695 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 16:02:05 +0200 Subject: [PATCH 04/27] thin_metadata_size: drop signe_mapping to = --- thin-provisioning/create_xml_data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 0b7438b..f6b442e 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -94,7 +94,7 @@ def end_device " \n" end -def single_mapping(from, to = 4711) +def single_mapping(from, to) " \n" end From 0e8c0774154203c817a6991ef8aba6f5d3b3dd76 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 18:06:07 +0200 Subject: [PATCH 05/27] thin_metadata_size: check for block size > 0 --- thin-provisioning/thin_metadata_size | 1 + 1 file changed, 1 insertion(+) diff --git a/thin-provisioning/thin_metadata_size b/thin-provisioning/thin_metadata_size index 04e9eb7..4d10c4f 100755 --- a/thin-provisioning/thin_metadata_size +++ b/thin-provisioning/thin_metadata_size @@ -37,6 +37,7 @@ end def check_opts(opts) abort "#{$prg} - 3 arguments required!" if opts.length < 3 + abort "#{$prg} - block size must be > 0" if opts[:blocksize] <= 0 abort "#{$prg} - poolsize must be much larger than blocksize" if opts[:poolsize] < opts[:blocksize] abort "#{$prg} - maximum number of thin provisioned devices must be > 0" if opts[:maxthins].nil? || opts[:maxthins] == 0 end From fbfc0817afebe554e9b35b892ac6476653e72572 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 18:06:16 +0200 Subject: [PATCH 06/27] create_xml_data: support --size-variation and check for block size > 0 --- thin-provisioning/create_xml_data | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index f6b442e..50b7bfd 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -40,8 +40,10 @@ end def check_opts(opts) abort "#{$prg} - 3 arguments required!" if opts.length < 3 + abort "#{$prg} - block size must be > 0" if opts[:blocksize] <= 0 abort "#{$prg} - size must be much greater/equal blocksize" if opts[:thinsize] < opts[:blocksize] abort "#{$prg} - number of thin provisioned devices or snapshots must be > 0" if opts[:thins].nil? || opts[:thins] == 0 + abort "#{$prg} - size variation too large!" if !opts[:variation].nil? && (opts[:variation] > 2 * (opts[:thinsize] - opts[:blocksize])) end def parse_command_line(argv, units) @@ -62,6 +64,9 @@ def parse_command_line(argv, units) o.on("-t", "--thins #THINS", Integer, "Sum of thin devices and snapshots.") do |mt| opts[:thins] = mt end + o.on("-v", "--size-variation SIZE[#{units[:chars]}]", String, "Size variation of thin devices and snapshots.") do |sv| + opts[:variation] = to_sectors(sv, units) + end o.on("-h", "--help", "Output this help.") do puts o exit @@ -102,17 +107,26 @@ def range_mapping(from, to, length) " \n" end -def xml_metadata(opts, units) - blocks, to = opts[:thinsize] / opts[:blocksize], 0 +def blocks(opts) + opts[:thinsize] / opts[:blocksize] +end - puts begin_superblock(opts[:blocksize], opts[:thins] * blocks) - 0.step(opts[:thins] - 1) do |devid| - puts begin_device(devid, blocks) +def this_blocks(opts) + opts[:variation].nil? ? blocks(opts) : (2 * opts[:thinsize] - rand(opts[:variation])) / 2 / opts[:blocksize] +end + +def xml_metadata(opts, units) + to = 0 + + puts begin_superblock(opts[:blocksize], 2 * opts[:thins] * blocks(opts)) + 0.step(opts[:thins] - 1) do |dev_id| + b = this_blocks(opts) + puts begin_device(dev_id, b) if opts[:range] - puts range_mapping(0, to, blocks) - to += blocks + puts range_mapping(0, to, b) + to += b else - 0.step(blocks - 1) do |from| + 0.step(b - 1) do |from| puts single_mapping(from, to) to += 1 end From d87fa1e0eefb9d4185e2fef66a92b68eab3fa9c1 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 14:03:27 +0200 Subject: [PATCH 07/27] create_xml_data: fix nr_data_blocks --- thin-provisioning/create_xml_data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 42942cb..0168b40 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -105,7 +105,7 @@ end def xml_metadata(opts, units) blocks, to = opts[:thinsize] / opts[:blocksize], 0 - puts begin_superblock(opts[:blocksize], blocks) + puts begin_superblock(opts[:blocksize], opts[:thins] * blocks) 0.step(opts[:thins] - 1) do |devid| puts begin_device(devid, opts[:thinsize]) if opts[:range] From 8850204e8c1f85e76fb022c704ba1de19332e060 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 14:22:03 +0200 Subject: [PATCH 08/27] create_xml_data: fix device and range_mapping --- thin-provisioning/create_xml_data | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 0168b40..4fb5127 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -99,7 +99,7 @@ def single_mapping(from, to = 4711) end def range_mapping(from, to, length) - " \n" + " \n" end def xml_metadata(opts, units) @@ -107,7 +107,7 @@ def xml_metadata(opts, units) puts begin_superblock(opts[:blocksize], opts[:thins] * blocks) 0.step(opts[:thins] - 1) do |devid| - puts begin_device(devid, opts[:thinsize]) + puts begin_device(devid, blocks) if opts[:range] puts range_mapping(0, to, blocks) to += blocks From a54f7d18f84b729fd99fc918e9d6cb543c0f7eb4 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 14:59:25 +0200 Subject: [PATCH 09/27] thin_metadata_size,create_xml_data: fix units --- thin-provisioning/create_xml_data | 4 ++-- thin-provisioning/thin_metadata_size | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 4fb5127..0b7438b 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -15,14 +15,14 @@ $prg = Pathname.new($0).basename def init_units units = {} units[:bytes_per_sector] = 512 - units[:chars] = "bsKkMmGgTtPpEeZzYy" + units[:chars] = "bskKmMgGtTpPeEzZyY" units[:strings] = [ 'bytes', 'sectors', 'kilobytes', 'kibibytes', 'megabytes', 'mebibytes', 'gigabytes', 'gibibytes', 'terabytes', 'tebibytes', 'petabytes', 'pebibytes', 'exabytes', 'ebibytes', 'zetabytes', 'zebibytes', 'yottabytes', 'yobibytes' ] units[:factors] = [ 1, units[:bytes_per_sector] ] - 1.step(8) { |e| units[:factors] += [ 1000**e, 1024**e ] } + 1.step(8) { |e| units[:factors] += [ 1024**e, 1000**e ] } units end diff --git a/thin-provisioning/thin_metadata_size b/thin-provisioning/thin_metadata_size index 0895af4..04e9eb7 100755 --- a/thin-provisioning/thin_metadata_size +++ b/thin-provisioning/thin_metadata_size @@ -20,14 +20,14 @@ $prg = Pathname.new($0).basename def init_units units = {} units[:bytes_per_sector] = 512 - units[:chars] = "bsKkMmGgTtPpEeZzYy" + units[:chars] = "bskKmMgGtTpPeEzZyY" units[:strings] = [ 'bytes', 'sectors', 'kilobytes', 'kibibytes', 'megabytes', 'mebibytes', 'gigabytes', 'gibibytes', 'terabytes', 'tebibytes', 'petabytes', 'pebibytes', 'exabytes', 'ebibytes', 'zetabytes', 'zebibytes', 'yottabytes', 'yobibytes' ] units[:factors] = [ 1, units[:bytes_per_sector] ] - 1.step(8) { |e| units[:factors] += [ 1000**e, 1024**e ] } + 1.step(8) { |e| units[:factors] += [ 1024**e, 1000**e ] } units end From 4e0e2e30d3e21a35e4f475a9295d63552ccb761b Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 16:02:05 +0200 Subject: [PATCH 10/27] thin_metadata_size: drop signe_mapping to = --- thin-provisioning/create_xml_data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 0b7438b..f6b442e 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -94,7 +94,7 @@ def end_device " \n" end -def single_mapping(from, to = 4711) +def single_mapping(from, to) " \n" end From daf8cf490415350409a2e2bcaa035eee03d82eec Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 18:06:07 +0200 Subject: [PATCH 11/27] thin_metadata_size: check for block size > 0 --- thin-provisioning/thin_metadata_size | 1 + 1 file changed, 1 insertion(+) diff --git a/thin-provisioning/thin_metadata_size b/thin-provisioning/thin_metadata_size index 04e9eb7..4d10c4f 100755 --- a/thin-provisioning/thin_metadata_size +++ b/thin-provisioning/thin_metadata_size @@ -37,6 +37,7 @@ end def check_opts(opts) abort "#{$prg} - 3 arguments required!" if opts.length < 3 + abort "#{$prg} - block size must be > 0" if opts[:blocksize] <= 0 abort "#{$prg} - poolsize must be much larger than blocksize" if opts[:poolsize] < opts[:blocksize] abort "#{$prg} - maximum number of thin provisioned devices must be > 0" if opts[:maxthins].nil? || opts[:maxthins] == 0 end From 8eb568619ebd713aa3423897aa56f7702069494c Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 18:06:16 +0200 Subject: [PATCH 12/27] create_xml_data: support --size-variation and check for block size > 0 --- thin-provisioning/create_xml_data | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index f6b442e..50b7bfd 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -40,8 +40,10 @@ end def check_opts(opts) abort "#{$prg} - 3 arguments required!" if opts.length < 3 + abort "#{$prg} - block size must be > 0" if opts[:blocksize] <= 0 abort "#{$prg} - size must be much greater/equal blocksize" if opts[:thinsize] < opts[:blocksize] abort "#{$prg} - number of thin provisioned devices or snapshots must be > 0" if opts[:thins].nil? || opts[:thins] == 0 + abort "#{$prg} - size variation too large!" if !opts[:variation].nil? && (opts[:variation] > 2 * (opts[:thinsize] - opts[:blocksize])) end def parse_command_line(argv, units) @@ -62,6 +64,9 @@ def parse_command_line(argv, units) o.on("-t", "--thins #THINS", Integer, "Sum of thin devices and snapshots.") do |mt| opts[:thins] = mt end + o.on("-v", "--size-variation SIZE[#{units[:chars]}]", String, "Size variation of thin devices and snapshots.") do |sv| + opts[:variation] = to_sectors(sv, units) + end o.on("-h", "--help", "Output this help.") do puts o exit @@ -102,17 +107,26 @@ def range_mapping(from, to, length) " \n" end -def xml_metadata(opts, units) - blocks, to = opts[:thinsize] / opts[:blocksize], 0 +def blocks(opts) + opts[:thinsize] / opts[:blocksize] +end - puts begin_superblock(opts[:blocksize], opts[:thins] * blocks) - 0.step(opts[:thins] - 1) do |devid| - puts begin_device(devid, blocks) +def this_blocks(opts) + opts[:variation].nil? ? blocks(opts) : (2 * opts[:thinsize] - rand(opts[:variation])) / 2 / opts[:blocksize] +end + +def xml_metadata(opts, units) + to = 0 + + puts begin_superblock(opts[:blocksize], 2 * opts[:thins] * blocks(opts)) + 0.step(opts[:thins] - 1) do |dev_id| + b = this_blocks(opts) + puts begin_device(dev_id, b) if opts[:range] - puts range_mapping(0, to, blocks) - to += blocks + puts range_mapping(0, to, b) + to += b else - 0.step(blocks - 1) do |from| + 0.step(b - 1) do |from| puts single_mapping(from, to) to += 1 end From ab83844ffb89ec1ef5db19891f01c88b8635bd13 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Thu, 27 Jun 2013 15:04:57 +0200 Subject: [PATCH 13/27] create_xml_data: remove space in dev_id ouput --- thin-provisioning/create_xml_data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 50b7bfd..6ef50d0 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -92,7 +92,7 @@ def end_superblock end def begin_device(devid, size) - " \n" + " \n" end def end_device From d0baf34139c5b80add70845928add008b1d832c7 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Thu, 27 Jun 2013 15:36:50 +0200 Subject: [PATCH 14/27] create_xml_data: adjust filed order to thin_dumo format; fix nr_data_blocks --- thin-provisioning/create_xml_data | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 6ef50d0..a49eec5 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -100,11 +100,11 @@ def end_device end def single_mapping(from, to) - " \n" + " \n" end def range_mapping(from, to, length) - " \n" + " \n" end def blocks(opts) @@ -116,11 +116,17 @@ def this_blocks(opts) end def xml_metadata(opts, units) - to = 0 + nr_data_blocks, to = 0, 0 + blks = [] - puts begin_superblock(opts[:blocksize], 2 * opts[:thins] * blocks(opts)) + 0.step(opts[:thins] - 1) do + blks << this_blocks(opts) + nr_data_blocks += blks[-1] + end + + puts begin_superblock(opts[:blocksize], nr_data_blocks) 0.step(opts[:thins] - 1) do |dev_id| - b = this_blocks(opts) + b = blks.shift puts begin_device(dev_id, b) if opts[:range] puts range_mapping(0, to, b) From 2c3530515aa5d8bb0d533dcaf8374fe0acd5c158 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Thu, 27 Jun 2013 15:57:12 +0200 Subject: [PATCH 15/27] create_xml_data: adjust to thinp_xml output --- thin-provisioning/create_xml_data | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index a49eec5..0a13000 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -84,7 +84,7 @@ def parse_command_line(argv, units) end def begin_superblock(blocksize, nr_data_blocks) - "\n" + "\n" end def end_superblock @@ -100,11 +100,11 @@ def end_device end def single_mapping(from, to) - " \n" + " \n" end def range_mapping(from, to, length) - " \n" + " \n" end def blocks(opts) From 4f320be8da79f5eaac8cd0051a55a9f34b4cf83c Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Fri, 28 Jun 2013 12:10:17 +0200 Subject: [PATCH 16/27] create_xml_data: fiddling --- thin-provisioning/create_xml_data | 38 ++++++++++++++----------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 0a13000..3d5e322 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -41,7 +41,7 @@ end def check_opts(opts) abort "#{$prg} - 3 arguments required!" if opts.length < 3 abort "#{$prg} - block size must be > 0" if opts[:blocksize] <= 0 - abort "#{$prg} - size must be much greater/equal blocksize" if opts[:thinsize] < opts[:blocksize] + abort "#{$prg} - thin size must be much greater/equal blocksize" if opts[:thinsize] < opts[:blocksize] abort "#{$prg} - number of thin provisioned devices or snapshots must be > 0" if opts[:thins].nil? || opts[:thins] == 0 abort "#{$prg} - size variation too large!" if !opts[:variation].nil? && (opts[:variation] > 2 * (opts[:thinsize] - opts[:blocksize])) end @@ -84,27 +84,27 @@ def parse_command_line(argv, units) end def begin_superblock(blocksize, nr_data_blocks) - "\n" + "" end def end_superblock - "\n" + "" end def begin_device(devid, size) - " \n" + " " end def end_device - " \n" + " " end def single_mapping(from, to) - " \n" + " " end def range_mapping(from, to, length) - " \n" + " " end def blocks(opts) @@ -116,28 +116,24 @@ def this_blocks(opts) end def xml_metadata(opts, units) - nr_data_blocks, to = 0, 0 - blks = [] + blks, dev_id, nr_data_blocks, to = [], 0, 0, 0 0.step(opts[:thins] - 1) do - blks << this_blocks(opts) - nr_data_blocks += blks[-1] + blks << (b = this_blocks(opts)) + nr_data_blocks += b end puts begin_superblock(opts[:blocksize], nr_data_blocks) - 0.step(opts[:thins] - 1) do |dev_id| - b = blks.shift - puts begin_device(dev_id, b) + blks.each do |b| if opts[:range] - puts range_mapping(0, to, b) - to += b + puts begin_device(dev_id, b), range_mapping(0, to, b), end_device else - 0.step(b - 1) do |from| - puts single_mapping(from, to) - to += 1 - end + puts begin_device(dev_id, b) + 0.step(b - 1) { |from| puts single_mapping(from, to + from) } + puts end_device end - puts end_device + dev_id += 1 + to += b end puts end_superblock end From 24c664f3cbfd7bc5a94a88fd744d007b0b6dda99 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 14:03:27 +0200 Subject: [PATCH 17/27] create_xml_data: fix nr_data_blocks --- thin-provisioning/create_xml_data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 42942cb..0168b40 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -105,7 +105,7 @@ end def xml_metadata(opts, units) blocks, to = opts[:thinsize] / opts[:blocksize], 0 - puts begin_superblock(opts[:blocksize], blocks) + puts begin_superblock(opts[:blocksize], opts[:thins] * blocks) 0.step(opts[:thins] - 1) do |devid| puts begin_device(devid, opts[:thinsize]) if opts[:range] From a2f22fd55e1d2e7a3af4b13e7d4c8d34b6b220d9 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 14:22:03 +0200 Subject: [PATCH 18/27] create_xml_data: fix device and range_mapping --- thin-provisioning/create_xml_data | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 0168b40..4fb5127 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -99,7 +99,7 @@ def single_mapping(from, to = 4711) end def range_mapping(from, to, length) - " \n" + " \n" end def xml_metadata(opts, units) @@ -107,7 +107,7 @@ def xml_metadata(opts, units) puts begin_superblock(opts[:blocksize], opts[:thins] * blocks) 0.step(opts[:thins] - 1) do |devid| - puts begin_device(devid, opts[:thinsize]) + puts begin_device(devid, blocks) if opts[:range] puts range_mapping(0, to, blocks) to += blocks From 191bdd177e571c5966ad919c343ccc9c0d5239a5 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 14:59:25 +0200 Subject: [PATCH 19/27] thin_metadata_size,create_xml_data: fix units --- thin-provisioning/create_xml_data | 4 ++-- thin-provisioning/thin_metadata_size | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 4fb5127..0b7438b 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -15,14 +15,14 @@ $prg = Pathname.new($0).basename def init_units units = {} units[:bytes_per_sector] = 512 - units[:chars] = "bsKkMmGgTtPpEeZzYy" + units[:chars] = "bskKmMgGtTpPeEzZyY" units[:strings] = [ 'bytes', 'sectors', 'kilobytes', 'kibibytes', 'megabytes', 'mebibytes', 'gigabytes', 'gibibytes', 'terabytes', 'tebibytes', 'petabytes', 'pebibytes', 'exabytes', 'ebibytes', 'zetabytes', 'zebibytes', 'yottabytes', 'yobibytes' ] units[:factors] = [ 1, units[:bytes_per_sector] ] - 1.step(8) { |e| units[:factors] += [ 1000**e, 1024**e ] } + 1.step(8) { |e| units[:factors] += [ 1024**e, 1000**e ] } units end diff --git a/thin-provisioning/thin_metadata_size b/thin-provisioning/thin_metadata_size index 0895af4..04e9eb7 100755 --- a/thin-provisioning/thin_metadata_size +++ b/thin-provisioning/thin_metadata_size @@ -20,14 +20,14 @@ $prg = Pathname.new($0).basename def init_units units = {} units[:bytes_per_sector] = 512 - units[:chars] = "bsKkMmGgTtPpEeZzYy" + units[:chars] = "bskKmMgGtTpPeEzZyY" units[:strings] = [ 'bytes', 'sectors', 'kilobytes', 'kibibytes', 'megabytes', 'mebibytes', 'gigabytes', 'gibibytes', 'terabytes', 'tebibytes', 'petabytes', 'pebibytes', 'exabytes', 'ebibytes', 'zetabytes', 'zebibytes', 'yottabytes', 'yobibytes' ] units[:factors] = [ 1, units[:bytes_per_sector] ] - 1.step(8) { |e| units[:factors] += [ 1000**e, 1024**e ] } + 1.step(8) { |e| units[:factors] += [ 1024**e, 1000**e ] } units end From a084e053a54964825ab1d27fe575c6f3b59da133 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 16:02:05 +0200 Subject: [PATCH 20/27] thin_metadata_size: drop signe_mapping to = --- thin-provisioning/create_xml_data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 0b7438b..f6b442e 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -94,7 +94,7 @@ def end_device " \n" end -def single_mapping(from, to = 4711) +def single_mapping(from, to) " \n" end From 57fdceb26d8666c01bfca270dc9d8d6e15b61e8d Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 18:06:07 +0200 Subject: [PATCH 21/27] thin_metadata_size: check for block size > 0 --- thin-provisioning/thin_metadata_size | 1 + 1 file changed, 1 insertion(+) diff --git a/thin-provisioning/thin_metadata_size b/thin-provisioning/thin_metadata_size index 04e9eb7..4d10c4f 100755 --- a/thin-provisioning/thin_metadata_size +++ b/thin-provisioning/thin_metadata_size @@ -37,6 +37,7 @@ end def check_opts(opts) abort "#{$prg} - 3 arguments required!" if opts.length < 3 + abort "#{$prg} - block size must be > 0" if opts[:blocksize] <= 0 abort "#{$prg} - poolsize must be much larger than blocksize" if opts[:poolsize] < opts[:blocksize] abort "#{$prg} - maximum number of thin provisioned devices must be > 0" if opts[:maxthins].nil? || opts[:maxthins] == 0 end From 993dad400b33baf6145c1a9ed601ed4ef4dcfa9b Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 18:06:16 +0200 Subject: [PATCH 22/27] create_xml_data: support --size-variation and check for block size > 0 --- thin-provisioning/create_xml_data | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index f6b442e..50b7bfd 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -40,8 +40,10 @@ end def check_opts(opts) abort "#{$prg} - 3 arguments required!" if opts.length < 3 + abort "#{$prg} - block size must be > 0" if opts[:blocksize] <= 0 abort "#{$prg} - size must be much greater/equal blocksize" if opts[:thinsize] < opts[:blocksize] abort "#{$prg} - number of thin provisioned devices or snapshots must be > 0" if opts[:thins].nil? || opts[:thins] == 0 + abort "#{$prg} - size variation too large!" if !opts[:variation].nil? && (opts[:variation] > 2 * (opts[:thinsize] - opts[:blocksize])) end def parse_command_line(argv, units) @@ -62,6 +64,9 @@ def parse_command_line(argv, units) o.on("-t", "--thins #THINS", Integer, "Sum of thin devices and snapshots.") do |mt| opts[:thins] = mt end + o.on("-v", "--size-variation SIZE[#{units[:chars]}]", String, "Size variation of thin devices and snapshots.") do |sv| + opts[:variation] = to_sectors(sv, units) + end o.on("-h", "--help", "Output this help.") do puts o exit @@ -102,17 +107,26 @@ def range_mapping(from, to, length) " \n" end -def xml_metadata(opts, units) - blocks, to = opts[:thinsize] / opts[:blocksize], 0 +def blocks(opts) + opts[:thinsize] / opts[:blocksize] +end - puts begin_superblock(opts[:blocksize], opts[:thins] * blocks) - 0.step(opts[:thins] - 1) do |devid| - puts begin_device(devid, blocks) +def this_blocks(opts) + opts[:variation].nil? ? blocks(opts) : (2 * opts[:thinsize] - rand(opts[:variation])) / 2 / opts[:blocksize] +end + +def xml_metadata(opts, units) + to = 0 + + puts begin_superblock(opts[:blocksize], 2 * opts[:thins] * blocks(opts)) + 0.step(opts[:thins] - 1) do |dev_id| + b = this_blocks(opts) + puts begin_device(dev_id, b) if opts[:range] - puts range_mapping(0, to, blocks) - to += blocks + puts range_mapping(0, to, b) + to += b else - 0.step(blocks - 1) do |from| + 0.step(b - 1) do |from| puts single_mapping(from, to) to += 1 end From 27faf671ee4f2d76c3ba4fe081ae6af2a956f8c1 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Thu, 27 Jun 2013 15:04:57 +0200 Subject: [PATCH 23/27] create_xml_data: remove space in dev_id ouput --- thin-provisioning/create_xml_data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 50b7bfd..6ef50d0 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -92,7 +92,7 @@ def end_superblock end def begin_device(devid, size) - " \n" + " \n" end def end_device From dd8b9a7cd5693df94efe4b560536acb68582ba14 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Thu, 27 Jun 2013 15:36:50 +0200 Subject: [PATCH 24/27] create_xml_data: adjust filed order to thin_dumo format; fix nr_data_blocks --- thin-provisioning/create_xml_data | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 6ef50d0..a49eec5 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -100,11 +100,11 @@ def end_device end def single_mapping(from, to) - " \n" + " \n" end def range_mapping(from, to, length) - " \n" + " \n" end def blocks(opts) @@ -116,11 +116,17 @@ def this_blocks(opts) end def xml_metadata(opts, units) - to = 0 + nr_data_blocks, to = 0, 0 + blks = [] - puts begin_superblock(opts[:blocksize], 2 * opts[:thins] * blocks(opts)) + 0.step(opts[:thins] - 1) do + blks << this_blocks(opts) + nr_data_blocks += blks[-1] + end + + puts begin_superblock(opts[:blocksize], nr_data_blocks) 0.step(opts[:thins] - 1) do |dev_id| - b = this_blocks(opts) + b = blks.shift puts begin_device(dev_id, b) if opts[:range] puts range_mapping(0, to, b) From e486fe4bec13cbfe551112bdc139f26b5153c7a5 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Thu, 27 Jun 2013 15:57:12 +0200 Subject: [PATCH 25/27] create_xml_data: adjust to thinp_xml output --- thin-provisioning/create_xml_data | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index a49eec5..0a13000 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -84,7 +84,7 @@ def parse_command_line(argv, units) end def begin_superblock(blocksize, nr_data_blocks) - "\n" + "\n" end def end_superblock @@ -100,11 +100,11 @@ def end_device end def single_mapping(from, to) - " \n" + " \n" end def range_mapping(from, to, length) - " \n" + " \n" end def blocks(opts) From afe0fddee2fe27ef72d0af3fa826b119bbe3a206 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Fri, 28 Jun 2013 12:10:17 +0200 Subject: [PATCH 26/27] create_xml_data: fiddling --- thin-provisioning/create_xml_data | 38 ++++++++++++++----------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 0a13000..3d5e322 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -41,7 +41,7 @@ end def check_opts(opts) abort "#{$prg} - 3 arguments required!" if opts.length < 3 abort "#{$prg} - block size must be > 0" if opts[:blocksize] <= 0 - abort "#{$prg} - size must be much greater/equal blocksize" if opts[:thinsize] < opts[:blocksize] + abort "#{$prg} - thin size must be much greater/equal blocksize" if opts[:thinsize] < opts[:blocksize] abort "#{$prg} - number of thin provisioned devices or snapshots must be > 0" if opts[:thins].nil? || opts[:thins] == 0 abort "#{$prg} - size variation too large!" if !opts[:variation].nil? && (opts[:variation] > 2 * (opts[:thinsize] - opts[:blocksize])) end @@ -84,27 +84,27 @@ def parse_command_line(argv, units) end def begin_superblock(blocksize, nr_data_blocks) - "\n" + "" end def end_superblock - "\n" + "" end def begin_device(devid, size) - " \n" + " " end def end_device - " \n" + " " end def single_mapping(from, to) - " \n" + " " end def range_mapping(from, to, length) - " \n" + " " end def blocks(opts) @@ -116,28 +116,24 @@ def this_blocks(opts) end def xml_metadata(opts, units) - nr_data_blocks, to = 0, 0 - blks = [] + blks, dev_id, nr_data_blocks, to = [], 0, 0, 0 0.step(opts[:thins] - 1) do - blks << this_blocks(opts) - nr_data_blocks += blks[-1] + blks << (b = this_blocks(opts)) + nr_data_blocks += b end puts begin_superblock(opts[:blocksize], nr_data_blocks) - 0.step(opts[:thins] - 1) do |dev_id| - b = blks.shift - puts begin_device(dev_id, b) + blks.each do |b| if opts[:range] - puts range_mapping(0, to, b) - to += b + puts begin_device(dev_id, b), range_mapping(0, to, b), end_device else - 0.step(b - 1) do |from| - puts single_mapping(from, to) - to += 1 - end + puts begin_device(dev_id, b) + 0.step(b - 1) { |from| puts single_mapping(from, to + from) } + puts end_device end - puts end_device + dev_id += 1 + to += b end puts end_superblock end From ceabeed00ede9279b1174d5cda17c4a3d55d3d71 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Fri, 28 Jun 2013 13:43:59 +0200 Subject: [PATCH 27/27] create_xml_data: simplify to mappings; drop all units --- thin-provisioning/create_xml_data | 84 ++++++++----------------------- 1 file changed, 20 insertions(+), 64 deletions(-) diff --git a/thin-provisioning/create_xml_data b/thin-provisioning/create_xml_data index 3d5e322..387f365 100755 --- a/thin-provisioning/create_xml_data +++ b/thin-provisioning/create_xml_data @@ -2,7 +2,7 @@ # # Copyright (C) 2013 Red Hat, GmbH # -# Simple XML metadata creation tool +# Simple thinp provisioning XML metadata creation tool # require 'optparse' @@ -12,65 +12,25 @@ require 'pathname' $prg = Pathname.new($0).basename -def init_units - units = {} - units[:bytes_per_sector] = 512 - units[:chars] = "bskKmMgGtTpPeEzZyY" - units[:strings] = [ 'bytes', 'sectors', - 'kilobytes', 'kibibytes', 'megabytes', 'mebibytes', - 'gigabytes', 'gibibytes', 'terabytes', 'tebibytes', - 'petabytes', 'pebibytes', 'exabytes', 'ebibytes', - 'zetabytes', 'zebibytes', 'yottabytes', 'yobibytes' ] - units[:factors] = [ 1, units[:bytes_per_sector] ] - 1.step(8) { |e| units[:factors] += [ 1024**e, 1000**e ] } - units -end - -def get_index(unit_char, units) - unit_char ? units[:chars].index(unit_char) : 1 -end - -def to_sectors(size, units) - a = size.split(/[#{units[:chars]}]/) - s = size.to_i.to_s - abort "#{$prg} - only one unit character allowed!" if a.length > 1 || size.length - s.length > 1 - abort "#{$prg} - invalid unit specifier!" if s != a[0] - size.to_i * units[:factors][get_index(size[a[0].length], units)] / units[:bytes_per_sector] -end - def check_opts(opts) abort "#{$prg} - 3 arguments required!" if opts.length < 3 - abort "#{$prg} - block size must be > 0" if opts[:blocksize] <= 0 - abort "#{$prg} - thin size must be much greater/equal blocksize" if opts[:thinsize] < opts[:blocksize] - abort "#{$prg} - number of thin provisioned devices or snapshots must be > 0" if opts[:thins].nil? || opts[:thins] == 0 - abort "#{$prg} - size variation too large!" if !opts[:variation].nil? && (opts[:variation] > 2 * (opts[:thinsize] - opts[:blocksize])) + abort "#{$prg} - block size must be 2^^N with N > 1" if opts[:blocksize] < 2 || (opts[:blocksize] & opts[:blocksize] - 1) + abort "#{$prg} - mappings must be > 0" if opts[:mappings] < 1 + abort "#{$prg} - number of thin provisioned devices or snapshots must be > 0" if opts[:thins].nil? || opts[:thins] < 1 + abort "#{$prg} - size variation too large!" if !opts[:variation].nil? && (opts[:mappings] < 2 || (opts[:variation] >= 2 * (opts[:mapings] - 1))) end -def parse_command_line(argv, units) +def parse_command_line(argv) opts = {} os = OptionParser.new do |o| o.banner = "Thin Provisioning XML Test Metadata Generator.\nUsage: #{$prg} [opts]" - o.on("-b", "--block-size BLOCKSIZE[#{units[:chars]}]", String, - "Block size of thin provisioned devices.") do |bs| - opts[:blocksize] = to_sectors(bs, units) - end - o.on("-s", "--thin-size SIZE[#{units[:chars]}]", String, "Average size of thin devices and snapshots.") do |sz| - opts[:thinsize] = to_sectors(sz, units) - end - o.on("-r", "--range-mappings", "Create range mappings") do - opts[:range] = true - end - o.on("-t", "--thins #THINS", Integer, "Sum of thin devices and snapshots.") do |mt| - opts[:thins] = mt - end - o.on("-v", "--size-variation SIZE[#{units[:chars]}]", String, "Size variation of thin devices and snapshots.") do |sv| - opts[:variation] = to_sectors(sv, units) - end - o.on("-h", "--help", "Output this help.") do - puts o - exit - end + o.on("-b", "--block-size #SECTORS", Integer, "Block size of thin provisioned devices in sectors.") { |bs| opts[:blocksize] = bs } + o.on("-m", "--mappings #MAPPINGS", Integer, "Number of mappings per thin device or snapshot.") { |m| opts[:mappings] = m } + o.on("-r", "--range-mappings", "Create range mappings") { opts[:range] = true } + o.on("-t", "--thin-devices #THINS", Integer, "Sum of thin devices and snapshots.") { |mt| opts[:thins] = mt } + o.on("-v", "--variations SIZE]", Integer, "Mapping variation of thin devices and snapshots.") { |mv| opts[:variation] = mv } + o.on("-h", "--help", "Output this help.") { puts o; exit } end begin @@ -107,24 +67,20 @@ def range_mapping(from, to, length) " " end -def blocks(opts) - opts[:thinsize] / opts[:blocksize] +def this_mappings(opts) + opts[:variation].nil? ? opts[:mappings] : ((2 * opts[:mappings] - rand(opts[:variation])) / 2) end -def this_blocks(opts) - opts[:variation].nil? ? blocks(opts) : (2 * opts[:thinsize] - rand(opts[:variation])) / 2 / opts[:blocksize] -end - -def xml_metadata(opts, units) - blks, dev_id, nr_data_blocks, to = [], 0, 0, 0 +def xml_metadata(opts) + mappings, dev_id, nr_data_blocks, to = [], 0, 0, 0 0.step(opts[:thins] - 1) do - blks << (b = this_blocks(opts)) - nr_data_blocks += b + mappings << (m = this_mappings(opts)) + nr_data_blocks += m end puts begin_superblock(opts[:blocksize], nr_data_blocks) - blks.each do |b| + mappings.each do |b| if opts[:range] puts begin_device(dev_id, b), range_mapping(0, to, b), end_device else @@ -142,4 +98,4 @@ end #---------------------------------------------------------------- # Main # -xml_metadata(parse_command_line(ARGV, (units = init_units)), units) +xml_metadata(parse_command_line(ARGV))