Class: Lvm2Thin::DataMap

Inherits:
BTree
  • Object
show all
Defined in:
lib/VolumeManager/LVM/thin/data_map.rb

Constant Summary collapse

TIME_MASK =
(1 << 24) - 1

Constants inherited from BTree

BTree::FLAGS

Instance Attribute Summary

Attributes inherited from BTree

#root_address

Instance Method Summary collapse

Methods inherited from BTree

#[], #entry_for, #internal?, #key_address, #key_base, #keys, #leaf?, #max_entries, #num_entries, #root, #to_h, #value_address, #value_base

Constructor Details

#initialize(superblock, root_address) ⇒ DataMap

Returns a new instance of DataMap.



5
6
7
# File 'lib/VolumeManager/LVM/thin/data_map.rb', line 5

def initialize(superblock, root_address)
  super superblock, root_address, MAPPING_DETAILS
end

Instance Method Details

#block?(blk) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/VolumeManager/LVM/thin/data_map.rb', line 31

def block?(blk)
  blk < total_blocks
end

#data_block(device_block) ⇒ Object

Raises:

  • (RuntimeError)


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/VolumeManager/LVM/thin/data_map.rb', line 35

def data_block(device_block)
  device_blocks.reverse.each do |map_device_block|
    if map_device_block <= device_block
      entry = entry_for(map_device_block)
      return entry.data_block(device_block) if entry.is_a?(DataMap)
      raise RuntimeError, "LVM2Thin cannot find device block: #{device_block} (closest: #{map_device_block})" unless map_device_block == device_block
      return entry.first
    end
  end

  raise RuntimeError, "LVM2Thin could not find data block for #{device_block}"
end

#entriesObject



11
12
13
14
15
16
17
18
19
# File 'lib/VolumeManager/LVM/thin/data_map.rb', line 11

def entries
  @dmentries ||= begin
    super.collect do |entry|
      value = entry['value']
      internal? ? DataMap.new(@superblock, @superblock.md_block_address(value)) :
                  [extract_data_block(value), extract_time(value)]
    end
  end
end

#total_blocksObject



21
22
23
24
25
26
27
28
29
# File 'lib/VolumeManager/LVM/thin/data_map.rb', line 21

def total_blocks
  @total_blocks ||= begin
    t = 0
    entries.each do |entry|
      t += entry.kind_of?(DataMap) ? entry.total_blocks : 1
    end
    t
  end
end