nbd

package module
v0.0.0-...-96f47eb Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: BSD-3-Clause Imports: 14 Imported by: 1

README

A Linux Network Block Device (NBD) client library for Go.

This library allows you to create custom block devices for Linux using the NBD driver. A sample block device that uses a raw file, similar to the loopback device, is included.

This library is NOT intended for production use.

Documentation

Index

Constants

View Source
const (
	DefaultBlockSize     = 512
	DefaultConcurrentOps = 1

	// Maximum number of concurrent operations
	// (block device queue depth: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/block/nbd.c?h=v5.15#n1692)
	MaxConcurrentOps = 128
)

Variables

View Source
var (
	ErrUnsupported = errors.New("nbd: unsupported operation")
)

Functions

This section is empty.

Types

type BlockDevice

type BlockDevice interface {
	io.ReaderAt
	io.WriterAt
}

type BlockDeviceFlusher

type BlockDeviceFlusher interface {
	Flush() error
}

type BlockDeviceOptions

type BlockDeviceOptions struct {
	// BlockSize is the size of each block on the block device, in bytes.
	// Must be between 512 and the system page size (usually 4096 on x86).
	// If 0, the default value of DefaultBlockSize will be used.
	BlockSize int

	// ConcurrentOps is the number of operations (read, write, trim, flush)
	// which can be performed concurrently. Must be between 1 and 128.
	// If 0, the default value of DefaultConcurrentOps will be used.
	ConcurrentOps int

	// Readonly should be set to true if the block device is read-only.
	Readonly bool
}

type BlockDeviceTrimer

type BlockDeviceTrimer interface {
	Trim(off int64, length uint32) error
}

type NbdServer

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

func NewServer

func NewServer(dev string, block BlockDevice, size int64, opts BlockDeviceOptions) (*NbdServer, error)

func NewServerFromFd

func NewServerFromFd(devFd int, block BlockDevice, size int64, opts BlockDeviceOptions) (*NbdServer, error)
func NewServerWithNetlink(index int, block BlockDevice, size int64, opts BlockDeviceOptions) (*NbdServer, error)

func (*NbdServer) Disconnect

func (s *NbdServer) Disconnect() error

func (*NbdServer) Run

func (s *NbdServer) Run() error

type NetlinkConn

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

func NewNetlinkConn

func NewNetlinkConn(index int) (*NetlinkConn, error)

func (*NetlinkConn) Connect

func (c *NetlinkConn) Connect() error

func (*NetlinkConn) Disconnect

func (c *NetlinkConn) Disconnect() error

func (*NetlinkConn) SetBlockSize

func (c *NetlinkConn) SetBlockSize(size uint64)

func (*NetlinkConn) SetFd

func (c *NetlinkConn) SetFd(fd int)

func (*NetlinkConn) SetReadonly

func (c *NetlinkConn) SetReadonly(ro bool)

func (*NetlinkConn) SetSize

func (c *NetlinkConn) SetSize(size uint64)

func (*NetlinkConn) SetSupportsFlush

func (c *NetlinkConn) SetSupportsFlush(flush bool)

func (*NetlinkConn) SetSupportsTrim

func (c *NetlinkConn) SetSupportsTrim(trim bool)

type Reply

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

func NewReply

func NewReply(handle uint64, dataSize int) *Reply

func (*Reply) Buffer

func (r *Reply) Buffer() []byte

func (*Reply) BufferSize

func (r *Reply) BufferSize() int

func (*Reply) Send

func (r *Reply) Send(w io.Writer) error

func (*Reply) SetError

func (r *Reply) SetError(err uint32)

type ReplyPool

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

func (*ReplyPool) Get

func (p *ReplyPool) Get(handle uint64, size int) *Reply

func (*ReplyPool) Put

func (p *ReplyPool) Put(r *Reply)

type Request

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

func (*Request) Buffer

func (r *Request) Buffer() []byte

func (*Request) String

func (r *Request) String() string

type RequestPool

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

func (*RequestPool) Put

func (p *RequestPool) Put(r *Request)

func (*RequestPool) Recv

func (p *RequestPool) Recv(b *bufio.Reader) (*Request, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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