volume

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package volume manages persistent virtio-blk disk volumes for unikernel VMs. A volume is a raw disk image file in the volume root directory, identified by a human-readable name. Volumes survive VM restarts; they are only deleted when the user explicitly runs "jerboa volume rm".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureFormatted added in v0.51.0

func EnsureFormatted(ctx context.Context, diskPath, label string, sizeBytes int64, format Formatter) error

EnsureFormatted formats the disk at diskPath as an empty TFS volume labeled label if it is not already formatted. It is idempotent: a volume that already carries a TFS filesystem is left untouched so existing data is preserved. sizeBytes is the minimum image size; when <= 0 the current file size is used. format must be non-nil (the mkfs toolchain is supplied by the daemon).

func IsFormatted added in v0.51.0

func IsFormatted(path string) (bool, error)

IsFormatted reports whether the disk at path already carries a TFS filesystem (its first bytes match the TFS magic). A missing file or a freshly allocated zero-filled disk reports false.

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize parses a human size string ("512M", "1G", "2048K") into bytes. Supported suffixes: K (kibibytes), M (mebibytes), G (gibibytes). A bare integer is interpreted as bytes. Unknown suffixes are an error.

func SanitizeLabel added in v0.51.0

func SanitizeLabel(name string) string

SanitizeLabel trims name to a valid TFS label (<= maxLabelLen bytes). The kernel's volume_match compares the label verbatim, so it must equal the value injected into the guest mount config.

Types

type Formatter added in v0.51.0

type Formatter func(ctx context.Context, diskPath, label string, sizeBytes int64) error

Formatter formats the raw disk at diskPath as an empty TFS filesystem labeled label with a minimum size of sizeBytes. Implemented by internal/tools using the mkfs toolchain; the daemon supplies one at run time (mkfs is Linux-only, so formatting cannot happen on a Windows client at create time).

type Store

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

Store manages volumes on disk.

func NewStore

func NewStore(dir string) (*Store, error)

NewStore returns a Store rooted at dir, creating it if needed.

func (*Store) Create

func (s *Store) Create(name string, sizeBytes int64) (*Volume, error)

Create allocates a new volume named name with the given size in bytes. If sizeBytes is 0 the default (1 GiB) is used.

func (*Store) Get

func (s *Store) Get(name string) (*Volume, error)

Get returns the volume with the given name.

func (*Store) List

func (s *Store) List() ([]*Volume, error)

List returns all volumes in the store.

func (*Store) Remove

func (s *Store) Remove(name string) error

Remove deletes the volume and its disk image.

type Volume

type Volume struct {
	// ID is the volume name (unique within the store).
	ID string `json:"id"`
	// DiskPath is the absolute path to the raw disk image file.
	DiskPath string `json:"disk_path"`
	// SizeBytes is the allocated size of the disk image.
	SizeBytes int64 `json:"size_bytes"`
	// CreatedAt is when the volume was created.
	CreatedAt time.Time `json:"created_at"`
	// Label is the TFS filesystem label written when the volume is formatted.
	// It defaults to the volume ID and is the key the guest kernel matches to
	// mount this disk. Capped to maxLabelLen.
	Label string `json:"label,omitempty"`
}

Volume is a named persistent disk image.

Jump to

Keyboard shortcuts

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