Sha256: ff7e9b245fd24e183f31eb93b9a6513eb3a73321aa5a63387de2ccfe82cad297

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

module Lvm2Thin
  class DataMap < BTree
    TIME_MASK = (1 << 24) - 1

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

    alias :device_blocks :keys

    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

    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

    private

    def extract_data_block(value)
      value >> 24
    end

    def extract_time(value)
      value & TIME_MASK
    end
  end
end # module Lvm2Thin

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
manageiq-smartstate-0.1.4 lib/VolumeManager/LVM/thin/data_map.rb
manageiq-smartstate-0.1.3 lib/VolumeManager/LVM/thin/data_map.rb
manageiq-smartstate-0.1.2 lib/VolumeManager/LVM/thin/data_map.rb
manageiq-smartstate-0.1.1 lib/VolumeManager/LVM/thin/data_map.rb
manageiq-smartstate-0.1.0 lib/VolumeManager/LVM/thin/data_map.rb