class SyncWrap::MDRaid

Handles assembling mdraid (Linux Software RAID) arrays, lvm volumes, creating and mounting filesystems from previously attached raw devices.

Host component dependencies: <Distro>

Attributes

do_unmount[RW]

Attempt to unmount and remove from fstab any existing mount of the specified raw devices. WARNING: this may increase the danger of data loss! (Default: false)

fs_opts[RW]

Array of FS specific options to pass as mkfs -t #fs_type OPTS Default: [] (none)

fs_type[RW]

File System Type. Default: 'ext4'

instance[RW]

An instance number used for mdraid and volume group names. Increment this when applying multiple components of this type to the same host. Default: 0

lvm_volumes[RW]

A table of [ slice, path (,name) ] rows where; slice is a Numeric in range (0.0..1.0), path is the mount point, and name is the lvm name, defaulting if omitted to the last path element. The sum of all slice values in the table should be 1.0, unless unallocated space is desired. Default: [ [ 1.0, '/data' ] ]

mount_opts[RW]

Mount options Array Default: [ defaults auto noatime nodiratime ]

raid_chunk[RW]

RAID chunk size in KB Default: 256

raid_level[RW]

Numeric RAID level. (Default: 10 if there are at least 4 raw devices, otherwise 0.)

raid_read_ahead[RW]

RAID md device read-ahead setting, in 512-byte blocks. Default: 64

raw_devices[R]

A number, range, or array of raw device names. See raw_devices= for interpretation. Software raid is only used for >1 raw device. Default: 0

raw_read_ahead[RW]

Block device read-ahead setting for the raw devices, in 512-byte blocks. Default: 32

Public Class Methods

new( opts = {} ) click to toggle source
Calls superclass method SyncWrap::Component.new
# File lib/syncwrap/components/mdraid.rb, line 79
def initialize( opts = {} )
  @instance = 0 #FIXME: Or compute from existing volumes?

  @raw_devices = []
  @raw_read_ahead = 32 #512B blocks
  @do_unmount = false

  @raid_level = nil #default_raid_level
  @raid_read_ahead  = 64  #512B blocks
  @raid_chunk       = 256 #K

  @lvm_volumes = [ [ 1.0, '/data' ] ]
  @fs_type = 'ext4'
  @fs_opts = []
  @mount_opts = %w[ defaults auto noatime nodiratime ]

  super
end

Public Instance Methods

install() click to toggle source

Install only if all #lvm_volumes paths do not yet exist.

# File lib/syncwrap/components/mdraid.rb, line 118
def install
  return if raw_devices.empty? || lvm_volumes.empty?

  paths = lvm_volumes.map { |r| r[1] }
  test = paths.map { |p| "! -e #{p}" }.join( " -a " )
  sudo_if( "[ #{test} ]" ) do
    dist_install( "mdadm", "lvm2", minimal: true )

    raw_devices.each do |d|
      unmount_device( d ) if do_unmount
      sudo "blockdev --setra #{raw_read_ahead} #{d}"
    end

    if raw_devices.count > 1
      dev = "/dev/md#{instance}"
      create_raid( dev )
    else
      dev = raw_devices.first
    end

    create_volumes( dev )
  end
end
raw_devices=( val ) click to toggle source

Set raw devices to assemble.

  • Interprets an Integer val as a count of N devices with names /dev/xvdh1 to /dev/xvdhN.

  • Interprets a Range value as /dev/xvdhN for each N in range.

  • Interprets an Array as the actual device path strings.

# File lib/syncwrap/components/mdraid.rb, line 104
def raw_devices=( val )
  @raw_devices = case val
                 when Integer
                   val.times.map { |i| "/dev/xvdh#{i+1}" }
                 when Range
                   val.map { |i| "/dev/xvdh#{i}" }
                 when Array
                   val
                 else
                   raise "Unsupported raw_devices setting #{val.inspect}"
                 end
end