Help us shape the future of Go! Take the 2026 Go Developer Survey

storage

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package storage provides storage driver management.

Index

Constants

View Source
const (
	DriverFuseOverlayFS = "fuse-overlayfs"
	DriverOverlay2      = "overlay2"
)

Variables

This section is empty.

Functions

func DetectBestDriver

func DetectBestDriver(root string) string

DetectBestDriver detects the best available storage driver for the system.

func EnsureDriverDir

func EnsureDriverDir(root string) error

EnsureDriverDir creates driver directories.

func LinkParent

func LinkParent(root, childID, parentID string) error

LinkParent links a child layer to its parent.

func SaveLayerMetadata

func SaveLayerMetadata(root, id string, meta map[string]string) error

SaveLayerMetadata saves metadata for a layer.

Types

type BtrfsDriver

type BtrfsDriver struct {
	// contains filtered or unexported fields
}

BtrfsDriver implements the storage driver using btrfs subvolumes.

func NewBtrfsDriver

func NewBtrfsDriver(root string) (*BtrfsDriver, error)

NewBtrfsDriver creates a new btrfs storage driver rooted at root.

func (*BtrfsDriver) Cleanup

func (d *BtrfsDriver) Cleanup() error

Cleanup releases resources held by the btrfs driver.

func (*BtrfsDriver) Exists

func (d *BtrfsDriver) Exists(id string) bool

Exists checks whether a btrfs subvolume for the given layer id exists.

func (*BtrfsDriver) Get

func (d *BtrfsDriver) Get(id, _ string) (string, error)

Get mounts the btrfs subvolume for the given layer id and returns its mount path.

func (*BtrfsDriver) GetMetadata

func (d *BtrfsDriver) GetMetadata(_ string) (map[string]string, error)

GetMetadata returns metadata for the given layer.

func (*BtrfsDriver) Name

func (d *BtrfsDriver) Name() string

Name returns the name of the btrfs driver.

func (*BtrfsDriver) Put

func (d *BtrfsDriver) Put(id, _ string) (string, error)

Put unmounts the btrfs subvolume for the given layer id and returns its mount path.

func (*BtrfsDriver) Remove

func (d *BtrfsDriver) Remove(id string) error

Remove deletes the btrfs subvolume for the given layer id.

type Driver

type Driver interface {
	Get(id, mountLabel string) (string, error)
	Put(id, mountLabel string) (string, error)
	Exists(id string) bool
	Cleanup() error
	Remove(id string) error
	GetMetadata(id string) (map[string]string, error)
	Name() string
}

Driver is the interface for storage drivers.

type FuseOverlayFSDriver

type FuseOverlayFSDriver struct {
	// contains filtered or unexported fields
}

FuseOverlayFSDriver implements the Driver interface using fuse-overlayfs.

func NewFuseOverlayFSDriver

func NewFuseOverlayFSDriver(root string) (*FuseOverlayFSDriver, error)

NewFuseOverlayFSDriver creates a new fuse-overlayfs driver.

func (*FuseOverlayFSDriver) Cleanup

func (d *FuseOverlayFSDriver) Cleanup() error

func (*FuseOverlayFSDriver) Exists

func (d *FuseOverlayFSDriver) Exists(id string) bool

func (*FuseOverlayFSDriver) Get

func (d *FuseOverlayFSDriver) Get(id, _ string) (string, error)

func (*FuseOverlayFSDriver) GetMetadata

func (d *FuseOverlayFSDriver) GetMetadata(id string) (map[string]string, error)

func (*FuseOverlayFSDriver) Name

func (d *FuseOverlayFSDriver) Name() string

func (*FuseOverlayFSDriver) Put

func (d *FuseOverlayFSDriver) Put(id, _ string) (string, error)

func (*FuseOverlayFSDriver) Remove

func (d *FuseOverlayFSDriver) Remove(id string) error

type GCConfig

type GCConfig struct {
	Enabled      bool
	Interval     time.Duration
	MaxAge       time.Duration
	MinFreeSpace int64
}

GCConfig holds configuration for garbage collection.

type GarbageCollector

type GarbageCollector struct {
	// contains filtered or unexported fields
}

GarbageCollector runs periodic garbage collection on unused layers.

func NewGarbageCollector

func NewGarbageCollector(store *Manager, cfg GCConfig) *GarbageCollector

NewGarbageCollector creates a new garbage collector for the given storage manager.

func (*GarbageCollector) Start

func (g *GarbageCollector) Start()

Start begins periodic garbage collection.

func (*GarbageCollector) Stop

func (g *GarbageCollector) Stop()

Stop halts the garbage collector.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages storage drivers.

func NewManager

func NewManager(root string, driverName string) (*Manager, error)

NewManager creates a new storage manager.

func (*Manager) Cleanup

func (m *Manager) Cleanup() error

Cleanup performs cleanup of the storage driver.

func (*Manager) Driver

func (m *Manager) Driver() Driver

Driver returns the current driver.

func (*Manager) Exists

func (m *Manager) Exists(id string) bool

Exists checks if a container layer exists.

func (*Manager) Get

func (m *Manager) Get(id, mountLabel string) (string, error)

Get returns the path to a container layer directory.

func (*Manager) GetMetadata

func (m *Manager) GetMetadata(id string) (map[string]string, error)

GetMetadata returns metadata for a container layer.

func (*Manager) Name

func (m *Manager) Name() string

Name returns the name of the current storage driver.

func (*Manager) Put

func (m *Manager) Put(id, mountLabel string) (string, error)

Put releases a container layer.

func (*Manager) Remove

func (m *Manager) Remove(id string) error

Remove removes a container layer.

func (*Manager) Root

func (m *Manager) Root() string

Root returns the root directory for storage.

func (*Manager) Stats

func (m *Manager) Stats() StorageStats

Stats returns storage statistics.

type Overlay2Driver

type Overlay2Driver struct {
	// contains filtered or unexported fields
}

Overlay2Driver implements the Driver interface using native overlay2.

func NewOverlay2Driver

func NewOverlay2Driver(root string) (*Overlay2Driver, error)

NewOverlay2Driver creates a new overlay2 driver.

func (*Overlay2Driver) Cleanup

func (d *Overlay2Driver) Cleanup() error

func (*Overlay2Driver) Exists

func (d *Overlay2Driver) Exists(id string) bool

func (*Overlay2Driver) Get

func (d *Overlay2Driver) Get(id, _ string) (string, error)

func (*Overlay2Driver) GetMetadata

func (d *Overlay2Driver) GetMetadata(id string) (map[string]string, error)

func (*Overlay2Driver) Name

func (d *Overlay2Driver) Name() string

func (*Overlay2Driver) Put

func (d *Overlay2Driver) Put(id, _ string) (string, error)

func (*Overlay2Driver) Remove

func (d *Overlay2Driver) Remove(id string) error

type QuotaManager

type QuotaManager struct {
	// contains filtered or unexported fields
}

QuotaManager manages disk quotas for storage drivers.

func NewQuotaManager

func NewQuotaManager(driver Driver) *QuotaManager

NewQuotaManager creates a new quota manager.

func (*QuotaManager) GetQuota

func (q *QuotaManager) GetQuota(id string) (int64, error)

GetQuota returns the current quota for a container layer.

func (*QuotaManager) GetUsage

func (q *QuotaManager) GetUsage(id string) (int64, error)

GetUsage returns the current disk usage for a container layer.

func (*QuotaManager) SetQuota

func (q *QuotaManager) SetQuota(id string, size int64) error

SetQuota sets a disk quota for a container layer. Size is in bytes. 0 means no limit.

type Snapshot

type Snapshot struct {
	ID        string            `json:"id"`
	ParentID  string            `json:"parent_id,omitempty"`
	CreatedAt time.Time         `json:"created_at"`
	Size      int64             `json:"size"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

Snapshot represents a storage snapshot.

type SnapshotManager

type SnapshotManager struct {
	// contains filtered or unexported fields
}

SnapshotManager manages storage snapshots.

func NewSnapshotManager

func NewSnapshotManager(root string, driver Driver) *SnapshotManager

NewSnapshotManager creates a new snapshot manager.

func (*SnapshotManager) Create

func (sm *SnapshotManager) Create(id string, metadata map[string]string) (*Snapshot, error)

Create creates a snapshot of a container layer.

func (*SnapshotManager) Delete

func (sm *SnapshotManager) Delete(id string) error

Delete deletes a snapshot.

func (*SnapshotManager) List

func (sm *SnapshotManager) List() ([]*Snapshot, error)

List returns all snapshots.

func (*SnapshotManager) Load

func (sm *SnapshotManager) Load(id string) (*Snapshot, error)

Load loads a snapshot by ID.

func (*SnapshotManager) Restore

func (sm *SnapshotManager) Restore(snapID, targetID string) error

Restore restores a snapshot to a container layer.

type StorageStats

type StorageStats struct {
	DriverName string `json:"driver_name"`
	RootPath   string `json:"root_path"`
	LayerCount int    `json:"layer_count"`
	TotalSize  int64  `json:"total_size"`
	FreeSpace  int64  `json:"free_space"`
}

StorageStats returns storage statistics.

type VFSDriver

type VFSDriver struct {
	// contains filtered or unexported fields
}

VFSDriver implements the storage driver using the host filesystem directly.

func NewVFSDriver

func NewVFSDriver(root string) (*VFSDriver, error)

NewVFSDriver creates a new VFS storage driver.

func (*VFSDriver) Cleanup

func (d *VFSDriver) Cleanup() error

Cleanup releases resources held by the VFS driver.

func (*VFSDriver) Exists

func (d *VFSDriver) Exists(id string) bool

Exists checks whether the directory for the given layer id exists.

func (*VFSDriver) Get

func (d *VFSDriver) Get(id, _ string) (string, error)

Get returns the filesystem path for the given layer id.

func (*VFSDriver) GetMetadata

func (d *VFSDriver) GetMetadata(_ string) (map[string]string, error)

GetMetadata returns metadata for the given layer.

func (*VFSDriver) Name

func (d *VFSDriver) Name() string

Name returns the name of the VFS driver.

func (*VFSDriver) Put

func (d *VFSDriver) Put(id, _ string) (string, error)

Put returns the filesystem path for the given layer id.

func (*VFSDriver) Remove

func (d *VFSDriver) Remove(id string) error

Remove deletes the directory for the given layer id.

type ZFSDriver

type ZFSDriver struct {
	// contains filtered or unexported fields
}

ZFSDriver implements the storage driver using ZFS filesystems.

func NewZFSDriver

func NewZFSDriver(root, pool, fsPrefix string) (*ZFSDriver, error)

NewZFSDriver creates a new ZFS storage driver.

func (*ZFSDriver) Cleanup

func (d *ZFSDriver) Cleanup() error

Cleanup releases resources held by the ZFS driver.

func (*ZFSDriver) Exists

func (d *ZFSDriver) Exists(id string) bool

Exists checks whether a ZFS filesystem for the given layer id exists.

func (*ZFSDriver) Get

func (d *ZFSDriver) Get(id, _ string) (string, error)

Get mounts the ZFS filesystem for the given layer id and returns its mount path.

func (*ZFSDriver) GetMetadata

func (d *ZFSDriver) GetMetadata(_ string) (map[string]string, error)

GetMetadata returns metadata for the given layer.

func (*ZFSDriver) Name

func (d *ZFSDriver) Name() string

Name returns the name of the ZFS driver.

func (*ZFSDriver) Put

func (d *ZFSDriver) Put(id, _ string) (string, error)

Put unmounts the ZFS filesystem for the given layer id and returns its mount path.

func (*ZFSDriver) Remove

func (d *ZFSDriver) Remove(id string) error

Remove destroys the ZFS filesystem for the given layer id.

Jump to

Keyboard shortcuts

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