create_xml_data: support --size-variation and check for block size > 0

This commit is contained in:
Heinz Mauelshagen 2013-06-26 18:06:16 +02:00
parent 8ca0a87eda
commit 42a1db8792

View File

@ -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)
" <range_mapping time=\"0\" origin_begin=\"#{from}\" data_begin=\"#{to}\" length=\"#{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