create_xml_data: support --size-variation and check for block size > 0
This commit is contained in:
parent
daf8cf4904
commit
8eb568619e
@ -40,8 +40,10 @@ end
|
|||||||
|
|
||||||
def check_opts(opts)
|
def check_opts(opts)
|
||||||
abort "#{$prg} - 3 arguments required!" if opts.length < 3
|
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} - 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} - 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
|
end
|
||||||
|
|
||||||
def parse_command_line(argv, units)
|
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|
|
o.on("-t", "--thins #THINS", Integer, "Sum of thin devices and snapshots.") do |mt|
|
||||||
opts[:thins] = mt
|
opts[:thins] = mt
|
||||||
end
|
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
|
o.on("-h", "--help", "Output this help.") do
|
||||||
puts o
|
puts o
|
||||||
exit
|
exit
|
||||||
@ -102,17 +107,26 @@ def range_mapping(from, to, length)
|
|||||||
" <range_mapping time=\"0\" origin_begin=\"#{from}\" data_begin=\"#{to}\" length=\"#{length}\"/>\n"
|
" <range_mapping time=\"0\" origin_begin=\"#{from}\" data_begin=\"#{to}\" length=\"#{length}\"/>\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def xml_metadata(opts, units)
|
def blocks(opts)
|
||||||
blocks, to = opts[:thinsize] / opts[:blocksize], 0
|
opts[:thinsize] / opts[:blocksize]
|
||||||
|
end
|
||||||
|
|
||||||
puts begin_superblock(opts[:blocksize], opts[:thins] * blocks)
|
def this_blocks(opts)
|
||||||
0.step(opts[:thins] - 1) do |devid|
|
opts[:variation].nil? ? blocks(opts) : (2 * opts[:thinsize] - rand(opts[:variation])) / 2 / opts[:blocksize]
|
||||||
puts begin_device(devid, blocks)
|
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]
|
if opts[:range]
|
||||||
puts range_mapping(0, to, blocks)
|
puts range_mapping(0, to, b)
|
||||||
to += blocks
|
to += b
|
||||||
else
|
else
|
||||||
0.step(blocks - 1) do |from|
|
0.step(b - 1) do |from|
|
||||||
puts single_mapping(from, to)
|
puts single_mapping(from, to)
|
||||||
to += 1
|
to += 1
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user