Skip to content

Commit

Permalink
Set faked geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
shundhammer committed Feb 22, 2016
1 parent d7d6f0c commit 9da2b24
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/lib/storage/fake_device_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def create_disk(parent, args)
@disks << name
disk = ::Storage::Disk.create(@devicegraph, name)
disk.size_k = size.size_k
disk.geometry = fake_geometry(size)
name
end

Expand Down Expand Up @@ -327,6 +328,7 @@ def create_free(parent, args)
# @param key [String] key in the hash to access
# @param type [String] type (description) of 'key'
# @param name [String] name of the object that 'hash' belongs to
#
def fetch(hash, key, type, name)
value = hash[key.downcase]
raise ArgumentError, "Invalid #{type} #{key} for #{name} - use one of #{hash.keys}" unless value
Expand All @@ -353,14 +355,14 @@ def unused_region(disk_name, size)
disk.partition_table.unused_partition_slots.each do |slot|
log.info("Free slot on #{disk_name}")
block_size = slot.region.block_size
if size.unlimited
if size.unlimited?
region_start = slot.region.start
blocks = region.length
blocks = slot.region.length
break
else
requested_blocks = (1024 * size.size_k) / block_size

if requested_blocks <= region.length
if requested_blocks <= slot.region.length
region_start = slot.region.start
blocks = requested_blocks
break
Expand All @@ -374,6 +376,21 @@ def unused_region(disk_name, size)
# region.dup doesn't seem to work (SWIG bindings problem?)
::Storage::Region.new(region_start, blocks, block_size)
end

# Return a fake disk geometry with a given size.
#
# @param size [DiskSize]
# @return [::Storage::Geometry] Geometry with that size
#
def fake_geometry(size)
sector_size = 512
blocks = (size.size_k * 1024) / sector_size
heads = 16 # 1 MiB cylinders (16 * 128 * 512 Bytes)
sectors = 128
cyl = blocks / (heads * sectors)
# log.info("Geometry: #{cyl} cyl #{heads} heads #{sectors} sectors = #{size}")
::Storage::Geometry.new(cyl, heads, sectors, sector_size)
end
end
end
end

0 comments on commit 9da2b24

Please sign in to comment.