Documentation ¶
Overview ¶
A library for maintaining virtual volumes on top of a physical block device (or file). Snapshots supported. Command-line utility for query and management operations included.
Device layout:
- Bytes [0, 4096) contain the the superblock
- Bytes [4096, ExtentOffset) hold the volume and snapshot metadata (ExtentOffset is block aligned)
- Bytes [ExtentOffset, DataOffset) hold the extent metadata (DataOffset is extent aligned)
- Bytes [DataOffset, DeviceSize) hold the data
Index ¶
- Constants
- func CloneSnapshot(device string, newVolumeName string, snapshotId uint) error
- func CreateSnapshot(device string, volumeName string) error
- func CreateVolume(device string, volumeName string, volumeSize uint64) error
- func DeleteSnapshot(device string, snapshotId uint) error
- func DeleteVolume(device string, volumeName string) error
- func InitDevice(device string) error
- func RenameVolume(device string, volumeName string, newVolumeName string) error
- func VacuumDevice(device string) error
- type DeviceContext
- func (dc *DeviceContext) AddSnapshot(parentSnapshotId uint16) (uint16, error)
- func (dc *DeviceContext) AddVolume(volumeName string, volumeSize uint64) (*VolumeMetadata, error)
- func (dc *DeviceContext) Close() error
- func (dc *DeviceContext) CopyExtentData(esrc uint, edst uint) error
- func (dc *DeviceContext) CountSnapshots(v *VolumeMetadata) uint
- func (dc *DeviceContext) CountVolumes() uint
- func (dc *DeviceContext) FindChildSnapshot(snapshotId uint16) uint16
- func (dc *DeviceContext) FindVolume(volumeName string) *VolumeMetadata
- func (dc *DeviceContext) FindVolumeWithSnapshot(snapshotId uint16) *VolumeMetadata
- func (dc *DeviceContext) ReadBlockData(data []byte, epos uint, bidx uint) error
- func (dc *DeviceContext) ReadExtents(eb []ExtentMetadata, eidx uint) error
- func (dc *DeviceContext) ReadMetadata() error
- func (dc *DeviceContext) ReadSuperblock() error
- func (dc *DeviceContext) WriteBlockData(data []byte, epos uint, bidx uint) error
- func (dc *DeviceContext) WriteExtent(e *ExtentMetadata, eidx uint) error
- func (dc *DeviceContext) WriteExtents(eb []ExtentMetadata, eidx uint) error
- func (dc *DeviceContext) WriteMetadata() error
- func (dc *DeviceContext) WriteSuperblock() error
- type DeviceInfo
- type DirectFile
- type ExtentMap
- func (em *ExtentMap) ClearAll() error
- func (em *ExtentMap) CopyAllToSnapshot(snapshotId uint16) error
- func (em *ExtentMap) CopyExtentToSnapshot(eidx uint32, snapshotId uint16) error
- func (em *ExtentMap) MergeAllInto(emdst *ExtentMap, snapshotId uint16) error
- func (em *ExtentMap) NewExtentToSnapshot(eidx uint32, snapshotId uint16) error
- func (em *ExtentMap) WriteExtent(eidx uint32) error
- type ExtentMetadata
- type SnapshotInfo
- type SnapshotMetadata
- type Superblock
- type VolumeContext
- func (vc *VolumeContext) CloseVolume() error
- func (vc *VolumeContext) ReadAt(data []byte, offset uint64) error
- func (vc *VolumeContext) ReadBlock(data []byte, block uint64) error
- func (vc *VolumeContext) UnmapAt(length uint64, offset uint64) error
- func (vc *VolumeContext) UnmapBlock(block uint64) error
- func (vc *VolumeContext) WriteAt(data []byte, offset uint64) error
- func (vc *VolumeContext) WriteBlock(data []byte, block uint64) error
- type VolumeInfo
- type VolumeMetadata
Constants ¶
const ( MAGIC = "DBS@393!" VERSION = 0x00010000 MAX_VOLUMES = 256 MAX_SNAPSHOTS = 65535 MAX_VOLUME_NAME_SIZE = 255 BLOCK_SIZE = 4096 EXTENT_SIZE = 1048576 // 1 MB EXTENT_BITMAP_SIZE = 32 BLOCK_BITS_IN_EXTENT = 8 BLOCK_MASK_IN_EXTENT = 0xFF )
const (
EXTENT_BATCH = 65536
)
const (
SIZEOF_EXTENT_METADATA = 6 + EXTENT_BITMAP_SIZE
)
Variables ¶
This section is empty.
Functions ¶
func CreateSnapshot ¶
func DeleteSnapshot ¶
func DeleteVolume ¶
func InitDevice ¶
func VacuumDevice ¶
Types ¶
type DeviceContext ¶
type DeviceContext struct {
// contains filtered or unexported fields
}
The device context holds the device file descriptor and all metadata except extents.
func GetDeviceContext ¶
func GetDeviceContext(device string) (*DeviceContext, error)
func NewDeviceContext ¶
func NewDeviceContext(device string) (*DeviceContext, error)
Initialize a new, empty device context.
func (*DeviceContext) AddSnapshot ¶
func (dc *DeviceContext) AddSnapshot(parentSnapshotId uint16) (uint16, error)
Add a new snapshot. Return the snapshot identifier.
func (*DeviceContext) AddVolume ¶
func (dc *DeviceContext) AddVolume(volumeName string, volumeSize uint64) (*VolumeMetadata, error)
Add a new volume (and corresponding snapshot). Return a pointer to the volume metadata.
func (*DeviceContext) Close ¶
func (dc *DeviceContext) Close() error
Close the device file descriptor.
func (*DeviceContext) CopyExtentData ¶
func (dc *DeviceContext) CopyExtentData(esrc uint, edst uint) error
func (*DeviceContext) CountSnapshots ¶
func (dc *DeviceContext) CountSnapshots(v *VolumeMetadata) uint
func (*DeviceContext) CountVolumes ¶
func (dc *DeviceContext) CountVolumes() uint
func (*DeviceContext) FindChildSnapshot ¶
func (dc *DeviceContext) FindChildSnapshot(snapshotId uint16) uint16
Find the descendant of the snapshot with the given identifier. Returns 0 if not found.
func (*DeviceContext) FindVolume ¶
func (dc *DeviceContext) FindVolume(volumeName string) *VolumeMetadata
Find the volume metadata for the given volume name. Returns nil if not found.
func (*DeviceContext) FindVolumeWithSnapshot ¶
func (dc *DeviceContext) FindVolumeWithSnapshot(snapshotId uint16) *VolumeMetadata
Find the volume metadata for the given snapshot identifier. Returns 0 if not found.
func (*DeviceContext) ReadBlockData ¶
func (dc *DeviceContext) ReadBlockData(data []byte, epos uint, bidx uint) error
func (*DeviceContext) ReadExtents ¶
func (dc *DeviceContext) ReadExtents(eb []ExtentMetadata, eidx uint) error
func (*DeviceContext) ReadMetadata ¶
func (dc *DeviceContext) ReadMetadata() error
func (*DeviceContext) ReadSuperblock ¶
func (dc *DeviceContext) ReadSuperblock() error
func (*DeviceContext) WriteBlockData ¶
func (dc *DeviceContext) WriteBlockData(data []byte, epos uint, bidx uint) error
func (*DeviceContext) WriteExtent ¶
func (dc *DeviceContext) WriteExtent(e *ExtentMetadata, eidx uint) error
func (*DeviceContext) WriteExtents ¶
func (dc *DeviceContext) WriteExtents(eb []ExtentMetadata, eidx uint) error
func (*DeviceContext) WriteMetadata ¶
func (dc *DeviceContext) WriteMetadata() error
func (*DeviceContext) WriteSuperblock ¶
func (dc *DeviceContext) WriteSuperblock() error
type DeviceInfo ¶
type DeviceInfo struct { Version string DeviceSize uint64 TotalDeviceExtents uint AllocatedDeviceExtents uint VolumeCount uint }
func GetDeviceInfo ¶
func GetDeviceInfo(device string) (*DeviceInfo, error)
type DirectFile ¶
Wrapper to file object supporting direct I/O
func NewDirectFile ¶
func (*DirectFile) Close ¶
func (file *DirectFile) Close() error
func (*DirectFile) ReadAt ¶
func (file *DirectFile) ReadAt(data []byte, offset uint64) (int, error)
Read using direct I/O
func (*DirectFile) Size ¶
func (file *DirectFile) Size() (int64, error)
type ExtentMap ¶
type ExtentMap struct {
// contains filtered or unexported fields
}
Map of the whole volume. Empty extents have an empty snapshot identifier. The extent bitmap is used to speed up operations.
func GetSnapshotExtentMap ¶
func GetSnapshotExtentMap(dc *DeviceContext, deviceSize uint64, snapshotId uint16) (*ExtentMap, error)
Get the map of a specific snapshot.
func GetVolumeExtentMap ¶
func GetVolumeExtentMap(dc *DeviceContext, deviceSize uint64, snapshotId uint16) (*ExtentMap, error)
Get the map of a volume starting at a snapshot and including all ancestors.
func (*ExtentMap) CopyAllToSnapshot ¶
Copy the whole map to another snapshot.
func (*ExtentMap) CopyExtentToSnapshot ¶
Copy over all data from an extent to another snapshot and update the map.
func (*ExtentMap) MergeAllInto ¶
Clear all metadata included in the map.
func (*ExtentMap) NewExtentToSnapshot ¶
Allocate a new extent into the map.
func (*ExtentMap) WriteExtent ¶
Write extent metadata to the device.
type ExtentMetadata ¶
type ExtentMetadata struct { SnapshotId uint16 ExtentPos uint32 BlockBitmap [EXTENT_BITMAP_SIZE]byte }
type SnapshotInfo ¶
func GetSnapshotInfo ¶
func GetSnapshotInfo(device string, volumeName string) ([]SnapshotInfo, error)
type SnapshotMetadata ¶
type Superblock ¶
type VolumeContext ¶
type VolumeContext struct {
// contains filtered or unexported fields
}
func OpenVolume ¶
func OpenVolume(device string, volumeName string) (*VolumeContext, error)
func (*VolumeContext) CloseVolume ¶
func (vc *VolumeContext) CloseVolume() error
func (*VolumeContext) ReadBlock ¶
func (vc *VolumeContext) ReadBlock(data []byte, block uint64) error
func (*VolumeContext) UnmapAt ¶
func (vc *VolumeContext) UnmapAt(length uint64, offset uint64) error
func (*VolumeContext) UnmapBlock ¶
func (vc *VolumeContext) UnmapBlock(block uint64) error
func (*VolumeContext) WriteBlock ¶
func (vc *VolumeContext) WriteBlock(data []byte, block uint64) error
type VolumeInfo ¶
type VolumeInfo struct { VolumeName string VolumeSize uint64 SnapshotId uint CreatedAt time.Time SnapshotCount uint }
func GetVolumeInfo ¶
func GetVolumeInfo(device string) ([]VolumeInfo, error)
type VolumeMetadata ¶
type VolumeMetadata struct { SnapshotId uint16 // Index in snapshots table + 1 VolumeSize uint64 VolumeName [MAX_VOLUME_NAME_SIZE + 1]byte }