From 993dad400b33baf6145c1a9ed601ed4ef4dcfa9b Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Wed, 26 Jun 2013 18:06:16 +0200 Subject: [PATCH] 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