Conflicts:
	Makefile.in
This commit is contained in:
Joe Thornber 2013-06-25 11:18:45 +01:00
commit 7b603183df

View File

@ -18,51 +18,48 @@ require 'pathname'
$prg = Pathname.new($0).basename $prg = Pathname.new($0).basename
def init_units def init_units
units = Hash.new units = {}
units[:chars] = "sKkMmGgTtPpEeZzYy" units[:bytes_per_sector] = 512
units[:strings] = [ 'sectors', units[:chars] = "bsKkMmGgTtPpEeZzYy"
units[:strings] = [ 'bytes', 'sectors',
'kilobytes', 'kibibytes', 'megabytes', 'mebibytes', 'kilobytes', 'kibibytes', 'megabytes', 'mebibytes',
'gigabytes', 'gibibytes', 'terabytes', 'tebibytes', 'gigabytes', 'gibibytes', 'terabytes', 'tebibytes',
'petabytes', 'pebibytes', 'exabytes', 'ebibytes', 'petabytes', 'pebibytes', 'exabytes', 'ebibytes',
'zetabytes', 'zebibytes', 'yottabytes', 'yobibytes' ] 'zetabytes', 'zebibytes', 'yottabytes', 'yobibytes' ]
units[:factors] = Array.new units[:factors] = [ 1, units[:bytes_per_sector] ]
1.step(8) { |e| units[:factors] += [ 1024**e, 1000**e ] }
units[:factors][0] = 512
1.step(8) do |e|
i = (e - 1) * 2 + 1
units[:factors][i] = 1024**e
units[:factors][i + 1] = 1000**e
end
units units
end end
def get_index(unit_char, units)
unit_char ? units[:chars].index(unit_char) : 1
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} - poolsize must be much larger than blocksize" if opts[:poolsize] < opts[:blocksize] 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 abort "#{$prg} - maximum number of thin provisioned devices must be > 0" if opts[:maxthins].nil? || opts[:maxthins] == 0
end end
def to_sectors(size, units) def to_bytes(size, units)
a = size.split(/[#{units[:chars]}]/) a = size.split(/[#{units[:chars]}]/)
s = size.to_i.to_s s = size.to_i.to_s
abort "#{$prg} - only one unit character allowed!" if a.length > 1 || size.length - s.length > 1 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] abort "#{$prg} - invalid unit specifier!" if s != a[0]
idx = units[:chars].index(size[a[0].length]) size.to_i * units[:factors][get_index(size[a[0].length], units)]
r = size.to_i * units[:factors][idx] / units[:factors][0]
r
end end
def parse_command_line(argv, units) def parse_command_line(argv, units)
opts = {} opts = {}
os = OptionParser.new do |o| os = OptionParser.new do |o|
o.banner = "Thin Provisioning Metadata Size Calculator.\nUsage: #{$prg} [opts]" o.banner = "Thin Provisioning Metadata Device Size Calculator.\nUsage: #{$prg} [opts]"
o.on("-b", "--block-size BLOCKSIZE[#{units[:chars]}]", String, o.on("-b", "--block-size BLOCKSIZE[#{units[:chars]}]", String,
"Block size of thin provisioned devices.") do |bs| "Block size of thin provisioned devices.") do |bs|
opts[:blocksize] = to_sectors(bs, units) opts[:blocksize] = to_bytes(bs, units)
end end
o.on("-s", "--pool-size SIZE[#{units[:chars]}]", String, "Size of the pool device.") do |ps| o.on("-s", "--pool-size SIZE[#{units[:chars]}]", String, "Size of pool device.") do |ps|
opts[:poolsize] = to_sectors(ps, units) opts[:poolsize] = to_bytes(ps, units)
end end
o.on("-m", "--max-thins #MAXTHINS", Integer, "Maximum sum of all thin devices and snapshots.") do |mt| o.on("-m", "--max-thins #MAXTHINS", Integer, "Maximum sum of all thin devices and snapshots.") do |mt|
opts[:maxthins] = mt opts[:maxthins] = mt
@ -96,10 +93,10 @@ def mappings_per_block
end end
def estimated_result(opts, units) def estimated_result(opts, units)
idx = opts[:units] ? units[:chars].index(opts[:units]) : 0 idx = get_index(opts[:units], units)
# double-fold # of nodes, because they aren't fully populated in average # double-fold # of nodes, because they aren't fully populated in average
r = (1.0 + ((opts[:poolsize] / opts[:blocksize] / mappings_per_block) * 2 + opts[:maxthins])) * 8 * units[:factors][0] # in bytes! r = (1.0 + (2 * (opts[:poolsize] / opts[:blocksize] / mappings_per_block) + opts[:maxthins])) * 8 * units[:bytes_per_sector] # in bytes!
r /= units[:factors][idx] r /= units[:factors][idx] # in requested unit
tmp = "%.2f" % r tmp = "%.2f" % r
if tmp.to_f > 0.0 if tmp.to_f > 0.0
r = tmp.to_i.to_f == tmp.to_f ? tmp.to_i : tmp r = tmp.to_i.to_f == tmp.to_f ? tmp.to_i : tmp
@ -113,6 +110,5 @@ end
#---------------------------------------------------------------- #----------------------------------------------------------------
# Main # Main
#
units = init_units puts estimated_result(parse_command_line(ARGV, (units = init_units)), units)
puts estimated_result(parse_command_line(ARGV, units), units)