dbs

package module
v0.0.0-...-2238e6b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Direct Block Store

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.

Build with go build, test with go test -p 1, read the docs with godoc.

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

View Source
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
)
View Source
const (
	EXTENT_BATCH = 65536
)
View Source
const (
	SIZEOF_EXTENT_METADATA = 6 + EXTENT_BITMAP_SIZE
)

Variables

This section is empty.

Functions

func CloneSnapshot

func CloneSnapshot(device string, newVolumeName string, snapshotId uint) error

func CreateSnapshot

func CreateSnapshot(device string, volumeName string) error

func CreateVolume

func CreateVolume(device string, volumeName string, volumeSize uint64) error

func DeleteSnapshot

func DeleteSnapshot(device string, snapshotId uint) error

func DeleteVolume

func DeleteVolume(device string, volumeName string) error

func InitDevice

func InitDevice(device string) error

func RenameVolume

func RenameVolume(device string, volumeName string, newVolumeName string) error

func VacuumDevice

func VacuumDevice(device string) error

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

type DirectFile struct {
	*os.File
	Name string
}

Wrapper to file object supporting direct I/O

func NewDirectFile

func NewDirectFile(name string, flag int, perm os.FileMode) (*DirectFile, error)

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)

func (*DirectFile) WriteAt

func (file *DirectFile) WriteAt(data []byte, offset uint64) (int, error)

Write using direct I/O

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) ClearAll

func (em *ExtentMap) ClearAll() error

Clear all metadata included in the map.

func (*ExtentMap) CopyAllToSnapshot

func (em *ExtentMap) CopyAllToSnapshot(snapshotId uint16) error

Copy the whole map to another snapshot.

func (*ExtentMap) CopyExtentToSnapshot

func (em *ExtentMap) CopyExtentToSnapshot(eidx uint32, snapshotId uint16) error

Copy over all data from an extent to another snapshot and update the map.

func (*ExtentMap) MergeAllInto

func (em *ExtentMap) MergeAllInto(emdst *ExtentMap, snapshotId uint16) error

Clear all metadata included in the map.

func (*ExtentMap) NewExtentToSnapshot

func (em *ExtentMap) NewExtentToSnapshot(eidx uint32, snapshotId uint16) error

Allocate a new extent into the map.

func (*ExtentMap) WriteExtent

func (em *ExtentMap) WriteExtent(eidx uint32) error

Write extent metadata to the device.

type ExtentMetadata

type ExtentMetadata struct {
	SnapshotId  uint16
	ExtentPos   uint32
	BlockBitmap [EXTENT_BITMAP_SIZE]byte
}

type SnapshotInfo

type SnapshotInfo struct {
	SnapshotId       uint
	ParentSnapshotId uint
	CreatedAt        time.Time
}

func GetSnapshotInfo

func GetSnapshotInfo(device string, volumeName string) ([]SnapshotInfo, error)

type SnapshotMetadata

type SnapshotMetadata struct {
	ParentSnapshotId uint16
	CreatedAt        int64
}

type Superblock

type Superblock struct {
	Magic                  [8]byte
	Version                uint32 // 16-bit major, 8-bit minor, 8-bit patch
	AllocatedDeviceExtents uint32
	DeviceSize             uint64
}

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) ReadAt

func (vc *VolumeContext) ReadAt(data []byte, offset uint64) 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) WriteAt

func (vc *VolumeContext) WriteAt(data []byte, offset 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
}

Directories

Path Synopsis
cmd
dbsctl
A command line utility exposing the query and management APIs of DBS.
A command line utility exposing the query and management APIs of DBS.
dbssrv
NBD server for DBS.
NBD server for DBS.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL