blk

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package blk exports persistent sparse volumes through pure-Go NBD over Unix sockets or TCP. Other storage implementations can implement Device directly.

The volume adapter exposes persistent sparse volumes backed by the same chunk, compression, cache and writeback engine as compactfs files.

Index

Constants

View Source
const (
	FlagHasFlags    = uint16(1)
	FlagReadOnly    = uint16(2)
	FlagFlush       = uint16(4)
	FlagFUA         = uint16(8)
	FlagTrim        = uint16(32)
	FlagWriteZeroes = uint16(64)
	FlagMultiConn   = uint16(256)
)
View Source
const (
	SectorSize  = 512
	DefaultSize = int64(100 << 30)
)

Variables

This section is empty.

Functions

func Attach

func Attach(ctx context.Context, cfg AttachConfig) error

Attach negotiates in userspace and hands connected sockets to Linux NBD. It runs in the foreground until Detach or context cancellation. It neither formats nor mounts the block device and does not require cgo or nbd-client.

func Detach

func Detach(devicePath string) error

Detach refuses mounted/in-use devices through an exclusive block open. It flushes before asking the kernel to disconnect the existing connection.

func List

func List(ctx context.Context, network, address string) ([]string, error)

Types

type AttachConfig

type AttachConfig struct {
	Network     string
	Address     string
	Export      string
	Device      string
	Connections int
	Timeout     time.Duration
}

type Client

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

Client is a serial userspace NBD connection. Use several clients for parallel I/O, or Attach to let the Linux block layer multiplex requests itself.

func Dial

func Dial(ctx context.Context, network, address, name string) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

Close disconnects without an implicit FLUSH; call Flush for durability.

func (*Client) Flush

func (c *Client) Flush(ctx context.Context) error

func (*Client) Info

func (c *Client) Info() ExportInfo

func (*Client) ReadAt

func (c *Client) ReadAt(ctx context.Context, p []byte, off int64) (int, error)

func (*Client) Trim

func (c *Client) Trim(ctx context.Context, off int64, length uint32) error

func (*Client) WriteAt

func (c *Client) WriteAt(ctx context.Context, p []byte, off int64) (int, error)

func (*Client) WriteAtFUA

func (c *Client) WriteAtFUA(ctx context.Context, p []byte, off int64, fua bool) (int, error)

func (*Client) Zero

func (c *Client) Zero(ctx context.Context, off int64, length uint32, noHole, fua bool) error

type Config

type Config struct {
	Exports          []Export
	Concurrency      int
	MaxRequest       uint32
	MaxConnections   int
	HandshakeTimeout time.Duration
}

type Device

type Device interface {
	Size() int64
	ReadOnly() bool
	ReadAt(context.Context, []byte, int64) (int, error)
	WriteAt(context.Context, []byte, int64) (int, error)
	Flush(context.Context) error
	Trim(context.Context, int64, int64) error
	Zero(context.Context, int64, int64, bool) error
}

type Export

type Export struct {
	Name   string
	Device Device
}

type ExportInfo

type ExportInfo struct {
	Name           string `json:"name"`
	Size           int64  `json:"size"`
	Flags          uint16 `json:"flags"`
	MinimumBlock   uint32 `json:"minimum_block"`
	PreferredBlock uint32 `json:"preferred_block"`
	MaximumBlock   uint32 `json:"maximum_block"`
}

ExportInfo is the geometry and capability information negotiated with NBD.

type Server

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

func NewServer

func NewServer(cfg Config) (*Server, error)

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, listeners ...net.Listener) error

Serve owns its listeners until cancellation or an accept error. Shutdown closes transports, then waits for every dispatched storage operation.

func (*Server) Stats

func (s *Server) Stats() Stats

func (*Server) String

func (s *Server) String() string

type Stats

type Stats struct {
	Connections int64 `json:"connections"`
	Requests    int64 `json:"requests"`
	ReadBytes   int64 `json:"read_bytes"`
	WriteBytes  int64 `json:"write_bytes"`
	Flushes     int64 `json:"flushes"`
	Trims       int64 `json:"trims"`
	Errors      int64 `json:"errors"`
}

type Volume

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

func Open

func Open(ctx context.Context, cfg VolumeConfig) (*Volume, error)

Open must be called once per exported volume; all connections share its File.

func (*Volume) Close

func (v *Volume) Close(ctx context.Context) error

func (*Volume) Flush

func (v *Volume) Flush(ctx context.Context) error

func (*Volume) Name

func (v *Volume) Name() string

func (*Volume) ReadAt

func (v *Volume) ReadAt(ctx context.Context, p []byte, off int64) (int, error)

func (*Volume) ReadOnly

func (v *Volume) ReadOnly() bool

func (*Volume) Size

func (v *Volume) Size() int64

func (*Volume) Trim

func (v *Volume) Trim(ctx context.Context, off, length int64) error

func (*Volume) WriteAt

func (v *Volume) WriteAt(ctx context.Context, p []byte, off int64) (int, error)

func (*Volume) Zero

func (v *Volume) Zero(ctx context.Context, off, length int64, noHole bool) error

type VolumeConfig

type VolumeConfig struct {
	FileSystem *core.FileSystem
	Name       string
	// Size is fixed at creation. Zero reopens the stored size, or creates a
	// DefaultSize volume when it does not exist. Existing sizes never change.
	Size     int64
	ReadOnly bool
	// SyncBackend makes FLUSH/FUA wait for backend persistence. Otherwise the
	// durable local raw cache is sufficient, as for mount --sync-mode=local.
	SyncBackend bool
}

Jump to

Keyboard shortcuts

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