create_xml_data: fiddling

This commit is contained in:
Heinz Mauelshagen 2013-06-28 12:10:17 +02:00
parent 195398a640
commit 9e118bc335

View File

@ -41,7 +41,7 @@ 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} - 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} - 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} - size variation too large!" if !opts[:variation].nil? && (opts[:variation] > 2 * (opts[:thinsize] - opts[:blocksize]))
end end
@ -84,27 +84,27 @@ def parse_command_line(argv, units)
end end
def begin_superblock(blocksize, nr_data_blocks) def begin_superblock(blocksize, nr_data_blocks)
"<superblock uuid=\"\" time=\"0\" transaction=\"1\" data_block_size=\"#{blocksize}\" nr_data_blocks=\"#{nr_data_blocks}\">\n" "<superblock uuid=\"\" time=\"0\" transaction=\"1\" data_block_size=\"#{blocksize}\" nr_data_blocks=\"#{nr_data_blocks}\">"
end end
def end_superblock def end_superblock
"</superblock>\n" "</superblock>"
end end
def begin_device(devid, size) def begin_device(devid, size)
" <device dev_id=\"#{devid}\" mapped_blocks=\"#{size}\" transaction=\"0\" creation_time=\"0\" snap_time=\"0\">\n" " <device dev_id=\"#{devid}\" mapped_blocks=\"#{size}\" transaction=\"0\" creation_time=\"0\" snap_time=\"0\">"
end end
def end_device def end_device
" </device>\n" " </device>"
end end
def single_mapping(from, to) def single_mapping(from, to)
" <single_mapping origin_block=\"#{from}\" data_block=\"#{to}\" time=\"1\"/>\n" " <single_mapping origin_block=\"#{from}\" data_block=\"#{to}\" time=\"1\"/>"
end end
def range_mapping(from, to, length) def range_mapping(from, to, length)
" <range_mapping origin_begin=\"#{from}\" data_begin=\"#{to}\" length=\"#{length}\" time=\"1\"/>\n" " <range_mapping origin_begin=\"#{from}\" data_begin=\"#{to}\" length=\"#{length}\" time=\"1\"/>"
end end
def blocks(opts) def blocks(opts)
@ -116,28 +116,24 @@ def this_blocks(opts)
end end
def xml_metadata(opts, units) def xml_metadata(opts, units)
nr_data_blocks, to = 0, 0 blks, dev_id, nr_data_blocks, to = [], 0, 0, 0
blks = []
0.step(opts[:thins] - 1) do 0.step(opts[:thins] - 1) do
blks << this_blocks(opts) blks << (b = this_blocks(opts))
nr_data_blocks += blks[-1] nr_data_blocks += b
end end
puts begin_superblock(opts[:blocksize], nr_data_blocks) puts begin_superblock(opts[:blocksize], nr_data_blocks)
0.step(opts[:thins] - 1) do |dev_id| blks.each do |b|
b = blks.shift
puts begin_device(dev_id, b)
if opts[:range] if opts[:range]
puts range_mapping(0, to, b) puts begin_device(dev_id, b), range_mapping(0, to, b), end_device
to += b
else else
0.step(b - 1) do |from| puts begin_device(dev_id, b)
puts single_mapping(from, to) 0.step(b - 1) { |from| puts single_mapping(from, to + from) }
to += 1 puts end_device
end
end end
puts end_device dev_id += 1
to += b
end end
puts end_superblock puts end_superblock
end end