class ZFS

Defines a class capable of manipulating ZFS volumes. This classes uses the standard command line tools (zfs and zpool), not the C API.

Public Class Methods

delete_volume(volume_path) click to toggle source

Delete (destroy) a volume from the ZFS pool. This command can handle both raw paths, and absolute paths.

# File lib/SANStore/zfs/zfs.rb, line 38
def self.delete_volume(volume_path)
  
  # Work out if this is a raw volume path, or an absolute path
  if volume_path.index(/\/dev\/zvol\/rdsk/) then
    # This is a relative path, so we need to split the
    # device prefix off to get the volume path
    volume_path = volume_path.partition(/\/dev\/zvol\/rdsk/)[2]
  end

  # Remove any slash prefixes
  if volume_path[0] == 0x2F then
    volume_path = volume_path[1..volume_path.length]
  end 
  
  # Delete the volume from the system
  SANStore::CLI::Logger.instance.log_level(:low, :delete, "Removing ZFS volume #{volume_path} from the file-store")
  cmd = %x[zfs destroy -r -f #{volume_path}]
  
end
new_volume(volume_path, volume_size) click to toggle source

Create a new volume, at the specified location and of the specified size.

NOTE: This command currently only supports the creation of sparse volumes. If you really need pre-allocated volumes for some reason, this command needs to be extended

# File lib/SANStore/zfs/zfs.rb, line 28
def self.new_volume(volume_path, volume_size)
  
  # Create the volume
  SANStore::CLI::Logger.instance.log_level(:low, :create, "#{volume_size} ZFS volume at #{volume_path}")
  cmd = %x[zfs create -s -V #{volume_size} #{volume_path}]

end